Calligraphy icon indicating copy to clipboard operation
Calligraphy copied to clipboard

Default font style not applied on older platforms <4.0.4

Open drindt opened this issue 9 years ago • 10 comments

I test the calligraphy styled application on a older android 4.0.4 (GT-P7100) with the result that the font is not applied. It seems that the default definition isn't applied which i have declared in this way:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:textAppearance">@style/LightTextAppearance</item>
    </style>

    <style name="LightTextAppearance" parent="android:TextAppearance">
        <item name="fontPath">fonts/LightWeb.ttf</item>
    </style>

This worked fine so far on other devices and api level. What can i do further solving this issue?

drindt avatar Apr 19 '16 07:04 drindt

Here's what README.md says about this:

Define your default font using CalligraphyConfig, in your Application class in the #onCreate() method.

@Override
public void onCreate() {
    super.onCreate();
    CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
                            .setDefaultFontPath("fonts/Roboto-RobotoRegular.ttf")
                            .setFontAttrId(R.attr.fontPath)
                            .build()
            );
    //....
}

Note: You don't need to define CalligraphyConfig but the library will apply no default font and use the default attribute of R.id.fontPath.

consp1racy avatar Apr 19 '16 18:04 consp1racy

I had exactly this set, but without effect. I changed the font right now, and now it works as expected. Seems the font is the problem. The font can just set in the styles to work.

drindt avatar Apr 19 '16 19:04 drindt

OTF fonts are a pain they hardly work. And you need to use well formatted TTF, (Generally Webfonts work)

chrisjenx avatar Apr 19 '16 23:04 chrisjenx

But what lets me wonder it seems there is a difference in handling the font. Then it works well when i set it in styles.xml, programmatically in application class has no effect. I have attached the font t let you confirm. BrooklynSamuelsNo5-LightWeb.ttf.zip

drindt avatar Apr 20 '16 05:04 drindt

Post a sample of how you are setting it too. Cheers.

On Wed, 20 Apr 2016, 06:38 Daniel Rindt, [email protected] wrote:

But what lets me wonder it seems there is a difference in handling the font. Then it works well when i set it in styles.xml, programmatically in application class has no effect. I have attached the font t let you confirm. BrooklynSamuelsNo5-LightWeb.ttf.zip https://github.com/chrisjenx/Calligraphy/files/227261/BrooklynSamuelsNo5-LightWeb.ttf.zip

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/chrisjenx/Calligraphy/issues/277#issuecomment-212267293

chrisjenx avatar Apr 20 '16 07:04 chrisjenx

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
       ...
        <item name="android:textAppearance">@style/LightTextAppearance</item>
    </style>

    <style name="LightTextAppearance" parent="android:TextAppearance">
        <item name="fontPath">fonts/BrooklynSamuelsNo5-LightWeb.ttf</item>
    </style>

This is how i add it. And it works on platforms >4.0.4. Applications onCreate:

CalligraphyConfig.initDefault(new Builder()
    .setFontAttrId(R.attr.fontPath)
    .build());

It makes no difference if i add this too:

.setDefaultFontPath("fonts/BrooklynSamuelsNo5-LightWeb.ttf")

If i set another ttf there it works.

drindt avatar Apr 20 '16 07:04 drindt

Out of interest what is the other TTF?

chrisjenx avatar Apr 20 '16 13:04 chrisjenx

Yeah the fonts are loaded the same way, have a look. one one works through styles only pre 4.0.4 is bizzare...

chrisjenx avatar Apr 25 '16 17:04 chrisjenx

Yes, thank you for caring!

drindt avatar Apr 25 '16 17:04 drindt