1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-09-21 01:47:44 +03:00

Fix tspan position and color

This commit is contained in:
Alisa Mylnikova 2018-05-07 15:10:12 +07:00
parent 495f42e864
commit 68b5762a0a

View File

@ -883,7 +883,7 @@ open class SVGParser {
if nextString.rangeOfCharacter(from: CharacterSet.whitespacesAndNewlines).location == 0 {
withWhitespace = true
}
return collectTspans(fullString.substring(from: closingTagRange.location + closingTagRange.length), collectedTspans: collection, withWhitespace: withWhitespace, textAnchor: textAnchor, fill: fill, stroke: stroke, opacity: opacity, fontName: fontName, fontSize: fontSize, fontWeight: fontWeight, bounds: text.bounds())
return collectTspans(fullString.substring(from: closingTagRange.location + closingTagRange.length), collectedTspans: collection, withWhitespace: withWhitespace, textAnchor: textAnchor, fill: fill, stroke: stroke, opacity: opacity, fontName: fontName, fontSize: fontSize, fontWeight: fontWeight, bounds: Rect(x: bounds.x, y: bounds.y, w: bounds.w + text.bounds().w, h: bounds.h))
}
// parse as regular text element
var textString: NSString
@ -902,9 +902,12 @@ open class SVGParser {
fill: fill ?? Color.black, stroke: stroke, align: anchorToAlign(textAnchor), baseline: .alphabetic,
place: Transform().move(dx: bounds.x + bounds.w, dy: bounds.y), opacity: opacity)
collection.append(text)
if tagRange.location >= fullString.length { // leave recursion
return collection
}
return collectTspans(fullString.substring(from: tagRange.location), collectedTspans: collection,
withWhitespace: nextStringWhitespace, textAnchor: textAnchor, fill: fill, stroke: stroke,
opacity: opacity, fontName: fontName, fontSize: fontSize, fontWeight: fontWeight, bounds: text.bounds())
opacity: opacity, fontName: fontName, fontSize: fontSize, fontWeight: fontWeight, bounds: Rect(x: bounds.x, y: bounds.y, w: bounds.w + text.bounds().w, h: bounds.h))
}
fileprivate func parseTspan(_ tspan: XMLIndexer, withWhitespace: Bool = false, textAnchor: String?, fill: Fill?, stroke: Stroke?, opacity: Double, fontName: String?, fontSize: Int?, fontWeight: String?, bounds: Rect) -> Text? {
@ -920,7 +923,7 @@ open class SVGParser {
let attributes = getStyleAttributes([:], element: element)
return Text(text: text, font: getFont(attributes, fontName: fontName, fontWeight: fontWeight, fontSize: fontSize),
fill: fill ?? getFillColor(attributes) ?? Color.black, stroke: stroke ?? getStroke(attributes),
fill: ((attributes["fill"] != nil) ? getFillColor(attributes)! : fill) ?? Color.black, stroke: stroke ?? getStroke(attributes),
align: anchorToAlign(textAnchor ?? getTextAnchor(attributes)), baseline: .alphabetic,
place: pos, opacity: getOpacity(attributes), tag: getTag(element))
}