2022-02-19 15:40:47 +00:00
|
|
|
package love.distributedrebirth.unicode4d;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileInputStream;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import javax.xml.parsers.SAXParser;
|
|
|
|
import javax.xml.parsers.SAXParserFactory;
|
|
|
|
|
|
|
|
import org.xml.sax.Attributes;
|
|
|
|
import org.xml.sax.ContentHandler;
|
|
|
|
import org.xml.sax.InputSource;
|
|
|
|
import org.xml.sax.Locator;
|
|
|
|
import org.xml.sax.SAXException;
|
|
|
|
import org.xml.sax.XMLReader;
|
|
|
|
|
|
|
|
import love.distributedrebirth.bassboonyd.BãßBȍőnAuthorInfoʸᴰ;
|
|
|
|
import love.distributedrebirth.numberxd.base2t.part.T02PartBinary;
|
|
|
|
import love.distributedrebirth.numberxd.base2t.type.V072Tong;
|
2022-02-20 23:41:24 +00:00
|
|
|
import love.distributedrebirth.unicode4d.atlas.FontAtlas;
|
|
|
|
import love.distributedrebirth.unicode4d.atlas.FontAtlasDriver;
|
|
|
|
import love.distributedrebirth.unicode4d.atlas.FontAtlasStore;
|
|
|
|
import love.distributedrebirth.unicode4d.atlas.FontAtlasStoreGlyph;
|
2022-02-19 15:40:47 +00:00
|
|
|
|
|
|
|
@BãßBȍőnAuthorInfoʸᴰ(name = "willemtsade", copyright = "©Δ∞ 仙上主天")
|
|
|
|
public class TestConvFont {
|
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
TestConvFont tcf = new TestConvFont();
|
|
|
|
tcf.run();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void run() {
|
|
|
|
try {
|
|
|
|
// NOTE: Are in order like the FontAtlas of ImGui
|
2022-02-20 23:41:24 +00:00
|
|
|
conf("Code2000", new File("../conv-font/bin/code-2000.xml"), new File("../main-gdxapp/assets/font/code-2000.xml"));
|
|
|
|
conf("Code2001", new File("../conv-font/bin/code-2001.xml"), new File("../main-gdxapp/assets/font/code-2001.xml"));
|
|
|
|
conf("Code2002", new File("../conv-font/bin/code-2002.xml"), new File("../main-gdxapp/assets/font/code-2002.xml"));
|
|
|
|
conf("Free Sans", new File("../conv-font/bin/free-sans.xml"), new File("../main-gdxapp/assets/font/free-sans.xml"));
|
|
|
|
conf("New Gardiner BMP", new File("../conv-font/bin/new-gardiner-bmp.xml"), new File("../main-gdxapp/assets/font/new-gardiner-bmp.xml"));
|
|
|
|
conf("Font Awesome", new File("../conv-font/bin/fa-solid-900.xml"), new File("../main-gdxapp/assets/font/fa-solid-900.xml"));
|
|
|
|
conf("Noto Sans Brahmi", new File("../conv-font/bin/noto-sans-brahmi.xml"), new File("../main-gdxapp/assets/font/noto-sans-brahmi.xml"));
|
|
|
|
|
2022-02-19 15:40:47 +00:00
|
|
|
} catch (Exception e) {
|
|
|
|
// TODO Auto-generated catch block
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
public void conf(String fontName, File input, File output) throws Exception {
|
2022-02-19 15:40:47 +00:00
|
|
|
System.out.println("START WITH: "+input);
|
2022-02-20 23:41:24 +00:00
|
|
|
|
2022-02-19 15:40:47 +00:00
|
|
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
|
|
|
SAXParser parser = factory.newSAXParser();
|
|
|
|
XMLReader reader = parser.getXMLReader();
|
2022-02-20 23:41:24 +00:00
|
|
|
|
|
|
|
FontAtlas fontAtlas = new FontAtlas();
|
|
|
|
FontAtlasStore fontStore = new FontAtlasStore();
|
|
|
|
fontStore.setName(fontName);
|
|
|
|
fontAtlas.addStore(fontStore);
|
|
|
|
FontContentHandler fontContentHandler = new FontContentHandler(fontStore, input.getName());
|
2022-02-19 15:40:47 +00:00
|
|
|
reader.setContentHandler(fontContentHandler);
|
|
|
|
|
|
|
|
InputSource inputSource = new InputSource(new FileInputStream(input));
|
|
|
|
reader.parse(inputSource);
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
FontAtlasDriver.newInstance().createWriter().writeFile(fontAtlas, output);
|
2022-02-19 15:40:47 +00:00
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
System.out.println("END WITH: "+output+" wrote: "+fontContentHandler.getGlyphCounter());
|
2022-02-19 15:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class FontContentHandler implements ContentHandler {
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
private FontAtlasStore fontStore;
|
|
|
|
private int glyphCounter;
|
|
|
|
private List<V072Tong> tongs;
|
2022-02-19 15:40:47 +00:00
|
|
|
private boolean startPoint = false;
|
|
|
|
private V072Tong point = null;
|
|
|
|
private int unicode = -1;
|
2022-02-20 23:41:24 +00:00
|
|
|
private UnicodePlaneᶻᴰ unicodePlane2;
|
2022-02-19 15:40:47 +00:00
|
|
|
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
public FontContentHandler(FontAtlasStore fontStore, String inputName) {
|
|
|
|
this.fontStore = fontStore;
|
2022-02-19 15:40:47 +00:00
|
|
|
}
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
public int getGlyphCounter() {
|
|
|
|
return glyphCounter;
|
2022-02-19 15:40:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void characters(char[] arg0, int arg1, int arg2) throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void endDocument() throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
|
|
|
|
if ("opentype".equals(qName)) {
|
|
|
|
|
|
|
|
} else if ("glyph".equals(qName)) {
|
|
|
|
|
|
|
|
if (CodePointCommandᶻᴰ.NOP != CodePointᶻᴰ.INSTANCE.getCommand(point.getValue(T02PartBinary.PART_1))) {
|
2022-02-20 23:41:24 +00:00
|
|
|
tongs.add(point);
|
2022-02-19 15:40:47 +00:00
|
|
|
}
|
2022-02-20 23:41:24 +00:00
|
|
|
glyphCounter++;
|
|
|
|
FontAtlasStoreGlyph baseGlyph = new FontAtlasStoreGlyph();
|
|
|
|
baseGlyph.setTongs(tongs);
|
|
|
|
fontStore.addGlyph(baseGlyph);
|
2022-02-19 15:40:47 +00:00
|
|
|
|
|
|
|
} else if ("contour".equals(qName)) {
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void endPrefixMapping(String arg0) throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void ignorableWhitespace(char[] arg0, int arg1, int arg2) throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void processingInstruction(String arg0, String arg1) throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setDocumentLocator(Locator arg0) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void skippedEntity(String arg0) throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startDocument() throws SAXException {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
|
|
|
|
|
|
|
|
if ("opentype".equals(qName)) {
|
|
|
|
|
|
|
|
} else if ("glyph".equals(qName)) {
|
2022-02-20 23:41:24 +00:00
|
|
|
tongs = new ArrayList<>();
|
2022-02-19 15:40:47 +00:00
|
|
|
point = new V072Tong();
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.NOP);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.NOP);
|
|
|
|
|
|
|
|
unicode = Integer.parseInt(atts.getValue("unicode"), 16);
|
2022-02-20 23:41:24 +00:00
|
|
|
unicodePlane2 = UnicodePlaneᶻᴰ.valueOfUnicode(unicode);
|
2022-02-19 15:40:47 +00:00
|
|
|
int xMax = Integer.parseInt(atts.getValue("xMax"));
|
|
|
|
int yMax = Integer.parseInt(atts.getValue("yMax"));
|
|
|
|
int xMin = Integer.parseInt(atts.getValue("xMin"));
|
|
|
|
int yMin = Integer.parseInt(atts.getValue("yMin"));
|
|
|
|
int advanceWidth = Integer.parseInt(atts.getValue("advanceWidth"));
|
|
|
|
int leftSideBearing = Integer.parseInt(atts.getValue("leftSideBearing"));
|
|
|
|
|
|
|
|
V072Tong v0 = new V072Tong();
|
|
|
|
V072Tong v1 = new V072Tong();
|
|
|
|
V072Tong v2 = new V072Tong();
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
if (unicodePlane2.isLeftToRight()) {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v0.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.START_LR);
|
|
|
|
} else {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v0.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.START_RL);
|
|
|
|
}
|
2022-02-19 15:40:47 +00:00
|
|
|
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v0.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.UNICODE);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgumentUnicode(v0.getValue(T02PartBinary.PART_2), unicode);
|
|
|
|
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v1.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.XY_MAX);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v1.getValue(T02PartBinary.PART_1), T02PartBinary.PART_1, xMax);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v1.getValue(T02PartBinary.PART_1), T02PartBinary.PART_2, yMax);
|
|
|
|
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v1.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.XY_MIN);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v1.getValue(T02PartBinary.PART_2), T02PartBinary.PART_1, xMin);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v1.getValue(T02PartBinary.PART_2), T02PartBinary.PART_2, yMin);
|
|
|
|
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v2.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.ADVANCE);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v2.getValue(T02PartBinary.PART_1), T02PartBinary.PART_1, advanceWidth);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(v2.getValue(T02PartBinary.PART_1), T02PartBinary.PART_2, leftSideBearing);
|
|
|
|
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(v2.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.NOP);
|
|
|
|
|
2022-02-20 23:41:24 +00:00
|
|
|
tongs.add(v0);
|
|
|
|
tongs.add(v1);
|
|
|
|
tongs.add(v2);
|
2022-02-19 15:40:47 +00:00
|
|
|
|
|
|
|
} else if ("contour".equals(qName)) {
|
|
|
|
startPoint = true;
|
|
|
|
|
|
|
|
} else if ("point".equals(qName)) {
|
|
|
|
boolean onCurve = Boolean.parseBoolean(atts.getValue("onCurve"));
|
|
|
|
int x = (int) Float.parseFloat(atts.getValue("x"));
|
|
|
|
int y = (int) Float.parseFloat(atts.getValue("y"));
|
|
|
|
|
|
|
|
T02PartBinary part = T02PartBinary.PART_1;
|
|
|
|
if (CodePointCommandᶻᴰ.NOP != CodePointᶻᴰ.INSTANCE.getCommand(point.getValue(T02PartBinary.PART_1))) {
|
|
|
|
part = T02PartBinary.PART_2;
|
|
|
|
}
|
|
|
|
if (onCurve) {
|
|
|
|
if (startPoint) {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(part), CodePointCommandᶻᴰ.XY_ON_CURVE_START);
|
|
|
|
} else {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(part), CodePointCommandᶻᴰ.XY_ON_CURVE);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (startPoint) {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(part), CodePointCommandᶻᴰ.XY_OFF_CURVE_START);
|
|
|
|
} else {
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(part), CodePointCommandᶻᴰ.XY_OFF_CURVE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(point.getValue(part), T02PartBinary.PART_1, x);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setArgument(point.getValue(part), T02PartBinary.PART_2, y);
|
|
|
|
if (part == T02PartBinary.PART_2) {
|
2022-02-20 23:41:24 +00:00
|
|
|
tongs.add(point);
|
2022-02-19 15:40:47 +00:00
|
|
|
point = new V072Tong();
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_1), CodePointCommandᶻᴰ.NOP);
|
|
|
|
CodePointᶻᴰ.INSTANCE.setCommand(point.getValue(T02PartBinary.PART_2), CodePointCommandᶻᴰ.NOP);
|
|
|
|
}
|
|
|
|
if (startPoint) {
|
|
|
|
startPoint = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void startPrefixMapping(String arg0, String arg1) throws SAXException {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|