1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
| unit u_lazfreetype;
{$MODE objfpc}{$H+}
interface
uses
Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs;
type
{ TForm1 }
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormPaint(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
uses
BGRABitmap, BGRABitmapTypes, BGRAFreeType, BGRATextFX,
BGRAGradients,
LazFreeTypeFontCollection;
const
CHARS: array[0..9] of string = (
'!""""""""#',
'$tMvWlVmT%',
'$OoOoOoOo%',
'$ + + + +%',
'$+ +wL + %',
'$ + Qk+ +%',
'$+ + + + %',
'$pPpPpPpP%',
'$RnBqKbNr%',
'/(((((((()'
);
var
Bitmap: TBGRABitmap;
Renderer: TBGRATextEffectFontRenderer;
FFontCollection: TFreeTypeFontCollection;
{ TForm1 }
procedure TForm1.FormCreate(Sender: TObject);
begin
FFontCollection := TFreeTypeFontCollection.Create;
FFontCollection.AddFile('arial.ttf');
FFontCollection.AddFile('alfoches.ttf');
FFontCollection.AddFile('condfont.ttf');
SetDefaultFreeTypeFontCollection(FFontCollection);
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
SetDefaultFreeTypeFontCollection(nil);
FreeAndNil(FFontCollection);
end;
procedure TForm1.FormPaint(Sender: TObject);
var
bmp: TBGRABitmap;
renderer: TBGRAFreeTypeFontRenderer;
row: integer;
begin
bmp := TBGRABitmap.Create(ClientWidth, ClientHeight, ColorToRGB(clBtnFace));
renderer := TBGRAFreeTypeFontRenderer.Create;
renderer.ShadowVisible := True;
bmp.FontRenderer := renderer;
//bmp.FontName := 'Chess Alfonso-X';
bmp.FontName := 'Chess Condal';
bmp.FontFullHeight := 40;
bmp.FontQuality := fqFineClearTypeRGB;
for row := 0 to 9 do
bmp.TextOut(0, 40 * row, CHARS[row], BGRABlack);
bmp.Draw(Canvas, 0, 0);
bmp.Free;
end;
end. |
Partager