#include "commons/commons_bdf.h" #include #include "commons/commons_hex.h" #include "commons/commons_base.h" #include "commons/commons_region_alloc.h" #include "commons/commons_stringparser.h" namespace BdfParser { auto API NextGlyph(bdf_parser& self, region_alloc& alloc, bdf_glyph& out) -> bool { auto allocMark = alloc.at; for (;;) { RegionAlloc_Reset(alloc, allocMark); if (ByteParser_StartsWith(self, "ENDFONT"_s)) return false; if (!ByteParser_StartsWithAdvance(self, "ENCODING "_s)) { ByteParser_NextLine(self); continue; } out.encoding = CastU32(StringParser_ParseLong(self)); ByteParser_NextLine(self); ASSERT(ByteParser_StartsWithAdvance(self, "SWIDTH "_s)); ByteParser_NextLine(self); ASSERT(ByteParser_StartsWithAdvance(self, "DWIDTH "_s)); for (uint32_t i = 0; i < 2; ++i) { out.dwidth[i] = CastI32(StringParser_ParseLong(self)); if (i != 1) ASSERT(ByteParser_Read(self) == ' '); } ByteParser_NextLine(self); ASSERT(ByteParser_StartsWithAdvance(self, "BBX "_s)); for (uint32_t i = 0; i < 4; ++i) { int64_t l = StringParser_ParseLong(self); out.bbx[i] = CastI32(l); if (i != 3) ASSERT(ByteParser_Read(self) == ' '); } ByteParser_NextLine(self); ASSERT(ByteParser_StartsWithAdvance(self, "BITMAP"_s)); ByteParser_NextLine(self); span data = RegionAlloc_AllocArray(alloc, 32ULL * 2ULL); uint32_t i = 0; uint32_t count = 0; while (!ByteParser_StartsWith(self, "ENDCHAR"_s)) { uint8_t ch1 = ByteParser_Read(self); uint8_t ch2 = ByteParser_Read(self); data[i++] = ParseHexByte(ch1, ch2); ++count; ch1 = ByteParser_Read(self); ch2 = ByteParser_Read(self); data[i++] = ParseHexByte(ch1, ch2); ++count; ByteParser_NextLine(self); } out.bitmap = data; return true; } } } // namespace BdfParser