Skip to content

Commit

Permalink
Keep going on structured JSON.
Browse files Browse the repository at this point in the history
  • Loading branch information
tommyettinger committed Feb 21, 2024
1 parent 6b6527d commit 2f6c12e
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions src/main/java/com/github/tommyettinger/textra/Font.java
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,10 @@ public Font(String jsonName, TextureRegion textureRegion,
if (distanceField != DistanceFieldType.STANDARD) {
textureRegion.getTexture().setFilter(Texture.TextureFilter.Linear, Texture.TextureFilter.Linear);
}
this.xAdjust = xAdjust;
this.yAdjust = yAdjust;
this.widthAdjust = widthAdjust;
this.heightAdjust = heightAdjust;

FileHandle fntHandle;
JsonValue fnt;
Expand All @@ -2062,8 +2066,29 @@ public Font(String jsonName, TextureRegion textureRegion,
throw new RuntimeException("Missing font file: " + jsonName);
}
int pages = 1;
TextureRegion parent = textureRegion;
this.setDistanceField(distanceField);

JsonValue atlas = fnt.get("atlas");
String dfType = atlas.getString("type", "");
if("msdf".equals(dfType) || "mtsdf".equals(dfType))
this.setDistanceField(DistanceFieldType.MSDF);
else if("sdf".equals(dfType) || "psdf".equals(dfType))
this.setDistanceField(DistanceFieldType.SDF);
else
this.setDistanceField(DistanceFieldType.STANDARD);

float distanceRange = atlas.getFloat("distanceRange", 2f);

float size = atlas.getFloat("size", 16f);

JsonValue metrics = fnt.get("metrics");
//"emSize":1,"lineHeight":1.25,"ascender":0.97699999999999998,"descender":-0.20500000000000002,"underlineY":-0.074999999999999997,"underlineThickness":0.050000000000000003

size *= metrics.getFloat("emSize", 1f);
originalCellHeight = cellHeight = size * atlas.getFloat("lineHeight", 1f) + heightAdjust;
float ascender = size * atlas.getFloat("ascender", 0.75f);
descent = size * atlas.getFloat("descender", -0.25f);
underY = atlas.getFloat("underlineY", -0.1f);
underBreadth = atlas.getFloat("underlineThickness", 0.05f);

// int columns = fnt.getInt("Columns");
// int padding = fnt.getInt("GlyphPadding");
Expand Down

0 comments on commit 2f6c12e

Please sign in to comment.