ScummVM API documentation
maketext.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  * Additional copyright for this file:
8  * Copyright (C) 1994-1998 Revolution Software Ltd.
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef SWORD2_MAKETEXT_H
25 #define SWORD2_MAKETEXT_H
26 
27 #include "sword2/debug.h"
28 
29 namespace Sword2 {
30 
31 // Output color for character border - should be be black but note that we
32 // have to use a different pen number during sequences
33 
34 #define BORDER_PEN 194
35 
36 // Usually the only texts on screen are the subtitles and the mouse-over text,
37 // but there can also be a considerable number of debugging messages...
38 
39 #define MAX_text_blocs MAX_DEBUG_TEXTS + 1
40 
41 enum {
42  // Doesn't keep the text inside the screen - only for debug text!
43  NO_JUSTIFICATION = 0,
44 
45  // These all force text inside the screen edge margin when necessary
46  POSITION_AT_CENTER_OF_BASE = 1,
47  POSITION_AT_CENTER_OF_TOP = 2,
48  POSITION_AT_LEFT_OF_TOP = 3,
49  POSITION_AT_RIGHT_OF_TOP = 4,
50  POSITION_AT_LEFT_OF_BASE = 5,
51  POSITION_AT_RIGHT_OF_BASE = 6,
52  POSITION_AT_LEFT_OF_CENTER = 7,
53  POSITION_AT_RIGHT_OF_CENTER = 8,
54  POSITION_AT_CENTER_OF_CENTER = 9
55 };
56 
57 enum {
58  DEFAULT_TEXT = 0,
59  FINNISH_TEXT = 1,
60  POLISH_TEXT = 2
61 };
62 
63 // Info about the text, used to create the SpriteInfo struct
64 
65  struct TextBloc {
66  int16 x;
67  int16 y;
68  uint16 type;
69  byte *text_mem;
70 };
71 
72 // Info for each line of words in the output text sprite
73 
74 struct LineInfo {
75  uint16 width; // Width in pixels
76  uint16 length; // Length in characters
77  bool skipSpace; // Whether there is a trailing space
78 };
79 
80 class FontRenderer {
81 private:
82  Sword2Engine *_vm;
83  TextBloc _blocList[MAX_text_blocs];
84 
85  // Layout variables - these used to be defines, but now we're dealing
86  // with three character sets
87 
88  int8 _lineSpacing; // no. of pixels to separate lines of
89  // characters in the output sprite - negative
90  // for overlap
91  int8 _charSpacing; // no. of pixels to separate characters along
92  // each line - negative for overlap
93  uint8 _borderPen; // output pen color of character borders
94 
96  static const int kChineseWidth = 20;
97  static const int kChineseHeight = 26;
98  struct ChineseGlyph {
99  byte bitmap[kChineseWidth * kChineseHeight];
100  };
101  Common::Array<ChineseGlyph> _chineseFont;
102 
103  uint16 analyzeSentence(const byte *sentence, uint16 maxWidth, uint32 fontRes, LineInfo *line, bool isChinese);
104  byte *buildTextSprite(const byte *sentence, uint32 fontRes, uint8 pen, LineInfo *line, uint16 noOfLines, bool isChinese);
105  uint16 charWidth(byte ch, uint32 fontRes);
106  uint16 wcharWidth(byte hi, byte lo, uint32 fontRes);
107  uint16 charHeight(uint32 fontRes);
108  byte *findChar(byte ch, byte *charSet);
109  byte *findWChar(byte hi, byte lo, byte *charSet);
110  void copyChar(const byte *charPtr, byte *spritePtr, uint16 spriteWidth, uint8 pen);
111  void copyWChar(const byte *charPtr, byte *spritePtr, uint16 spriteWidth, uint8 pen);
112  void copyCharRaw(const byte *source, uint16 charWidth, uint16 charHeight, byte *spritePtr, uint16 spriteWidth, uint8 pen);
113  bool isKoreanChar(const byte hi, const byte lo, const uint32 fontRes);
114 
115 public:
116  FontRenderer(Sword2Engine *vm) : _vm(vm) {
117  for (int i = 0; i < MAX_text_blocs; i++)
118  _blocList[i].text_mem = nullptr;
119  }
120 
121  ~FontRenderer() {
122  for (int i = 0; i < MAX_text_blocs; i++)
123  free(_blocList[i].text_mem);
124  }
125 
126  byte *makeTextSprite(const byte *sentence, uint16 maxWidth, uint8 pen, uint32 fontRes, uint8 border = BORDER_PEN);
127 
128  void killTextBloc(uint32 bloc_number);
129  void printTextBlocs();
130 
131  uint32 buildNewBloc(byte *ascii, int16 x, int16 y, uint16 width, uint8 pen, uint32 type, uint32 fontRes, uint8 justification);
132 
133  void loadTranslations();
134 };
135 
136 } // End of namespace Sword2
137 
138 #endif
Definition: maketext.h:74
Definition: animation.h:37
Definition: maketext.h:65
Definition: sword2.h:99
Definition: maketext.h:80