Skip to content

Commit b66fe34

Browse files
Various improvements and publishing setup
1 parent f43ff1b commit b66fe34

File tree

15 files changed

+236
-55
lines changed

15 files changed

+236
-55
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will build a package using Gradle and then publish it to Bintray when a release is created
2+
# For more information see: https://github.com/actions/setup-java#publishing-using-gradle
3+
4+
name: Publish Releases
5+
6+
on:
7+
release:
8+
types: [published]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up JDK 1.8
18+
uses: actions/setup-java@v1
19+
with:
20+
java-version: 1.8
21+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
22+
settings-path: ${{ github.workspace }} # location for the settings.xml file
23+
24+
- name: Build with Gradle
25+
run: ./gradlew :bitfontcore:build
26+
27+
- name: Publish to Bintray
28+
run: ./gradlew :bitfontcore:bintrayUpload
29+
env:
30+
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
31+
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# This workflow will build a package using Gradle and then publish it oss.jfrog.org when a release is created
2+
# For more information see: https://github.com/actions/setup-java#publishing-using-gradle
3+
4+
name: Publish Snapshots
5+
6+
on: push
7+
8+
jobs:
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Set up JDK 1.8
16+
uses: actions/setup-java@v1
17+
with:
18+
java-version: 1.8
19+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
20+
settings-path: ${{ github.workspace }} # location for the settings.xml file
21+
22+
- name: Build with Gradle
23+
run: ./gradlew :bitfontcore:build
24+
25+
- name: Publish to oss.jfrog.org
26+
run: ./gradlew :bitfontcore:artifactoryPublish
27+
env:
28+
SNAPSHOT_BRANCH: ${{ github.ref }}
29+
BINTRAY_USER: ${{ secrets.BINTRAY_USER }}
30+
BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }}
31+
ARTIFACTORY_BUILD_NUMBER: ${{ github.run_number }}

build.gradle

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release"
7+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
8+
}
9+
}
10+
11+
plugins {
12+
id "org.jetbrains.kotlin.jvm" version "1.4.0"
13+
}
14+
15+
def maven_version = library_version
16+
def snapshotBranch = System.getenv('SNAPSHOT_BRANCH')
17+
if(snapshotBranch != null) {
18+
if(snapshotBranch.startsWith('refs/heads/'))
19+
snapshotBranch = snapshotBranch.substring('refs/heads/'.length())
20+
maven_version = snapshotBranch.replaceAll('[^.\\w-]', '-') + '-SNAPSHOT'
21+
logger.lifecycle("Using SNAPSHOT version `{}`", version)
22+
}
23+
24+
// pass `-PbitfontVersion=foo` to set the version directly. Useful for publishing to the local maven repository
25+
if(hasProperty('bitfontVersion')) {
26+
maven_version = bitfontVersion
27+
}
28+
29+
allprojects {
30+
group = "dev.thecodewarrior.bitfont"
31+
version = maven_version
32+
33+
repositories {
34+
jcenter()
35+
}
36+
}

build.gradle.kts

Lines changed: 0 additions & 18 deletions
This file was deleted.

core/build.gradle

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
plugins {
22
id 'java'
3-
id 'org.jetbrains.kotlin.jvm' version '1.4.0'
3+
id 'org.jetbrains.kotlin.jvm'
44
id 'maven'
55
}
66

