-
Notifications
You must be signed in to change notification settings - Fork 2
/
Pilot.sb
1422 lines (1380 loc) · 37.2 KB
/
Pilot.sb
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
' Anime Pilot - to show anime array
' Version 0.2
' Copyright © 2019-2020 Nonki Takahashi. The MIT License.
' Last update 2020-04-09
' Program ID QXF519-0
Init()
Anime_Init()
Anime_Animate()
Sub Init
title = "Anime Pilot - Rocket"
GraphicsWindow.Title = title
gw = 598
gh = 428
GraphicsWindow.Width = gw
GraphicsWindow.Height = gh
GraphicsWindow.BackgroundColor = "Black"
Not = "False=True;True=False;"
WQ = Text.GetCharacter(34)
qt = WQ
CR = Text.GetCharacter(13)
LF = Text.GetCharacter(10)
LT = "<"
UPPER = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LOWER = "abcdefghijkomnopqrstuvwxyz"
DIGIT = "0123456789"
LCHAR = UPPER + LOWER + "_"
TCHAR = LCHAR + DIGIT
maxPalette = 32
EndSub
Sub Anime_Animate
t0 = Clock.ElapsedMilliseconds
nP = 0
iT = 1
at = idxS[iT]
cont = "True"
While cont
Program.Delay(100)
now = Clock.ElapsedMilliseconds - t0
GraphicsWindow.Title = title + " | " + now + "[ms]"
If (iT <= nT) And (at <= now) Then
' action added to process
nS = Array.GetItemCount(sequence[at])
For iS = 1 To nS
seq = sequence[at][iS]
proc = seq
proc["ts"] = at
proc["te"] = at + proc["dur"]
name = proc["name"]
spr = sprite[name]
If spr["type"] = "shp" Then
Group_GetIndexOf()
grp = group[i]
If proc["func"] = "move" Then
proc["xs"] = grp["x"]
proc["ys"] = grp["y"]
ElseIf proc["func"] = "rotate" Then
proc["as"] = grp["angle"]
EndIf
Else
If proc["func"] = "move" Then
proc["xs"] = Shapes.GetLeft(spr["obj"])
proc["ys"] = Shapes.GetTop(spr["obj"])
ElseIf proc["func"] = "rotate" Then
proc["as"] = spr["angle"]
EndIf
EndIf
nP = nP + 1
process[nP] = proc
EndFor
If iT <= nT Then
iT = iT + 1
at = idxS[iT]
EndIf
EndIf
_nP = Array.GetItemCount(process)
If 0 < _nP Then
idxP = Array.GetAllIndices(process)
nD = 0
idxD = ""
For iP = 1 To _nP
' animate each process
proc = process[idxP[iP]]
name = proc["name"]
spr = sprite[name]
If spr["type"] = "shp" Then
Group_GetIndexOf()
EndIf
If proc["te"] = proc["ts"] Then
_k = 1
Else
_k = (now - proc["ts"]) / (proc["te"] - proc["ts"])
If 1 < _k Then
_k = 1
EndIf
EndIf
If proc["func"] = "move" Then
x = proc["xs"] * (1 - _k) + proc["x"] * _k
y = proc["ys"] * (1 - _k) + proc["y"] * _k
If spr["type"] = "shp" Then
Group_Move()
Else
Shapes.Move(spr["obj"], x, y)
EndIf
ElseIf proc["func"] = "rotate" Then
angle = proc["as"] * (1 - _k) + proc["angle"] * _k
If spr["type"] = "shp" Then
Group_Rotate()
Else
Shapes.Rotate(spr["obj"], angle)
spr["angle"] = angle
sprite[proc["name"]] = spr
EndIf
EndIf
If 1 <= _k Then
nD = nD + 1
idxD[nD] = idxP[iP]
EndIf
EndFor
For iD = 1 To nD
process[idxD[iD]] = ""
EndFor
ElseIf nT <= iT Then
cont = "False"
EndIf
EndWhile
EndSub
Sub Anime_DumpSequence
nT = Array.GetItemCount(sequence)
idxS = Array.GetAllIndices(sequence)
For iT = 1 To nT
at = idxS[iT]
TextWindow.WriteLine("At " + at)
seq = sequence[at]
nS = Array.GetItemCount(seq)
For iS = 1 To nS
TextWindow.WriteLine(" " + seq[iS])
EndFor
EndFor
EndSub
Sub Anime_Init
anime = ""
anime[1] = "func=load;name=Stars1;x=0;y=0;path=img/stars.png;"
anime[2] = "func=move;name=Stars1;x=0;y=428;at=0s;dur=3s;"
anime[3] = "func=move;name=Stars1;x=-598;y=0;at=3s;"
anime[4] = "func=move;name=Stars1;x=0;y=0;at=6s;dur=3s;"
anime[5] = "func=move;name=Stars1;x=0;y=-428;at=12s;dur=3s;"
anime[6] = "func=load;name=Stars2;x=0;y=-428;path=img/stars.png;"
anime[7] = "func=move;name=Stars2;x=0;y=0;at=0s;dur=3s;"
anime[8] = "func=move;name=Stars2;x=598;y=0;at=6s;dur=3s;"
anime[9] = "func=move;name=Stars2;x=0;y=428;at=9s;"
anime[10] = "func=move;name=Stars2;x=0;y=0;at=12s;dur=3s;"
anime[11] = "func=load;name=Rocket;x=208;y=154;path=Rocket.sb;"
anime[12] = "func=move;name=Rocket;x=208;y=10;at=0s;dur=3s;"
anime[13] = "func=rotate;name=Rocket;angle=-90;at=3s;dur=3s;"
anime[14] = "func=rotate;name=Rocket;angle=0;at=9s;dur=3s;"
anime[15] = "func=move;name=Rocket;x=208;y=154;at=12s;dur=3s;"
nA = Array.GetItemCount(anime)
For iA = 1 To nA
anm = anime[iA]
If anm["func"] = "load" Then
' load a sprite or an image from file
spr = ""
x = anm["x"]
y = anm["y"]
If Text.EndsWith(anm["path"], ".sb") Then
spr["type"] = "shp"
path = anm["path"]
name = anm["name"]
Shapes_Read()
If anm["scale"] = "" Then
scale = 1
Else
scale = anm["scale"]
EndIf
Group_Add()
i = nGroup
Group_Move()
Else
spr["type"] = "img"
fullPath = Program.Directory + "\" + anm["path"]
spr["obj"] = Shapes.AddImage(fullPath)
Shapes.Move(spr["obj"], x, y)
spr["angle"] = 0
EndIf
sprite[anm["name"]] = spr
Else
' add action to process array
buf = anm["dur"]
p = 1
Parse_Time()
anm["dur"] = ms
buf = anm["at"]
p = 1
Parse_Time()
anm["at"] = ms
seq = sequence[ms]
nS = Array.GetItemCount(seq)
seq[nS + 1] = anm
sequence[ms] = seq
EndIf
EndFor
Anime_SortSequence()
EndSub
Sub Anime_SortSequence
nT = Array.GetItemCount(sequence)
idxS = Array.GetAllIndices(sequence)
For jT = 1 To nT - 1
For iT = jT + 1 To nT
If idxS[iT] < idxS[jT] Then
tmp = idxS[jT]
idxS[jT] = idxS[iT]
idxS[iT] = tmp
EndIf
EndFor
EndFor
_sequence = sequence
sequence = ""
For iT = 1 To nT
sequence[idxS[iT]] = _sequence[idxS[iT]]
EndFor
EndSub
Sub CS_AddColorToPalette
' Color Selector | Add color to palette
' param color - color to set
' param maxPalette
' param nPalette
' param palette
' param tPalette - target palette
Stack.PushValue("local", i)
For i = 1 To nPalette
pltt = palette[i]
If color = pltt["color"] Then
Goto csactp_not_new_color
EndIf
EndFor
pltt = palette[tPalette]
pltt["color"] = color
palette[tPalette] = pltt
If nPalette < maxPalette Then
nPalette = nPalette + 1
EndIf
tPalette = tPalette + 1
If maxPalette < tPalette Then
tPalette = 1
EndIf
csactp_not_new_color:
i = Stack.PopValue("local")
EndSub
Sub File_GetBasename
' FIle | Get basename from path
' param path
' return basename
' return ext - extension
pPath = 1
While Text.IsSubText(Text.GetSubTextToEnd(path, pPath), "\")
iBackslash = Text.GetIndexOf(Text.GetSubTextToEnd(path, pPath), "\")
pPath = pPath + iBackslash
EndWhile
iDot = Text.GetIndexOf(Text.GetSubTextToEnd(path, pPath), ".")
_iDot = iDot
While 0 < _iDot
_iDot = Text.GetIndexOf(Text.GetSubTextToEnd(path, pPath + iDot), ".")
If 0 < _iDot Then
iDot = iDot + _iDot
EndIf
EndWhile
If 0 < iDot Then
basename = Text.GetSubText(path, pPath, iDot - 1)
ext = Text.GetSubTextToEnd(path, pPath + iDot)
Else
basename = Text.GetSubTextToEnd(path, pPath)
ext = ""
EndIf
EndSub
Sub Group_Add
' Group | add shapes to a group
' param name - group name
' param shX, shY - origin of shape array
' param scale - to resize
' param shape[] - shape array
' param nGroup - number of group
' return nGroup - updated number of group
' return group - group array
Stack.PushValue("local", i)
Stack.PushValue("local", x)
Stack.PushValue("local", y)
nGroup = nGroup + 1
grp = ""
grp["name"] = name
grp["x"] = shX
grp["y"] = shY
grp["angle"] = 0
grp["dir"] = 1
Shapes_CalcWidthAndHeight()
grp["width"] = shWidth
grp["height"] = shHeight
grp["cx"] = shWidth / 2
grp["cy"] = shHeight / 2
s = scale
grp["scale"] = s
For i = 1 To Array.GetItemCount(shape)
shp = shape[i]
GraphicsWindow.PenWidth = shp["pw"] * s
If shp["pw"] > 0 Then
GraphicsWindow.PenColor = shp["pc"]
EndIf
If Text.IsSubText("rect|ell|tri|text|btn", shp["func"]) Then
GraphicsWindow.BrushColor = shp["bc"]
EndIf
If Text.IsSubText("text|btn", shp["func"]) Then
If silverlight Then
fs = Math.Floor(shp["fs"] * 0.9)
Else
fs = shp["fs"]
EndIf
GraphicsWindow.FontSize = fs * s
GraphicsWindow.FontName = shp["fn"]
If shp["fb"] = "False" Then
GraphicsWindow.FontBold = "False"
Else
GraphicsWindow.FontBold = "True"
EndIf
EndIf
If shp["func"] = "rect" Then
shp["obj"] = Shapes.AddRectangle(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "ell" Then
shp["obj"] = Shapes.AddEllipse(shp["width"] * s, shp["height"] * s)
ElseIf shp["func"] = "tri" Then
shp["obj"] = Shapes.AddTriangle(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s, shp["x3"] * s, shp["y3"] * s)
ElseIf shp["func"] = "line" Then
shp["obj"] = Shapes.AddLine(shp["x1"] * s, shp["y1"] * s, shp["x2"] * s, shp["y2"] * s)
ElseIf shp["func"] = "text" Then
shp["obj"] = Shapes.AddText(shp["text"])
EndIf
x = shp["x"]
y = shp["y"]
shp["rx"] = x
shp["ry"] = y
If sbd And (shp["func"] = "line") Then
shp["wx"] = x
shp["wy"] = y
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_alpha = Math.GetRadians(shp["angle"])
SB_RotateWorkaround()
shp["wx"] = x
shp["wy"] = y
EndIf
If shp["func"] = "btn" Then
shp["obj"] = Controls.AddButton(shp["caption"], shX + x * s, shY + y * s)
Else
Shapes.Move(shp["obj"], shX + x * s, shY + y * s)
EndIf
If Text.IsSubText("rect|ell|tri|text", shp["func"]) And (shp["angle"] <> 0) And (shp["angle"] <> "") Then
Shapes.Rotate(shp["obj"], shp["angle"])
EndIf
shape[i] = shp
EndFor
grp["shape"] = shape
group[nGroup] = grp
y = Stack.PopValue("local")
x = Stack.PopValue("local")
i = Stack.PopValue("local")
EndSub
Sub Group_GetIndexOf
' Group | get index of a group
' param name - a group name
' return i - index of the group
i = 0 ' not found
For _i = 1 To nGroup
grp = group[_i]
If grp["name"] = name Then
i = _i
_i = nGroup ' exit For
EndIf
EndFor
EndSub
Sub Group_Move
' Group | move a group
' param group[i] - group To move
' param x, y - position To move
' return group[i] - updated group
Stack.PushValue("local", j)
grp = group[i]
s = grp["scale"]
grp["x"] = x
grp["y"] = y
shape = grp["shape"]
n = Array.GetItemCount(shape)
For j = 1 To n
shp = shape[j]
If sbd And (shp["func"] = "line") Then
_x = shp["wx"]
_y = shp["wy"]
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_x = shp["wx"]
_y = shp["wy"]
Else
_x = shp["rx"]
_y = shp["ry"]
EndIf
Shapes.Move(shp["obj"], grp["x"] + _x * s, grp["y"] + _y * s)
EndFor
group[i] = grp
j = Stack.PopValue("local")
EndSub
Sub Group_Rotate
' Group | rotate a group
' param group[i] - group to move
' param cx, cy - rotation center (if given)
' param angle - to rotate
Stack.PushValue("local", x)
Stack.PushValue("local", y)
Stack.PushValue("local", n)
grp = group[i]
shape = grp["shape"]
moved = "False"
If cx <> "" Then
moved = "True"
Else
cx = "" ' to avoid syntax error
EndIf
If cy <> "" Then
moved = "True"
Else
cy = "" ' to avoid syntax error
EndIf
If moved Then
param["x"] = grp["x"]
param["y"] = grp["y"]
param["cx"] = cx
param["cy"] = cy
param["width"] = grp["width"]
param["height"] = grp["height"]
param["scale"] = 1
param["angle"] = angle
Shapes_CalcRotateZoomPos()
grp["x"] = x
grp["y"] = y
EndIf
param["cx"] = grp["width"] / 2
param["cy"] = grp["height"] / 2
param["scale"] = grp["scale"]
grp["angle"] = angle
param["angle"] = grp["angle"]
n = Array.GetItemCount(shape)
Stack.PushValue("local", i)
For i = 1 To n
shp = shape[i]
param["x"] = shp["x"]
param["y"] = shp["y"]
param["width"] = shp["width"]
param["height"] = shp["height"]
Shapes_CalcRotateZoomPos()
shp["rx"] = x
shp["ry"] = y
alpha = shp["angle"] + grp["angle"]
If sbd And (shp["func"] = "line") And (alpha <> 0) Then
x1 = shp["x1"]
y1 = shp["y1"]
x2 = shp["x2"]
y2 = shp["y2"]
pw = shp["pw"]
SB_LineWorkaround()
shp["wx"] = x
shp["wy"] = y
ElseIf silverlight And Text.IsSubText("tri|line", shp["func"]) Then
_alpha = Math.GetRadians(alpha)
SB_RotateWorkAround()
shp["wx"] = x
shp["wy"] = y
EndIf
Shapes.Move(shp["obj"], grp["x"] + x, grp["y"] + y)
Shapes.Rotate(shp["obj"], shp["angle"] + grp["angle"])
shape[i] = shp
EndFor
i = Stack.PopValue("local")
grp["shape"] = shape
group[i] = grp
n = Stack.PopValue("local")
y = Stack.PopValue("local")
x = Stack.PopValue("local")
EndSub
Sub Math_CartesianToPolar
' Math | convert cartesian coodinate to polar coordinate
' param x, y - cartesian coordinate
' return r, a - polar coordinate
r = Math.SquareRoot(x * x + y * y)
If x = 0 And y > 0 Then
a = 90 ' [degree]
ElseIf x = 0 And y < 0 Then
a = -90
Else
a = Math.ArcTan(y / x) * 180 / Math.Pi
EndIf
If x < 0 Then
a = a + 180
ElseIf x > 0 And y < 0 Then
a = a + 360
EndIf
EndSub
Sub Parse_Angle
' param attr["transform"] - transform attribute in tag
' return angle - angle
angle = ""
If attr["transform"] <> "" Then
pAngle = 8
lAngle = Text.GetIndexOf(Text.GetSubTextToEnd(attr["transform"], pAngle), " ") - 1
angle = Text.GetSubText(attr["transform"], pAngle, lAngle)
EndIf
EndSub
Sub Parse_CalcDetectBorder
' param i - index of shapes
shp = shape[i]
If shp["func"] = "line" Then ' line
x = shp["x2"] - shp["x1"]
y = shp["y2"] - shp["y1"]
Math_CartesianToPolar()
If 180 <= a Then
a = a - 180
EndIf
shp["angle"] = a
cx = shp["x"] + Math.Abs(x) / 2
cy = shp["y"] + Math.Abs(y) / 2
len = Math.SquareRoot(x * x + y * y)
shp["_x0"] = Math.Floor(cx - len / 2)
shp["_x1"] = Math.Floor(cx + len / 2)
shp["_y0"] = cy - 4
shp["_y1"] = cy + 4
Else ' rectangle, ellipse or triangle
If shp["func"] = "tri" Then ' triangle
shp["width"] = shp["x3"]
shp["height"] = shp["y2"]
EndIf
shp["_x0"] = shp["x"]
shp["_y0"] = shp["y"]
shp["_x1"] = shp["x"] + shp["width"]
shp["_y1"] = shp["y"] + shp["height"]
EndIf
shape[i] = shp
EndSub
Sub Parse_Defs
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "defs>") Then
Stack.PushValue("local", p)
p = p + 6
Parse_Space()
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "g id=" + WQ + "g1" + WQ + ">") Then
p = p + 11
match = "True"
EndIf
_p = Stack.PopValue("local")
If Not[match] Then
p = _p
EndIf
EndIf
EndSub
Sub Parse_Ellipse
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
' return shp - shape entry
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "ellipse") Then
param = "tag=ellipse;"
Parse_FindTag() ' p is updated
Parse_GetAttrAndText()
cx = attr["cx"]
cy = attr["cy"]
rx = attr["rx"]
ry = attr["ry"]
Parse_SetStyle()
Parse_Angle()
shp = ""
shp["func"] = "ell"
shp["x"] = cx - rx - Math.Floor(pw / 2)
shp["y"] = cy - ry - Math.Floor(pw / 2)
shp["width"] = 2 * rx + pw
shp["height"] = 2 * ry + pw
shp["angle"] = angle
shp["pw"] = pw
shp["pc"] = pc
shp["bc"] = bc
match = "True"
EndIf
EndSub
Sub Parse_FindTag
' find tag from html buffer
' param["tag"] - tag name
' param["class"] - class name
' param p - pointer for buffer
' param buf - html buffer
' return tag - found tag
pSave = p
tag = ""
findNext = "True"
While findNext
findNext = "False" ' tag may be not found
pTag = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), LT + param["tag"])
If 0 < pTag Then
lTag = Text.GetLength(param["tag"]) + 1
pTag = p + pTag - 1
len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/" + param["tag"] + ">")
If len = 0 Then
lTag = 1
len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, pTag), "/>")
EndIf
If param["class"] = "" Then
len = len + lTag
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
ElseIf 0 < len Then
findNext = "True" ' tag may have different class
len = len + lTag
attr = "class=" + qt + param["class"] + qt
pAttr = pTag + lTag + 1
lAttr = Text.GetLength(attr)
If Text.GetSubText(buf, pAttr, lAttr) = attr Then
tag = Text.GetSubText(buf, pTag, len)
findNext = "False" ' found the tag
EndIf
EndIf
p = pTag + len
EndIf
EndWhile
If tag = "" Then
p = pSave
EndIf
EndSub
Sub Parse_GetAttrAndText
' get attributes and text from given tag
' param tag - given tag
' return attr[] - array of attributes in the tag
' return txt - text in the tag
' return len - length of the tag
pTag = Text.GetIndexOf(tag, " ") + 1
pEnd = Text.GetIndexOf(tag, ">")
attr = ""
While pTag <= pEnd
Parse_SkipSpaceInTag()
pEq = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), "=")
If 0 < pEq Then
pEq = pTag + pEq - 1
If Text.GetSubText(tag, pEq + 1, 1) = qt Then
pQ = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pEq + 2), qt)
If 0 < pQ Then
pQ = pEq + 2 + pQ - 1
attr[Text.GetSubText(tag, pTag, pEq - pTag)] = Text.GetSubText(tag, pEq + 2, pQ - pEq - 2)
pTag = pQ + 2
EndIf
EndIf
Else
pTag = pEnd + 1
EndIf
EndWhile
If pEnd + 1 < pTag Then
pTag = pEnd + 1
EndIf
len = Text.GetLength(tag)
txt = ""
While pTag <= len
pL = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), LT)
If pL = 0 Then
txt = Text.Append(txt, Text.GetSubTextToEnd(tag, pTag))
pTag = len + 1
Else
pL = pTag + pL - 1
txt = Text.Append(txt, Text.GetSubText(tag, pTag, pL - pTag))
pR = Text.GetIndexOf(Text.GetSubTextToEnd(tag, pTag), ">")
If 0 < pR Then
pTag = pTag + pR
Else
pTag = len + 1
EndIf
EndIf
EndWhile
EndSub
Sub Parse_GetStyleAttr
' param kw - keyword
' param attr["style"] - style attribute
' param pStyle - pointer to search in style attribute
' return value - value
pKw = Text.GetIndexOf(Text.GetSubTextToEnd(attr["style"], pStyle), kw)
If pKw = 0 Then
value = ""
Else
pValue = pStyle + pKw + Text.GetLength(kw)
pColon = Text.GetIndexOf(Text.GetSubTextToEnd(attr["style"], pValue), ";")
If pColon = 0 Then
pColon = Text.GetLength(kw) + 1
EndIf
value = Text.GetSubText(attr["style"], pValue, pColon - 1)
EndIf
EndSub
Sub Parse_Header
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
' return shp - shape entry
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "svg") Then
len = Text.GetIndexOf(Text.GetSubTextToEnd(buf, p), ">")
If 0 < len Then
tag = Text.GetSubText(buf, p, len)
Parse_GetAttrAndText()
width = attr["width"]
height = attr["height"]
p = p + len
match = "True"
EndIf
EndIf
EndSub
Sub Parse_Line
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
' return shp - shape entry
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "line") Then
param = "tag=line;"
Parse_FindTag() ' p is updated
Parse_GetAttrAndText()
Parse_SetStyle()
points = attr["x1"] + "," + attr["y1"] + " " + attr["x2"] + "," + attr["y2"]
Parse_Points()
shp = ""
shp["func"] = "line"
shp["x"] = x
shp["y"] = y
shp["width"] = width
shp["height"] = height
shp["x1"] = px[1] - x
shp["y1"] = py[1] - y
shp["x2"] = px[2] - x
shp["y2"] = py[2] - y
shp["pw"] = pw
shp["pc"] = pc
match = "True"
EndIf
EndSub
Sub Parse_Num
' param buf - buffert to parse
' param p - pointer to the buffer
' return _num - number
' return match - "True" if match
_c = Text.GetSubText(buf, p, 1)
_num = ""
match = "False"
While Text.IsSubText(DIGIT, _c)
match = "True"
_num = Text.Append(_num, _c)
p = p + 1
_c = Text.GetSubText(buf, p, 1)
EndWhile
EndSub
Sub Parse_Points
' param points - points in a polygon
' return px[], py[] - array of the points
' return x, y - left top of the points
' return width, height - size of the polygon
len = Text.GetLength(points)
px = ""
py = ""
nPoints = 1
For pPoints = 1 To len
c = Text.GetSubText(points, pPoints, 1)
While (pPoints <= len) And Text.IsSubText(DIGIT, c)
px[nPoints] = Text.Append(px[nPoints], c)
pPoints = pPoints + 1
c = Text.GetSubText(points, pPoints, 1)
EndWhile
If c = "," Then
pPoints = pPoints + 1
c = Text.GetSubText(points, pPoints, 1)
EndIf
While (pPoints <= len) And Text.IsSubText(DIGIT, c)
py[nPoints] = Text.Append(py[nPoints], c)
pPoints = pPoints + 1
c = Text.GetSubText(points, pPoints, 1)
EndWhile
If nPoints = 1 Then
xmin = px[1]
ymin = py[1]
xmax = px[1]
ymax = py[1]
Else
If px[nPoints] < xmin Then
xmin = px[nPoints]
EndIf
If py[nPoints] < ymin Then
ymin = py[nPoints]
EndIf
If xmax < px[nPoints] Then
xmax = px[nPoints]
EndIf
If ymax < py[nPoints] Then
ymax = py[nPoints]
EndIf
EndIf
If c = " " Then
nPoints = nPoints + 1
EndIf
EndFor
x = xmin
y = ymin
width = xmax - xmin
height = ymax - ymin
EndSub
Sub Parse_Polygon
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
' return shp - shape entry
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "polygon") Then
param = "tag=polygon;"
Parse_FindTag() ' p is updated
Parse_GetAttrAndText()
points = attr["points"]
Parse_Points()
Parse_SetStyle()
Parse_Angle()
shp = ""
shp["func"] = "tri"
shp["x"] = x
shp["y"] = y
shp["width"] = width
shp["height"] = height
shp["angle"] = angle
shp["x1"] = px[1] - x
shp["y1"] = py[1] - y
shp["x2"] = px[2] - x
shp["y2"] = py[2] - y
shp["x3"] = px[3] - x
shp["y3"] = py[3] - y
shp["pw"] = pw
shp["pc"] = pc
shp["bc"] = bc
match = "True"
EndIf
EndSub
Sub Parse_Rect
' param buf - SVG buffer
' param p - pointer to SVG buffer
' return match - "True" if match
' return shp - shape entry
match = "False"
If Text.StartsWith(Text.GetSubTextToEnd(buf, p), LT + "rect") Then
param = "tag=rect;"
Parse_FindTag() ' p is updated
Parse_GetAttrAndText()
x = attr["x"]
y = attr["y"]
width = attr["width"]
height = attr["height"]
Parse_SetStyle()
Parse_Angle()
shp = ""
shp["func"] = "rect"
shp["x"] = x - Math.Floor(pw / 2)
shp["y"] = y - Math.Floor(pw / 2)
shp["width"] = width + pw
shp["height"] = height + pw
shp["angle"] = angle
shp["pw"] = pw
shp["pc"] = pc
shp["bc"] = bc
match = "True"
EndIf
EndSub
Sub Parse_SetStyle
pStyle = 1
kw = "fill"
Parse_GetStyleAttr()
bc = Text.ConvertToUpperCase(value)
kw = "stroke"
Parse_GetStyleAttr()
pc = Text.ConvertToUpperCase(value)
kw = "stroke-width"
Parse_GetStyleAttr()
pw = value
EndSub
Sub Parse_SB
subname = "Shapes_Init_" + name
filename = Program.Directory + "\" + path
buf = ""
SB_AppendSub()
ptr = Text.GetIndexOf(buf, "Sub " + subname)
If ptr = 0 Then
Goto rs_exit
EndIf
' Parse "shX = ..."
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), "shX = ")
If _ptr = 0 Then
Goto rs_exit
EndIf
shX = ""
ptr = ptr + _ptr + 5
c = Text.GetSubText(buf, ptr, 1)
While Text.GetIndexOf("0123456789", c) > 0
shX = Text.Append(shX, c)
ptr = ptr + 1
c = Text.GetSubText(buf, ptr, 1)
EndWhile
' Parse "shY = ..."
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), "shY = ")
If _ptr = 0 Then
Goto rs_exit
EndIf
shY = ""
ptr = ptr + _ptr + 5
c = Text.GetSubText(buf, ptr, 1)
While Text.GetIndexOf("0123456789", c) > 0
shY = Text.Append(shY, c)
ptr = ptr + 1
c = Text.GetSubText(buf, ptr, 1)
EndWhile
' Parse "shape[i] = ..."
While "True"
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), "shape[")
If _ptr = 0 Then
Goto rs_exit
EndIf
ptr = ptr + _ptr + 5
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), "] = " + WQ)
If _ptr = 0 Then
Goto rs_exit
EndIf
i = Text.GetSubText(buf, ptr, _ptr - 1)
If (i * 1) <> (i + 0) Then ' i is not number
Goto rs_exit
EndIf
ptr = ptr + _ptr + 4
_ptr = Text.GetIndexOf(Text.GetSubTextToEnd(buf, ptr), WQ)
If _ptr = 0 Then
Goto rs_exit
EndIf
shape[nShapes + i] = Text.GetSubText(buf, ptr, _ptr - 1)
ptr = ptr + _ptr
EndWhile
rs_exit:
iMin = nShapes + 1
nShapes = Array.GetItemCount(shape)
iMax = nShapes
For i = iMin To iMax
shp = shape[i]
If shp["func"] = "tri" And (shp["y2"] < shp["y1"]) Then
shp["y2"] = shp["y1"]
shp["y1"] = shp["y3"]
shp["y3"] = shp["y2"]
shp["angle"] = shp["angle"] + 180
If shp["angle"] >= 360 Then
shp["angle"] = shp["angle"] - 360
EndIf
EndIf
shape[i] = shp
Parse_CalcDetectBorder()
If shp["pc"] <> "" Then
color = shp["pc"]
CS_AddColorToPalette()
EndIf
If shp["bc"] <> "" Then
color = shp["bc"]
CS_AddColorToPalette()
EndIf
EndFor
scale = 1
EndSub
Sub Parse_SkipSpaceInTag