-
Notifications
You must be signed in to change notification settings - Fork 0
/
ufrmmain.pas
1104 lines (1014 loc) · 33.7 KB
/
ufrmmain.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
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
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit ufrmmain;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls, lcltype, Clipbrd,
ExtCtrls, Buttons, FileCtrl, ExtDlgs, IniFiles,
ActnList, ComCtrls,
uglyphdata, ucharacterinfo,
utools;
//icons by Icons8 (https://icons8.com)
type
{ TfrmMain }
TfrmMain = class(TForm)
actCopy: TAction;
actCut: TAction;
actPaste: TAction;
ActionList1: TActionList;
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
BitBtn3: TBitBtn;
BitBtn4: TBitBtn;
BitBtn5: TBitBtn;
BitBtn6: TBitBtn;
cboGardiner: TComboBox;
FileListBox1: TFileListBox;
ImageList1: TImageList;
MenuItem1: TMenuItem;
mnuEditDirectionLtR: TMenuItem;
mnuEditDirectionRtL: TMenuItem;
Separator6: TMenuItem;
MenuItem2: TMenuItem;
mnuToolsAliases: TMenuItem;
Separator5: TMenuItem;
mnuViewMainToolBar: TMenuItem;
pnlToolBar: TPanel;
pnlGlyphs: TFlowPanel;
gbGlyphsList: TGroupBox;
imgMainDisplay: TImage;
Image2: TImage;
mnuMain: TMainMenu;
txtMainEditor: TMemo;
mnuFile: TMenuItem;
mnuTools: TMenuItem;
mnuToolsOptions: TMenuItem;
mnuEdit: TMenuItem;
mnuEditCopy: TMenuItem;
mnuEditCut: TMenuItem;
mnuEditPaste: TMenuItem;
mnuHelp: TMenuItem;
mnuHelpTopics: TMenuItem;
mnuHelpAbout: TMenuItem;
mnuFileNew: TMenuItem;
mnuViewUpdate: TMenuItem;
mnuFileSaveImageAs: TMenuItem;
mnuViewGlyphs: TMenuItem;
OpenDialog1: TOpenDialog;
SaveDialog1: TSaveDialog;
SavePictureDialog1: TSavePictureDialog;
Separator4: TMenuItem;
ScrollBox1: TScrollBox;
Separator3: TMenuItem;
mnuViewVertical: TMenuItem;
mnuViewHorizontal: TMenuItem;
Separator2: TMenuItem;
mnuFileOpen: TMenuItem;
mnuFileSaveText: TMenuItem;
mnuFileSaveTextAs: TMenuItem;
mnuFileExit: TMenuItem;
mnuView: TMenuItem;
mnuToolsGlyphs: TMenuItem;
Panel1: TPanel;
Separator1: TMenuItem;
Splitter1: TSplitter;
procedure actCopyExecute(Sender: TObject);
procedure actCutExecute(Sender: TObject);
procedure actDeleteExecute(Sender: TObject);
procedure actPasteExecute(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
procedure BitBtn3Click(Sender: TObject);
procedure BitBtn4Click(Sender: TObject);
procedure BitBtn5Click(Sender: TObject);
procedure BitBtn6Click(Sender: TObject);
procedure cboGardinerChange(Sender: TObject);
procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure gbGlyphsListClick(Sender: TObject);
procedure Image2Click(Sender: TObject);
procedure mnuEditDirectionLtRClick(Sender: TObject);
procedure mnuEditDirectionRtLClick(Sender: TObject);
procedure mnuToolsAliasesClick(Sender: TObject);
procedure mnuViewMainToolBarClick(Sender: TObject);
procedure mnuFileSaveImageAsClick(Sender: TObject);
procedure mnuFileSaveTextAsClick(Sender: TObject);
procedure mnuFileSaveTextClick(Sender: TObject);
procedure mnuToolsGlyphsClick(Sender: TObject);
procedure mnuToolsOptionsClick(Sender: TObject);
procedure mnuViewGlyphsClick(Sender: TObject);
procedure mnuViewHorizontalClick(Sender: TObject);
procedure mnuViewVerticalClick(Sender: TObject);
procedure txtMainEditorChange(Sender: TObject);
procedure txtMainEditorExit(Sender: TObject);
procedure mnuHelpAboutClick(Sender: TObject);
procedure mnuViewUpdateClick(Sender: TObject);
procedure mnuFileNewClick(Sender: TObject);
procedure mnuFileOpenClick(Sender: TObject);
procedure mnuFileExitClick(Sender: TObject);
procedure updateview;
procedure glyphbuttonClick(Sender: TObject);
procedure processhierofile(afilename:string);
procedure initdata;
procedure generate_image(characters: TList; afilename:string);
function builddatafile: integer;
private
public
end;
var
frmMain: TfrmMain;
rawdata, combinations:TStringList;
glyphs:TList;
glyph:TGlyphData;
config:TStringList;
unsaved:boolean;
currentfilename:string;
implementation
uses
ufrmabout, ufrmglyphs, ufrmoptions, ufrmalias;
{$R *.lfm}
{ TfrmMain }
procedure TfrmMain.mnuFileExitClick(Sender: TObject);
begin
close;
end;
procedure TfrmMain.updateview;
var
bmp:TBitMap;
begin
screen.Cursor:=crHourGlass;
txtMainEditor.lines.SaveToFile('default.txt');
//processhierofile('');
bmp:=texttoimage(txtMainEditor.Text);
//imgMainDisplay.Canvas.CopyRect(bmp.canvas.ClipRect, bmp.canvas, bmp.canvas.ClipRect);
//imgMainDisplay.Picture.assign(bmp);// loadfromfile('tmp.bmp');
//imgMainDisplay.Picture.loadfromfile('tmp.bmp');
imgMainDisplay.Picture.Bitmap:=bmp;
imgMainDisplay.Picture.SaveToFile('default.png');
screen.Cursor:=crDefault;
//txtMainEditor.SetFocus;
end;
procedure TfrmMain.glyphbuttonClick(Sender: TObject);
begin
txtMainEditor.SelText:=' ' + (Sender as TImage).Hint + ' ';
txtMainEditor.SetFocus;
end;
procedure TfrmMain.gbGlyphsListClick(Sender: TObject);
begin
end;
procedure TfrmMain.Image2Click(Sender: TObject);
begin
end;
procedure TfrmMain.mnuEditDirectionLtRClick(Sender: TObject);
begin
mnuEditDirectionLtR.Checked:=true;
mnuEditDirectionRtL.Checked:=false;
ini.WriteString('Graphic Options', 'Text Direction', 'Left to Right');
mnuViewUpdateClick(self);
end;
procedure TfrmMain.mnuEditDirectionRtLClick(Sender: TObject);
begin
mnuEditDirectionLtR.Checked:=false;
mnuEditDirectionRtL.Checked:=true;
ini.WriteString('Graphic Options', 'Text Direction', 'Right to Left');
mnuViewUpdateClick(self);
end;
procedure TfrmMain.mnuToolsAliasesClick(Sender: TObject);
begin
frmAliases.showmodal;
end;
procedure TfrmMain.mnuViewMainToolBarClick(Sender: TObject);
begin
if pnlToolBar.Visible then begin
pnlToolBar.Visible:=false;
mnuViewMainToolBar.Checked:=false;
end else begin
pnlToolBar.Visible:=true;
mnuViewMainToolBar.Checked:=true;
end;
ini.WriteBool('Main Toolbar', 'Visible', pnlToolBar.Visible);
end;
procedure TfrmMain.mnuFileSaveImageAsClick(Sender: TObject);
begin
SavePictureDialog1.FileName:=StringReplace(currentfilename, '.hiero', '.png', [rfReplaceAll]);
if SavePictureDialog1.execute then begin
imgMainDisplay.Picture.SaveToFile(SavePictureDialog1.FileName);
end;
end;
procedure TfrmMain.mnuFileSaveTextAsClick(Sender: TObject);
begin
SaveDialog1.FileName:=currentfilename;
if SaveDialog1.execute then begin
currentfilename:=SaveDialog1.FileName;
txtMainEditor.Lines.SaveToFile(SaveDialog1.FileName);
unsaved:=false;
end;
end;
procedure TfrmMain.mnuFileSaveTextClick(Sender: TObject);
begin
if currentfilename='' then begin
if SaveDialog1.execute then begin
currentfilename:=SaveDialog1.FileName;
txtMainEditor.Lines.SaveToFile(SaveDialog1.FileName);
unsaved:=false;
end;
end else begin
txtMainEditor.Lines.SaveToFile(currentfilename);
unsaved:=false;
end;
end;
procedure TfrmMain.mnuToolsGlyphsClick(Sender: TObject);
begin
frmGlyphs.show;
end;
procedure TfrmMain.mnuToolsOptionsClick(Sender: TObject);
begin
frmOptions.showmodal;
ini:=TIniFile.Create(IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'panghiero.ini');
if frmOptions.ModalResult = mrOK then begin
screen.cursor:=crHourGlass;
ini.writeString('Editor Font', 'Name', frmOptions.FontDialog1.font.Name);
ini.writeInteger('Editor Font', 'Size', frmOptions.FontDialog1.font.Size);
ini.writeInteger('Graphic Options', 'Image Border', frmOptions.spnTextBorder.Value);
ini.writeInteger('Graphic Options', 'Line Height', frmOptions.spnTextLineHeight.Value);
ini.writeInteger('Graphic Options', 'Maximum Text Width', frmOptions.spnTextMaxWidth.Value);
ini.writeInteger('Graphic Options', 'Maximum Text Height', frmOptions.spnTextMaxHeight.Value);
ini.writeInteger('Graphic Options', 'Character Spacing', frmOptions.spnTextSpace.Value);
ini.writeInteger('Graphic Options', 'Interlinear Space', frmOptions.spnTextLineSpace.Value);
txtMainEditor.font.Name:=ini.ReadString('Editor Font', 'Name', 'Aegyptus');
txtMainEditor.font.Size:=ini.ReadInteger('Editor Font', 'Size', 20);
screen.cursor:=crDefault;
end;
end;
procedure TfrmMain.mnuViewGlyphsClick(Sender: TObject);
begin
if (gbGlyphsList.Visible) then begin
gbGlyphsList.Visible:=false;
mnuViewGlyphs.Checked:=false;
end else begin
gbGlyphsList.Visible:=true;
mnuViewGlyphs.Checked:=true;
end;
ini.WriteBool('Glyphs List', 'Visible', gbGlyphsList.Visible);
end;
procedure TfrmMain.mnuViewHorizontalClick(Sender: TObject);
begin
mnuViewHorizontal.Checked:=true;
mnuViewVertical.Checked:=false;
imgMainDisplay.align:=alright;
imgMainDisplay.Width:=0;
Splitter1.align:=alnone;
Splitter1.Left:=1000;
txtMainEditor.align:=alleft;
txtMainEditor.Width:=Panel1.width div 2;
Splitter1.ResizeAnchor:=akLeft;
Splitter1.width:=5;
Splitter1.align:=alleft;
imgMainDisplay.align:=alclient;
ini.writestring('Editor Layout', 'Orientation', 'horizontal')
end;
procedure TfrmMain.mnuViewVerticalClick(Sender: TObject);
begin
mnuViewVertical.Checked:=True;
mnuViewHorizontal.Checked:=false;
imgMainDisplay.align:=alBottom;
imgMainDisplay.Height:=0;
Splitter1.align:=alNone;
Splitter1.Top:=1000;
txtMainEditor.align:=altop;
txtMainEditor.height:=0;
Splitter1.ResizeAnchor:=akTop;
Splitter1.height:=5;
Splitter1.align:=altop;
txtMainEditor.height:=panel1.Height div 2;
imgMainDisplay.align:=alclient;
ini.writestring('Editor Layout', 'Orientation', 'vertical')
end;
procedure TfrmMain.txtMainEditorChange(Sender: TObject);
begin
unsaved:=true;
end;
procedure TfrmMain.txtMainEditorExit(Sender: TObject);
begin
updateview;
end;
procedure TfrmMain.mnuHelpAboutClick(Sender: TObject);
begin
frmAbout.showmodal;
end;
procedure TfrmMain.mnuViewUpdateClick(Sender: TObject);
begin
updateview;
txtMainEditor.SetFocus;
end;
procedure TfrmMain.mnuFileNewClick(Sender: TObject);
var
ok:boolean;
answer:integer;
begin
ok:=true;
if unsaved then begin
ok:=false;
SaveDialog1.FileName:=currentfilename;
case application.MessageBox('The current file has been modified. Do you want to save it before switching to a new file?', 'Unsaved file', MB_YESNOCANCEL + MB_ICONWARNING) of
IDYES: begin
if currentfilename='' then begin
if SaveDialog1.execute then begin
currentfilename:=SaveDialog1.FileName;
txtMainEditor.Lines.SaveToFile(SaveDialog1.FileName);
ok:=true;
end;
end else begin
txtMainEditor.Lines.SaveToFile(currentfilename);
ok:=true;
end;
end;
IDNO: begin
ok:=true;
end;
IDCANCEL: begin
end;
end;
end;
if ok then begin
txtMainEditor.Lines.Clear;
imgMainDisplay.Picture.Clear;
unsaved:=false;
end;
end;
procedure TfrmMain.mnuFileOpenClick(Sender: TObject);
var
ok:boolean;
answer:integer;
begin
ok:=true;
if unsaved then begin
ok:=false;
SaveDialog1.FileName:=currentfilename;
case application.MessageBox('The current file has been modified. Do you want to save it before opening another file?', 'Unsaved file', MB_YESNOCANCEL + MB_ICONWARNING) of
IDYES: begin
if currentfilename='' then begin
if SaveDialog1.execute then begin
showmessage(SaveDialog1.FileName);
currentfilename:=SaveDialog1.FileName;
txtMainEditor.Lines.SaveToFile(SaveDialog1.FileName);
ok:=true;
end;
end else begin
txtMainEditor.Lines.SaveToFile(currentfilename);
ok:=true;
end;
end;
IDNO: begin
ok:=true;
end;
IDCANCEL: begin
end;
end;
end;
if ok then begin
if OpenDialog1.Execute then begin
txtMainEditor.Lines.LoadFromFile(OpenDialog1.FileName);
//processhierofile(OpenDialog1.FileName);
texttoimage(txtMainEditor.Text);
imgMainDisplay.Picture.LoadFromFile('tmp.bmp');
unsaved:=false;
end;
end;
end;
procedure TfrmMain.FormCreate(Sender: TObject);
var
i:integer;
src:TStringList;
begin
initdata;
unsaved:=false;
ini:=TIniFile.Create(IncludeTrailingBackslash(ExtractFilePath(ParamStr(0))) + 'panghiero.ini');
if (paramcount()>0) then begin
for i:=1 to paramcount() do begin
src:=TStringList.create;
src.LoadFromFile(paramstr(i));
texttoimage(txtMainEditor.Text).SaveToFile(StringReplace(paramstr(i), '.hiero', '.png', [rfReplaceAll]));
//processhierofile(ParamStr(i));
end;
Application.Terminate;
end else begin
currentfilename:='';
panel1.align:=alClient;
if (fileexists('default.txt')) then begin
txtMainEditor.lines.loadfromfile('default.txt');
end;
if (fileexists('default.png')) then begin
imgMainDisplay.picture.loadfromfile('default.png');
end;
end;
end;
procedure TfrmMain.FormResize(Sender: TObject);
begin
txtMainEditor.Width:=panel1.Width div 2;
end;
procedure TfrmMain.FormShow(Sender: TObject);
begin
txtMainEditor.font.Name:=ini.ReadString('Editor Font', 'Name', 'Aegyptus');
txtMainEditor.font.Size:=ini.ReadInteger('Editor Font', 'Size', 20);
if (ini.ReadString('Graphic Options', 'Text Direction', 'Left to Right')='Right to Left') then begin
mnuEditDirectionLtR.Checked:=false;
mnuEditDirectionRtL.Checked:=true;
ini.WriteString('Graphic Options', 'Text Direction', 'Right to Left');
end else begin
mnuEditDirectionLtR.Checked:=true;
mnuEditDirectionRtL.Checked:=false;
ini.WriteString('Graphic Options', 'Text Direction', 'Left to Right');
end;
if (ini.readstring('Editor Layout', 'Orientation', 'horizontal')='horizontal') then begin
mnuViewHorizontalClick(self);
end else begin
mnuViewVerticalClick(self);
end;
if (ini.ReadBool('Main Toolbar', 'Visible', true)) then begin
pnlToolBar.Visible:=true;
mnuViewMainToolBar.Checked:=true;
end else begin
pnlToolBar.Visible:=false;
mnuViewMainToolBar.Checked:=false;
end;
if (ini.ReadBool('Glyphs List', 'Visible', true)) then begin
gbGlyphsList.Visible:=true;
mnuViewGlyphs.Checked:=true;
end else begin
gbGlyphsList.Visible:=false;
mnuViewGlyphs.Checked:=false;
end;
end;
procedure TfrmMain.cboGardinerChange(Sender: TObject);
var
prefix:string;
i:integer;
btn:TImage;
bl, test:string;
ok:boolean;
isnum, k:integer;
phoneticsigns:string;
signlist:TStringArray;
flnm:string;
begin
prefix:='A';
case cboGardiner.ItemIndex of
0: prefix := 'A'; //Man and his occupations
1: prefix := 'B'; //Woman and her occupations
2: prefix := 'C'; //Anthropomorphic deities
3: prefix := 'D'; //Parts of the human body
4: prefix := 'E'; //Mammals
5: prefix := 'F'; //Parts of mammals
6: prefix := 'G'; //Birds
7: prefix := 'H'; //Parts of birds
8: prefix := 'I'; //Amphibious animals, reptiles, etc.
9: prefix := 'K'; //Fishes and parts of fishes
10: prefix := 'L'; //Invertebrata and lesser animals
11: prefix := 'M'; //Trees and plants
12: prefix := 'N'; //Sky, earth, water
13: prefix := 'NU'; //Upper nile
14: prefix := 'NL'; //Lower nile
15: prefix := 'O'; //Buildings, parts of buildings, etc.
16: prefix := 'P'; //Ships and parts of ships
17: prefix := 'Q'; //Domestic and funerary furniture
18: prefix := 'R'; //Temple furniture and sacred emblems
19: prefix := 'S'; //Crowns, dress, staves, etc.
20: prefix := 'T'; //Warfare, hunting, butchery
21: prefix := 'U'; //Agriculture, crafts, and professions
22: prefix := 'V'; //Rope, fibre, baskets, bags, etc.
23: prefix := 'W'; //Vessels of stone and earthenware
24: prefix := 'X'; //Loaves and cakes
25: prefix := 'Y'; //Writings, games, music
26: prefix := 'Z'; //Strokes, signs derived from Hieratic, geometrical features
27: prefix := 'Aa'; //Unclassified signs
28: prefix := 'uniliteral'; //uniliteral signs
29: prefix := 'biliteral'; //biliteral signs
30: prefix := 'triliteral'; //triliteral signs
end;
for i:=pnlGlyphs.ComponentCount-1 downto 0 do begin
pnlGlyphs.Controls[i].Destroy;
end;
if (cboGardiner.ItemIndex>27) then begin
case prefix of
'uniliteral': begin
phoneticsigns:='G1,M17,M17A,Z4,D36,G43,Z7,D58,Q3,I9,G17,N35,D21,O4,V28,Aa1,F32,O34,S29,N37,N29,V31,W11,X1,V13,D46,I10';
end;
'biliteral': begin
phoneticsigns:='F40,U23,G25,M15,Q1,F51C,D54,E9,E8,F34,Aa13,Z11,A27,K1,W24,W25,A48,D4,T24,M40,A19,I3,V15,O29,F16,T24,G35,'
+ 'K3,V26,V27,V4,T21,F13,E34,M42,G36,F51C,Q1,Q2,M13,V24,V25,G29,W10,W10A,F18,G40,G41,O1,F22,D56,T9,U1,D36,D38,N36,W19,N35A,'
+ 'G18,T1,Y5,N36,O5,U6,U23,V22,D35,D41,U19,W24,V30,O5,T34,T35,M22A,H4,G21,F20,Aa27,E23,T13,U13,M16,F18,Aa5,N42,U36,M2,U8,V36'
+ ',D2,N31,W14,T3,T4,L6,M12,N28,D43,R22,M3,K4,D33,F26,T28,G39,V16,V17,O50,Aa17,Aa18,M23,T22,V29,F29,Q1,S22,Z9,H7,M8,H6,N40'
+ ',V1,V7,V6,F30,Aa8,T19,Aa28,D28,R5,I6,G38,G28,Aa13,Aa16,N16,N17,U30,U33,D1,T8,U15,M6,G47,S24,D37,X8,U28,U29,X8,N26,G22,M36,R11,I11';
end;
'triliteral': begin
phoneticsigns:='E26,O28,F44,S39,Aa20,S34,P6,I1,V29,S40,M13,D60,F25,F12,Aa11,S12,F35,R8,T12,S38,R4,L1,W17,S42,P8,U34,W9,N14,F42,F36,S29,G54,T31,U21,F21,A50,M26,T18,U17,G4,T25';
end;
end;
signlist:=phoneticsigns.Split(',');
for i:=0 to Length(signlist)-1 do begin
flnm:=IncludeTrailingBackslash(extractfiledir(paramstr(0))) + IncludeTrailingBackslash('img') + 'hiero_' + signlist[i] + '.png';
if (FileExists(flnm)) then begin
btn:=TImage.Create(pnlGlyphs);
btn.Picture.LoadFromFile(flnm);
btn.Hint:=signlist[i];
btn.ShowHint:=true;
btn.OnClick:=@glyphbuttonClick;
btn.Width:=btn.Picture.Bitmap.Canvas.Width;
//btn.AutoSize:=true;
btn.Parent:=pnlGlyphs;
end;
end;
end else begin
FileListBox1.Mask:='hiero_' + prefix + '*.png';
FileListBox1.Directory:=IncludeTrailingBackslash(extractfiledir(paramstr(0))) + 'img';
for i:=0 to FileListBox1.Items.count -1 do begin
bl:=StringReplace(FileListBox1.Items[i], 'hiero_', '', [rfReplaceAll]);
bl:=stringreplace(bl, '.png', '', [rfReplaceAll]);
ok := false;
if (trim(bl)<>'') then begin
test:=StringReplace(bl, prefix, '', [rfReplaceAll]);
val(test, k, isnum);
if (isnum=0) then begin
ok:=true;
end;
end;
if ok then begin
btn:=TImage.Create(pnlGlyphs);
btn.Picture.LoadFromFile(IncludeTrailingBackslash(extractfiledir(paramstr(0))) + IncludeTrailingBackslash('img') + FileListBox1.Items[i]);
btn.Hint:=bl;
btn.ShowHint:=true;
btn.OnClick:=@glyphbuttonClick;
btn.Width:=btn.Picture.Bitmap.Canvas.Width;
//btn.AutoSize:=true;
btn.Parent:=pnlGlyphs;
end;
end;
end;
txtMainEditor.SetFocus;
end;
procedure TfrmMain.actCopyExecute(Sender: TObject);
begin
txtMainEditor.CopyToClipboard;
//Clipboard.AsText:=txtMainEditor.SelText;
end;
procedure TfrmMain.actCutExecute(Sender: TObject);
begin
txtMainEditor.CutToClipboard;
end;
procedure TfrmMain.actDeleteExecute(Sender: TObject);
begin
txtMainEditor.SelText:='';
end;
procedure TfrmMain.actPasteExecute(Sender: TObject);
begin
txtMainEditor.PasteFromClipboard;
end;
procedure TfrmMain.BitBtn1Click(Sender: TObject);
begin
mnuFileOpenClick(self);
end;
procedure TfrmMain.BitBtn2Click(Sender: TObject);
begin
mnuFileNewClick(self);
end;
procedure TfrmMain.BitBtn3Click(Sender: TObject);
begin
mnuFileSaveTextClick(self);
end;
procedure TfrmMain.BitBtn4Click(Sender: TObject);
begin
mnuFileSaveTextAsClick(self);
end;
procedure TfrmMain.BitBtn5Click(Sender: TObject);
begin
mnuViewUpdateClick(self);
end;
procedure TfrmMain.BitBtn6Click(Sender: TObject);
begin
mnuFileSaveImageAsClick(self);
end;
procedure TfrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
end;
procedure TfrmMain.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
CanClose:=true;
if unsaved then begin
CanClose:=false;
SaveDialog1.FileName:=currentfilename;
case application.MessageBox('The current file has been modified. Do you want to save it before closing the program?', 'Unsaved file', MB_YESNOCANCEL + MB_ICONWARNING) of
IDYES: begin
if currentfilename='' then begin
if SaveDialog1.execute then begin
currentfilename:=SaveDialog1.FileName;
txtMainEditor.Lines.SaveToFile(SaveDialog1.FileName);
CanClose:=true;
end;
end else begin
txtMainEditor.Lines.SaveToFile(currentfilename);
CanClose:=true;
end;
end;
IDNO: begin
CanClose:=true;
end;
IDCANCEL: begin
CanClose:=false;
end;
end;
end;
end;
procedure TfrmMain.processhierofile(afilename:string);
var
lines:TStringList;
src, token:string;
parsed, tmp, subtokens, subsubtokens:TStringArray;
i,d,c,t,v,h,s:integer;
characters:TList;
character:TCharacterInfo;
done:Boolean;
begin
config:=TStringList.create;
config.Clear;
//writeln('Processing source file ''' + filename + '''...');
characters:=TList.create;
lines:=TStringList.create;
//lines.LoadFromFile(filename);
if (FileExists(afilename)) then begin
if (Pos('.hiero', afilename)<>0) then begin
lines.LoadFromFile(afilename);
end;
end else begin
lines.Text:=txtMainEditor.text;
end;
src:='';
for i:=0 to lines.count-1 do begin
if (pos('config', lines[i])=0) then begin
src += lines[i] + ' ';
end else begin
//writeln('Configuration option found: ' + stringreplace(lines[i], 'config:', '', [rfReplaceAll]));
config.add(lines[i]);
end;
end;
src:=trim(src);
src:=StringReplace(src, '-', ' ', [rfReplaceAll]);
//src:=StringReplace(src, #13#10, ' ', [rfReplaceAll]);
//src:=StringReplace(src, #13, ' ', [rfReplaceAll]);
//src:=StringReplace(src, #10, ' ', [rfReplaceAll]);
src:=StringReplace(src, '!', ' ! ', [rfReplaceAll]);
src:=StringReplace(src, ' ', ' ', [rfReplaceAll]);
while (Pos(' ', src)>0) do begin
src:=StringReplace(src, ' ', ' ', [rfReplaceAll]);
end;
src:=StringReplace(src, '* ', '*', [rfReplaceAll]);
src:=StringReplace(src, ' *', '*', [rfReplaceAll]);
src:=StringReplace(src, ': ', ':', [rfReplaceAll]);
src:=StringReplace(src, ' :', ':', [rfReplaceAll]);
//writeln('Processed source text: '#13#10'----------------------');
//writeln(src);
//writeln('----------------------');
parsed:=src.Split(' ');
for i:=0 to length(parsed)-1 do begin
token:=trim(parsed[i]);
done:=false;
if (token='!') then begin
character:=TCharacterInfo.create;
character.name:=token;
character.code:=token;
character.position:='eol';
characters.add(character);
done:=true;
end;
//check for pre-composed groups
if ((pos(':', token)>0)or(pos('*', token)>0)) then begin
for d:=0 to combinations.count-1 do begin
if (token=combinations[d]) then begin
character:=TCharacterInfo.create;
character.code:=token;
character.name:='pre';
characters.add(character);
done:=true;
end;
end;
end;
if not done then begin
if (pos(':', token)=0) then begin
//no vertical group; so, ignore horizontal grouping
tmp:=token.Split('*');
for t:=0 to Length(tmp)-1 do begin
character:=TCharacterInfo.create;
character.code:=tmp[t];
characters.add(character);
end;
end else begin
//vertical grouping
subtokens:=token.split(':');
if (pos('*', subtokens[0])=0) then begin
//no horizontal composition
character:=TCharacterInfo.create;
character.code:=subtokens[0];
character.position:='top';
characters.add(character);
end else begin
//horizontal composition
subsubtokens:=subtokens[0].split('*');
character:=TCharacterInfo.create;
character.code:=subsubtokens[0];
character.position:='top-left';
characters.add(character);
character:=TCharacterInfo.create;
character.code:=subsubtokens[1];
character.position:='top-right';
characters.add(character);
end;
if (pos('*', subtokens[1])=0) then begin
//no horizontal composition
character:=TCharacterInfo.create;
character.code:=subtokens[1];
character.position:='bottom';
characters.add(character);
end else begin
//horizontal composition
subsubtokens:=subtokens[1].split('*');
character:=TCharacterInfo.create;
character.code:=subsubtokens[0];
character.position:='bottom-left';
characters.add(character);
character:=TCharacterInfo.create;
character.code:=subsubtokens[1];
character.position:='bottom-right';
characters.add(character);
end;
end;
end;
//////////////////////////////
end;
generate_image(characters, afilename);
end;
procedure TfrmMain.initdata;
var
i,j:integer;
begin
combinations:=TStringList.create;
rawdata:=TStringList.create;
if (not FileExists('img/hiero_A1.png')) then begin
//writeln('[!] ERROR: Image files NOT FOUND!');
halt(1);
end;
if (FileExists('glyphdata.dat')) then begin
//writeln('Loading glyph data...');
rawdata.LoadFromFile('glyphdata.dat');
end else begin
//writeln('[!] Data file glyphdata.dat NOT FOUND!');
//writeln('Trying to load alternate data file...');
if (FileExists('altglyphdata.dat')) then begin
//writeln('Loading glyph data from alternate file...');
rawdata.LoadFromFile('altglyphdata.dat');
end else begin
//writeln('[!] Alternate data file altglyphdata.dat NOT FOUND!');
//writeln('Trying to generate alternate data file from image files...');
j:=builddatafile;
if (FileExists('altglyphdata.dat')) then begin
//writeln('Loading glyph data from alternate file...');
rawdata.LoadFromFile('altglyphdata.dat');
end else begin
//writeln('[!] Alternate data file altglyphdata.dat NOT FOUND!');
halt(1);
end;
end;
end;
glyphs:=TList.Create;
for i:=0 to rawdata.count-1 do begin
glyph:=TGlyphData.create(rawdata[i]);
glyphs.add(glyph);
if ((pos(':', glyph.code.text)>0)or(pos('*', glyph.code.text)>0)) then begin
for j:= 0 to glyph.code.Count-1 do begin
combinations.add(glyph.code[j]);
end;
end;
end;
end;
procedure TfrmMain.generate_image(characters: TList; afilename:string);
var
glyph, finalimage:TPortableNetworkGraphic;
bmp:TBitMap;
r:TRect;
lineheight, textwidth, maxwidth, maxheight, space,
x, y,
glyphx, glyphy,
groupwidth,
nextx,
finalwidth, finalheight,
i, g, j, k :integer;
glyphfilename:string;
tmp:string;
isnum:integer;
begin
lineheight:=0;
textwidth:=0;
maxwidth:=1000;
maxheight:=5000;
space:=5;
for i:=0 to config.count-1 do begin
if (pos(':maxwidth=', config.text)>0) then begin
tmp:=trim(StringReplace(config[i], 'config:maxwidth=', '', [rfReplaceAll]));
val(tmp, k, isnum);
if (isnum=0) then begin
maxwidth:=StrToInt(tmp);
end;
end;
if (pos(':maxheight=', config.text)>0) then begin
tmp:=trim(StringReplace(config[i], 'config:maxheight=', '', [rfReplaceAll]));
val(tmp, k, isnum);
if (isnum=0) then begin
maxheight:=StrToInt(tmp);
end;
end;
if (pos(':lineheight=', config.text)>0) then begin
tmp:=trim(StringReplace(config[i], 'config:lineheight=', '', [rfReplaceAll]));
val(tmp, k, isnum);
if (isnum=0) then begin
lineheight:=StrToInt(tmp);
end;
end;
if (pos(':space=', config.text)>0) then begin
tmp:=trim(StringReplace(config[i], 'config:space=', '', [rfReplaceAll]));
val(tmp, k, isnum);
if (isnum=0) then begin
space:=StrToInt(tmp);
end;
end;
end;
x:=0;
y:=0;
bmp:=TBitmap.Create;
bmp.Width:=maxwidth;
bmp.Height:=maxheight;
bmp.Canvas.Pen.Color:=clWhite;
bmp.Canvas.Brush.Color:=clWhite;
bmp.Canvas.FillRect(0,0,maxwidth,maxheight);
for i:=0 to characters.count-1 do begin
for g:=0 to glyphs.count-1 do begin
if (
(TGlyphData(glyphs[g]).matchcode(TCharacterInfo(characters[i]).code))
or
(TCharacterInfo(characters[i]).code=TGlyphData(glyphs[g]).name)) then begin
TCharacterInfo(characters[i]).name:=TGlyphData(glyphs[g]).name;
TCharacterInfo(characters[i]).width:=TGlyphData(glyphs[g]).width;
TCharacterInfo(characters[i]).height:=TGlyphData(glyphs[g]).height;
end;
end;
end;
for i:=0 to characters.count-1 do begin
if (TCharacterInfo(characters[i]).height>lineheight) then begin
lineheight:=TCharacterInfo(characters[i]).height;
end;
if (TCharacterInfo(characters[i]).name='!')then begin
x := 0;
y := y + lineheight + space;
end else begin
case TCharacterInfo(characters[i]).position of
'regular': begin
if (x+TCharacterInfo(characters[i]).width > maxwidth) then begin
x := 0;
y := y + lineheight + space;
end;
end;
'top': begin
if (x+TCharacterInfo(characters[i]).width > maxwidth) then begin
x := 0;
y := y + lineheight + space;
end;
end;
'top-left':begin
if (x+TCharacterInfo(characters[i+2]).width > maxwidth) then begin
x := 0;
y := y + lineheight + space;
end;
end;
end;
glyphx := x;
glyphy := y + ((lineheight - TCharacterInfo(characters[i]).height) div 2);
nextx := x + TCharacterInfo(characters[i]).width + space;
case TCharacterInfo(characters[i]).position of
'top': begin
glyphy := y;
nextx := x;
if (i<characters.Count) then begin
if (TCharacterInfo(characters[i+1]).width > TCharacterInfo(characters[i]).width) then begin
glyphx := glyphx + (TCharacterInfo(characters[i+1]).width - TCharacterInfo(characters[i]).width) div 2;
end;
glyphy := y + ((lineheight div 2) - TCharacterInfo(characters[i]).height) div 2;
end;
end;
'bottom': begin
glyphy := y * (lineheight div 2);
if (i>0) then begin
if (TCharacterInfo(characters[i-1]).width > TCharacterInfo(characters[i]).width) then begin
glyphx := glyphx + ((TCharacterInfo(characters[i-1]).width - TCharacterInfo(characters[i]).width) div 2);
if (TCharacterInfo(characters[i]).width > TCharacterInfo(characters[i-1]).width) then begin
nextx := x + TCharacterInfo(characters[i]).width + space;
end else begin
nextx := x + TCharacterInfo(characters[i-1]).width + space;