Skip to content

Commit

Permalink
Dependencies update, fix dist task
Browse files Browse the repository at this point in the history
  • Loading branch information
maltaisn committed Feb 27, 2023
1 parent 45cfcc0 commit 0e3d749
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
### v0.1.4
- Generate whitespace characters (#6).

### v0.1.3
- Fixed out of memory error when generating large charset (#3)
- Added `--fast-pack` option to enable the fast mode for the texture packer.
Expand Down
13 changes: 6 additions & 7 deletions gen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ java {

val mainClassName = "com.maltaisn.msdfgdx.gen.MainKt"
tasks.register<JavaExec>("run") {
main = mainClassName
mainClass.set(mainClassName)
classpath = sourceSets.main.get().runtimeClasspath
standardInput = System.`in`
isIgnoreExitValue = true
Expand All @@ -55,7 +55,9 @@ val dist = tasks.register<Jar>("dist") {

from(files(sourceSets.main.get().output.classesDirs))
from(files(sourceSets.main.get().resources.srcDirs))
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) })
from(configurations.runtimeClasspath.get().map { if (it.isDirectory) it else zipTree(it) }) {
exclude("**/module-info.class")
}
archiveBaseName.set("msdfgen")

manifest {
Expand All @@ -65,13 +67,10 @@ val dist = tasks.register<Jar>("dist") {
}

tasks.register<ProGuardTask>("shrinkJar") {
// Make sure to run this task using IntelliJ, not on the command line, so that java.home
// refers to Oracle JDK 8 which has a rt.jar file (unlike later versions).
val distFile = dist.get().archiveFile.get().asFile
configuration("proguard-rules.pro")
// Use the jar task output as an input jar. This will automatically add the necessary task dependency.
injars(distFile)
// outjars("build/proguard-obfuscated.jar")

val javaHome = System.getProperty("java.home")
// Automatically handle the Java version of this build.
Expand All @@ -80,10 +79,10 @@ tasks.register<ProGuardTask>("shrinkJar") {
libraryjars("$javaHome/lib/rt.jar")
} else {
// As of Java 9, the runtime classes are packaged in modular jmod files.
println("AAAAAA: ${javaHome}")
libraryjars(
// filters must be specified first, as a map
mapOf("jarfilter" to "!**.jar",
"filter" to "!module-info.class"),
"filter" to "!module-info.class"),
"$javaHome/jmods/java.base.jmod"
)
}
Expand Down
9 changes: 2 additions & 7 deletions gen/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,8 @@
-dontwarn com.badlogic.gdx.**

# Kotlin coroutines
-dontwarn kotlinx.coroutines.flow.**
-dontwarn kotlinx.coroutines.debug.**
-keepnames class kotlinx.coroutines.internal.MainDispatcherFactory {}
-keepnames class kotlinx.coroutines.CoroutineExceptionHandler {}
-keepclassmembernames class kotlinx.** {
volatile <fields>;
}
-dontwarn org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement
-dontwarn android.annotation.SuppressLint

# Enums
-keepclassmembers class * extends java.lang.Enum {
Expand Down
20 changes: 10 additions & 10 deletions gen/src/main/kotlin/com/maltaisn/msdfgdx/gen/BMFont.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import kotlin.math.roundToInt
* Note that font and glyph metrics seems kinda off sometimes. I used:
* - https://github.com/libgdx/libgdx/tree/aff6dd4a2622d64a62196111eb018d4699a19c8a/extensions/gdx-tools/src/com/badlogic/gdx/tools/hiero
* - https://github.com/soimy/msdf-bmfont-xml/blob/ff3669c2bfffd06f29bacedcdf3f073379b45e7e/index.js
* To guess which font metrics would work but it might not work for all fonts.
* To guess which font metrics would work, but it might not work for all fonts.
*/
class BMFont(
private val fontFile: File,
Expand Down Expand Up @@ -94,15 +94,15 @@ class BMFont(
progressListener(GenerationStep.GLYPH,
glyphsGenerated.incrementAndGet().toFloat() / params.charList.length)

if (glyph == null) null else char to glyph
char to glyph
}
}.awaitAll().filterNotNull()
}.awaitAll()
}

progressListener(GenerationStep.GLYPH, 1f)
}

private fun generateGlyph(char: Char, kernings: IntIntMap): FontGlyph? {
private fun generateGlyph(char: Char, kernings: IntIntMap): FontGlyph {
// Create glyph vector and get its bounding box.
val glyphVector = font.createGlyphVector(fontRenderContext, char.toString())
val bounds = glyphVector.visualBounds
Expand All @@ -112,7 +112,7 @@ class BMFont(

// Set kerning distances
for (other in params.charList) {
val pair = (char.toInt() shl 16) or other.toInt()
val pair = (char.code shl 16) or other.code
if (kernings[pair, 0] != 0) {
glyph.kernings[other] = kernings[pair, 0]
}
Expand Down Expand Up @@ -157,7 +157,7 @@ class BMFont(
}

/**
* Pack the generate glyphs to a texture atlas.
* Pack the generated glyphs to a texture atlas.
*/
private fun pack(progressListener: ProgressListener) {
val packer = TexturePacker(File(params.outputDir), TexturePacker.Settings().apply {
Expand Down Expand Up @@ -185,7 +185,7 @@ class BMFont(

// Add glyph images to packer
for ((char, glyph) in glyphs) {
packer.addImage(glyph.image, char.toInt().toString())
packer.addImage(glyph.image, char.code.toString())
}

// Remove any existing atlas related files.
Expand Down Expand Up @@ -249,14 +249,14 @@ class BMFont(
bmfont.appendLine("page id=$i file=\"${getTextureAtlasFile(i).name}\"")
}

val kerningsCount = glyphs.values.map { it.kernings.size }.sum()
val kerningsCount = glyphs.values.sumOf { it.kernings.size }
val elementsCount = glyphs.size + kerningsCount
var elementsDone = 0f

// Char tags
bmfont.appendLine("chars count=${glyphs.size}")
for ((char, glyph) in glyphs) {
bmfont.appendLine("char id=${char.toInt()} x=${glyph.x} y=${glyph.y} " +
bmfont.appendLine("char id=${char.code} x=${glyph.x} y=${glyph.y} " +
"width=${glyph.width} height=${glyph.height} " +
"xoffset=${glyph.xOffset} yoffset=${glyph.yOffset} " +
"xadvance=${glyph.xAdvance} page=${glyph.page} chnl=${glyph.channels}")
Expand All @@ -268,7 +268,7 @@ class BMFont(
bmfont.appendLine("kernings count=$kerningsCount")
for ((char, glyph) in glyphs) {
for ((other, kerning) in glyph.kernings) {
bmfont.appendLine("kerning first=${char.toInt()} second=${other.toInt()} amount=$kerning")
bmfont.appendLine("kerning first=${char.code} second=${other.code} amount=$kerning")
elementsDone++
progressListener(GenerationStep.FONT_FILE, elementsDone / elementsCount)
}
Expand Down
2 changes: 1 addition & 1 deletion gen/src/main/kotlin/com/maltaisn/msdfgdx/gen/Parameters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Parameters {
var fieldType: String = FIELD_TYPE_MSDF

@Parameter(names = ["-a", "--alpha-field-type"], description = "Alpha field type: none | sdf | psdf", order = 3)
var alphaFieldType: String = FIELD_TYPE_SDF
var alphaFieldType: String = ""

@Parameter(names = ["-s", "--font-size"], description = "Font size for generated textures", order = 4)
var fontSize: Int = 32
Expand Down
2 changes: 1 addition & 1 deletion gen/src/main/res/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.4-SNAPSHOT
0.1.4
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
genVersion=0.1.4-SNAPSHOT
proguardVersion=7.3.0
githubReleasePluginVersion=2.2.12
kotlinVersion=1.4.30
coroutinesVersion=1.4.3
genVersion=0.1.4
proguardVersion=7.3.1
githubReleasePluginVersion=2.4.1
kotlinVersion=1.8.10
coroutinesVersion=1.6.4
gdxVersion=1.11.0
jcommanderVersion=1.82
pngtasticVersion=1.5

0 comments on commit 0e3d749

Please sign in to comment.