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