@@ -12,14 +12,156 @@ class ViewController: UIViewController, TNSCanvasListener {
12
12
let PI : Float = . pi
13
13
let TWO_PI : Float = . pi * 2
14
14
var tapped = 0
15
-
15
+ var svg : TNSSVG ?
16
16
override func viewDidLoad( ) {
17
17
super. viewDidLoad ( )
18
18
scale = Int ( UIScreen . main. scale)
19
19
// Do any additional setup after loading the view.
20
20
canvas1. setListener ( self )
21
+ canvas1. isHidden = true
21
22
//let matrix = Canvas.createSVGMatrix()
22
23
//matrix.a = 3.0
24
+ svg = TNSSVG ( frame: view. bounds)
25
+ canvas1. addSubview ( svg!)
26
+ svg? . bringSubviewToFront ( canvas1)
27
+ svg!. backgroundColor = . white
28
+ // svg?.src = """
29
+ //<svg width="660" height="220" style="outline: 1px solid red">
30
+ // <defs>
31
+ // <clipPath id="text-2">
32
+ // <text x="50" y="133" font-family="Georgia" font-weight="bold" font-size="4px" >Clipping Path</text>
33
+ // </clipPath>
34
+ // </defs>
35
+ //
36
+ // <g transform="translate(300 300)" clip-path="url(#text-2)">
37
+ // <polygon points="110 10, 660 110, 110,210" fill="#c99" />
38
+ // <circle cx="110" cy="110" r="100" fill="#9c6" />
39
+ // </g>
40
+ //</svg>
41
+ //"""
42
+
43
+ // svg?.src = """
44
+ // <svg xmlns="http://www.w3.org/2000/svg">
45
+ // <defs>
46
+ // <linearGradient id="Gradient1">
47
+ // <stop offset="5%" stop-color="white"/>
48
+ // <stop offset="95%" stop-color="blue"/>
49
+ // </linearGradient>
50
+ // <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
51
+ // <stop offset="5%" stop-color="red"/>
52
+ // <stop offset="95%" stop-color="orange"/>
53
+ // </linearGradient>
54
+ // <pattern id="Pattern" x="0" y="0" width="1" height="1">
55
+ // <rect x="0" y="0" width="50" height="50" fill="skyblue"/>
56
+ // <rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
57
+ // <circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
58
+ // </pattern>
59
+ // </defs>
60
+ // <rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
61
+ // </svg>
62
+ // """
63
+
64
+
65
+ /* svg.src = """
66
+ <svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
67
+ <defs>
68
+ <linearGradient id="Gradient1">
69
+ <stop offset="5%" stop-color="white"/>
70
+ <stop offset="95%" stop-color="blue"/>
71
+ </linearGradient>
72
+ <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
73
+ <stop offset="5%" stop-color="red"/>
74
+ <stop offset="95%" stop-color="orange"/>
75
+ </linearGradient>
76
+ <pattern id="Pattern" x="0" y="0" width=".25" height=".25">
77
+ <rect x="0" y="0" width="50" height="50" fill="skyblue"/>
78
+ <rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
79
+ <circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
80
+ </pattern>
81
+ </defs>
82
+ <rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
83
+ </svg>
84
+ """*/
85
+
86
+ // svg.src = """
87
+ // <svg viewBox="0 0 230 100" xmlns="http://www.w3.org/2000/svg">
88
+ // <defs>
89
+ // <pattern fill="red" id="star" viewBox="0,0,10,10" width="10%" height="10%">
90
+ // <polygon points="0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2"/>
91
+ // </pattern>
92
+ // </defs>
93
+ // <circle cx="50" cy="50" r="50" fill="url(#star)"/>
94
+ // <circle cx="180" cy="50" r="40" fill="none" stroke-width="20" stroke="url(#star)"/>
95
+ // </svg>
96
+ // """
97
+
98
+ // svg.src = """
99
+ // <svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg"
100
+ // xmlns:xlink="http://www.w3.org/1999/xlink">
101
+ // <!-- Our symbol in its own coordinate system -->
102
+ // <symbol id="myDot" width="10" height="10" viewBox="0 0 2 2">
103
+ // <circle cx="1" cy="1" r="1" />
104
+ // </symbol>
105
+ //
106
+ // <!-- A grid to materialize our symbol positioning -->
107
+ // <path transform="translate(10)" d="M0,10 h80 M10,0 v20 M25,0 v20 M40,0 v20 M55,0 v20 M70,0 v20" fill="none" stroke="pink" />
108
+ //
109
+ // <!-- All instances of our symbol -->
110
+ // <use xlink:href="#myDot" x="5" y="50" style="opacity:1.0" />
111
+ // <use xlink:href="#myDot" x="20" y="50" />
112
+ // <use xlink:href="#myDot" x="35" y="50" />
113
+ // <use xlink:href="#myDot" x="50" y="50" />
114
+ // <use xlink:href="#myDot" x="65" y="50" style="opacity:0.2" />
115
+ // </svg>
116
+ // """
117
+
118
+
119
+ // https://upload.wikimedia.org/wikipedia/commons/4/4c/The_Hague%2C_Netherlands%2C_the_old_city_center.svg
120
+ // https://upload.wikimedia.org/wikipedia/commons/6/6c/Trajans-Column-lower-animated.svg
121
+
122
+ // https://upload.wikimedia.org/wikipedia/commons/b/b1/Cluse_de_Chamb%C3%A9ry_-_Carte_de_l%27occupation_des_sols_%28CORINE%29.svg
123
+
124
+
125
+ //https://upload.wikimedia.org/wikipedia/commons/b/b6/Moldova_%281483%29-en.svg
126
+
127
+ // https://upload.wikimedia.org/wikipedia/commons/a/a0/Location_map_San_Francisco_Bay_Area.svg // 40mb
128
+
129
+ // https://upload.wikimedia.org/wikipedia/commons/c/c1/Propane_flame_contours-en.svg
130
+
131
+ // https://upload.wikimedia.org/wikipedia/commons/9/95/Kaiserstandarte_Version1.svg
132
+
133
+ // https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/car.svg
134
+
135
+ // https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/lineargradient1.svg
136
+
137
+ //http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg
138
+
139
+ // https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/AJ_Digital_Camera.svg
140
+
141
+ // https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/tiger.svg
142
+
143
+ // https://upload.wikimedia.org/wikipedia/commons/f/ff/1_42_polytope_7-cube.svg
144
+
145
+ // https://upload.wikimedia.org/wikipedia/commons/7/7c/Map_of_the_world_by_the_US_Gov_as_of_2016_no_legend.svg
146
+
147
+ // https://upload.wikimedia.org/wikipedia/commons/9/9d/The_Rhodopes_on_The_Paths_Of_Orpheus_And_Eurydice_Project_Map.svg
148
+
149
+ // https://upload.wikimedia.org/wikipedia/commons/1/1c/KINTETSU23000_20140424A.svg
150
+
151
+ // do{
152
+ // let svg_file = NSURL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + "_svg_file.svg")
153
+ // let svg_data = try Data(contentsOf: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/tiger.svg")!)
154
+ // try svg_data.write(to: svg_file.absoluteURL!, options: .atomicWrite)
155
+ // //let svgContents = String(data: svg_data, encoding: .utf8)
156
+ // svg?.srcPath = svg_file.path
157
+ // //svg?.src = svgContents
158
+ //
159
+ // }catch {
160
+ // print(error)
161
+ // }
162
+
163
+
164
+
23
165
}
24
166
25
167
var drawn = false
@@ -145,6 +287,61 @@ class ViewController: UIViewController, TNSCanvasListener {
145
287
146
288
147
289
func drawAll( ) {
290
+
291
+ svg? . src = """
292
+ <svg viewBox= " 0 0 10 10 " xmlns= " http://www.w3.org/2000/svg "
293
+ xmlns:xlink= " http://www.w3.org/1999/xlink " >
294
+ <defs>
295
+ <radialGradient id= " myGradient " >
296
+ <stop offset= " 10% " stop-color= " gold " />
297
+ <stop offset= " 95% " stop-color= " red " />
298
+ </radialGradient>
299
+ </defs>
300
+
301
+ <!-- using my radial gradient -->
302
+ <circle transform= " scale(10 10) " cx= " 5 " cy= " 5 " r= " 4 " />
303
+ </svg>
304
+ """
305
+
306
+
307
+ // do{
308
+ // let svg_file = NSURL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + "_svg_file.svg")
309
+ // let svg_data = try Data(contentsOf: URL(string: "http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg")!)
310
+ // try svg_data.write(to: svg_file.absoluteURL!, options: .atomicWrite)
311
+ // //let svgContents = String(data: svg_data, encoding: .utf8)
312
+ // svg?.srcPath = svg_file.path
313
+ // //svg?.src = svgContents
314
+ //
315
+ // }catch {
316
+ // print(error)
317
+ // }
318
+
319
+
320
+
321
+ //
322
+ // svg?.src = """
323
+ // <svg xmlns="http://www.w3.org/2000/svg">
324
+ // <defs>
325
+ // <linearGradient id="Gradient1">
326
+ // <stop offset="5%" stop-color="white"/>
327
+ // <stop offset="95%" stop-color="blue"/>
328
+ // </linearGradient>
329
+ // <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
330
+ // <stop offset="5%" stop-color="red"/>
331
+ // <stop offset="95%" stop-color="orange"/>
332
+ // </linearGradient>
333
+ // <pattern id="Pattern" x="0" y="0" width=".25" height=".25">
334
+ // <rect x="0" y="0" width="50" height="50" fill="skyblue"/>
335
+ // <rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
336
+ // <circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
337
+ // </pattern>
338
+ // </defs>
339
+ // <rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
340
+ // </svg>
341
+ // """
342
+
343
+
344
+
148
345
// let gl = self.canvas1?.getContext("webgl2") as! TNSWebGLRenderingContext
149
346
//canvas1?.handleInvalidationManually = true
150
347
0 commit comments