ScummVM API documentation
ags_font_renderer.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 AGS_SHARED_FONT_AGS_FONT_RENDERER_H
23 #define AGS_SHARED_FONT_AGS_FONT_RENDERER_H
24 
25 #include "common/std/utility.h"
26 #include "ags/shared/core/types.h"
27 #include "ags/shared/util/string.h"
28 
29 namespace AGS3 {
30 
31 class BITMAP;
32 
34 public:
35  virtual bool LoadFromDisk(int fontNumber, int fontSize) = 0;
36  virtual void FreeMemory(int fontNumber) = 0;
37  virtual bool SupportsExtendedCharacters(int fontNumber) = 0;
38  virtual int GetTextWidth(const char *text, int fontNumber) = 0;
39  // Get actual height of the given line of text
40  virtual int GetTextHeight(const char *text, int fontNumber) = 0;
41  virtual void RenderText(const char *text, int fontNumber, BITMAP *destination, int x, int y, int colour) = 0;
42  virtual void AdjustYCoordinateForFont(int *ycoord, int fontNumber) = 0;
43  virtual void EnsureTextValidForFont(char *text, int fontNumber) = 0;
44 protected:
45  IAGSFontRenderer() {}
46  ~IAGSFontRenderer() {}
47 };
48 
49 // Extended font renderer interface.
50 // WARNING: this interface is exposed for plugins and declared for the second time in agsplugin.h
52 public:
53  // Returns engine API version this font renderer complies to.
54  // Must not be lower than 26 (this interface was added at API v26).
55  virtual int GetVersion() = 0;
56  // Returns an arbitrary renderer name; this is for informational
57  // purposes only.
58  virtual const char *GetRendererName() = 0;
59  // Returns given font's name (if available).
60  virtual const char *GetFontName(int fontNumber) = 0;
61  // Returns the given font's height: that is the maximal vertical size
62  // that the font glyphs may occupy.
63  virtual int GetFontHeight(int fontNumber) = 0;
64  // Returns the given font's linespacing;
65  // is allowed to return 0, telling that no specific linespacing
66  // is assigned for this font.
67  virtual int GetLineSpacing(int fontNumber) = 0;
68 
69 protected:
71  ~IAGSFontRenderer2() {}
72 };
73 
74 // Font render params, mainly for dealing with various compatibility issues.
76  // Font's render multiplier
77  int SizeMultiplier = 1;
78  int LoadMode = 0; // contains font flags from FFLG_LOADMODEMASK
79 };
80 
81 // Describes loaded font's properties
82 struct FontMetrics {
83  // Nominal font's height, equals to the game-requested size of the font.
84  // This may or not be equal to font's face height; sometimes a font cannot
85  // be scaled exactly to particular size, and then nominal height appears different
86  // (usually - smaller) than the real one.
87  int NominalHeight = 0;
88  // Real font's height, equals to reported ascender + descender.
89  // This is what you normally think as a font's height.
90  int RealHeight = 0;
91  // Compatible height, equals to either NominalHeight or RealHeight,
92  // selected depending on the game settings.
93  // This property is used in calculating linespace, etc.
94  int CompatHeight = 0;
95  // Maximal vertical extent of a font (top; bottom), this tells the actual
96  // graphical bounds that may be occupied by font's glyphs.
97  // In a "proper" font this extent is (0; RealHeight-1), but "bad" fonts may
98  // have individual glyphs exceeding these bounds, in both directions.
99  // Note that "top" may be negative!
100  std::pair<int, int> VExtent;
101 
102  inline int ExtentHeight() const { return VExtent.second - VExtent.first; }
103 };
104 
105 // The strictly internal font renderer interface, not to use in plugin API.
106 // Contains methods necessary for built-in font renderers.
108 public:
109  // Tells if this is a bitmap font (otherwise it's a vector font)
110  virtual bool IsBitmapFont() = 0;
111  // Load font, applying extended font rendering parameters
112  virtual bool LoadFromDiskEx(int fontNumber, int fontSize, AGS::Shared::String *src_filename,
113  const FontRenderParams *params, FontMetrics *metrics) = 0;
114  // Fill FontMetrics struct; note that it may be left cleared if this is not supported
115  virtual void GetFontMetrics(int fontNumber, FontMetrics *metrics) = 0;
116  // Perform any necessary adjustments when the AA mode is toggled
117  virtual void AdjustFontForAntiAlias(int fontNumber, bool aa_mode) = 0;
118 
119 protected:
122 };
123 
124 } // namespace AGS3
125 
126 #endif
Definition: surface.h:32
Definition: ags_font_renderer.h:75
Definition: ags_font_renderer.h:107
Definition: ags_font_renderer.h:51
Definition: ags_font_renderer.h:82
Definition: string.h:62
Definition: ags.h:40
Definition: ags_font_renderer.h:33