aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--graphics/fonts/ttf.cpp19
-rw-r--r--graphics/fonts/ttf.h19
2 files changed, 38 insertions, 0 deletions
diff --git a/graphics/fonts/ttf.cpp b/graphics/fonts/ttf.cpp
index 76b7f731be..0b7ae50e41 100644
--- a/graphics/fonts/ttf.cpp
+++ b/graphics/fonts/ttf.cpp
@@ -31,11 +31,13 @@
#include "graphics/font.h"
#include "graphics/surface.h"
+#include "common/file.h"
#include "common/singleton.h"
#include "common/stream.h"
#include "common/memstream.h"
#include "common/hashmap.h"
#include "common/ptr.h"
+#include "common/unzip.h"
#include <ft2build.h>
#include FT_FREETYPE_H
@@ -666,6 +668,23 @@ Font *loadTTFFont(Common::SeekableReadStream &stream, int size, TTFSizeMode size
return font;
}
+Font *loadTTFFontFromArchive(const Common::String &filename, int size, TTFSizeMode sizeMode, uint dpi, TTFRenderMode renderMode, const uint32 *mapping) {
+ Common::Archive *archive;
+ if (!Common::File::exists("fonts.dat") || (archive = Common::makeZipArchive("fonts.dat")) == nullptr) {
+ return 0;
+ }
+
+ Common::File f;
+ if (!f.open(filename, *archive)) {
+ return 0;
+ }
+
+ Font *font = loadTTFFont(f, size, sizeMode, dpi, renderMode, mapping);
+
+ delete archive;
+ return font;
+}
+
} // End of namespace Graphics
namespace Common {
diff --git a/graphics/fonts/ttf.h b/graphics/fonts/ttf.h
index 4110486357..26a93a163f 100644
--- a/graphics/fonts/ttf.h
+++ b/graphics/fonts/ttf.h
@@ -95,6 +95,25 @@ enum TTFSizeMode {
*/
Font *loadTTFFont(Common::SeekableReadStream &stream, int size, TTFSizeMode sizeMode = kTTFSizeModeCharacter, uint dpi = 0, TTFRenderMode renderMode = kTTFRenderModeLight, const uint32 *mapping = 0);
+/**
+ * Loads a TTF font file from the common fonts archive.
+ *
+ * @param filename The name of the font to load.
+ * @param size The point size to load.
+ * @param sizeMode The point size definition used for the size parameter.
+ * @param dpi The dpi to use for size calculations, by default 72dpi
+ * are used.
+ * @param renderMode FreeType2 mode used to render glyphs. @see TTFRenderMode
+ * @param mapping A mapping from code points 0-255 into UTF-32 code points.
+ * This can be used to support various 8bit character sets.
+ * In case the msb of the UTF-32 code point is set the font
+ * loading fails in case no glyph for it is found. When this
+ * is non-null only characters given in the mapping are
+ * supported.
+ * @return 0 in case loading fails, otherwise a pointer to the Font object.
+ */
+Font *loadTTFFontFromArchive(const Common::String &filename, int size, TTFSizeMode sizeMode = kTTFSizeModeCharacter, uint dpi = 0, TTFRenderMode renderMode = kTTFRenderModeLight, const uint32 *mapping = 0);
+
void shutdownTTF();
} // End of namespace Graphics