-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
zint_render_lmf.pas
100 lines (79 loc) · 2.11 KB
/
zint_render_lmf.pas
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
98
99
100
unit zint_render_lmf;
{
Based on Zint (done by Robin Stuart and the Zint team)
http://github.com/zint/zint
Translation by TheUnknownOnes
http://theunknownones.net
License: Apache License 2.0
}
{$mode objfpc}{$H+}
interface
uses
zint, zint_render_canvas, Graphics, zint_lmf;
type
{ TZintRenderTargetLMF }
TZintRenderTargetLMF = class(TZintRenderTargetCanvas)
private
procedure SetMetafile(AValue: TlmfImage);
protected
FMetafile : TlmfImage;
procedure Inflate(const ANewWidth, ANewHeight : Single); override;
procedure CreateCanvas;
procedure DrawText(const AParams: TZintDrawTextParams); override;
public
procedure Render(ASymbol : TZintSymbol); override;
property Metafile : TlmfImage read FMetafile write SetMetafile;
end;
implementation
uses
Types, Classes;
{ TZintRenderTargetLMF }
procedure TZintRenderTargetLMF.SetMetafile(AValue: TlmfImage);
begin
if Assigned(AValue) then
begin
WidthDesired := AValue.Width;
HeightDesired := AValue.Height;
end;
FMetafile := AValue;
end;
procedure TZintRenderTargetLMF.Inflate(const ANewWidth, ANewHeight: Single);
begin
if Assigned(FCanvas) then
FCanvas.Free;
FMetafile.Width := Round(ANewWidth);
FMetafile.Height := Round(ANewHeight);
CreateCanvas;
end;
procedure TZintRenderTargetLMF.CreateCanvas;
begin
FCanvas := TlmfCanvas.Create(FMetafile);
FCanvas.Font.Assign(FFont);
end;
procedure TZintRenderTargetLMF.DrawText(const AParams: TZintDrawTextParams);
var
r : TRect;
ts : TTextStyle;
w : Integer;
begin
//because the lmf ignores the Alignment, we have to align it manually
r.Left := Round(AParams.X);
r.Top := Round(AParams.Y);
r.Right := Round(AParams.X + AParams.Width);
r.Bottom := Round(AParams.Y + AParams.Height);
FCanvas.Brush.Style := bsClear;
ts.Layout := tlCenter;
ts.SystemFont := False;
w := FCanvas.TextWidth(AParams.Text);
FCanvas.TextRect(r, r.Left + Round((AParams.Width - w) / 2), r.Top, AParams.Text, ts);
end;
procedure TZintRenderTargetLMF.Render(ASymbol: TZintSymbol);
begin
CreateCanvas;
try
inherited;
finally
FCanvas.Free;
end;
end;
end.