-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSDIMAIN.PAS
More file actions
403 lines (360 loc) · 11.8 KB
/
SDIMAIN.PAS
File metadata and controls
403 lines (360 loc) · 11.8 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
unit SDIMAIN;
interface
uses Winapi.Windows, System.Classes, Vcl.Graphics, Vcl.Forms, Vcl.Controls,
Vcl.Menus, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Buttons, Vcl.ExtCtrls, Vcl.ComCtrls,
Vcl.ImgList, Vcl.StdActns, Vcl.ActnList, Vcl.ToolWin, System.ImageList,
System.Actions, Vcl.Samples.Spin, Vcl.Grids, SysUtils, Vcl.CheckLst, StrUtils,
Vcl.DBActns;
type
TSDIAppForm = class(TForm)
OpenDialog: TOpenDialog;
SaveDialog: TSaveDialog;
ToolBar1: TToolBar;
ActionList1: TActionList;
FileNew1: TAction;
FileOpen1: TAction;
FileSave1: TAction;
FileSaveAs1: TAction;
FileExit1: TAction;
EditCut1: TEditCut;
EditCopy1: TEditCopy;
EditPaste1: TEditPaste;
HelpAbout1: TAction;
StatusBar: TStatusBar;
ImageList1: TImageList;
MainMenu1: TMainMenu;
File1: TMenuItem;
FileNewItem: TMenuItem;
FileOpenItem: TMenuItem;
FileSaveItem: TMenuItem;
FileSaveAsItem: TMenuItem;
N1: TMenuItem;
FileExitItem: TMenuItem;
Edit1: TMenuItem;
CutItem: TMenuItem;
CopyItem: TMenuItem;
PasteItem: TMenuItem;
Help1: TMenuItem;
HelpAboutItem: TMenuItem;
PC: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
Memo1: TMemo;
TabSheet3: TTabSheet;
DatasetInsert1: TDataSetInsert;
ToolButton8: TToolButton;
Memo2: TMemo;
PopupMenu1: TPopupMenu;
N2: TMenuItem;
procedure FileNew1Execute(Sender: TObject);
procedure FileOpen1Execute(Sender: TObject);
procedure FileSave1Execute(Sender: TObject);
procedure FileExit1Execute(Sender: TObject);
procedure HelpAbout1Execute(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure CBLClickCheck(Sender: TObject);
procedure ToolButton8Click(Sender: TObject);
procedure PCContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
procedure N2Click(Sender: TObject);
private
{ Private declarations }
FrmCnt:Integer;
procedure NeedMakeProg(Sender: TObject);
procedure InsertFrame(PageIndex:Integer);
public
{ Public declarations }
procedure MakeProg;
end;
var
SDIAppForm: TSDIAppForm;
implementation
uses About, FontFrame;
{$R *.dfm}
procedure TSDIAppForm.FileNew1Execute(Sender: TObject);
begin
{ Do nothing }
end;
procedure TSDIAppForm.FileOpen1Execute(Sender: TObject);
begin
OpenDialog.Execute;
end;
procedure TSDIAppForm.FileSave1Execute(Sender: TObject);
begin
SaveDialog.Execute;
end;
procedure TSDIAppForm.FormShow(Sender: TObject);
begin
PC.TabIndex:=0;
InsertFrame(0);
end;
procedure TSDIAppForm.Button1Click(Sender: TObject);
begin
MakeProg;
end;
procedure TSDIAppForm.Button3Click(Sender: TObject);
begin
MakeProg;
end;
procedure TSDIAppForm.CBLClickCheck(Sender: TObject);
begin
MakeProg;
end;
procedure TSDIAppForm.FileExit1Execute(Sender: TObject);
begin
Close;
end;
procedure TSDIAppForm.HelpAbout1Execute(Sender: TObject);
begin
AboutBox.ShowModal;
end;
procedure TSDIAppForm.InsertFrame(PageIndex: Integer);
var Frm:TFontFrm;
begin
Frm:=TFontFrm.Create(Self);
FRM.Name:=Frm.Name+IntToStr(FrmCnt);
FRM.Parent:=PC.Pages[PageIndex];
FRM.InitFont;
FRM.OnNeedMakeProg:=NeedMakeProg;
FrmCnt:=FrmCnt+1;
end;
procedure TSDIAppForm.MakeProg;
var S,FntNm,Comment:String;
p,a,x,y,m,size,FntNmL:Integer;
b,bc,cnt:word;
L:TLetter;
LS,LI:TStrings;
indexes:array [0..224] of word;
// symbols:array [0..223] of integer;
widths:array [0..223] of byte;
ipoint:byte;
CBL:TCheckListBox;
Fnt:TFont;
Frm:TFontFrm;
begin
memo1.Lines.Clear;
memo1.Lines.Add('/**');
memo1.Lines.Add(' ******************************************************************************');
memo1.Lines.Add(' * @file : varyfonts.c');
memo1.Lines.Add(' * @brief : fonts descriptions for st7735 and ssd1306');
memo1.Lines.Add(' ******************************************************************************');
memo1.Lines.Add(' * @attention');
memo1.Lines.Add(' *');
memo1.Lines.Add(' * "Äîì ñâîáîäíûé, æèâèòå, êòî õîòèòå" (ñ) Ïðîñòîêâàøèíî ))');
memo1.Lines.Add(' * ');
memo1.Lines.Add(' * Created on: '+DateToStr(Now));
memo1.Lines.Add(' * Author: FontGenerator;');
memo1.Lines.Add(' ******************************************************************************');
memo1.Lines.Add(' */');
memo1.Lines.Add('');
memo1.Lines.Add('#include "varyfonts.h"');
memo1.Lines.Add('#include "string.h"');
memo1.Lines.Add('');
LS:=TStringList.Create;
LI:=TStringList.Create;
FntNmL:=0;
try
for p := 0 to PC.PageCount-1 do begin
if PC.Pages[p].Tag=0 then begin
LI.Clear;
FRM:=TFontFrm(PC.Pages[p].Controls[0]);
CBL:=Frm.CBL;
FntNm:=FRM.FontName;
FntNm:=ReplaceStr(FntNm,' ','_');
FntNm:=ReplaceStr(FntNm,',','');
if Length(FntNm)>FntNmL then FntNmL:=Length(FntNm);
S:='static uint16_t Font_'+FntNm+' [] = {';
LS.Add(' {"'+FntNm+'", '+IntToStr(FRM.MaxH)+', VFontMetrics_'+FntNm+', Font_'+FntNM+'},');
// {"Tahoma_8",13,FontWidths_Tahoma_8,FontOffsets_Tahoma_8,Font_Tahoma_8},
// {"Tahoma_8_bold",13,FontWidths_Tahoma_8_bold,FontOffsets_Tahoma_8_bold,Font_Tahoma_8_bold},
Memo1.Lines.Add(S);
ipoint:=0;
indexes[0]:=0;
indexes[1]:=0;
//symbols[0]:=0;
for a := 0 to CBL.Count-1 do begin
widths[a]:=0;
if CBL.Checked[a] then begin
indexes[ipoint+1]:=indexes[ipoint];
L:=TLetter(FRM.List.objects[a]);
widths[a]:=L.Width;
S:='';
b:=0;
bc:=32768;
cnt:=0;
for y := 0 to FRM.MaxH-1 do begin
for x := 0 to L.Width-1 do begin
if L.Matrix[x][y]=clBlack then b:=b + bc;
bc:=Trunc(bc/2);
if bc=0 then begin
bc:=32768;
S:=S+'0x'+IntToHex(b)+', ';
b:=0;
cnt:=cnt+1;
// indexes[ipoint+1]:=indexes[ipoint+1]+1;
end;
end;
end;
if bc<>32768 then begin
S:=S+'0x'+IntToHex(b)+', ';
cnt:=cnt+1;
// indexes[ipoint+1]:=indexes[ipoint+1]+1;
end;
indexes[ipoint+1]:=indexes[ipoint+1]+cnt;
if a=0 then Comment:=' // '+IntToStr(a+32)+' sp'
else if a=60 then Comment:=' /* '+IntToStr(a+32)+' \ */'
else Comment:=' // '+IntToStr(a+32)+' '+AnsiChar(a+32);
LI.Add(' {'+IntToStr(widths[a])+', '+IntToStr(cnt)+', '+IntToStr(indexes[ipoint])+'}, '+Comment);
S:=S+Comment+' // offset '+IntToStr(Indexes[ipoint])+' 0x'+IntToHex(indexes[ipoint]);
Memo1.Lines.Add(S);
ipoint:=ipoint+1;
end else begin
//symbols[a]:=-1;
LI.Add(' {0,0,0}, // no symbol');
end;
end;
Memo1.Lines.Add('};');
Memo1.Lines.Add('');
Memo1.Lines.Add('VLetterMetrics VFontMetrics_'+FntNm+'[]={');
Memo1.Lines.AddStrings(LI);
memo1.Lines.Add('};');
Memo1.Lines.Add('');
// Memo1.Lines.Add('// bytes '+IntToStr(Cnt*2));
Memo1.Lines.Add('');
// S:='static const uint8_t FontWidths_'+FntNm+' [] = {';
// Memo1.Lines.Add(S);
// for a := 0 to 223 do begin
// S:='0x'+IntToHex(widths[a])+', ';
// if a=0 then S:=S+' // '+IntToStr(a+32)+' sp'
// else if a=60 then S:=S+' /* '+IntToStr(a+32)+' \ */'
// else S:=S+' // '+IntToStr(a+32)+' '+AnsiChar(a+32);
// Memo1.Lines.Add(S);
// end;
// Memo1.Lines.Add('};');
// Memo1.Lines.Add('');
// S:='static const uint16_t FontOffsets_'+FntNm+' [] = {';
// Memo1.Lines.Add(S);
// ipoint:=0;
// for a := 0 to CBL.Count-1 do begin
// if CBL.Checked[a] then begin
// S:='0x'+IntToHex(indexes[ipoint])+', ';
// if a=0 then S:=S+' // '+IntToStr(a+32)+' sp'
// else if a=60 then S:=S+' /* '+IntToStr(a+32)+' \ */'
// else S:=S+' // '+IntToStr(a+32)+' '+AnsiChar(a+32);
// Memo1.Lines.Add(S);
// ipoint:=ipoint+1;
// end;
// end;
// Memo1.Lines.Add('};');
end;
end;
memo1.Lines.Add('VFontDef VFontList[] = {');
Memo1.Lines.AddStrings(LS);
memo1.Lines.Add(' {NULL,0,0,0},');
memo1.Lines.Add('};');
memo1.Lines.Add('');
memo1.Lines.Add('VFontDef GetVFont(char *name){');
memo1.Lines.Add(' uint8_t i = 0;');
memo1.Lines.Add(' VFontDef res = {NULL,0,0,0};');
memo1.Lines.Add(' for(;;){');
memo1.Lines.Add(' if(VFontList[i].Name==NULL){');
memo1.Lines.Add(' break;');
memo1.Lines.Add(' }');
memo1.Lines.Add(' if(strcmp(name,VFontList[i].Name)==0){');
memo1.Lines.Add(' res=VFontList[i];');
memo1.Lines.Add(' break;');
memo1.Lines.Add(' }');
memo1.Lines.Add(' i++;');
memo1.Lines.Add(' }');
memo1.Lines.Add(' return res;');
memo1.Lines.Add('}');
memo1.Lines.Add('');
memo2.Lines.Clear;
memo2.Lines.Add('');
memo2.Lines.Add('/*');
memo2.Lines.Add(' * varyfonts.h');
memo2.Lines.Add(' *');
memo2.Lines.Add(' * Created on: '+DateToStr(Now));
memo2.Lines.Add(' * Author: FontGenerator');
memo2.Lines.Add(' */');
memo2.Lines.Add('');
memo2.Lines.Add('#ifndef VARYFONTS_H_');
memo2.Lines.Add('#define VARYFONTS_H_');
memo2.Lines.Add('');
memo2.Lines.Add('#include "stdint.h"');
memo2.Lines.Add('');
memo2.Lines.Add('');
memo2.Lines.Add('typedef struct {');
memo2.Lines.Add(' uint8_t Width; // øèðèíà ñèìâîëà â ïèêñåëÿõ');
memo2.Lines.Add(' uint8_t Size; // ðàçìåð äàííûõ â ñëîâàõ');
memo2.Lines.Add(' uint16_t Offset; // ñìåùåíèå ñèìâîëà â ñëîâàõ îò íà÷àëà ìàññèâà äàííûõ');
memo2.Lines.Add('} VLetterMetrics;');
memo2.Lines.Add('');
memo2.Lines.Add('typedef struct {');
memo2.Lines.Add(' char Name['+IntToStr(FntNmL+1)+']; // íàèìåíîâàíèå øðèôòà');
memo2.Lines.Add(' uint8_t Height; // âûñîòà â ïèêñåëÿõ');
memo2.Lines.Add(' VLetterMetrics * Metrics; // ññûëêà íà ìåòðèêè ñèìâîëîâ');
memo2.Lines.Add(' uint16_t * Font; // ññûëêà íà äàííûå øðèôòà');
memo2.Lines.Add('} VFontDef;');
memo2.Lines.Add('');
memo2.Lines.Add('VFontDef GetVFont(char *name);');
memo2.Lines.Add('');
memo2.Lines.Add('#endif /* VARYFONTS_H_ */');
finally
LS.Free;
LI.Free;
end;
end;
procedure TSDIAppForm.N2Click(Sender: TObject);
var x,c:Integer;
begin
if PC.ActivePage.Tag=0 then begin
c:=0;
for x := 0 to PC.PageCount-1 do
if PC.Pages[x].Tag=0 then c:=c+1;
if c>1 then begin
if MessageDlg('Çàêðûòü òåêóùóþ âêëàäêó?',
mtConfirmation, [mbYes, mbNo], 0, mbYes) = mrYes then begin
PC.ActivePage.Destroy;
if PC.ActivePageIndex<>0 then PC.ActivePageIndex:=PC.ActivePageIndex-1;
MakeProg;
end;
end;
end;
end;
procedure TSDIAppForm.NeedMakeProg(Sender: TObject);
var p:Integer;
FRM:TFontFrm;
begin
for p := 0 to PC.PageCount-1 do begin
if PC.Pages[p].Tag=0 then begin
FRM:=TFontFrm(PC.Pages[p].Controls[0]);
if not FRM.Button1.Enabled then PC.Pages[p].Caption:=FRM.FontName;
end;
end;
MakeProg;
end;
procedure TSDIAppForm.PCContextPopup(Sender: TObject; MousePos: TPoint;
var Handled: Boolean);
var R:TRect;
begin
R:=PC.TabRect(PC.ActivePageIndex);
if(MousePos.Y>R.Bottom) then
Handled:=true;
end;
procedure TSDIAppForm.ToolButton8Click(Sender: TObject);
var Tab:TTabSheet;
x:Integer;
begin
Tab:=TTabSheet.Create(PC);
Tab.PageControl:=PC;
Tab.Caption:='Øðèôò';
for x := PC.PageCount-1 downto 0 do begin
if PC.Pages[x].Tag=-2 then PC.Pages[x].PageIndex:=PC.PageCount-1;
if PC.Pages[x].Tag=-1 then PC.Pages[x].PageIndex:=PC.PageCount-2;
end;
InsertFrame(Tab.PageIndex);
end;
end.