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