bool BdfFont::cacheFontData(const BdfFont &font, const Common::String &filename) { Common::DumpFile cacheFile; if (!cacheFile.open(filename)) { warning("BdfFont::cacheFontData: Couldn't open file '%s' for writing", filename.c_str()); return false; } const BdfFontData &data = font._data; cacheFile.writeUint32BE(BDF_FONTCACHE_TAG); cacheFile.writeUint32BE(BDF_FONTCACHE_VERSION); cacheFile.writeUint16BE(data.maxAdvance); cacheFile.writeByte(data.height); cacheFile.writeByte(data.defaultBox.width); cacheFile.writeByte(data.defaultBox.height); cacheFile.writeSByte(data.defaultBox.xOffset); cacheFile.writeSByte(data.defaultBox.yOffset); cacheFile.writeByte(data.ascent); cacheFile.writeUint16BE(data.firstCharacter); cacheFile.writeSint16BE(data.defaultCharacter); cacheFile.writeUint16BE(data.numCharacters); for (int i = 0; i < data.numCharacters; ++i) { const BdfBoundingBox &box = data.boxes ? data.boxes[i] : data.defaultBox; if (data.bitmaps[i]) { const int bytes = ((box.width + 7) / 8) * box.height; cacheFile.writeUint32BE(bytes); cacheFile.write(data.bitmaps[i], bytes); } else { cacheFile.writeUint32BE(0); } } if (data.advances) { cacheFile.writeByte(0xFF); cacheFile.write(data.advances, data.numCharacters); } else { cacheFile.writeByte(0x00); } if (data.boxes) { cacheFile.writeByte(0xFF); for (int i = 0; i < data.numCharacters; ++i) { const BdfBoundingBox &box = data.boxes[i]; cacheFile.writeByte(box.width); cacheFile.writeByte(box.height); cacheFile.writeSByte(box.xOffset); cacheFile.writeSByte(box.yOffset); } } else { cacheFile.writeByte(0x00); } return !cacheFile.err(); }
bool NewFont::cacheFontData(const NewFont &font, const Common::String &filename) { Common::DumpFile cacheFile; if (!cacheFile.open(filename)) { warning("Couldn't open file '%s' for writing", filename.c_str()); return false; } cacheFile.writeUint16BE(font.desc.maxwidth); cacheFile.writeUint16BE(font.desc.height); cacheFile.writeUint16BE(font.desc.fbbw); cacheFile.writeUint16BE(font.desc.fbbh); cacheFile.writeSint16BE(font.desc.fbbx); cacheFile.writeSint16BE(font.desc.fbby); cacheFile.writeUint16BE(font.desc.ascent); cacheFile.writeUint16BE(font.desc.firstchar); cacheFile.writeUint16BE(font.desc.size); cacheFile.writeUint16BE(font.desc.defaultchar); cacheFile.writeUint32BE(font.desc.bits_size); for (long i = 0; i < font.desc.bits_size; ++i) { cacheFile.writeUint16BE(font.desc.bits[i]); } if (font.desc.offset) { cacheFile.writeByte(1); for (int i = 0; i < font.desc.size; ++i) { cacheFile.writeUint32BE(font.desc.offset[i]); } } else { cacheFile.writeByte(0); } if (font.desc.width) { cacheFile.writeByte(1); for (int i = 0; i < font.desc.size; ++i) { cacheFile.writeByte(font.desc.width[i]); } } else { cacheFile.writeByte(0); } if (font.desc.bbx) { cacheFile.writeByte(1); for (int i = 0; i < font.desc.size; ++i) { cacheFile.writeByte(font.desc.bbx[i].w); cacheFile.writeByte(font.desc.bbx[i].h); cacheFile.writeByte(font.desc.bbx[i].x); cacheFile.writeByte(font.desc.bbx[i].y); } } else { cacheFile.writeByte(0); } return !cacheFile.err(); }