Blender  V3.3
blf_internal_types.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2008 Blender Foundation. All rights reserved. */
3 
8 #pragma once
9 
10 #include "GPU_texture.h"
11 #include "GPU_vertex_buffer.h"
12 
13 #include FT_MULTIPLE_MASTERS_H /* Variable font support. */
14 
15 #define BLF_VARIATIONS_MAX 16 /* Maximum variation axes per font. */
16 
17 #define MAKE_DVAR_TAG(a, b, c, d) \
18  (((uint32_t)a << 24u) | ((uint32_t)b << 16u) | ((uint32_t)c << 8u) | ((uint32_t)d))
19 
20 #define blf_variation_axis_weight MAKE_DVAR_TAG('w', 'g', 'h', 't') /* 'wght' weight axis. */
21 #define blf_variation_axis_slant MAKE_DVAR_TAG('s', 'l', 'n', 't') /* 'slnt' slant axis. */
22 #define blf_variation_axis_width MAKE_DVAR_TAG('w', 'd', 't', 'h') /* 'wdth' width axis. */
23 #define blf_variation_axis_spacing MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* 'spac' spacing axis. */
24 #define blf_variation_axis_optsize MAKE_DVAR_TAG('o', 'p', 's', 'z') /* 'opsz' optical size. */
25 
26 /* -------------------------------------------------------------------- */
37 typedef int32_t ft_pix;
38 
39 /* Macros copied from `include/freetype/internal/ftobjs.h`. */
40 
41 /* FIXME(@campbellbarton): Follow rounding from Blender 3.1x and older.
42  * This is what users will expect and changing this creates wider spaced text.
43  * Use this macro to communicate that rounding should be used, using floor is to avoid
44  * user visible changes, which can be reviewed and handled separately. */
45 #define USE_LEGACY_SPACING
46 
47 #define FT_PIX_FLOOR(x) ((x) & ~63)
48 #define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
49 #define FT_PIX_CEIL(x) ((x) + 63)
50 
51 #ifdef USE_LEGACY_SPACING
52 # define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_FLOOR(x)
53 #else
54 # define FT_PIX_DEFAULT_ROUNDING(x) FT_PIX_ROUND(x)
55 #endif
56 
58 {
59 #ifdef USE_LEGACY_SPACING
60  return (int)(v >> 6);
61 #else
62  return (int)(FT_PIX_DEFAULT_ROUNDING(v) >> 6);
63 #endif
64 }
65 
67 {
68  return (int)(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
69 }
70 
72 {
73  return (int)(FT_PIX_CEIL(v) >> 6);
74 }
75 
77 {
78  return v * 64;
79 }
80 
82 {
83  return lroundf(v * 64.0f);
84 }
85 
87 {
88  /* See #USE_LEGACY_SPACING, rounding logic could change here. */
90 }
91 
92 #undef FT_PIX_ROUND
93 #undef FT_PIX_CEIL
94 #undef FT_PIX_DEFAULT_ROUNDING
95 
98 #define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
99 
100 /* Number of characters in GlyphCacheBLF.glyph_ascii_table. */
101 #define GLYPH_ASCII_TABLE_SIZE 128
102 
103 /* Number of characters in KerningCacheBLF.table. */
104 #define KERNING_CACHE_TABLE_SIZE 128
105 
106 /* A value in the kerning cache that indicates it is not yet set. */
107 #define KERNING_ENTRY_UNSET INT_MAX
108 
109 typedef struct BatchBLF {
110  struct FontBLF *font; /* can only batch glyph from the same font */
111  struct GPUBatch *batch;
112  struct GPUVertBuf *verts;
113  struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step;
115  unsigned int glyph_len;
116  int ofs[2]; /* copy of font->pos */
117  float mat[4][4]; /* previous call modelmatrix. */
121 
122 extern BatchBLF g_batch;
123 
124 typedef struct KerningCacheBLF {
131 
132 typedef struct GlyphCacheBLF {
135 
136  /* font size. */
137  float size;
138 
139  /* and DPI. */
140  unsigned int dpi;
141  float char_weight;
142  float char_slant;
143  float char_width;
145 
146  bool bold;
147  bool italic;
148 
149  /* Column width when printing monospaced. */
151 
152  /* and the glyphs. */
154 
155  /* fast ascii lookup */
157 
158  /* texture array, to draw the glyphs. */
164 
166 
167 typedef struct GlyphBLF {
168  struct GlyphBLF *next;
169  struct GlyphBLF *prev;
170 
171  /* and the character, as UTF-32 */
172  unsigned int c;
173 
174  /* freetype2 index, to speed-up the search. */
175  FT_UInt idx;
176 
177  /* glyph box. */
182 
184 
185  /* The difference in bearings when hinting is active, zero otherwise. */
188 
189  /* position inside the texture where this glyph is store. */
190  int offset;
191 
192  /* Bitmap data, from freetype. Take care that this
193  * can be NULL.
194  */
195  unsigned char *bitmap;
196 
197  /* Glyph width and height. */
198  int dims[2];
199  int pitch;
200 
206  int pos[2];
207 
210 
211 typedef struct FontBufInfoBLF {
212  /* for draw to buffer, always set this to NULL after finish! */
213  float *fbuf;
214 
215  /* the same but unsigned char */
216  unsigned char *cbuf;
217 
219  int dims[2];
220 
221  /* number of channels. */
222  int ch;
223 
224  /* display device used for color management */
226 
227  /* and the color, the alphas is get from the glyph!
228  * color is sRGB space */
229  float col_init[4];
230  /* cached conversion from 'col_init' */
231  unsigned char col_char[4];
232  float col_float[4];
233 
235 
236 typedef struct FontBLF {
237  /* font name. */
238  char *name;
239 
240  /* # of times this font was loaded */
241  unsigned int reference_count;
242 
244  char *filepath;
245 
246  /* Copied from the SFNT OS/2 table. Bit flags for unicode blocks and ranges
247  * considered "functional". Cached here because face might not always exist.
248  * See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur */
250 
251  /* aspect ratio or scale. */
252  float aspect[3];
253 
254  /* initial position for draw the text. */
255  int pos[3];
256 
257  /* angle in radians. */
258  float angle;
259 
260 #if 0 /* BLF_BLUR_ENABLE */
261  /* blur: 3 or 5 large kernel */
262  int blur;
263 #endif
264 
265  /* shadow level. */
266  int shadow;
267 
268  /* and shadow offset. */
269  int shadow_x;
270  int shadow_y;
271 
272  /* shadow color. */
273  unsigned char shadow_color[4];
274 
275  /* main text color. */
276  unsigned char color[4];
277 
278  /* Multiplied this matrix with the current one before
279  * draw the text! see blf_draw__start.
280  */
281  float m[16];
282 
283  /* clipping rectangle. */
285 
286  /* the width to wrap the text, see BLF_WORD_WRAP */
288 
289  /* Font DPI (default 72). */
290  unsigned int dpi;
291 
292  /* font size. */
293  float size;
294 
295  /* Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */
296  FT_MM_Var *variations;
297 
298  /* Character variation; 0=default, -1=min, +1=max. */
299  float char_weight;
300  float char_slant;
301  float char_width;
303 
304  /* max texture size. */
306 
307  /* font options. */
308  int flags;
309 
315 
316  /* Cache of unscaled kerning values. Will be NULL if font does not have kerning. */
318 
319  /* freetype2 lib handle. */
320  FT_Library ft_lib;
321 
322  /* Mutex lock for library */
324 
325  /* freetype2 face. */
326  FT_Face face;
327 
328  /* data for buffer usage (drawing into a texture buffer) */
330 
331  /* Mutex lock for glyph cache. */
334 
335 typedef struct DirBLF {
336  struct DirBLF *next;
337  struct DirBLF *prev;
338 
339  /* full path where search fonts. */
340  char *path;
#define BLI_INLINE
unsigned int uint
Definition: BLI_sys_types.h:67
pthread_spinlock_t SpinLock
Definition: BLI_threads.h:110
GPUBatch
Definition: GPU_batch.h:78
struct GPUTexture GPUTexture
Definition: GPU_texture.h:17
struct GPUVertBuf GPUVertBuf
#define FT_PIX_CEIL(x)
BatchBLF g_batch
Definition: blf_font.c:52
struct FontBufInfoBLF FontBufInfoBLF
struct GlyphBLF GlyphBLF
BLI_INLINE int ft_pix_to_int_floor(ft_pix v)
#define GLYPH_ASCII_TABLE_SIZE
struct DirBLF DirBLF
BLI_INLINE ft_pix ft_pix_from_float(float v)
int32_t ft_pix
BLI_INLINE ft_pix ft_pix_from_int(int v)
#define FT_PIX_DEFAULT_ROUNDING(x)
struct BatchBLF BatchBLF
#define KERNING_CACHE_TABLE_SIZE
BLI_INLINE ft_pix ft_pix_round_advance(ft_pix v, ft_pix step)
struct KerningCacheBLF KerningCacheBLF
BLI_INLINE int ft_pix_to_int(ft_pix v)
struct FontBLF FontBLF
BLI_INLINE int ft_pix_to_int_ceil(ft_pix v)
struct GlyphCacheBLF GlyphCacheBLF
ATTR_WARN_UNUSED_RESULT const BMVert * v
signed int int32_t
Definition: stdint.h:77
unsigned int pos_loc
struct GPUBatch * batch
unsigned int col_loc
unsigned int offset_loc
struct GPUVertBuf * verts
struct FontBLF * font
float mat[4][4]
struct GPUVertBufRaw pos_step col_step offset_step glyph_size_step
struct GlyphCacheBLF * glyph_cache
unsigned int glyph_len
unsigned int glyph_size_loc
struct DirBLF * next
struct DirBLF * prev
KerningCacheBLF * kerning_cache
unsigned int dpi
uint UnicodeRanges[4]
SpinLock * glyph_cache_mutex
unsigned char color[4]
float char_spacing
FT_MM_Var * variations
float aspect[3]
SpinLock * ft_lib_mutex
unsigned int reference_count
FT_Library ft_lib
ListBase cache
FontBufInfoBLF buf_info
float m[16]
unsigned char shadow_color[4]
unsigned char col_char[4]
unsigned char * cbuf
struct ColorManagedDisplay * display
unsigned char * bitmap
unsigned int c
struct GlyphCacheBLF * glyph_cache
struct GlyphBLF * prev
struct GlyphBLF * next
unsigned int dpi
struct GlyphBLF * glyph_ascii_table[GLYPH_ASCII_TABLE_SIZE]
GPUTexture * texture
struct GlyphCacheBLF * next
ListBase bucket[257]
struct GlyphCacheBLF * prev
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE]