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 
32 namespace AGS3 {
33 
34 class IAGSFontRenderer;
35 class IAGSFontRenderer2;
36 class IAGSFontRendererInternal;
37 struct FontInfo;
38 struct FontRenderParams;
39 
40 namespace AGS {
41 namespace Shared {
42 
43 struct 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 
66 using namespace AGS;
67 
68 void init_font_renderer();
69 void shutdown_font_renderer();
70 void adjust_y_coordinate_for_text(int *ypos, size_t fontnum);
71 IAGSFontRenderer *font_replace_renderer(size_t fontNumber, IAGSFontRenderer *renderer);
72 IAGSFontRenderer *font_replace_renderer(size_t fontNumber, IAGSFontRenderer2 *renderer);
73  void font_recalc_metrics(size_t fontNumber);
74 bool font_first_renderer_loaded();
75 bool is_font_loaded(size_t fontNumber);
76 bool is_bitmap_font(size_t fontNumber);
77 bool font_supports_extended_characters(size_t fontNumber);
78 // Get font's name, if it's available, otherwise returns empty string
79 const char *get_font_name(size_t fontNumber);
80 // Get a collection of FFLG_* flags corresponding to this font
81 int 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.
88 void ensure_text_valid_for_font(char *text, size_t fontnum);
89 // Get font's scaling multiplier
90 int get_font_scaling_mul(size_t fontNumber);
91 // Calculate actual width of a line of text
92 int get_text_width(const char *texx, size_t fontNumber);
93 // Get the maximal width of the given font, with corresponding outlining
94 int get_text_width_outlined(const char *text, size_t font_number);
95 // Get font's height; this value is used for logical arrangement of UI elements;
96 // note that this is a "formal" font height, that may have different value
97 // depending on compatibility mode (used when running old games);
98 int get_font_height(size_t fontNumber);
99 // Get the maximal height of the given font, with corresponding outlining
100 int get_font_height_outlined(size_t fontNumber);
101 // Get font's surface height: this always returns the height enough to accommodate
102 // font letters on a bitmap or a texture; the distinction is needed for compatibility reasons
103 int get_font_surface_height(size_t fontNumber);
104 // Get font's maximal graphical extent: this means the farthest vertical positions of glyphs,
105 // relative to the "pen" position. Besides letting to calculate the surface height,
106 // this information also lets to detect if some of the glyphs may appear above y0.
107 std::pair<int, int> get_font_surface_extent(size_t fontNumber);
108 // Get font's line spacing
109 int get_font_linespacing(size_t fontNumber);
110 // Set font's line spacing
111 void set_font_linespacing(size_t fontNumber, int spacing);
112 // Get font's outline type
113 int get_font_outline(size_t font_number);
114 // Get font's automatic outline thickness (if set)
115 int get_font_outline_thickness(size_t font_number);
116 // Gets the total maximal height of the given number of lines printed with the given font;
117 // note that this uses formal font height, for compatibility purposes
118 int get_text_lines_height(size_t fontNumber, size_t numlines);
119 // Gets the height of a graphic surface enough to accommodate this number of text lines;
120 // note this accounts for the real pixel font height
121 int get_text_lines_surf_height(size_t fontNumber, size_t numlines);
122 // Set font's outline type
123 void set_font_outline(size_t font_number, int outline_type,
124  enum FontInfo::AutoOutlineStyle style = FontInfo::kSquared, int thickness = 1);
125 bool is_font_antialiased(size_t font_number);
126 // Outputs a single line of text on the defined position on bitmap, using defined font, color and parameters
127 void wouttextxy(Shared::Bitmap *ds, int xxx, int yyy, size_t fontNumber, color_t text_color, const char *texx);
128 // Assigns FontInfo to the font
129 void set_fontinfo(size_t fontNumber, const FontInfo &finfo);
130 // Gets full information about the font
131 FontInfo get_fontinfo(size_t font_number);
132 // Loads a font from disk
133 bool 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, ...);
134 // Allocates two outline stencil buffers, or returns previously creates ones;
135 // these buffers are owned by the font, they should not be deleted by the caller.
136 void alloc_font_outline_buffers(size_t font_number,
137  Shared::Bitmap **text_stencil, Shared::Bitmap **outline_stencil,
138  int text_width, int text_height, int color_depth);
139 // Perform necessary adjustments on all fonts in case the text render mode changed (anti-aliasing etc)
140 void adjust_fonts_for_render_mode(bool aa_mode);
141 // Free particular font's data
142 void wfreefont(size_t fontNumber);
143 // Free all fonts data
144 void free_all_fonts();
145 
146 // Tells if the text should be antialiased when possible
147 bool ShouldAntiAliasText();
148 
149 // SplitLines class represents a list of lines and is meant to reduce
150 // subsequent memory (de)allocations if used often during game loops
151 // and drawing. For that reason it is not equivalent to std::vector,
152 // but keeps constructed String buffers intact for most time.
153 // TODO: implement proper strings pool.
154 class SplitLines {
155 public:
156  inline size_t Count() const {
157  return _count;
158  }
159  inline const Shared::String &operator[](size_t i) const {
160  return _pool[i];
161  }
162  inline Shared::String &operator[](size_t i) {
163  return _pool[i];
164  }
165  inline void Clear() {
166  _pool.clear();
167  _count = 0;
168  }
169  inline void Reset() {
170  _count = 0;
171  }
172  inline void Add(const char *cstr) {
173  if (_pool.size() == _count) _pool.resize(_count + 1);
174  _pool[_count++].SetString(cstr);
175  }
176 
177  // An auxiliary line processing buffer
178  std::vector<char> LineBuf;
179 
180 private:
182  size_t _count; // actual number of lines in use
183 };
184 
185 // Break up the text into lines restricted by the given width;
186 // returns number of lines, or 0 if text cannot be split well to fit in this width
187 size_t split_lines(const char *texx, SplitLines &lines, int width, int fontNumber, size_t max_lines = -1);
188 
189 } // namespace AGS3
190 
191 #endif
Definition: achievements_tables.h:27
Definition: allegro_bitmap.h:44
Definition: fonts.h:43
Definition: ags_font_renderer.h:107
Definition: ags_font_renderer.h:51
Definition: fonts.h:154
Definition: ags_font_renderer.h:82
Definition: string.h:62
Definition: game_struct_defines.h:268
Definition: ags.h:40
Definition: ags_font_renderer.h:33