summaryrefslogtreecommitdiff
path: root/src/fontcache_internal.h
diff options
context:
space:
mode:
authorMichael Lutz <michi@icosahedron.de>2021-02-13 17:34:22 +0100
committerMichael Lutz <michi@icosahedron.de>2021-02-13 20:09:14 +0100
commitc6af8f16f63d878371d1a823c12fbf21423505b5 (patch)
treebd0e33995d016b99d39187f2da04ccbee847504f /src/fontcache_internal.h
parent5ad16409847a17534389054a1b7f5fb83703fb4d (diff)
downloadopenttd-c6af8f16f63d878371d1a823c12fbf21423505b5.tar.xz
Codechange: [Win32] Move Win32-specific font code to a seperate file.
Diffstat (limited to 'src/fontcache_internal.h')
-rw-r--r--src/fontcache_internal.h76
1 files changed, 76 insertions, 0 deletions
diff --git a/src/fontcache_internal.h b/src/fontcache_internal.h
new file mode 100644
index 000000000..09e676234
--- /dev/null
+++ b/src/fontcache_internal.h
@@ -0,0 +1,76 @@
+/*
+ * This file is part of OpenTTD.
+ * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
+ * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file fontcache_internal.h Support types and functions for platform-specific font support. */
+
+#ifndef FONTCACHE_INTERNAL_H
+#define FONTCACHE_INTERNAL_H
+
+#include "core/smallmap_type.hpp"
+#include "fontcache.h"
+
+
+static const int MAX_FONT_SIZE = 72; ///< Maximum font size.
+
+static const byte FACE_COLOUR = 1;
+static const byte SHADOW_COLOUR = 2;
+
+/** Font cache for fonts that are based on a TrueType font. */
+class TrueTypeFontCache : public FontCache {
+protected:
+ int req_size; ///< Requested font size.
+ int used_size; ///< Used font size.
+
+ typedef SmallMap<uint32, std::pair<size_t, const void *> > FontTable; ///< Table with font table cache
+ FontTable font_tables; ///< Cached font tables.
+
+ /** Container for information about a glyph. */
+ struct GlyphEntry {
+ Sprite *sprite; ///< The loaded sprite.
+ byte width; ///< The width of the glyph.
+ bool duplicate; ///< Whether this glyph entry is a duplicate, i.e. may this be freed?
+ };
+
+ /**
+ * The glyph cache. This is structured to reduce memory consumption.
+ * 1) There is a 'segment' table for each font size.
+ * 2) Each segment table is a discrete block of characters.
+ * 3) Each block contains 256 (aligned) characters sequential characters.
+ *
+ * The cache is accessed in the following way:
+ * For character 0x0041 ('A'): glyph_to_sprite[0x00][0x41]
+ * For character 0x20AC (Euro): glyph_to_sprite[0x20][0xAC]
+ *
+ * Currently only 256 segments are allocated, "limiting" us to 65536 characters.
+ * This can be simply changed in the two functions Get & SetGlyphPtr.
+ */
+ GlyphEntry **glyph_to_sprite;
+
+ GlyphEntry *GetGlyphPtr(GlyphID key);
+ void SetGlyphPtr(GlyphID key, const GlyphEntry *glyph, bool duplicate = false);
+
+ virtual const void *InternalGetFontTable(uint32 tag, size_t &length) = 0;
+ virtual const Sprite *InternalGetGlyph(GlyphID key, bool aa) = 0;
+
+public:
+ TrueTypeFontCache(FontSize fs, int pixels);
+ virtual ~TrueTypeFontCache();
+ int GetFontSize() const override { return this->used_size; }
+ SpriteID GetUnicodeGlyph(WChar key) override { return this->parent->GetUnicodeGlyph(key); }
+ void SetUnicodeGlyph(WChar key, SpriteID sprite) override { this->parent->SetUnicodeGlyph(key, sprite); }
+ void InitializeUnicodeGlyphMap() override { this->parent->InitializeUnicodeGlyphMap(); }
+ const Sprite *GetGlyph(GlyphID key) override;
+ const void *GetFontTable(uint32 tag, size_t &length) override;
+ void ClearFontCache() override;
+ uint GetGlyphWidth(GlyphID key) override;
+ bool GetDrawGlyphShadow() override;
+ bool IsBuiltInFont() override { return false; }
+};
+
+void *AllocateFont(size_t size);
+
+#endif /* FONTCACHE_INTERNAL_H */