Skip to content

Commit 8c4abda

Browse files
authored
Merge pull request #2 from jmecn/master
Add fixedResolution feature. Add pom.xml and build.gradle. Add some test cases.
2 parents 4b5fd8f + f50a1d2 commit 8c4abda

File tree

89 files changed

+1178
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+1178
-59
lines changed

.gitignore

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
3+
hs_err_pid*
4+
5+
# Vscode
6+
/.vscode/
7+
8+
# Eclipse project
9+
/.settings/
10+
.project
11+
.classpath
12+
13+
# IDEA project
14+
/.idea/
15+
.iml
16+
.iws
17+
.ipr
18+
19+
# Netbeans project
20+
/nbproject/private/
21+
/netbeans/
22+
/.nb-gradle/
23+
24+
# build tool output
25+
/.gradle/
26+
/bin/
27+
/build/
28+
/dist/
29+
/out/
30+
/target/
31+
.gradletasknamecache
32+
33+
34+
# MacOS
35+
.DS_Store
36+
37+
# Runtime
38+
*.dll
39+
*.so
40+
*.jnilib
41+
*.dylib
42+
*.iml
43+
*.class
44+
*.jtxt

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ src="https://dl.dropboxusercontent.com/s/fydn0y11xxckxp2/1693b179e6b26b076e9748f
3131

3232
jME-TTF depends upon Google's Sfntly library available at https://github.com/rillig/sfntly
3333

34-
You can find more about jME-TTF including usage documentation at http://1337atr.weebly.com/jmettf.html
34+
You can find more about jME-TTF including usage documentation at http://1337atr.weebly.com/jttf.html

build.gradle

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
dependencies {
6+
if( project.hasProperty('releaseUser') ) {
7+
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
8+
}
9+
}
10+
}
11+
12+
plugins {
13+
id 'java-library'
14+
id 'maven'
15+
}
16+
17+
version='2.1.3'
18+
group='com.atr'
19+
20+
sourceCompatibility = 1.7
21+
compileJava {
22+
options.encoding = 'UTF-8'
23+
options.compilerArgs << "-Xlint:unchecked" << "-Xlint:deprecation"
24+
}
25+
26+
ext.jme3Version='[3.1,)'
27+
28+
repositories {
29+
mavenLocal()
30+
31+
if( JavaVersion.current() == JavaVersion.VERSION_1_7 ) {
32+
// Fallback for JDK 7 that can no longer connect to jcenter with https
33+
maven { url "http://jcenter.bintray.com" }
34+
} else {
35+
jcenter()
36+
}
37+
}
38+
39+
dependencies {
40+
api "org.jmonkeyengine:jme3-core:${jme3Version}"
41+
api 'com.jaredrummler:sfntly:1.+'
42+
43+
// provided when running on Desktop
44+
compileOnly "org.jmonkeyengine:jme3-desktop:${jme3Version}"
45+
46+
// provided when running on Android
47+
compileOnly "org.jmonkeyengine:jme3-android:${jme3Version}"
48+
compileOnly 'com.google.android:android:[4.1,)'
49+
50+
// test runtime
51+
testRuntimeOnly "org.jmonkeyengine:jme3-lwjgl:${jme3Version}"
52+
}

nbproject/project.properties

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ dist.jar=${dist.dir}/jME-TTF.jar
3030
dist.javadoc.dir=${dist.dir}/javadoc
3131
endorsed.classpath=
3232
excludes=
33+
file.reference.main-java=src/main/java
34+
file.reference.test-java=src/test/java
3335
file.reference.android.jar=/home/adam/Android/Sdk/platforms/android-21/android.jar
3436
file.reference.android.jar-1=/media/adam/Nomad1/Android/sdk-eclipse/platforms/android-21/android.jar
3537
file.reference.jme3-core.jar=/home/adam/Java/jMonkey3/jMonkeyLibraries/jME3.1_Fix/jMonkeyEngine-3.1-Beta1/build/libDist/lib/jme3-core.jar
@@ -81,5 +83,5 @@ run.test.classpath=\
8183
${javac.test.classpath}:\
8284
${build.test.classes.dir}
8385
source.encoding=UTF-8
84-
src.dir=src
85-
test.src.dir=test
86+
src.dir=${file.reference.main-java}
87+
test.src.dir=${file.reference.test-java}

