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 
32 namespace Graphics {
33 class Font;
34 }
35 
36 namespace Scumm {
37 
38 class ScummEngine;
39 class NutRenderer;
40 struct VirtScreen;
41 
42 static 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 
54 static inline bool checkSJISCode(byte c) {
55  if ((c >= 0x80 && c <= 0x9f) || (c >= 0xe0 && c <= 0xfd))
56  return true;
57  return false;
58 }
59 
60 static 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 
71 public:
72 
73  Common::Rect _str;
74 
75  int _top;
76  int _left, _startLeft;
77  int _right;
78 
79 protected:
80  byte _color;
81 
82 public:
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 
92 protected:
93  ScummEngine *_vm;
94  int32 _curId;
95 
96 public:
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 #ifdef USE_TTS
120  virtual Common::U32String convertText(const Common::String &text, Common::Language language) const { return Common::U32String(text, _vm->getDialogCodePage()); }
121 #endif
122 };
123 
125 public:
126  enum ShadowType {
127  kNoShadowType,
128  kNormalShadowType,
129  kHorizontalShadowType,
130  kOutlineShadowType
131  };
132 
134 
135  void setCurID(int32 id) override;
136 
137  int getFontHeight() const override;
138 
139 protected:
140  const byte *_fontPtr;
141  int _bitsPerPixel;
142  int _fontHeight;
143  int _numChars;
144 
145  byte _shadowColor;
146  ShadowType _shadowType;
147 };
148 
150 public:
152 
153 protected:
154  virtual void setShadowMode(ShadowType mode);
155  virtual void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height);
156  void drawBits1Kor(Graphics::Surface &dest, int x1, int y1, const byte *src, int drawTop, int width, int height);
157 };
158 
160 protected:
161  virtual void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height);
162  void printCharIntern(bool is2byte, const byte *charPtr, int origWidth, int origHeight, int width, int height, VirtScreen *vs, bool ignoreCharsetMask);
163  virtual bool prepareDraw(uint16 chr);
164 
165  int _width, _height, _origWidth, _origHeight;
166  int _cjkSpacing;
167  int _offsX, _offsY;
168  const byte *_charPtr;
169 
170  // On which virtual screen will be drawn right now
171  VirtScreenNumber _drawScreen;
172 
173 public:
174  CharsetRendererClassic(ScummEngine *vm, int cjkSpacing) : CharsetRendererPC(vm), _width(0), _height(0), _origWidth(0), _origHeight(0),
175  _cjkSpacing(cjkSpacing), _offsX(0), _offsY(0), _charPtr(nullptr), _drawScreen(kMainVirtScreen) {}
176  CharsetRendererClassic(ScummEngine *vm) : CharsetRendererClassic(vm, vm->_game.id == GID_INDY4 &&
177  (vm->_game.platform == Common::kPlatformMacintosh || vm->_game.platform == Common::kPlatformDOS) &&
178  vm->_language == Common::JA_JPN ? -3 : 0) {}
179 
180  void printChar(int chr, bool ignoreCharsetMask) override;
181  void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
182 
183  int getCharWidth(uint16 chr) const override;
184 };
185 
186 #ifdef USE_RGB_COLOR
187 #ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
188 class CharsetRendererTownsClassic : public CharsetRendererClassic {
189 public:
190  CharsetRendererTownsClassic(ScummEngine *vm);
191 
192  int getCharWidth(uint16 chr) const override;
193  int getFontHeight() const override;
194 
195 private:
196  void drawBitsN(const Graphics::Surface &s, byte *dst, const byte *src, byte bpp, int drawTop, int width, int height) override;
197  bool prepareDraw(uint16 chr) override;
198  void setupShadowMode();
199  bool useFontRomCharacter(uint16 chr) const;
200  void processCharsetColors();
201 
202  uint16 _sjisCurChar;
203 };
204 #endif
205 #endif
206 
208 protected:
209  byte *_trTable = nullptr;
210 
211  void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height);
212 
213 public:
215 
216  void setCurID(int32 id) override {}
217  void printChar(int chr, bool ignoreCharsetMask) override;
218  void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
219 
220  int getFontHeight() const override { return 8; }
221  int getCharWidth(uint16 chr) const override { return 8; }
222 };
223 
225 protected:
226  virtual int getDrawWidthIntern(uint16 chr);
227  virtual int getDrawHeightIntern(uint16 chr);
228  virtual void setDrawCharIntern(uint16 chr) {}
229 
230  const byte *_widthTable = nullptr;
231 
232 public:
234 
235  void printChar(int chr, bool ignoreCharsetMask) override;
236  void drawChar(int chr, Graphics::Surface &s, int x, int y) override;
237  void setCurID(int32 id) override;
238  void setColor(byte color, bool shadowModeSpecialFlag) override;
239  int getCharWidth(uint16 chr) const override;
240 };
241 
243 public:
245 
246  int getCharWidth(uint16 chr) const override;
247  int getFontHeight() const override;
248 
249 private:
250  void setShadowMode(ShadowType mode) override;
251  void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height) override;
252 #ifndef DISABLE_TOWNS_DUAL_LAYER_MODE
253  int getDrawWidthIntern(uint16 chr) override;
254  int getDrawHeightIntern(uint16 chr) override;
255  void setDrawCharIntern(uint16 chr) override;
256 #endif
257  uint16 _sjisCurChar;
258 };
259 
260 #ifdef USE_RGB_COLOR
261 class CharsetRendererPCE : public CharsetRendererV3 {
262 private:
263  void drawBits1(Graphics::Surface &dest, int x, int y, const byte *src, int drawTop, int width, int height) override;
264 
265  int getDrawWidthIntern(uint16 chr) override;
266  int getDrawHeightIntern(uint16 chr) override;
267  void setDrawCharIntern(uint16 chr) override;
268 
269  uint16 _sjisCurChar;
270 
271 public:
272  CharsetRendererPCE(ScummEngine *vm) : CharsetRendererV3(vm), _sjisCurChar(0) {}
273 
274  void setColor(byte color, bool) override;
275 };
276 #endif
277 
279 protected:
280  bool _deleteFontPtr;
281 
282 public:
284  ~CharsetRendererV2() override;
285 
286  void setCurID(int32 id) override {}
287  int getCharWidth(uint16 chr) const override { return 8; }
288 
289 #ifdef USE_TTS
290  Common::U32String convertText(const Common::String &text, Common::Language language) const override;
291 #endif
292 };
293 
295 protected:
296  const Graphics::Font *_font = nullptr;
297  bool _useCorrectFontSpacing;
298  bool _pad;
299  int _lastTop;
300 
301  int getDrawWidthIntern(uint16 chr) const;
302  void printCharInternal(int chr, int color, bool shadow, int x, int y);
303 
304  byte getTextColor();
305  byte getTextShadowColor();
306 
307  Graphics::Surface *_glyphSurface;
308 
309 public:
310  CharsetRendererMac(ScummEngine *vm, const Common::Path &fontFile);
311  ~CharsetRendererMac() override;
312 
313  void setCurID(int32 id) override;
314 
315  int getStringWidth(int arg, const byte *text) override;
316  int getFontHeight() const override;
317  int getCharWidth(uint16 chr) const override;
318  void printChar(int chr, bool ignoreCharsetMask) override;
319  void setColor(byte color, bool) override;
320 };
321 
322 #ifdef ENABLE_SCUMM_7_8
323 class CharsetRendererV7 : public CharsetRendererClassic, public GlyphRenderer_v7 {
324 public:
325  CharsetRendererV7(ScummEngine *vm);
326  ~CharsetRendererV7() override {};
327 
328  void printChar(int, bool) override { error("CharsetRendererV7::printChar(): Unexpected call to deprecated function"); }
329 
330  int draw2byte(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, uint16 chr) override;
331  int drawCharV7(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, TextStyleFlags flags, byte chr) override;
332  int getCharWidth(uint16 chr) const override;
333  int getCharHeight(uint16 chr) const override { return ((chr & 0x80) && _vm->_useCJKMode) ? _vm->_2byteHeight : _fontHeight; }
334  int getFontHeight() const override { return _fontHeight; }
335  int setFont(int) override { return 0; }
336  bool newStyleWrapping() const override { return _newStyle; }
337 private:
338  const bool _newStyle;
339  const int _direction;
340 };
341 
342 class CharsetRendererNut : public CharsetRenderer, public GlyphRenderer_v7 {
343 public:
344  CharsetRendererNut(ScummEngine *vm);
345  ~CharsetRendererNut() override;
346 
347  void printChar(int, bool) override { error("CharsetRendererNut::printChar(): Unexpected call to deprecated function"); }
348 
349  void setCurID(int32 id) override;
350  int setFont(int id) override;
351  bool newStyleWrapping() const override { return true; }
352 
353  int draw2byte(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, uint16 chr) override;
354  int drawCharV7(byte *buffer, Common::Rect &clipRect, int x, int y, int pitch, int16 col, TextStyleFlags flags, byte chr) override;
355 
356  int getFontHeight() const override;
357  int getCharWidth(uint16 chr) const override;
358  int getCharHeight(uint16 chr) const override;
359 
360 private:
361  NutRenderer *_fr[5];
362  NutRenderer *_current;
363 };
364 #endif
365 
366 } // End of namespace Scumm
367 
368 
369 #endif
Definition: charset.h:70
VirtScreenNumber
Definition: gfx.h:161
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
Definition: charset.h:149
byte id
Definition: detection.h:77
Definition: rect.h:524
Definition: path.h:52
Common::Platform platform
Definition: detection.h:99
Definition: charset.h:294
Definition: serializer.h:79
Definition: scumm.h:508
Definition: gfx.h:185
Definition: ustr.h:57
Definition: charset.h:278
Definition: formatinfo.h:28
Definition: charset.h:124
Definition: charset.h:159
void NORETURN_PRE error(MSVC_PRINTF const char *s,...) GCC_PRINTF(1
Definition: charset.h:242
Definition: charset.h:207
Definition: charset.h:224
Definition: actor.h:30
Language
Definition: language.h:45