From 5dfd954db1af0dc06a6697f50bf4598025992487 Mon Sep 17 00:00:00 2001 From: Willem Date: Fri, 18 Mar 2022 02:10:02 +0100 Subject: [PATCH] Draw unicode4d glyphs working --- .../app/glyphdemo/GlyphDemoComponent.java | 2 +- .../apps/DemoUnicodePlaneDeskApp.java | 38 ++++++--- .../gdxapp4d/app/notepad/NotepadDeskApp.java | 74 +++-------------- .../numberxd/base2t/type/V018TordTest.java | 20 +++++ gdxapp4d-lib-unicodezd/pom.xml | 4 + .../unicode4d/CodePointᶻᴰ.java | 37 +++++---- .../unicode4d/UnicodePlaneᶻᴰ.java | 4 + .../unicode4d/draw/ImCharacter.java | 79 +++++++++++++++++++ .../unicode4d/CodePointTest.java | 55 +++++++++++++ 9 files changed, 223 insertions(+), 90 deletions(-) create mode 100644 gdxapp4d-lib-numberxd/src/test/java/love/distributedrebirth/numberxd/base2t/type/V018TordTest.java create mode 100644 gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/draw/ImCharacter.java create mode 100644 gdxapp4d-lib-unicodezd/src/test/java/love/distributedrebirth/unicode4d/CodePointTest.java diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java index 45b73afd..6c919f65 100644 --- a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/GlyphDemoComponent.java @@ -38,7 +38,7 @@ public class GlyphDemoComponent { private final DeskAppLauncher basePartLauncher; public GlyphDemoComponent() { - unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle())); + unicodeLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Unicode Plane", () -> new DemoUnicodePlaneDeskApp(createBundle(), unicode4DService)); baseGlyphLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Glyph Set", () -> new DemoGlyphSetDeskApp(createBundle())); basePartLauncher = new DeskAppLauncher(DeskAppMenuSection.PROGRAMMING, "Demo Number Parts", () -> new DemoNumberPartDeskApp(createBundle())); } diff --git a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnicodePlaneDeskApp.java b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnicodePlaneDeskApp.java index 6500fce5..21ec1cf4 100644 --- a/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnicodePlaneDeskApp.java +++ b/gdxapp4d-app-glyphdemo/src/main/java/love/distributedrebirth/gdxapp4d/app/glyphdemo/apps/DemoUnicodePlaneDeskApp.java @@ -5,17 +5,22 @@ import java.util.ResourceBundle; import imgui.ImGui; import imgui.flag.ImGuiTableFlags; import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.gdxapp4d.vrgem4.service.VrGem4Unicode4DService; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.AbstractDeskApp; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppContourSection; import love.distributedrebirth.gdxapp4d.vrgem4.service.deskapp.DeskAppRenderer; import love.distributedrebirth.unicode4d.UnicodePlaneᶻᴰ; +import love.distributedrebirth.unicode4d.draw.DrawCharacter; +import love.distributedrebirth.unicode4d.draw.ImCharacter; @BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") public class DemoUnicodePlaneDeskApp extends AbstractDeskApp implements DeskAppRenderer { + private final VrGem4Unicode4DService unicode4DService; private final ResourceBundle bundle; - public DemoUnicodePlaneDeskApp(ResourceBundle bundle) { + public DemoUnicodePlaneDeskApp(ResourceBundle bundle, VrGem4Unicode4DService unicode4DService) { + this.unicode4DService = unicode4DService; this.bundle = bundle; } @@ -40,16 +45,31 @@ public class DemoUnicodePlaneDeskApp extends AbstractDeskApp implements DeskAppR ImGui.tableNextColumn(); ImGui.text(plane.name()); ImGui.tableNextColumn(); - StringBuilder buf = new StringBuilder(); - int offset = 33; - for (int i=plane.getStart()+offset;i_VtxCurrentIdx < (1 << 16) && "Too many vertices in ImDrawList using 16-bit indices. Read comment above" + // Assertion Located At: /tmp/imgui/jni/imgui.cpp:4526 + int offset = 33; + for (int i=plane.getStart()+offset;igdxapp4d-lib-numberxd ${project.version} + + io.github.spair + imgui-java-binding + \ No newline at end of file diff --git a/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/CodePointᶻᴰ.java b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/CodePointᶻᴰ.java index e9bfa3c9..aef0086d 100644 --- a/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/CodePointᶻᴰ.java +++ b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/CodePointᶻᴰ.java @@ -13,7 +13,8 @@ public enum CodePointᶻᴰ { INSTANCE; private static final int MASK_CMD = 0b111000000000000000; - private static final int MASK_ARGU = 0b000111111111111111; + private static final int MASK_SIGN = 0b000100000000000000; + private static final int MASK_ARGU = 0b000011111111111111; public static final int MODIFIER_STRIKE_HIGH = 0b000000000000000001; public static final int MODIFIER_STRIKE_MID = 0b000000000000000010; @@ -26,34 +27,36 @@ public enum CodePointᶻᴰ { public static final int MODIFIER_ENVELOP = 0b000000000100000000; public int getArgument(V036Teger teger, T02PartBinary part) { - return teger.getValue(part).getValueNumber() & MASK_ARGU; + int value = teger.getValue(part).getValueNumber(); + int result = value & MASK_ARGU; + if ((value & MASK_SIGN) != 0) { + result |= 0xFFFFC000; + } + return result; } public void setArgument(V036Teger teger, T02PartBinary part, int number) { int value = teger.getValue(part).getValueNumber(); - teger.getValue(part).setValueNumber((value & MASK_CMD) + (number & MASK_ARGU)); + int result = (value & MASK_CMD) + ((number >> 17) & MASK_SIGN) + (number & MASK_ARGU); + teger.getValue(part).setValueNumber(result); } public int getArgumentUnicode(V036Teger teger) { int unicode = 0; - unicode += getArgument(teger, T02PartBinary.PART_1); - unicode += getArgument(teger, T02PartBinary.PART_2) << 15; + unicode += teger.getValue(T02PartBinary.PART_1).getValueNumber() & MASK_ARGU+MASK_SIGN; + unicode += (teger.getValue(T02PartBinary.PART_2).getValueNumber() & MASK_ARGU+MASK_SIGN) << 15; return unicode; } public void setArgumentUnicode(V036Teger teger, int unicode) { - setArgument(teger, T02PartBinary.PART_1, unicode); - setArgument(teger, T02PartBinary.PART_2, unicode >> 15); - } - /* - public long getArgumentNumber(V036Teger teger) { - return teger.getValueNumber(); + int value1 = teger.getValue(T02PartBinary.PART_1).getValueNumber(); + int value2 = teger.getValue(T02PartBinary.PART_2).getValueNumber(); + value1 = (value1 & MASK_CMD) + (unicode & MASK_ARGU+MASK_SIGN); + value2 = (value2 & MASK_CMD) + ((unicode >> 15) & MASK_ARGU+MASK_SIGN); + teger.getValue(T02PartBinary.PART_1).setValueNumber(value1); + teger.getValue(T02PartBinary.PART_2).setValueNumber(value2); } - public void setArgumentNumber(V036Teger teger, long number) { - teger.setValueNumber(number); - } - */ public CodePointCommandᶻᴰ getCommand(V036Teger teger) { int mode = 0; mode += (teger.getValue(T02PartBinary.PART_1).getValueNumber() >> 15) << 0; @@ -65,8 +68,8 @@ public enum CodePointᶻᴰ { int mode = command.ordinal(); int value1 = teger.getValue(T02PartBinary.PART_1).getValueNumber(); int value2 = teger.getValue(T02PartBinary.PART_2).getValueNumber(); - teger.getValue(T02PartBinary.PART_1).setValueNumber((value1 & MASK_ARGU) + (((mode >> 0) & 0b111) << 15)); - teger.getValue(T02PartBinary.PART_2).setValueNumber((value2 & MASK_ARGU) + (((mode >> 3) & 0b111) << 15)); + teger.getValue(T02PartBinary.PART_1).setValueNumber(value1 | (((mode >> 0) << 15)) & MASK_CMD); + teger.getValue(T02PartBinary.PART_2).setValueNumber(value2 | (((mode >> 3) << 15)) & MASK_CMD); } public int searchUnicode(List tongs) { diff --git a/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/UnicodePlaneᶻᴰ.java b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/UnicodePlaneᶻᴰ.java index 02940a38..a9d831e8 100644 --- a/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/UnicodePlaneᶻᴰ.java +++ b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/UnicodePlaneᶻᴰ.java @@ -391,6 +391,10 @@ public enum UnicodePlaneᶻᴰ { return leftToRight; } + public boolean isPlane0() { + return getStart() < 0xFFFF; + } + public static UnicodePlaneᶻᴰ valueOfUnicode(int unicode) { for (UnicodePlaneᶻᴰ value:values()) { if (unicode >= value.getStart() && unicode <= value.getStop()) { diff --git a/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/draw/ImCharacter.java b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/draw/ImCharacter.java new file mode 100644 index 00000000..e904f865 --- /dev/null +++ b/gdxapp4d-lib-unicodezd/src/main/java/love/distributedrebirth/unicode4d/draw/ImCharacter.java @@ -0,0 +1,79 @@ +package love.distributedrebirth.unicode4d.draw; + +import imgui.ImColor; +import imgui.ImDrawList; +import imgui.ImGui; +import imgui.ImVec2; +import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphLineTo; +import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphPathCommand; +import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo; + +public class ImCharacter { + + private final DrawCharacter drawChar; + + public ImCharacter(DrawCharacter drawChar) { + this.drawChar = drawChar; + } + + public void render() { + ImVec2 size = new ImVec2(35f, 50f); + ImGui.invisibleButton("canvas", size.x, size.y); + ImVec2 p0 = ImGui.getItemRectMin(); + ImVec2 p1 = ImGui.getItemRectMax(); // p1 = p0 + size + ImDrawList drawList = ImGui.getWindowDrawList(); + drawList.pushClipRect(p0.x, p0.y, p1.x, p1.y); + + // draw unicode4D + float xOff = p0.x; + float yOff = p0.y + 35f; + float yFlip = -1f; + float scale = 0.0165f; + ImGlyphPathCommand first = null; + ImGlyphPathCommand prev = null; + int color = ImColor.intToColor(255, 127, 63, 255); + for (ImGlyphPathCommand cmd: drawChar.getGlyphPath().getPath()) { + if (cmd.isImGlyphMoveTo()) { + first = cmd; + prev = cmd; + continue; + } + if (cmd.isImGlyphLineTo()) { + ImGlyphLineTo lineTo = cmd.toImGlyphLineTo(); + drawList.addLine( + xOff+prev.getX()*scale, + yOff+prev.getY()*scale*yFlip, + xOff+lineTo.getX()*scale, + yOff+lineTo.getY()*scale*yFlip, + color); + prev = cmd; + continue; + } + if (cmd.isImGlyphQuadCurveTo()) { + ImGlyphQuadCurveTo quadCurveTo = cmd.toImGlyphQuadCurveTo(); + drawList.addBezierQuadratic( + xOff+prev.getX()*scale, + yOff+prev.getY()*scale*yFlip, + xOff+quadCurveTo.getX1()*scale, + yOff+quadCurveTo.getY1()*scale*yFlip, + xOff+quadCurveTo.getX()*scale, + yOff+quadCurveTo.getY()*scale*yFlip, + color, + 1); + prev = cmd; + continue; + } + if (cmd.isImGlyphClosePath()) { + drawList.addLine( + xOff+prev.getX()*scale, + yOff+prev.getY()*scale*yFlip, + xOff+first.getX()*scale, + yOff+first.getY()*scale*yFlip, + color); + } + } + 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); + drawList.popClipRect(); + } +} \ No newline at end of file diff --git a/gdxapp4d-lib-unicodezd/src/test/java/love/distributedrebirth/unicode4d/CodePointTest.java b/gdxapp4d-lib-unicodezd/src/test/java/love/distributedrebirth/unicode4d/CodePointTest.java new file mode 100644 index 00000000..970d5389 --- /dev/null +++ b/gdxapp4d-lib-unicodezd/src/test/java/love/distributedrebirth/unicode4d/CodePointTest.java @@ -0,0 +1,55 @@ +package love.distributedrebirth.unicode4d; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ; +import love.distributedrebirth.numberxd.base2t.part.T02PartBinary; +import love.distributedrebirth.numberxd.base2t.type.V036Teger; + +@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天") +public class CodePointTest { + + @Test + public void testCommand() { + V036Teger teger = new V036Teger(); + CodePointᶻᴰ.INSTANCE.setArgument(teger, T02PartBinary.PART_1, 0); + CodePointᶻᴰ.INSTANCE.setArgument(teger, T02PartBinary.PART_2, 12345); + for (CodePointCommandᶻᴰ cmd:CodePointCommandᶻᴰ.values()) { + CodePointᶻᴰ.INSTANCE.setCommand(teger, cmd); + int value1 = CodePointᶻᴰ.INSTANCE.getArgument(teger, T02PartBinary.PART_1); + int value2 = CodePointᶻᴰ.INSTANCE.getArgument(teger, T02PartBinary.PART_2); + Assertions.assertEquals(0, value1); + Assertions.assertEquals(12345, value2); + } + } + + @Test + public void testNegativeArguments() { + V036Teger teger = new V036Teger(); + for (int i=-16384;i<16384;i++) { + for (CodePointCommandᶻᴰ cmd:CodePointCommandᶻᴰ.values()) { + CodePointᶻᴰ.INSTANCE.setArgument(teger, T02PartBinary.PART_1, i); + CodePointᶻᴰ.INSTANCE.setArgument(teger, T02PartBinary.PART_2, i); + CodePointᶻᴰ.INSTANCE.setCommand(teger, cmd); + int value1 = CodePointᶻᴰ.INSTANCE.getArgument(teger, T02PartBinary.PART_1); + int value2 = CodePointᶻᴰ.INSTANCE.getArgument(teger, T02PartBinary.PART_2); + Assertions.assertEquals(i, value1); + Assertions.assertEquals(i, value2); + } + } + } + + @Test + public void testUnicode() { + V036Teger teger = new V036Teger(); + for (int i=0;i<244000;i++) { + for (CodePointCommandᶻᴰ cmd:CodePointCommandᶻᴰ.values()) { + CodePointᶻᴰ.INSTANCE.setArgumentUnicode(teger, i); + CodePointᶻᴰ.INSTANCE.setCommand(teger, cmd); + int value = CodePointᶻᴰ.INSTANCE.getArgumentUnicode(teger); + Assertions.assertEquals(i, value); + } + } + } +}