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