JoanZapata / android-iconify

Android integration of multiple icon providers such as FontAwesome, Entypo, Typicons,...
http://joanzapata.com/android-iconify
Other
3.93k stars 527 forks source link

Some icons cut off in sample app #155

Open keunes opened 8 years ago

keunes commented 8 years ago

e.g. md-access-alarm and mdi-youtube-play

JoanZapata commented 8 years ago

Can't reproduce, can you please provide a screenshot? Which version are you using?

keunes commented 8 years ago

Iconify 2.1.0 Android 4.2.2 Fairphone 1

Here's two screenshots where I think there's some of the icons which are cut off. screenshot_2016-01-25-10-30-18 screenshot_2016-01-25-10-29-59

JoanZapata commented 8 years ago

That's weird, I can't see that. Thanks for the screenshots, I'll try to reproduce it with the emulator.

mburst commented 8 years ago

Seeing this with the fa-twitter icon in my app. Let me know if there is anything I can do to help debug

hahv commented 4 years ago

To fix, in class IconDrawable change draw method as following: https://stackoverflow.com/questions/12166476/android-canvas-drawtext-set-font-size-from-width

@Override
    public void draw(Canvas canvas) {
        Rect bounds = getBounds();
        int height = bounds.height();
        int desiredWidth = bounds.width();

        float defaultTextSize = height;
        paint.setTextSize(defaultTextSize);

        Rect textBounds = new Rect();
        String textValue = String.valueOf(icon.character());
        paint.getTextBounds(textValue, 0, 1, textBounds);

        // Calculate the desired size as a proportion of our defaultTextSize.
        // fix bug some Icon cut off (because some icon have width > height)
        float desiredTextSize = defaultTextSize *  desiredWidth/ textBounds.width();

        if(desiredTextSize < defaultTextSize) {
            paint.setTextSize(desiredTextSize);
            paint.getTextBounds(textValue, 0, 1, textBounds);
        }

        int textHeight = textBounds.height();
        float textBottom = bounds.top + (height - textHeight) / 2f + textHeight - textBounds.bottom;
        canvas.drawText(textValue, bounds.exactCenterX(), textBottom, paint);
    }