Fixed ttf4d rendering

This commit is contained in:
Willem Cazander 2022-03-18 16:05:38 +01:00
parent 5679699282
commit 05993d3768
6 changed files with 51 additions and 43 deletions

View file

@ -3,6 +3,7 @@ package love.distributedrebirth.gdxapp4d.app.glyphdemo.apps;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import imgui.ImGui; import imgui.ImGui;
import imgui.flag.ImGuiStyleVar;
import imgui.flag.ImGuiTableFlags; import imgui.flag.ImGuiTableFlags;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService; import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService;
@ -60,24 +61,28 @@ public class DemoUnicodePlaneDeskApp extends AbstractDeskApp implements DeskAppR
// Dear ImGui Assertion Failed: draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above" // Dear ImGui Assertion Failed: draw_list->_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above"
// Assertion Located At: /tmp/imgui/jni/imgui.cpp:4526 // Assertion Located At: /tmp/imgui/jni/imgui.cpp:4526
DrawCharacter drawChar2 = unicode4DService.getCharacterForUnicode('?'); ImGui.pushStyleVar(ImGuiStyleVar.ItemSpacing, 0f, 0f);
DrawCharacter drawChar2 = unicode4DService.getCharacterForUnicode(' ');
if (drawChar2 != null) { if (drawChar2 != null) {
new ImCharacter(drawChar2).render(); ImCharacter.render(drawChar2);
ImGui.sameLine(); // print before beginChild to fix height of table row ImGui.sameLine(); // print before beginChild to fix height of table row
} }
int offset = 33; int offset = 33;
ImGui.beginChild("row"+plane.name()); ImGui.beginChild("row"+plane.name());
for (int i=plane.getStart()+offset;i<plane.getStart()+17+offset;i++) { for (int i=plane.getStart()+offset;i<plane.getStart()+33+offset;i++) {
DrawCharacter drawChar = unicode4DService.getCharacterForUnicode(i); DrawCharacter drawChar = unicode4DService.getCharacterForUnicode(i);
if (drawChar != null) { if (drawChar != null) {
new ImCharacter(drawChar).render(); ImCharacter.render(drawChar);
} else { } else {
ImGui.text("?"); ImGui.text("?");
} }
ImGui.sameLine(); ImGui.sameLine();
} }
ImGui.endChild(); ImGui.endChild();
ImGui.popStyleVar();
} }
} }
ImGui.endTable(); ImGui.endTable();

View file

@ -28,32 +28,24 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
ImGui.text("Value:"); ImGui.text("Value:");
ImGui.text(value); ImGui.text(value);
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('ﷲ').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('ﷲ'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('v').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('v'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('r').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('r'));
//ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('G').charValue())).render();
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('E').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('G'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('M').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('E'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('⁴').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('M'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('\'').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('⁴'));
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('^').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('M'));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('ᵃ').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode(Integer.parseInt("27d6", 16)));
ImGui.sameLine(); ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('a').charValue())).render(); ImCharacter.render(unicode4DService.getCharacterForUnicode('仙'));
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('A').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(Integer.parseInt("27d6", 16))).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('仙').charValue())).render();
} }
} }

View file

