almosr / android-svg-code-render

Convert SVG files into Java source and use it in your Android app
Apache License 2.0
24 stars 3 forks source link

Could not convert svg #73

Closed bbratu closed 6 years ago

bbratu commented 7 years ago

First of all, I want to apologize if I am doing something wrong and this is my mistake. I have tried to convert multiple svgs and the only one I was successful with was the creature.svg from https://drive.google.com/file/d/0B2YCglOQi4aNNmtHc0Y2SzZuM2c/edit Some of the svgs give the error

W/android.graphics.Canvas: Inner Matrix instance is not initialized yet when read from Canvas

on conversion but I don't think this is the problem. I think the problem is that the generated java file has these values:

public static final float WIDTH = -1.000000f;
public static final float HEIGHT = -1.000000f;
private static final float[] FLOATCONSTANTARRAY_0 = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f};

while the code generated for creature.svg has positive values:

public static final float WIDTH = 500.000000f;
public static final float HEIGHT = 500.000000f;
private static final float[] FLOATCONSTANTARRAY_0 = {1.0f, 0.0f, 31.4707f, 0.0f, 1.0f, 40.445297f, 0.0f, 0.0f, 1.0f}; .....

If you want to try one of the svgs is the low resolution vector from here: https://www.amcharts.com/svg-maps/?map=world

almosr commented 7 years ago

Thanks for the detailed report. I had a look at the world map SVG, you are right about the problem: the size in the generated file is invalid (obviously width and height must be greater than 0).

The reason why this happened: there is no size defined in the SVG file, the tag needs width and height attributes. Although, this is still valid for SVG, it is not particularly useful when you want to render the SVG to the screen. So, I might say that this is not a bug in the tool, but the current behavior is not particularly useful.

I am going to add an error output to the tool when this happen to make it easier to spot the problem.

To fix the issue for this particular SVG you need to define the document size for the SVG file. It is not too complicated, just load it into any SVG-compatible vector editor and define the page size.

Here, I used Inkscape:

inkscape_before_fix

inkscape_after_fix

bbratu commented 7 years ago

Thank you very much. It worked perfectly.