IDE, Printing: break long lines. Fix Utf8. Update for rev 36529 #63bc45df7b

git-svn-id: trunk@36547 -
This commit is contained in:
martin 2012-04-03 17:40:36 +00:00
parent 63512ed1c7
commit 8afdbf2a7a

View File

@ -23,7 +23,7 @@ unit SourcePrinter;
interface
uses
Classes, SysUtils, Printers, Graphics, PrintersDlgs, ExtCtrls, GraphType;
Classes, SysUtils, Printers, Graphics, PrintersDlgs, ExtCtrls, GraphType, LazUTF8;
type
TSourcePrinter = class(TObject)
@ -130,7 +130,8 @@ begin
s := Text[j];
if ShowLineNumbers then s2 := Format('%4d: ',[i]);
l := Printer.Canvas.TextFitInfo(s2 + s, Printer.PageWidth - 2 * Margin);
l := l - Length(s2);
l := l - Length(s2); // s2 has only single byte
l := UTF8CharToByteIndex(PChar(s), length(s), l);
while (l > MIN_LINE_LEN) and (l < length(s)) do begin
l2 := l;
while (l2 > MIN_LINE_LEN) and
@ -140,12 +141,17 @@ begin
dec(l2);
if l2 <= MIN_LINE_LEN then
l2 := l;
// find utf8 start
while (l2 > 1) and (ord(s[l2]) >= 128) and (ord(s[l2+1]) >= 128) and (ord(s[l2+1]) < 192) do
dec(l2);
if l2 = 0 then l2 := UTF8CharToByteIndex(PChar(s), length(s), MIN_LINE_LEN);
Text[j] := copy(s, 1, l2);
delete(s, 1, l2);
inc(j);
Text.InsertObject(j, '', nil);
l := Printer.Canvas.TextFitInfo(s2 + s, Printer.PageWidth - 2 * Margin);
l := l - Length(s2);
l := UTF8CharToByteIndex(PChar(s), length(s), l);
end;
Text[j] := s;
inc(i);