pom.xml

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>com.atr</groupId>
8+
<artifactId>jme-ttf</artifactId>
9+
<version>2.1.3</version>
10+
<inceptionYear>2016</inceptionYear>
11+
12+
<licenses>
13+
<license>
14+
<name>Free Public License 1.0.0</name>
15+
<url>http://opensource.org/licenses/FPL-1.0.0</url>
16+
<distribution>repo</distribution>
17+
</license>
18+
<license>
19+
<name>BSD New</name>
20+
<url>http://opensource.org/licenses/BSD-3-Clause</url>
21+
<distribution>repo</distribution>
22+
</license>
23+
</licenses>
24+
25+
<properties>
26+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
27+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
28+
<java.version>1.7</java.version>
29+
<jme3.version>[3.1,)</jme3.version>
30+
<sfntly.version>1.0.1</sfntly.version>
31+
<android.version>[4.1,)</android.version>
32+
</properties>
33+
34+
<dependencies>
35+
<dependency>
36+
<groupId>org.jmonkeyengine</groupId>
37+
<artifactId>jme3-core</artifactId>
38+
<version>${jme3.version}</version>
39+
<scope>compile</scope>
40+
</dependency>
41+
42+
<dependency>
43+
<groupId>com.jaredrummler</groupId>
44+
<artifactId>sfntly</artifactId>
45+
<version>${sfntly.version}</version>
46+
<scope>compile</scope>
47+
</dependency>
48+
49+
<!-- provided when running on Desktop -->
50+
<dependency>
51+
<groupId>org.jmonkeyengine</groupId>
52+
<artifactId>jme3-desktop</artifactId>
53+
<version>${jme3.version}</version>
54+
<scope>provided</scope>
55+
</dependency>
56+
57+
<!-- provided when running on Android -->
58+
<dependency>
59+
<groupId>org.jmonkeyengine</groupId>
60+
<artifactId>jme3-android</artifactId>
61+
<version>${jme3.version}</version>
62+
<scope>provided</scope>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>com.google.android</groupId>
67+
<artifactId>android</artifactId>
68+
<version>${android.version}</version>
69+
<scope>provided</scope>
70+
</dependency>
71+
72+
<!-- test runtime -->
73+
<dependency>
74+
<groupId>junit</groupId>
75+
<artifactId>junit</artifactId>
76+
<version>4.12</version>
77+
<scope>test</scope>
78+
</dependency>
79+
80+
<dependency>
81+
<groupId>org.jmonkeyengine</groupId>
82+
<artifactId>jme3-lwjgl</artifactId>
83+
<version>${jme3.version}</version>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
87+
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>org.apache.maven.plugins</groupId>
92+
<artifactId>maven-compiler-plugin</artifactId>
93+
<configuration>
94+
<source>${java.version}</source>
95+
<target>${java.version}</target>
96+
<encoding>${project.build.sourceEncoding}</encoding>
97+
</configuration>
98+
</plugin>
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-source-plugin</artifactId>
102+
<executions>
103+
<execution>
104+
<phase>compile</phase>
105+
<goals>
106+
<goal>jar-no-fork</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
</plugins>
112+
</build>
113+
</project>

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rootProject.name = 'jme-ttf'

