看来reportbuild5.5以后的单元全改了,现在分析了一下,可能在getnextword和
TppPlainText.WordWrap中找问题的解决方式了,有一点不明白就是哪个属性来判断
每行的长度,大家可以看看这个函数提提参考意见:
class procedure TppPlainText.WordWrap(const aText: String;
aRect: TppRect;
aTextAlignment: TppTextAlignment;
aAutoSize: Boolean;
aFont: TFont;
aCharWrap: Boolean;
aLeading: Integer;
aTabStops: TStrings;
aPrinter: TObject;
var aCharPos: Integer;
aWrappedText: TStrings);
var
lTextWrapper: TppTextWrapper;
begin
lTextWrapper := TppTextWrapper.Create;
lTextWrapper.AreaAvailable := aRect;
lTextWrapper.Alignment := aTextAlignment;
lTextWrapper.AutoSize := aAutoSize;
lTextWrapper.CharWrap := aCharWrap;
lTextWrapper.Font := aFont;
lTextWrapper.Leading := aLeading;
lTextWrapper.Printer := TppPrinter(aPrinter);
lTextWrapper.Tabs := aTabStops;
lTextWrapper.Text := aText;
try
{set the current character position}
lTextWrapper.CharPos := aCharPos;
{wrap the text}
lTextWrapper.Wrap;
{get the new character position}
aCharPos := lTextWrapper.CharPos;
{get the wrapped text}
aWrappedText.Assign(lTextWrapper.WrappedText);
finally
lTextWrapper.Free;
end;
end;
还有lTextWrapper.Wrap;其实就是调用下面的函数
function TppPlainTextParser.GetNextWord: String;
var
lbEndOfWord: Boolean;
lCharacter: Char;
lsWord: String;
begin
lsWord := '';
lbEndOfWord := False;
while not(lbEndOfWord) and not(FAllWordsParsed)do
begin
{move to next position in the text}
Inc(FCharPos);
{reached end of the text}
if (FCharPos > FTextLength) then
FAllWordsParsed := True
else
begin
lCharacter := FText[FCharPos];
if (lCharacter = TppTextMarkups.Null) then
FAllWordsParsed := True
else
if (lCharacter = TppTextMarkups.Space) then
begin
lbEndOfWord := True;
if (lsWord = '') then
lsWord := TppTextMarkups.Space
else
Dec(FCharPos);
end
else
if (lCharacter = TppTextMarkups.CR) then
begin
lbEndOfWord := True;
if (lsWord <> '') then
Dec(FCharPos)
else
begin
if ((FCharPos + 1) <= FTextLength) and (FText[FCharPos + 1] = TppTextMarkups.LF) then
Inc(FCharPos);
{skip over the LF char since it was found immediately following CR}
if (FCharPos <= FTextLength) then
lsWord := TppTextMarkups.CRLF;
end;
end
else
if (lCharacter = TppTextMarkups.LF) then
begin
lbEndOfWord := True;
if (lsWord <> '') then
Dec(FCharPos)
else
if (FCharPos <= FTextLength) then
lsWord := TppTextMarkups.CRLF;
end
else
if (lCharacter = TppTextMarkups.Tab) then
begin
lbEndOfWord := True;
if (lsWord = '') then
lsWord := TppTextMarkups.Tab
else
Dec(FCharPos);
end
else
if ((FCharPos + 1) <= FTextLength) and (lCharacter + FText[FCharPos + 1] = TppTextMarkups.EOP) then
begin
lbEndOfWord := True;
if (lsWord <> '') then
Dec(FCharPos)
else
begin
Inc(FCharPos);
lsWord := TppTextMarkups.CRLF;
end;
end
else
lsWord := lsWord + lCharacter;
end;
end;
Result := lsWord;
end;
这里的判断换行方式实在让人费解,有人知道吗