-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add more meaningful error messages around font loading
- Loading branch information
1 parent
e919805
commit dc4b7ba
Showing
9 changed files
with
111 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
easylauncher/src/main/kotlin/com/project/starter/easylauncher/filter/DefaultFont.kt
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
easylauncher/src/main/kotlin/com/project/starter/easylauncher/filter/FontLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.project.starter.easylauncher.filter | ||
|
||
import java.awt.Font | ||
import java.io.File | ||
|
||
private object FontLoader | ||
|
||
private val EASYLAUNCHER_DEFAULT_FONT by lazy { | ||
FontLoader::class.java.classLoader | ||
.getResourceAsStream("Roboto-Regular.ttf") | ||
.use { | ||
runCatching { Font.createFont(Font.TRUETYPE_FONT, it) } | ||
.getOrElse { error("Couldn't load bundled font. Visit issue #201 for more details") } | ||
} | ||
} | ||
|
||
internal fun getFont( | ||
resource: File?, | ||
name: String?, | ||
): Font { | ||
if (resource != null) { | ||
if (!resource.exists()) { | ||
error("${resource.path} does not exits. Make sure it points at existing font resource.") | ||
} | ||
|
||
return runCatching { Font.createFont(Font.TRUETYPE_FONT, resource) } | ||
.getOrElse { throw IllegalStateException("Error while loading ${resource.path}", it) } | ||
} | ||
|
||
if (name != null) { | ||
return runCatching { Font.decode(name) } | ||
.getOrElse { throw IllegalStateException("Couldn't load font $name.", it) } | ||
} | ||
|
||
return EASYLAUNCHER_DEFAULT_FONT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters