SDWebImageSVGKitPlugin icon indicating copy to clipboard operation
SDWebImageSVGKitPlugin copied to clipboard

Stop SDAdjustSVGContentMode from centering?

Open taschmidt opened this issue 6 years ago • 2 comments

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...?

taschmidt avatar Aug 11 '19 05:08 taschmidt

@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 !

dreampiggy avatar Aug 11 '19 10:08 dreampiggy

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?

taschmidt avatar Aug 13 '19 14:08 taschmidt