SDWebImage / SDWebImageSVGKitPlugin

A SDWebImage plugin to support SVG with SVGKit and category
MIT License
16 stars 21 forks source link

Stop SDAdjustSVGContentMode from centering? #1

Open taschmidt opened 5 years ago

taschmidt commented 5 years ago

I'd like to load an SVG with aspect fit but I'd like it to draw top left rather than centered. In other words, skip this behavior:

https://github.com/SDWebImage/SDWebImageSVGCoder/blob/master/SDWebImageSVGCoder/Classes/SDWebImageSVGCoderDefine.m#L46

I tried setting the viewport to x:0 and y:0 in my completion block of sd_setImage but it doesn't appear to have any effect...?

dreampiggy commented 5 years ago

@taschmidt This is just a convenient method for most use case, when you specify sd_adjustContentMode = YES, it try to modify the SVG DOM tree to adjust content fit.

Actually, you can keep sd_adjustContentMode = NO (by default it's NO). And adjust the SVGKImage DOM tree by your self.

For your cases, you can change the viewBox, but not the viewPort. You can change the viewport (x, y, w, h) -> (x - x1, y-y1, w, h), x1, y1 depends on your SVG's draw image code's offset X and Y.....

Learn more here: http://tutorials.jenkov.com/svg/svg-viewport-view-box.html

Actually, I'm not be expert on SVG spec. I just a normal user of SVGKit and provide this codec for SDWebImage. If you think this implementation has something wrong or better way to declare the syntax, PR is welcomed !

taschmidt commented 5 years ago

I tried messing with viewBox and viewport in the completion handler of sd_setImage and couldn't get it working so I reverted back to using SVGKit directly. One problem I had when messing with it in that handler was multiple SVG images composited on top of each other. I'm not sure if I was doing something wrong?