-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathu_Main.pas
2884 lines (2510 loc) · 81.5 KB
/
u_Main.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 u_Main;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.StdCtrls,
Vcl.ExtDlgs, Vcl.ToolWin, profixxml,
Vcl.Samples.Spin, Winapi.CommCtrl, SynEditHighlighter, SynHighlighterXML,
SynEdit, Vcl.Grids, System.Math, System.ImageList, Vcl.ImgList,
SynHighlighterIni, System.NetEncoding, System.Actions, Vcl.ActnList,
SVG, Types, SVGTypes, SVGParse, Winapi.GDIPAPI, Winapi.GDIPOBJ;
type
TFontFace=record
font_family: string;
units_per_em: integer;
ascent: integer;
descent: integer;
x_height: integer;
cap_height: integer;
right: integer;
baseright: integer;
horiz_adv_x: integer;
end;
TGlyph=class
PtBuf:array of TPoint;
TpBuf:array of Byte;
Right:integer;
Bounds:TRect;
rng:array of TRect;
end;
TMainForm = class(TForm)
pcGlyph: TPageControl;
splGlyph: TSplitter;
tsGlyph: TTabSheet;
tsXML: TTabSheet;
pnFont: TPanel;
tbrFile: TToolBar;
tbFontOpen: TToolButton;
tbFontSave: TToolButton;
treeFNT: TTreeView;
tsHeap: TTabSheet;
lbUnicodeRegions: TListBox;
StatusBar1: TStatusBar;
tbSep8: TToolButton;
tbFontConfig: TToolButton;
dlgFont: TFontDialog;
sbrPaint: TScrollBox;
pnImg: TPanel;
Draw: TPaintBox;
seGlyph: TSynEdit;
SynXMLSyn1: TSynXMLSyn;
sgGlyph: TStringGrid;
sgBase: TStringGrid;
ilMain: TImageList;
Panel1: TPanel;
Panel2: TPanel;
Label1: TLabel;
seZoom: TSpinEdit;
seGrid: TSpinEdit;
Label2: TLabel;
dlgSave: TSaveDialog;
tsKern: TTabSheet;
sg: TStringGrid;
SynIniSyn1: TSynIniSyn;
tbgKerning: TToolBar;
ToolButton24: TToolButton;
ToolButton26: TToolButton;
ToolButton25: TToolButton;
ToolButton27: TToolButton;
tbClearKern: TToolButton;
tbSep6: TToolButton;
tbSep7: TToolButton;
Panel3: TPanel;
seKern: TSynEdit;
KernPaint: TPaintBox;
tbrXML: TToolBar;
tbApplyXML: TToolButton;
tbResetXML: TToolButton;
alMain: TActionList;
aApply: TAction;
aReset: TAction;
aGoToZero: TAction;
aSetBase: TAction;
aAlignTop: TAction;
aAlignDown: TAction;
aAlignMidle: TAction;
aAlignHeight: TAction;
aLeftEdge: TAction;
aMoveLeft: TAction;
aMoveRight: TAction;
aRightEdge: TAction;
aEdgeLeft: TAction;
aEdgeRight: TAction;
aKerningRows: TAction;
aKerningCols: TAction;
aKerningCalc: TAction;
aKerningApply: TAction;
aKerningClear: TAction;
aFontOpen: TAction;
aFontSave: TAction;
aFontConfig: TAction;
aStopCalc: TAction;
tbStopCalc: TToolButton;
pbrProcessing: TProgressBar;
pscrGlyph: TPageScroller;
tbrGlyph: TToolBar;
tbGoToZero: TToolButton;
tbApply: TToolButton;
tbSep1: TToolButton;
tbReset: TToolButton;
tbSep2: TToolButton;
tbSetBase: TToolButton;
tbAlignUp: TToolButton;
tbAlignDown: TToolButton;
tbSep3: TToolButton;
tbAlignMidle: TToolButton;
tbAlignHeight: TToolButton;
tbSep4: TToolButton;
tbLeftEdge: TToolButton;
tbMoveLeft: TToolButton;
tbMoveRight: TToolButton;
tbSep5: TToolButton;
ToolButton22: TToolButton;
ToolButton20: TToolButton;
ToolButton21: TToolButton;
aMoveUp: TAction;
aMoveDown: TAction;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
dlgOpenSVG: TOpenDialog;
tbFolderSVG: TToolButton;
pnOptions: TPanel;
GroupBox1: TGroupBox;
chbEditGlyph: TCheckBox;
chbEditSVG: TCheckBox;
GroupBox2: TGroupBox;
chbShowGlyph: TCheckBox;
chbShowSVG: TCheckBox;
aCenter: TAction;
tbCenter: TToolButton;
ToolButton3: TToolButton;
aPlusSize: TAction;
aMinusSize: TAction;
tbMinusSize: TToolButton;
tbPlusSize: TToolButton;
GroupBox3: TGroupBox;
chFixViewBox: TCheckBox;
Splitter1: TSplitter;
GroupBox4: TGroupBox;
lblInfo: TLabel;
aToSize: TAction;
tbToSize: TToolButton;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure treeFNTAdvancedCustomDrawItem(Sender: TCustomTreeView;
Node: TTreeNode; State: TCustomDrawState; Stage: TCustomDrawStage;
var PaintImages, DefaultDraw: Boolean);
procedure treeFNTCompare(Sender: TObject; Node1, Node2: TTreeNode;
Data: Integer; var Compare: Integer);
procedure treeFNTChange(Sender: TObject; Node: TTreeNode);
procedure treeFNTChanging(Sender: TObject; Node: TTreeNode;
var AllowChange: Boolean);
procedure DrawPaint(Sender: TObject);
procedure DrawStartDrag(Sender: TObject; var DragObject: TDragObject);
procedure DrawMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure DrawDragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
procedure seZoomChange(Sender: TObject);
procedure seGridChange(Sender: TObject);
procedure KernPaintPaint(Sender: TObject);
procedure sgSelectCell(Sender: TObject; ACol, ARow: Integer;
var CanSelect: Boolean);
procedure sgDrawCell(Sender: TObject; ACol, ARow: Integer; Rect: TRect;
State: TGridDrawState);
procedure aApplyExecute(Sender: TObject);
procedure aResetExecute(Sender: TObject);
procedure aGoToZeroExecute(Sender: TObject);
procedure aSetBaseExecute(Sender: TObject);
procedure aAlignTopExecute(Sender: TObject);
procedure aAlignDownExecute(Sender: TObject);
procedure aAlignMidleExecute(Sender: TObject);
procedure aAlignHeightExecute(Sender: TObject);
procedure aAlignTopUpdate(Sender: TObject);
procedure aApplyUpdate(Sender: TObject);
procedure aSetBaseUpdate(Sender: TObject);
procedure aLeftEdgeExecute(Sender: TObject);
procedure aMoveLeftExecute(Sender: TObject);
procedure aMoveRightExecute(Sender: TObject);
procedure aRightEdgeExecute(Sender: TObject);
procedure aEdgeLeftExecute(Sender: TObject);
procedure aEdgeRightExecute(Sender: TObject);
procedure aRightEdgeUpdate(Sender: TObject);
procedure aKerningRowsExecute(Sender: TObject);
procedure aKerningColsExecute(Sender: TObject);
procedure aKerningClearExecute(Sender: TObject);
procedure aKerningCalcExecute(Sender: TObject);
procedure aKerningApplyExecute(Sender: TObject);
procedure aFontOpenExecute(Sender: TObject);
procedure aFontSaveExecute(Sender: TObject);
procedure aFontConfigExecute(Sender: TObject);
procedure aFontSaveUpdate(Sender: TObject);
procedure aResetUpdate(Sender: TObject);
procedure aStopCalcExecute(Sender: TObject);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
procedure aKerningRowsUpdate(Sender: TObject);
procedure aKerningCalcUpdate(Sender: TObject);
procedure aMoveUpExecute(Sender: TObject);
procedure aMoveDownExecute(Sender: TObject);
procedure sgSetEditText(Sender: TObject; ACol, ARow: Integer;
const Value: string);
procedure tbFolderSVGClick(Sender: TObject);
procedure chbShowGlyphClick(Sender: TObject);
procedure chbShowSVGClick(Sender: TObject);
procedure aCenterUpdate(Sender: TObject);
procedure aCenterExecute(Sender: TObject);
procedure aPlusSizeExecute(Sender: TObject);
procedure aMinusSizeExecute(Sender: TObject);
procedure aPlusSizeUpdate(Sender: TObject);
procedure chFixViewBoxClick(Sender: TObject);
procedure ToolButton4Click(Sender: TObject);
procedure Memo1Change(Sender: TObject);
procedure aToSizeUpdate(Sender: TObject);
procedure aToSizeExecute(Sender: TObject);
private
{ Private declarations }
procedure ResetFNT;
procedure ParsePath(APath: string);
procedure PathAbs(Idx: integer);
procedure PathRel(Idx: integer);
procedure PathZoom(Idx: integer; k: double);
public
{ Public declarations }
MouseStart, ZeroXY:TPoint;
zm:double;
FNT: TXML_Doc;
hFont: string;
FontFace: TFontFace;
BaseRect,GlyphRect:TRect;
Nod:TXML_Nod;
BrushBitmap:TBitmap;
FocusedNode:TTreeNode;
SvgFolder:string;
StopFlag:boolean;
ColorGlyph:TSVG;
GlyphMatrix:TAffineMatrix;
GlyphAspect:double;
GlyphFilename:string;
function StrToXY(s:string;Def:integer):double;
procedure DeltaPolyBezierTo(const Points: array of TPoint;ZeroXY:Tpoint);
procedure SvgArcTo(Curr:TPoint; rx,ry:Integer; ax:double; fa, fs:boolean; x,y:integer; Canvas:TCanvas);
procedure DrawPath(sgDots:TStringGrid;ACanvas:TCanvas;ZeroXY:TPoint;ZM:double);
procedure ApplyGlyph;
procedure DrawGlypf(ACanvas:TCanvas; AGlyph:TGlyph; dx,dy:Integer);
procedure ExistKerning;
procedure RecalcGlyph(Glyph:TGlyph; Nod:TXML_Nod);
procedure ForEachSelection(AEvent:TNotifyEvent);
function SvgSize(ASVG:TSVGObject; Trans:boolean=False ):TRectF;
procedure ApplyViewBox(ASVG:TSVG; AGlyphMatrix:string);overload;
procedure ApplyViewBox(ASVG:TSVG; AGlyphMatrix:TAffineMatrix);overload;
procedure LoadSvgFontFit(ASVG:TSVG; AFileName:string; ANod:TXML_NOD);
end;
var
MainForm: TMainForm;
implementation
{$R *.dfm}
uses FileCtrl;
type
TSvgPoint=record
X,Y:Double;
end;
PSvgPoint=^TSvgPoint;
XYZ=record
x,y,z:double;
end;
function GetCode(nod:TXML_Nod):integer;
var
s, gl_name, gl_code, rs:string;
begin
s := THTMLEncoding.HTML.Decode(nod.Attribute['unicode']);
if s='' then result := -1
else
result := ord(s[1])
{
gl_name := nod.Attribute['glyph-name'];
gl_code := nod.Attribute['unicode'];
s := '-1';
if Pos('uni',gl_name)=1 then
begin
s := copy(gl_name,4,5);
s := '$'+Copy(s,1,Pos('.',s+'.')-1);
end
else
if length(gl_code)=1 then
s := '$'+IntToHex(ord(gl_code[1]))
else begin
s := '$'+copy(gl_code,1,pos(';',gl_code)-1);
s := StringReplace(s,'&#x','$',[rfIgnoreCase]);
s := StringReplace(s,'&#','',[rfIgnoreCase]);
end;
result := StrToIntDef(s,-1);
}
end;
Procedure DifV (P,Q: XYZ; Var R: XYZ);
Begin
With R Do
Begin
x:=P.x-Q.x;
y:=P.y-Q.y;
z:=P.z-Q.z;
End;
End;
Procedure DotV (P,Q: XYZ; Var d: Double);
Begin
d:=P.x*Q.x+P.y*Q.y+P.z*Q.z;
End;
Procedure VecX (P,G: XYZ; s: Double; Var X: XYZ);
Begin
With X do
Begin
x:=P.x+s*G.x;
y:=P.y+s*G.y;
z:=P.z+s*G.z;
End;
End;
Procedure DisA (X1,X2: XYZ; Var Da: XYZ; Var Lq: Double);
Begin
With Da do
Begin
x:=X2.x-X1.x;
y:=X2.y-X1.y;
z:=X2.z-X1.z;
Lq:=Sqr(x)+Sqr(y)+Sqr(z);
End;
End;
Procedure Dist (p1,q1,p2,q2: XYZ; Var x1,x2: XYZ; Var dis: Double);
Var a11,a12,a22,b1,b2,D0,D1,D2 : Double;
s1,s2,n1,n2,sa,sb,dq,eq : Double;
g1,g2,dp,da : XYZ;
flg : Integer;
Begin
DifV(q1,p1,g1);
DifV(q2,p2,g2);
DifV(p2,p1,dp);
DotV(g1,g1,a11);
DotV(g1,g2,a12); a12:=-a12;
DotV(g2,g2,a22);
DotV(g1,dp,b1);
DotV(g2,dp,b2); b2:=-b2;
{ Cramer determinants }
D0:=a11*a22-a12*a12;
D1:= b1*a22- b2*a12;
D2:=-b1*a12+ b2*a11;
{ In-line distance }
flg:=0;
If D0>0 Then
Begin
If (0<D1) And (D1<D0) Then Inc(flg);
If (0<D2) And (D2<D0) Then Inc(flg);
End;
If D0<0 Then
Begin
If (0>D1) And (D1>D0) Then Inc(flg);
If (0>D2) And (D2>D0) Then Inc(flg);
End;
If flg=2 Then
Begin
sa:=D1/D0;
sb:=D2/D0;
End;
{ Out-line distance }
If flg<2 Then
Begin
{ a11>=0, a22>=0 }
s1:=0;
n2:=b2; { s2:=(b2-a12*s1)/a22 }
flg:=0;
If n2<=0 Then
Begin
s2:=0;
Inc(flg);
End;
If n2>=a22 Then
Begin
s2:=1;
Inc(flg);
End;
If flg=0 Then s2:=n2/a22;
VecX (p1,g1,s1,x1);
VecX (p2,g2,s2,x2);
DisA (x1,x2,da,eq);
sa:=s1; sb:=s2; dq:=eq;
s1:=1;
n2:=b2-a12; { s2:=(b2-a12*s1)/a22 }
flg:=0;
If n2<=0 Then
Begin
s2:=0;
Inc(flg);
End;
If n2>=a22 Then
Begin
s2:=1;
Inc(flg);
End;
If flg=0 Then s2:=n2/a22;
VecX (p1,g1,s1,x1);
VecX (p2,g2,s2,x2);
DisA (x1,x2,da,eq);
If eq<dq Then
Begin
sa:=s1;
sb:=s2;
dq:=eq;
End;
s2:=0;
n1:=b1; { s1=(b1-a12*s2)/a11 }
flg:=0;
If n1<=0 Then
Begin
s1:=0;
Inc(flg);
End;
If n1>=a11 Then
Begin
s1:=1;
Inc(flg);
End;
If flg=0 Then s1:=n1/a11;
VecX (p1,g1,s1,x1);
VecX (p2,g2,s2,x2);
DisA (x1,x2,da,eq);
If eq<dq Then
Begin
sa:=s1;
sb:=s2;
dq:=eq;
End;
s2:=1;
n1:=b1-a12; { s1=(b1-a12*s2)/a11 }
flg:=0;
If n1<=0 Then
Begin
s1:=0;
Inc(flg);
End;
If n1>=a11 Then
Begin
s1:=1;
Inc(flg);
End;
If flg=0 Then s1:=n1/a11;
VecX (p1,g1,s1,x1);
VecX (p2,g2,s2,x2);
DisA (x1,x2,da,eq);
If eq<dq Then
Begin
sa:=s1;
sb:=s2;
dq:=eq;
End;
End;
{ For all sa=s1, sb=s2, refresh }
VecX (p1,g1,sa,x1);
VecX (p2,g2,sb,x2);
DisA (x1,x2,da,dq);
dis:=Sqrt(dq);
End;
procedure TMainForm.aAlignDownExecute(Sender: TObject);
var sz:TRectF;
BsR:TRect;
begin
if Sender=nil then
begin
if tbSetBase.Down then
BsR := BaseRect
else
BsR := GlyphRect;
if tbSetBase.Down and chbShowGlyph.Checked and chbEditGlyph.Checked then
sgGlyph.Cells[3,1] := FloatToStr(StrToXY(sgGlyph.Cells[3,1],0)
- BsR.Bottom + GlyphRect.Bottom );
if chbShowSVG.Checked and chbEditSVG.Checked and (ColorGlyph<>nil) then
begin
sz:=SvgSize(ColorGlyph);
if chFixViewBox.Checked then
begin
BsR.Top := BsR.Top + round(ColorGlyph.ViewBox.Height);
BsR.Bottom := BsR.Bottom + round(ColorGlyph.ViewBox.Height);
end;
GlyphMatrix.dy := GlyphMatrix.dy - (sz.Bottom - BsR.Bottom * GlyphAspect);
ApplyViewBox(ColorGlyph, GlyphMatrix);
end;
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aAlignDownExecute)
end;
procedure TMainForm.aAlignHeightExecute(Sender: TObject);
var k: Double;
i: Integer;
sz:TRectF;
BsR:TRect;
begin
if Sender=nil then
begin
if tbSetBase.Down then
BsR := BaseRect
else
BsR := GlyphRect;
if tbSetBase.Down and chbShowGlyph.Checked and chbEditGlyph.Checked then
begin
k := Abs(BsR.Height/GlyphRect.Height);
for I := 1 to sgGlyph.RowCount-1 do
PathZoom(i,k);
sgGlyph.Cells[3,1] := FloatToStr(StrToXY(sgGlyph.Cells[3,1],0)
- BaseRect.Top + GlyphRect.Top*k );
sgGlyph.Cells[2,1] := FloatToStr(StrToXY(sgGlyph.Cells[2,1],0)
+ GlyphRect.Left - GlyphRect.Left*k );
FontFace.right:= Round(
FontFace.right - GlyphRect.Width + GlyphRect.Width*k );
end;
if chbShowSVG.Checked and chbEditSVG.Checked and (ColorGlyph<>nil) then
begin
sz:=SvgSize(ColorGlyph);
GlyphMatrix.m11 := GlyphMatrix.m11 / sz.Height * BsR.Height * GlyphAspect;
GlyphMatrix.m22 := GlyphMatrix.m11;
ApplyViewBox(ColorGlyph, GlyphMatrix);
end;
aAlignMidleExecute(Sender);
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aAlignHeightExecute)
end;
procedure TMainForm.aAlignMidleExecute(Sender: TObject);
var sz:TRectF;
BsR:TRect;
begin
if Sender=nil then
begin
if tbSetBase.Down then
BsR := BaseRect
else
BsR := GlyphRect;
if tbSetBase.Down and chbShowGlyph.Checked and chbEditGlyph.Checked then
sgGlyph.Cells[3,1] := FloatToStr(StrToXY(sgGlyph.Cells[3,1],0)
- (BsR.CenterPoint.Y - GlyphRect.CenterPoint.Y));
if chbShowSVG.Checked and chbEditSVG.Checked and (ColorGlyph<>nil) then
begin
sz:=SvgSize(ColorGlyph);
if chFixViewBox.Checked then
begin
BsR.Top := BsR.Top + round(ColorGlyph.ViewBox.Height);
BsR.Bottom := BsR.Bottom + round(ColorGlyph.ViewBox.Height);
end;
GlyphMatrix.dy := GlyphMatrix.dy - (sz.CenterPoint.y - BsR.CenterPoint.Y * GlyphAspect);
ApplyViewBox(ColorGlyph, GlyphMatrix);
end;
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aAlignMidleExecute)
end;
procedure TMainForm.aAlignTopExecute(Sender: TObject);
var sz:TRectF;
dy:single;
BsR:TRect;
begin
if Sender=nil then
begin
if tbSetBase.Down then
BsR := BaseRect
else
BsR := GlyphRect;
if tbSetBase.Down and chbShowGlyph.Checked and chbEditGlyph.Checked then
sgGlyph.Cells[3,1] := FloatToStr(StrToXY(sgGlyph.Cells[3,1],0)
- BsR.Top + GlyphRect.Top );
if chbShowSVG.Checked and chbEditSVG.Checked and (ColorGlyph<>nil) then
begin
sz:=SvgSize(ColorGlyph);
if chFixViewBox.Checked then
begin
BsR.Top := BsR.Top + round(ColorGlyph.ViewBox.Height);
BsR.Bottom := BsR.Bottom + round(ColorGlyph.ViewBox.Height);
end;
GlyphMatrix.dy := GlyphMatrix.dy - (sz.top - BsR.Top * GlyphAspect);
ApplyViewBox(ColorGlyph, GlyphMatrix);
end;
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aAlignTopExecute)
end;
procedure TMainForm.aAlignTopUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (treeFNT.SelectionCount>0)
and ((chbShowGlyph.Checked and chbEditGlyph.Checked and tbSetBase.Down)
or (chbShowSVG.Checked and chbEditSVG.Checked and (FocusedNode.HasChildren or (ColorGlyph <> nil)) ));
end;
procedure TMainForm.aApplyExecute(Sender: TObject);
begin
Nod.ResetXml(seGlyph.Text);
if ColorGlyph <> nil then
begin
Nod.Attribute['ColorSVG'] := Format('matrix(%.5f 0 0 %.5f %.3f %.3f)',
[GlyphMatrix.m11, GlyphMatrix.m11, GlyphMatrix.dx,GlyphMatrix.dy]);
end;
seGlyph.Modified := False;
end;
procedure TMainForm.aApplyUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (Nod <> nil) and (seGlyph.Modified);
end;
procedure TMainForm.aCenterExecute(Sender: TObject);
var sz:TRectF;
begin
if Sender=nil then
begin
if chbShowSVG.Checked and chbEditSVG.Checked and (ColorGlyph<>nil) then
begin
sz:=SvgSize(ColorGlyph);
GlyphMatrix.dx := GlyphMatrix.dx - (sz.CenterPoint.x - GlyphRect.CenterPoint.x * GlyphAspect) ;
ApplyViewBox(ColorGlyph, GlyphMatrix);
end;
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aCenterExecute)
end;
procedure TMainForm.aCenterUpdate(Sender: TObject);
begin
TAction(Sender).Enabled := (treeFNT.SelectionCount>0)
and chbShowGlyph.Checked
and chbShowSVG.Checked
and chbEditSVG.Checked
and (FocusedNode.HasChildren or(ColorGlyph <> nil));
end;
procedure TMainForm.aEdgeLeftExecute(Sender: TObject);
begin
if Sender=nil then
begin
FontFace.right:= FontFace.right - Round(seGrid.Value / zm );
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aEdgeLeftExecute)
end;
procedure TMainForm.aEdgeRightExecute(Sender: TObject);
begin
if Sender=nil then
begin
FontFace.right:= FontFace.right + Round(seGrid.Value / zm );
DrawPaint(Draw);
ApplyGlyph;
end
else ForEachSelection(aEdgeRightExecute)
end;
procedure TMainForm.aFontConfigExecute(Sender: TObject);
begin
dlgFont.Execute();
treeFNT.Indent:=abs(dlgFont.Font.Height) div 2;
treeFNT.Perform( TVM_SETITEMHEIGHT,abs(dlgFont.Font.Height) , 0);
treeFNT.Invalidate;
end;
procedure TMainForm.aFontOpenExecute(Sender: TObject);
begin
if dlgOpenSVG.Execute then
begin
if hFont<>'' then RemoveFontResource(PChar(hFont));
tbSetBase.Down := false;
if aReset.Enabled then
aReset.Execute;
Nod := nil;
dlgSave.FileName := dlgOpenSVG.FileName;
hFont := '';
if SvgFolder='' then
SvgFolder := ExtractFilePath(dlgOpenSVG.FileName);
FNT.LoadFromFile(dlgOpenSVG.FileName);
if FileExists(ChangeFileExt(dlgOpenSVG.FileName,'.OTF')) then
hFont := ChangeFileExt(dlgOpenSVG.FileName,'.OTF')
else
if FileExists(ChangeFileExt(dlgOpenSVG.FileName,'.TTF')) then
hFont := ChangeFileExt(dlgOpenSVG.FileName,'.TTF');
if hFont<>'' then
AddFontResourceEx(PChar(hFont), FR_PRIVATE ,nil);
SendMessage(HWND_BROADCAST, WM_FONTCHANGE, 0, 0) ;
FontFace.horiz_adv_x := Round(StrToFloatDef(FNT.Node['svg'].Node['defs'].Node['font'].Attribute['horiz-adv-x'], 1024));
with FNT.Node['svg'].Node['defs'].Node['font'].Node['font-face'] do
begin
FontFace.font_family := Attribute['font-family'];
FontFace.units_per_em := Round(StrToFloatDef( Attribute['units-per-em'], 2048));
FontFace.ascent := Round(StrToFloatDef( Attribute['ascent'], 1536));
FontFace.descent := Round(StrToFloatDef( Attribute['descent'], -512));
FontFace.x_height := Round(StrToFloatDef( Attribute['x-height'], 768));
FontFace.cap_height := Round(StrToFloatDef( Attribute['cap-height'], 1024));
end;
if FNT.Node['svg'].Node['metadata']=nil then
FNT.Node['svg'].Add('metadata');
if FNT.Node['svg'].Node['metadata'].Attribute['folder']<>'' then
begin
SvgFolder := ExtractFilePath(dlgOpenSVG.FileName) +'\' + FNT.Node['svg'].Node['metadata'].Attribute['folder']
end;
ZeroXY.y := - FontFace.ascent ;
if seZoom.Value>0 then
ZeroXY.y := ZeroXY.y * seZoom.Value
else
ZeroXY.y := -ZeroXY.y div seZoom.Value;
ZeroXY.x := - 100;
// hFontName := FNT.Node['svg'].Node['defs'].Node['font'].Attribute['id'];
StatusBar1.Panels[0].Text:='Font: '+ FontFace.font_family;
dlgFont.Font.Name := FontFace.font_family;
treeFNT.Indent:=abs(dlgFont.Font.Height) div 2;
treeFNT.Perform( TVM_SETITEMHEIGHT,abs(dlgFont.Font.Height) , 0);
ResetFNT;
DrawPaint(Draw);
tbClearKern.Click;
end;
end;
procedure TMainForm.aFontSaveExecute(Sender: TObject);
var
nod,n1:TXML_Nod;
s,n:string;
TempSvg:TXML_Doc;
begin
if seGlyph.Modified then
case MessageDlg('Apply XML chandes before saving?', TMsgDlgType.mtConfirmation, [mbYes,mbNo,mbAbort],0 ) of
mrYes: aApply.Execute;
// mrNo: aReset.Execute;
mrAbort:exit;
end;
if dlgSave.Execute() then
begin
FNT.SaveToFile(dlgSave.FileName);
nod := FNT;
repeat
if nod.Attribute['ColorSVG']<>'' then
begin
s := THTMLEncoding.HTML.Decode(nod.Attribute['unicode'])+#0;
s := SvgFolder + '\U+'+IntToHex(Ord(s[1]),4) +'.svg';
if FileExists(s)then
try
TempSvg:=TXML_Doc.Create;
TempSvg.LoadFromFile(s);
if not FileExists(ChangeFileExt(s,'.bak')) then
RenameFile(s,ChangeFileExt(s,'.bak'));
n1 := TempSvg;
repeat
if (n1.LocalName='svg') or (n1.LocalName='svg:svg') then
begin
if n1.Attributes.ByName('transform')<>nil then
n1.Attributes.ByName('transform').Free;
if n1.Nodes.ByID('FontFit')=nil then
begin
n := n1.Nodes.xml;
n1.Nodes.Clear;
n1 := n1.Add('g');
n1.Attribute['id'] := 'FontFit';
n1.Nodes.xml := n;
n1.Attribute['transform']:= nod.Attribute['ColorSVG'];
end
else
n1.Nodes.ByID('FontFit').Attribute['transform']:= nod.Attribute['ColorSVG'];
nod.Attributes.ByName('ColorSVG').free;
break;
end;
n1:=n1.Next;
until n1=nil;
TempSvg.SaveToFile(s);
finally
FreeAndNil(TempSvg);
end;
end;
nod := nod.Next;
until nod = nil;
end;
end;
procedure TMainForm.aFontSaveUpdate(Sender: TObject);
begin
taction(Sender).Enabled := treeFNT.Items.Count>0;
end;
procedure TMainForm.aGoToZeroExecute(Sender: TObject);
begin
// seZoom.Value := -3;
ZeroXY.y := round(- FontFace.ascent * zm);
ZeroXY.x := - 100;
DrawPaint(Draw);
end;
procedure TMainForm.aKerningApplyExecute(Sender: TObject);
var
i,j,k:integer;
n1,nod:TXML_Nod;
s:string;
sl1:TStringList;
sl2:TStringList;
begin
if MessageDlg('Apply new kernig settings?', TMsgDlgType.mtConfirmation, [mbYes,mbNo],0)<>mrYes then exit;
pbrProcessing.Position:=0;
pbrProcessing.Max := FNT.Node['svg'].Node['defs'].Node['font'].Nodes.Count + sg.RowCount-2;
pbrProcessing.Visible := True;
sl1:=TStringList.Create;
sl1.CaseSensitive:=True;
sl2:=TStringList.Create;
sl2.CaseSensitive:=True;
nod := FNT;
while nod<>nil do
begin
pbrProcessing.Position:=pbrProcessing.Position+1;
Application.ProcessMessages;
n1 := nod.next;
if nod.LocalName='hkern' then
begin
if nod.Attribute['g1']<>'' then
begin
sl1.CommaText := nod.Attribute['g1'];
sl2.CommaText := nod.Attribute['g2'];
for i := 2 to sg.RowCount-1 do
if sl1.IndexOf(sg.Cols[0][i])>-1 then
begin
for j := 2 to sg.ColCount-1 do
if sl2.IndexOf(sg.Rows[0][j])>-1 then
begin
sl2.Delete(sl2.IndexOf(sg.Rows[0][j]));
if sl2.count=0 then break;
end;
if sl2.count=0 then break;
end;
if sl2.count=0 then
nod.Free
else
nod.Attribute['g2'] := sl2.CommaText;
end
else
if nod.Attribute['u1']<>'' then
begin
sl1.Text := sg.Cols[1].Text;
sl2.Text := sg.Rows[1].Text;
if (sl1.IndexOf(THTMLEncoding.HTML.Decode(nod.Attribute['u1']))>-1) and
(sl2.IndexOf(THTMLEncoding.HTML.Decode(nod.Attribute['u2']))>-1)
then
nod.Free;
end;
{
for i := 2 to sg.RowCount-1 do
if (THTMLEncoding.HTML.Decode(nod.Attribute['u1'])=sg.Cells[1,i]) or
(pos(','+sg.Cells[0,i]+',', ','+nod.Attribute['g1']+',')>0)
then
begin
for j := 2 to sg.ColCount-1 do
if (THTMLEncoding.HTML.Decode(nod.Attribute['u2'])=sg.Cells[j,1]) then
begin
nod.Attribute['u2'] := '';
break;
end
else
if (pos(','+sg.Cells[j,0]+',', ','+nod.Attribute['g2']+',')>0)
then begin
s := StringReplace(',' + nod.Attribute['g2'] +',', ','+sg.Cells[j,0]+',', ',',[]);
if s[1]=',' then
delete(s,1,1);
if Copy(s,length(s),1) =',' then
delete(s,length(s),1);
nod.Attribute['g2'] := s;
break;
end;
end;
}
end;
nod := n1;
end;
sl1.free;
sl2.free;
for i := 2 to sg.RowCount-1 do
begin
pbrProcessing.Position:=pbrProcessing.Position+1;
for j := 2 to sg.ColCount-1 do
if sg.Cells[j,i] <> '' then
begin
sg.Objects[j,i] := nil;
nod := nil;
for k := j-1 downto 2 do
if sg.Cells[j,i]=sg.Cells[k,i] then
begin
nod :=pointer(sg.Objects[k,i]);
break;
end;
if nod=nil then
begin
nod := FNT.Node['svg'].Node['defs'].Node['font'].Nodes.Add;
nod.LocalName := 'hkern';
nod.Attribute['g1'] :=sg.Cells[0,i];
nod.Attribute['k'] :=sg.Cells[j,i];
end;
if nod.Attribute['g2']<>'' then
nod.Attribute['g2'] := nod.Attribute['g2'] + ',';
nod.Attribute['g2'] := nod.Attribute['g2'] + sg.Cells[j,0];
sg.Objects[j,i] := Nod;
end;
end;
pbrProcessing.Visible := False;
end;
procedure TMainForm.aKerningCalcExecute(Sender: TObject);
var
i,j,k,l:integer;