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
This commit is contained in:
jesusr
2014-12-06 02:31:38 +00:00
parent dca64b78bc
commit ec9ab37f74
3 changed files with 34 additions and 10 deletions

View File

@ -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);

View File

@ -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;

View File

@ -1,4 +1,4 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<Package Version="4">
<PathDelim Value="\"/>
@ -17,14 +17,10 @@
</SyntaxOptions>
</Parsing>
<Other>
<CompilerMessages>
<UseMsgFile Value="True"/>
</CompilerMessages>
<CustomOptions Value="-dLAZ_POWERPDF"/>
<CompilerPath Value="$(CompPath)"/>
</Other>
</CompilerOptions>
<Version Minor="9" Release="10"/>
<Version Minor="9" Release="12"/>
<Files Count="12">
<Item1>
<Filename Value="PdfTypes.pas"/>