exyte / Macaw

Powerful and easy-to-use vector graphics Swift library with SVG support
MIT License
6.01k stars 554 forks source link

Using SVG image as mask for a node produces blurred lines #674

Open K-Be opened 4 years ago

K-Be commented 4 years ago

I need to use a SVG icon to make masked image with appropriated colour. (Same as UIImageView creates it for UIImages with UIImage.RenderingMode.alwaysTemplate) For this I've wrote a code:

func coloredNode(_ node: Node, withColor color: UIColor) -> Node {
        let cloner = FASVGNodeDuplicator()
        let maskNode = cloner.clone(node)
        let locus = node.bounds ?? Rect(x: 0.0, y: 0.0, w: 28.0, h: 28.0)
        let imageNode = Shape(form: locus,
                                      fill: Color(withColor: color),
                                      mask: maskNode)
                return imageNode
    }

bounds always presents, therefore a code Rect(x: 0.0, y: 0.0, w: 28.0, h: 28.0) never will called.

For example, my icon has size 2626, on a screen with 2x, it will drawn with pixel size 5252. I saw that result has blurred lines. After some research I've found that in method getMaskedImage generated CGImage mask with size 26*26. It produces blurred result: Screenshot 2020-03-06 at 12 28 53

How I can make mask with an alpha component of a node with respects of a screen scale?