mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-04-20 12:19:31 +02:00
CairoCanvas, fix textrect with multiline text, modified test
git-svn-id: trunk@40721 -
This commit is contained in:
parent
606d865ad3
commit
8fc6a8eb4b
@ -772,7 +772,7 @@ var
|
||||
r,b: double;
|
||||
{$ifdef pangocairo}
|
||||
Layout: PPangoLayout;
|
||||
theRect: TPangoRectangle;
|
||||
ink,logical: TPangoRectangle;
|
||||
{$endif}
|
||||
|
||||
{$ifndef breaklines}
|
||||
@ -930,18 +930,19 @@ begin
|
||||
|
||||
//DebugLn('i=%i y=%f s1=%s',[i,y,s1]);
|
||||
{$ifdef pangocairo}
|
||||
cairo_text_extents(cr, PChar(s1), @te);
|
||||
//cairo_text_extents(cr, PChar(s1), @te);
|
||||
pango_layout_set_text(layout, pchar(s1), -1);
|
||||
pango_layout_get_extents(Layout, @theRect, nil);
|
||||
pango_layout_get_extents(Layout, @ink, @logical);
|
||||
case Style.Alignment of
|
||||
taLeftJustify: x := StartLeft;
|
||||
taCenter: x := BoxLeft + BoxWidth/2 - theRect.width/PANGO_SCALE/2 - te.x_bearing;
|
||||
taRightJustify: x := BoxLeft+BoxWidth - theRect.Width/PANGO_SCALE - te.x_bearing;
|
||||
taCenter: x := BoxLeft + BoxWidth/2 - ink.width/PANGO_SCALE/2;
|
||||
taRightJustify: x := BoxLeft+BoxWidth - ink.Width/PANGO_SCALE;
|
||||
end;
|
||||
cairo_move_to(cr, x, y);
|
||||
//DebugLn('TextRect ',S1);
|
||||
//DebugSys;
|
||||
pango_cairo_show_layout(cr, layout);
|
||||
y := y + logical.height/PANGO_SCALE;
|
||||
{$else}
|
||||
case Style.Alignment of
|
||||
taLeftJustify: x := StartLeft;
|
||||
@ -950,8 +951,8 @@ begin
|
||||
end;
|
||||
cairo_move_to(cr, x, y+fe.ascent);
|
||||
cairo_show_text(cr, PChar(s1)); //Reference point is on the base line
|
||||
{$endif}
|
||||
y := y + fe.height;
|
||||
{$endif}
|
||||
end;
|
||||
{$ifdef pangocairo}
|
||||
g_object_unref(layout);
|
||||
|
@ -36,9 +36,9 @@ object Form1: TForm1
|
||||
TabOrder = 2
|
||||
end
|
||||
object chkTests: TCheckGroup
|
||||
Left = 528
|
||||
Left = 526
|
||||
Height = 80
|
||||
Top = 100
|
||||
Top = 144
|
||||
Width = 97
|
||||
AutoFill = True
|
||||
Caption = 'Paint or Print'
|
||||
@ -55,7 +55,7 @@ object Form1: TForm1
|
||||
Items.Strings = (
|
||||
'24217'
|
||||
'19435'
|
||||
'TestHola'
|
||||
'Other'
|
||||
)
|
||||
OnItemClick = chkTestsItemClick
|
||||
TabOrder = 3
|
||||
@ -64,13 +64,22 @@ object Form1: TForm1
|
||||
}
|
||||
end
|
||||
object btnPrintAll: TButton
|
||||
Left = 548
|
||||
Left = 546
|
||||
Height = 25
|
||||
Top = 192
|
||||
Top = 236
|
||||
Width = 75
|
||||
Caption = 'btnPrintAll'
|
||||
TabOrder = 4
|
||||
end
|
||||
object btnOther: TButton
|
||||
Left = 548
|
||||
Height = 25
|
||||
Top = 100
|
||||
Width = 75
|
||||
Caption = 'btnOther'
|
||||
OnClick = btnOtherClick
|
||||
TabOrder = 5
|
||||
end
|
||||
object PrintDialog1: TPrintDialog
|
||||
left = 129
|
||||
top = 28
|
||||
|
@ -17,9 +17,11 @@ type
|
||||
btn24217: TButton;
|
||||
btn19435: TButton;
|
||||
btnPrintAll: TButton;
|
||||
btnOther: TButton;
|
||||
chkTests: TCheckGroup;
|
||||
PrintDialog1: TPrintDialog;
|
||||
procedure btn19435Click(Sender: TObject);
|
||||
procedure btnOtherClick(Sender: TObject);
|
||||
procedure Button1Click(Sender: TObject);
|
||||
procedure btn24217Click(Sender: TObject);
|
||||
procedure chkTestsItemClick(Sender: TObject; Index: integer);
|
||||
@ -27,7 +29,7 @@ type
|
||||
private
|
||||
procedure Draw19435(cnv: TCanvas; XDPI,YDPI: Integer);
|
||||
procedure Draw24217(cnv: TCanvas; XDPI,YDPI: Integer);
|
||||
procedure DrawTestBoth(cnv: TCanvas; XDPI,YDPI: Integer);
|
||||
procedure DrawOther(cnv: TCanvas; XDPI,YDPI: Integer);
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
@ -74,6 +76,21 @@ begin
|
||||
CairoPrinter.Free;
|
||||
end;
|
||||
|
||||
procedure TForm1.btnOtherClick(Sender: TObject);
|
||||
var
|
||||
CairoPrinter: TCairoFilePrinter;
|
||||
begin
|
||||
CairoPrinter := TCairoFilePrinter.create;
|
||||
//CairoPrinter.CairoBackend:=cbPS;
|
||||
CairoPrinter.CairoBackend:=cbPDF;
|
||||
CairoPrinter.FileName:='other';
|
||||
CairoPrinter.BeginDoc;
|
||||
with CairoPrinter do
|
||||
DrawOther(Canvas, XDPI, YDPI);
|
||||
CairoPrinter.EndDoc;
|
||||
CairoPrinter.Free;
|
||||
end;
|
||||
|
||||
procedure TForm1.btn24217Click(Sender: TObject);
|
||||
var
|
||||
CairoPrinter: TCairoFilePrinter;
|
||||
@ -102,7 +119,7 @@ begin
|
||||
ResY := ResX;
|
||||
if chkTests.Checked[0] then Draw24217(Canvas, ResX, ResY);
|
||||
if chkTests.Checked[1] then Draw19435(Canvas, ResX, ResY);
|
||||
if chkTests.Checked[2] then DrawTestBoth(Canvas, ResX, ResY);
|
||||
if chkTests.Checked[2] then DrawOther(Canvas, ResX, ResY);
|
||||
end;
|
||||
|
||||
procedure TForm1.Draw19435(cnv: TCanvas; XDPI, YDPI: Integer);
|
||||
@ -212,12 +229,20 @@ begin
|
||||
|
||||
end;
|
||||
|
||||
procedure TForm1.DrawTestBoth(cnv: TCanvas; XDPI, YDPI: Integer);
|
||||
procedure TForm1.DrawOther(cnv: TCanvas; XDPI, YDPI: Integer);
|
||||
const
|
||||
CTEXT='Hola';
|
||||
Par =
|
||||
'Uno' + LineEnding+
|
||||
'noU' + LineEnding+
|
||||
'oUn' + LineEnding+
|
||||
'01.' + LineEnding+
|
||||
'1.0' + LineEnding+
|
||||
'.01';
|
||||
var
|
||||
R: TRect;
|
||||
sz: TSize;
|
||||
style: TTextStyle;
|
||||
begin
|
||||
|
||||
R := Rect(XDPI, YDPI*2, XDPI*3, round(YDPI*2.5));
|
||||
@ -242,6 +267,19 @@ begin
|
||||
cnv.TextOut(R.Left, R.Top, 'Line1'); OffsetRect(R, 0, sz.cy);
|
||||
cnv.TextOut(R.Left, R.Top, 'Line2'); OffsetRect(R, 0, sz.cy);
|
||||
cnv.TextOut(R.Left, R.Top, 'Line3'); OffsetRect(R, 0, sz.cy);
|
||||
|
||||
R := Rect(XDPI*4, YDPI*2, Round(XDPI*6), round(YDPI*6));
|
||||
cnv.Font.Name := 'Arial';
|
||||
cnv.Font.Size := 40;
|
||||
cnv.Font.Color := clGreen;
|
||||
cnv.Brush.Style := bsClear;
|
||||
cnv.Pen.Color := clSilver;
|
||||
style := cnv.TextStyle;
|
||||
style.SingleLine := false;
|
||||
style.Alignment := taRightJustify;
|
||||
cnv.TextStyle := style;
|
||||
cnv.TextRect(R, R.Left, R.Top, Par);
|
||||
cnv.Rectangle(R);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user