mirror of
https://github.com/exyte/Macaw.git
synced 2024-08-15 16:10:39 +03:00
change location of SVGKeys
This commit is contained in:
parent
d08bd4a60b
commit
922a68bf6f
@ -1,11 +1,5 @@
|
||||
open class SVGConstants {
|
||||
|
||||
public enum Keys {
|
||||
public static let fill = "fill"
|
||||
public static let color = "color"
|
||||
public static let currentColor = "currentColor"
|
||||
}
|
||||
|
||||
public static let valueToColor = [
|
||||
0x000000: "black",
|
||||
0x000080: "navy",
|
||||
|
@ -156,7 +156,7 @@ open class SVGParser {
|
||||
}
|
||||
if let id = element.allAttributes["id"]?.text {
|
||||
switch element.name {
|
||||
case "linearGradient", "radialGradient", SVGConstants.Keys.fill:
|
||||
case "linearGradient", "radialGradient", SVGKeys.fill:
|
||||
defFills[id] = try parseFill(node)
|
||||
case "pattern":
|
||||
defPatterns[id] = try parsePattern(node)
|
||||
@ -316,7 +316,7 @@ open class SVGParser {
|
||||
case "use":
|
||||
return try parseUse(node, groupStyle: style, place: position)
|
||||
case "title", "desc", "mask", "clip", "filter",
|
||||
"linearGradient", "radialGradient", SVGConstants.Keys.fill:
|
||||
"linearGradient", "radialGradient", SVGKeys.fill:
|
||||
break
|
||||
default:
|
||||
print("SVG parsing error. Shape \(element.name) not supported")
|
||||
@ -571,12 +571,12 @@ open class SVGParser {
|
||||
}
|
||||
}
|
||||
|
||||
let hasCurrentColor = styleAttributes[SVGConstants.Keys.fill] == SVGConstants.Keys.currentColor
|
||||
let hasCurrentColor = styleAttributes[SVGKeys.fill] == SVGKeys.currentColor
|
||||
|
||||
self.availableStyleAttributes.forEach { availableAttribute in
|
||||
if let styleAttribute = element.allAttributes[availableAttribute]?.text, styleAttribute != "inherit" {
|
||||
|
||||
if !hasCurrentColor || availableAttribute != SVGConstants.Keys.color {
|
||||
if !hasCurrentColor || availableAttribute != SVGKeys.color {
|
||||
styleAttributes.updateValue(styleAttribute, forKey: availableAttribute)
|
||||
}
|
||||
}
|
||||
@ -630,7 +630,7 @@ open class SVGParser {
|
||||
opacity = Double(fillOpacity.replacingOccurrences(of: " ", with: "")) ?? 1
|
||||
}
|
||||
|
||||
guard var fillColor = styleParts[SVGConstants.Keys.fill] else {
|
||||
guard var fillColor = styleParts[SVGKeys.fill] else {
|
||||
return Color.black.with(a: opacity)
|
||||
}
|
||||
if let colorId = parseIdFromUrl(fillColor) {
|
||||
@ -641,7 +641,7 @@ open class SVGParser {
|
||||
return getPatternFill(pattern: pattern, locus: locus)
|
||||
}
|
||||
}
|
||||
if fillColor == SVGConstants.Keys.currentColor, let currentColor = groupStyle[SVGConstants.Keys.color] {
|
||||
if fillColor == SVGKeys.currentColor, let currentColor = groupStyle[SVGKeys.color] {
|
||||
fillColor = currentColor
|
||||
}
|
||||
|
||||
@ -665,7 +665,7 @@ open class SVGParser {
|
||||
guard var strokeColor = styleParts["stroke"] else {
|
||||
return .none
|
||||
}
|
||||
if strokeColor == SVGConstants.Keys.currentColor, let currentColor = groupStyle[SVGConstants.Keys.color] {
|
||||
if strokeColor == SVGKeys.currentColor, let currentColor = groupStyle[SVGKeys.color] {
|
||||
strokeColor = currentColor
|
||||
}
|
||||
var opacity: Double = 1
|
||||
@ -1002,7 +1002,7 @@ open class SVGParser {
|
||||
let attributes = getStyleAttributes([:], element: element)
|
||||
|
||||
return Text(text: text, font: getFont(attributes, fontName: fontName, fontWeight: fontWeight, fontSize: fontSize),
|
||||
fill: (attributes[SVGConstants.Keys.fill] != nil) ? getFillColor(attributes)! : fill, stroke: stroke ?? getStroke(attributes),
|
||||
fill: (attributes[SVGKeys.fill] != nil) ? getFillColor(attributes)! : fill, stroke: stroke ?? getStroke(attributes),
|
||||
align: anchorToAlign(textAnchor ?? getTextAnchor(attributes)), baseline: .alphabetic,
|
||||
place: pos, opacity: getOpacity(attributes), tag: getTag(element))
|
||||
}
|
||||
@ -1357,7 +1357,7 @@ open class SVGParser {
|
||||
}
|
||||
var color = Color.black.with(a: opacity)
|
||||
if var stopColor = getStyleAttributes([:], element: element)["stop-color"] {
|
||||
if stopColor == SVGConstants.Keys.currentColor, let currentColor = groupStyle[SVGConstants.Keys.color] {
|
||||
if stopColor == SVGKeys.currentColor, let currentColor = groupStyle[SVGKeys.color] {
|
||||
stopColor = currentColor
|
||||
}
|
||||
color = createColor(stopColor.replacingOccurrences(of: " ", with: ""), opacity: opacity)!
|
||||
@ -1847,3 +1847,9 @@ fileprivate class UserSpacePattern {
|
||||
self.contentUserSpace = contentUserSpace
|
||||
}
|
||||
}
|
||||
|
||||
fileprivate enum SVGKeys {
|
||||
static let fill = "fill"
|
||||
static let color = "color"
|
||||
static let currentColor = "currentColor"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user