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