7+
apply plugin: 'maven-publish'
8+
apply plugin: 'com.jfrog.bintray'
9+
apply plugin: "com.jfrog.artifactory"
10+
711
repositories {
812
mavenCentral()
913
jcenter()
@@ -41,6 +45,70 @@ task sourcesJar(type: Jar) {
4145

4246
jar.dependsOn sourcesJar
4347

44-
artifacts {
45-
archives sourcesJar
48+
publishing {
49+
publications {
50+
create("maven", MavenPublication) {
51+
groupId = 'dev.thecodewarrior'
52+
artifactId = 'bitfont'
53+
version = project.version
54+
55+
artifact sourcesJar
56+
from components.java
57+
58+
pom {
59+
name = "Bitfont"
60+
description = "A custom bitmap font format and platform-agnostic text layout engine"
61+
url = 'http://github.com/thecodewarrior/Bitfont'
62+
licenses {
63+
license {
64+
name = 'BSD 2-Clause'
65+
}
66+
}
67+
scm {
68+
connection = 'scm:git:https://github.com/thecodewarrior/Bitfont.git'
69+
developerConnection = 'scm:git:ssh://github.com/thecodewarrior/Bitfont.git'
70+
url = 'https://github.com/thecodewarrior/Bitfont'
71+
}
72+
}
73+
}
74+
}
75+
}
76+
77+
apply plugin: 'com.jfrog.bintray'
78+
79+
bintray {
80+
user = System.getenv("BINTRAY_USER")
81+
key = System.getenv("BINTRAY_API_KEY")
82+
publications = ["maven"]
83+
pkg {
84+
repo = "thecodewarrior"
85+
name = "bitfont"
86+
desc = project.description
87+
labels = ["bitmap fonts", "typesetting", "text-layout"]
88+
licenses = ["BSD 2-Clause"]
89+
90+
websiteUrl = "https://github.com/thecodewarrior/Bitfont"
91+
githubRepo = "thecodewarrior/Bitfont"
92+
vcsUrl = "https://github.com/thecodewarrior/Bitfont.git"
93+
issueTrackerUrl = "https://github.com/thecodewarrior/Bitfont/issues"
94+
95+
}
96+
}
97+
98+
apply plugin: 'com.jfrog.artifactory'
99+
100+
artifactory {
101+
setContextUrl 'https://oss.jfrog.org'
102+
publish {
103+
repository {
104+
repoKey = project.version.endsWith("-SNAPSHOT") ? "oss-snapshot-local" : "oss-release-local"
105+
username = System.getenv("BINTRAY_USER")
106+
password = System.getenv("BINTRAY_API_KEY")
107+
maven = true
108+
}
109+
defaults {
110+
publications "maven"
111+
}
112+
}
113+
clientConfig.info.setBuildNumber(System.getenv('ARTIFACTORY_BUILD_NUMBER')) // no env = null -> default value
46114
}

core/src/main/kotlin/dev/thecodewarrior/bitfont/data/Bitfont.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package dev.thecodewarrior.bitfont.data
22

3+
import dev.thecodewarrior.bitfont.data.file.BitfontFile
4+
import dev.thecodewarrior.bitfont.data.file.BitfontFileFormat
35
import dev.thecodewarrior.bitfont.utils.clamp
46
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap
7+
import java.io.InputStream
58

69
class Bitfont(name: String, ascent: Int, descent: Int, capHeight: Int, xHeight: Int, spacing: Int) {
710
var name: String = name
@@ -57,4 +60,12 @@ class Bitfont(name: String, ascent: Int, descent: Int, capHeight: Int, xHeight:
5760
glyph.image = grid
5861
return glyph
5962
}
63+
64+
public companion object {
65+
@JvmStatic
66+
public fun unpack(stream: InputStream): Bitfont {
67+
val file = BitfontFile.unpack(stream)
68+
return BitfontFileFormat.unpack(file)
69+
}
70+
}
6071
}

core/src/main/kotlin/dev/thecodewarrior/bitfont/typesetting/GraphemeCluster.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,27 @@ import com.ibm.icu.lang.UCharacter
44

55
public class GraphemeCluster(public val main: TypesetGlyph) {
66
/**
7-
* Any combining characters attached to [main]. These are positioned relative to [main].
7+
* Offset the X position of [main] and all its [attachments]
8+
*/
9+
public fun offsetX(offset: Int) {
10+
main.posX += offset
11+
attachments.forEach {
12+
it.posX += offset
13+
}
14+
}
15+
16+
/**
17+
* Offset the Y position of [main] and move all its [attachments]
18+
*/
19+
public fun offsetY(offset: Int) {
20+
main.posY += offset
21+
attachments.forEach {
22+
it.posY += offset
23+
}
24+
}
25+
26+
/**
27+
* Any combining characters attached to [main]. These are positioned absolutely, not relatively.
828
*/
929
public val attachments: MutableList<TypesetGlyph> = mutableListOf()
1030

core/src/main/kotlin/dev/thecodewarrior/bitfont/typesetting/TextContainer.kt

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package dev.thecodewarrior.bitfont.typesetting
22

3+
import dev.thecodewarrior.bitfont.utils.BufferedIterator
4+
35
public open class TextContainer @JvmOverloads constructor(
46
/**
57
* The width of the container
@@ -15,8 +17,6 @@ public open class TextContainer @JvmOverloads constructor(
1517
public var maxLines: Int = Int.MAX_VALUE
1618
) {
1719

18-
// var lineBreakMode: LineBreakMode = LineBreakMode.WRAP_WORDS
19-
2020
public val lines: MutableList<TypesetLine> = mutableListOf()
2121

2222
/**
@@ -35,8 +35,26 @@ public open class TextContainer @JvmOverloads constructor(
3535
public data class LineBounds(val spacing: Int, var posX: Int, var posY: Int, var width: Int, val height: Int)
3636

3737
public class TypesetLine(
38-
public var posX: Int, public var posY: Int,
39-
public var width: Int, public var height: Int,
40-
public val glyphs: List<TypesetGlyph>
41-
)
38+
public val posX: Int, public val posY: Int,
39+
public val width: Int, public val height: Int,
40+
public val clusters: List<GraphemeCluster>
41+
): Iterable<TypesetGlyph> {
42+
override fun iterator(): Iterator<TypesetGlyph> {
43+
return Iter()
44+
}
45+
46+
private inner class Iter: BufferedIterator<TypesetGlyph>() {
47+
val clusterIterator = clusters.iterator()
48+
49+
override fun refillBuffer() {
50+
if(clusterIterator.hasNext()) {
51+
val cluster = clusterIterator.next()
52+
push(cluster.main)
53+
cluster.attachments.forEach {
54+
push(it)
55+
}
56+
}
57+
}
58+
}
59+
}
4260
}

core/src/main/kotlin/dev/thecodewarrior/bitfont/typesetting/TextLayoutManager.kt

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public open class TextLayoutManager(font: Bitfont, vararg containers: TextContai
178178
// === append truncation string ===
179179
val truncationStartX = line.clusters.lastOrNull()?.main?.afterX ?: 0
180180
truncationGlyphs.forEach {
181-
it.main.posX += truncationStartX
181+
it.offsetX(truncationStartX)
182182
}
183183
line.clusters.addAll(truncationGlyphs)
184184
}
@@ -338,9 +338,9 @@ public open class TextLayoutManager(font: Bitfont, vararg containers: TextContai
338338

339339
// === applying shifts ===
340340
// shift all the glyphs into the correct locations
341-
line.clusters.forEach {
342-
it.main.posX -= startX
343-
it.main.posY += line.baseline
341+
line.clusters.forEach { cluster ->
342+
cluster.offsetX(-startX)
343+
cluster.offsetY(line.baseline)
344344
}
345345
}
346346

@@ -387,16 +387,7 @@ public open class TextLayoutManager(font: Bitfont, vararg containers: TextContai
387387
}
388388

389389
public fun toTypesetLine(): TextContainer.TypesetLine {
390-
val glyphs = mutableListOf<TypesetGlyph>()
391-
clusters.forEach { cluster ->
392-
glyphs.add(cluster.main)
393-
cluster.attachments.forEach {
394-
it.posX += cluster.main.posX
395-
it.posY += cluster.main.posY
396-
glyphs.add(it)
397-
}
398-
}
399-
return TextContainer.TypesetLine(posX, posY, width, height, glyphs)
390+
return TextContainer.TypesetLine(posX, posY, width, height, clusters)
400391
}
401392
}
402393

core/src/main/kotlin/dev/thecodewarrior/bitfont/typesetting/TypesetGlyph.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ public open class TypesetGlyph(
1111
public val afterX: Int
1212
get() = posX + textObject.advance
1313

14-
public fun setPosition(posX: Int, posY: Int): TypesetGlyph {
15-
this.posX = posX
16-
this.posY = posY
17-
return this
18-
}
19-
2014
private var attributeOverrides: MutableMap<TextAttribute<*>, Any?>? = null
2115

2216
/**

0 commit comments

Comments
 (0)