ScummVM API documentation
font.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef DGDS_FONT_H
23#define DGDS_FONT_H
24
25#include "common/scummsys.h"
26#include "common/hashmap.h"
27#include "common/func.h"
28#include "graphics/font.h"
29
30#include "dgds/dgds.h"
31
32namespace Graphics {
33class Font;
34struct Surface;
35}
36
37namespace Common {
38class SeekableReadStream;
39}
40
41namespace Dgds {
42
43class ResourceManager;
44class Decompressor;
45
46class DgdsFont : public Graphics::Font {
47public:
48 DgdsFont(byte w, byte h, byte start, byte count, const byte *glyphs);
49 virtual ~DgdsFont();
50 virtual int getFontHeight() const override { return _h; }
51 virtual int getMaxCharWidth() const override { return _w; }
52 virtual int getCharWidth(uint32 chr) const override = 0;
53 static DgdsFont *load(const Common::String &filename, ResourceManager *resourceManager, Decompressor *decompressor);
54
55protected:
56 byte _w;
57 byte _h;
58 byte _start;
59 byte _count;
60 const byte *_glyphs;
61
62 void drawDgdsChar(Graphics::Surface* dst, int pos, int x, int y, int w, uint32 color) const;
63 bool hasChar(byte chr) const;
64 virtual int charOffset(byte chr) const = 0;
65};
66
67/* Proportional font (each char has its own width and so data is a different size) */
68class PFont : public DgdsFont {
69public:
70 PFont(byte w, byte h, byte start, byte count, byte *data);
71 ~PFont();
72 int getCharWidth(uint32 chr) const override;
73 void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
74 static PFont *load(Common::SeekableReadStream &input, Decompressor *decompressor);
75
76protected:
77 const uint16 *_offsets;
78 const byte *_widths;
79 byte *_rawData;
80
81 int charOffset(byte chr) const override;
82};
83
84/* Fixed-width font */
85class FFont : public DgdsFont {
86public:
87 FFont(byte w, byte h, byte start, byte count, byte *data);
88 ~FFont();
89 int getCharWidth(uint32 chr) const override { return _w; }
90 void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
91 static FFont *load(Common::SeekableReadStream &input);
92
93protected:
94 byte *_rawData;
95
96 int charOffset(byte chr) const override;
97};
98
100public:
101 enum FontType {
102 kDefaultFont = 0,
103 k8x8Font,
104 k6x6Font,
105 k4x5Font,
106 kGameFont, // DRAGON for Rise of the Dragon, WILLY for Willy Beamish, HOC for Heart of China.
107 kGameDlgFont, // P6x6 for Rise of the Dragon, COMIX_16 for Willy Beamish, CHINESE for Heart of China
108 k7x8Font, // Rise of the Dragon only
109 kVCRFont, // Willy Beamish only
110 kChinaFont, // Heart of China only
111 };
112
113 FontManager() {}
114 ~FontManager();
115
116 const DgdsFont *getFont(FontType) const;
117 FontType fontTypeByName(const Common::String &filename) const;
118 void loadFonts(DgdsGameId gameId, ResourceManager *resourceManager, Decompressor *decompressor);
119
120private:
121 void tryLoadFont(const char *filename, ResourceManager *resourceManager, Decompressor *decompressor);
122
123 struct FontTypeHash {
125
126 uint operator()(FontType val) const {
127 return (uint)val;
128 }
129 };
130
132};
133
134} // End of namespace Dgds
135
136
137#endif // DGDS_FONT_H
Definition: hashmap.h:85
Definition: stream.h:745
Definition: str.h:59
Definition: decompress.h:67
Definition: font.h:46
virtual int getCharWidth(uint32 chr) const override=0
virtual int getFontHeight() const override
Definition: font.h:50
virtual int getMaxCharWidth() const override
Definition: font.h:51
Definition: font.h:85
int getCharWidth(uint32 chr) const override
Definition: font.h:89
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override
Definition: font.h:99
Definition: font.h:68
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override
int getCharWidth(uint32 chr) const override
Definition: resource.h:48
Definition: font.h:83
Definition: algorithm.h:29
Definition: formatinfo.h:28
Definition: hash-str.h:74
Definition: surface.h:67