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  int getMaxCharWidth() const override { return _maxCharWidth; }
48  int getCharWidth(uint32 chr) const override;
49  int getKerningOffset(uint32 left, uint32 right) const override { return 1; }
50 
51  void drawChar(Graphics::Surface *dst, uint32 chr, int x, int y, uint32 color) const override;
52 
53  const Graphics::ManagedSurface &getImageSurface() const { return _image; }
54 
55  // Custom word wrapping function to fix an edge case with overflowing whitespaces
56  void wordWrap(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0) const;
57 
58 private:
59  Common::Rect getCharacterSourceRect(char chr) const;
60 
61  Common::String _description;
62  Common::Point _color0CoordsOffset;
63  Common::Point _color1CoordsOffset; // Added to source rects when colored text is requested
64  int16 _charSpace = 0;
65  uint16 _spaceWidth = 0;
66 
67  // Specific offsets into the _characterRects array
68  uint16 _uppercaseOffset = 0;
69  uint16 _lowercaseOffset = 0;
70  uint16 _digitOffset = 0;
71  uint16 _periodOffset = 0;
72  uint16 _commaOffset = 0;
73  uint16 _equalitySignOffset = 0;
74  uint16 _colonOffset = 0;
75  uint16 _dashOffset = 0;
76  uint16 _questionMarkOffset = 0;
77  uint16 _exclamationMarkOffset = 0;
78  uint16 _percentOffset = 0;
79  uint16 _ampersandOffset = 0;
80  uint16 _asteriskOffset = 0;
81  uint16 _leftBracketOffset = 0;
82  uint16 _rightBracketOffset = 0;
83  uint16 _plusOffset = 0;
84  uint16 _apostropheOffset = 0;
85  uint16 _semicolonOffset = 0;
86  uint16 _slashOffset = 0;
87 
88  // Specific offsets for Cyrillic characters. Introduced in nancy5, only used in Russian variants
89  // The original data references the letters one by one, out of order. We only keep the two offsets below
90  int16 _cyrillicUppercaseOffset = -1;
91  int16 _cyrillicLowercaseOffset = -1;
92 
93  // More specific offsets for extended ASCII characters. Introduced in nancy6
94  int16 _aWithGraveOffset = -1;
95  int16 _cWithCedillaOffset = -1;
96  int16 _eWithGraveOffset = -1;
97  int16 _eWithAcuteOffset = -1;
98  int16 _eWithCircumflexOffset = -1;
99  int16 _eWithDiaeresisOffset = -1;
100  int16 _oWithCircumflexOffset = -1;
101  int16 _uppercaseAWithGraveOffset = -1;
102  int16 _aWithCircumflexOffset = -1;
103  int16 _iWithCircumflexOffset = -1;
104  int16 _uWithGraveOffset = -1;
105  int16 _uppercaseAWithDiaeresisOffset = -1;
106  int16 _aWithDiaeresisOffset = -1;
107  int16 _uppercaseOWithDiaeresisOffset = -1;
108  int16 _oWithDiaeresisOffset = -1;
109  int16 _uppercaseUWithDiaeresisOffset = -1;
110  int16 _uWithDiaeresisOffset = -1;
111  int16 _invertedExclamationMarkOffset = -1;
112  int16 _invertedQuestionMarkOffset = -1;
113  int16 _uppercaseNWithTildeOffset = -1;
114  int16 _nWithTildeOffset = -1;
115  int16 _uppercaseEWithAcuteOffset = -1;
116  int16 _aWithAcuteOffset = -1;
117  int16 _iWithAcuteOffset = -1;
118  int16 _oWithAcuteOffset = -1;
119  int16 _uWithAcuteOffset = -1;
120  int16 _eszettOffset = -1;
121 
122  // Even more specific offsets for extended ASCII characters. Introduced in nancy10
123  int16 _uppercaseAWithDotOffset = -1;
124  int16 _aWithDotOffset = -1;
125  int16 _underscoreOffset = -1;
126  int16 _hashOffset = -1;
127  int16 _dollarOffset = -1;
128  int16 _lessThanOffset = -1;
129  int16 _greaterThanOffset = -1;
130  int16 _leftCurlyBracketOffset = -1;
131  int16 _rightCurlyBracketOffset = -1;
132  int16 _euroOffset = -1;
133 
134  Common::Array<Common::Rect> _characterRects;
135 
137 
138  const struct TBOX *_textboxData = nullptr;
139 
140  int _fontHeight = 0;
141  int _maxCharWidth = 0;
142  uint _transColor = 0;
143 };
144 
145 } // End of namespace Nancy
146 
147 #endif // NANCY_FONT_H
Definition: managed_surface.h:51
Definition: str.h:59
Definition: font.h:83
Definition: surface.h:67
Definition: rect.h:524
int getKerningOffset(uint32 left, uint32 right) const override
Definition: font.h:49
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:150
Definition: actionmanager.h:32
int getMaxCharWidth() const override
Definition: font.h:47