src/com/atr/jme/font/TrueTypeAWT.java renamed to src/main/java/com/atr/jme/font/TrueTypeAWT.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public class TrueTypeAWT extends TrueTypeBMP<GlyphAWT> {
5555
private final AffineTransform transform;
5656

5757
public TrueTypeAWT(AssetManager assetManager, Font font, Style style, int pointSize,
58-
int outline, int dpi, int maxAtlasResolution, String preload) {
59-
super(assetManager, style, pointSize, outline, dpi, maxAtlasResolution);
58+
int outline, int dpi, int maxAtlasResolution, String preload, boolean fixedResolution) {
59+
super(assetManager, style, pointSize, outline, dpi, maxAtlasResolution, fixedResolution);
6060

6161
if (font != null) {
6262
this.font = font;
@@ -206,9 +206,11 @@ protected void createAtlas() {
206206
BufferUtils.destroyDirectBuffer(buf);
207207
}
208208
}
209+
atlas.setImage(new AWTLoader().load(tmpImg, false));
210+
} else {
211+
atlas = new Texture2D(new AWTLoader().load(tmpImg, false));
209212
}
210-
211-
atlas = new Texture2D(new AWTLoader().load(tmpImg, false));
213+
212214
g.dispose();
213215

214216
atlasResized = false;
@@ -252,16 +254,19 @@ protected void createAtlasOutlined() {
252254
g.translate(-x, -y);
253255

254256
}
257+
255258
if (atlas != null) {
256259
atlas.getImage().dispose();
257260
if (!NativeObjectManager.UNSAFE) {
258261
for (ByteBuffer buf : atlas.getImage().getData()) {
259262
BufferUtils.destroyDirectBuffer(buf);
260263
}
261264
}
265+
atlas.setImage(new AWTLoader().load(tmpImg, false));
266+
} else {
267+
atlas = new Texture2D(new AWTLoader().load(tmpImg, false));
262268
}
263-
264-
atlas = new Texture2D(new AWTLoader().load(tmpImg, false));
269+
265270
g.dispose();
266271

267272
atlasResized = false;

src/com/atr/jme/font/TrueTypeBMP.java renamed to src/main/java/com/atr/jme/font/TrueTypeBMP.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,18 @@ public abstract class TrueTypeBMP<T extends GlyphBMP> extends TrueTypeFont<T, Tr
6767
protected int atlasWidth = 0;
6868
protected int atlasHeight = 0;
6969
protected int maxTexRes = 2048;
70-
7170
protected final List<AtlasListener> onAtlas = new LinkedList<AtlasListener>();
7271

72+
protected boolean fixedResolution = false;
73+
7374
public TrueTypeBMP(AssetManager assetManager, Style style, int pointSize, int outline, int dpi,
74-
int maxAtlasResolution) {
75+
int maxAtlasResolution, boolean fixedResolution) {
7576
super(assetManager, style, pointSize, dpi);
7677

7778
this.outline = outline;
7879
padding = 10 + (outline * 2);
7980
maxTexRes = maxAtlasResolution;
81+
this.fixedResolution = fixedResolution;
8082
}
8183

8284
/**
@@ -204,6 +206,7 @@ public TrueTypeContainer getFormattedText(StringContainer stringContainer,
204206
return ttc;
205207
}
206208

209+
@SuppressWarnings("unchecked")
207210
@Override
208211
public T[] getGlyphs(StringBuilder text) {
209212
T[] glyphs = (T[])new GlyphBMP[text.length()];
@@ -233,6 +236,7 @@ public T[] getGlyphs(StringBuilder text) {
233236
return glyphs;
234237
}
235238

239+
@SuppressWarnings("unchecked")
236240
@Override
237241
public T[][] getGlyphMatrix(String text) {
238242
String[] strings = text.split("\n");
@@ -275,8 +279,13 @@ public int getOutline() {
275279
* @see TrueTypeSfntly#createGlyphs(java.util.List)
276280
*/
277281
protected void resizeAtlas() {
278-
atlasWidth += (atlasWidth + resizeWidth > maxTexRes) ? 0 : resizeWidth;
279-
atlasHeight += (atlasHeight + charHeight > maxTexRes) ? 0 : charHeight;
282+
if (fixedResolution) {
283+
atlasWidth = this.maxTexRes;
284+
atlasHeight = this.maxTexRes;
285+
} else {
286+
atlasWidth += (atlasWidth + resizeWidth > maxTexRes) ? 0 : resizeWidth;
287+
atlasHeight += (atlasHeight + charHeight > maxTexRes) ? 0 : charHeight;
288+
}
280289

281290
int numNewLines = (int)FastMath.floor((float)atlasHeight / charHeight) - atlasLines.size();
282291
for (int i = 0; i < numNewLines; i++) {

src/com/atr/jme/font/TrueTypeFont.java renamed to src/main/java/com/atr/jme/font/TrueTypeFont.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
* @see TrueTypeBMP
4040
* @see TrueTypeMesh
4141
*/
42+
@SuppressWarnings("rawtypes")
4243
public abstract class TrueTypeFont<T extends Glyph, S extends TrueTypeNode> {
4344
public static final int SPACE_CODEPOINT = ' ';
4445

src/com/atr/jme/font/TrueTypeMesh.java renamed to src/main/java/com/atr/jme/font/TrueTypeMesh.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ public TrueTypeContainer getFormattedText(StringContainer stringContainer,
260260
return ttmc;
261261
}
262262

263+
@SuppressWarnings("unchecked")
263264
@Override
264265
public GlyphMesh[] getGlyphs(StringBuilder text) {
265266
GlyphMesh[] glyphs = new GlyphMesh[text.length()];

0 commit comments

Comments
 (0)