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

Font not loading #1347

Open
codezan opened this issue Nov 28, 2021 · 1 comment
Open

Font not loading #1347

codezan opened this issue Nov 28, 2021 · 1 comment

Comments

@codezan
Copy link

codezan commented Nov 28, 2021

I am having trouble loading a particular Font in my app.
The .ttf file is in the resources folder and the path to the file is also correct. This is the code I used to check:

val fontStr = "fonts/FiraCode-Regular.ttf".apply {
  val inputStream = MethodHandles.lookup().lookupClass().getResourceAsStream(this)
  val clazzPackage = MethodHandles.lookup().lookupClass().packageName

  println("FONT LOADING: $clazzPackage -> $inputStream -> ${loadFont("fonts/FiraCode-Regular.ttf", 14)}")
}

The output when I run the application is
FONT LOADING: me.blocky.logreader.style -> java.io.BufferedInputStream@6ebd22fa -> null
Clearly, the file is there since the inputStream is not null. But the loadFont method still returns null.
Does anybody know what's going on?

@SchweinchenFuntik
Copy link
Contributor

fonts/FiraCode-Regular.ttf - relative path
/fonts/FiraCode-Regular.ttf - absolute path

the first option will result in errors if your class is in the org.name package since the full path will be org/name/fons/FiraCode-Regular.ttf

see #1313

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

2 participants