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 GRAPHICS_FONT_H
23 #define GRAPHICS_FONT_H
24 
25 #include "common/str.h"
26 #include "common/ustr.h"
27 #include "common/rect.h"
28 
29 namespace Common {
30 template<class T> class Array;
31 }
32 
33 namespace Graphics {
34 
44 struct Surface;
45 class ManagedSurface;
46 
48 enum TextAlign {
55 };
56 
62 };
63 
74 TextAlign convertTextAlignH(TextAlign alignH, bool rtl);
75 
82 class Font {
83 public:
84  Font() {}
85  virtual ~Font() {}
86 
92  virtual int getFontHeight() const = 0;
93 
97  virtual Common::String getFontName() const { return ""; }
98 
105  virtual int getFontAscent() const;
106 
113  virtual int getFontDescent() const;
114 
123  virtual int getFontLeading() const;
124 
130  virtual int getMaxCharWidth() const = 0;
131 
139  virtual int getCharWidth(uint32 chr) const = 0;
140 
149  virtual int getKerningOffset(uint32 left, uint32 right) const;
150 
167  virtual Common::Rect getBoundingBox(uint32 chr) const;
168 
188  Common::Rect getBoundingBox(const Common::String &str, int x = 0, int y = 0, const int w = 0, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
190  Common::Rect getBoundingBox(const Common::U32String &str, int x = 0, int _y = 0, const int w = 0, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
191 
212  virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const = 0;
213  virtual void drawChar(ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const;
214 
231  void drawString(Surface *dst, const Common::String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
233  void drawString(Surface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
235  void drawString(ManagedSurface *dst, const Common::String &str, int x, int _y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
237  void drawString(ManagedSurface *dst, const Common::U32String &str, int x, int y, int w, uint32 color, TextAlign align = kTextAlignLeft, int deltax = 0, bool useEllipsis = false) const;
238 
248  int getStringWidth(const Common::String &str) const;
250  int getStringWidth(const Common::U32String &str) const;
251 
269  int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
271  int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
280  int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, Common::Array<bool> &lineContinuation, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
281 
300  void scaleSingleGlyph(Surface *scaleSurface, int *grayScaleMap, int grayScaleMapSize, int width, int height, int xOffset, int yOffset, int grayLevel, int chr, int srcheight, int srcwidth, float scale) const;
301 
302 };
304 } // End of namespace Graphics
305 
306 #endif
Definition: managed_surface.h:51
Center the text.
Definition: font.h:52
Definition: str.h:59
Definition: font.h:82
TextAlign
Definition: font.h:48
Definition: surface.h:66
Default wrapping mode.
Definition: font.h:59
Align the text to the left.
Definition: font.h:51
Indicates invalid alignment.
Definition: font.h:49
Make the resulting line segments close to the same width.
Definition: font.h:60
Definition: rect.h:144
WordWrapMode
Definition: font.h:58
Graphics::Surface * scale(const Graphics::Surface &srcImage, int xSize, int ySize)
TextAlign convertTextAlignH(TextAlign alignH, bool rtl)
Definition: ustr.h:57
Align the text to the right.
Definition: font.h:54
Align the text to start of line (virtual).
Definition: font.h:50
Definition: algorithm.h:29
Definition: formatinfo.h:28
Align the text to end of line (virtual).
Definition: font.h:53
Text is wrapped on new lines. Otherwise, treats them as single whitespace.
Definition: font.h:61
virtual Common::String getFontName() const
Definition: font.h:97