From ec9ab37f745f0ca6ffbfca918974230109b41d81 Mon Sep 17 00:00:00 2001 From: jesusr Date: Sat, 6 Dec 2014 02:31:38 +0000 Subject: [PATCH] PowerPDF: implements Justify Alignment by resizing spaces instead of resizing characters, version=9.12 git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3825 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/powerpdf/PReport.pas | 22 ++++++++++++++++++---- components/powerpdf/PdfTypes.pas | 14 ++++++++++++++ components/powerpdf/pack_powerpdf.lpk | 8 ++------ 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/components/powerpdf/PReport.pas b/components/powerpdf/PReport.pas index b2d21e959..2f0b6dc81 100644 --- a/components/powerpdf/PReport.pas +++ b/components/powerpdf/PReport.pas @@ -47,7 +47,7 @@ interface uses {$IFDEF LAZ_POWERPDF} - LCLType, LMessages, LCLIntf, GraphType, FPCanvas, LCLProc, + LCLType, LMessages, LCLIntf, GraphType, FPCanvas, LazUTF8, LCLProc, {$ELSE} Windows, Messages, {$ENDIF} @@ -1722,10 +1722,11 @@ begin for i:=1 to UTF8Length(S) do begin Word := UTF8Copy(s, i, 1); Canvas.TextOut(Round(Pos), Y, Word); - with APdfCanvas do + with APdfCanvas do begin Pos := Pos + TextWidth(Word) + Attribute.CharSpace; - if Word=' ' then - Pos := Pos + FWordSpace + if Word=' ' then + Pos := Pos + Attribute.WordSpace; + end; end; result := Pos; end; @@ -1866,6 +1867,9 @@ var tmpWidth: Single; tmpCharSpace: Single; CharCount: integer; + {$IFDEF LAZ_POWERPDF} + str: string; + {$ENDIF} begin // setting canvas attribute to the internal doc(to get font infomation). with ACanvas do @@ -1876,6 +1880,15 @@ begin if AlignJustified then begin SetCharSpace(0); + {$IFDEF LAZ_POWERPDF} + str := UTF8Trim(Caption, [u8tKeepStart]); + tmpWidth := TextWidth(str); + CharCount := _GetSpcCount(str); + if CharCount>0 then begin + tmpCharSpace := (Self.Width - tmpWidth) / CharCount; + SetWordSpace(tmpCharSpace); + end; + {$ELSE} tmpWidth := TextWidth(Caption); CharCount := _GetCharCount(Caption); if CharCount > 1 then @@ -1884,6 +1897,7 @@ begin tmpCharSpace := 0; if tmpCharSpace > 0 then SetCharSpace(tmpCharSpace); + {$ENDIF} end else SetCharSpace(CharSpace); diff --git a/components/powerpdf/PdfTypes.pas b/components/powerpdf/PdfTypes.pas index da5d1395b..a9576b1ab 100644 --- a/components/powerpdf/PdfTypes.pas +++ b/components/powerpdf/PdfTypes.pas @@ -305,6 +305,7 @@ type function _UTF8ToWinAnsi(const value:string; InvalidChar:char='?'): string; procedure PdfLazRegisterClassAlias(aClass: TPersistentClass; const Alias: string); function PdfLazFindClass(const aClassName: string):TPersistentClass; + function _GetSpcCount(const Text: string): Integer; {$ENDIF} implementation @@ -1236,6 +1237,19 @@ begin raise EClassNotFound.CreateFmt('No class was found', [aClassName]); end; +function _GetSpcCount(const Text: string): Integer; +var + i: Integer; + W: widestring; +begin + result := 0; + W := UTF8Decode(Text); + for i:=1 to Length(W) do begin + if W[i]=' ' then + inc(result); + end; +end; + initialization AliasList := nil; diff --git a/components/powerpdf/pack_powerpdf.lpk b/components/powerpdf/pack_powerpdf.lpk index 8ce3eca6a..2a08d1731 100644 --- a/components/powerpdf/pack_powerpdf.lpk +++ b/components/powerpdf/pack_powerpdf.lpk @@ -1,4 +1,4 @@ - + @@ -17,14 +17,10 @@ - - - - - +