Giter Site home page Giter Site logo

Using custom fonts about markwon HOT 7 CLOSED

noties avatar noties commented on August 27, 2024
Using custom fonts

from markwon.

Comments (7)

noties avatar noties commented on August 27, 2024

Hey!

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

from markwon.

Arkuda avatar Arkuda commented on August 27, 2024

@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.

from markwon.

noties avatar noties commented on August 27, 2024

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

from markwon.

Arkuda avatar Arkuda commented on August 27, 2024

@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.

from markwon.

Arkuda avatar Arkuda commented on August 27, 2024

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

from markwon.

delacrixmorgan avatar delacrixmorgan commented on August 27, 2024

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

Header - Use Font Gelica
Regular - Use Font Helvetica

from markwon.

delacrixmorgan avatar delacrixmorgan commented on August 27, 2024

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()

from markwon.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.