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 
63 };
64 
75 TextAlign convertTextAlignH(TextAlign alignH, bool rtl);
76 
83 class Font {
84 public:
85  Font() {}
86  virtual ~Font() {}
87 
93  virtual int getFontHeight() const = 0;
94 
98  virtual Common::String getFontName() const { return ""; }
99 
106  virtual int getFontAscent() const;
107 
114  virtual int getFontDescent() const;
115 
124  virtual int getFontLeading() const;
125 
131  virtual int getMaxCharWidth() const = 0;
132 
140  virtual int getCharWidth(uint32 chr) const = 0;
141 
150  virtual int getKerningOffset(uint32 left, uint32 right) const;
151 
168  virtual Common::Rect getBoundingBox(uint32 chr) const;
169 
189  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;
191  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;
192 
213  virtual void drawChar(Surface *dst, uint32 chr, int x, int y, uint32 color) const = 0;
214  virtual void drawChar(ManagedSurface *dst, uint32 chr, int x, int y, uint32 color) const;
215 
232  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;
234  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;
236  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;
238  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;
239 
249  int getStringWidth(const Common::String &str) const;
251  int getStringWidth(const Common::U32String &str) const;
252 
270  int wordWrapText(const Common::String &str, int maxWidth, Common::Array<Common::String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
272  int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
281  int wordWrapText(const Common::U32String &str, int maxWidth, Common::Array<Common::U32String> &lines, Common::Array<bool> &lineContinuation, int initWidth = 0, uint32 mode = kWordWrapOnExplicitNewLines) const;
282 
301  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;
302 
303 };
305 } // End of namespace Graphics
306 
307 #endif
Definition: managed_surface.h:51
Center the text.
Definition: font.h:52
Definition: str.h:59
Definition: font.h:83
TextAlign
Definition: font.h:48
Definition: surface.h:67
Default wrapping mode.
Definition: font.h:59
Allow any amount of trailing whitespace before wrapping as it won&#39;t be drawn.
Definition: font.h:62
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:98