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#ifndef NANCY_FONT_H
22#define NANCY_FONT_H
23
24#include "common/array.h"
25#include "common/ptr.h"
26
27#include "graphics/font.h"
28#include "graphics/managed_surface.h"
29
30namespace Common {
31class SeekableReadStream;
32}
33
34namespace Nancy {
35
36class NancyEngine;
37
38class Font : public Graphics::Font {
39public:
40 Font() = default;
41 ~Font() = default;
42
43 Font(Font &&) = default;
44
45 void read(Common::SeekableReadStream &stream);
46
47 // Nancy16+ uses system fonts, which get drawn with a TrueType substitute.
48 // The color passed when drawing is then a font color ID. Every font also
49 // comes in bold, which gets "_Bold" added to its name.
50 void readSystemFont(Common::SeekableReadStream &stream, bool bold);
51 void setSystemFont(const Common::String &name, const Common::String &faceName, int32 height, int32 weight);
52 const Common::String &getName() const { return _description; }
53 // Nancy16+: the substitute font, for drawing with an explicit color instead of a color ID
54 const Graphics::Font *getSystemFont() const { return _systemFont.get(); }
55
56 int getFontHeight() const override { return _systemFont ? _systemFont->getFontHeight() : _fontHeight - 1; }
57
58 // The vertical advance between text lines (height of the first glyph).
59 int getLineHeight() const;
60
61 int getMaxCharWidth() const override { return _systemFont ? _systemFont->getMaxCharWidth() : _maxCharWidth; }
62 int getCharWidth(uint32 chr) const override;
63 int getKerningOffset(uint32 left, uint32 right) const override { return _systemFont ? _systemFont->getKerningOffset(left, right) : 0; }
64
65 void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
66
67 const Graphics::ManagedSurface &getImageSurface() const { return _image; }
68
69 // Samples an opaque pixel from a solid glyph rendered in the given color
70 // variant, so callers can match the exact text color. Used to draw
71 // underlines (the <u> markup toggle), for which the atlas has no glyph.
72 uint32 getColorPixel(uint color) const;
73
74 // Custom word wrapping function to fix an edge case with overflowing whitespaces
75 void wordWrap(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0) const;
76
77private:
78 Common::Rect getCharacterSourceRect(char chr) const;
79
80 Common::String _description;
81 Common::Point _color0CoordsOffset;
82 Common::Point _color1CoordsOffset; // Added to source rects when colored text is requested
83 int16 _charSpace = 0;
84 uint16 _spaceWidth = 0;
85
86 // Specific offsets into the _characterRects array
87 uint16 _uppercaseOffset = 0;
88 uint16 _lowercaseOffset = 0;
89 uint16 _digitOffset = 0;
90 uint16 _periodOffset = 0;
91 uint16 _commaOffset = 0;
92 uint16 _equalitySignOffset = 0;
93 uint16 _colonOffset = 0;
94 uint16 _dashOffset = 0;
95 uint16 _questionMarkOffset = 0;
96 uint16 _exclamationMarkOffset = 0;
97 uint16 _percentOffset = 0;
98 uint16 _ampersandOffset = 0;
99 uint16 _asteriskOffset = 0;
100 uint16 _leftBracketOffset = 0;
101 uint16 _rightBracketOffset = 0;
102 uint16 _plusOffset = 0;
103 uint16 _apostropheOffset = 0;
104 uint16 _semicolonOffset = 0;
105 uint16 _slashOffset = 0;
106
107 // Specific offsets for Cyrillic characters. Introduced in nancy5, only used in Russian variants
108 // The original data references the letters one by one, out of order. We only keep the two offsets below
109 int16 _cyrillicUppercaseOffset = -1;
110 int16 _cyrillicLowercaseOffset = -1;
111
112 // More specific offsets for extended ASCII characters. Introduced in nancy6
113 int16 _aWithGraveOffset = -1;
114 int16 _cWithCedillaOffset = -1;
115 int16 _eWithGraveOffset = -1;
116 int16 _eWithAcuteOffset = -1;
117 int16 _eWithCircumflexOffset = -1;
118 int16 _eWithDiaeresisOffset = -1;
119 int16 _oWithCircumflexOffset = -1;
120 int16 _uppercaseAWithGraveOffset = -1;
121 int16 _aWithCircumflexOffset = -1;
122 int16 _iWithCircumflexOffset = -1;
123 int16 _uWithGraveOffset = -1;
124 int16 _uppercaseAWithDiaeresisOffset = -1;
125 int16 _aWithDiaeresisOffset = -1;
126 int16 _uppercaseOWithDiaeresisOffset = -1;
127 int16 _oWithDiaeresisOffset = -1;
128 int16 _uppercaseUWithDiaeresisOffset = -1;
129 int16 _uWithDiaeresisOffset = -1;
130 int16 _invertedExclamationMarkOffset = -1;
131 int16 _invertedQuestionMarkOffset = -1;
132 int16 _uppercaseNWithTildeOffset = -1;
133 int16 _nWithTildeOffset = -1;
134 int16 _uppercaseEWithAcuteOffset = -1;
135 int16 _aWithAcuteOffset = -1;
136 int16 _iWithAcuteOffset = -1;
137 int16 _oWithAcuteOffset = -1;
138 int16 _uWithAcuteOffset = -1;
139 int16 _eszettOffset = -1;
140
141 // Even more specific offsets for extended ASCII characters. Introduced in nancy10
142 int16 _uppercaseAWithDotOffset = -1;
143 int16 _aWithDotOffset = -1;
144 int16 _underscoreOffset = -1;
145 int16 _hashOffset = -1;
146 int16 _dollarOffset = -1;
147 int16 _lessThanOffset = -1;
148 int16 _greaterThanOffset = -1;
149 int16 _leftCurlyBracketOffset = -1;
150 int16 _rightCurlyBracketOffset = -1;
151 int16 _euroOffset = -1;
152
153 // Two more characters, introduced in nancy15
154 int16 _caretOffset = -1;
155 int16 _atSignOffset = -1;
156
157 // Specific offsets in French variant of nancy12
158 int16 _uppercaseCWithCedillaOffset = -1;
159 int16 _uWithCircumflexOffset = -1;
160 int16 _oeLigatureOffset = -1;
161 int16 _iWithDiaeresisOffset = -1;
162
163 Common::Array<Common::Rect> _characterRects;
164
166
167 const struct TBOX *_textboxData = nullptr;
168
169 Common::DisposablePtr<const Graphics::Font> _systemFont{nullptr, DisposeAfterUse::NO};
170
171 int _fontHeight = 0;
172 int _maxCharWidth = 0;
173 uint _transColor = 0;
174};
175
176} // End of namespace Nancy
177
178#endif // NANCY_FONT_H
PointerType get() const
Definition: ptr.h:733
Definition: stream.h:745
Definition: str.h:59
Definition: font.h:83
virtual int getFontHeight() const =0
virtual int getKerningOffset(uint32 left, uint32 right) const
virtual int getMaxCharWidth() const =0
Definition: managed_surface.h:51
Definition: font.h:38
int getKerningOffset(uint32 left, uint32 right) const override
Definition: font.h:63
void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override
int getMaxCharWidth() const override
Definition: font.h:61
int getCharWidth(uint32 chr) const override
int getFontHeight() const override
Definition: font.h:56
Definition: algorithm.h:29
Definition: actionmanager.h:32
Definition: rect.h:144
Definition: rect.h:536
Definition: surface.h:67
Definition: enginedata.h:183