Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for viewBox attribute #185

Merged
merged 8 commits into from
Dec 3, 2020
Merged

support for viewBox attribute #185

merged 8 commits into from
Dec 3, 2020

Conversation

arielelkin
Copy link
Collaborator

Based on @NeedNap's work on #181

Copy link

@NeedNap NeedNap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a good solution. I'll give it a try as soon as I can

@NeedNap
Copy link

NeedNap commented Oct 28, 2020

You should check this function at line

- (CGRect) viewBox {
because not all code paths return a value.
You can see it in the "checks" console

@arielelkin
Copy link
Collaborator Author

@NeedNap thanks, that's fixed now.

@arielelkin
Copy link
Collaborator Author

@NeedNap did you have a chance to give this a try?

@arielelkin
Copy link
Collaborator Author

Hello @NeedNap! Could I please get your approval before merging this? I want to make sure it works for you as you requested the original feature.

@NeedNap
Copy link

NeedNap commented Dec 2, 2020

Hi @arielelkin, I think it's ok. You can merge it.

@arielelkin arielelkin merged commit d0dde62 into master Dec 3, 2020
@arielelkin arielelkin deleted the viewBox branch December 3, 2020 18:26
@arielelkin
Copy link
Collaborator Author

This is now in 2.7.0 🎉

@robaho
Copy link

robaho commented Jun 20, 2024

Hi @arielelkin Is there any docs on how to use this? I have the following SVG that fails to display.

<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#e8eaed"><path d="M200-120q-51 0-72.5-45.5T138-250l222-270v-240h-40q-17 0-28.5-11.5T280-800q0-17 11.5-28.5T320-840h320q17 0 28.5 11.5T680-800q0 17-11.5 28.5T640-760h-40v240l222 270q32 39 10.5 84.5T760-120H200Zm0-80h560L520-492v-268h-80v268L200-200Zm280-280Z"/></svg>

The only way I can get it to work is by changing SVGLayer.m with

        CGRect const pathBounds = path.bounds;
        layer.frame = CGRectApplyAffineTransform(pathBounds, layerTransform);

        CGAffineTransform tx = CGAffineTransformIdentity;
        if(!CGRectEqualToRect(self.viewBox,CGRectNull)) {
            double yScale = size.height /self.viewBox.size.height;
            double xScale = size.width /self.viewBox.size.width;
            double yOffset = (self.viewBox.size.height-size.height)/2;
            double xOffset = (self.viewBox.size.width-size.width)/2;
            tx = CGAffineTransformConcat(CGAffineTransformMakeTranslation(self.viewBox.origin.x,self.viewBox.origin.y*-1),CGAffineTransformMakeScale(xScale,yScale));
        }

        CGAffineTransform const pathTransform = CGAffineTransformConcat(tx,
                                                    CGAffineTransformConcat(CGAffineTransformMakeTranslation(-pathBounds.origin.x,-pathBounds.origin.y),scale));

I can't seem to get it to display in any of the upper layers (e.g. demo apps) with any sort of transform related to the view box.

The SVG displays fine in browser and other online viewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants