SynEdit: Refactor, LengthOfLongestLine

git-svn-id: trunk@25789 -
This commit is contained in:
martin 2010-05-31 00:31:12 +00:00
parent 4ab9eaac1b
commit 0e98a5118a

View File

@ -311,10 +311,8 @@ end;
function TSynEditStringTabExpander.GetLengthOfLongestLine: integer;
var
Line: String;
CharWidths: TPhysicalCharWidths;
n, m: Integer;
//var
i, j: integer;
CharWidths: PPhysicalCharWidth;
i, j, n, m: Integer;
begin
if (fIndexOfLongestLine >= 0) and (fIndexOfLongestLine < Count) then begin
Result := FTabData[fIndexOfLongestLine];
@ -322,40 +320,45 @@ begin
exit;
end;
Result := 0;
m := 0;
for i := 0 to Count - 1 do begin
j := FTabData[i];
if j = LINE_LEN_UNKNOWN then begin
// embedd a copy of ExpandedStringLength
// allows to re-use CharWidths
Line := fSynStrings[i];
j := 0;
if (Line = '') then begin
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
end else begin
n := length(Line);
if n > m then begin
SetLength(CharWidths, n);
m := n;
end;
DoGetPhysicalCharWidths(Pchar(Line), n, i, @CharWidths[0]);
for m := 0 to n-1 do
j := j + CharWidths[m];
if FLastLineHasTab then // FLastLineHasTab is set by GetPhysicalCharWidths
FTabData[i] := j
else
try
Result := 0;
m := 0;
CharWidths := nil;
for i := 0 to Count - 1 do begin
j := FTabData[i];
if j = LINE_LEN_UNKNOWN then begin
// embedd a copy of ExpandedStringLength
// allows to re-use CharWidths
Line := fSynStrings[i];
j := 0;
if (Line = '') then begin
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
end else begin
n := length(Line);
if n > m then begin
ReAllocMem(CharWidths, n * SizeOf(TPhysicalCharWidth));
m := n;
end;
DoGetPhysicalCharWidths(Pchar(Line), n, i, CharWidths);
for m := 0 to n-1 do
j := j + CharWidths[m];
if FLastLineHasTab then // FLastLineHasTab is set by GetPhysicalCharWidths
FTabData[i] := j
else
FTabData[i] := j + NO_TAB_IN_LINE_OFFSET;
end;
end
else
if j >= NO_TAB_IN_LINE_OFFSET then
j := j - NO_TAB_IN_LINE_OFFSET;
if j > Result then begin
Result := j;
fIndexOfLongestLine := i;
end;
end
else
if j >= NO_TAB_IN_LINE_OFFSET then
j := j - NO_TAB_IN_LINE_OFFSET;
if j > Result then begin
Result := j;
fIndexOfLongestLine := i;
end;
finally
ReAllocMem(CharWidths, 0);
end;
end;