-
-
Notifications
You must be signed in to change notification settings - Fork 314
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
SvgSupport for svg without a width and height info #165
Comments
Hello @3dmg ! It's an interesting case and I haven't seen SVG without width/height so far. It seems that absent width/height just says We can try rendering such SVGs without scaling, can you try this and see if it solves your problem? public class SvgPictureMediaDecoder extends MediaDecoder {
public static final String CONTENT_TYPE = "image/svg+xml";
@NonNull
public static SvgPictureMediaDecoder create() {
return new SvgPictureMediaDecoder();
}
@NonNull
@Override
public Drawable decode(@Nullable String contentType, @NonNull InputStream inputStream) {
final SVG svg;
try {
svg = SVG.getFromInputStream(inputStream);
} catch (SVGParseException e) {
throw new IllegalStateException("Exception decoding SVG", e);
}
final Picture picture = svg.renderToPicture();
return new PictureDrawable(picture);
}
@NonNull
@Override
public Collection<String> supportedTypes() {
return Collections.singleton(CONTENT_TYPE);
}
} And usage (this will replace default SvgMediaDecoder): final Markwon markwon = Markwon.builder(context)
.usePlugin(ImagesPlugin.create(configure -> {
configure.addMediaDecoder(SvgPictureMediaDecoder.create());
}))
.build(); |
Yes, this is working. Thank you! When you need it, here you find a big list of different SVGs, with and without the size info: https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/ |
Thanks, I'm going to take a look at it and see if some generic solution can be implemented 👍 |
I have added |
First of all, thank you for your great work!
When I want to load a SVG without a
width & height
set in the file, I get this exception:Most of the SVGs, I found online, were without these size information.
Is it possible to fallback to a default size for this case or is there another solution?
One example of an affected SVG: https://upload.wikimedia.org/wikipedia/commons/d/d7/Android_robot.svg
The text was updated successfully, but these errors were encountered: