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
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (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, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  *
22  */
23 
24 #ifndef ZVISION_TEXT_H
25 #define ZVISION_TEXT_H
26 
27 #include "zvision/text/truetype_font.h"
28 #include "zvision/zvision.h"
29 
30 namespace ZVision {
31 
32 class ZVision;
33 
34 enum TextJustification {
35 	TEXT_JUSTIFY_CENTER = 0,
36 	TEXT_JUSTIFY_LEFT = 1,
37 	TEXT_JUSTIFY_RIGHT = 2
38 };
39 
40 enum TextChange {
41 	TEXT_CHANGE_NONE = 0x0,
42 	TEXT_CHANGE_FONT_TYPE = 0x1,
43 	TEXT_CHANGE_FONT_STYLE = 0x2,
44 	TEXT_CHANGE_NEWLINE = 0x4,
45 	TEXT_CHANGE_HAS_STATE_BOX = 0x8
46 };
47 
48 class TextStyleState {
49 public:
50 	TextStyleState();
51 	TextChange parseStyle(const Common::String &str, int16 len);
52 	void readAllStyles(const Common::String &txt);
53 	void updateFontWithTextState(StyledTTFont &font);
54 
getTextColor(ZVision * engine)55 	uint32 getTextColor(ZVision *engine) {
56 		return engine->_resourcePixelFormat.RGBToColor(_red, _green, _blue);
57 	}
58 
59 public:
60 	Common::String _fontname;
61 	TextJustification _justification;
62 	int16 _size;
63 	uint8 _red;     // 0-255
64 	uint8 _green;   // 0-255
65 	uint8 _blue;    // 0-255
66 	bool _italic;
67 	bool _bold;
68 	bool _underline;
69 	bool _strikeout;
70 	int32 _statebox;
71 	bool _sharp;
72 };
73 
74 class TextRenderer {
75 public:
TextRenderer(ZVision * engine)76 	TextRenderer(ZVision *engine): _engine(engine) {};
77 
78 	void drawTextWithJustification(const Common::String &text, StyledTTFont &font, uint32 color, Graphics::Surface &dest, int lineY, TextJustification jusification);
79 	int32 drawText(const Common::String &text, TextStyleState &state, Graphics::Surface &dest);
80 	void drawTextWithWordWrapping(const Common::String &text, Graphics::Surface &dest);
81 
82 private:
83 	ZVision *_engine;
84 };
85 
86 Common::String readWideLine(Common::SeekableReadStream &stream);
87 int8 getUtf8CharSize(char chr);
88 uint16 readUtf8Char(const char *chr);
89 
90 } // End of namespace ZVision
91 
92 #endif
93