Skip to content
This repository has been archived by the owner on Aug 3, 2022. It is now read-only.

Stop SDAdjustSVGContentMode from centering? #1

Open
taschmidt opened this issue Aug 11, 2019 · 2 comments
Open

Stop SDAdjustSVGContentMode from centering? #1

taschmidt opened this issue Aug 11, 2019 · 2 comments

Comments

@taschmidt
Copy link

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
Copy link
Contributor

dreampiggy commented Aug 11, 2019

@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
Copy link
Author

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?

@dreampiggy dreampiggy transferred this issue from SDWebImage/SDWebImageSVGCoder Nov 15, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants