You've already forked lazarus-ccr
PowerPDF, convert text to winansiencoding before getting textwidth
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1199 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1290,7 +1290,11 @@ var
|
||||
tmpWidth: Single;
|
||||
begin
|
||||
Result := 0;
|
||||
|
||||
{$IFDEF LAZ_POWERPDF}
|
||||
// for invalid char, any value less than 32 will make FFont.GetCharWidth
|
||||
// to return a default missing width for that font.
|
||||
Text := _UTF8ToWinAnsi(Text, #31);
|
||||
{$ENDIF}
|
||||
// calculate width of specified text from current attributes
|
||||
for i := 1 to Length(Text) do
|
||||
begin
|
||||
@ -1321,6 +1325,10 @@ begin
|
||||
Result := 0;
|
||||
tmpTotalWidth := 0;
|
||||
|
||||
{$IFDEF LAZ_POWERPDF}
|
||||
Text := _UTF8ToWinAnsi(Text, #31);
|
||||
{$ENDIF}
|
||||
|
||||
// calculate number of charactor contain in the specified width.
|
||||
for i := 1 to Length(Text) do
|
||||
begin
|
||||
@ -2159,7 +2167,7 @@ end;
|
||||
|
||||
procedure TPdfCanvas.RoundRect(x, y, width, height, rx, ry: Single);
|
||||
var
|
||||
hm,wm,h1,w1:single;
|
||||
h1,w1:single;
|
||||
begin
|
||||
h1 := ry*11/20;
|
||||
w1 := rx*11/20;
|
||||
|
@ -300,6 +300,7 @@ type
|
||||
|
||||
{$IFDEF LAZ_POWERPDF}
|
||||
function _UTF8StrToUnicodeHex(const Value:string): string;
|
||||
function _UTF8ToWinAnsi(const value:string; InvalidChar:char='?'): string;
|
||||
procedure PdfLazRegisterClassAlias(aClass: TPersistentClass; Alias: string);
|
||||
function PdfLazFindClass(aClassName: string):TPersistentClass;
|
||||
{$ENDIF}
|
||||
@ -1052,7 +1053,7 @@ end;
|
||||
//type
|
||||
// TConvFunc=function(const W:Word): char;
|
||||
|
||||
function CP1252(const W: Word): Char;
|
||||
function CP1252(const W: Word; const InvalidChar: Char): Char;
|
||||
begin
|
||||
case W of
|
||||
$00..$7F,$A0..$FF: result := char(W);
|
||||
@ -1084,19 +1085,10 @@ begin
|
||||
$017E: result := #$9E;
|
||||
$0178: result := #$9F;
|
||||
else
|
||||
result:='?';
|
||||
result:=InvalidChar;
|
||||
end;
|
||||
end;
|
||||
|
||||
function UnicodeToWinAnsi(W: widestring): string;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
result := '';
|
||||
for i:=1 to length(w) do
|
||||
result := result + CP1252(word(w[i]));
|
||||
end;
|
||||
|
||||
// _EscapeText
|
||||
function _EscapeText(const Value: string): string;
|
||||
const
|
||||
@ -1106,15 +1098,17 @@ var
|
||||
i, j: integer;
|
||||
flg: boolean;
|
||||
S: string;
|
||||
W: widestring;
|
||||
begin
|
||||
// If text contains chars to need escape, replace text using "\".
|
||||
//
|
||||
// TODO: implement UNICODE support in powerpdf. Currently we can't do
|
||||
// any better than converting utf-8 strings to unicode.
|
||||
W := UTF8Decode(Value);
|
||||
S := UnicodeToWinAnsi(W);
|
||||
result := '';
|
||||
{$IFDEF LAZ_POWERPDF}
|
||||
S := _UTF8ToWinAnsi(Value);
|
||||
{$ELSE}
|
||||
S := Value;
|
||||
{$ENDIF}
|
||||
for i := 1 to Length(S) do
|
||||
begin
|
||||
flg := false;
|
||||
@ -1207,6 +1201,17 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function _UTF8ToWinAnsi(const value: string; InvalidChar:char='?'): string;
|
||||
var
|
||||
W: widestring;
|
||||
i: Integer;
|
||||
begin
|
||||
W := UTF8Decode(Value);
|
||||
result := '';
|
||||
for i:=1 to length(w) do
|
||||
result := result + CP1252(word(w[i]), InvalidChar);
|
||||
end;
|
||||
|
||||
procedure PdfLazRegisterClassAlias(aClass: TPersistentClass; Alias: string);
|
||||
begin
|
||||
Classes.RegisterClass(aClass);
|
||||
|
@ -20,7 +20,7 @@
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Version Minor="9" Release="4"/>
|
||||
<Version Minor="9" Release="5"/>
|
||||
<Files Count="12">
|
||||
<Item1>
|
||||
<Filename Value="PdfTypes.pas"/>
|
||||
|
Reference in New Issue
Block a user