Blender V5.0
blf_internal_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2008 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
11#include <atomic>
12#include <cmath>
13
14#include "DNA_vec_types.h"
15
16#include "BLF_api.hh"
17
18#include "BLI_map.hh"
19#include "BLI_mutex.hh"
20#include "BLI_vector.hh"
21
22#include "GPU_shader_shared.hh"
23#include "GPU_storage_buffer.hh"
24#include "GPU_texture.hh"
25
26#include <ft2build.h>
27
28struct FontBLF;
29struct GlyphCacheBLF;
30struct GlyphBLF;
31
32namespace blender::gpu {
33class Batch;
34class VertBuf;
35} // namespace blender::gpu
36struct GPUVertBufRaw;
37
38namespace blender::ocio {
39class ColorSpace;
40} // namespace blender::ocio
42
43#include FT_MULTIPLE_MASTERS_H /* Variable font support. */
44
46#define BLF_VARIATIONS_MAX 16
47
48#define MAKE_DVAR_TAG(a, b, c, d) \
49 ((uint32_t(a) << 24u) | (uint32_t(b) << 16u) | (uint32_t(c) << 8u) | (uint32_t(d)))
50
51#define BLF_VARIATION_AXIS_WEIGHT MAKE_DVAR_TAG('w', 'g', 'h', 't') /* `wght` weight axis. */
52#define BLF_VARIATION_AXIS_SLANT MAKE_DVAR_TAG('s', 'l', 'n', 't') /* `slnt` slant axis. */
53#define BLF_VARIATION_AXIS_WIDTH MAKE_DVAR_TAG('w', 'd', 't', 'h') /* `wdth` width axis. */
54#define BLF_VARIATION_AXIS_SPACING MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* `spac` spacing axis. */
55#define BLF_VARIATION_AXIS_OPTSIZE MAKE_DVAR_TAG('o', 'p', 's', 'z') /* `opsz` optical size. */
56
57/* -------------------------------------------------------------------- */
63
69
70/* Macros copied from `include/freetype/internal/ftobjs.h`. */
71
72#define FT_PIX_FLOOR(x) ((x) & ~63)
73#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
74#define FT_PIX_CEIL(x) ((x) + 63)
75
77{
78 return int(v >> 6);
79}
80
82{
83 return int(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
84}
85
87{
88 return (FT_PIX_CEIL(v) >> 6);
89}
90
92{
93 return v * 64;
94}
95
97{
98 return lroundf(v * 64.0f);
99}
100
102
103#define BLF_BATCH_DRAW_LEN_MAX 128 /* in glyph */
104
106#define KERNING_CACHE_TABLE_SIZE 128
107
109#define KERNING_ENTRY_UNSET INT_MAX
110
126
127extern BatchBLF g_batch;
128
136
139 uint8_t subpixel;
140 friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
141 {
142 return a.charcode == b.charcode && a.subpixel == b.subpixel;
143 }
145 {
147 }
148};
149
177
178struct GlyphBLF {
180 unsigned int c;
181
183 FT_UInt idx;
184
190
192 uint8_t subpixel;
193
197
200
205 unsigned char *bitmap;
206
208 int dims[2];
209 int pitch;
211
217 int pos[2];
218
220
221 ~GlyphBLF();
222};
223
226 float *fbuf;
227
229 unsigned char *cbuf;
230
232 int dims[2];
233
236
238 float col_init[4];
240 unsigned char col_char[4];
241 float col_float[4];
242};
243
309
310struct FontBLF {
312 char *filepath;
313
315 void *mem;
316 size_t mem_size;
318 char *mem_name;
319
326
328 std::atomic<uint32_t> reference_count;
329
331 float aspect[3];
332
334 int pos[3];
335
337 float angle;
338
341
345
347 unsigned char shadow_color[4];
348
350 unsigned char color[4];
351
354
358
360 float size;
361
363 FT_MM_Var *variations;
364
365 /* Character variations. */
366
375
378
381
387
390
392 FT_Library ft_lib;
393
395 FT_Face face;
396
398 FT_Size ft_size;
399
401 FT_Long face_flags;
402
405
408
411};
blender::ocio::ColorSpace ColorSpace
Definition BLF_api.hh:38
BLFWrapMode
Definition BLF_enums.hh:20
FontFlags
Definition BLF_enums.hh:31
FontShadowType
Definition BLF_enums.hh:13
unsigned int uint
BatchBLF g_batch
Definition blf_font.cc:59
#define FT_PIX_CEIL(x)
ft_pix ft_pix_from_float(float v)
ft_pix ft_pix_from_int(int v)
int32_t ft_pix
#define BLF_BATCH_DRAW_LEN_MAX
#define KERNING_CACHE_TABLE_SIZE
int ft_pix_to_int_floor(ft_pix v)
int ft_pix_to_int_ceil(ft_pix v)
int ft_pix_to_int(ft_pix v)
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned long long int uint64_t
uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:233
std::mutex Mutex
Definition BLI_mutex.hh:47
blender::gpu::Batch * batch
float mat[4][4]
GlyphCacheBLF * glyph_cache
GlyphQuad glyph_data[BLF_BATCH_DRAW_LEN_MAX]
blender::gpu::StorageBuf * glyph_buf
KerningCacheBLF * kerning_cache
uint unicode_ranges[4]
blender::Vector< std::unique_ptr< GlyphCacheBLF > > cache
unsigned char color[4]
FontFlags flags
FT_MM_Var * variations
std::atomic< uint32_t > reference_count
FontMetrics metrics
BLFWrapMode wrap_mode
FT_Library ft_lib
FontBufInfoBLF buf_info
FontShadowType shadow
blender::Mutex glyph_cache_mutex
unsigned char shadow_color[4]
const ColorSpace * colorspace
unsigned char col_char[4]
unsigned char * cbuf
GlyphCacheBLF * glyph_cache
unsigned char * bitmap
unsigned int c
blender::Map< GlyphCacheKey, std::unique_ptr< GlyphBLF > > glyphs
blender::gpu::Texture * texture
uint64_t hash() const
friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE]