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

Using custom fonts #24

Closed
Arkuda opened this issue Jan 11, 2018 · 7 comments
Closed

Using custom fonts #24

Arkuda opened this issue Jan 11, 2018 · 7 comments

Comments

@Arkuda
Copy link

Arkuda commented Jan 11, 2018

Is it possible to use custom fonts painlessly? SpannableTheme does not represent such an opportunity. You can use the custom font, but only for blocks of code.

@noties
Copy link
Owner

noties commented Jan 11, 2018

Hey!

Of cause it's possible! You can change font as usual (applying it for a TextView directly)

@Arkuda
Copy link
Author

Arkuda commented Jan 11, 2018

@noties hey. What i do wrong ?
I create TextView, render markdown to it Markwon.setMarkdown(textView,markdownStr);,
create typeface from asset Typeface typeface = Typeface.createFromAsset(context.getAssets(), "myfont.ttf"); and apply it textView.setTypeface(typeface);, but typeface don't changes.

@noties
Copy link
Owner

noties commented Jan 11, 2018

Most likely there is some issue with loading your custom typeface.

  • make sure that your custom typeface file is located in root of assets (not raw) folder (it can be in a nested folder, but then you have to specify it like: Typeface.createFromAsset(getAssets(), "fonts/myfont.ttf")
  • make sure that you have specified file name correctly
  • make sure that it's valid typeface (maybe it's corrupted or something)

I have just checked setting custom typeface in the sample application and it works as expected (Noto Serif):
screenshot_1515677324

@Arkuda
Copy link
Author

Arkuda commented Jan 11, 2018

@noties can you show the code of sample ? Because Typeface.createFromAsset(context.getAssets(), "myfont.ttf"); works normal and return work typeface, i use him in config SpannableTheme.builder().codeTypeface(typeface) to MarkwonView, and in MarkwonView some parts of text renders with this font. But only some parts.

@Arkuda
Copy link
Author

Arkuda commented Jan 11, 2018

Oh... this is problem in my code. Typeface is not setting in TextView. Sorry, its my problem. Thx, super library.

@Arkuda Arkuda closed this as completed Jan 11, 2018
@delacrixmorgan
Copy link

Is it possible to add different custom fonts depending on which type you are?
For example.

Header - Use Font Gelica
Regular - Use Font Helvetica

@delacrixmorgan
Copy link

delacrixmorgan commented Jan 5, 2023

Alright, I've figure it out. It's actually using AbstractMarkwonPlugin.configureTheme to set the headingTypeface.
Then, I just use the conventional TextField.style from Android SDK to set it for the rest.

Not ideal, but workable.

val markwon = Markwon.builder(requireContext())
      .usePlugin(object : AbstractMarkwonPlugin() {
          override fun configureTheme(builder: MarkwonTheme.Builder) {
              val gelicaTypeface = ResourcesCompat.getFont(requireContext(), R.font.gelica_regular)
              val maisonTypeface = ResourcesCompat.getFont(requireContext(), R.font.maison_neue)
            
              builder.headingTypeface(gelicaTypeface)
          }
      }).build()

@noties noties reopened this Apr 13, 2023
@noties noties closed this as completed Apr 13, 2023
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

3 participants