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

Fontawesome svg not loaded #448

Open
visyone opened this issue Jul 7, 2023 · 0 comments
Open

Fontawesome svg not loaded #448

visyone opened this issue Jul 7, 2023 · 0 comments

Comments

@visyone
Copy link

visyone commented Jul 7, 2023

Hi, I'm trying to use markown to show fontawesome icons (SVGs) as an image in a HTML tag, but I can figure it out.

I have configured the markown instance like this:

Markown markown = Markwon.builder(ctx).usePlugins(List.of(
           HtmlPlugin.create(),
           ImagesPlugin.create(plugin -> plugin.addSchemeHandler(OkHttpNetworkSchemeHandler.create(new OkHttpClient()))),
           ImagesPlugin.create(plugin -> plugin.addSchemeHandler(FileSchemeHandler.createWithAssets(ctx)))
           ))
           .build();

I have put the font awesome files in the assets folder of the app (the path to an icon is assets/fontawesome/svgs/solid/plus.svg)

and I used the com.caverock:androidsvg:1.4 dependency for render the SVGs.

With this configuration I'm try to display the following markdown:

<img alt=\"font-awesome-plus\" src=\"file:///android_asset/fontawesome/svgs/solid/plus.svg\" width=\"150px\" height=\"150px\">

The SVG is not loaded (the alt text of the image is shown) and the error seems referees to the decode function of the SVGMediaDecoder class

    @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 float w = svg.getDocumentWidth();
        final float h = svg.getDocumentHeight();
        final float density = resources.getDisplayMetrics().density;

        final int width = (int) (w * density + .5F);
        final int height = (int) (h * density + .5F);

        final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);
        final Canvas canvas = new Canvas(bitmap);
        canvas.scale(density, density);
        svg.renderToCanvas(canvas);

        return new BitmapDrawable(resources, bitmap);
    }

when the decode function runs the width and height are -1 causing the error in Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_4444);

Which configuration do I miss?

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

No branches or pull requests

1 participant