Comments (4)
Hi. Thanks for the report.
The sample file you attached is an example of the sort of file that I refer to
in the release notes. That is, one that might previously have been scaled but
won't be now.
The reason it is not being scaled is because it has no viewBox defined.
Without a viewBox, there is nothing to tell the renderer how the content should
be scaled to fit the canvas. See
http://www.w3.org/TR/SVG/coords.html#ViewBoxAttribute
In previous versions of the library, I was being a bit over-enthusiastic and
auto-scaling documents that in theory shouldn't have been. That code worked in
some situations, but not others, and made some assumptions that meant that
scaling wouldn't necessarily be correct anyway.
I decided to remove that code and instead provide some API methods that would
allow users to have better control over how scaling happens.
In this particular situation (with this particular file) there are two
solutions to your problem.
Solution 1: Add a viewBox to the file.
Add the following attribute to your root <svg> element.
viewBox="0 0 20 20"
You will also need to remove the "width" and "height" attributes (or
set them to "100%") if you want to scale this document to any size
other than 20x20.
Solution 2: Use the API to make the equivalent changes.
After loading your SVG add the following:
// (setVewBox() values may need to be different for other files)
svg.setDocumentViewBox(0f, 0f, 20f, 20f);
svg.setDocumentWidth("100%");
svg.setDocumentHeight("100%");
My apologies that this release broke your code, but I felt it was important
that I brought AndroidSVG into line with other renderers. Your file as it is
would not scale with any other renderer either.
If you have any other problems, let me know.
Paul
Original comment by [email protected]
on 18 Jul 2013 at 8:31
- Changed state: Invalid
from androidsvg.
Thank you very much for the full response, you have solved my problem.
The problem was not the viewBox. I am using viewBox, but was testing different
options to find if something works and for some reason uploaded a file without
one.
The problem was the presence of width and height. Almost all of my files do not
have width and height, just a few and they had the problem.
Something to note is the fact that the Apache Batik library allows for scaling
when width and height are set in pixels. Apache Batik is perhaps the most
popular SVG library for Java (not Android). I have also tested a few other
non-Android SVG libraries and 5-10 Android libraries and I think most allow for
scaling when width and height are set. Having said that the SVGs I use will not
have width and height from now on, so I will not use it if you decide to change
it.
I am making a game that supports both web and android version and something
else I have noticed not supported by androidsvg is preserveAspectRatio inside
the SVG. For example:
preserveAspectRatio="xMidYMid slice"
Having said that your library is incredible. It is so much better than anything
else available on android, it is unbelievable. With the latest 1.2.0 update it
renders everything I have perfectly (I had some alpha objects rendered solid
color with the previous version).
Original comment by [email protected]
on 18 Jul 2013 at 9:26
from androidsvg.
Thanks for the nice feedback.
You wrote:
> I have noticed not supported by androidsvg is preserveAspectRatio inside the
SVG. For
> example: preserveAspectRatio="xMidYMid slice"
This should be working. My tests are all working. Can you send me an example of
one that fails?
Original comment by [email protected]
on 18 Jul 2013 at 9:37
from androidsvg.
I stand corrected. You are right, preserveAspectRatio does work. I was testing
with files having width and height. Now that I test with correct files it
works. Thank you very much.
On a side note if you are interested in the game I am working on (as it uses
your library) send me a message.
Original comment by [email protected]
on 18 Jul 2013 at 10:02
from androidsvg.
Related Issues (20)
- SVGAndroidRenderer.processMaskBitmaps is very slow HOT 1
- SVGParser is not thread-safe [with fix] (SVG parse error: Invalid colour keyword: white) HOT 2
- Feature request: replace text HOT 6
- FAQ promotes extremely bad backward-compatibility practice HOT 6
- Image references missing SVG support. HOT 3
- Canvas changed after renderToCanvas HOT 1
- Position of Rectf ignored when renderToCanvas HOT 1
- Support for hardware acceleration
- Android version support HOT 1
- Android version support HOT 1
- Pattern fills are rendered with visible grid HOT 4
- Provide copy constructor or allow rendering to multiple viewBox at once HOT 3
- migrate the repository HOT 3
- Move project to Github HOT 1
- NullPointerException in 1.2.2-beta1 when parsing SVG document HOT 4
- SVGImageView crashes on Android 5.0 and higher HOT 5
- Proguard breaks reflective CSS selectors HOT 1
- java.lang.ArrayIndexOutOfBoundsException: length=0; index=-2 in SVGAndroidRenderer.arcTo(SourceFile:2572) HOT 1
- Incorrect rendering of SVG image HOT 5
- Unable to execute dex: Multiple dex files define HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from androidsvg.