ScummVM API documentation
font.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 ULTIMA8_GFX_FONTS_FONT_H
23#define ULTIMA8_GFX_FONTS_FONT_H
24
25#include "common/list.h"
26#include "common/rect.h"
27#include "common/str.h"
28#include "ultima/ultima8/misc/encoding.h"
29
30namespace Ultima {
31namespace Ultima8 {
32
33class RenderedText;
34
36 Common::String _text;
37 Common::Rect32 _dims;
38 Common::String::size_type _cursor;
39};
40
41class Font {
42public:
43 Font();
44 virtual ~Font();
45
46 enum TextAlign {
47 TEXT_LEFT,
48 TEXT_CENTER,
49 TEXT_RIGHT
50 };
51
53 virtual int getHeight() = 0;
54
56 virtual int getBaseline() = 0;
57
59 virtual int getBaselineSkip() = 0;
60
65 virtual void getStringSize(const Common::String &text,
66 int32 &width, int32 &height) = 0;
67
78 unsigned int &remaining, int32 width = 0, int32 height = 0,
79 TextAlign align = TEXT_LEFT, bool u8specials = false,
80 bool pagebreaks = false,
81 Common::String::size_type cursor = Common::String::npos) = 0;
82
93 virtual void getTextSize(const Common::String &text,
94 int32 &resultwidth, int32 &resultheight, unsigned int &remaining,
95 int32 width = 0, int32 height = 0, TextAlign align = TEXT_LEFT,
96 bool u8specials = false, bool pagebreaks = false);
97
98 void setHighRes(bool hr) {
99 _highRes = hr;
100 }
101 bool isHighRes() const {
102 return _highRes;
103 }
104
105protected:
106 bool _highRes;
107
108 struct Traits {
109 static bool isSpace(Common::String::const_iterator &i, bool u8specials) {
110 char c = *i;
111 return (c == ' ' || c == '\t' || c == '\n' || c == '\r' ||
112 (u8specials && (c == '%' || c == '~' || c == '*' || c == '^')));
113 }
114 static bool isTab(Common::String::const_iterator &i, bool u8specials) {
115 char c = *i;
116 return (c == '\t' ||
117 (u8specials && (c == '\t' || c == '%')));
118 }
119 static bool isBreak(Common::String::const_iterator &i, bool u8specials) {
120 char c = *i;
121 return (c == '\n' ||
122 (u8specials && (c == '\n' || c == '~' || c == '*')));
123 }
124 static bool isPageBreak(Common::String::const_iterator &i, bool u8specials) {
125 char c = *i;
126 return (u8specials && c == '*');
127 }
128 static bool canBreakAfter(Common::String::const_iterator &i);
129 static void advance(Common::String::const_iterator &i) {
130 ++i;
131 }
132 static Common::String::size_type length(const Common::String &t) {
133 return t.size();
134 }
135 static uint32 unicode(Common::String::const_iterator &i) {
136 return encoding[static_cast<uint8>(*i++)];
137 }
138 };
139 struct SJISTraits : public Traits {
140 static bool canBreakAfter(Common::String::const_iterator &i);
141 static void advance(Common::String::const_iterator &i) {
142 // FIXME: this can advance past the end of a malformed string
143 uint8 c = *i;
144 i++;
145 if (c >= 0x80) i++;
146 }
147 static Common::String::size_type length(const Common::String &t) {
148 Common::String::size_type l = 0;
149 Common::String::const_iterator iter = t.begin();
150 while (iter != t.end()) {
151 advance(iter);
152 l++;
153 }
154 return l;
155 }
156 static uint32 unicode(Common::String::const_iterator &i) {
157 uint16 s = static_cast<uint8>(*i);
158 i++;
159 if (s >= 0x80) {
160 uint16 t = static_cast<uint8>(*i++);
161 s |= (t << 8);
162 }
163 return shiftjis_to_unicode(s);
164 }
165 };
166};
167
168template<class T>
169Common::List<PositionedText> typesetText(Font *font,
170 const Common::String &text, unsigned int &remaining,
171 int32 width, int32 height, Font::TextAlign align,
172 bool u8specials, bool pagebreaks,
173 int32 &resultwidth, int32 &resultheight,
174 Common::String::size_type cursor = Common::String::npos);
175
176} // End of namespace Ultima8
177} // End of namespace Ultima
178
179#endif
Definition: list.h:44
Definition: str.h:59
Definition: font.h:41
virtual int getHeight()=0
get the height of the font
virtual int getBaseline()=0
get the baseline of the font (relative from the top)
virtual int getBaselineSkip()=0
get the baselineskip of the font (distance between two baselines)
virtual void getStringSize(const Common::String &text, int32 &width, int32 &height)=0
virtual void getTextSize(const Common::String &text, int32 &resultwidth, int32 &resultheight, unsigned int &remaining, int32 width=0, int32 height=0, TextAlign align=TEXT_LEFT, bool u8specials=false, bool pagebreaks=false)
virtual RenderedText * renderText(const Common::String &text, unsigned int &remaining, int32 width=0, int32 height=0, TextAlign align=TEXT_LEFT, bool u8specials=false, bool pagebreaks=false, Common::String::size_type cursor=Common::String::npos)=0
Definition: rendered_text.h:32
Definition: rect.h:538
Definition: font.h:139
Definition: font.h:108
Definition: font.h:35