mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-05 15:18:16 +02:00
LazFreeType: Improve example to use DrawTextRect. Based on code by "circular"
git-svn-id: trunk@40109 -
This commit is contained in:
parent
56537d3db2
commit
ba96ce8bdd
@ -1,32 +1,33 @@
|
||||
object Form1: TForm1
|
||||
Left = 238
|
||||
Left = 362
|
||||
Height = 240
|
||||
Top = 161
|
||||
Width = 344
|
||||
Top = 172
|
||||
Width = 441
|
||||
Align = alBottom
|
||||
Caption = 'Form1'
|
||||
Caption = 'Test LazFreeType'
|
||||
ClientHeight = 240
|
||||
ClientWidth = 344
|
||||
ClientWidth = 441
|
||||
KeyPreview = True
|
||||
OnCreate = FormCreate
|
||||
OnDestroy = FormDestroy
|
||||
OnMouseMove = FormMouseMove
|
||||
OnPaint = FormPaint
|
||||
Position = poDefault
|
||||
LCLVersion = '1.1'
|
||||
object Panel_Option: TPanel
|
||||
Left = 0
|
||||
Height = 40
|
||||
Top = 200
|
||||
Width = 344
|
||||
Width = 441
|
||||
Align = alBottom
|
||||
ClientHeight = 40
|
||||
ClientWidth = 344
|
||||
ClientWidth = 441
|
||||
TabOrder = 0
|
||||
object TrackBar_Size: TTrackBar
|
||||
Left = 96
|
||||
Height = 25
|
||||
Top = 8
|
||||
Width = 186
|
||||
Width = 243
|
||||
Frequency = 0
|
||||
Max = 300
|
||||
Min = 1
|
||||
@ -36,7 +37,7 @@ object Form1: TForm1
|
||||
TabOrder = 0
|
||||
end
|
||||
object LFontSize: TLabel
|
||||
Left = 287
|
||||
Left = 336
|
||||
Height = 16
|
||||
Top = 12
|
||||
Width = 51
|
||||
@ -65,5 +66,15 @@ object Form1: TForm1
|
||||
TabOrder = 1
|
||||
Value = 1
|
||||
end
|
||||
object CheckBox_Rect: TCheckBox
|
||||
Left = 393
|
||||
Height = 17
|
||||
Top = 10
|
||||
Width = 42
|
||||
Anchors = [akTop, akRight]
|
||||
Caption = 'Rect'
|
||||
OnChange = CheckBox_RectChange
|
||||
TabOrder = 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,11 +19,13 @@ type
|
||||
{ TForm1 }
|
||||
|
||||
TForm1 = class(TForm)
|
||||
CheckBox_Rect: TCheckBox;
|
||||
Label1: TLabel;
|
||||
LFontSize: TLabel;
|
||||
Panel_Option: TPanel;
|
||||
SpinEdit_Zoom: TSpinEdit;
|
||||
TrackBar_Size: TTrackBar;
|
||||
procedure CheckBox_RectChange(Sender: TObject);
|
||||
procedure FormCreate(Sender: TObject);
|
||||
procedure FormDestroy(Sender: TObject);
|
||||
procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
|
||||
@ -87,6 +89,11 @@ begin
|
||||
UpdateSizeLabel;
|
||||
end;
|
||||
|
||||
procedure TForm1.CheckBox_RectChange(Sender: TObject);
|
||||
begin
|
||||
invalidate;
|
||||
end;
|
||||
|
||||
procedure TForm1.FormDestroy(Sender: TObject);
|
||||
begin
|
||||
ftFont1.Free;
|
||||
@ -113,7 +120,7 @@ begin
|
||||
end;
|
||||
|
||||
procedure TForm1.FormPaint(Sender: TObject);
|
||||
const testtext = 'Enjoy'+LineEnding+'and play!';
|
||||
const testtext = 'The quick brown fox jumps over the lazy dog';
|
||||
var bmp: TBitmap;
|
||||
tx,ty: integer;
|
||||
p: array of TCharPosition;
|
||||
@ -142,23 +149,35 @@ begin
|
||||
ftFont1.ClearType := true;
|
||||
ftFont1.Quality := grqHighQuality;
|
||||
ftFont1.SmallLinePadding := false;
|
||||
drawer.DrawText(ftFont1.Information[ftiFullName], ftFont1, x, y, colBlack, [ftaRight, ftaBottom]);
|
||||
if CheckBox_Rect.Checked then
|
||||
drawer.DrawTextRect(testtext, ftFont1, 0,0, tx/3,ty, colBlack, [ftaLeft, ftaBottom])
|
||||
else
|
||||
drawer.DrawText(ftFont1.Information[ftiFullName], ftFont1, x, y, colBlack, [ftaRight, ftaBottom]);
|
||||
|
||||
ftFont2.Hinted := false;
|
||||
ftFont2.ClearType := false;
|
||||
ftFont2.Quality := grqHighQuality;
|
||||
drawer.DrawText(ftFont2.Information[ftiFullName], ftFont2, x, y, colRed, 192, [ftaCenter, ftaBaseline]);
|
||||
if CheckBox_Rect.Checked then
|
||||
drawer.DrawTextRect(testtext, ftFont2, tx/3,0, 2*tx/3,ty, colRed, [ftaCenter, ftaVerticalCenter])
|
||||
else
|
||||
drawer.DrawText(ftFont2.Information[ftiFullName], ftFont2, x, y, colRed, 192, [ftaCenter, ftaBaseline]);
|
||||
|
||||
ftFont3.Hinted := false;
|
||||
ftFont3.ClearType := false;
|
||||
ftFont3.Quality := grqMonochrome;
|
||||
drawer.DrawText(ftFont3.Information[ftiFullName]+' '+ftFont3.VersionNumber, ftFont3, x, y, colBlack, 128, [ftaLeft, ftaTop]);
|
||||
if CheckBox_Rect.Checked then
|
||||
drawer.DrawTextRect(testtext, ftFont3, 2*tx/3,0, tx,ty, colBlue, [ftaRight, ftaTop])
|
||||
else
|
||||
drawer.DrawText(ftFont3.Information[ftiFullName]+' '+ftFont3.VersionNumber, ftFont3, x, y, colBlack, 128, [ftaLeft, ftaTop]);
|
||||
|
||||
p := ftFont1.CharsPosition(ftFont1.Information[ftiFullName],[ftaRight, ftaBottom]);
|
||||
for i := 0 to high(p) do
|
||||
if not CheckBox_Rect.Checked then
|
||||
begin
|
||||
drawer.DrawVertLine(round(x+p[i].x),round(y+p[i].yTop),round(y+p[i].yBottom), TColorToFPColor(clBlue));
|
||||
drawer.DrawHorizLine(round(x+p[i].x),round(y+p[i].yBase),round(x+p[i].x+p[i].width), TColorToFPColor(clBlue));
|
||||
p := ftFont1.CharsPosition(ftFont1.Information[ftiFullName],[ftaRight, ftaBottom]);
|
||||
for i := 0 to high(p) do
|
||||
begin
|
||||
drawer.DrawVertLine(round(x+p[i].x),round(y+p[i].yTop),round(y+p[i].yBottom), TColorToFPColor(clBlue));
|
||||
drawer.DrawHorizLine(round(x+p[i].x),round(y+p[i].yBase),round(x+p[i].x+p[i].width), TColorToFPColor(clBlue));
|
||||
end;
|
||||
end;
|
||||
|
||||
EndTime := Now;
|
||||
|
Loading…
Reference in New Issue
Block a user