PowerPDF, added support for underline font style

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1175 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
jesusr
2010-03-05 16:42:19 +00:00
parent 99fc954036
commit 6b8197d3ee
4 changed files with 104 additions and 15 deletions

View File

@@ -338,8 +338,10 @@ type
FFontBold: boolean; FFontBold: boolean;
FFontItalic: boolean; FFontItalic: boolean;
FCharSpace: Single; FCharSpace: Single;
FFontUnderLine: boolean;
FWordSpace: Single; FWordSpace: Single;
procedure SetCharSpace(Value: Single); procedure SetCharSpace(Value: Single);
procedure SetFontUnderline(const Value: boolean);
procedure SetWordSpace(Value: Single); procedure SetWordSpace(Value: Single);
procedure SetFontColor(Value: TColor); procedure SetFontColor(Value: TColor);
function GetFontClassName: string; function GetFontClassName: string;
@@ -363,6 +365,7 @@ type
property FontSize: Single read FFontSize write SetFontSize; property FontSize: Single read FFontSize write SetFontSize;
property FontBold: boolean read FFontBold write SetFontBold default false; property FontBold: boolean read FFontBold write SetFontBold default false;
property FontItalic: boolean read FFontItalic write SetFontItalic default false; property FontItalic: boolean read FFontItalic write SetFontItalic default false;
property FontUnderline: boolean read FFontUnderLine write SetFontUnderline default false;
property CharSpace: Single read FCharSpace write SetCharSpace; property CharSpace: Single read FCharSpace write SetCharSpace;
property WordSpace: Single read FWordSpace write SetWordSpace; property WordSpace: Single read FWordSpace write SetWordSpace;
end; end;
@@ -1798,7 +1801,7 @@ end;
// GetText // GetText
function TPRText.GetText: string; function TPRText.GetText: string;
begin begin
result := Trim(FLines.Text); result := TrimRight(FLines.Text);
end; end;
// Create // Create
@@ -1918,6 +1921,7 @@ begin
SetCharSpace(CharSpace); SetCharSpace(CharSpace);
SetWordSpace(WordSpace); SetWordSpace(WordSpace);
SetLeading(Leading); SetLeading(Leading);
Attribute.FontUnderline:=FontUnderline;
with ARect do with ARect do
MultilineTextRect(_PdfRect(Left, GetPage.Height- Top, Right, GetPage.Height- Bottom), MultilineTextRect(_PdfRect(Left, GetPage.Height- Top, Right, GetPage.Height- Bottom),
@@ -1935,6 +1939,19 @@ begin
end; end;
end; end;
procedure TPRCustomLabel.SetFontUnderline(const Value: boolean);
begin
if FFontUnderLine <> Value then
begin
FFontUnderLine := Value;
if Value then
Font.Style := Font.Style + [fsUnderline]
else
Font.Style := Font.Style - [fsUnderline];
Invalidate;
end;
end;
// SetLeading // SetLeading
procedure TPRText.SetLeading(Value: Single); procedure TPRText.SetLeading(Value: Single);
begin begin

View File

@@ -357,6 +357,7 @@ type
FFont: TPdfFont; FFont: TPdfFont;
FLeading: Single; FLeading: Single;
FHorizontalScaling: Word; FHorizontalScaling: Word;
FFontUnderline: boolean;
procedure SetWordSpace(Value: Single); procedure SetWordSpace(Value: Single);
procedure SetCharSpace(Value: Single); procedure SetCharSpace(Value: Single);
procedure SetFontSize(Value: Single); procedure SetFontSize(Value: Single);
@@ -372,6 +373,7 @@ type
property Leading: Single read FLeading write SetLeading; property Leading: Single read FLeading write SetLeading;
property FontSize: Single read FFontSize write SetFontSize; property FontSize: Single read FFontSize write SetFontSize;
property Font: TPdfFont read FFont write FFont; property Font: TPdfFont read FFont write FFont;
property FontUnderline: boolean read FFontUnderline write FFontUnderline;
end; end;
{ TPdfCanvas } { TPdfCanvas }
@@ -541,9 +543,13 @@ type
property Pages: TPdfDictionary read GetPages write SetPages; property Pages: TPdfDictionary read GetPages write SetPages;
end; end;
{ TPdfFont }
TPdfFont = class(TPdfDictionaryWrapper) TPdfFont = class(TPdfDictionaryWrapper)
private private
FName: string; FName: string;
FUnderlinePosition: Integer;
FUnderlineThickness: Integer;
protected protected
procedure AddStrElements(ADic: TPdfDictionary; ATable: array of TPDF_STR_TBL); procedure AddStrElements(ADic: TPdfDictionary; ATable: array of TPDF_STR_TBL);
procedure AddIntElements(ADic: TPdfDictionary; ATable: array of TPDF_INT_TBL); procedure AddIntElements(ADic: TPdfDictionary; ATable: array of TPDF_INT_TBL);
@@ -551,6 +557,8 @@ type
constructor Create(AXref: TPdfXref; AName: string); virtual; constructor Create(AXref: TPdfXref; AName: string); virtual;
function GetCharWidth(AText: string; APos: integer): integer; virtual; function GetCharWidth(AText: string; APos: integer): integer; virtual;
property Name: string read FName; property Name: string read FName;
property UnderlinePosition: Integer read FUnderlinePosition write FUnderlinePosition;
property UnderlineThickness: Integer read FUnderlineThickness write FUnderlineThickness;
end; end;
TPdfDestination = class(TObject) TPdfDestination = class(TObject)
@@ -1500,11 +1508,22 @@ end;
// TextOut // TextOut
procedure TPdfCanvas.TextOut(X, Y: Single; Text: string); procedure TPdfCanvas.TextOut(X, Y: Single; Text: string);
var
UPos, UWidth: Single;
begin begin
BeginText; BeginText;
MoveTextPoint(X, Y); MoveTextPoint(X, Y);
ShowText(Text); ShowText(Text);
EndText; EndText;
//TODO: Check Underline
if FAttr.FontUnderline then
begin
UPos := FAttr.Font.UnderlinePosition/1000*FAttr.FontSize;
UWidth := FAttr.Font.UnderlineThickness/1000*FAttr.FontSize;
Rectangle(X, Y+UPos, FAttr.TextWidth(Text), UWidth);
Fill;
end;
end; end;
// TextRect // TextRect
@@ -1512,7 +1531,7 @@ procedure TPdfCanvas.TextRect(ARect: TPdfRect; Text: string;
Alignment: TPdfAlignment; Clipping: boolean); Alignment: TPdfAlignment; Clipping: boolean);
var var
tmpWidth: Single; tmpWidth: Single;
XPos: Single; XPos,YPos,UPos,UWidth: Single;
begin begin
// calculate text width. // calculate text width.
tmpWidth := TextWidth(Text); tmpWidth := TextWidth(Text);
@@ -1540,22 +1559,32 @@ begin
NewPath; NewPath;
end; end;
YPos := ARect.Top - FAttr.FontSize * 0.85;
BeginText; BeginText;
MoveTextPoint(ARect.Left + XPos, ARect.Top - FAttr.FontSize * 0.85); MoveTextPoint(ARect.Left + XPos, YPos);
ShowText(Text); ShowText(Text);
EndText; EndText;
//TODO: Check Underline
if FAttr.FontUnderline then
begin
UPos := FAttr.Font.UnderlinePosition/1000*FAttr.FontSize;
UWidth := FAttr.Font.UnderlineThickness/1000*FAttr.FontSize;
Rectangle(ARect.Left + XPos, YPos + UPos, FAttr.TextWidth(Text), UWidth);
Fill;
end;
if Clipping then if Clipping then
GRestore; GRestore;
end; end;
// MultilineTextRect // MultilineTextRect
procedure TPdfCanvas.MultilineTextRect(ARect: TPdfRect; procedure TPdfCanvas.MultilineTextRect(ARect: TPdfRect; Text: string;
Text: string; WordWrap: boolean); WordWrap: boolean);
var var
i: integer; i: integer;
S1, S2: string; S1, S2: string;
XPos, YPos: Single; XPos, YPos, UPos, UWidth: Single;
tmpXPos: Single; tmpXPos: Single;
tmpWidth: Single; tmpWidth: Single;
ln: integer; ln: integer;
@@ -1571,14 +1600,36 @@ var
ShowText(S); ShowText(S);
end; end;
procedure WriteText;
begin
if FAttr.FontUnderline then
begin
BeginText;
MoveTextPoint(ARect.Left, YPos);
InternalShowText(S2, ARect.Right - ARect.Left);
EndText;
Rectangle(ARect.Left, YPos+UPos, XPos-ARect.Left, UWidth);
Fill;
end else
InternalShowText(S2, ARect.Right - ARect.Left);
end;
begin begin
YPos := ARect.Top - FAttr.FontSize*0.85; YPos := ARect.Top - FAttr.FontSize*0.85;
XPos := ARect.Left; XPos := ARect.Left;
FText := Text; FText := Text;
BeginText; if FAttr.FontUnderline then
begin
UPos := FAttr.Font.UnderlinePosition/1000*FAttr.FontSize;
UWidth := FAttr.Font.UnderlineThickness/1000*FAttr.FontSize;
end else
begin
BeginText;
MoveTextPoint(XPos, YPos);
end;
MoveTextPoint(XPos, YPos);
i := 1; i := 1;
S2 := GetNextWord(FText, i); S2 := GetNextWord(FText, i);
XPos := XPos + TextWidth(S2); XPos := XPos + TextWidth(S2);
@@ -1604,9 +1655,13 @@ begin
FourceReturn then FourceReturn then
begin begin
if S2 <> '' then if S2 <> '' then
InternalShowText(S2, ARect.Right - ARect.Left); WriteText;
S2 := ''; S2 := '';
MoveToNextLine;
if not FAttr.FontUnderline then
MoveToNextLine;
ARect.Top := ARect.Top - FAttr.Leading; ARect.Top := ARect.Top - FAttr.Leading;
if ARect.Top < ARect.Bottom + FAttr.FontSize then if ARect.Top < ARect.Bottom + FAttr.FontSize then
Break; Break;
@@ -1619,8 +1674,10 @@ begin
end; end;
if S2 <> '' then if S2 <> '' then
InternalShowText(S2, ARect.Right - ARect.Left); WriteText;
EndText;
if not FAttr.FontUnderline then
EndText;
end; end;
// DrawXObject // DrawXObject
@@ -2559,6 +2616,8 @@ constructor TPdfFont.Create(AXref: TPdfXref; AName: string);
begin begin
inherited Create; inherited Create;
FName := AName; FName := AName;
FUnderlinePosition := -150;
FUnderlineThickness := 50;
end; end;
{ PdfDestination } { PdfDestination }

View File

@@ -490,6 +490,9 @@ const
SCRIPT_BBOX: array[0..3] of Integer = (-184,-363,505,758); SCRIPT_BBOX: array[0..3] of Integer = (-184,-363,505,758);
type type
{ TPdfType1Font }
TPdfType1Font = class(TPdfFont) TPdfType1Font = class(TPdfFont)
private private
FFirstChar: Byte; FFirstChar: Byte;
@@ -578,6 +581,7 @@ var
i: integer; i: integer;
DefaultWidth: Word; DefaultWidth: Word;
Widths: TPdfArray; Widths: TPdfArray;
ANumber: TPdfNumber;
begin begin
inherited SetData(Value); inherited SetData(Value);
@@ -700,6 +704,8 @@ begin
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_W_ARRAY); FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths); FFont.AddInternalItem('Widths', FWidths);
UnderlinePosition := -151;
SetData(FFont); SetData(FFont);
end; end;
@@ -720,6 +726,9 @@ begin
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_BOLD_W_ARRAY); FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_BOLD_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths); FFont.AddInternalItem('Widths', FWidths);
UnderlinePosition := -155;
UnderlineThickness := 69;
SetData(FFont); SetData(FFont);
end; end;
@@ -740,6 +749,8 @@ begin
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_ITALIC_W_ARRAY); FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_ITALIC_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths); FFont.AddInternalItem('Widths', FWidths);
UnderlinePosition := -151;
SetData(FFont); SetData(FFont);
end; end;
@@ -760,6 +771,9 @@ begin
FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_BOLDITALIC_W_ARRAY); FWidths := TPdfArray.CreateNumArray(AXref, ARIAL_BOLDITALIC_W_ARRAY);
FFont.AddInternalItem('Widths', FWidths); FFont.AddInternalItem('Widths', FWidths);
UnderlinePosition := -111;
UnderlineThickness := 69;
SetData(FFont); SetData(FFont);
end; end;

View File

@@ -16,12 +16,11 @@
</SyntaxOptions> </SyntaxOptions>
</Parsing> </Parsing>
<Other> <Other>
<CustomOptions Value="-dLAZ_POWERPDF <CustomOptions Value="-dLAZ_POWERPDF"/>
"/>
<CompilerPath Value="$(CompPath)"/> <CompilerPath Value="$(CompPath)"/>
</Other> </Other>
</CompilerOptions> </CompilerOptions>
<Version Minor="9" Release="3" Build="1"/> <Version Minor="9" Release="4"/>
<Files Count="12"> <Files Count="12">
<Item1> <Item1>
<Filename Value="PdfTypes.pas"/> <Filename Value="PdfTypes.pas"/>