-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathzint_render_wmf.pas
85 lines (66 loc) · 1.72 KB
/
zint_render_wmf.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
unit zint_render_wmf;
{
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
}
{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
interface
uses
zint, zint_render_canvas, Graphics, SysUtils;
type
TZintRenderTargetWMF = class(TZintRenderTargetCanvas)
protected
FMetafile : TMetafile;
procedure SetWMF(const Value: TMetafile); virtual;
function CalcTextWidth(const AParams : TZintCalcTextWidthParams) : Single; override;
procedure Inflate(const ANewWidth, ANewHeight : Single); override;
procedure CreateCanvas;
public
procedure Render(ASymbol : TZintSymbol); override;
property Metafile : TMetafile read FMetafile write SetWMF;
end;
implementation
{ TZintRenderTargetWMF }
function TZintRenderTargetWMF.CalcTextWidth(
const AParams: TZintCalcTextWidthParams): Single;
begin
Result:=inherited CalcTextWidth(AParams);
if Length(AParams.Text)=1 then
Result:=Result * 2;
end;
procedure TZintRenderTargetWMF.Inflate(const ANewWidth, ANewHeight: Single);
begin
if Assigned(FCanvas) then
FreeAndNil(FCanvas);
FMetafile.SetSize(Round(ANewWidth), Round(ANewHeight));
CreateCanvas;
end;
procedure TZintRenderTargetWMF.CreateCanvas;
begin
FCanvas:=TMetafileCanvas.Create(FMetafile, 0);
FCanvas.Font.Assign(FFont);
end;
procedure TZintRenderTargetWMF.Render(ASymbol: TZintSymbol);
begin
CreateCanvas;
try
inherited;
finally
FCanvas.Free;
end;
end;
procedure TZintRenderTargetWMF.SetWMF(const Value: TMetafile);
begin
if Assigned(Value) then
begin
WidthDesired := Value.Width;
HeightDesired := Value.Height;
end;
FMetafile := Value;
end;
end.