-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExport.pas
164 lines (135 loc) · 4.41 KB
/
Export.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
UNIT Export;
// ============================================================================
INTERFACE
USES
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Buttons, ExtCtrls, ExtDlgs, ovceditf, ovcedpop, ovcedsld;
type
TdlgJPEGExport = class(TForm)
gbSample: TGroupBox;
lblFontName: TLabel;
cbBold: TSpeedButton;
cbItalic: TSpeedButton;
cbUnderline: TSpeedButton;
cbStrikeout: TSpeedButton;
eSample: TEdit;
rgExportAs: TRadioGroup;
bExport: TButton;
bClose: TButton;
dlgSavePicture: TSavePictureDialog;
osePointSize: TOvcSliderEdit;
procedure cbBoldClick(Sender: TObject);
procedure cbItalicClick(Sender: TObject);
procedure cbUnderlineClick(Sender: TObject);
procedure cbStrikeoutClick(Sender: TObject);
procedure osePointSizeChange(Sender: TObject);
procedure bExportClick(Sender: TObject);
private
public
procedure Execute (fntName: String);
end;
var
dlgJPEGExport: TdlgJPEGExport;
// ============================================================================
IMPLEMENTATION
USES
Jpeg;
{$R *.DFM}
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.Execute (fntName: String);
begin
lblFontName.Caption := fntName;
eSample.Font.Name := fntName;
eSample.Font.Size := osePointSize.AsInteger;
eSample.Font.Style := [];
if cbBold.Down then
eSample.Font.Style := eSample.Font.Style + [fsBold];
if cbItalic.Down then
eSample.Font.Style := eSample.Font.Style + [fsItalic];
if cbUnderline.Down then
eSample.Font.Style := eSample.Font.Style + [fsUnderline];
if cbStrikeout.Down then
eSample.Font.Style := eSample.Font.Style + [fsStrikeout];
if eSample.Text = '' then
eSample.Text := 'Hello';
ShowModal
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.cbBoldClick(Sender: TObject);
begin
if cbBold.Down then
eSample.Font.Style := eSample.Font.Style + [fsBold]
else
eSample.Font.Style := eSample.Font.Style - [fsBold]
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.cbItalicClick(Sender: TObject);
begin
if cbItalic.Down then
eSample.Font.Style := eSample.Font.Style + [fsItalic]
else
eSample.Font.Style := eSample.Font.Style - [fsItalic]
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.cbUnderlineClick(Sender: TObject);
begin
if cbUnderline.Down then
eSample.Font.Style := eSample.Font.Style + [fsUnderline]
else
eSample.Font.Style := eSample.Font.Style - [fsUnderline]
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.cbStrikeoutClick(Sender: TObject);
begin
if cbStrikeout.Down then
eSample.Font.Style := eSample.Font.Style + [fsStrikeout]
else
eSample.Font.Style := eSample.Font.Style - [fsStrikeout]
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.osePointSizeChange(Sender: TObject);
begin
eSample.Font.Size := osePointSize.AsInteger
end;
//------------------------------------------------------------------------------
procedure TdlgJPEGExport.bExportClick(Sender: TObject);
var
theName, ext: String;
MyBMP: TBitmap;
MyJPEG: TJPEGImage;
begin
if rgExportAs.ItemIndex = 0 then
dlgSavePicture.DefaultExt := '.bmp'
else
dlgSavePicture.DefaultExt := '.jpg';
if dlgSavePicture.Execute then
begin
theName := dlgSavePicture.FileName;
MyBMP := TBitmap.Create;
with MyBMP do begin
Canvas.Font.Assign (eSample.Font);
Width := Canvas.TextWidth (eSample.Text);
Height := Canvas.TextHeight (eSample.Text);
Canvas.TextOut (0, 0, eSample.Text)
end;
ext := lowercase (ExtractFileExt (theName));
try
if (ext = '.jpg') or (ext = '.jpeg') then
begin
MyJPEG := TJPEGImage.Create;
with MyJPEG do
begin
Assign (MyBMP);
SaveToFile (theName);
Free
end
end
else
MyBMP.SaveToFile (theName);
except
ShowMessage ('Could not save to ' + theName)
end;
MyBMP.Free
end
end;
END.