@ -22,15 +22,26 @@ for(let glyphIndex = 0; glyphIndex < num; glyphIndex++) {
// JS NOTE: without calling xMin the getContours returns empty set.... :''( // JS NOTE: without calling xMin the getContours returns empty set.... :''(
glyph.xMin; glyph.xMin;
var contours = glyph.getContours(); var contours = glyph.getContours();
if (contours.length === 0) { //space is also without contours
continue; // TODO: add compound support // if (contours.length === 0) {
} // continue; // TODO: add compound support
// }
if (glyph.unicodes.length === 0) { if (glyph.unicodes.length === 0) {
continue; // with cmds, these are compound glyphs by index base only continue; // with cmds, these are compound glyphs by index base only
} }
let uni = glyph.unicodes.map(formatUnicode).join(', '); let uni = glyph.unicodes.map(formatUnicode).join(', ');
let xMax = glyph.xMax;
let yMax = glyph.yMax;
let xMin = glyph.xMin;
let yMin = glyph.yMin;
if (glyph.xMax === undefined) { xMax = 0; }
if (glyph.yMax === undefined) { yMax = 0; }
if (glyph.xMin === undefined) { xMin = 0; }
if (glyph.yMin === undefined) { yMin = 0; }
console.log("\t<glyph unicode=\""+uni+"\" name=\""+glyph.name+"\" advanceWidth=\""+glyph.advanceWidth+"\" "+ console.log("\t<glyph unicode=\""+uni+"\" name=\""+glyph.name+"\" advanceWidth=\""+glyph.advanceWidth+"\" "+
"xMin=\""+glyph.xMin+"\" xMax=\""+glyph.xMax+"\" yMin=\""+glyph.yMin+"\" yMax=\""+glyph.yMax+"\" "+ "xMin=\""+xMin+"\" xMax=\""+xMax+"\" yMin=\""+yMin+"\" yMax=\""+yMax+"\" "+
"leftSideBearing=\""+glyph.leftSideBearing+"\">"); "leftSideBearing=\""+glyph.leftSideBearing+"\">");
for (let contourIndex = 0; contourIndex < contours.length; ++contourIndex) { for (let contourIndex = 0; contourIndex < contours.length; ++contourIndex) {

View file

@ -6,5 +6,7 @@ SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
for FILE in `ls $1` for FILE in `ls $1`
do do
node $SCRIPT_DIR/conv-font.js $1/$FILE > $2/$FILE.xml if [[ $FILE == *.ttf ]]; then
done node $SCRIPT_DIR/conv-font.js $1/$FILE > $2/$FILE.xml
fi
done

View file

@ -10,14 +10,8 @@ import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo;
public class ImCharacter { public class ImCharacter {
private final DrawCharacter drawChar; public static void render(DrawCharacter drawChar) {
ImVec2 size = new ImVec2(22f, 26f);
public ImCharacter(DrawCharacter drawChar) {
this.drawChar = drawChar;
}
public void render() {
ImVec2 size = new ImVec2(35f, 50f);
ImGui.invisibleButton("canvas", size.x, size.y); ImGui.invisibleButton("canvas", size.x, size.y);
ImVec2 p0 = ImGui.getItemRectMin(); ImVec2 p0 = ImGui.getItemRectMin();
ImVec2 p1 = ImGui.getItemRectMax(); // p1 = p0 + size ImVec2 p1 = ImGui.getItemRectMax(); // p1 = p0 + size
@ -26,12 +20,12 @@ public class ImCharacter {
// draw unicode4D // draw unicode4D
float xOff = p0.x; float xOff = p0.x;
float yOff = p0.y + 35f; float yOff = p0.y + 19f;
float yFlip = -1f; float yFlip = -1f;
float scale = 0.0165f; float scale = 0.0090f;
ImGlyphPathCommand first = null; ImGlyphPathCommand first = null;
ImGlyphPathCommand prev = null; ImGlyphPathCommand prev = null;
int color = ImColor.intToColor(255, 127, 63, 255); int color = ImColor.intToColor(255, 255, 255, 255);
for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) { for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) {
if (cmd.isImGlyphMoveTo()) { if (cmd.isImGlyphMoveTo()) {
first = cmd; first = cmd;
@ -72,8 +66,8 @@ public class ImCharacter {
color); color);
} }
} }
drawList.addQuad(p0.x, p0.y, p0.x+size.x, p0.y, p1.x, p1.y, p0.x, p0.y+size.y, //drawList.addQuad(p0.x, p0.y, p0.x+size.x, p0.y, p1.x, p1.y, p0.x, p0.y+size.y,
ImColor.intToColor(127, 127, 255, 255), 1f); // ImColor.intToColor(127, 127, 255, 255), 1f);
drawList.popClipRect(); drawList.popClipRect();
} }
} }

View file

@ -42,7 +42,7 @@ public class TestConvFont {
try { try {
// NOTE: Are in order like the FontAtlas of ImGui // NOTE: Are in order like the FontAtlas of ImGui
String in = "../gdxapp4d-chain-font-unicode4d/target/chain2/"; String in = "../gdxapp4d-chain-font-unicode4d/target/chain2/";
String out = "../gdxapp4d-chain-font-unicode4d/target/chain/"; String out = "../gdxapp4d-chain-font-unicode4d/src/main/chain/";
conf("code-2000", new File(in+"plane0/code-2000.ttf.xml"), new File(out+"plane0/code-2000.ttf4d")); conf("code-2000", new File(in+"plane0/code-2000.ttf.xml"), new File(out+"plane0/code-2000.ttf4d"));
conf("fa-solid-900", new File(in+"plane0/fa-solid-900.ttf.xml"), new File(out+"plane0/fa-solid-900.ttf4d")); conf("fa-solid-900", new File(in+"plane0/fa-solid-900.ttf.xml"), new File(out+"plane0/fa-solid-900.ttf4d"));
@ -182,7 +182,11 @@ public class TestConvFont {
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.NOP); CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.NOP);
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.NOP); CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.NOP);
unicode = Integer.parseInt(atts.getValue("unicode"), 16); String unicodeStr = atts.getValue("unicode");
if (unicodeStr.startsWith("0000, ")) {
unicodeStr = unicodeStr.substring(7);
}
unicode = Integer.parseInt(unicodeStr, 16);
unicodePlane2 = UnicodePlaneᶻᴰ.valueOfUnicode(unicode); unicodePlane2 = UnicodePlaneᶻᴰ.valueOfUnicode(unicode);
int xMax = Integer.parseInt(atts.getValue("xMax")); int xMax = Integer.parseInt(atts.getValue("xMax"));
int yMax = Integer.parseInt(atts.getValue("yMax")); int yMax = Integer.parseInt(atts.getValue("yMax"));