mirror of
https://github.com/curioustorvald/Terrarum-sans-bitmap.git
synced 2026-06-06 05:58:30 +09:00
making new font class for typewriter; renaming existing one with more sensible name
This commit is contained in:
@@ -7,7 +7,7 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch
|
|||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer
|
||||||
import com.badlogic.gdx.utils.ScreenUtils
|
import com.badlogic.gdx.utils.ScreenUtils
|
||||||
import com.badlogic.gdx.utils.StreamUtils
|
import com.badlogic.gdx.utils.StreamUtils
|
||||||
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
|
import net.torvald.terrarumsansbitmap.gdx.TerrarumSansBitmap
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
|
||||||
@@ -16,7 +16,7 @@ import java.io.OutputStream
|
|||||||
*/
|
*/
|
||||||
class FontTestGDX : Game() {
|
class FontTestGDX : Game() {
|
||||||
|
|
||||||
lateinit var font: GameFontBase
|
lateinit var font: TerrarumSansBitmap
|
||||||
|
|
||||||
lateinit var inputText: List<String>
|
lateinit var inputText: List<String>
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ class FontTestGDX : Game() {
|
|||||||
private val outimageName = if (testing) "testing.PNG" else "demo.PNG"
|
private val outimageName = if (testing) "testing.PNG" else "demo.PNG"
|
||||||
|
|
||||||
override fun create() {
|
override fun create() {
|
||||||
font = GameFontBase("./assets", flipY = false, errorOnUnknownChar = false, shadowAlpha = 0.796f) // must test for two flipY cases
|
font = TerrarumSansBitmap("./assets", flipY = false, errorOnUnknownChar = false, shadowAlpha = 0.796f) // must test for two flipY cases
|
||||||
|
|
||||||
val inTextFile = Gdx.files.internal("./$demotextName")
|
val inTextFile = Gdx.files.internal("./$demotextName")
|
||||||
val reader = inTextFile.reader("UTF-8")
|
val reader = inTextFile.reader("UTF-8")
|
||||||
|
|||||||
@@ -92,21 +92,29 @@ internal typealias Hash = Long
|
|||||||
*
|
*
|
||||||
* Created by minjaesong on 2017-06-15.
|
* Created by minjaesong on 2017-06-15.
|
||||||
*/
|
*/
|
||||||
class GameFontBase(
|
class TerrarumSansBitmap(
|
||||||
fontDir: String,
|
fontDir: String,
|
||||||
val noShadow: Boolean = false,
|
val noShadow: Boolean = false,
|
||||||
val flipY: Boolean = false,
|
val flipY: Boolean = false,
|
||||||
val invertShadow: Boolean = false,
|
val invertShadow: Boolean = false,
|
||||||
val minFilter: Texture.TextureFilter = Texture.TextureFilter.Nearest,
|
var errorOnUnknownChar: Boolean = false,
|
||||||
val magFilter: Texture.TextureFilter = Texture.TextureFilter.Nearest,
|
val textCacheSize: Int = 256,
|
||||||
var errorOnUnknownChar: Boolean = false,
|
|
||||||
val textCacheSize: Int = 256,
|
|
||||||
val debug: Boolean = false,
|
val debug: Boolean = false,
|
||||||
val shadowAlpha: Float = 0.5f,
|
val shadowAlpha: Float = 0.5f,
|
||||||
val shadowAlphaPremultiply: Boolean = false
|
val shadowAlphaPremultiply: Boolean = false
|
||||||
) : BitmapFont() {
|
) : BitmapFont() {
|
||||||
|
|
||||||
constructor(fontDir: String, noShadow: Boolean, flipY: Boolean, invertShadow: Boolean) : this(fontDir, noShadow, flipY, invertShadow, Texture.TextureFilter.Nearest, Texture.TextureFilter.Nearest, false, 256, false)
|
constructor(fontDir: String, noShadow: Boolean, flipY: Boolean, invertShadow: Boolean) : this(fontDir, noShadow, flipY, invertShadow, false, 256, false)
|
||||||
|
|
||||||
|
/* This font is a collection of various subsystems, and thus contains copious amount of quick-and-dirty codes.
|
||||||
|
*
|
||||||
|
* Notable subsystems:
|
||||||
|
* - Hangul Assembler with 19 sets
|
||||||
|
* - Cyrillic Bulgarian and Serbian Variant Selectors
|
||||||
|
* - Colour Codes
|
||||||
|
* - Insular, Kana (these are relatively trivial; they just attemps to merge various Unicode sections
|
||||||
|
* into one sheet and gives custom internal indices)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* lowercase AND the height is equal to x-height (e.g. lowercase B, D, F, H, K, L, ... does not count
|
* lowercase AND the height is equal to x-height (e.g. lowercase B, D, F, H, K, L, ... does not count
|
||||||
@@ -320,12 +328,11 @@ class GameFontBase(
|
|||||||
|
|
||||||
override fun getLineHeight(): Float = H.toFloat()
|
override fun getLineHeight(): Float = H.toFloat()
|
||||||
|
|
||||||
override fun getXHeight() = lineHeight
|
override fun getXHeight() = 8f
|
||||||
override fun getCapHeight() = lineHeight
|
override fun getCapHeight() = 12f
|
||||||
override fun getAscent() = 0f
|
override fun getAscent() = 3f
|
||||||
override fun getDescent() = 0f
|
override fun getDescent() = 3f
|
||||||
|
override fun isFlipped() = flipY
|
||||||
override fun isFlipped() = false
|
|
||||||
|
|
||||||
override fun setFixedWidthGlyphs(glyphs: CharSequence) {
|
override fun setFixedWidthGlyphs(glyphs: CharSequence) {
|
||||||
throw UnsupportedOperationException("Nope, no monospace, and figures are already fixed width, bruv.")
|
throw UnsupportedOperationException("Nope, no monospace, and figures are already fixed width, bruv.")
|
||||||
@@ -1204,11 +1211,11 @@ class GameFontBase(
|
|||||||
|
|
||||||
val newColor = Color(pixel)
|
val newColor = Color(pixel)
|
||||||
newColor.a *= shadowAlpha
|
newColor.a *= shadowAlpha
|
||||||
/*if (shadowAlphaPremultiply) {
|
if (shadowAlphaPremultiply) {
|
||||||
newColor.r *= shadowAlpha
|
newColor.r *= shadowAlpha
|
||||||
newColor.g *= shadowAlpha
|
newColor.g *= shadowAlpha
|
||||||
newColor.b *= shadowAlpha
|
newColor.b *= shadowAlpha
|
||||||
}*/
|
}
|
||||||
|
|
||||||
// in the current version, all colour-coded glyphs are guaranteed
|
// in the current version, all colour-coded glyphs are guaranteed
|
||||||
// to be opaque
|
// to be opaque
|
||||||
@@ -1282,8 +1289,8 @@ class GameFontBase(
|
|||||||
else throw IllegalArgumentException("Font scale cannot be zero or negative (input: $value)")
|
else throw IllegalArgumentException("Font scale cannot be zero or negative (input: $value)")
|
||||||
}
|
}
|
||||||
|
|
||||||
fun toColorCode(argb4444: Int): String = GameFontBase.toColorCode(argb4444)
|
fun toColorCode(argb4444: Int): String = TerrarumSansBitmap.toColorCode(argb4444)
|
||||||
fun toColorCode(r: Int, g: Int, b: Int, a: Int = 0x0F): String = GameFontBase.toColorCode(r, g, b, a)
|
fun toColorCode(r: Int, g: Int, b: Int, a: Int = 0x0F): String = TerrarumSansBitmap.toColorCode(r, g, b, a)
|
||||||
val noColorCode = toColorCode(0x0000)
|
val noColorCode = toColorCode(0x0000)
|
||||||
|
|
||||||
val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString()
|
val charsetOverrideDefault = Character.toChars(CHARSET_OVERRIDE_DEFAULT).toSurrogatedString()
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package net.torvald.terrarumtypewriterbitmap.gdx
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by minjaesong on 2021-11-04.
|
||||||
|
*/
|
||||||
|
class TerrarumTypewriterBitmap(
|
||||||
|
fontDir: String,
|
||||||
|
val flipY: Boolean = false,
|
||||||
|
var errorOnUnknownChar: Boolean = false,
|
||||||
|
val textCacheSize: Int = 256,
|
||||||
|
val debug: Boolean = false
|
||||||
|
) : BitmapFont() {
|
||||||
|
|
||||||
|
override fun getLineHeight() = 20f
|
||||||
|
|
||||||
|
override fun getXHeight() = 8f
|
||||||
|
override fun getCapHeight() = 12f
|
||||||
|
override fun getAscent() = 3f
|
||||||
|
override fun getDescent() = 3f
|
||||||
|
override fun isFlipped() = flipY
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user