Skip to content

Commit 9aebfc6

Browse files
committed
Allow "flip" to work in FWSkin, JsonFontData.
1 parent f17eec0 commit 9aebfc6

File tree

4 files changed

+26
-20
lines changed

4 files changed

+26
-20
lines changed

src/main/java/com/github/tommyettinger/textra/BitmapFontSupport.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ public static BitmapFont loadStructuredJson(FileHandle jsonFont, TextureRegion r
4646
* a TextureRegion for the image the JSON needs; this region is often part of an atlas.
4747
* @param jsonFont a FileHandle with the path to a Structured JSON Font (typically a .json file)
4848
* @param region a TextureRegion, often part of a shared atlas, holding the image the JSON needs
49-
* @param integerPositions if true, positions will be rounded to integer positions; default to false
49+
* @param flip true if this BitmapFont has been flipped for use with a y-down coordinate system
5050
* @return a new BitmapFont loaded from {@code jsonFont}
5151
*/
52-
public static BitmapFont loadStructuredJson(FileHandle jsonFont, TextureRegion region, boolean integerPositions) {
53-
JsonFontData data = new JsonFontData(jsonFont);
54-
return new BitmapFont(data, region, integerPositions);
52+
public static BitmapFont loadStructuredJson(FileHandle jsonFont, TextureRegion region, boolean flip) {
53+
JsonFontData data = new JsonFontData(jsonFont, null, flip);
54+
return new BitmapFont(data, region, false);
5555
}
5656

5757
/**
@@ -73,12 +73,12 @@ public static BitmapFont loadStructuredJson(FileHandle jsonFont, String imagePat
7373
* a relative path (from {@code jsonFont}) to the necessary image file, with the path as a String.
7474
* @param jsonFont a FileHandle with the path to a Structured JSON Font (typically a .json file)
7575
* @param imagePath a String holding the relative path from {@code jsonFont} to the image file the JSON needs
76-
* @param integerPositions if true, positions will be rounded to integer positions; default to false
76+
* @param flip true if this BitmapFont has been flipped for use with a y-down coordinate system
7777
* @return a new BitmapFont loaded from {@code jsonFont}
7878
*/
79-
public static BitmapFont loadStructuredJson(FileHandle jsonFont, String imagePath, boolean integerPositions) {
80-
JsonFontData data = new JsonFontData(jsonFont, imagePath);
81-
return new BitmapFont(data, (TextureRegion) null, integerPositions);
79+
public static BitmapFont loadStructuredJson(FileHandle jsonFont, String imagePath, boolean flip) {
80+
JsonFontData data = new JsonFontData(jsonFont, imagePath, flip);
81+
return new BitmapFont(data, (TextureRegion) null, false);
8282
}
8383

8484
/**
@@ -92,14 +92,18 @@ public JsonFontData() {
9292
}
9393

9494
public JsonFontData(FileHandle jsonFont) {
95-
super();
96-
load(jsonFont, false);
95+
this(jsonFont, null);
9796
}
9897

9998
public JsonFontData(FileHandle jsonFont, String imagePath) {
99+
this(jsonFont, imagePath, false);
100+
}
101+
102+
public JsonFontData(FileHandle jsonFont, String imagePath, boolean flip) {
100103
super();
101104
path = imagePath;
102-
load(jsonFont, false);
105+
this.flipped = flip;
106+
load(jsonFont, flip);
103107
}
104108

105109
@Override
@@ -174,12 +178,12 @@ else if (ch <= Character.MAX_VALUE)
174178
}
175179
if (planeBounds != null) {
176180
glyph.xoffset = round(planeBounds.getFloat("left", 0f) * size);
177-
glyph.yoffset = round(size + planeBounds.getFloat("bottom", 0f) * size);
181+
glyph.yoffset = flip
182+
? round(-size - planeBounds.getFloat("top", 0f) * size)
183+
: round(size + planeBounds.getFloat("bottom", 0f) * size);
178184
} else {
179185
glyph.xoffset = glyph.yoffset = 0;
180186
}
181-
182-
// if (glyph.width > 0 && glyph.height > 0) descent = Math.min(baseLine + glyph.yoffset, descent);
183187
}
184188

185189
JsonValue kern = fnt.get("kerning");

src/main/java/com/github/tommyettinger/textra/FWSkin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,15 @@ public BitmapFont read (Json json, JsonValue jsonData, Class type) {
9898
Array<TextureRegion> regions = skin.getRegions(regionName);
9999
if (regions != null && regions.notEmpty()) {
100100
if(fw)
101-
font = BitmapFontSupport.loadStructuredJson(fontFile, regions.first());
101+
font = BitmapFontSupport.loadStructuredJson(fontFile, regions.first(), flip);
102102
else
103103
font = new BitmapFont(new BitmapFont.BitmapFontData(fontFile, flip), regions, true);
104104
} else {
105105
TextureRegion region = skin.optional(regionName, TextureRegion.class);
106106
if (region != null)
107107
{
108108
if(fw)
109-
font = BitmapFontSupport.loadStructuredJson(fontFile, region);
109+
font = BitmapFontSupport.loadStructuredJson(fontFile, region, flip);
110110
else
111111
font = new BitmapFont(fontFile, region, flip);
112112
}
@@ -115,12 +115,12 @@ public BitmapFont read (Json json, JsonValue jsonData, Class type) {
115115
if (imageFile.exists()) {
116116
if(fw)
117117
font = BitmapFontSupport.loadStructuredJson(fontFile,
118-
new TextureRegion(new Texture(imageFile)));
118+
new TextureRegion(new Texture(imageFile)), flip);
119119
else
120120
font = new BitmapFont(fontFile, imageFile, flip);
121121
} else {
122122
if(fw)
123-
font = BitmapFontSupport.loadStructuredJson(fontFile, "");
123+
font = BitmapFontSupport.loadStructuredJson(fontFile, "", flip);
124124
else
125125
font = new BitmapFont(fontFile, flip);
126126
}

src/test/resources/uiskin3.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
BitmapFont: { default-font: { file: experimental/GentiumUnItalic-standard.json,
3-
scaledSize: 14
3+
scaledSize: 14,
4+
flip: true
45
} },
56
Color: {
67
green: { a: 1, b: 0, g: 1, r: 0 },

src/test/resources/uiskin4.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
BitmapFont: { default-font: { file: experimental/GentiumUnItalic-bmfont.fnt,
3-
scaledSize: 14
3+
scaledSize: 14,
4+
flip: true
45
} },
56
Color: {
67
green: { a: 1, b: 0, g: 1, r: 0 },

0 commit comments

Comments
 (0)