Blender V5.3
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_enum_flags.hh"
19#include "BLI_map.hh"
20#include "BLI_mutex.hh"
21#include "BLI_vector.hh"
22
23#include "GPU_shader_shared.hh"
24#include "GPU_storage_buffer.hh"
25#include "GPU_texture.hh"
26
27#include <ft2build.h>
28
29namespace blender {
30
31struct FontBLF;
32struct GlyphCacheBLF;
33struct GlyphBLF;
34
35namespace gpu {
36class Batch;
37class VertBuf;
38} // namespace gpu
39struct GPUVertBufRaw;
40
41namespace ocio {
42class ColorSpace;
43} // namespace ocio
44using ColorSpace = ocio::ColorSpace;
45
46#include FT_MULTIPLE_MASTERS_H /* Variable font support. */
47
49#define BLF_VARIATIONS_MAX 16
50
51#define MAKE_DVAR_TAG(a, b, c, d) \
52 ((uint32_t(a) << 24u) | (uint32_t(b) << 16u) | (uint32_t(c) << 8u) | (uint32_t(d)))
53
54#define BLF_VARIATION_AXIS_WEIGHT MAKE_DVAR_TAG('w', 'g', 'h', 't') /* `wght` weight axis. */
55#define BLF_VARIATION_AXIS_SLANT MAKE_DVAR_TAG('s', 'l', 'n', 't') /* `slnt` slant axis. */
56#define BLF_VARIATION_AXIS_WIDTH MAKE_DVAR_TAG('w', 'd', 't', 'h') /* `wdth` width axis. */
57#define BLF_VARIATION_AXIS_SPACING MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* `spac` spacing axis. */
58#define BLF_VARIATION_AXIS_OPTSIZE MAKE_DVAR_TAG('o', 'p', 's', 'z') /* `opsz` optical size. */
59
60/* -------------------------------------------------------------------- */
66
72
73/* Macros copied from `include/freetype/internal/ftobjs.h`. */
74
75#define FT_PIX_FLOOR(x) ((x) & ~63)
76#define FT_PIX_ROUND(x) FT_PIX_FLOOR((x) + 32)
77#define FT_PIX_CEIL(x) ((x) + 63)
78
80{
81 return int(v >> 6);
82}
83
85{
86 return int(v >> 6); /* No need for explicit floor as the bits are removed when shifting. */
87}
88
90{
91 return (FT_PIX_CEIL(v) >> 6);
92}
93
95{
96 return v * 64;
97}
98
100{
101 return lroundf(v * 64.0f);
102}
103
105
106#define BLF_BATCH_DRAW_LEN_MAX 128 /* in glyph */
107
109#define KERNING_CACHE_TABLE_SIZE 128
110
112#define KERNING_ENTRY_UNSET INT_MAX
113
129
130extern BatchBLF g_batch;
131
139
143 friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
144 {
145 return a.charcode == b.charcode && a.subpixel == b.subpixel;
146 }
148 {
150 }
151};
152
180
181enum class GlyphFlagBLF : uint8_t {
182 None = 0,
187 Combining = (1 << 0),
188};
190
237
240 float *fbuf;
241
243 unsigned char *cbuf;
244
246 int dims[2];
247
253
256
261 float col_init[4];
263 unsigned char col_char[4];
264 float col_float[4];
265};
266
333
334struct FontBLF {
336 char *filepath;
337
339 const void *mem;
340 size_t mem_size;
342 char *mem_name;
343
350
352 std::atomic<uint32_t> reference_count;
353
355 float aspect[3];
356
358 int pos[3];
359
361 float angle;
362
365
369
371 unsigned char shadow_color[4];
372
374 unsigned char color[4];
375
378
382
384 float size;
385
387 FT_MM_Var *variations;
388
389 /* Character variations. */
390
399
402
405
411
414
416 FT_Library ft_lib;
417
419 FT_Face face;
420
422 FT_Size ft_size;
423
425 FT_Long face_flags;
426
429
432
435};
436
437} // namespace blender
#define FT_PIX_CEIL(x)
#define BLF_BATCH_DRAW_LEN_MAX
#define KERNING_CACHE_TABLE_SIZE
ENUM_OPERATORS(Layer::Flags)
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
ft_pix ft_pix_from_int(int v)
unsigned int uint
Definition BKE_text.h:55
BatchBLF g_batch
Definition blf_font.cc:61
ATTR_WARN_UNUSED_RESULT const BMVert * v
unsigned char uint8_t
Definition BKE_text.h:79
int ft_pix_to_int_ceil(ft_pix v)
ft_pix ft_pix_from_float(float v)
std::mutex Mutex
Definition BLI_mutex.hh:51
signed int int32_t
Definition BKE_text.h:78
int ft_pix_to_int(ft_pix v)
constexpr uint64_t get_default_hash(const T &v, const Args &...args)
Definition BLI_hash.hh:252
int ft_pix_to_int_floor(ft_pix v)
ocio::ColorSpace ColorSpace
Definition BLF_api.hh:42
GlyphCacheBLF * glyph_cache
GlyphQuad glyph_data[BLF_BATCH_DRAW_LEN_MAX]
gpu::StorageBuf * glyph_buf
unsigned char shadow_color[4]
FontBufInfoBLF buf_info
unsigned char color[4]
std::atomic< uint32_t > reference_count
Vector< std::unique_ptr< GlyphCacheBLF > > cache
KerningCacheBLF * kerning_cache
GlyphCacheBLF * glyph_cache
Map< GlyphCacheKey, std::unique_ptr< GlyphBLF > > glyphs
friend bool operator==(const GlyphCacheKey &a, const GlyphCacheKey &b)
int ascii_table[KERNING_CACHE_TABLE_SIZE][KERNING_CACHE_TABLE_SIZE]