ScummVM API documentation
charset.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 SCUMM_CHARSET_H
23#define SCUMM_CHARSET_H
24
25#include "common/scummsys.h"
26#include "common/rect.h"
27#include "graphics/sjis.h"
28#include "scumm/charset_v7.h"
29#include "scumm/scumm.h"
30#include "scumm/gfx.h"
31
32namespace Graphics {
33class Font;
34}
35
36namespace Scumm {
37
38class ScummEngine;
39class NutRenderer;
40struct VirtScreen;
41
42static inline bool checkKSCode(byte hi, byte lo) {
43 //hi : xx
44 //lo : yy
45 if ((0xA1 > lo) || (0xFE < lo)) {
46 return false;
47 }
48 if ((hi >= 0xB0) && (hi <= 0xC8)) {
49 return true;
50 }
51 return false;
52}
53
54static inline bool checkSJISCode(byte c) {
55 if ((c >= 0x80 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfd))
56 return true;
57 return false;
58}
59
60static inline bool is2ByteCharacter(Common::Language lang, byte c) {
61 if (lang == Common::JA_JPN)
62 return (c >= 0x80 && c <= 0x9F) || (c >= 0xE0 && c <= 0xFD);
63 else if (lang == Common::KO_KOR)
64 return (c >= 0xB0 && c <= 0xD0);
65 else if (lang == Common::ZH_TWN || lang == Common::ZH_CHN)
66 return (c >= 0x80);
67 return false;
68}
69
71public:
72
73 Common::Rect _str;
74
75 int _top;
76 int _left, _startLeft;
77 int _right;
78
79protected:
80 byte _color;
81
82public:
83 bool _center;
84
85 bool _hasMask; // True if "removable" text is visible somewhere (should be called _hasText or so)
86 VirtScreenNumber _textScreenID; // ID of the virtual screen on which the text is visible.
87
88 bool _blitAlso;
89 bool _firstChar;
90 bool _disableOffsX;
91
92protected:
93 ScummEngine *_vm;
94 int32 _curId;
95
96public:
98 virtual ~CharsetRenderer();
99
100 virtual void printChar(int chr, bool ignoreCharsetMask) = 0;
101 virtual void drawChar(int chr, Graphics::Surface &s, int x, int y) {}
102
103 virtual int getStringWidth(int arg, const byte *text);
104 void addLinebreaks(int a, byte *str, int pos, int maxwidth);
105 void translateColor();
106
107 virtual void setCurID(int32 id) = 0;
108 int getCurID() { return _curId; }
109
110 virtual int getFontHeight() const = 0;
111 virtual int getCharHeight(uint16 chr) const { return getFontHeight(); }
112 virtual int getCharWidth(uint16 chr) const = 0;
113
114 virtual void setColor(byte color, bool shadowModeSpecialFlag = false) { _color = color; translateColor(); }
115 virtual byte getColor() { return _color; }
116
117 void saveLoadWithSerializer(Common::Serializer &ser);
118
119 virtual Common::U32String convertText(const Common::String &text, Common::Language language) const { return Common::U32String(text, _vm->getDialogCodePage()); }
120};
121
123public:
124 enum ShadowType {
125 kNoShadowType,
126 kNormalShadowType,
127 kHorizontalShadowType,
128 kOutlineShadowType
129 };
130
132
133 void setCurID(int32 id) override;
134
135 int getFontHeight() const override;
136
137protected:
138 const byte *_fontPtr;
139 int _bitsPerPixel;
140 int _fontHeight;
141 int _numChars;
142
143 byte _shadowColor;
144 ShadowType _shadowType;
145};
146
148public:
150
151protected:
152 virtual void setShadowMode(ShadowType mode);
153 virtual void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height);
154 void drawBits1Kor(Graphics::Surface &dest, int x1, int y1, const byte *src, int drawTop, int width, int height);
155};
156
158protected:
159 virtual void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height);
160 void printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask);
161 virtual bool prepareDraw(uint16 chr);
162
163 int _width, _height, _origWidth, _origHeight;
164 int _cjkSpacing;
165 int _offsX, _offsY;
166 const byte *_charPtr;
167
168 // On which virtual screen will be drawn right now
169 VirtScreenNumber _drawScreen;
170
171public:
172 CharsetRendererClassic(ScummEngine *vm, int cjkSpacing) : CharsetRendererPC(vm), _width(0), _height(0), _origWidth(0), _origHeight(0),
173 _cjkSpacing(cjkSpacing), _offsX(0), _offsY(0), _charPtr(nullptr), _drawScreen(kMainVirtScreen) {}
174 CharsetRendererClassic(ScummEngine *vm) : CharsetRendererClassic(vm, vm->_game.id == GID_INDY4 &&
175 (vm->_game.platform == Common::kPlatformMacintosh || vm->_game.platform == Common::kPlatformDOS) &&
176 vm->_language == Common::JA_JPN ? -3 : 0) {}
177
178 void printChar(int chr, bool ignoreCharsetMask) override;
179 void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
180
181 int getCharWidth(uint16 chr) const override;
182};
183
184#ifdef USE_RGB_COLOR
185#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
186class CharsetRendererTownsClassic : public CharsetRendererClassic {
187public:
188 CharsetRendererTownsClassic(ScummEngine *vm);
189
190 int getCharWidth(uint16 chr) const override;
191 int getFontHeight() const override;
192
193private:
194 void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) override;
195 bool prepareDraw(uint16 chr) override;
196 void setupShadowMode();
197 bool useFontRomCharacter(uint16 chr) const;
198 void processCharsetColors();
199
200 uint16 _sjisCurChar;
201};
202#endif
203#endif
204
206protected:
207 byte *_trTable = nullptr;
208
209 void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height);
210
211public:
213
214 void setCurID(int32 id) override {}
215 void printChar(int chr, bool ignoreCharsetMask) override;
216 void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
217
218 int getFontHeight() const override { return 8; }
219 int getCharWidth(uint16 chr) const override { return 8; }
220};
221
223protected:
224 virtual int getDrawWidthIntern(uint16 chr);
225 virtual int getDrawHeightIntern(uint16 chr);
226 virtual void setDrawCharIntern(uint16 chr) {}
227
228 const byte *_widthTable = nullptr;
229
230public:
232
233 void printChar(int chr, bool ignoreCharsetMask) override;
234 void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
235 void setCurID(int32 id) override;
236 void setColor(byte color, bool shadowModeSpecialFlag) override;
237 int getCharWidth(uint16 chr) const override;
238};
239
241public:
243
244 int getCharWidth(uint16 chr) const override;
245 int getFontHeight() const override;
246
247private:
248 void setShadowMode(ShadowType mode) override;
249 void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height) override;
250#ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
251 int getDrawWidthIntern(uint16 chr) override;
252 int getDrawHeightIntern(uint16 chr) override;
253 void setDrawCharIntern(uint16 chr) override;
254#endif
255 uint16 _sjisCurChar;
256};
257
258#ifdef USE_RGB_COLOR
259class CharsetRendererPCE : public CharsetRendererV3 {
260private:
261 void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height) override;
262
263 int getDrawWidthIntern(uint16 chr) override;
264 int getDrawHeightIntern(uint16 chr) override;
265 void setDrawCharIntern(uint16 chr) override;
266
267 uint16 _sjisCurChar;
268
269public:
270 CharsetRendererPCE(ScummEngine *vm) : CharsetRendererV3(vm), _sjisCurChar(0) {}
271
272 void setColor(byte color, bool) override;
273};
274#endif
275
277protected:
278 bool _deleteFontPtr;
279
280public:
282 ~CharsetRendererV2() override;
283
284 void setCurID(int32 id) override {}
285 int getCharWidth(uint16 chr) const override { return 8; }
286
287 Common::U32String convertText(const Common::String &text, Common::Language language) const override;
288};
289
291protected:
292 const Graphics::Font *_font = nullptr;
293 bool _useCorrectFontSpacing;
294 bool _pad;
295 int _lastTop;
296
297 int getDrawWidthIntern(uint16 chr) const;
298 void printCharInternal(int chr, int color, bool shadow, int x, int y);
299
300 byte getTextColor();
301 byte getTextShadowColor();
302
303 Graphics::Surface *_glyphSurface;
304
305public:
306 CharsetRendererMac(ScummEngine *vm, const Common::Path &fontFile);
307 ~CharsetRendererMac() override;
308
309 void setCurID(int32 id) override;
310
311 int getStringWidth(int arg, const byte *text) override;
312 int getFontHeight() const override;
313 int getCharWidth(uint16 chr) const override;
314 void printChar(int chr, bool ignoreCharsetMask) override;
315 void setColor(byte color, bool) override;
316};
317
318#ifdef ENABLE_SCUMM_7_8
319class CharsetRendererV7 : public CharsetRendererClassic, public GlyphRenderer_v7 {
320public:
321 CharsetRendererV7(ScummEngine *vm);
322 ~CharsetRendererV7() override {};
323
324 void printChar(int, bool) override { error("CharsetRendererV7::printChar(): Unexpected call to deprecated function"); }
325
326 int draw2byte(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, uint16 chr) override;
327 int drawCharV7(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, TextStyleFlags flags, byte chr) override;
328 int getCharWidth(uint16 chr) const override;
329 int getCharHeight(uint16 chr) const override { return ((chr & 0x80) && _vm->_useCJKMode) ? _vm->_2byteHeight : _fontHeight; }
330 int getFontHeight() const override { return _fontHeight; }
331 int setFont(int) override { return 0; }
332 bool newStyleWrapping() const override { return _newStyle; }
333private:
334 const bool _newStyle;
335 const int _direction;
336};
337
338class CharsetRendererNut : public CharsetRenderer, public GlyphRenderer_v7 {
339public:
340 CharsetRendererNut(ScummEngine *vm);
341 ~CharsetRendererNut() override;
342
343 void printChar(int, bool) override { error("CharsetRendererNut::printChar(): Unexpected call to deprecated function"); }
344
345 void setCurID(int32 id) override;
346 int setFont(int id) override;
347 bool newStyleWrapping() const override { return true; }
348
349 int draw2byte(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, uint16 chr) override;
350 int drawCharV7(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, TextStyleFlags flags, byte chr) override;
351
352 int getFontHeight() const override;
353 int getCharWidth(uint16 chr) const override;
354 int getCharHeight(uint16 chr) const override;
355
356private:
357 NutRenderer *_fr[5];
358 NutRenderer *_current;
359};
360#endif
361
362} // End of namespace Scumm
363
364
365#endif
Definition: path.h:52
Definition: serializer.h:80
Definition: str.h:59
Definition: ustr.h:57
Definition: font.h:83
Definition: charset.h:157
Definition: charset.h:122
Definition: charset.h:70
Definition: charset.h:290
Definition: charset.h:205
Definition: charset.h:147
Definition: charset.h:240
Definition: charset.h:276
Definition: charset.h:222
Definition: scumm.h:536
Language
Definition: language.h:45
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: formatinfo.h:28
Definition: actor.h:30
VirtScreenNumber
Definition: gfx.h:161
Definition: rect.h:536
Definition: surface.h:67
Common::Platform platform
Definition: detection.h:110
byte id
Definition: detection.h:88
Definition: gfx.h:185