Open gonzobrains opened 3 years ago
Can you provide a sample snippet of the code?
What were you using previously?
I added this in MainApplication:OnCreate():
CalligraphyConfig.Builder builder = new CalligraphyConfig.Builder(); CalligraphyConfig config = builder.SetDefaultFontPath("/fonts/Ubuntu-Regular.ttf").Build(); CalligraphyConfig.InitDefault(config);
I didn't have anything here before. My TextViews all have something like this:
fontPath="fonts/Ubuntu-Medium.ttf"
My BaseActivity.cs looks like this:
protected override void AttachBaseContext(Context newBase) { base.AttachBaseContext(CalligraphyContextWrapper.Wrap(newBase)); }
My fonts are in this folder:
Just as I suspected, Android can't find my fonts. How do I update the path to work with your library?
I just read your TypeFace load() code. I may have to remove the leading "/"
Hi, again. It looks like I resolved the error, but the fonts are still not being used. What else should I try?
Are you compiling the fonts correct as assets
?
Hi. Thanks for the quick response. I did not originally write the code so I am not familiar with the original usage of the old Calligraphy 2 library.
Is this what you mean by compiling them correctly (ie., setting the Build Action to AndroidAsset)?
I've literally left everything in place as it was with the old library (fonts, font paths, layout XML files, etc). The only change I made was to the Application class as I wrote above. Do I need to add an interceptor or something? I didn't see that in your instructions but I see some dialog about it in the underlying native project's github.
Thanks again!
What are you referring to with the "Old Calligraphy 2" Library? you mean the original java one?
The mikescandy one:
https://github.com/mikescandy/Calligraphy-xamarin
I uninstalled it, installed yours, and made some tweaks.
If you can do a quick test, Android compilers someones don't like having a -
in the filename. I know this is mostly for resources, but maybe you can test the fonts as well? Either remove the -
or change to a _
I will try this. Is this something that could have changed with API Level 29? The font names haven't changed in a while and I haven't updated VS lately either.
What else should I check while I'm at it?
On Thu, Dec 10, 2020, 2:59 PM Nathan Westfall notifications@github.com wrote:
If you can do a quick test, Android compilers someones don't like having a
- in the filename. I know this is mostly for resources, but maybe you can test the fonts as well? Either remove the - or change to a _
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/nwestfall/Calligraphy.Xamarin/issues/15#issuecomment-742761951, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACY5JXCLEII64MT76PSA4LSUESCXANCNFSM4UVLZORQ .
If you can do a quick test, Android compilers someones don't like having a
-
in the filename. I know this is mostly for resources, but maybe you can test the fonts as well? Either remove the-
or change to a_
I tried this. It didn't help.
Can you explain how to do this (from your documentation)? Perhaps I am missing something:
"Define your default font using CalligraphyConfig, in your Application class in the #onCreate() method and pass it to the CalligraphyInterceptor that you add to your ViewPump builder."
I have a similar issue with fonts not loading. I made the same switch from https://github.com/mikescandy/Calligraphy-xamarin as part of an upgrade to API30.
I've found that the default font using SetDefaultFontPath("...")
is applied correctly.
I'm also using the fontPath
property in xml to apply FontAwesome to some controls as needed, but these don't get applied at all. It seems that fontPath is ignored in favour of the default font above.
I cloned the source to see what was going on, and I think I've found the issue (at least in my case).
In CalligraphyFactory.OnViewCreatedInternal
the font path is correctly resolved from the xml property.
The next part then sets the textViewFont
variable to null (in my case it's the else branch that gets called):
// Try theme attributes
if(!string.IsNullOrEmpty(textViewFont))
{
int[] styleForTextView = GetStyleForTextView(textView);
if (styleForTextView[1] != -1)
textViewFont = CalligraphyUtils.PullFontPathFromTheme(context, styleForTextView[0], styleForTextView[1], attributeId);
else
textViewFont = CalligraphyUtils.PullFontPathFromTheme(context, styleForTextView[0], attributeId);
}
Commenting out the above section loads the font as expected.
Digging deeper, CalligraphyUtils.cs line 238 seems to be setting the null from the typedArray.GetString(0)
call.
Hi,
I switched to using your project after I had to upgrade my project to API Level 29. I was previously using Callygraphy.Xamarin, which I believe is deprecated and doesn't support Android 10.
My project builds but I don't see my fonts coming up. I even added the config code to OnCreate() per your instructions. Is this a drop-in replacement or do I have to make more code changes? All of my fonts are under my projects "Asset/fonts" folder.
Thanks, Jeff