-
Notifications
You must be signed in to change notification settings - Fork 67
/
VectorEnginePlugin.pck.st
3587 lines (3264 loc) · 151 KB
/
VectorEnginePlugin.pck.st
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
'From Cuis 5.0 [latest update: #4911] on 26 October 2022 at 10:46:22 am'!
'Description '!
!provides: 'VectorEnginePlugin' 1 32!
!requires: 'VMMaker' 1 7 nil!
SystemOrganization addCategory: 'VectorEnginePlugin'!
!classDefinition: #VectorEnginePlugin category: 'VectorEnginePlugin'!
SmartSyntaxInterpreterPlugin subclass: #VectorEnginePlugin
instanceVariableNames: 'targetBits morphIds edgeCounts edgeCountsWP alphaMask alphaMaskWP contour targetWidth targetHeight antiAliasingWidth subPixelDelta hop strokeWidth strokeR strokeG strokeB strokeA fillR fillG fillB fillA txA11 txA12 txA13 txA21 txA22 txA23 currentMorphId currentClipsSubmorphs clipCurrentMorph clipLeft clipTop clipRight clipBottom auxAntiAliasingWidthScaledInverse auxStrokeWidthDilatedHalf auxStrokeWidthDilatedHalfSquared auxStrokeWidthErodedHalfSquared spanLeft spanTop spanRight spanBottom prevYTruncated prevYRounded leftAtThisY rightAtThisY'
classVariableNames: ''
poolDictionaries: ''
category: 'VectorEnginePlugin'!
!classDefinition: 'VectorEnginePlugin class' category: 'VectorEnginePlugin'!
VectorEnginePlugin class
instanceVariableNames: ''!
!VectorEnginePlugin commentStamp: '<historical>' prior: 0!
Slang implementation of VectorGraphicsEngine. Based on https://www.researchgate.net/publication/267152327_Prefiltering_Antialiasing_for_General_Vector_Graphics
VectorEnginePlugin translateInDirectory: DirectoryEntry currentDirectory doInlining: true!
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 6/11/2021 12:05:12'!
antiAliasingWidth: aFloat subPixelDelta: otherFloat hopLength: anotherFloat
self
primitive: 'primAntiAliasingWidthsubPixelDeltaHopLength'
parameters: #(Float Float Float).
antiAliasingWidth := aFloat.
auxAntiAliasingWidthScaledInverse := 127.0 / aFloat.
subPixelDelta := otherFloat.
hop := anotherFloat! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 9/21/2021 20:07:36'!
clipCurrentMorph: aBoolean morphIds: aWordArray
self
primitive: 'primClipCurrentMorph'
parameters: #(Boolean WordArray).
morphIds := aWordArray.
(clipCurrentMorph and: [ aBoolean not ]) ifTrue: [
| pixelIndex |
clipTop to: clipBottom do: [ :displayY |
pixelIndex := displayY * targetWidth + clipLeft.
clipLeft to: clipRight do: [ :displayX |
morphIds at: pixelIndex put: ((morphIds at: pixelIndex) bitAnd: 16rFFFFFF00).
pixelIndex := pixelIndex + 1 ]]].
clipCurrentMorph := aBoolean! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 3/11/2021 11:00:23'!
clipLeft: l clipTop: t clipRight: r clipBottom: b
self
primitive: 'primClipLeftclipTopclipRightclipBottom'
parameters: #(SmallInteger SmallInteger SmallInteger SmallInteger).
clipLeft := l.
clipTop := t.
clipRight := r.
clipBottom := b! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 3/11/2021 11:00:29'!
currentMorphId: aNumber currentClipsSubmorphs: aBoolean
"Bound it someway to 31 or 32 bits (SmallInteger in 32 bits, or uint in 32 bits, etc...)"
self
primitive: 'primCurrentMorphIdcurrentClipsSubmorphs'
parameters: #(SmallInteger Boolean).
currentMorphId := aNumber.
currentMorphId = 0 ifTrue: [ clipCurrentMorph := false ]. "Essentially for initialization"
currentClipsSubmorphs := aBoolean.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 5/17/2021 16:29:46'!
fillR: r g: g b: b a: a
self
primitive: 'primFillRGBA'
parameters: #(Float Float Float Float).
fillR := r * 255.0.
fillG := g * 255.0.
fillB := b * 255.0.
fillA := a.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 5/13/2021 11:46:17'!
geometryTxA11: a11 a12: a12 a13: a13 a21: a21 a22: a22 a23: a23
self
primitive: 'primGeometryTxSet'
parameters: #(Float Float Float Float Float Float).
txA11 := a11.
txA12 := a12.
txA13 := a13.
txA21 := a21.
txA22 := a22.
txA23 := a23.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 7/5/2021 16:11:13'!
initializePath
self
primitive: 'primInitializePath'
parameters: #().
spanLeft := targetWidth. "drawable right. Will later be refined."
spanTop := targetHeight. "drawable bottom. Will later be refined."
spanRight := 0. "drawable left. Will later be refined."
spanBottom := 0. "drawable top. Will later be refined."
prevYRounded := 16r7FFFFFFF.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'dtl 7/27/2021 16:40:35'!
initializeTrajectoryFragment
prevYTruncated := 16r7FFFFFFF.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'dtl 7/27/2021 16:41:01'!
newTrajectoryFragment
self
primitive: 'primNewTrajectoryFragment'
parameters: #().
^ self initializeTrajectoryFragment.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 8/22/2021 16:11:57'!
pluginApiVersion
"
VectorEngineWithPlugin isPluginAvailable
API version is a SmallInteger.
Note: this is Api version, not package version. If no Api change, Api version doesn't change, regardless of changes in the Plugin or Smalltalk code.
See senders and implementors.
"
self
primitive: 'pluginApiVersion'
parameters: #().
^ 6 asOop: SmallInteger.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 8/22/2021 16:09:48'!
resetContourTop: t bottom: b contour: aFloat32Array
self
primitive: 'primReset2Contour'
parameters: #(SmallInteger SmallInteger Float32Array).
contour := aFloat32Array.
leftAtThisY := targetWidth.
rightAtThisY := 0.
t to: b do: [ :y |
contour at: y * 2 put: targetWidth.
contour at: y * 2 + 1 put: 0 ].! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 3/10/2021 10:53:54'!
spanBottom
self
primitive: 'primSpanBottom'
parameters: #().
^(spanBottom + auxStrokeWidthDilatedHalf) asInteger asOop: SmallInteger.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 4/6/2021 16:13:04'!
spanLeft
self
primitive: 'primSpanLeft'
parameters: #().
"(int(z+1)) works equally well than the more intuitive but slower (int(ceil(z))"
^(spanLeft - auxStrokeWidthDilatedHalf - subPixelDelta + 1) asInteger asOop: SmallInteger! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 4/6/2021 16:13:38'!
spanRight
self
primitive: 'primSpanRight'
parameters: #().
"Make room not just for updated mask, but also edges (hence, +1)"
^(spanRight + auxStrokeWidthDilatedHalf + subPixelDelta) asInteger +1 asOop: SmallInteger.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 4/6/2021 16:13:45'!
spanTop
self
primitive: 'primSpanTop'
parameters: #().
"(int(z+1)) works equally well than the more intuitive but slower (int(ceil(z))"
^(spanTop - auxStrokeWidthDilatedHalf + 1) asInteger asOop: SmallInteger! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 5/17/2021 16:30:15'!
strokeR: r g: g b: b a: a
self
primitive: 'primStrokeRGBA'
parameters: #(Float Float Float Float).
strokeR := r * 255.0.
strokeG := g * 255.0.
strokeB := b * 255.0.
strokeA := a.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 4/12/2021 11:21:40'!
strokeWidth: aNumber
| swErodedHalf |
self
primitive: 'primStrokeWidth'
parameters: #(Float).
self var: #swErodedHalf type: 'float'.
strokeWidth := aNumber.
auxStrokeWidthDilatedHalf := strokeWidth + antiAliasingWidth * 0.5.
auxStrokeWidthDilatedHalfSquared := auxStrokeWidthDilatedHalf * auxStrokeWidthDilatedHalf.
swErodedHalf := strokeWidth - antiAliasingWidth * 0.5.
self cCode:
'auxStrokeWidthErodedHalfSquared = swErodedHalf * fabs(swErodedHalf);'
inSmalltalk: [ auxStrokeWidthErodedHalfSquared := swErodedHalf * swErodedHalf abs ].! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 7/5/2021 17:04:09'!
targetBits: aBitmap morphIds: aWordArray edgeCounts: otherWordArray alphaMask: anotherWordArray contour: aFloat32Array targetWidth: aNumber targetHeight: otherNumber
"All arrays could be pinned instead of passing them every time!!"
self
primitive: 'primSetTarget'
parameters: #(WordArray WordArray WordArray WordArray Float32Array SmallInteger SmallInteger).
targetBits := aBitmap.
morphIds := aWordArray.
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
contour := aFloat32Array.
targetWidth := aNumber.
targetHeight := otherNumber.! !
!VectorEnginePlugin methodsFor: 'accessing' stamp: 'jmv 7/5/2021 17:04:14'!
targetBits: aBitmap morphIds: aWordArray edgeCountsWP: otherByteArray alphaMaskWP: anotherByteArray contour: aFloat32Array targetWidth: aNumber targetHeight: otherNumber
"All arrays could be pinned instead of passing them every time!!"
self
primitive: 'primSetTargetWP'
parameters: #(WordArray WordArray ByteArray ByteArray Float32Array SmallInteger SmallInteger).
targetBits := aBitmap.
morphIds := aWordArray.
edgeCountsWP := otherByteArray.
alphaMaskWP := anotherByteArray.
contour := aFloat32Array.
targetWidth := aNumber.
targetHeight := otherNumber.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 9/15/2021 15:09:43'!
arcCenterX: centerX centerY: centerY radiusX: radiusPointX radiusY: radiusPointY start: startAngle sweep: sweepAngle rotationCos: tthetaCos rotationSin: tthetaSin edgeCounts: otherWordArray alphaMask: anotherWordArray contour: aFloat32Array
| tcx tcy trx try scale hops d angle xp yp x y |
self
primitive: 'primArc'
parameters: #(Float Float Float Float Float Float Float Float WordArray WordArray Float32Array).
self var: #tcx type: 'float'.
self var: #tcy type: 'float'.
self var: #trx type: 'float'.
self var: #try type: 'float'.
self var: #scale type: 'float'.
self var: #angle type: 'float'.
self var: #xp type: 'float'.
self var: #yp type: 'float'.
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #hops type: 'int'.
self var: #d type: 'float'.
tcx := (centerX * txA11) + (centerY * txA12) + txA13.
tcy := (centerX * txA21) + (centerY * txA22) + txA23.
self cCode: 'scale = sqrt(txA11*txA11 + txA21*txA21);'
inSmalltalk: [scale := (txA11 squared + txA21 squared) sqrt].
trx := radiusPointX * scale.
try := radiusPointY * scale.
hops := ((trx max: try) * (self cCode: 'fabs(sweepAngle)' inSmalltalk: [sweepAngle abs]) / hop) asInteger + 2.
d := hops.
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
contour := aFloat32Array.
0 to: hops do: [ :h |
self cCode: 'angle = ((float)h / d) * sweepAngle + startAngle;'
inSmalltalk: [angle := h / d * sweepAngle + startAngle ].
xp := angle cos * trx.
yp := angle sin * try.
x := tthetaCos * xp - (tthetaSin * yp) + tcx.
y := tthetaSin * xp + (tthetaCos * yp) + tcy.
spanLeft := spanLeft min: x.
spanTop := spanTop min: y.
spanRight := spanRight max: x.
spanBottom := spanBottom max: y.
self updateAlphasForX: x y: y.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: x y: y ].
self updateContourForX: x y: y. ].! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 7/5/2021 15:54:16'!
cubicBezierFromX: xFrom y: yFrom toX: xTo y: yTo control1X: xControl1 y: yControl1 control2X: xControl2 y: yControl2 edgeCounts: otherWordArray alphaMask: anotherWordArray contour: aFloat32Array
self
primitive: 'primCubicBezier'
parameters: #(Float Float Float Float Float Float Float Float WordArray WordArray Float32Array).
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
contour := aFloat32Array.
self pvt_cubicBezierFromX: xFrom y: yFrom toX: xTo y: yTo control1X: xControl1 y: yControl1 control2X: xControl2 y: yControl2! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 7/5/2021 15:57:23'!
lineFromX: xFrom y: yFrom toX: xTo y: yTo edgeCounts: otherWordArray alphaMask: anotherWordArray contour: aFloat32Array
self
primitive: 'primLine'
parameters: #(Float Float Float Float WordArray WordArray Float32Array).
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
contour := aFloat32Array.
self pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 10/12/2021 09:58:38'!
pvt_cubicBezierFromX: xFrom y: yFrom toX: xTo y: yTo control1X: xControl1 y: yControl1 control2X: xControl2 y: yControl2
| txFrom tyFrom txTo tyTo txControl1 tyControl1 txControl2 tyControl2 dx dy dx2 dy2 dx3 dy3 hops xMinEnd xMaxEnd yMinEnd yMaxEnd t oneLessT increment f1 f23 f2 f3 f4 x y |
self var: #xFrom type: 'float'.
self var: #yFrom type: 'float'.
self var: #xTo type: 'float'.
self var: #yTo type: 'float'.
self var: #xControl1 type: 'float'.
self var: #yControl1 type: 'float'.
self var: #xControl2 type: 'float'.
self var: #yControl2 type: 'float'.
self var: #txFrom type: 'float'.
self var: #tyFrom type: 'float'.
self var: #txTo type: 'float'.
self var: #tyTo type: 'float'.
self var: #txControl1 type: 'float'.
self var: #tyControl1 type: 'float'.
self var: #txControl2 type: 'float'.
self var: #tyControl2 type: 'float'.
self var: #dx type: 'float'.
self var: #dy type: 'float'.
self var: #dx2 type: 'float'.
self var: #dy2 type: 'float'.
self var: #dx3 type: 'float'.
self var: #dy3 type: 'float'.
self var: #hops type: 'int'.
self var: #t type: 'float'.
self var: #oneLessT type: 'float'.
self var: #increment type: 'float'.
self var: #f1 type: 'float'.
self var: #f23 type: 'float'.
self var: #f2 type: 'float'.
self var: #f3 type: 'float'.
self var: #f4 type: 'float'.
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #xMinEnd type: 'float'.
self var: #xMaxEnd type: 'float'.
self var: #yMinEnd type: 'float'.
self var: #yMaxEnd type: 'float'.
txFrom := (xFrom * txA11) + (yFrom * txA12) + txA13.
tyFrom := (xFrom * txA21) + (yFrom * txA22) + txA23.
txTo := (xTo * txA11) + (yTo * txA12) + txA13.
tyTo := (xTo * txA21) + (yTo * txA22) + txA23.
txControl1 := (xControl1 * txA11) + (yControl1 * txA12) + txA13.
tyControl1 := (xControl1 * txA21) + (yControl1 * txA22) + txA23.
txControl2 := (xControl2 * txA11) + (yControl2 * txA12) + txA13.
tyControl2 := (xControl2 * txA21) + (yControl2 * txA22) + txA23.
self cCode: '
dx = fabs(txControl1-txFrom);
dx2 = fabs(txTo-txControl2);
dx3 = fabs(txControl2-txControl1);
dy = fabs(tyControl1-tyFrom);
dy2 = fabs(tyTo-tyControl2);
dy3 = fabs(tyControl2-tyControl1);'
inSmalltalk: [
dx := (txControl1-txFrom) abs.
dx2 := (txTo-txControl2) abs.
dx3 := (txControl2-txControl1) abs.
dy := (tyControl1-tyFrom) abs.
dy2 := (tyTo-tyControl2) abs.
dy3 := (tyControl2-tyControl1) abs ].
dx := (dx max: dx2) * 3 max: dx3 * 1.5.
dy := (dy max: dy2) * 3 max: dy3 * 1.5.
hops := ((dx max: dy) / hop) asInteger + 1.
"This computed span of the Bezier curve is a bit pessimistic (larger than strict bounds), but safe."
xMinEnd := txFrom min: txTo.
xMaxEnd := txFrom max: txTo.
yMinEnd := tyFrom min: tyTo.
yMaxEnd := tyFrom max: tyTo.
spanLeft := spanLeft min: (xMinEnd min: xMinEnd*0.25 + ((txControl1 min: txControl2)*0.75)).
spanRight := spanRight max: (xMaxEnd max: xMaxEnd*0.25 + ((txControl1 max: txControl2)*0.75)).
spanTop := spanTop min: (yMinEnd min: yMinEnd*0.25 + ((tyControl1 min: tyControl2)*0.75)).
spanBottom := spanBottom max: (yMaxEnd max: yMaxEnd*0.25 + ((tyControl1 max: tyControl2)*0.75)).
t := 0.0.
increment := 1.0 / hops.
[ t < 1.0 ] whileTrue: [
oneLessT := 1.0 - t.
f1 := oneLessT * oneLessT * oneLessT.
f23 := 3.0 * oneLessT * t.
f2 := f23 * oneLessT.
f3 := f23 * t.
f4 := t * t * t.
x := (f1 * txFrom) + (f2 * txControl1) + (f3 * txControl2) + (f4 * txTo).
y := (f1 * tyFrom) + (f2 * tyControl1) + (f3 * tyControl2) + (f4 * tyTo).
self updateAlphasForX: x y: y.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: x y: y ].
self updateContourForX: x y: y.
t := t + increment. ].
self updateAlphasForX: txTo y: tyTo.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: txTo y: tyTo ].
self updateContourForX: txTo y: tyTo.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 10/12/2021 10:18:55'!
pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo
| txFrom tyFrom txTo tyTo dx dy hops t oneLessT increment x y |
self var: #xFrom type: 'float'.
self var: #yFrom type: 'float'.
self var: #xTo type: 'float'.
self var: #yTo type: 'float'.
self var: #txFrom type: 'float'.
self var: #tyFrom type: 'float'.
self var: #txTo type: 'float'.
self var: #tyTo type: 'float'.
self var: #dx type: 'float'.
self var: #dy type: 'float'.
self var: #hops type: 'int'.
self var: #t type: 'float'.
self var: #oneLessT type: 'float'.
self var: #increment type: 'float'.
self var: #x type: 'float'.
self var: #y type: 'float'.
txFrom := (xFrom * txA11) + (yFrom * txA12) + txA13.
tyFrom := (xFrom * txA21) + (yFrom * txA22) + txA23.
txTo := (xTo * txA11) + (yTo * txA12) + txA13.
tyTo := (xTo * txA21) + (yTo * txA22) + txA23.
dx := txTo-txFrom.
dy := tyTo-tyFrom.
self cCode: '
dx = fabs(dx);
dy = fabs(dy);'
inSmalltalk: [
dx := dx abs.
dy := dy abs ].
hops := ((dx max: dy) / hop) asInteger + 1.
spanLeft := spanLeft min: (txFrom min: txTo).
spanRight := spanRight max: (txFrom max: txTo).
spanTop := spanTop min: (tyFrom min: tyTo).
spanBottom := spanBottom max: (tyFrom max: tyTo).
t := 0.0.
increment := 1.0 / hops.
[ t < 1.0 ] whileTrue: [
oneLessT := 1.0 - t.
x := (oneLessT * txFrom) + (t * txTo).
y := (oneLessT * tyFrom) + (t * tyTo).
self updateAlphasForX: x y: y.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: x y: y ].
self updateContourForX: x y: y.
t := t + increment. ].
self updateAlphasForX: txTo y: tyTo.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: txTo y: tyTo ].
self updateContourForX: txTo y: tyTo.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 7/22/2021 23:22:55'!
pvt_quadraticBezierFromX: xFrom y: yFrom toX: xTo y: yTo controlX: xControl y: yControl
| txFrom tyFrom txTo tyTo txControl tyControl dx dy dx2 dy2 length xMinEnd xMaxEnd yMinEnd yMaxEnd t0 x0 y0 t oneLessT increment f1 f2 f3 x y correction |
self var: #xFrom type: 'float'.
self var: #yFrom type: 'float'.
self var: #xTo type: 'float'.
self var: #yTo type: 'float'.
self var: #xControl type: 'float'.
self var: #yControl type: 'float'.
self var: #txFrom type: 'float'.
self var: #tyFrom type: 'float'.
self var: #txTo type: 'float'.
self var: #tyTo type: 'float'.
self var: #txControl type: 'float'.
self var: #tyControl type: 'float'.
self var: #dx type: 'float'.
self var: #dy type: 'float'.
self var: #dx2 type: 'float'.
self var: #dy2 type: 'float'.
self var: #length type: 'float'.
self var: #correction type: 'float'.
self var: #t0 type: 'float'.
self var: #x0 type: 'float'.
self var: #y0 type: 'float'.
self var: #t type: 'float'.
self var: #oneLessT type: 'float'.
self var: #increment type: 'float'.
self var: #f1 type: 'float'.
self var: #f2 type: 'float'.
self var: #f3 type: 'float'.
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #xMinEnd type: 'float'.
self var: #xMaxEnd type: 'float'.
self var: #yMinEnd type: 'float'.
self var: #yMaxEnd type: 'float'.
"If control point is bogus, just draw a line"
(xControl = xTo and: [ yControl = yTo ]) ifTrue: [
^self pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo ].
(xControl = xFrom and: [ yControl = yFrom ]) ifTrue: [
^self pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo ].
txFrom := (xFrom * txA11) + (yFrom * txA12) + txA13.
tyFrom := (xFrom * txA21) + (yFrom * txA22) + txA23.
txTo := (xTo * txA11) + (yTo * txA12) + txA13.
tyTo := (xTo * txA21) + (yTo * txA22) + txA23.
txControl := (xControl * txA11) + (yControl * txA12) + txA13.
tyControl := (xControl * txA21) + (yControl * txA22) + txA23.
self cCode: '
dx = fabs(txTo-txFrom);
dx2 = fabs(txControl-txFrom);
dy = fabs(tyTo-tyFrom);
dy2 = fabs(tyControl-tyFrom);'
inSmalltalk: [
dx := (txTo-txFrom) abs.
dx2 := (txControl-txFrom) abs.
dy := (tyTo-tyFrom) abs.
dy2 := (tyControl-tyFrom) abs.].
"If almost a vertical line, just draw a line. (Ignoring control point)"
(dx < 1.0 and: [dx2 < 1.0]) ifTrue: [
^self pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo ].
"If almost an horizontal line, just draw a line. (Ignoring control point)"
(dy < 1.0 and: [dy2 < 1.0]) ifTrue: [
^self pvt_lineFromX: xFrom y: yFrom toX: xTo y: yTo ].
"This computed span of the Bezier curve is a bit pessimistic (larger than strict bounds), but safe."
xMinEnd := txFrom min: txTo.
xMaxEnd := txFrom max: txTo.
yMinEnd := tyFrom min: tyTo.
yMaxEnd := tyFrom max: tyTo.
spanLeft := spanLeft min: (xMinEnd min: (xMinEnd+txControl) / 2.0).
spanRight := spanRight max: (xMaxEnd max: (xMaxEnd+txControl) / 2.0).
spanTop := spanTop min: (yMinEnd min: (yMinEnd+tyControl) / 2.0).
spanBottom := spanBottom max: (yMaxEnd max: (yMaxEnd+tyControl) / 2.0).
"Case t = 0.0"
x := txFrom.
y := tyFrom.
self updateAlphasForX: x y: y.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: x y: y ].
self updateContourForX: x y: y.
"Will be corrected for each hop. This, being close to pointFrom, is a good initial guess for first correction."
increment := 0.5 / (dx max: dy) min: 0.5.
t := 0.0.
[
t0 := t. x0 := x. y0 := y.
"Compute next point"
t := t0 + increment. oneLessT := 1.0 - t.
f1 := oneLessT * oneLessT. f2 := 2.0 * oneLessT * t. f3 := t * t.
x := (f1 * txFrom) + (f2 * txControl) + (f3 * txTo).
y := (f1 * tyFrom) + (f2 * tyControl) + (f3 * tyTo).
"Now adjust the increment to aim at the required hop length, and recompute next point."
dx := x-x0. dy := y-y0.
self cCode: '
length = sqrt(dx*dx + dy*dy);'
inSmalltalk: [ length := ((dx*dx) + (dy*dy)) sqrt ].
correction := hop / length.
[
increment := increment / length * hop.
t := t0 + increment. oneLessT := 1.0 - t.
f1 := oneLessT * oneLessT. f2 := 2.0 * oneLessT * t. f3 := t * t.
x := (f1 * txFrom) + (f2 * txControl) + (f3 * txTo).
y := (f1 * tyFrom) + (f2 * tyControl) + (f3 * tyTo).
dx := x-x0. dy := y-y0.
self cCode: '
length = sqrt(dx*dx + dy*dy);'
inSmalltalk: [ length := ((dx*dx) + (dy*dy)) sqrt ].
correction := hop / length.
correction < 1.0] whileTrue. "Keep adjusting if hop would be too big"
t < 1.0 ]
whileTrue: [
self updateAlphasForX: x y: y.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: x y: y ].
self updateContourForX: x y: y ].
"Case t= 1.0"
self updateAlphasForX: txTo y: tyTo.
fillA = 0.0 ifFalse: [
self updateEdgeCountAtX: txTo y: tyTo ].
self updateContourForX: txTo y: tyTo.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 7/5/2021 15:59:47'!
quadraticBezierFromX: xFrom y: yFrom toX: xTo y: yTo controlX: xControl y: yControl edgeCounts: otherWordArray alphaMask: anotherWordArray contour: aFloat32Array
self
primitive: 'primQuadraticBezier'
parameters: #(Float Float Float Float Float Float WordArray WordArray Float32Array).
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
contour := aFloat32Array.
self pvt_quadraticBezierFromX: xFrom y: yFrom toX: xTo y: yTo controlX: xControl y: yControl.! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 5/18/2021 10:53:25'!
updateAlphasForX: x y: y
| t b l r pixelIndex candidateAlpha alphaWord redAlpha greenAlpha blueAlpha doUpdate distanceToAxisSquared dy dySquared dx dxp |
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #candidateAlpha type: 'uint32_t'.
self var: #alphaWord type: 'uint32_t'.
self var: #redAlpha type: 'uint32_t'.
self var: #greenAlpha type: 'uint32_t'.
self var: #blueAlpha type: 'uint32_t'.
self var: #distanceToAxisSquared type: 'float'.
self var: #dy type: 'float'.
self var: #dySquared type: 'float'.
self var: #dx type: 'float'.
self var: #dxSquared type: 'float'.
self var: #dxp type: 'float'.
"Compute affected rect. Honor clipRect"
t := (y - auxStrokeWidthDilatedHalf + 1) asInteger. "(int(z+1)) works equally well than the more intuitive but slower (int(ceil(z))"
t < clipTop ifTrue: [ t := clipTop ].
b := (y + auxStrokeWidthDilatedHalf) asInteger.
b > clipBottom ifTrue: [ b := clipBottom ].
l := (x - auxStrokeWidthDilatedHalf - subPixelDelta + 1) asInteger. "(int(z+1)) works equally well than the more intuitive but slower (int(ceil(z))"
l < clipLeft ifTrue: [ l := clipLeft ].
r := (x + auxStrokeWidthDilatedHalf + subPixelDelta) asInteger.
r > clipRight ifTrue: [ r := clipRight ].
t to: b do: [ :displayY |
pixelIndex := displayY * targetWidth + l -1.
dy := displayY - y.
dySquared := dy * dy.
l to: r do: [ :displayX |
pixelIndex := pixelIndex + 1.
alphaWord := alphaMask at: pixelIndex.
alphaWord = 16r007F7F7F ifFalse: [
redAlpha := alphaWord bitAnd: 16r7F0000.
greenAlpha := alphaWord bitAnd: 16r7F00.
blueAlpha := alphaWord bitAnd: 16r7F.
doUpdate := false.
dx := displayX - x.
"Red"
dxp := dx - subPixelDelta.
distanceToAxisSquared := dxp * dxp + dySquared.
distanceToAxisSquared < auxStrokeWidthDilatedHalfSquared
ifTrue: [
distanceToAxisSquared <= auxStrokeWidthErodedHalfSquared
ifTrue: [
candidateAlpha := 16r7F0000 ]
ifFalse: [
self cCode: '
candidateAlpha = (uint32_t)((auxStrokeWidthDilatedHalf - (sqrt(distanceToAxisSquared))) * auxAntiAliasingWidthScaledInverse);
candidateAlpha = candidateAlpha << 16;'
inSmalltalk: [
candidateAlpha := (auxStrokeWidthDilatedHalf - distanceToAxisSquared sqrt * auxAntiAliasingWidthScaledInverse) asInteger.
candidateAlpha := candidateAlpha bitShift: 16 ]].
candidateAlpha > redAlpha ifTrue: [
doUpdate := true.
redAlpha := candidateAlpha ]].
"Green"
distanceToAxisSquared := dx * dx + dySquared.
distanceToAxisSquared < auxStrokeWidthDilatedHalfSquared
ifTrue: [
distanceToAxisSquared <= auxStrokeWidthErodedHalfSquared
ifTrue: [
candidateAlpha := 16r7F00 ]
ifFalse: [
self cCode: '
candidateAlpha = (uint32_t)((auxStrokeWidthDilatedHalf - (sqrt(distanceToAxisSquared))) * auxAntiAliasingWidthScaledInverse);
candidateAlpha = candidateAlpha << 8;'
inSmalltalk: [
candidateAlpha := (auxStrokeWidthDilatedHalf - distanceToAxisSquared sqrt * auxAntiAliasingWidthScaledInverse) asInteger.
candidateAlpha := candidateAlpha bitShift: 8 ]].
candidateAlpha > greenAlpha ifTrue: [
doUpdate := true.
greenAlpha := candidateAlpha ]].
"Blue"
dxp := dx + subPixelDelta.
distanceToAxisSquared := dxp * dxp + dySquared.
distanceToAxisSquared < auxStrokeWidthDilatedHalfSquared
ifTrue: [
distanceToAxisSquared <= auxStrokeWidthErodedHalfSquared
ifTrue: [
candidateAlpha := 16r7F ]
ifFalse: [
self cCode: '
candidateAlpha = (uint32_t)((auxStrokeWidthDilatedHalf - (sqrt(distanceToAxisSquared))) * auxAntiAliasingWidthScaledInverse);'
inSmalltalk: [
candidateAlpha := (auxStrokeWidthDilatedHalf - distanceToAxisSquared sqrt * auxAntiAliasingWidthScaledInverse) asInteger ].
].
candidateAlpha > blueAlpha ifTrue: [
doUpdate := true.
blueAlpha := candidateAlpha ]].
doUpdate ifTrue: [
alphaWord := (redAlpha bitOr: greenAlpha) bitOr: blueAlpha.
alphaMask at: pixelIndex put: alphaWord ]]]]! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 7/5/2021 16:22:38'!
updateContourForX: x y: y
"The Contour of the current morph is the pixel area affected, but without holes.
For each y line where a pixel is affected, record the leftmost and rightmost affected pixels.
Note: Only includes pen trajectory, but not stroke width."
| thisYRounded |
self var: #x type: 'float'.
self var: #y type: 'float'.
thisYRounded := (y + 0.5) asInteger.
(thisYRounded between: 0 and: targetHeight-1) ifTrue: [
thisYRounded = prevYRounded ifFalse: [
prevYRounded = 16r7FFFFFFF ifFalse: [
contour at: prevYRounded * 2 put: leftAtThisY.
contour at: prevYRounded * 2 + 1 put: rightAtThisY ].
leftAtThisY := contour at: thisYRounded * 2.
rightAtThisY := contour at: thisYRounded * 2 + 1.
prevYRounded := thisYRounded ].
leftAtThisY := leftAtThisY min: x.
rightAtThisY := rightAtThisY max: x ].! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 8/22/2021 16:09:52'!
updateContourLastLine: aFloat32Array
self
primitive: 'primUpdate2ContourLastLine'
parameters: #(Float32Array).
contour := aFloat32Array.
prevYRounded = 16r7FFFFFFF ifFalse: [
contour at: prevYRounded * 2 put: leftAtThisY.
contour at: prevYRounded * 2 + 1 put: rightAtThisY ].! !
!VectorEnginePlugin methodsFor: 'paths algorithms' stamp: 'jmv 5/18/2021 10:07:05'!
updateEdgeCountAtX: x y: y
"Compute edges intersecting with this horizontal line, for fills."
| thisYTruncated pixelY pixelIndexBase redPixelIndex greenPixelIndex bluePixelIndex redIncrement greenIncrement blueIncrement countWord redCount greenCount blueCount rest redOffset greenOffset blueOffset |
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #countWord type: 'uint32_t'.
self var: #redCount type: 'uint32_t'.
self var: #greenCount type: 'uint32_t'.
self var: #blueCount type: 'uint32_t'.
self var: #redIncrement type: 'uint32_t'.
self var: #greenIncrement type: 'uint32_t'.
self var: #blueIncrement type: 'uint32_t'.
thisYTruncated := y asInteger. "truncated, both in C and Smalltalk"
thisYTruncated = prevYTruncated ifTrue: [
^ 0].
(thisYTruncated between: clipTop-1 and: clipBottom) ifFalse: [
^ 0 ].
prevYTruncated = 16r7FFFFFFF ifTrue: [
prevYTruncated := thisYTruncated.
^ 0 ].
thisYTruncated > prevYTruncated
ifTrue: [
pixelY := thisYTruncated.
redIncrement := 16r010000.
greenIncrement := 16r0100.
blueIncrement := 16r01 ]
ifFalse: [
pixelY := prevYTruncated.
redIncrement := 16rFF0000.
greenIncrement := 16rFF00.
blueIncrement := 16rFF ].
prevYTruncated := thisYTruncated.
"All edge count at the left of the clipRect are added there (at the left of the clipRect).
The effect is the same, and we need to clean up less stuff afterwards.
More important, it avoids trying to acess pixels outside our form, i.e. invalid array acesses."
pixelIndexBase := pixelY * targetWidth.
redOffset := (x+subPixelDelta+1) asInteger max: clipLeft. "take the next red subpixel center to the right of x"
greenOffset := (x+1) asInteger max: clipLeft. "take the next green subpixel center to the right of x"
blueOffset := (x-subPixelDelta+1) asInteger max: clipLeft. "take the next blue subpixel center to the right of x"
redPixelIndex := pixelIndexBase + redOffset.
greenPixelIndex := pixelIndexBase + greenOffset.
bluePixelIndex := pixelIndexBase + blueOffset.
"Three possible cases here: RGB in one word (pixel); RG in one, and G in another; R in one, GB in another"
redPixelIndex = bluePixelIndex
ifTrue: [ "First case: RGB in the same word"
redOffset <= clipRight ifTrue: [
countWord := edgeCounts at: redPixelIndex.
redCount := (countWord + redIncrement) bitAnd: 16rFF0000.
greenCount := (countWord + greenIncrement) bitAnd: 16rFF00.
blueCount := (countWord + blueIncrement) bitAnd: 16rFF.
countWord := (redCount bitOr: greenCount) bitOr: blueCount.
edgeCounts at: redPixelIndex put: countWord ].
]
ifFalse: [
redPixelIndex = greenPixelIndex
ifTrue: [ "Second case: RG in one word, B in previous"
redOffset <= clipRight ifTrue: [
countWord := edgeCounts at: redPixelIndex.
redCount := (countWord + redIncrement) bitAnd: 16rFF0000.
greenCount := (countWord + greenIncrement) bitAnd: 16rFF00.
rest := countWord bitAnd: 16rFF.
countWord := (redCount bitOr: greenCount) bitOr: rest.
edgeCounts at: redPixelIndex put: countWord ].
blueOffset <= clipRight ifTrue: [
countWord := edgeCounts at: bluePixelIndex.
rest := countWord bitAnd: 16rFFFF00.
blueCount := (countWord + blueIncrement) bitAnd: 16rFF.
countWord := rest bitOr: blueCount.
edgeCounts at: bluePixelIndex put: countWord ].
]
ifFalse: [ "Third case: R in one word, GB in the previous"
redOffset <= clipRight ifTrue: [
countWord := edgeCounts at: redPixelIndex.
redCount := (countWord + redIncrement) bitAnd: 16rFF0000.
rest := countWord bitAnd: 16rFFFF.
countWord := redCount bitOr: rest.
edgeCounts at: redPixelIndex put: countWord ].
blueOffset <= clipRight ifTrue: [
countWord := edgeCounts at: bluePixelIndex.
rest := countWord bitAnd: 16rFF0000.
greenCount := (countWord + greenIncrement) bitAnd: 16rFF00.
blueCount := (countWord + blueIncrement) bitAnd: 16rFF.
countWord := (rest bitOr: greenCount) bitOr: blueCount.
edgeCounts at: bluePixelIndex put: countWord ].
]
].! !
!VectorEnginePlugin methodsFor: 'text and multi paths' stamp: 'dtl 7/27/2021 16:41:33'!
displayString: aString from: startIndex to: stopIndex atx: destX y: destY scalex: sx y: sy contourData: contourData contourDataIndexes: contourDataIndexes useST80Glyphs: aBoolean edgeCounts: otherWordArray alphaMask: anotherWordArray
| answer nextGlyphX nextGlyphY ttMoveToX ttMoveToY ttEndX ttEndY ttControlX ttControlY advanceWidth numContours contourStartX contourStartY numBeziers startX startY endX endY controlX controlY dx dy iso8859s15 i xMinEnd xMaxEnd yMinEnd yMaxEnd length t0 x0 y0 t oneLessT increment f1 f2 f3 x y correction |
self
primitive: 'primDisplayString'
parameters: #(String SmallInteger SmallInteger Float Float Float Float Float32Array IntegerArray Boolean WordArray WordArray).
self var: #answer type: 'double'.
self var: #nextGlyphX type: 'float'.
self var: #nextGlyphY type: 'float'.
self var: #ttMoveToX type: 'float'.
self var: #ttMoveToY type: 'float'.
self var: #ttEndX type: 'float'.
self var: #ttEndY type: 'float'.
self var: #ttControlX type: 'float'.
self var: #ttControlY type: 'float'.
self var: #advanceWidth type: 'float'.
self var: #contourStartX type: 'float'.
self var: #contourStartY type: 'float'.
self var: #startX type: 'float'.
self var: #startY type: 'float'.
self var: #endX type: 'float'.
self var: #endY type: 'float'.
self var: #controlX type: 'float'.
self var: #controlY type: 'float'.
self var: #dx type: 'float'.
self var: #dy type: 'float'.
self var: #iso8859s15 type: 'uint8_t'.
self var: #length type: 'float'.
self var: #correction type: 'float'.
self var: #t0 type: 'float'.
self var: #x0 type: 'float'.
self var: #y0 type: 'float'.
self var: #t type: 'float'.
self var: #oneLessT type: 'float'.
self var: #increment type: 'float'.
self var: #f1 type: 'float'.
self var: #f2 type: 'float'.
self var: #f3 type: 'float'.
self var: #x type: 'float'.
self var: #y type: 'float'.
self var: #xMinEnd type: 'float'.
self var: #xMaxEnd type: 'float'.
self var: #yMinEnd type: 'float'.
self var: #yMaxEnd type: 'float'.
edgeCounts := otherWordArray.
alphaMask := anotherWordArray.
txA11 := txA11 * sx.
txA12 := txA12 * sy.
txA21 := txA21 * sx.
txA22 := txA22 * sy.
nextGlyphX := destX / sx.
nextGlyphY := destY / sy.
startIndex-1 to: stopIndex-1 do: [ :charIndex |
self cCode:
'iso8859s15 = aString[charIndex];'
inSmalltalk: [
iso8859s15 := (aString at: charIndex+1) iso8859s15Code. ].
aBoolean ifTrue: [
iso8859s15 = 95 ifTrue: [ iso8859s15 := 28 ]. "If underscore, use left arrow"
iso8859s15 = 94 ifTrue: [ iso8859s15 := 30 ]. "If caret, use up arrow"
].
i := contourDataIndexes at: iso8859s15.
i := i - 1.
advanceWidth := contourData at: i. i := i + 5.
numContours := (contourData at: i) asInteger. i := i + 1.
1 to: numContours do: [ :idx |
numBeziers := (contourData at: i) asInteger. i := i + 1.
ttMoveToX := (contourData at: i) + nextGlyphX. i := i + 1.
ttMoveToY := (contourData at: i) + nextGlyphY. i := i + 1.
startX := (ttMoveToX * txA11) + (ttMoveToY * txA12) + txA13.
startY := (ttMoveToX * txA21) + (ttMoveToY * txA22) + txA23.
contourStartX := startX.
contourStartY := startY.
self initializeTrajectoryFragment.
1 to: numBeziers do: [ :idx2 |
ttEndX := contourData at: i. i := i + 1.
ttEndY := contourData at: i. i := i + 1.
ttControlX := contourData at: i. i := i + 1.
ttControlY := contourData at: i. i := i + 1.
endX := (ttEndX * txA11) + (ttEndY * txA12) + startX.
endY := (ttEndX * txA21) + (ttEndY * txA22) + startY.
controlX := (ttControlX * txA11) + (ttControlY * txA12) + startX.
controlY := (ttControlX * txA21) + (ttControlY * txA22) + startY.
"This computed span of the Bezier curve is a bit pessimistic (larger than strict bounds), but safe."
xMinEnd := startX min: endX.
xMaxEnd := startX max: endX.
yMinEnd := startY min: endY.
yMaxEnd := startY max: endY.
spanLeft := spanLeft min: (xMinEnd min: (xMinEnd+controlX) / 2.0).
spanRight := spanRight max: (xMaxEnd max: (xMaxEnd+controlX) / 2.0).
spanTop := spanTop min: (yMinEnd min: (yMinEnd+controlY) / 2.0).
spanBottom := spanBottom max: (yMaxEnd max: (yMaxEnd+controlY) / 2.0).
"Compute Quadratic Bezier Curve,"
"Case t = 0.0"
x := startX.
y := startY.
self updateAlphasForX: x y: y.
self updateEdgeCountAtX: x y: y.
"Will be corrected for each hop. This, being close to pointFrom, is a good initial guess for first correction."
self cCode: 'dx = fabs(endX-startX); dy = fabs(endY-startY);'
inSmalltalk: [ dx := (endX-startX) abs. dy := (endY-startY) abs ].
increment := 0.5 / (dx max: dy) min: 0.5.
t := 0.0.
[
t0 := t. x0 := x. y0 := y.
"Compute next point"
t := t0 + increment. oneLessT := 1.0 - t.
f1 := oneLessT * oneLessT. f2 := 2.0 * oneLessT * t. f3 := t * t.
x := (f1 * startX) + (f2 * controlX) + (f3 * endX).
y := (f1 * startY) + (f2 * controlY) + (f3 * endY).
"Now adjust the increment to aim at the required hop length, and recompute next point."
dx := x-x0. dy := y-y0.
self cCode: '
length = sqrt(dx*dx + dy*dy);'
inSmalltalk: [ length := ((dx*dx) + (dy*dy)) sqrt ].
correction := hop / length.
[
increment := increment / length * hop.
t := t0 + increment. oneLessT := 1.0 - t.
f1 := oneLessT * oneLessT. f2 := 2.0 * oneLessT * t. f3 := t * t.
x := (f1 * startX) + (f2 * controlX) + (f3 * endX).
y := (f1 * startY) + (f2 * controlY) + (f3 * endY).
dx := x-x0. dy := y-y0.
self cCode: '
length = sqrt(dx*dx + dy*dy);'
inSmalltalk: [ length := ((dx*dx) + (dy*dy)) sqrt ].
correction := hop / length.
correction < 1.0] whileTrue. "Keep adjusting if hop would be too big"
t < 1.0 ]
whileTrue: [
self updateAlphasForX: x y: y.
self updateEdgeCountAtX: x y: y ].
"Note: For TrueType font definitions, we assume that all contour fragments start exactly where the previous ends.
This means that the end point is only added for the last fragment of the contour, and not for each one of them."
startX := endX.
startY := endY.
].
self updateAlphasForX: endX y: endY.
self updateEdgeCountAtX: endX y: endY.
"Similar effect to ensureClosePath in #finishPath:,
but assume the TrueType definition is essentially right, and there might only be a rounding error.
So, don't draw a line, but just (possibly) correct edgeCounts. The possibility of rounding error is most likely zero.
Anyway, this is cheap."
self updateEdgeCountAtX: contourStartX y: contourStartY.
].
nextGlyphX := nextGlyphX + advanceWidth.
].
txA11 := txA11 / sx.
txA12 := txA12 / sy.
txA21 := txA21 / sx.
txA22 := txA22 / sy.