Blender V4.5
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_texture.hh"
23#include "GPU_vertex_buffer.hh"
24
25#include <ft2build.h>
26
27struct FontBLF;
28struct GlyphCacheBLF;
29struct GlyphBLF;
30
31namespace blender::gpu {
32class Batch;
33class VertBuf;
34} // namespace blender::gpu
35struct GPUVertBufRaw;
36
37namespace blender::ocio {
38class Display;
39} // namespace blender::ocio
41
42#include FT_MULTIPLE_MASTERS_H /* Variable font support. */
43
45#define BLF_VARIATIONS_MAX 16
46
47#define MAKE_DVAR_TAG(a, b, c, d) \
48 ((uint32_t(a) << 24u) | (uint32_t(b) << 16u) | (uint32_t(c) << 8u) | (uint32_t(d)))
49
50#define BLF_VARIATION_AXIS_WEIGHT MAKE_DVAR_TAG('w', 'g', 'h', 't') /* `wght` weight axis. */
51#define BLF_VARIATION_AXIS_SLANT MAKE_DVAR_TAG('s', 'l', 'n', 't') /* `slnt` slant axis. */
52#define BLF_VARIATION_AXIS_WIDTH MAKE_DVAR_TAG('w', 'd', 't', 'h') /* `wdth` width axis. */
53#define BLF_VARIATION_AXIS_SPACING MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* `spac` spacing axis. */
54#define BLF_VARIATION_AXIS_OPTSIZE MAKE_DVAR_TAG('o', 'p', 's', 'z') /* `opsz` optical size. */
55
56/* -------------------------------------------------------------------- */
62
68
69/* Macros copied from `include/freetype/internal/ftobjs.h`. */
70
71#define FT_PIX_FLOOR(x) ((x) & ~63)
72#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
73#define FT_PIX_CEIL(x) ((x) + 63)
74
76{
77 return int(v >> 6);
78}
79
81{
82 return int(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
83}
84
86{
87 return (FT_PIX_CEIL(v) >> 6);
88}
89
91{
92 return v * 64;
93}
94
96{
97 return lroundf(v * 64.0f);
98}
99
101
102#define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
103
105#define KERNING_CACHE_TABLE_SIZE 128
106
108#define KERNING_ENTRY_UNSET INT_MAX
109
125
126extern BatchBLF g_batch;
127
135
138 uint8_t subpixel;
139 friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
140 {
141 return a.charcode == b.charcode && a.subpixel == b.subpixel;
142 }
144 {
146 }
147};
148
176
177struct GlyphBLF {
179 unsigned int c;
180
182 FT_UInt idx;
183
189
191 uint8_t subpixel;
192
196
199
204 unsigned char *bitmap;
205
207 int dims[2];
208 int pitch;
210
216 int pos[2];
217
219
220 ~GlyphBLF();
221};
222
225 float *fbuf;
226
228 unsigned char *cbuf;
229
231 int dims[2];
232
235
237 float col_init[4];
239 unsigned char col_char[4];
240 float col_float[4];
241};
242
308
309struct FontBLF {
311 char *filepath;
312
314 void *mem;
315 size_t mem_size;
317 char *mem_name;
318
325
327 std::atomic<uint32_t> reference_count;
328
330 float aspect[3];
331
333 int pos[3];
334
336 float angle;
337
340
344
346 unsigned char shadow_color[4];
347
349 unsigned char color[4];
350
353
357
359 float size;
360
362 FT_MM_Var *variations;
363
365 int char_weight; /* 100 - 900, 400 = normal. */
366 float char_slant; /* Slant in clockwise degrees. 0.0 = upright. */
367 float char_width; /* Factor of normal character width. 1.0 = normal. */
368 float char_spacing; /* Factor of normal character spacing. 0.0 = normal. */
369
372
374 int flags;
375
381
384
386 FT_Library ft_lib;
387
389 FT_Face face;
390
392 FT_Size ft_size;
393
395 FT_Long face_flags;
396
399
402
405};
BLFWrapMode
Definition BLF_api.hh:44
blender::ocio::Display ColorManagedDisplay
Definition BLF_api.hh:35
FontShadowType
Definition BLF_api.hh:37
unsigned int uint
#define Display
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 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
unsigned int pos_loc
unsigned int glyph_flags_loc
blender::gpu::Batch * batch
unsigned int col_loc
unsigned int offset_loc
float mat[4][4]
GlyphCacheBLF * glyph_cache
unsigned int glyph_len
GPUVertBufRaw pos_step
GPUVertBufRaw offset_step
unsigned int glyph_size_loc
GPUVertBufRaw glyph_flags_step
GPUVertBufRaw col_step
GPUVertBufRaw glyph_size_step
blender::gpu::VertBuf * verts
KerningCacheBLF * kerning_cache
uint unicode_ranges[4]
blender::Vector< std::unique_ptr< GlyphCacheBLF > > cache
unsigned char color[4]
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 ColorManagedDisplay * display
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
uint64_t hash() const
friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE]