-
Notifications
You must be signed in to change notification settings - Fork 1
/
SVG.pck.st
1577 lines (1291 loc) · 50.5 KB
/
SVG.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 Cuis7.1 [latest update: #6771] on 14 October 2024 at 11:36:14 am'!
'Description '!
!provides: 'SVG' 1 22!
!requires: 'LinearAlgebra' 1 nil nil!
!requires: 'Color-Extras' 1 7 nil!
!requires: 'YAXO' 1 nil nil!
SystemOrganization addCategory: #'SVG-Elements'!
SystemOrganization addCategory: #'SVG-Shapes'!
!classDefinition: #SVGWarning category: #'SVG-Elements'!
Warning subclass: #SVGWarning
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGWarning class' category: #'SVG-Elements'!
SVGWarning class
instanceVariableNames: ''!
!classDefinition: #SVGElementMorph category: #'SVG-Elements'!
PlacedMorph subclass: #SVGElementMorph
instanceVariableNames: 'defs opacity strokeWidth strokeColorOrGradient strokeOpacity fillColorOrGradient fillOpacity strokeDashArray strokeDashArrayOffset'
classVariableNames: 'DefaultedAtributes IgnoredAttributes IgnoredElements IgnoredPrefixes'
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGElementMorph class' category: #'SVG-Elements'!
SVGElementMorph class
instanceVariableNames: ''!
!classDefinition: #SVGGroupMorph category: #'SVG-Elements'!
SVGElementMorph subclass: #SVGGroupMorph
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGGroupMorph class' category: #'SVG-Elements'!
SVGGroupMorph class
instanceVariableNames: ''!
!classDefinition: #SVGMainMorph category: #'SVG-Elements'!
SVGGroupMorph subclass: #SVGMainMorph
instanceVariableNames: 'extent'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGMainMorph class' category: #'SVG-Elements'!
SVGMainMorph class
instanceVariableNames: ''!
!classDefinition: #SVGCircle category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGCircle
instanceVariableNames: 'cx cy r'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGCircle class' category: #'SVG-Shapes'!
SVGCircle class
instanceVariableNames: ''!
!classDefinition: #SVGEllipse category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGEllipse
instanceVariableNames: 'cx cy rx ry'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGEllipse class' category: #'SVG-Shapes'!
SVGEllipse class
instanceVariableNames: ''!
!classDefinition: #SVGLine category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGLine
instanceVariableNames: 'x1 y1 x2 y2'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGLine class' category: #'SVG-Shapes'!
SVGLine class
instanceVariableNames: ''!
!classDefinition: #SVGPath category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGPath
instanceVariableNames: 'commands'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGPath class' category: #'SVG-Shapes'!
SVGPath class
instanceVariableNames: ''!
!classDefinition: #SVGPolyLine category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGPolyLine
instanceVariableNames: 'points'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGPolyLine class' category: #'SVG-Shapes'!
SVGPolyLine class
instanceVariableNames: ''!
!classDefinition: #SVGPolygon category: #'SVG-Shapes'!
SVGPolyLine subclass: #SVGPolygon
instanceVariableNames: ''
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGPolygon class' category: #'SVG-Shapes'!
SVGPolygon class
instanceVariableNames: ''!
!classDefinition: #SVGRect category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGRect
instanceVariableNames: 'xMin xMax yMin yMax rx ry'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGRect class' category: #'SVG-Shapes'!
SVGRect class
instanceVariableNames: ''!
!classDefinition: #SVGText category: #'SVG-Shapes'!
SVGElementMorph subclass: #SVGText
instanceVariableNames: 'string pointSize x y'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Shapes'!
!classDefinition: 'SVGText class' category: #'SVG-Shapes'!
SVGText class
instanceVariableNames: ''!
!classDefinition: #SVGDefElement category: #'SVG-Elements'!
Object subclass: #SVGDefElement
instanceVariableNames: 'def'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGDefElement class' category: #'SVG-Elements'!
SVGDefElement class
instanceVariableNames: ''!
!classDefinition: #SVGGradient category: #'SVG-Elements'!
SVGDefElement subclass: #SVGGradient
instanceVariableNames: 'stops name inheritFrom averageColor'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGGradient class' category: #'SVG-Elements'!
SVGGradient class
instanceVariableNames: ''!
!classDefinition: #SVGLinearGradient category: #'SVG-Elements'!
SVGGradient subclass: #SVGLinearGradient
instanceVariableNames: 'vectorX1 vectorY1 vectorX2 vectorY2'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGLinearGradient class' category: #'SVG-Elements'!
SVGLinearGradient class
instanceVariableNames: ''!
!classDefinition: #SVGRadialGradient category: #'SVG-Elements'!
SVGGradient subclass: #SVGRadialGradient
instanceVariableNames: 'cx cy r'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGRadialGradient class' category: #'SVG-Elements'!
SVGRadialGradient class
instanceVariableNames: ''!
!classDefinition: #SVGGradientStop category: #'SVG-Elements'!
SVGDefElement subclass: #SVGGradientStop
instanceVariableNames: 'offset color'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGGradientStop class' category: #'SVG-Elements'!
SVGGradientStop class
instanceVariableNames: ''!
!classDefinition: #SVGDefs category: #'SVG-Elements'!
Object subclass: #SVGDefs
instanceVariableNames: 'defs'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGDefs class' category: #'SVG-Elements'!
SVGDefs class
instanceVariableNames: ''!
!classDefinition: #SVGTransform category: #'SVG-Elements'!
Object subclass: #SVGTransform
instanceVariableNames: 'a'
classVariableNames: ''
poolDictionaries: ''
category: 'SVG-Elements'!
!classDefinition: 'SVGTransform class' category: #'SVG-Elements'!
SVGTransform class
instanceVariableNames: ''!
!SVGElementMorph commentStamp: '<historical>' prior: 0!
See class methods in 'examples' category in SVGMainMorph.!
!SVGMainMorph commentStamp: '<historical>' prior: 0!
See class methods in 'examples' category.!
!SVGElementMorph methodsFor: 'building' stamp: 'jmv 1/21/2015 09:03'!
buildFromXml: anXMLElement
| usedAttributeNames styleAttributes strokeDashArrayData strokeDashArrayOffsetData transformData svgTransform |
styleAttributes _ self class styleAttributesIn: anXMLElement.
"These are always nested. No need to inherit."
svgTransform _ SVGTransform new.
transformData _ self class attributeAt: 'transform' in: anXMLElement orIn: styleAttributes.
transformData ifNotNil: [
svgTransform buildFrom: transformData.
location _ svgTransform asAffineTransformation ].
strokeWidth _ self class numberAttributeAt: 'stroke-width' in: anXMLElement orIn: styleAttributes.
strokeColorOrGradient _ self class colorAttributeAt: 'stroke' in: anXMLElement orIn: styleAttributes.
fillColorOrGradient _ self class colorAttributeAt: 'fill' in: anXMLElement orIn: styleAttributes.
strokeOpacity _ self class numberAttributeAt: 'stroke-opacity' in: anXMLElement orIn: styleAttributes.
fillOpacity _ self class numberAttributeAt: 'fill-opacity' in: anXMLElement orIn: styleAttributes.
opacity _ self class numberAttributeAt: 'opacity' in: anXMLElement orIn: styleAttributes.
strokeDashArrayData _ self class attributeAt: 'stroke-dasharray' in: anXMLElement orIn: styleAttributes.
strokeDashArrayOffsetData _ self class attributeAt: 'stroke-dashoffset' in: anXMLElement orIn: styleAttributes.
(strokeDashArrayData notNil and: [ strokeDashArrayData ~= 'none' ]) ifTrue: [
strokeDashArray _ (self class numbersIn: strokeDashArrayData).
strokeDashArray size even ifFalse: [
strokeDashArray _ strokeDashArray, strokeDashArray ].
strokeDashArrayOffsetData ifNotNil: [
strokeDashArrayOffset _ strokeDashArrayOffsetData asNumber ]].
defs _ nil.
anXMLElement elementsDo: [ :subElement |
"Process def elements first"
(subElement name = SVGDefs svgName)
ifTrue: [
defs ifNil: [ defs _ SVGDefs new ].
defs buildFromXml: subElement]].
usedAttributeNames _ self usedAttributeNames asSet.
anXMLElement attributes keysAndValuesDo: [ :attrName :value |
((usedAttributeNames includes: attrName) or: [
(IgnoredAttributes includes: attrName) or: [
(IgnoredPrefixes anySatisfy: [ :prefix | attrName beginsWith: prefix]) or: [
(DefaultedAtributes at: attrName ifAbsent: []) = value]]]) ifFalse: [
SVGWarning signal: 'Unhandled attribute: ', attrName printString, ' in: ', self class name, ' value: ', value printString ]].
styleAttributes ifNotNil: [
styleAttributes keysAndValuesDo: [ :attrName :value |
((usedAttributeNames includes: attrName) or: [
(IgnoredAttributes includes: attrName) or: [
(IgnoredPrefixes anySatisfy: [ :prefix | attrName beginsWith: prefix]) or: [
(DefaultedAtributes at: attrName ifAbsent: []) = value]]]) ifFalse: [
SVGWarning signal: 'Unhandled style token: ', attrName printString, ' in: ', self class name, ' value: ', value printString ]]].
anXMLElement elementsDo: [ :subElement |
(self isKindOf: SVGGroupMorph) ifFalse: [
SVGWarning signal: 'Unexpected element: ', subElement name printString, ' in: ', self class name ]
]! !
!SVGElementMorph methodsFor: 'building' stamp: 'jmv 6/16/2010 10:01'!
usedAttributeNames
^#('style' 'fill' 'fill-opacity' 'opacity' 'stroke' 'stroke-opacity' 'stroke-width' 'transform' 'stroke-dasharray' 'stroke-dashoffset')! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/10/2010 14:17'!
defAt: aString
| answer |
answer _ defs ifNotNil: [ defs defAt: aString ].
^answer ifNil: [
(owner isKindOf: SVGElementMorph)
ifTrue: [ owner defAt: aString ] ]! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/18/2021 12:44:44'!
fillColor
"Answer a Color, even if a gradient was specified. See also #fillColorOrGradient"
fillColorOrGradient == #inherit ifTrue: [
fillColorOrGradient _ (owner isKindOf: SVGElementMorph)
ifTrue: [ owner fillColor ]
ifFalse: [ Color black ]].
"The SVG standard defines current color. In Cuis we don't have such concept.
Maybe we'll find a better way to set the actual color to use.
Just use black for the time being."
fillColorOrGradient == #currentColor ifTrue: [
fillColorOrGradient _ Color black ].
fillColorOrGradient isString ifTrue: [
fillColorOrGradient _ self defAt: fillColorOrGradient ].
fillColorOrGradient ifNil: [ ^nil ].
(fillColorOrGradient isKindOf: SVGGradient)
ifTrue: [ fillColorOrGradient _ fillColorOrGradient averageColor ].
^fillColorOrGradient alpha: self fillOpacity * self opacity! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:32:50'!
fillColor: aColor
fillColorOrGradient := aColor.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/10/2010 15:54'!
fillOpacity
^fillOpacity == #inherit
ifFalse: [ fillOpacity ]
ifTrue: [
(owner isKindOf: SVGElementMorph)
ifTrue: [ owner fillOpacity ]
ifFalse: [ 1.0 ]]! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:35:46'!
fillOpacity: aNumber
fillOpacity := aNumber.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/10/2010 15:54'!
opacity
^opacity == #inherit
ifFalse: [ opacity ]
ifTrue: [
(owner isKindOf: SVGElementMorph)
ifTrue: [ owner opacity ]
ifFalse: [ 1.0 ]]! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:35:30'!
opacity: aNumber
opacity := aNumber.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/18/2021 12:44:25'!
strokeColor
"Answer a Color, even if a gradient was specified. See also #strokeColorOrGradient"
strokeColorOrGradient == #inherit ifTrue: [
strokeColorOrGradient _ (owner isKindOf: SVGElementMorph)
ifTrue: [ owner strokeColor ]
ifFalse: [ nil ]].
"The SVG standard defines current color. In Cuis we don't have such concept.
Maybe we'll find a better way to set the actual color to use.
Just use black for the time being."
strokeColorOrGradient == #currentColor ifTrue: [
strokeColorOrGradient _ Color black ].
strokeColorOrGradient isString ifTrue: [
strokeColorOrGradient _ self defAt: strokeColorOrGradient ].
strokeColorOrGradient ifNil: [ ^nil ].
(strokeColorOrGradient isKindOf: SVGGradient)
ifTrue: [ strokeColorOrGradient _ strokeColorOrGradient averageColor].
^strokeColorOrGradient alpha: self strokeOpacity * self opacity! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:31:43'!
strokeColor: aColor
strokeColorOrGradient := aColor.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 4/29/2011 21:55'!
strokeDashArray
| s |
^strokeDashArray ifNotNil: [
s _ 0.0.
strokeDashArray collect: [ :d |
s _ s + d.
s]]! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 4/29/2011 21:54'!
strokeDashArrayOffset
^ strokeDashArrayOffset! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/10/2010 15:54'!
strokeOpacity
^strokeOpacity == #inherit
ifFalse: [ strokeOpacity ]
ifTrue: [
(owner isKindOf: SVGElementMorph)
ifTrue: [ owner strokeOpacity ]
ifFalse: [ 1.0 ]]! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:35:53'!
strokeOpacity: aNumber
strokeOpacity := aNumber.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 6/10/2010 15:16'!
strokeWidth
strokeWidth == #inherit ifTrue: [
^ (owner isKindOf: SVGElementMorph)
ifTrue: [ owner strokeWidth ]
ifFalse: [ 1 ]].
"nil"
^strokeWidth! !
!SVGElementMorph methodsFor: 'accessing' stamp: 'jmv 10/14/2024 11:31:01'!
strokeWidth: aNumber
strokeWidth := aNumber.
self redrawNeeded.! !
!SVGElementMorph methodsFor: 'private' stamp: 'jmv 12/15/2021 14:47:32'!
fixYAxisDirection
"SVG already specifies desired TX. No need to correct it.
Also note that we redefine #yAxisPointsUp to agree with the TX we were given."! !
!SVGElementMorph methodsFor: 'geometry testing' stamp: 'jmv 12/15/2021 11:30:52'!
yAxisPointsUp
"SVG elements usually define an explicit affine transformation.
Give an answer consistent with it.
Also note that we redefine #fixYAxisDirection as NOP"
| answer |
answer _ owner ifNil: [false] ifNotNil: [owner yAxisPointsUp].
location doesMirror ifTrue: [ answer _ answer not ].
^answer! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:16'!
attributeAt: attributeName in: anXMLElement orIn: styleDictionary
^anXMLElement attributeAt: attributeName ifAbsent: [
styleDictionary ifNotNil: [ styleDictionary at: attributeName ifAbsent: nil ]]! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/18/2021 12:35:45'!
colorAttributeAt: attributeName in: anXMLElement orIn: styleDictionary
| data |
data _ self attributeAt: attributeName in: anXMLElement orIn: styleDictionary.
data ifNil: [
^ #inherit ].
data = 'currentColor' ifTrue: [
^ #currentColor ].
^self svgColorOrGradientNameFor: data! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/16/2010 09:50'!
ignoredAttributes
^IgnoredAttributes! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/16/2010 10:44'!
ignoredElements
^IgnoredElements! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/16/2010 10:08'!
ignoredPrefixes
^IgnoredPrefixes! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:17'!
numberAttributeAt: attributeName in: anXMLElement orIn: styleDictionary
| data |
data _ self attributeAt: attributeName in: anXMLElement orIn: styleDictionary.
^data
ifNil: [ #inherit ]
ifNotNil: [ data asNumber ]! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:18'!
numbersIn: aString
| rs |
rs _ aString readStream.
^Array streamContents: [ :strm |
[ rs atEnd ] whileFalse: [
rs nextNumber ifNotNil: [ :n |
strm nextPut: n ]]]! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 7/30/2012 18:00'!
styleAttributesIn: anXMLElement
| styleDict styleData pair |
styleData _ anXMLElement attributeAt: 'style'.
styleData ifNil: [ ^nil ].
styleDict _ Dictionary new.
(styleData findTokens: #($;)) do: [ :each | "For example, 'fill:#653300'"
pair _ each findTokens: #($:).
pair size > 1 ifTrue: [
styleDict at: pair first withBlanksTrimmed put: pair second withBlanksTrimmed ]].
^styleDict! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 2/15/2013 16:53'!
svgColorOrGradientNameFor: aString
| dataStream |
aString = 'none' ifTrue: [^nil].
self revisar.
(aString beginsWith: 'url')
ifFalse: [ ^Color "fromCSS2String: just hex? Or real CSS2?" fromString: aString ].
" 'url' means reference to a def object. Just keep the name, for later binding"
dataStream _ aString readStream.
dataStream upTo: $#.
^(dataStream upTo: $) ) withBlanksTrimmed! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:20'!
svgHeightFractionIn: anXMLElement
| string |
string _ anXMLElement attributeAt: 'height' ifAbsent: [ ^ nil ].
^self svgLengthFractionFor: string! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 12/9/2021 19:46:17'!
svgLengthFractionFor: aString
| string |
string _ aString withBlanksTrimmed.
(string last = $%) ifTrue: [
^ string asNumber / 100.0 ].
^nil! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:21'!
svgPixelHeightIn: anXMLElement
| string |
string _ anXMLElement attributeAt: 'height' ifAbsent: [ ^ nil ].
^self svgPixelLengthFor: string! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 12/9/2021 19:53:46'!
svgPixelLengthFor: aString
| string data |
string _ aString withBlanksTrimmed.
(string last = $%) ifTrue: [ ^nil ].
data _ string asNumber.
(string endsWith: 'in')
ifTrue: [ ^(data * 90) ].
(string endsWith: 'mm')
ifTrue: [ ^(data * 3.571429) ].
(string endsWith: 'cm')
ifTrue: [ ^(data * 35.71429) ].
(string endsWith: 'pt')
ifTrue: [ ^(data * 1.25) ].
(string endsWith: 'pc')
ifTrue: [ ^(data * 15) ].
^data! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:21'!
svgPixelWidthIn: anXMLElement
| string |
string _ anXMLElement attributeAt: 'width' ifAbsent: [ ^ nil ].
^self svgPixelLengthFor: string! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:21'!
svgViewBoxIn: anXMLElement
| string data |
string _ anXMLElement attributeAt: 'viewBox' ifAbsent: [ ^ nil ].
data _ string substrings collect: [ :str | str asNumber].
^Rectangle origin: (data first @ data second) extent: (data third @ data fourth)! !
!SVGElementMorph class methodsFor: 'building - aux' stamp: 'jmv 6/14/2010 17:21'!
svgWidthFractionIn: anXMLElement
| string |
string _ anXMLElement attributeAt: 'width' ifAbsent: [ ^ nil ].
^self svgLengthFractionFor: string! !
!SVGElementMorph class methodsFor: 'instance creation' stamp: 'jmv 6/9/2010 22:25'!
classFor: anSVGName
self allSubclassesDo: [ :cls |
cls svgName = anSVGName
ifTrue: [ ^cls ] ].
^nil! !
!SVGElementMorph class methodsFor: 'instance creation' stamp: 'jmv 6/16/2010 10:32'!
fromXml: anXMLElement
| cls n |
n _ anXMLElement name.
cls _ SVGElementMorph classFor: n.
cls ifNil: [
((IgnoredElements includes: n) or: [
IgnoredPrefixes anySatisfy: [ :prefix | n beginsWith: prefix ]]) ifFalse: [
SVGWarning signal: ('Unhandled element: ', n printString) ].
^nil ].
^ cls new buildFromXml: anXMLElement! !
!SVGElementMorph class methodsFor: 'instance creation' stamp: 'jmv 6/9/2010 22:28'!
svgName
"Answer the name of the svg elements we can represent"
^self subclassResponsibility! !
!SVGElementMorph class methodsFor: 'class initialization' stamp: 'jmv 12/9/2021 19:16:20'!
initialize
"
self initialize
"
IgnoredPrefixes _ #('sodipodi:' 'inkscape:' 'xmlns:' 'i:') asSet.
IgnoredElements _ #('title' 'metadata' 'foreignObject') asSet.
IgnoredAttributes _ #('id' 'stroke-miterlimit') asSet.
"Any specified value in an SVG file will be ignored. Only these defaults are supported"
DefaultedAtributes _ Dictionary new
at: 'fill-rule' put: 'nonzero';
at: 'stroke-linecap' put: 'round';
at: 'stroke-linejoin' put: 'round';
yourself! !
!SVGElementMorph class methodsFor: 'please remove' stamp: 'jmv 12/27/2021 14:21:38'!
revisar! !
!SVGGroupMorph methodsFor: 'building' stamp: 'jmv 6/10/2010 10:17'!
buildFromXml: anXMLElement
| m |
super buildFromXml: anXMLElement.
anXMLElement elementsDo: [ :subElement |
"Skip de def elements"
(subElement name = SVGDefs svgName)
ifFalse: [
m _ SVGElementMorph fromXml: subElement.
m ifNotNil: [
self addMorph: m ]]].! !
!SVGGroupMorph methodsFor: 'drawing' stamp: 'jmv 11/8/2012 19:28'!
drawOn: aCanvas
"Nothing to do here..."! !
!SVGGroupMorph class methodsFor: 'instance creation' stamp: 'jmv 6/9/2010 22:35'!
svgName
"Answer the name of the svg elements we can represent"
^#g! !
!SVGMainMorph methodsFor: 'building' stamp: 'jmv 12/14/2021 11:39:39'!
buildFromXml: anXMLElement
| viewBox w h wFraction hFraction s |
super buildFromXml: anXMLElement.
viewBox _ self class svgViewBoxIn: anXMLElement.
viewBox ifNotNil: [
extent _ viewBox extent.
w _ self class svgPixelWidthIn: anXMLElement.
h _ self class svgPixelHeightIn: anXMLElement.
w ifNotNil: [
s _ w / viewBox width max: h / viewBox height.
self scale: s ]
ifNil: [
wFraction _ self class svgWidthFractionIn: anXMLElement.
hFraction _ self class svgHeightFractionIn: anXMLElement.
wFraction ifNotNil: [
s _ wFraction max: hFraction.
self scale: s ]
].
].! !
!SVGMainMorph methodsFor: 'building' stamp: 'jmv 6/10/2010 08:56'!
usedAttributeNames
^super usedAttributeNames,
#('version' 'xmlns' 'xmlns:xlink' 'viewBox' 'width' 'height')! !
!SVGMainMorph methodsFor: 'geometry' stamp: 'jmv 12/15/2021 14:56:35'!
findFullBoundsInOwner
"If extent ivar is defined, answer after it (no need to actually find the bounds)."
self knowsOwnLocalBounds ifFalse: [ ^super findFullBoundsInOwner ].
^self fullBoundsInOwner.! !
!SVGMainMorph methodsFor: 'geometry' stamp: 'jmv 12/15/2021 14:56:26'!
fullBoundsInOwner
"If extent ivar is defined, answer after it."
self knowsOwnLocalBounds ifFalse: [ ^super fullBoundsInOwner ].
^ (self externalizeBoundingRectOf: (`0@0` extent: extent)) encompassingIntegerRectangle.! !
!SVGMainMorph methodsFor: 'geometry' stamp: 'hlsf 9/2/2024 20:48:19'!
localBounds
"Can only be asked for if #knowsOwnLocalBounds answers true!!"
^`0@0` extent: extent.! !
!SVGMainMorph methodsFor: 'geometry' stamp: 'hlsf 9/2/2024 20:48:47'!
localBoundsForError
"Only to be used for drawing in an error condition. See senders."
self knowsOwnLocalBounds ifFalse: [ ^super localBoundsForError ].
^self localBounds.! !
!SVGMainMorph methodsFor: 'geometry' stamp: 'jmv 12/14/2021 11:40:06'!
morphExtent
"In our own coordinates!!
nil if unknown."
^ extent! !
!SVGMainMorph methodsFor: 'geometry testing' stamp: 'jmv 12/15/2021 14:55:29'!
knowsOwnLocalBounds
"Meaning that it doesn't need running #drawOn: and #postDrawOn: to explore affected pixels to deduce actual morph bounds. See senders."
^extent notNil! !
!SVGMainMorph class methodsFor: 'services' stamp: 'jmv 6/9/2010 22:26'!
attributeAt: attributeName in: anXMLElement orIn: styleDictionary
^anXMLElement attributeAt: attributeName ifAbsent: [
styleDictionary ifNotNil: [ styleDictionary at: attributeName ifAbsent: nil ]]! !
!SVGMainMorph class methodsFor: 'services' stamp: 'jmv 6/9/2010 22:26'!
numbersIn: aString
| rs |
rs _ aString readStream.
^Array streamContents: [ :strm |
[ rs atEnd ] whileFalse: [
strm nextPut: rs nextNumber ]]! !
!SVGMainMorph class methodsFor: 'services' stamp: 'jmv 7/30/2012 18:00'!
styleAttributesIn: anXMLElement
| styleDict styleData pair |
styleData _ anXMLElement attributeAt: 'style'.
styleData ifNil: [ ^nil ].
styleDict _ Dictionary new.
(styleData findTokens: #($;)) do: [ :each | "For example, 'fill:#653300'"
pair _ each findTokens: #($:).
pair size > 1 ifTrue: [
styleDict at: pair first withBlanksTrimmed put: pair second withBlanksTrimmed ]].
^styleDict! !
!SVGMainMorph class methodsFor: 'services' stamp: 'jmv 2/15/2013 16:53'!
svgColorOrGradientNameFor: aString
| dataStream |
aString = 'none' ifTrue: [^nil].
self revisar.
(aString beginsWith: 'url')
ifFalse: [ ^Color "fromCSS2String: just hex? Or real CSS2?" fromString: aString ].
" 'url' means reference to a def object. Just keep the name, for later binding"
dataStream _ aString readStream.
dataStream upTo: $#.
^(dataStream upTo: $) ) withBlanksTrimmed! !
!SVGMainMorph class methodsFor: 'services' stamp: 'jmv 2/15/2013 16:53'!
svgColorOrGradientNameFor: aString opacity: opacityString
| dataStream c |
aString = 'none' ifTrue: [^nil].
self revisar.
(aString beginsWith: 'url')
ifFalse: [
c _ Color "fromCSS2String: just hex? Or real CSS2?" fromString: aString.
opacityString ifNotNil: [
c _ c alpha: opacityString asNumber ].
^c ].
" 'url' means reference to a def object. Just keep the name, for later binding"
dataStream _ aString readStream.
dataStream upTo: $#.
^(dataStream upTo: $) ) withBlanksTrimmed! !
!SVGMainMorph class methodsFor: 'instance creation' stamp: 'jmv 9/6/2021 12:13:37'!
fromFile: aFileEntry
| xmlDocument |
xmlDocument _ XMLDOMParser parseDocumentFromFile: aFileEntry readIntoMemory: true.
^ self fromXml: xmlDocument elements first.! !
!SVGMainMorph class methodsFor: 'instance creation' stamp: 'jmv 6/9/2010 22:25'!
svgName
"Answer the name of the svg elements we can represent"
^#svg! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:32:59'!
exampleBeer
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleBeer
SVGMainMorph exampleBeer openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'beer.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:33:31'!
exampleButterfly
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleButterfly
SVGMainMorph exampleButterfly openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'butterfly.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:33:59'!
exampleCar
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleCar
SVGMainMorph exampleCar openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'car.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:34:24'!
exampleCowboy
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleCowboy
SVGMainMorph exampleCowboy openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'cowboy.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:36:20'!
exampleGrapes
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleGrapes
SVGMainMorph exampleGrapes openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'rg1024_green_grapes.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:35:00'!
exampleLion
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleLion
SVGMainMorph exampleLion openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'lion.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:31:54'!
exampleMacaw
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleMacaw
SVGMainMorph exampleMacaw openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'arara-caninde-TRACE-BITMAP.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:35:23'!
examplePhone
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph examplePhone
SVGMainMorph examplePhone openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'Phone.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:35:47'!
examplePicasso
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph examplePicasso
SVGMainMorph examplePicasso openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'Picasso.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:32:21'!
examplePlane
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph examplePlane
SVGMainMorph examplePlane openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'b8.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:36:45'!
exampleTiger
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleTiger
SVGMainMorph exampleTiger openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'tiger.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:37:09'!
exampleWizard
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleWizard
SVGMainMorph exampleWizard openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'wizard.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:37:24'!
exampleWorld
"Read and answer a SVG sample file.
Also try 'printIt'!!
"
"
SVGMainMorph exampleWorld
SVGMainMorph exampleWorld openInWorld
"
^ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'world.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 9/6/2021 12:37:52'!
openAllExamples
"Open all svg examples as morphs, in a forked process."
"
SVGMainMorph openAllExamples
SVGMainMorph allInstancesDo: [ :m | m delete ].
"
| s |
s _ Semaphore new signal.
[
self package packageDirectory
allFilesDo: [ :file |
s wait.
UISupervisor whenUIinSafeState: [
[ (self fromFile: file) openInWorld ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].
s signal
].
]
matches: [ :file | '*.svg' match: file name ].
] fork! !
!SVGMainMorph class methodsFor: 'examples' stamp: 'jmv 10/8/2021 09:52:13'!
seamlessRasterizationExample
"
This example shows that Cuis' VectorGraphics can rasterize seampless SVG.
Compare the two images.
Also try opening the svg file in, for example, Chrome.
SVGMainMorph seamlessRasterizationExample
"
| m f |
m _ [ (self fromFile: self package packageDirectory / 'SVGSamples' // 'clinton.svg') ]
on: SVGWarning
do: [ :warning | "warning print. "warning resume ].
f _ Form extent: 360@480 depth:32.
m privateOwner: self runningWorld.
m morphPosition: 0@0.
"Translucent target only supported in the SubPixel flavor of the VM Plugin"
(VectorCanvas onFormWithSubPixelAntiAliasing: f) fullDraw: m.
Display fillColor: Color black.
f displayOn: Display at: 0@0.
f makeAllPixelsOpaque.
f displayOn: Display at: 360@0.
Display copy inspect.! !
!SVGCircle methodsFor: 'building' stamp: 'jmv 3/13/2023 10:02:13'!
buildFromXml: anXMLElement