Draw unicode4d glyphs working

This commit is contained in:
Willem Cazander 2022-03-18 02:10:02 +01:00
parent df5efd4dab
commit 5dfd954db1
9 changed files with 223 additions and 90 deletions

View file

@ -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()));
}

View file

@ -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<plane.getStart()+33+offset;i++) {
if (i < 65536) {
buf.append((char)i);
if (plane.isPlane0()) {
StringBuilder buf = new StringBuilder();
int offset = 33;
for (int i=plane.getStart()+offset;i<plane.getStart()+33+offset;i++) {
if (i < 65536) {
buf.append((char)i);
}
buf.append(" ");
}
ImGui.text(buf.toString());
} else {
// LIMITED;
// 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
int offset = 33;
for (int i=plane.getStart()+offset;i<plane.getStart()+7+offset;i++) {
DrawCharacter drawChar = unicode4DService.getCharacterForUnicode(i);
if (drawChar != null) {
new ImCharacter(drawChar).render();
} else {
ImGui.text("?");
}
ImGui.sameLine();
}
buf.append(" ");
}
ImGui.text(buf.toString());
}
ImGui.endTable();
}

View file

@ -1,18 +1,12 @@
package love.distributedrebirth.gdxapp4d.app.notepad;
import imgui.ImColor;
import imgui.ImDrawList;
import imgui.ImGui;
import imgui.ImVec2;
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.draw.DrawCharacter;
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphLineTo;
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphPathCommand;
import love.distributedrebirth.unicode4d.draw.DrawGlyphPath.ImGlyphQuadCurveTo;
import love.distributedrebirth.unicode4d.draw.ImCharacter;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
@ -34,9 +28,6 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
ImGui.text("Value:");
ImGui.text(value);
//Integer.parseInt("27d6", 16)
//new Character('ﷲ').charValue()
//new ImCharacter(unicode4DService.getCharacterForUnicode(Integer.parseInt("27d6", 16))).render();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('ﷲ').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('v').charValue())).render();
@ -50,62 +41,19 @@ public class NotepadDeskApp extends AbstractDeskApp implements DeskAppRenderer {
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('M').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('⁴').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('\'').charValue())).render();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('^').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('ᵃ').charValue())).render();
ImGui.sameLine();
new ImCharacter(unicode4DService.getCharacterForUnicode(new Character('a').charValue())).render();
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();
}
class ImCharacter {
private final DrawCharacter drawChar;
public ImCharacter(DrawCharacter drawChar) {
this.drawChar = drawChar;
}
public void render() {
ImVec2 size = new ImVec2(50f, 70f);
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 + 55f;
float yFlip = -1f;
float scale = 0.025f;
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();
}
}
}

View file

@ -0,0 +1,20 @@
package love.distributedrebirth.numberxd.base2t.type;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
public class V018TordTest {
@Test
public void testSetValue() {
V018Tord tord = new V018Tord();
for (int i=0;i<262144;i++) {
tord.setValueNumber(i);
int value = tord.getValueNumber();
Assertions.assertEquals(i, value);
}
}
}

View file

@ -17,5 +17,9 @@
<artifactId>gdxapp4d-lib-numberxd</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.github.spair</groupId>
<artifactId>imgui-java-binding</artifactId>
</dependency>
</dependencies>
</project>

View file

@ -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<V072Tong> tongs) {

View file

@ -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()) {

View file

@ -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();
}
}

View file

@ -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);
}
}
}
}