diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 7780478..d9cf356 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -7,34 +7,11 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -116,11 +108,14 @@ @@ -144,11 +139,6 @@ - - - - - @@ -178,6 +168,7 @@ + @@ -201,7 +192,7 @@ - + @@ -224,25 +215,21 @@ - + - - - - - - - - - - + @@ -416,7 +398,7 @@ - + @@ -424,7 +406,7 @@ - + @@ -633,30 +615,61 @@ - + - - + + - - - - + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + diff --git a/FontTestGDX/lib/TerrarumSansBitmap.jar b/FontTestGDX/lib/TerrarumSansBitmap.jar index 521e9d4..c36fbaf 100644 Binary files a/FontTestGDX/lib/TerrarumSansBitmap.jar and b/FontTestGDX/lib/TerrarumSansBitmap.jar differ diff --git a/FontTestGDX/src/FontTestGDX.kt b/FontTestGDX/src/FontTestGDX.kt index e65c427..bb3cd42 100644 --- a/FontTestGDX/src/FontTestGDX.kt +++ b/FontTestGDX/src/FontTestGDX.kt @@ -4,6 +4,7 @@ import com.badlogic.gdx.Screen import com.badlogic.gdx.backends.lwjgl.LwjglApplication import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration import com.badlogic.gdx.graphics.GL20 +import com.badlogic.gdx.graphics.g2d.SpriteBatch import net.torvald.terrarumsansbitmap.gdx.GameFontBase /** @@ -13,8 +14,19 @@ class FontTestGDX : Game() { lateinit var font: GameFontBase + lateinit var inputText: List + + lateinit var batch: SpriteBatch + override fun create() { - font = GameFontBase("./assets") + font = GameFontBase("./assets", flipY = false) // must test for two cases + + val inTextFile = Gdx.files.internal("./FontTestGDX/demotext.txt") + val reader = inTextFile.reader() + inputText = reader.readLines() + reader.close() + + batch = SpriteBatch() } override fun getScreen(): Screen? { @@ -26,12 +38,20 @@ class FontTestGDX : Game() { override fun render() { - Gdx.gl.glClearColor(.094f, .094f, .094f, 1f) + Gdx.gl.glClearColor(1f - 0xBA/255f, 1f - 0xDA/255f, 1f - 0x55/255f, 1f) Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT) Gdx.gl.glEnable(GL20.GL_TEXTURE_2D) Gdx.gl.glEnable(GL20.GL_BLEND) Gdx.gl.glBlendFunc(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA) + + batch.begin() + + inputText.reversed().forEachIndexed { index, s -> + font.draw(batch, s, 10f, 10f + index * font.lineHeight) + } + + batch.end() } override fun pause() { @@ -52,8 +72,8 @@ fun main(args: Array) { val appConfig = LwjglApplicationConfiguration() appConfig.vSyncEnabled = false appConfig.resizable = false//true; - appConfig.width = 740 // photographic ratio (1.5:1) - appConfig.height = 1110 // photographic ratio (1.5:1) + appConfig.width = 1024 // photographic ratio (1.5:1) + appConfig.height = 1024 // photographic ratio (1.5:1) appConfig.title = "Terrarum Sans Bitmap Test (GDX)" LwjglApplication(FontTestGDX(), appConfig) diff --git a/LICENSE.md b/LICENSE.md index f7bb48b..ed86c6e 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ Terrarum Sans Bitmap -Copyright (c) 2017 Minjae Song (Torvald) and the contributors +Copyright (c) 2017-2018 Minjae Song (Torvald) and the contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 2955468..1fb81ab 100644 --- a/README.md +++ b/README.md @@ -239,4 +239,4 @@ This is a Kotlin-like pseudocode for assembling the glyph: Thanks to kind people of [/r/Typography](https://www.reddit.com/r/typography/) for amazing feedbacks. -CJK Ideographs are powered by [WenQuanYi Font](http://wenq.org/wqy2/index.cgi?BitmapSong). The font is distributed under the GNU GPL version 2. Although the glyphs themselves are not copyrightable (the program codes—e.g. TTF—do), we would like to give a credit for the font and the people behind it. +CJK Ideographs are powered by [WenQuanYi Font](http://wenq.org/wqy2/index.cgi?BitmapSong). The font is distributed under the GNU GPL version 2. Although, in some countries including where I'm based on, the shapes of typefaces are not copyrightable (the program codes—e.g. TTF—do), we would like to give a credit for the font and the people behind it. diff --git a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt index f306653..00b57fd 100644 --- a/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt +++ b/src/net/torvald/terrarumsansbitmap/gdx/GameFontBase.kt @@ -400,6 +400,10 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo private lateinit var originalColour: Color override fun draw(batch: Batch, str: CharSequence, x: Float, y: Float): GlyphLayout? { + + fun Int.flipY() = this * if (flipY) 1 else -1 + + // always draw at integer position; this is bitmap font after all val x = Math.round(x).toFloat() val y = Math.round(y).toFloat() @@ -508,7 +512,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo sheets[sheetID].get(sheetX, sheetY), x + textBWidth[index] + 1 + offset, y + (if (sheetID == SHEET_UNIHAN) // evil exceptions - offsetUnihan + offsetUnihan.flipY() else if (sheetID == SHEET_CUSTOM_SYM) offsetCustomSym else @@ -518,7 +522,7 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo sheets[sheetID].get(sheetX, sheetY), x + textBWidth[index] + offset, y + (if (sheetID == SHEET_UNIHAN) // evil exceptions - offsetUnihan + 1 + offsetUnihan.flipY() + 1 else if (sheetID == SHEET_CUSTOM_SYM) offsetCustomSym + 1 else @@ -528,11 +532,11 @@ class GameFontBase(fontDir: String, val noShadow: Boolean = false, val flipY: Bo sheets[sheetID].get(sheetX, sheetY), x + textBWidth[index] + 1 + offset, y + (if (sheetID == SHEET_UNIHAN) // evil exceptions - offsetUnihan + 1 + offsetUnihan.flipY() + 1 else if (sheetID == SHEET_CUSTOM_SYM) offsetCustomSym + 1 else - 1) * if (flipY) 1 else -1 + 1).flipY() ) }