ScummVM API documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
sjis.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 // The code in this file is currently used in KYRA, SCI, SCUMM, SAGA,
23 // and AGOS. If none of those are enabled, we will skip compiling it.
24 // We also enable this code for ScummVM builds including support
25 // for dynamic engine plugins.
26 // If you plan to use this code in another engine, you will have
27 // to add the proper define check here.
28 #if !(defined(ENABLE_KYRA) || defined(ENABLE_SCI) || defined(ENABLE_SCUMM) || defined(ENABLE_SAGA) || defined(ENABLE_AGOS) || defined(DYNAMIC_MODULES))
29 
30 // If neither of the above mentioned is enabled, do not include the SJIS code.
31 
32 #else
33 
34 #ifndef GRAPHICS_SJIS_H
35 #define GRAPHICS_SJIS_H
36 
37 #ifdef __DS__
38 /* This disables the flipped mode which is used in FM-Towns versions
39  * of Monkey Island 1 (and maybe other SCUMM 5 games). These are not supported
40  * on the DS, so it makes sense to have a corresponding setting here.
41  */
42 #define DISABLE_FLIPPED_MODE
43 #endif
44 
45 #include "common/scummsys.h"
46 #include "common/platform.h"
47 
48 namespace Graphics {
49 
59 struct Surface;
60 
64 class FontSJIS {
65 public:
66  virtual ~FontSJIS() {}
67 
79  static FontSJIS *createFont(const Common::Platform platform = Common::kPlatformUnknown);
80 
84  virtual bool loadData() = 0;
85 
92  enum DrawingMode {
93  kDefaultMode,
94  kOutlineMode,
95  kShadowRightMode,
96  kShadowLeftMode,
97  kFMTownsShadowMode
98  };
99 
100  virtual void setDrawingMode(DrawingMode mode) {}
101 
105  virtual void toggleFatPrint(bool enable) {}
106 
110  virtual void toggleFlippedMode(bool enable) {}
111 
115  virtual void setCharSpacing(int spacing) {}
116  virtual void setLineSpacing(int spacing) {}
117 
121  virtual uint getFontHeight() const = 0;
122 
126  virtual uint getMaxFontWidth() const = 0;
127 
131  virtual uint getCharWidth(uint16 ch) const = 0;
132 
136  void drawChar(Graphics::Surface &dst, uint16 ch, int x, int y, uint32 c1, uint32 c2) const;
137 
150  virtual void drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, uint32 c2, int maxW, int maxH) const = 0;
151 };
152 
156 class FontSJISBase : public FontSJIS {
157 public:
158  FontSJISBase();
159 
160  virtual void setDrawingMode(DrawingMode mode);
161 
162  virtual void toggleFlippedMode(bool enable);
163 
164  virtual void toggleFatPrint(bool enable);
165 
166  virtual uint getFontHeight() const;
167 
168  virtual uint getMaxFontWidth() const;
169 
170  virtual uint getCharWidth(uint16 ch) const;
171 
172  virtual void drawChar(void *dst, uint16 ch, int pitch, int bpp, uint32 c1, uint32 c2, int maxW, int maxH) const;
173 private:
174  template<typename Color>
175  void blitCharacter(const uint8 *glyph, const int w, const int h, uint8 *dst, int pitch, Color c) const;
176  void createOutline(uint8 *outline, const uint8 *glyph, const int w, const int h) const;
177 
178 #ifndef DISABLE_FLIPPED_MODE
179  // This is used in the FM-Towns version of Monkey Island 1
180  // when Guybrush gets shot out of the cannon in the circus tent.
181  const uint8 *flipCharacter(const uint8 *glyph, const int w) const;
182  mutable uint8 _tempGlyph[32];
183 #endif
184  const uint8 *makeFatCharacter(const uint8 *glyph, const int w) const;
185  mutable uint8 _tempGlyph2[32];
186 protected:
187  DrawingMode _drawMode;
188  bool _flippedMode, _fatPrint;
189  int _fontWidth, _fontHeight;
190  uint8 _bitPosNewLineMask;
191 
192  bool isASCII(uint16 ch) const;
193 
194  virtual const uint8 *getCharData(uint16 c) const = 0;
195 
196  enum DrawingFeature {
197  kFeatDefault = 1 << 0,
198  kFeatOutline = 1 << 1,
199  kFeatShadow = 1 << 2,
200  kFeatFMTownsShadow = 1 << 3,
201  kFeatFlipped = 1 << 4,
202  kFeatFatPrint = 1 << 5
203  };
204 
205  virtual bool hasFeature(int feat) const = 0;
206 };
207 
213 class FontTowns : public FontSJISBase {
214 public:
218  bool loadData();
219 
220  static int getCharFMTChunk(uint16 ch);
221 
222 private:
223  enum {
224  kFont16x16Chars = 7808,
225  kFont8x16Chars = 256
226  };
227 
228  uint8 _fontData16x16[kFont16x16Chars * 32];
229  uint8 _fontData8x16[kFont8x16Chars * 32];
230 
231  virtual const uint8 *getCharData(uint16 c) const;
232 
233  bool hasFeature(int feat) const;
234 };
235 
241 class FontPC98 : public FontSJISBase {
242 public:
246  bool loadData() override;
247 
251  bool loadBMPData();
252 
253 protected:
254  const uint8 *getCharData(uint16 c) const override;
255 
256 private:
257  enum {
258  kFont16x16Chars = 8831,
259  kFont8x16Chars = 256
260  };
261 
262  uint8 _fontData16x16[kFont16x16Chars * 32];
263  uint8 _fontData8x16[kFont8x16Chars * 16];
264 
265  bool hasFeature(int feat) const override;
266 };
267 
273 class FontPCEngine : public FontSJISBase {
274 public:
278  bool loadData();
279 private:
280  enum {
281  kFont12x12Chars = 3418
282  };
283 
284  uint8 _fontData12x12[kFont12x12Chars * 18];
285 
286  virtual const uint8 *getCharData(uint16 c) const;
287 
288  bool hasFeature(int feat) const;
289 };
290 
294 class FontSjisSVM : public FontSJISBase {
295 public:
296  FontSjisSVM(const Common::Platform platform);
297  ~FontSjisSVM();
298 
302  bool loadData();
303 private:
304  uint8 *_fontData16x16;
305  uint _fontData16x16Size;
306 
307  uint8 *_fontData8x16;
308  uint _fontData8x16Size;
309 
310  uint8 *_fontData12x12;
311  uint _fontData12x12Size;
312 
313  virtual const uint8 *getCharData(uint16 c) const;
314 
315  bool hasFeature(int feat) const;
316 
317  const uint8 *getCharDataPCE(uint16 c) const;
318  const uint8 *getCharDataDefault(uint16 c) const;
319 
320  void mapKANJIChar(const uint8 fB, const uint8 sB, int &base, int &index) const;
321 
322  enum {
323  kSjisFontVersion = 3
324  };
325 };
326 
327 // TODO: Consider adding support for PC98 ROM
329 } // End of namespace Graphics
330 
331 #endif
332 
333 #endif // engine and dynamic plugins guard
Definition: surface.h:67
Definition: formatinfo.h:28
Platform
Definition: platform.h:46