Skip to content

Commit

Permalink
cjk font for desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhael-Danilov committed Dec 11, 2024
1 parent cfbedb3 commit 654b7a5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 8 deletions.
4 changes: 4 additions & 0 deletions RemixedDungeonDesktop/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ construo.targets.each { target ->
into("RemixedDungeon-${project.ext.version}-${tag}/mods/Remixed")
}

zipTask.from(file("src/desktop/d_assets")) {
into("RemixedDungeon-${project.ext.version}-${tag}/mods/Remixed")
}

zipTask.from(file("src/desktop/l10ns")) {
into("RemixedDungeon-${project.ext.version}-${tag}/mods/Remixed")
}
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.nyrds.platform.util.StringsManager;
import com.watabou.glwrap.Matrix;
import com.watabou.noosa.Text;

import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -34,8 +35,9 @@ public class SystemText extends Text {
private static final SystemTextPseudoBatch batch = new SystemTextPseudoBatch();
private static final float oversample = 4;
private ArrayList<Boolean> wordMask = null;

static {
generator = new FreeTypeFontGenerator(FileSystem.getInternalStorageFileHandle("fonts/pixel_font.ttf"));
invalidate();
}

public SystemText(float baseLine) {
Expand Down Expand Up @@ -98,14 +100,15 @@ private FreeTypeFontParameter getFontParameters(float baseLine) {
final FreeTypeFontParameter fontParameters;
fontParameters = new FreeTypeFontParameter();
fontParameters.characters = FreeTypeFontGenerator.DEFAULT_CHARS + StringsManager.getAllCharsAsString();
//PUtil.slog("font", "characters " + fontParameters.characters);
fontParameters.size = (int) (baseLine * oversample * fontScale);
fontParameters.borderColor = Color.BLACK;
fontParameters.borderWidth = oversample * fontScale;
fontParameters.flip = true;
fontParameters.genMipMaps = true;
fontParameters.magFilter = Texture.TextureFilter.Linear;
fontParameters.minFilter = Texture.TextureFilter.MipMapLinearLinear;
fontParameters.spaceX = 0;
fontParameters.spaceX = -2;
fontParameters.spaceY = 0;
return fontParameters;
}
Expand All @@ -120,7 +123,7 @@ private void wrapText() {
}

lines.clear();
if(mask != null) {
if (mask != null) {
wordMask = new ArrayList<>();
}

Expand All @@ -137,10 +140,10 @@ private void wrapText() {
float line_width = 0;
for (String word : words) {
glyphLayout.setText(font, word);
if(mask != null) {
if (mask != null) {
wordMask.add(mask[index]);
}
if ((line_width + glyphLayout.width + spaceLayout.width)/oversample <= maxWidth) {
if ((line_width + glyphLayout.width + spaceLayout.width) / oversample <= maxWidth) {
currentLine.add(word);
line_width += glyphLayout.width + spaceLayout.width;
} else {
Expand All @@ -149,7 +152,7 @@ private void wrapText() {
currentLine.add(word);
line_width = glyphLayout.width + spaceLayout.width;
}
index+=word.length();
index += word.length();
}
if (!currentLine.isEmpty()) {
lines.add(currentLine);
Expand Down Expand Up @@ -183,7 +186,7 @@ protected void updateMatrix() {

@Override
public void draw() {
if(dirty) {
if (dirty) {
lines.clear();
measure();
}
Expand All @@ -196,7 +199,7 @@ public void draw() {
float x = 0;
for (String word : line) {
glyphLayout.setText(font, word);
if(wordMask == null || wordMask.get(wi)) {
if (wordMask == null || wordMask.get(wi)) {
font.draw(batch, glyphLayout, x, y);
}
x += glyphLayout.width + spaceLayout.width; // Use spaceLayout.width
Expand Down Expand Up @@ -256,8 +259,14 @@ public int lines() {
public static void invalidate() {
if (generator != null) {
generator.dispose();
}

if (GamePreferences.classicFont()) {
generator = new FreeTypeFontGenerator(FileSystem.getInternalStorageFileHandle("fonts/pixel_font.ttf"));
} else {
generator = new FreeTypeFontGenerator(FileSystem.getInternalStorageFileHandle("fonts/LXGWWenKaiScreen.ttf"));
}

synchronized (fontCache) {
for (BitmapFont font : fontCache.values()) {
font.dispose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class FileSystem {
"mods/"+ModdingMode.activeMod()+"/",
"mods/Remixed/",
"../assets/",
"../d_assets/",
"../l10ns/",
"./",
}) {
Expand All @@ -48,6 +49,7 @@ public class FileSystem {
for(String path : new String[] {
"mods/Remixed/",
"../assets/",
"../d_assets/",
"./",
}) {
fileHandle = Gdx.files.internal(path+fileName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private static void parseStrings(String resource) {
String line = Utils.EMPTY_STRING;

while ((line = br.readLine()) != null) {
//PUtil.slog("strings",line);
JSONArray entry = new JSONArray(line);

String keyString = entry.getString(0);
Expand Down

0 comments on commit 654b7a5

Please sign in to comment.