swhitty / SwiftDraw

@@ -118,9 +118,5 @@
Loading
118 118
    var color: Color
119 119
    var fontName: String
120 120
    var size: Float
121 -
    
122 -
    static var normal: TextAttributes {
123 -
      return TextAttributes(color: .black, fontName: "Helvetica", size: 12.0)
124 -
    }
125 121
  }
126 122
}

@@ -35,13 +35,7 @@
Loading
35 35
    var x: Coordinate?
36 36
    var y: Coordinate?
37 37
    var value: String
38 -
    
39 -
    var fontFamily: String?
40 -
    var fontSize: Float?
41 -
    
42 -
    // var textLength: Coordinate
43 -
    // var text: [TSpan] child nodes
44 -
    
38 +
45 39
    init(x: Coordinate? = nil, y: Coordinate? = nil, value: String) {
46 40
      self.x = x
47 41
      self.y = y

@@ -49,7 +49,10 @@
Loading
49 49
  var fill: DOM.Fill?  { get set }
50 50
  var fillOpacity: DOM.Float?  { get set }
51 51
  var fillRule: DOM.FillRule?  { get set }
52 -
  
52 +
53 +
  var fontFamily: String?  { get set }
54 +
  var fontSize: Float?  { get set }
55 +
53 56
  var transform: [DOM.Transform]?  { get set }
54 57
  var clipPath: DOM.URL?  { get set }
55 58
  var mask: DOM.URL?  { get set }
@@ -75,7 +78,10 @@
Loading
75 78
    var fill: DOM.Fill?
76 79
    var fillOpacity: DOM.Float?
77 80
    var fillRule: DOM.FillRule?
78 -
    
81 +
82 +
    var fontFamily: String?
83 +
    var fontSize: Float?
84 +
79 85
    var transform: [DOM.Transform]?
80 86
    var clipPath: URL?
81 87
    var mask: URL?

@@ -237,11 +237,13 @@
Loading
237 237
    } catch {
238 238
      print(error)
239 239
    }
240 -
    
241 -
    
240 +
242 241
    el.fillOpacity = try att.parsePercentage("fill-opacity")
243 242
    el.fillRule = try att.parseRaw("fill-rule")
244 -
    
243 +
244 +
    el.fontFamily = (try att.parseString("font-family"))?.trimmingCharacters(in: .whitespacesAndNewlines)
245 +
    el.fontSize = try att.parseFloat("font-size")
246 +
245 247
    if let val = try? att.parseString("transform") {
246 248
      el.transform = try parseTransform(val)
247 249
    }
@@ -269,6 +271,8 @@
Loading
269 271
    fill = attributes.fill
270 272
    fillOpacity = attributes.fillOpacity
271 273
    fillRule = attributes.fillRule
274 +
    fontFamily = attributes.fontFamily
275 +
    fontSize = attributes.fontSize
272 276
    transform = attributes.transform
273 277
    clipPath = attributes.clipPath
274 278
    mask = attributes.mask

@@ -186,7 +186,12 @@
Loading
186 186
  }
187 187
188 188
  static func makeTextAttributes(with state: State) -> LayerTree.TextAttributes {
189 -
    return .normal
189 +
      let fill = LayerTree.Color.create(from: state.fill.makeColor()).withAlpha(state.fillOpacity).maybeNone()
190 +
      return LayerTree.TextAttributes(
191 +
        color: fill,
192 +
        fontName: state.fontFamily,
193 +
        size: state.fontSize
194 +
      )
190 195
  }
191 196
192 197
  func makePattern(for element: DOM.Pattern) -> LayerTree.Pattern {
@@ -249,6 +254,9 @@
Loading
249 254
    var fillOpacity: DOM.Float
250 255
    var fillRule: DOM.FillRule
251 256
257 +
    var fontFamily: String
258 +
    var fontSize: DOM.Float
259 +
252 260
    init() {
253 261
      //default root SVG element state
254 262
      opacity = 1.0
@@ -265,6 +273,9 @@
Loading
265 273
      fill = .color(.keyword(.black))
266 274
      fillOpacity = 1.0
267 275
      fillRule = .evenodd
276 +
277 +
      fontFamily = "Helvetica"
278 +
      fontSize = 12.0
268 279
    }
269 280
  }
270 281
@@ -285,6 +296,9 @@
Loading
285 296
    state.fillOpacity = attributes.fillOpacity ?? existing.fillOpacity
286 297
    state.fillRule = attributes.fillRule ?? existing.fillRule
287 298
299 +
    state.fontFamily = attributes.fontFamily ?? existing.fontFamily
300 +
      state.fontSize = attributes.fontSize ?? existing.fontSize
301 +
288 302
    return state
289 303
  }
290 304
}
Files Coverage
SwiftDraw 76.18%
Project Totals (59 files) 76.18%
1
ignore:
2
  - "SwiftDrawTests"
3
  - "CommandLine"
Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading