Blender  V2.93
blf_internal_types.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2008 Blender Foundation.
17  * All rights reserved.
18  */
19 
24 #pragma once
25 
26 #include "GPU_texture.h"
27 #include "GPU_vertex_buffer.h"
28 
29 #define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
30 
31 typedef struct BatchBLF {
32  struct FontBLF *font; /* can only batch glyph from the same font */
33  struct GPUBatch *batch;
34  struct GPUVertBuf *verts;
35  struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step;
37  unsigned int glyph_len;
38  float ofs[2]; /* copy of font->pos */
39  float mat[4][4]; /* previous call modelmatrix. */
43 
44 extern BatchBLF g_batch;
45 
46 typedef struct KerningCacheBLF {
48 
49  /* kerning mode. */
50  FT_UInt mode;
51 
52  /* only cache a ascii glyph pairs. Only store the x
53  * offset we are interested in, instead of the full FT_Vector. */
54  int table[0x80][0x80];
56 
57 typedef struct GlyphCacheBLF {
60 
61  /* font size. */
62  unsigned int size;
63 
64  /* and dpi. */
65  unsigned int dpi;
66 
67  bool bold;
68  bool italic;
69 
70  /* and the glyphs. */
72 
73  /* fast ascii lookup */
75 
76  /* texture array, to draw the glyphs. */
82 
83  /* and the bigger glyph in the font. */
86 
87  /* number of glyphs in the font. */
89 
90  /* number of glyphs not yet loaded (decreases every glyph loaded). */
92 
93  /* ascender and descender value. */
94  float ascender;
95  float descender;
97 
98 typedef struct GlyphBLF {
99  struct GlyphBLF *next;
100  struct GlyphBLF *prev;
101 
102  /* and the character, as UTF8 */
103  unsigned int c;
104 
105  /* freetype2 index, to speed-up the search. */
106  FT_UInt idx;
107 
108  /* glyph box. */
110 
111  /* advance size. */
112  float advance;
113  /* avoid conversion to int while drawing */
115 
116  /* position inside the texture where this glyph is store. */
117  int offset;
118 
119  /* Bitmap data, from freetype. Take care that this
120  * can be NULL.
121  */
122  unsigned char *bitmap;
123 
124  /* Glyph width and height. */
125  int dims[2];
126  int pitch;
127 
133  int pos[2];
134 
137 
138 typedef struct FontBufInfoBLF {
139  /* for draw to buffer, always set this to NULL after finish! */
140  float *fbuf;
141 
142  /* the same but unsigned char */
143  unsigned char *cbuf;
144 
146  int dims[2];
147 
148  /* number of channels. */
149  int ch;
150 
151  /* display device used for color management */
153 
154  /* and the color, the alphas is get from the glyph!
155  * color is srgb space */
156  float col_init[4];
157  /* cached conversion from 'col_init' */
158  unsigned char col_char[4];
159  float col_float[4];
160 
162 
163 typedef struct FontBLF {
164  /* font name. */
165  char *name;
166 
167  /* # of times this font was loaded */
168  unsigned int reference_count;
169 
170  /* filename or NULL. */
171  char *filename;
172 
173  /* aspect ratio or scale. */
174  float aspect[3];
175 
176  /* initial position for draw the text. */
177  float pos[3];
178 
179  /* angle in radians. */
180  float angle;
181 
182 #if 0 /* BLF_BLUR_ENABLE */
183  /* blur: 3 or 5 large kernel */
184  int blur;
185 #endif
186 
187  /* shadow level. */
188  int shadow;
189 
190  /* and shadow offset. */
191  int shadow_x;
192  int shadow_y;
193 
194  /* shadow color. */
195  unsigned char shadow_color[4];
196 
197  /* main text color. */
198  unsigned char color[4];
199 
200  /* Multiplied this matrix with the current one before
201  * draw the text! see blf_draw__start.
202  */
203  float m[16];
204 
205  /* clipping rectangle. */
207 
208  /* the width to wrap the text, see BLF_WORD_WRAP */
210 
211  /* font dpi (default 72). */
212  unsigned int dpi;
213 
214  /* font size. */
215  unsigned int size;
216 
217  /* max texture size. */
219 
220  /* font options. */
221  int flags;
222 
223  /* List of glyph caches (GlyphCacheBLF) for this font for size, dpi, bold, italic.
224  * Use blf_glyph_cache_acquire(font) and blf_glyph_cache_release(font) to access cache!
225  */
227 
228  /* list of kerning cache for this font. */
230 
231  /* current kerning cache for this font and kerning mode. */
233 
234  /* freetype2 lib handle. */
235  FT_Library ft_lib;
236 
237  /* Mutex lock for library */
239 
240  /* freetype2 face. */
241  FT_Face face;
242 
243  /* freetype kerning */
244  FT_UInt kerning_mode;
245 
246  /* data for buffer usage (drawing into a texture buffer) */
248 
249  /* Mutex lock for glyph cache. */
252 
253 typedef struct DirBLF {
254  struct DirBLF *next;
255  struct DirBLF *prev;
256 
257  /* full path where search fonts. */
258  char *path;
pthread_spinlock_t SpinLock
Definition: BLI_threads.h:111
GPUBatch
Definition: GPU_batch.h:93
struct GPUTexture GPUTexture
Definition: GPU_texture.h:33
struct GPUVertBuf GPUVertBuf
BatchBLF g_batch
Definition: blf_font.c:67
struct FontBufInfoBLF FontBufInfoBLF
struct GlyphBLF GlyphBLF
struct DirBLF DirBLF
struct BatchBLF BatchBLF
struct KerningCacheBLF KerningCacheBLF
struct FontBLF FontBLF
struct GlyphCacheBLF GlyphCacheBLF
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
float ofs[2]
unsigned int glyph_len
unsigned int glyph_size_loc
struct DirBLF * next
struct DirBLF * prev
FT_UInt kerning_mode
KerningCacheBLF * kerning_cache
unsigned int dpi
SpinLock * glyph_cache_mutex
unsigned char color[4]
ListBase kerning_caches
unsigned int size
float aspect[3]
float pos[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
struct GlyphBLF * glyph_ascii_table[256]
unsigned int size
unsigned int dpi
GPUTexture * texture
struct GlyphCacheBLF * next
ListBase bucket[257]
struct GlyphCacheBLF * prev
struct KerningCacheBLF * next
int table[0x80][0x80]
struct KerningCacheBLF * prev