|
32 | 32 | import Foundation |
33 | 33 |
|
34 | 34 | extension LayerTree.Builder { |
35 | | - |
36 | | - func makeShapeContents(from shape: LayerTree.Shape, with state: State) -> LayerTree.Layer.Contents { |
37 | | - let stroke = makeStrokeAttributes(with: state) |
38 | | - let fill = makeFillAttributes(with: state) |
39 | | - return .shape(shape, stroke, fill) |
40 | | - } |
41 | | - |
42 | | - func makeUseLayerContents(from use: DOM.Use, with state: State) throws -> LayerTree.Layer.Contents { |
43 | | - guard |
44 | | - let id = use.href.fragment, |
45 | | - let element = svg.defs.elements[id] else { |
46 | | - throw LayerTree.Error.invalid("missing referenced element: \(use.href)") |
| 35 | + |
| 36 | + func makeShapeContents(from shape: LayerTree.Shape, with state: State) -> LayerTree.Layer.Contents { |
| 37 | + let stroke = makeStrokeAttributes(with: state) |
| 38 | + let fill = makeFillAttributes(with: state) |
| 39 | + return .shape(shape, stroke, fill) |
47 | 40 | } |
48 | | - |
49 | | - let l = makeLayer(from: element, inheriting: state) |
50 | | - let x = use.x ?? 0.0 |
51 | | - let y = use.y ?? 0.0 |
52 | | - |
53 | | - if x != 0 || y != 0 { |
54 | | - l.transform.insert(.translate(tx: x, ty: y), at: 0) |
| 41 | + |
| 42 | + func makeUseLayerContents(from use: DOM.Use, with state: State) throws -> LayerTree.Layer.Contents { |
| 43 | + guard |
| 44 | + let id = use.href.fragment, |
| 45 | + let element = svg.defs.elements[id] else { |
| 46 | + throw LayerTree.Error.invalid("missing referenced element: \(use.href)") |
| 47 | + } |
| 48 | + |
| 49 | + let l = makeLayer(from: element, inheriting: state) |
| 50 | + let x = use.x ?? 0.0 |
| 51 | + let y = use.y ?? 0.0 |
| 52 | + |
| 53 | + if x != 0 || y != 0 { |
| 54 | + l.transform.insert(.translate(tx: x, ty: y), at: 0) |
| 55 | + } |
| 56 | + |
| 57 | + return .layer(l) |
| 58 | + |
| 59 | + } |
| 60 | + |
| 61 | + static func makeTextContents(from text: DOM.Text, with state: State) -> LayerTree.Layer.Contents { |
| 62 | + var point = Point(text.x ?? 0, text.y ?? 0) |
| 63 | + var att = makeTextAttributes(with: state) |
| 64 | + att.fontName = text.attributes.fontFamily ?? att.fontName |
| 65 | + att.size = text.attributes.fontSize ?? att.size |
| 66 | + att.anchor = text.attributes.textAnchor ?? att.anchor |
| 67 | + point.x += makeXOffset(for: text.value, with: att) |
| 68 | + return .text(text.value, point, att) |
55 | 69 | } |
56 | | - |
57 | | - return .layer(l) |
58 | | - |
59 | | - } |
60 | | - |
61 | | - static func makeTextContents(from text: DOM.Text, with state: State) -> LayerTree.Layer.Contents { |
62 | | - let point = Point(text.x ?? 0, text.y ?? 0) |
63 | | - var att = makeTextAttributes(with: state) |
64 | | - att.fontName = text.attributes.fontFamily ?? att.fontName |
65 | | - att.size = text.attributes.fontSize ?? att.size |
66 | | - return .text(text.value, point, att) |
67 | | - } |
68 | | - |
69 | | - static func makeImageContents(from image: DOM.Image) throws -> LayerTree.Layer.Contents { |
70 | | - guard |
71 | | - let decoded = image.href.decodedData, |
72 | | - let im = LayerTree.Image(mimeType: decoded.mimeType, data: decoded.data) else { |
73 | | - throw LayerTree.Error.invalid("Cannot decode image") |
| 70 | + |
| 71 | + static func makeImageContents(from image: DOM.Image) throws -> LayerTree.Layer.Contents { |
| 72 | + guard |
| 73 | + let decoded = image.href.decodedData, |
| 74 | + let im = LayerTree.Image(mimeType: decoded.mimeType, data: decoded.data) else { |
| 75 | + throw LayerTree.Error.invalid("Cannot decode image") |
| 76 | + } |
| 77 | + return .image(im) |
74 | 78 | } |
75 | | - return .image(im) |
76 | | - } |
77 | | - |
78 | | - |
79 | 79 | } |
0 commit comments