From 853939405b8d88abbb005dcc3d54ecc55bc2d33d Mon Sep 17 00:00:00 2001 From: sfan5 Date: Tue, 9 Nov 2021 22:19:35 +0100 Subject: [PATCH] Add XMLFontConverter source file --- tools/XMLFontConverter.cpp | 97 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 tools/XMLFontConverter.cpp diff --git a/tools/XMLFontConverter.cpp b/tools/XMLFontConverter.cpp new file mode 100644 index 00000000..ad03415a --- /dev/null +++ b/tools/XMLFontConverter.cpp @@ -0,0 +1,97 @@ +#include +#include + +using namespace irr; + +// Builds with an Irrlicht version that still has XML (e.g. 1.9.0mt2) +// g++ -Wall -O2 XMLFontConverter.cpp -o XMLFontConverter -I/tmp/irrlicht/include -L/tmp/irrlicht/lib/Linux -lIrrlichtMt + +int main(int argc, char* argv[]) +{ + if (argc < 3) + { + printf("Usage: XMLFontConverter \n"); + return 1; + } + + IrrlichtDevice *device = createDevice(video::EDT_NULL, + core::dimension2d(800, 600), 32, false, false, false, 0); + + io::IXMLReader *xml = device->getFileSystem()->createXMLReader(argv[1]); + io::IWriteFile *wf = device->getFileSystem()->createAndWriteFile(argv[2]); + u32 nchars = 0; + + while (xml->read()) + { + if (io::EXN_ELEMENT != xml->getNodeType()) + continue; + if (core::stringw(L"Texture") == xml->getNodeName()) + { + core::stringc fn = xml->getAttributeValue(L"filename"); + + core::stringc line("Texture: "); + line.append(fn); + line.append('\n'); + wf->write(line.c_str(), line.size()); + } + else if (core::stringw(L"c") == xml->getNodeName()) + { + core::rect rect; + s32 underhang = xml->getAttributeValueAsInt(L"u"); + s32 overhang = xml->getAttributeValueAsInt(L"o"); + core::stringc rectstr = xml->getAttributeValue(L"r"); + wchar_t ch = xml->getAttributeValue(L"c")[0]; + + nchars++; + + const c8 *c = rectstr.c_str(); + s32 val = core::strtol10(c, &c); + rect.UpperLeftCorner.X = val; + while (*c == L' ' || *c == L',') c++; + val = core::strtol10(c, &c); + rect.UpperLeftCorner.Y = val; + while (*c == L' ' || *c == L',') c++; + val = core::strtol10(c, &c); + rect.LowerRightCorner.X = val; + while (*c == L' ' || *c == L',') c++; + val = core::strtol10(c, &c); + rect.LowerRightCorner.Y = val; + + core::stringc line; + char tmp[6]; + + snprintf(tmp, 6, "%04X", static_cast(ch)); + line.append(tmp); + line.append('\t'); + + line.append(core::stringc(rect.UpperLeftCorner.X)); + line.append('\t'); + line.append(core::stringc(rect.UpperLeftCorner.Y)); + line.append('\t'); + line.append(core::stringc(rect.LowerRightCorner.X)); + line.append('\t'); + line.append(core::stringc(rect.LowerRightCorner.Y)); + + if (underhang != 0 || overhang != 0) + { + line.append('\t'); + line.append(core::stringc(underhang)); + if (overhang != 0) + { + line.append('\t'); + line.append(core::stringc(overhang)); + } + } + + line.append('\n'); + wf->write(line.c_str(), line.size()); + } + } + + printf("Success: %d chars\n", nchars); + xml->drop(); + wf->drop(); + device->drop(); + + return 0; +}