ScummVM API documentation
fonts.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_FONTS_H
23#define AGS_SHARED_FONT_FONTS_H
24
25#include "common/std/vector.h"
26#include "ags/shared/ac/game_struct_defines.h"
27#include "ags/shared/util/string.h"
28#include "ags/shared/ac/game_struct_defines.h"
29#include "ags/shared/font/ags_font_renderer.h"
30#include "ags/shared/gfx/allegro_bitmap.h"
31
32namespace AGS3 {
33
34class IAGSFontRenderer;
35class IAGSFontRenderer2;
36class IAGSFontRendererInternal;
37struct FontInfo;
38struct FontRenderParams;
39
40namespace AGS {
41namespace Shared {
42
43struct Font {
44 // Classic font renderer interface
45 IAGSFontRenderer *Renderer = nullptr;
46 // Extended font renderer interface (optional)
47 IAGSFontRenderer2 *Renderer2 = nullptr;
48 // Internal interface (only for built-in renderers)
49 IAGSFontRendererInternal *RendererInt = nullptr;
50 FontInfo Info;
51 // Values received from the renderer and saved for the reference
52 FontMetrics Metrics;
53 // Precalculated linespacing, based on font properties and compat settings
54 int LineSpacingCalc = 0;
55
56 // Outline buffers
57 Bitmap TextStencil, TextStencilSub;
58 Bitmap OutlineStencil, OutlineStencilSub;
59
60 Font() {}
61};
62
63} // namespace Shared
64} // namespace AGS
65
66using namespace AGS;
67
68void init_font_renderer();
69void shutdown_font_renderer();
70void adjust_y_coordinate_for_text(int *ypos, size_t fontnum);
71IAGSFontRenderer *font_replace_renderer(size_t fontNumber, IAGSFontRenderer *renderer);
72IAGSFontRenderer *font_replace_renderer(size_t fontNumber, IAGSFontRenderer2 *renderer);
73 void font_recalc_metrics(size_t fontNumber);
74bool font_first_renderer_loaded();
75bool is_font_loaded(size_t fontNumber);
76bool is_bitmap_font(size_t fontNumber);
77bool font_supports_extended_characters(size_t fontNumber);
78// Get font's name, if it's available, otherwise returns empty string
79const char *get_font_name(size_t fontNumber);
80// Get a collection of FFLG_* flags corresponding to this font
81int get_font_flags(size_t fontNumber);
82// TODO: with changes to WFN font renderer that implemented safe rendering of
83// strings containing invalid chars (since 3.3.1) this function is not
84// important, except for (maybe) few particular cases.
85// Furthermore, its use complicated things, because AGS could modify some texts
86// at random times (usually - drawing routines).
87// Need to check whether it is safe to completely remove it.
88void ensure_text_valid_for_font(char *text, size_t fontnum);
89// Get font's scaling multiplier
90int get_font_scaling_mul(size_t fontNumber);
91// Calculate actual width of a line of text
92int get_text_width(const char *texx, size_t fontNumber);
93// Get the maximal width of the line of text, with corresponding outlining
94int get_text_width_outlined(const char *text, size_t font_number);
95// Get the maximal height of the line of text;
96// note that this won't be a nominal font's height, but the max of each met glyph's graphical height.
97int get_text_height(const char *text, size_t font_number);
98// Get font's height; this value is used for logical arrangement of UI elements;
99// note that this is a "formal" font height, that may have different value
100// depending on compatibility mode (used when running old games);
101int get_font_height(size_t fontNumber);
102// Get the maximal height of the given font, with corresponding outlining
103int get_font_height_outlined(size_t fontNumber);
104// Get font's surface height: this always returns the height enough to accommodate
105// font letters on a bitmap or a texture; the distinction is needed for compatibility reasons
106int get_font_surface_height(size_t fontNumber);
107// Get font's maximal graphical extent: this means the farthest vertical positions of glyphs,
108// relative to the "pen" position. Besides letting to calculate the surface height,
109// this information also lets to detect if some of the glyphs may appear above y0.
110std::pair<int, int> get_font_surface_extent(size_t fontNumber);
111// Get font's line spacing
112int get_font_linespacing(size_t fontNumber);
113// Set font's line spacing
114void set_font_linespacing(size_t fontNumber, int spacing);
115// Get font's outline type
116int get_font_outline(size_t font_number);
117// Get font's automatic outline thickness (if set)
118int get_font_outline_thickness(size_t font_number);
119// Gets the total maximal height of the given number of lines printed with the given font;
120// note that this uses formal font height, for compatibility purposes
121int get_text_lines_height(size_t fontNumber, size_t numlines);
122// Gets the height of a graphic surface enough to accommodate this number of text lines;
123// note this accounts for the real pixel font height
124int get_text_lines_surf_height(size_t fontNumber, size_t numlines);
125// Set font's outline type
126void set_font_outline(size_t font_number, int outline_type,
127 enum FontInfo::AutoOutlineStyle style = FontInfo::kSquared, int thickness = 1);
128bool is_font_antialiased(size_t font_number);
129// Outputs a single line of text on the defined position on bitmap, using defined font, color and parameters
130void wouttextxy(Shared::Bitmap *ds, int xxx, int yyy, size_t fontNumber, color_t text_color, const char *texx);
131// Assigns FontInfo to the font
132void set_fontinfo(size_t fontNumber, const FontInfo &finfo);
133// Gets full information about the font
134FontInfo get_fontinfo(size_t font_number);
135// Loads a font from disk
136bool load_font_size(size_t fontNumber, const FontInfo &font_info); void wgtprintf(Shared::Bitmap *ds, int xxx, int yyy, size_t fontNumber, color_t text_color, char *fmt, ...);
137// Allocates two outline stencil buffers, or returns previously creates ones;
138// these buffers are owned by the font, they should not be deleted by the caller.
139void alloc_font_outline_buffers(size_t font_number,
140 Shared::Bitmap **text_stencil, Shared::Bitmap **outline_stencil,
141 int text_width, int text_height, int color_depth);
142// Perform necessary adjustments on all fonts in case the text render mode changed (anti-aliasing etc)
143void adjust_fonts_for_render_mode(bool aa_mode);
144// Free particular font's data
145void wfreefont(size_t fontNumber);
146// Free all fonts data
147void free_all_fonts();
148
149// Tells if the text should be antialiased when possible
150bool ShouldAntiAliasText();
151
152// SplitLines class represents a list of lines and is meant to reduce
153// subsequent memory (de)allocations if used often during game loops
154// and drawing. For that reason it is not equivalent to std::vector,
155// but keeps constructed String buffers intact for most time.
156// TODO: implement proper strings pool.
158public:
159 inline size_t Count() const {
160 return _count;
161 }
162 inline const Shared::String &operator[](size_t i) const {
163 return _pool[i];
164 }
165 inline Shared::String &operator[](size_t i) {
166 return _pool[i];
167 }
168 inline void Clear() {
169 _pool.clear();
170 _count = 0;
171 }
172 inline void Reset() {
173 _count = 0;
174 }
175 inline void Add(const char *cstr) {
176 if (_pool.size() == _count) _pool.resize(_count + 1);
177 _pool[_count++].SetString(cstr);
178 }
179
180 // An auxiliary line processing buffer
181 std::vector<char> LineBuf;
182
183private:
185 size_t _count; // actual number of lines in use
186};
187
188// Break up the text into lines restricted by the given width;
189// returns number of lines, or 0 if text cannot be split well to fit in this width
190size_t split_lines(const char *texx, SplitLines &lines, int width, int fontNumber, size_t max_lines = -1);
191
192} // namespace AGS3
193
194#endif
Definition: allegro_bitmap.h:44
Definition: string.h:60
Definition: ags_font_renderer.h:51
Definition: ags_font_renderer.h:33
Definition: ags_font_renderer.h:107
Definition: fonts.h:157
Definition: fonts.h:43
Definition: game_struct_defines.h:268
Definition: ags_font_renderer.h:82