Blender V5.3
blf_glyph.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2009 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <algorithm>
12#include <cmath>
13#include <cstdio>
14#include <cstdlib>
15#include <cstring>
16
17#include <ft2build.h>
18
19#include FT_FREETYPE_H
20#include FT_GLYPH_H
21#include FT_OUTLINE_H
22#include FT_BITMAP_H
23#include FT_ADVANCES_H /* For FT_Get_Advance. */
24#include FT_MULTIPLE_MASTERS_H /* Variable font support. */
25
26#include "MEM_guardedalloc.h"
27
28#include "BLI_listbase.hh"
29#include "BLI_math_color_c.hh"
30#include "BLI_math_geom_c.hh"
31#include "BLI_rect.hh"
32
33#include "BLF_api.hh"
34
35#include "GPU_capabilities.hh"
36
37#include "blf_internal.hh"
38#include "blf_internal_types.hh"
39
40#include "BLI_string_utf8.hh"
41
42#ifndef WITH_HEADLESS
43# include "nanosvgrast.h"
44
45# include "svg_icons.h"
46#endif /* WITH_HEADLESS */
47
48#include "BLI_strict_flags.hh" /* IWYU pragma: keep. Keep last. */
49
50namespace blender {
51
57#define BLF_GAMMA_CORRECT_GLYPHS
58
59/* -------------------------------------------------------------------- */
62
66static FT_Fixed to_16dot16(const double val)
67{
68 return FT_Fixed(lround(val * 65536.0));
69}
70
74static float from_16dot16(const FT_Fixed value)
75{
76 return float(value) / 65536.0f;
77}
78
80
81/* -------------------------------------------------------------------- */
84
86{
87 for (const std::unique_ptr<GlyphCacheBLF> &gc : font->cache) {
88 if (gc->size == font->size && (gc->bold == ((font->flags & BLF_BOLD) != 0)) &&
89 (gc->italic == ((font->flags & BLF_ITALIC) != 0)) &&
90 (gc->char_weight == font->char_weight) && (gc->char_slant == font->char_slant) &&
91 (gc->char_width == font->char_width) && (gc->char_spacing == font->char_spacing))
92 {
93 return gc.get();
94 }
95 }
96 return nullptr;
97}
98
100{
101 std::unique_ptr<GlyphCacheBLF> gc = std::make_unique<GlyphCacheBLF>();
102
103 gc->size = font->size;
104 gc->bold = ((font->flags & BLF_BOLD) != 0);
105 gc->italic = ((font->flags & BLF_ITALIC) != 0);
106 gc->char_weight = font->char_weight;
107 gc->char_slant = font->char_slant;
108 gc->char_width = font->char_width;
109 gc->char_spacing = font->char_spacing;
110
111 blf_ensure_size(font);
112
113 /* Determine ideal fixed-width size for monospaced output. */
114 FT_UInt gindex = blf_get_char_index(font, U'0');
115 if (gindex && font->face) {
116 FT_Fixed advance = 0;
117 FT_Get_Advance(font->face, gindex, FT_LOAD_NO_HINTING, &advance);
118 /* Use CSS 'ch unit' width, advance of zero character. */
119 gc->fixed_width = int(advance >> 16);
120 }
121 else {
122 /* Font does not have a face or does not contain "0" so use CSS fallback of 1/2 of em. */
123 gc->fixed_width = int((font->ft_size->metrics.height / 2) >> 6);
124 }
125 gc->fixed_width = std::max(gc->fixed_width, 1);
126
127 font->cache.append(std::move(gc));
128
129 return font->cache.last().get();
130}
131
133{
134 font->glyph_cache_mutex.lock();
135
137
138 if (!gc) {
139 gc = blf_glyph_cache_new(font);
140 }
141
142 return gc;
143}
144
146{
147 font->glyph_cache_mutex.unlock();
148}
149
151{
152 this->glyphs.clear();
153 if (this->texture) {
155 }
156 if (this->bitmap_result) {
157 MEM_delete(this->bitmap_result);
158 }
159}
160
162{
163 std::lock_guard lock{font->glyph_cache_mutex};
164 font->cache.clear_and_shrink();
165}
166
173 const uint charcode,
174 const uint8_t subpixel)
175{
176 const std::unique_ptr<GlyphBLF> *ptr = gc->glyphs.lookup_ptr_as(
177 GlyphCacheKey{charcode, subpixel});
178 if (ptr != nullptr) {
179 return ptr->get();
180 }
181 return nullptr;
182}
183
184#ifdef BLF_GAMMA_CORRECT_GLYPHS
185
198{
199 /* The following is `char(powf(c / 256.0f, 1.0f / 1.43f) * 256.0f)`. */
200 static const uchar gamma[256] = {
201 0, 5, 9, 11, 14, 16, 19, 21, 23, 25, 26, 28, 30, 32, 34, 35, 37, 38,
202 40, 41, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64,
203 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85,
204 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
205 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122,
206 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 133, 134, 135, 136, 137, 138, 139,
207 140, 141, 142, 143, 143, 144, 145, 146, 147, 148, 149, 150, 151, 151, 152, 153, 154, 155,
208 156, 157, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 168, 169, 170,
209 171, 172, 173, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 182, 183, 184, 185,
210 186, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 198, 199,
211 200, 201, 201, 202, 203, 204, 205, 205, 206, 207, 208, 208, 209, 210, 211, 211, 212, 213,
212 214, 214, 215, 216, 217, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226,
213 227, 228, 229, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239,
214 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252,
215 253, 254, 254, 255};
216 return gamma[c];
217}
218
219#endif /* BLF_GAMMA_CORRECT_GLYPHS */
220
225 const FT_GlyphSlot glyph,
226 const uint charcode,
227 const FT_UInt glyph_index,
228 const uint8_t subpixel)
229{
230 std::unique_ptr<GlyphBLF> g = std::make_unique<GlyphBLF>();
231 g->c = charcode;
232 g->idx = glyph_index;
233 g->advance_x = ft_pix(glyph->advance.x);
234 g->subpixel = subpixel;
235 g->flags = GlyphFlagBLF::None;
236
237 /* Use the un-hinted advance as `advance.x` is rounded to whole pixels when hinting,
238 * so narrow glyphs at small sizes have a zero advance (an "l" at size 1 for e.g.).
239 *
240 * Check the code-point as well since some fonts use zero-width glyphs for spacing characters
241 * (the "." in LCD style digit fonts for e.g.), see #162036. */
242 if ((glyph->linearHoriAdvance == 0) && (BLI_wcwidth_or_error(char32_t(charcode)) == 0)) {
243 g->flags |= GlyphFlagBLF::Combining;
244 }
245
246 FT_BBox bbox;
247 FT_Outline_Get_CBox(&(glyph->outline), &bbox);
248 g->box_xmin = ft_pix(bbox.xMin);
249 g->box_xmax = ft_pix(bbox.xMax);
250 g->box_ymin = ft_pix(bbox.yMin);
251 g->box_ymax = ft_pix(bbox.yMax);
252
253 /* Used to improve advance when hinting is enabled. */
254 g->lsb_delta = ft_pix(glyph->lsb_delta);
255 g->rsb_delta = ft_pix(glyph->rsb_delta);
256
257 if (glyph->format == FT_GLYPH_FORMAT_BITMAP) {
258 /* This has been rendered and we have a bitmap. */
259 g->pos[0] = glyph->bitmap_left;
260 g->pos[1] = glyph->bitmap_top;
261 g->dims[0] = int(glyph->bitmap.width);
262 g->dims[1] = int(glyph->bitmap.rows);
263 g->pitch = glyph->bitmap.pitch;
264 g->num_channels = 1;
265
266 switch (glyph->bitmap.pixel_mode) {
267 case FT_PIXEL_MODE_LCD:
268 g->num_channels = 3;
269 g->dims[0] /= 3;
270 break;
271 case FT_PIXEL_MODE_LCD_V:
272 g->num_channels = 3;
273 g->dims[1] /= 3;
274 g->pitch *= 3;
275 break;
276 case FT_PIXEL_MODE_BGRA:
277 g->num_channels = 4;
278 break;
279 }
280
281 const int buffer_size = g->dims[0] * g->dims[1] * g->num_channels;
282 g->bitmap = MEM_new_array_uninitialized<uchar>(size_t(buffer_size), "glyph bitmap");
283
284 if (ELEM(glyph->bitmap.pixel_mode,
285 FT_PIXEL_MODE_GRAY,
286 FT_PIXEL_MODE_GRAY2,
287 FT_PIXEL_MODE_GRAY4))
288 {
289 /* Scale 1, 2, 4-bit gray to 8-bit. */
290 const char scale = char(255 / (glyph->bitmap.num_grays - 1));
291 for (int i = 0; i < buffer_size; i++) {
292#ifdef BLF_GAMMA_CORRECT_GLYPHS
293 /* Convert coverage amounts to perceptually-improved lightness values. */
294 g->bitmap[i] = blf_glyph_gamma(glyph->bitmap.buffer[i] * scale);
295#else
296 g->bitmap[i] = glyph->bitmap.buffer[i] * scale;
297#endif /* BLF_GAMMA_CORRECT_GLYPHS */
298 }
299 }
300 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
301 /* RGB (BGR) in successive columns. */
302 for (size_t y = 0; y < size_t(g->dims[1]); y++) {
303 for (size_t x = 0; x < size_t(g->dims[0]); x++) {
304 size_t offs_in = (y * size_t(glyph->bitmap.pitch)) + (x * size_t(g->num_channels));
305 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
306 (x * size_t(g->num_channels));
307 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
308 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
309 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
310 }
311 }
312 }
313 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
314 /* RGB (BGR) in successive ROWS. */
315 for (size_t y = 0; y < size_t(g->dims[1]); y++) {
316 for (size_t x = 0; x < size_t(g->dims[0]); x++) {
317 size_t offs_in = (y * size_t(glyph->bitmap.pitch) * size_t(g->num_channels)) + x;
318 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
319 (x * size_t(g->num_channels));
320 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in];
321 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch)];
322 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + size_t(glyph->bitmap.pitch) +
323 size_t(glyph->bitmap.pitch)];
324 }
325 }
326 }
327 else if (glyph->bitmap.pixel_mode == FT_PIXEL_MODE_BGRA) {
328 /* Convert from BGRA to RGBA. */
329 for (size_t y = 0; y < size_t(g->dims[1]); y++) {
330 for (size_t x = 0; x < size_t(g->dims[0]); x++) {
331 size_t offs_in = (y * size_t(g->pitch)) + (x * size_t(g->num_channels));
332 size_t offs_out = (y * size_t(g->dims[0]) * size_t(g->num_channels)) +
333 (x * size_t(g->num_channels));
334 g->bitmap[offs_out + 0] = glyph->bitmap.buffer[offs_in + 2];
335 g->bitmap[offs_out + 1] = glyph->bitmap.buffer[offs_in + 1];
336 g->bitmap[offs_out + 2] = glyph->bitmap.buffer[offs_in + 0];
337 g->bitmap[offs_out + 3] = glyph->bitmap.buffer[offs_in + 3];
338 }
339 }
340 }
341 else {
342 memcpy(g->bitmap, glyph->bitmap.buffer, size_t(buffer_size));
343 }
344 }
345
346 GlyphBLF *result = g.get();
347 GlyphCacheKey key = {charcode, subpixel};
348 gc->glyphs.add(key, std::move(g));
349 return result;
350}
351
352#ifndef WITH_HEADLESS
354{
355 /* Add an empty GlyphBLF to the cache and return it. With
356 * zero dimensions it will be skipped by blf_glyph_draw. */
357 std::unique_ptr<GlyphBLF> g = std::make_unique<GlyphBLF>();
358 g->c = charcode;
359 GlyphBLF *result = g.get();
360 GlyphCacheKey key = {charcode, 0};
361 gc->glyphs.add(key, std::move(g));
362 return result;
363}
364
366 const uint charcode,
367 const bool color,
368 FunctionRef<void(std::string &)> edit_source_cb = nullptr)
369{
370 std::string svg_source = blf_get_icon_svg(int(charcode) - BLF_ICON_OFFSET);
371 if (edit_source_cb) {
372 edit_source_cb(svg_source);
373 }
374
375 NSVGimage *image = nsvgParse(svg_source.data(), "px", 96.0f);
376
377 if (image == nullptr) {
378 return blf_glyph_cache_add_blank(gc, charcode);
379 }
380
381 if (image->width == 0 || image->height == 0) {
382 nsvgDelete(image);
383 return blf_glyph_cache_add_blank(gc, charcode);
384 }
385
386 NSVGrasterizer *rast = nsvgCreateRasterizer();
387 if (rast == nullptr) {
388 nsvgDelete(image);
389 return blf_glyph_cache_add_blank(gc, charcode);
390 }
391
392 float scale = (gc->size / 1600.0f);
393 const int dest_w = int(ceil(image->width * scale));
394 const int dest_h = int(ceil(image->height * scale));
395 scale = float(dest_w) / image->width;
396
397 Array<uchar> render_bmp(dest_w * dest_h * 4);
398
399 nsvgRasterize(rast, image, 0.0f, 0.0f, scale, render_bmp.data(), dest_w, dest_h, dest_w * 4);
400 nsvgDeleteRasterizer(rast);
401
402 /* Bitmaps vary in size, so calculate the offsets needed when drawn. */
403 const int offset_x = std::max(int(round((gc->size - (image->width * scale)) / 2.0f)),
404 int(-100.0f * scale));
405
406 const int offset_y = std::max(int(ceil((gc->size + float(dest_h)) / 2.0f)),
407 dest_h - int(100.0f * scale));
408
409 nsvgDelete(image);
410
411 std::unique_ptr<GlyphBLF> g = std::make_unique<GlyphBLF>();
412 g->c = charcode;
413 g->idx = 0;
414 g->advance_x = dest_w * 64;
415 g->subpixel = 0;
416 g->flags = GlyphFlagBLF::None;
417 g->box_xmin = 0;
418 g->box_xmax = dest_w * 64;
419 g->box_ymin = 0;
420 g->box_ymax = dest_h * 64;
421 g->lsb_delta = 0;
422 g->rsb_delta = 0;
423 g->pos[0] = offset_x;
424 g->pos[1] = offset_y;
425 g->dims[0] = dest_w;
426 g->dims[1] = dest_h;
427 g->pitch = dest_w;
428 g->num_channels = color ? 4 : 1;
429
430 const int buffer_size = g->dims[0] * g->dims[1] * g->num_channels;
431 g->bitmap = MEM_new_array_uninitialized<uchar>(size_t(buffer_size), "glyph bitmap");
432
433 if (color) {
434 memcpy(g->bitmap, render_bmp.data(), size_t(buffer_size));
435 }
436 else {
437 /* Convert from RGBA to coverage map. */
438 for (int64_t y = 0; y < int64_t(g->dims[1]); y++) {
439 for (int64_t x = 0; x < int64_t(g->dims[0]); x++) {
440 int64_t offs_in = (y * int64_t(dest_w) * 4) + (x * 4);
441 int64_t offs_out = (y * int64_t(g->dims[0]) + x);
442 g->bitmap[offs_out] = uchar(float(srgb_to_grayscale_byte(&render_bmp[offs_in])) *
443 (float(render_bmp[int64_t(offs_in + 3)]) / 255.0f));
444 }
445 }
446 }
447
448 GlyphBLF *result = g.get();
449 GlyphCacheKey key = {charcode, 0};
450 gc->glyphs.add(key, std::move(g));
451 return result;
452}
453#endif /* WITH_HEADLESS */
454
456
457/* -------------------------------------------------------------------- */
463
467 int coverage_bit; /* 0-122. -1 is N/A. */
468 /* Later we add primary script and language for Harfbuzz, data from
469 * https://en.wikipedia.org/wiki/Unicode_block */
470};
471
472static const UnicodeBlock unicode_blocks[] = {
473 /* Must be in ascending order by start of range. */
474 {0x0, 0x7F, 0}, /* Basic Latin. */
475 {0x80, 0xFF, 1}, /* Latin-1 Supplement. */
476 {0x100, 0x17F, 2}, /* Latin Extended-A. */
477 {0x180, 0x24F, 3}, /* Latin Extended-B. */
478 {0x250, 0x2AF, 4}, /* IPA Extensions. */
479 {0x2B0, 0x2FF, 5}, /* Spacing Modifier Letters. */
480 {0x300, 0x36F, 6}, /* Combining Diacritical Marks. */
481 {0x370, 0x3FF, 7}, /* Greek. */
482 {0x400, 0x52F, 9}, /* Cyrillic. */
483 {0x530, 0x58F, 10}, /* Armenian. */
484 {0x590, 0x5FF, 11}, /* Hebrew. */
485 {0x600, 0x6FF, 13}, /* Arabic. */
486 {0x700, 0x74F, 71}, /* Syriac. */
487 {0x750, 0x77F, 13}, /* Arabic Supplement. */
488 {0x780, 0x7BF, 72}, /* Thaana. */
489 {0x7C0, 0x7FF, 14}, /* NKo. */
490 {0x800, 0x83F, -1}, /* Samaritan. */
491 {0x840, 0x85F, -1}, /* Mandaic. */
492 {0x900, 0x97F, 15}, /* Devanagari. */
493 {0x980, 0x9FF, 16}, /* Bengali. */
494 {0xA00, 0xA7F, 17}, /* Gurmukhi. */
495 {0xA80, 0xAFF, 18}, /* Gujarati. */
496 {0xB00, 0xB7F, 19}, /* Oriya. */
497 {0xB80, 0xBFF, 20}, /* Tamil. */
498 {0xC00, 0xC7F, 21}, /* Telugu. */
499 {0xC80, 0xCFF, 22}, /* Kannada. */
500 {0xD00, 0xD7F, 23}, /* Malayalam. */
501 {0xD80, 0xDFF, 73}, /* Sinhala. */
502 {0xE00, 0xE7F, 24}, /* Thai. */
503 {0xE80, 0xEFF, 25}, /* Lao. */
504 {0xF00, 0xFFF, 70}, /* Tibetan. */
505 {0x1000, 0x109F, 74}, /* Myanmar. */
506 {0x10A0, 0x10FF, 26}, /* Georgian. */
507 {0x1100, 0x11FF, 28}, /* Hangul Jamo. */
508 {0x1200, 0x139F, 75}, /* Ethiopic. */
509 {0x13A0, 0x13FF, 76}, /* Cherokee. */
510 {0x1400, 0x167F, 77}, /* Canadian Aboriginal. */
511 {0x1680, 0x169F, 78}, /* Ogham. */
512 {0x16A0, 0x16FF, 79}, /* unic. */
513 {0x1700, 0x171F, 84}, /* Tagalog. */
514 {0x1720, 0x173F, 84}, /* Hanunoo. */
515 {0x1740, 0x175F, 84}, /* Buhid. */
516 {0x1760, 0x177F, 84}, /* Tagbanwa. */
517 {0x1780, 0x17FF, 80}, /* Khmer. */
518 {0x1800, 0x18AF, 81}, /* Mongolian. */
519 {0x1900, 0x194F, 93}, /* Limbu. */
520 {0x1950, 0x197F, 94}, /* Tai Le. */
521 {0x1980, 0x19DF, 95}, /* New Tai Lue. */
522 {0x19E0, 0x19FF, 80}, /* Khmer. */
523 {0x1A00, 0x1A1F, 96}, /* Buginese. */
524 {0x1A20, 0x1AAF, -1}, /* Tai Tham. */
525 {0x1B00, 0x1B7F, 27}, /* Balinese. */
526 {0x1B80, 0x1BBF, 112}, /* Sundanese. */
527 {0x1BC0, 0x1BFF, -1}, /* Batak. */
528 {0x1C00, 0x1C4F, 113}, /* Lepcha. */
529 {0x1C50, 0x1C7F, 114}, /* Ol Chiki. */
530 {0x1D00, 0x1DBF, 4}, /* IPA Extensions. */
531 {0x1DC0, 0x1DFF, 6}, /* Combining Diacritical Marks. */
532 {0x1E00, 0x1EFF, 29}, /* Latin Extended Additional. */
533 {0x1F00, 0x1FFF, 30}, /* Greek Extended. */
534 {0x2000, 0x206F, 31}, /* General Punctuation. */
535 {0x2070, 0x209F, 32}, /* Superscripts And Subscripts. */
536 {0x20A0, 0x20CF, 33}, /* Currency Symbols. */
537 {0x20D0, 0x20FF, 34}, /* Combining Diacritical Marks For Symbols. */
538 {0x2100, 0x214F, 35}, /* Letterlike Symbols. */
539 {0x2150, 0x218F, 36}, /* Number Forms. */
540 {0x2190, 0x21FF, 37}, /* Arrows. */
541 {0x2200, 0x22FF, 38}, /* Mathematical Operators. */
542 {0x2300, 0x23FF, 39}, /* Miscellaneous Technical. */
543 {0x2400, 0x243F, 40}, /* Control Pictures. */
544 {0x2440, 0x245F, 41}, /* Optical Character Recognition. */
545 {0x2460, 0x24FF, 42}, /* Enclosed Alphanumerics. */
546 {0x2500, 0x257F, 43}, /* Box Drawing. */
547 {0x2580, 0x259F, 44}, /* Block Elements. */
548 {0x25A0, 0x25FF, 45}, /* Geometric Shapes. */
549 {0x2600, 0x26FF, 46}, /* Miscellaneous Symbols. */
550 {0x2700, 0x27BF, 47}, /* Dingbats. */
551 {0x27C0, 0x27EF, 38}, /* Mathematical Operators. */
552 {0x27F0, 0x27FF, 37}, /* Arrows. */
553 {0x2800, 0x28FF, 82}, /* Braille. */
554 {0x2900, 0x297F, 37}, /* Arrows. */
555 {0x2980, 0x2AFF, 38}, /* Mathematical Operators. */
556 {0x2B00, 0x2BFF, 37}, /* Arrows. */
557 {0x2C00, 0x2C5F, 97}, /* Glagolitic. */
558 {0x2C60, 0x2C7F, 29}, /* Latin Extended Additional. */
559 {0x2C80, 0x2CFF, 8}, /* Coptic. */
560 {0x2D00, 0x2D2F, 26}, /* Georgian. */
561 {0x2D30, 0x2D7F, 98}, /* Tifinagh. */
562 {0x2D80, 0x2DDF, 75}, /* Ethiopic. */
563 {0x2DE0, 0x2DFF, 9}, /* Cyrillic. */
564 {0x2E00, 0x2E7F, 31}, /* General Punctuation. */
565 {0x2E80, 0x2FFF, 59}, /* CJK Unified Ideographs. */
566 {0x3000, 0x303F, 48}, /* CJK Symbols And Punctuation. */
567 {0x3040, 0x309F, 49}, /* Hiragana. */
568 {0x30A0, 0x30FF, 50}, /* Katakana. */
569 {0x3100, 0x312F, 51}, /* Bopomofo. */
570 {0x3130, 0x318F, 52}, /* Hangul Compatibility Jamo. */
571 {0x3190, 0x319F, 59}, /* CJK Unified Ideographs. */
572 {0x31A0, 0x31BF, 51}, /* Bopomofo. */
573 {0x31C0, 0x31EF, 59}, /* CJK Unified Ideographs. */
574 {0x31F0, 0x31FF, 50}, /* Katakana. */
575 {0x3200, 0x32FF, 54}, /* Enclosed CJK Letters And Months. */
576 {0x3300, 0x33FF, 55}, /* CJK Compatibility. */
577 {0x3400, 0x4DBF, 59}, /* CJK Unified Ideographs. */
578 {0x4DC0, 0x4DFF, 99}, /* Yijing. */
579 {0x4E00, 0x9FFF, 59}, /* CJK Unified Ideographs. */
580 {0xA000, 0xA4CF, 83}, /* Yi. */
581 {0xA4D0, 0xA4FF, -1}, /* Lisu. */
582 {0xA500, 0xA63F, 12}, /* Vai. */
583 {0xA640, 0xA69F, 9}, /* Cyrillic. */
584 {0xA6A0, 0xA6FF, -1}, /* Bamum. */
585 {0xA700, 0xA71F, 5}, /* Spacing Modifier Letters. */
586 {0xA720, 0xA7FF, 29}, /* Latin Extended Additional. */
587 {0xA800, 0xA82F, 100}, /* Syloti Nagri. */
588 {0xA840, 0xA87F, 53}, /* Phags-pa. */
589 {0xA880, 0xA8DF, 115}, /* Saurashtra. */
590 {0xA900, 0xA92F, 116}, /* Kayah Li. */
591 {0xA930, 0xA95F, 117}, /* Rejang. */
592 {0xA960, 0xA97F, 56}, /* Hangul Syllables. */
593 {0xA980, 0xA9DF, -1}, /* Javanese. */
594 {0xA9E0, 0xA9FF, 74}, /* Myanmar. */
595 {0xAA00, 0xAA5F, 118}, /* Cham. */
596 {0xAA60, 0xAA7F, 74}, /* Myanmar. */
597 {0xAA80, 0xAADF, -1}, /* Tai Viet. */
598 {0xAAE0, 0xAAFF, -1}, /* Meetei Mayek. */
599 {0xAB00, 0xAB2F, 75}, /* Ethiopic. */
600 {0xAB70, 0xABBF, 76}, /* Cherokee. */
601 {0xABC0, 0xABFF, -1}, /* Meetei Mayek. */
602 {0xAC00, 0xD7AF, 56}, /* Hangul Syllables. */
603 {0xD800, 0xDFFF, 57}, /* Non-Plane 0. */
604 {0xE000, 0xF6FF, 60}, /* Private Use Area. */
605 {0xE700, 0xEFFF, -1}, /* MS Wingdings. */
606 {0xF000, 0xF8FF, -1}, /* MS Symbols. */
607 {0xF900, 0xFAFF, 61}, /* CJK Compatibility Ideographs. */
608 {0xFB00, 0xFB4F, 62}, /* Alphabetic Presentation Forms. */
609 {0xFB50, 0xFDFF, 63}, /* Arabic Presentation Forms-A. */
610 {0xFE00, 0xFE0F, 91}, /* Variation Selectors. */
611 {0xFE10, 0xFE1F, 65}, /* CJK Compatibility Forms. */
612 {0xFE20, 0xFE2F, 64}, /* Combining Half Marks. */
613 {0xFE30, 0xFE4F, 65}, /* CJK Compatibility Forms. */
614 {0xFE50, 0xFE6F, 66}, /* Small Form Variants. */
615 {0xFE70, 0xFEFF, 67}, /* Arabic Presentation Forms-B. */
616 {0xFF00, 0xFFEF, 68}, /* Half-width And Full-width Forms. */
617 {0xFFF0, 0xFFFF, 69}, /* Specials. */
618 {0x10000, 0x1013F, 101}, /* Linear B. */
619 {0x10140, 0x1018F, 102}, /* Ancient Greek Numbers. */
620 {0x10190, 0x101CF, 119}, /* Ancient Symbols. */
621 {0x101D0, 0x101FF, 120}, /* Phaistos Disc. */
622 {0x10280, 0x1029F, 121}, /* Lycian. */
623 {0x102A0, 0x102DF, 121}, /* Carian. */
624 {0x10300, 0x1032F, 85}, /* Old Italic. */
625 {0x10330, 0x1034F, 86}, /* Gothic. */
626 {0x10350, 0x1037F, -1}, /* Old Permic. */
627 {0x10380, 0x1039F, 103}, /* Ugaritic. */
628 {0x103A0, 0x103DF, 104}, /* Old Persian. */
629 {0x10400, 0x1044F, 87}, /* Deseret. */
630 {0x10450, 0x1047F, 105}, /* Shavian. */
631 {0x10480, 0x104AF, 106}, /* Osmanya. */
632 {0x104B0, 0x104FF, -1}, /* Osage. */
633 {0x10500, 0x1052F, -1}, /* Elbasan. */
634 {0x10530, 0x1056F, -1}, /* Caucasian Albanian. */
635 {0x10570, 0x105BF, -1}, /* Vithkuqi. */
636 {0x10600, 0x1077F, -1}, /* Linear A. */
637 {0x10780, 0x107BF, 3}, /* Latin Extended-B. */
638 {0x10800, 0x1083F, 107}, /* Cypriot Syllabary. */
639 {0x10840, 0x1085F, -1}, /* Imperial Aramaic. */
640 {0x10860, 0x1087F, -1}, /* Palmyrene. */
641 {0x10880, 0x108AF, -1}, /* Nabataean. */
642 {0x108E0, 0x108FF, -1}, /* Hatran. */
643 {0x10900, 0x1091F, 58}, /* Phoenician. */
644 {0x10920, 0x1093F, 121}, /* Lydian. */
645 {0x10980, 0x1099F, -1}, /* Meroitic Hieroglyphs. */
646 {0x109A0, 0x109FF, -1}, /* Meroitic Cursive. */
647 {0x10A00, 0x10A5F, 108}, /* Kharoshthi. */
648 {0x10A60, 0x10A7F, -1}, /* Old South Arabian. */
649 {0x10A80, 0x10A9F, -1}, /* Old North Arabian. */
650 {0x10AC0, 0x10AFF, -1}, /* Manichaean. */
651 {0x10B00, 0x10B3F, -1}, /* Avestan. */
652 {0x10B40, 0x10B5F, -1}, /* Inscriptional Parthian. */
653 {0x10B60, 0x10B7F, -1}, /* Inscriptional Pahlavi. */
654 {0x10B80, 0x10BAF, -1}, /* Psalter Pahlavi. */
655 {0x10C00, 0x10C4F, -1}, /* Old Turkic. */
656 {0x10C80, 0x10CFF, -1}, /* Old Hungarian. */
657 {0x10D00, 0x10D3F, -1}, /* Hanifi Rohingya. */
658 {0x108E0, 0x10E7F, -1}, /* Rumi Numeral Symbols. */
659 {0x10E80, 0x10EBF, -1}, /* Yezidi. */
660 {0x10F00, 0x10F2F, -1}, /* Old Sogdian. */
661 {0x10F30, 0x10F6F, -1}, /* Sogdian. */
662 {0x10F70, 0x10FAF, -1}, /* Old Uyghur. */
663 {0x10FB0, 0x10FDF, -1}, /* Chorasmian. */
664 {0x10FE0, 0x10FFF, -1}, /* Elymaic. */
665 {0x11000, 0x1107F, -1}, /* Brahmi. */
666 {0x11080, 0x110CF, -1}, /* Kaithi. */
667 {0x110D0, 0x110FF, -1}, /* Sora Sompeng. */
668 {0x11100, 0x1114F, -1}, /* Chakma. */
669 {0x11150, 0x1117F, -1}, /* Mahajani. */
670 {0x11180, 0x111DF, -1}, /* Sharada. */
671 {0x111E0, 0x111FF, -1}, /* Sinhala Archaic Numbers. */
672 {0x11200, 0x1124F, -1}, /* Khojki. */
673 {0x11280, 0x112AF, -1}, /* Multani. */
674 {0x112B0, 0x112FF, -1}, /* Khudawadi. */
675 {0x11300, 0x1137F, -1}, /* Grantha. */
676 {0x11400, 0x1147F, -1}, /* Newa. */
677 {0x11480, 0x114DF, -1}, /* Tirhuta. */
678 {0x11580, 0x115FF, -1}, /* Siddham. */
679 {0x11600, 0x1165F, -1}, /* Modi. */
680 {0x11660, 0x1167F, 81}, /* Mongolian. */
681 {0x11680, 0x116CF, -1}, /* Takri. */
682 {0x11700, 0x1174F, -1}, /* Ahom. */
683 {0x11800, 0x1184F, -1}, /* Dogra. */
684 {0x118A0, 0x118FF, -1}, /* Warang Citi. */
685 {0x11900, 0x1195F, -1}, /* Dives Akuru. */
686 {0x119A0, 0x119FF, -1}, /* Nandinagari. */
687 {0x11A00, 0x11A4F, -1}, /* Zanabazar Square. */
688 {0x11A50, 0x11AAF, -1}, /* Soyombo. */
689 {0x11AB0, 0x11ABF, 77}, /* Canadian Aboriginal Syllabics. */
690 {0x11AC0, 0x11AFF, -1}, /* Pau Cin Hau. */
691 {0x11C00, 0x11C6F, -1}, /* Bhaiksuki. */
692 {0x11C70, 0x11CBF, -1}, /* Marchen. */
693 {0x11D00, 0x11D5F, -1}, /* Masaram Gondi. */
694 {0x11D60, 0x11DAF, -1}, /* Gunjala Gondi. */
695 {0x11EE0, 0x11EFF, -1}, /* Makasar. */
696 {0x11FB0, 0x11FBF, -1}, /* Lisu. */
697 {0x11FC0, 0x11FFF, 20}, /* Tamil. */
698 {0x12000, 0x1254F, 110}, /* Cuneiform. */
699 {0x12F90, 0x12FFF, -1}, /* Cypro-Minoan. */
700 {0x13000, 0x1343F, -1}, /* Egyptian Hieroglyphs. */
701 {0x14400, 0x1467F, -1}, /* Anatolian Hieroglyphs. */
702 {0x16800, 0x16A3F, -1}, /* Bamum. */
703 {0x16A40, 0x16A6F, -1}, /* Mro. */
704 {0x16A70, 0x16ACF, -1}, /* Tangsa. */
705 {0x16AD0, 0x16AFF, -1}, /* Bassa Vah. */
706 {0x16B00, 0x16B8F, -1}, /* Pahawh Hmong. */
707 {0x16E40, 0x16E9F, -1}, /* Medefaidrin. */
708 {0x16F00, 0x16F9F, -1}, /* Miao. */
709 {0x16FE0, 0x16FFF, -1}, /* Ideographic Symbols. */
710 {0x17000, 0x18AFF, -1}, /* Tangut. */
711 {0x1B170, 0x1B2FF, -1}, /* Nushu. */
712 {0x1BC00, 0x1BC9F, -1}, /* Duployan. */
713 {0x1D000, 0x1D24F, 88}, /* Musical Symbols. */
714 {0x1D2E0, 0x1D2FF, -1}, /* Mayan Numerals. */
715 {0x1D300, 0x1D35F, 109}, /* Tai Xuan Jing. */
716 {0x1D360, 0x1D37F, 111}, /* Counting Rod Numerals. */
717 {0x1D400, 0x1D7FF, 89}, /* Mathematical Alphanumeric Symbols. */
718 {0x1E2C0, 0x1E2FF, -1}, /* Wancho. */
719 {0x1E800, 0x1E8DF, -1}, /* Mende Kikakui. */
720 {0x1E900, 0x1E95F, -1}, /* Adlam. */
721 {0x1EC70, 0x1ECBF, -1}, /* Indic Siyaq Numbers. */
722 {0x1F000, 0x1F02F, 122}, /* Mahjong Tiles. */
723 {0x1F030, 0x1F09F, 122}, /* Domino Tiles. */
724 {0x1F600, 0x1F64F, -1}, /* Emoticons. */
725 {0x20000, 0x2A6DF, 59}, /* CJK Unified Ideographs. */
726 {0x2F800, 0x2FA1F, 61}, /* CJK Compatibility Ideographs. */
727 {0xE0000, 0xE007F, 92}, /* Tags. */
728 {0xE0100, 0xE01EF, 91}, /* Variation Selectors. */
729 {0xF0000, 0x10FFFD, 90}}; /* Private Use Supplementary. */
730
735{
736 if (charcode < 0x80) {
737 /* Shortcut to Basic Latin. */
738 return &unicode_blocks[0];
739 }
740
741 /* Binary search for other blocks. */
742
743 int min = 0;
744 int max = int(ARRAY_SIZE(unicode_blocks)) - 1;
745
746 if (charcode < unicode_blocks[0].first || charcode > unicode_blocks[max].last) {
747 return nullptr;
748 }
749
750 while (max >= min) {
751 const int mid = (min + max) / 2;
752 if (charcode > unicode_blocks[mid].last) {
753 min = mid + 1;
754 }
755 else if (charcode < unicode_blocks[mid].first) {
756 max = mid - 1;
757 }
758 else {
759 return &unicode_blocks[mid];
760 }
761 }
762
763 return nullptr;
764}
765
766static int blf_charcode_to_coverage_bit(const uint charcode)
767{
768 int coverage_bit = -1;
769 const UnicodeBlock *block = blf_charcode_to_unicode_block(charcode);
770 if (block) {
771 coverage_bit = block->coverage_bit;
772 }
773
774 if (coverage_bit < 0 && charcode > 0xFFFF) {
775 /* No coverage bit, but OpenType specs v.1.3+ says bit 57 implies that there
776 * are code-points supported beyond the BMP, so only check fonts with this set. */
777 coverage_bit = 57;
778 }
779
780 return coverage_bit;
781}
782
783static bool blf_font_has_coverage_bit(const FontBLF *font, const int coverage_bit)
784{
785 if (coverage_bit < 0) {
786 return false;
787 }
788 return (font->unicode_ranges[uint(coverage_bit) >> 5] & (1u << (uint(coverage_bit) % 32)));
789}
790
795FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode)
796{
797 FT_UInt glyph_index = blf_get_char_index(*font, charcode);
798 if (glyph_index) {
799 return glyph_index;
800 }
801
802 /* Fallback disabled. */
803 if ((*font)->flags & BLF_NO_FALLBACK) {
804 return 0;
805 }
806
807 /* First look in fonts that match the coverage bit. */
808 int coverage_bit = blf_charcode_to_coverage_bit(charcode);
809 for (int i = 0; i < BLF_MAX_FONT; i++) {
810 FontBLF *f = global_font[i];
811 if (!f || f == *font || !(f->flags & BLF_DEFAULT) ||
812 (!((*font)->flags & BLF_MONOSPACED) && (f->flags & BLF_MONOSPACED)) ||
814 {
815 continue;
816 }
817 if (coverage_bit < 0 || blf_font_has_coverage_bit(f, coverage_bit)) {
818 glyph_index = blf_get_char_index(f, charcode);
819 if (glyph_index) {
820 *font = f;
821 return glyph_index;
822 }
823 }
824 }
825
826 /* Next look in the rest. */
827 for (int i = 0; i < BLF_MAX_FONT; i++) {
828 FontBLF *f = global_font[i];
829 if (!f || f == *font || !(f->flags & BLF_DEFAULT)) {
830 continue;
831 }
832 if (coverage_bit >= 0 && !blf_font_has_coverage_bit(f, coverage_bit)) {
833 glyph_index = blf_get_char_index(f, charcode);
834 if (glyph_index) {
835 *font = f;
836 return glyph_index;
837 }
838 }
839 }
840
841#ifndef NDEBUG
842 /* Disable this print even in debug mode as it floods the console
843 * when browsing a file-system containing unknown characters. */
844 // printf("Unicode character U+%04X not found in loaded fonts. \n", charcode);
845#endif
846
847 return 0;
848}
849
851
852/* -------------------------------------------------------------------- */
855
859static FT_GlyphSlot blf_glyph_load(FontBLF *font,
860 const FT_UInt glyph_index,
861 const bool outline_only)
862{
863 int load_flags;
864
865 if (outline_only) {
866 load_flags = FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP;
867 }
868 else if (font->flags & BLF_MONOCHROME) {
869 load_flags = FT_LOAD_TARGET_MONO;
870 }
871 else {
872 load_flags = FT_LOAD_NO_BITMAP;
873 if (font->flags & BLF_HINTING_NONE) {
874 load_flags |= FT_LOAD_TARGET_NORMAL | FT_LOAD_NO_HINTING;
875 }
876 else if (font->flags & BLF_HINTING_SLIGHT) {
877 load_flags |= FT_LOAD_TARGET_LIGHT;
878 }
879 else if (font->flags & BLF_HINTING_FULL) {
880 load_flags |= FT_LOAD_TARGET_NORMAL;
881 }
882 else {
883 /* Default "Auto" is Slight (vertical only) hinting. */
884 load_flags |= FT_LOAD_TARGET_LIGHT;
885 }
886 }
887
888 if (!outline_only && FT_HAS_COLOR(font->face)) {
889 load_flags |= FT_LOAD_COLOR;
890 }
891
892 if (FT_Load_Glyph(font->face, glyph_index, load_flags) == FT_Err_Ok) {
893 return font->face->glyph;
894 }
895 return nullptr;
896}
897
899
900/* -------------------------------------------------------------------- */
903
907static bool blf_glyph_render_bitmap(FontBLF *font, FT_GlyphSlot glyph)
908{
909 int render_mode;
910
911 if (font->flags & BLF_MONOCHROME) {
912 render_mode = FT_RENDER_MODE_MONO;
913 }
914 else if (font->flags & BLF_HINTING_SLIGHT) {
915 render_mode = FT_RENDER_MODE_LIGHT;
916 }
917 else {
918 render_mode = FT_RENDER_MODE_NORMAL;
919 }
920
921 /* Render the glyph curves to a bitmap. */
922 FT_Error err = FT_Render_Glyph(glyph, FT_Render_Mode(render_mode));
923 if (err != FT_Err_Ok) {
924 return false;
925 }
926
927 if (ELEM(glyph->bitmap.pixel_mode, FT_PIXEL_MODE_MONO, FT_PIXEL_MODE_GRAY2, FT_PIXEL_MODE_GRAY4))
928 {
929 /* Convert to 8 bit per pixel */
930 FT_Bitmap tempbitmap;
931 FT_Bitmap_New(&tempbitmap);
932
933 /* Does Blender use Pitch 1 always? It works so far */
934 err += FT_Bitmap_Convert(font->ft_lib, &glyph->bitmap, &tempbitmap, 1);
935 err += FT_Bitmap_Copy(font->ft_lib, &tempbitmap, &glyph->bitmap);
936 err += FT_Bitmap_Done(font->ft_lib, &tempbitmap);
937 }
938
939 return (err == FT_Err_Ok);
940}
941
943
944/* -------------------------------------------------------------------- */
947
955static const FT_Var_Axis *blf_var_axis_by_tag(const FT_MM_Var *variations,
956 const uint32_t tag,
957 int *r_axis_index)
958{
959 *r_axis_index = -1;
960 if (!variations) {
961 return nullptr;
962 }
963 for (int i = 0; i < int(variations->num_axis); i++) {
964 if (variations->axis[i].tag == tag) {
965 *r_axis_index = i;
966 return &(variations->axis)[i];
967 }
968 }
969 return nullptr;
970}
971
981[[maybe_unused]] static FT_Fixed blf_factor_to_coordinate(const FT_Var_Axis *axis,
982 const float factor)
983{
984 FT_Fixed value = axis->def;
985 if (factor > 0) {
986 /* Map 0-1 to axis->def - axis->maximum */
987 value += FT_Fixed(double(axis->maximum - axis->def) * factor);
988 }
989 else if (factor < 0) {
990 /* Map -1-0 to axis->minimum - axis->def */
991 value += FT_Fixed(double(axis->def - axis->minimum) * factor);
992 }
993 return value;
994}
995
1007[[maybe_unused]] static bool blf_glyph_set_variation_normalized(const FontBLF *font,
1008 FT_Fixed coords[],
1009 const uint32_t tag,
1010 const float factor)
1011{
1012 int axis_index;
1013 const FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index);
1014 if (axis && (axis_index < BLF_VARIATIONS_MAX)) {
1015 coords[axis_index] = blf_factor_to_coordinate(axis, factor);
1016 return true;
1017 }
1018 return false;
1019}
1020
1030 FT_Fixed coords[],
1031 uint32_t tag,
1032 float *value)
1033{
1034 int axis_index;
1035 const FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index);
1036 if (axis && (axis_index < BLF_VARIATIONS_MAX)) {
1037 FT_Fixed int_value = to_16dot16(*value);
1038 CLAMP(int_value, axis->minimum, axis->maximum);
1039 coords[axis_index] = int_value;
1040 *value = from_16dot16(int_value);
1041 return true;
1042 }
1043 return false;
1044}
1045
1054 FT_Fixed coords[],
1055 float current_weight,
1056 float target_weight)
1057{
1058 float value = target_weight;
1059 if (blf_glyph_set_variation_float(font, coords, BLF_VARIATION_AXIS_WEIGHT, &value)) {
1060 return value;
1061 }
1062 return current_weight;
1063}
1064
1073 FT_Fixed coords[],
1074 float current_degrees,
1075 float target_degrees)
1076{
1077 float value = -target_degrees;
1078 if (blf_glyph_set_variation_float(font, coords, BLF_VARIATION_AXIS_SLANT, &value)) {
1079 return -value;
1080 }
1081 return current_degrees;
1082}
1083
1092 FT_Fixed coords[],
1093 float current_width,
1094 float target_width)
1095{
1096 float value = target_width * 100.0f;
1097 if (blf_glyph_set_variation_float(font, coords, BLF_VARIATION_AXIS_WIDTH, &value)) {
1098 return value / 100.0f;
1099 }
1100 return current_width;
1101}
1102
1111 FT_Fixed coords[],
1112 float current_spacing,
1113 float target_spacing)
1114{
1115 float value = target_spacing;
1116 if (blf_glyph_set_variation_float(font, coords, BLF_VARIATION_AXIS_SPACING, &value)) {
1117 return value;
1118 }
1119 return current_spacing;
1120}
1121
1130 FT_Fixed coords[],
1131 const float points)
1132{
1133 float value = points;
1134 return blf_glyph_set_variation_float(font, coords, BLF_VARIATION_AXIS_OPTSIZE, &value);
1135}
1136
1138
1139/* -------------------------------------------------------------------- */
1142
1149static bool blf_glyph_transform_weight(FT_GlyphSlot glyph, float width, bool monospaced)
1150{
1151 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
1152 const FontBLF *font = static_cast<FontBLF *>(glyph->face->generic.data);
1153 const FT_Pos average_width = font->ft_size->metrics.height;
1154 float factor = width * 0.000225f;
1155 FT_Pos change = FT_Pos(float(average_width) * factor);
1156 FT_Outline_EmboldenXY(&glyph->outline, change, 0);
1157 if (monospaced) {
1158 /* Widened fixed-pitch font needs a nudge left. */
1159 FT_Outline_Translate(&glyph->outline, change / -2, 0);
1160 }
1161 else if (glyph->linearHoriAdvance != 0) {
1162 /* Need to increase horizontal advance.
1163 * Zero advance glyphs (combining characters for e.g.) must not be given an advance.
1164 * Check the un-hinted advance since narrow glyphs at small sizes round down to zero. */
1165 glyph->advance.x += change / 2;
1166 }
1167 return true;
1168 }
1169 return false;
1170}
1171
1178static bool blf_glyph_transform_slant(FT_GlyphSlot glyph, float degrees)
1179{
1180 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
1181 FT_Matrix transform = {to_16dot16(1), to_16dot16(degrees * 0.0225f), 0, to_16dot16(1)};
1182 FT_Outline_Transform(&glyph->outline, &transform);
1183 if (degrees < 0.0f) {
1184 /* Leftward slant could interfere with prior characters to nudge right. */
1185 const FontBLF *font = static_cast<FontBLF *>(glyph->face->generic.data);
1186 const FT_Pos average_width = font->ft_size->metrics.height;
1187 FT_Pos change = FT_Pos(float(average_width) * degrees * -0.01f);
1188 FT_Outline_Translate(&glyph->outline, change, 0);
1189 }
1190 return true;
1191 }
1192 return false;
1193}
1194
1201static bool blf_glyph_transform_width(FT_GlyphSlot glyph, float factor)
1202{
1203 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
1204 float scale = factor + 1.0f;
1205 FT_Matrix matrix = {to_16dot16(scale), 0, 0, to_16dot16(1)};
1206 FT_Outline_Transform(&glyph->outline, &matrix);
1207 glyph->advance.x = FT_Pos(double(glyph->advance.x) * scale);
1208 return true;
1209 }
1210 return false;
1211}
1212
1219static bool blf_glyph_transform_spacing(FT_GlyphSlot glyph, float factor)
1220{
1221 if (glyph->advance.x > 0) {
1222 const FontBLF *font = static_cast<FontBLF *>(glyph->face->generic.data);
1223 const long int size = font->ft_size->metrics.height;
1224 glyph->advance.x += FT_Pos(factor * float(size) / 6.0f);
1225 return true;
1226 }
1227 return false;
1228}
1229
1235static bool blf_glyph_transform_monospace(FT_GlyphSlot glyph, int width)
1236{
1237 if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) {
1238 FT_Fixed current = glyph->linearHoriAdvance;
1239 FT_Fixed target = FT_Fixed(width) << 16; /* Do math in 16.16 values. */
1240 if (target < current) {
1241 const FT_Pos embolden = FT_Pos((current - target) >> 13);
1242 /* Horizontally widen strokes to counteract narrowing. */
1243 FT_Outline_EmboldenXY(&glyph->outline, embolden, 0);
1244 const float scale = float(target - (embolden << 9)) / float(current);
1245 FT_Matrix matrix = {to_16dot16(scale), 0, 0, to_16dot16(1)};
1246 FT_Outline_Transform(&glyph->outline, &matrix);
1247 }
1248 else if (target > current) {
1249 /* Center narrow glyphs. */
1250 FT_Outline_Translate(&glyph->outline, FT_Pos((target - current) >> 11), 0);
1251 }
1252 glyph->advance.x = width << 6;
1253 return true;
1254 }
1255 return false;
1256}
1257
1259
1260/* -------------------------------------------------------------------- */
1263
1267static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font,
1268 FontBLF *glyph_font,
1269 FT_UInt glyph_index,
1270 uint charcode,
1271 uint8_t subpixel,
1272 int fixed_width,
1273 bool outline_only)
1274{
1275 if (glyph_font != settings_font) {
1276 blf_font_size(glyph_font, settings_font->size);
1277 }
1278
1279 blf_ensure_size(glyph_font);
1280
1281 /* Default style values of the font containing the glyph. */
1282 float weight = glyph_font->metrics.weight;
1283 float slant = glyph_font->metrics.slant;
1284 float width = glyph_font->metrics.width;
1285 float spacing = glyph_font->metrics.spacing;
1286
1287 /* Style targets are on the settings_font. */
1288 float weight_target = float(settings_font->char_weight);
1289 if (settings_font->flags & BLF_BOLD) {
1290 weight_target = std::min(weight_target + 300.0f, 900.0f);
1291 }
1292 float slant_target = settings_font->char_slant;
1293 if (settings_font->flags & BLF_ITALIC) {
1294 slant_target = std::min(slant_target + 8.0f, 15.0f);
1295 }
1296 float width_target = settings_font->char_width;
1297 float spacing_target = settings_font->char_spacing;
1298
1299 /* Font variations need to be set before glyph loading. Even if new value is zero. */
1300
1301 if (glyph_font->variations) {
1302 FT_Fixed coords[BLF_VARIATIONS_MAX];
1303 /* Load current design coordinates. */
1304 FT_Get_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]);
1305 /* Update design coordinates with new values. */
1306
1307 weight = blf_glyph_set_variation_weight(glyph_font, coords, weight, weight_target);
1308 slant = blf_glyph_set_variation_slant(glyph_font, coords, slant, slant_target);
1309 width = blf_glyph_set_variation_width(glyph_font, coords, width, width_target);
1310 spacing = blf_glyph_set_variation_spacing(glyph_font, coords, spacing, spacing_target);
1311 blf_glyph_set_variation_optical_size(glyph_font, coords, settings_font->size);
1312
1313 /* Save updated design coordinates. */
1314 FT_Set_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]);
1315 }
1316
1317 FT_GlyphSlot glyph = blf_glyph_load(glyph_font, glyph_index, outline_only);
1318 if (!glyph) {
1319 return nullptr;
1320 }
1321
1322 if ((settings_font->flags & BLF_MONOSPACED) && (settings_font != glyph_font)) {
1323 const int col = BLI_wcwidth_or_error(char32_t(charcode));
1324 if (col > 0) {
1325 blf_glyph_transform_monospace(glyph, col * fixed_width);
1326 }
1327 }
1328
1329 /* Fallback glyph transforms, but only if required and not yet done. */
1330
1331 if (weight != weight_target) {
1332 /* Check the settings font as fallback glyphs are also given a fixed advance,
1333 * see #blf_glyph_transform_monospace. */
1335 glyph, weight_target - weight, (settings_font->flags & BLF_MONOSPACED) != 0);
1336 }
1337 if (slant != slant_target) {
1338 blf_glyph_transform_slant(glyph, slant_target - slant);
1339 }
1340 if (width != width_target) {
1341 blf_glyph_transform_width(glyph, width_target - width);
1342 }
1343 if (spacing != spacing_target) {
1344 blf_glyph_transform_spacing(glyph, spacing_target - spacing);
1345 }
1346
1347 if (outline_only) {
1348 return glyph;
1349 }
1350
1351 FT_Outline_Translate(&glyph->outline, FT_Pos(subpixel), 0);
1352
1353 if (blf_glyph_render_bitmap(glyph_font, glyph)) {
1354 return glyph;
1355 }
1356 return nullptr;
1357}
1358
1359FT_GlyphSlot blf_glyph_render_outline(FontBLF *settings_font,
1360 FontBLF *glyph_font,
1361 FT_UInt glyph_index,
1362 uint charcode,
1363 int fixed_width)
1364{
1365 /* Exposed for `blf_glyph_curves.cc`. */
1366 return blf_glyph_render(settings_font, glyph_font, glyph_index, charcode, 0, fixed_width, true);
1367}
1368
1369GlyphBLF *blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, const uint charcode, uint8_t subpixel)
1370{
1371 if (charcode < 32) {
1372 if (ELEM(charcode, '\n', '\r')) {
1373 /* Do not render line feed or carriage return. #134972. */
1374 return nullptr;
1375 }
1376 /* Other C0 controls (U+0000 - U+001F) can show as space. #135421. */
1377 /* TODO: Return all but TAB as ".notdef" character when we have our own. */
1378 return blf_glyph_ensure(font, gc, ' ');
1379 }
1380
1381 GlyphBLF *g = blf_glyph_cache_find_glyph(gc, charcode, subpixel);
1382 if (g) {
1383 return g;
1384 }
1385
1386 /* Glyph might not come from the initial font. */
1387 FontBLF *font_with_glyph = font;
1388 FT_UInt glyph_index = blf_glyph_index_from_charcode(&font_with_glyph, charcode);
1389
1390 if (!glyph_index) {
1391 /* 1 = id of ICON_CHAR_NOTDEF */
1392#ifndef WITH_HEADLESS
1393 return blf_glyph_ensure_icon(gc, 1, false, nullptr);
1394#else
1395 return nullptr;
1396#endif
1397 }
1398
1399 if (!blf_ensure_face(font_with_glyph)) {
1400 return nullptr;
1401 }
1402
1403 FT_GlyphSlot glyph = blf_glyph_render(
1404 font, font_with_glyph, glyph_index, charcode, subpixel, gc->fixed_width, false);
1405
1406 if (glyph) {
1407 /* Save this glyph in the initial font's cache. */
1408 g = blf_glyph_cache_add_glyph(gc, glyph, charcode, glyph_index, subpixel);
1409 }
1410
1411 return g;
1412}
1413
1414#ifndef WITH_HEADLESS
1416 const uint icon_id,
1417 bool color,
1418 FunctionRef<void(std::string &)> edit_source_cb)
1419{
1421 if (g) {
1422 return g;
1423 }
1424 return blf_glyph_cache_add_svg(gc, icon_id + BLF_ICON_OFFSET, color, edit_source_cb);
1425}
1426#endif /* WITH_HEADLESS */
1427
1428#ifdef BLF_SUBPIXEL_AA
1430{
1431 if (!(font->flags & BLF_RENDER_SUBPIXELAA)) {
1432 /* Not if we are in mono mode (aliased) or the feature is turned off. */
1433 return g;
1434 }
1435
1436 if (font->size > 35.0f || g->dims[0] == 0 || flag_is_set(g->flags, GlyphFlagBLF::Combining)) {
1437 /* Single position for large sizes, spaces, and combining characters. */
1438 return g;
1439 }
1440
1441 /* Four sub-pixel positions up to 16 point, 2 until 35 points. */
1442 const uint8_t subpixel = uint8_t(pen_x & ((font->size > 16.0f) ? 32L : 48L));
1443
1444 if (g->subpixel != subpixel) {
1445 g = blf_glyph_ensure(font, gc, g->c, subpixel);
1446 }
1447 return g;
1448}
1449#endif
1450
1452{
1453 if (this->bitmap) {
1454 MEM_delete(this->bitmap);
1455 }
1456}
1457
1459
1460/* -------------------------------------------------------------------- */
1463
1464static void blf_glyph_calc_rect(const GlyphBLF *g, const int x, const int y, rcti *r_rect)
1465{
1466 r_rect->xmin = x + g->pos[0];
1467 r_rect->xmax = r_rect->xmin + g->dims[0];
1468 r_rect->ymin = y + g->pos[1];
1469 r_rect->ymax = r_rect->ymin - g->dims[1];
1470}
1471
1472static void blf_glyph_calc_rect_test(const GlyphBLF *g, const int x, const int y, rcti *r_rect)
1473{
1474 /* Intentionally check with `g->advance`, because this is the
1475 * width used by BLF_width. This allows that the text slightly
1476 * overlaps the clipping border to achieve better alignment. */
1477 r_rect->xmin = x + abs(g->pos[0]) + 1;
1478 r_rect->xmax = x + std::min(ft_pix_to_int(g->advance_x), g->dims[0]);
1479 r_rect->ymin = y;
1480 r_rect->ymax = r_rect->ymin - g->dims[1];
1481}
1482
1484 const GlyphBLF *g, const int x, const int y, const FontBLF *font, rcti *r_rect)
1485{
1486 blf_glyph_calc_rect(g, x + font->shadow_x, y + font->shadow_y, r_rect);
1487}
1488
1490
1491/* -------------------------------------------------------------------- */
1494
1495static void blf_texture_draw(const GlyphBLF *g,
1496 const uchar color[4],
1497 const FontShadowType shadow,
1498 const int x1,
1499 const int y1,
1500 const int x2,
1501 const int y2)
1502{
1504 GlyphQuad &glyph_data = g_batch.glyph_data[g_batch.glyph_len++];
1505 /* One vertex per glyph, instancing expands it into a quad. */
1506 glyph_data.position = int4(
1507 x1 + g_batch.ofs[0], y1 + g_batch.ofs[1], x2 + g_batch.ofs[0], y2 + g_batch.ofs[1]);
1508 glyph_data.glyph_color = float4(UNPACK4(color)) / 255.0f;
1509 glyph_data.glyph_size = int2(g->dims);
1510 glyph_data.offset = g->offset;
1511 /* Glyph flags packs color channel count and shadow type. */
1512 glyph_data.flags = uint32_t(shadow) | (uint32_t(g->num_channels) << 4);
1513
1514 /* Flush cache if it's full. */
1517 }
1518}
1519
1520void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, const int y)
1521{
1522 if ((!g->dims[0]) || (!g->dims[1])) {
1523 return;
1524 }
1525
1526 if (g->glyph_cache == nullptr) {
1527 if (font->tex_size_max == -1) {
1529 }
1530
1531 g->offset = gc->bitmap_len;
1532
1533 int buff_size = g->dims[0] * g->dims[1] * g->num_channels;
1534 int bitmap_len = gc->bitmap_len + buff_size;
1535
1536 if (bitmap_len > gc->bitmap_len_alloc) {
1537 int w = font->tex_size_max;
1538 int h = bitmap_len / w + 1;
1539
1540 gc->bitmap_len_alloc = w * h;
1541 gc->bitmap_result = static_cast<char *>(
1543
1544 /* Keep in sync with the texture. */
1545 if (gc->texture) {
1547 }
1549 __func__, w, h, 1, gpu::TextureFormat::UNORM_8, GPU_TEXTURE_USAGE_SHADER_READ, nullptr);
1550
1551 gc->bitmap_len_landed = 0;
1552 }
1553
1554 memcpy(&gc->bitmap_result[gc->bitmap_len], g->bitmap, size_t(buff_size));
1555 gc->bitmap_len = bitmap_len;
1556
1557 g->glyph_cache = gc;
1558 }
1559
1560 if (font->flags & BLF_CLIPPING) {
1561 float xa, ya;
1562
1563 if (font->flags & BLF_ASPECT) {
1564 xa = font->aspect[0];
1565 ya = font->aspect[1];
1566 }
1567 else {
1568 xa = 1.0f;
1569 ya = 1.0f;
1570 }
1571
1572 rcti rect_test;
1573 blf_glyph_calc_rect_test(g, int(float(x) * xa), int(float(y) * ya), &rect_test);
1574 BLI_rcti_translate(&rect_test, font->pos[0], font->pos[1]);
1575 if (!BLI_rcti_inside_rcti(&font->clip_rec, &rect_test)) {
1576 return;
1577 }
1578 }
1579
1580 if (g_batch.glyph_cache != g->glyph_cache) {
1583 }
1584
1585 if (font->flags & BLF_SHADOW) {
1586 rcti rect_ofs;
1587 blf_glyph_calc_rect_shadow(g, x, y, font, &rect_ofs);
1588
1590 font->shadow_color,
1591 font->shadow,
1592 rect_ofs.xmin,
1593 rect_ofs.ymin,
1594 rect_ofs.xmax,
1595 rect_ofs.ymax);
1596 }
1597
1598 rcti rect;
1599 blf_glyph_calc_rect(g, x, y, &rect);
1601 g, font->color, FontShadowType::None, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
1602}
1603
1605
1606} // namespace blender
Read Blender memory allocation and freeing.
volatile int lock
#define CLAMP(a, b, c)
#define UNPACK4(a)
#define ELEM(...)
#define BLF_MAX_FONT
#define BLF_ICON_OFFSET
#define BLF_VARIATIONS_MAX
#define BLF_VARIATION_AXIS_SLANT
#define BLF_VARIATION_AXIS_OPTSIZE
#define BLF_VARIATION_AXIS_WIDTH
#define BLF_VARIATION_AXIS_WEIGHT
#define BLF_VARIATION_AXIS_SPACING
#define BLF_BATCH_DRAW_LEN_MAX
#define MEM_realloc_uninitialized(vmemh, len)
btScalar max
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition btQuadWord.h:119
const T * data() const
Definition BLI_array.hh:323
#define round
#define abs
#define ceil
constexpr T degrees(T) RET
float3x3 scale(float3x3 mat, float2 scale)
BMesh Iterators.
UserDef U
Definition blender.cc:58
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
__int64 int64_t
Definition BKE_text.h:90
VecBase< int32_t, 4 > int4
static bool blf_glyph_set_variation_float(const FontBLF *font, FT_Fixed coords[], uint32_t tag, float *value)
bool blf_ensure_face(FontBLF *font)
Definition blf_font.cc:2087
unsigned int uint
Definition BKE_text.h:55
void * MEM_new_array_uninitialized(size_t len, size_t size, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1
FT_GlyphSlot blf_glyph_render_outline(FontBLF *settings_font, FontBLF *glyph_font, FT_UInt glyph_index, uint charcode, int fixed_width)
void blf_glyph_cache_release(FontBLF *font)
Definition blf_glyph.cc:145
MINLINE unsigned char srgb_to_grayscale_byte(const unsigned char rgb[3])
uint blf_get_char_index(FontBLF *font, const uint charcode)
Definition blf_font.cc:155
void blf_ensure_size(FontBLF *font)
Definition blf_font.cc:2310
static GlyphBLF * blf_glyph_cache_add_svg(GlyphCacheBLF *gc, const uint charcode, const bool color, FunctionRef< void(std::string &)> edit_source_cb=nullptr)
Definition blf_glyph.cc:365
BatchBLF g_batch
Definition blf_font.cc:61
static void blf_glyph_calc_rect_shadow(const GlyphBLF *g, const int x, const int y, const FontBLF *font, rcti *r_rect)
static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font, FontBLF *glyph_font, FT_UInt glyph_index, uint charcode, uint8_t subpixel, int fixed_width, bool outline_only)
static bool blf_font_has_coverage_bit(const FontBLF *font, const int coverage_bit)
Definition blf_glyph.cc:783
void blf_glyph_draw(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, const int y)
static float blf_glyph_set_variation_spacing(const FontBLF *font, FT_Fixed coords[], float current_spacing, float target_spacing)
int GPU_max_texture_size()
static FT_Fixed blf_factor_to_coordinate(const FT_Var_Axis *axis, const float factor)
Definition blf_glyph.cc:981
VecBase< float, 4 > float4
static bool blf_glyph_render_bitmap(FontBLF *font, FT_GlyphSlot glyph)
Definition blf_glyph.cc:907
unsigned int uint32_t
Definition BKE_text.h:81
static float from_16dot16(const FT_Fixed value)
Definition blf_glyph.cc:74
static GlyphBLF * blf_glyph_cache_add_blank(GlyphCacheBLF *gc, const uint charcode)
Definition blf_glyph.cc:353
VecBase< int32_t, 2 > int2
GlyphCacheBLF * blf_glyph_cache_acquire(FontBLF *font)
Definition blf_glyph.cc:132
unsigned char uchar
Definition BKE_text.h:58
static GlyphBLF * blf_glyph_cache_find_glyph(const GlyphCacheBLF *gc, const uint charcode, const uint8_t subpixel)
Definition blf_glyph.cc:172
@ GPU_TEXTURE_USAGE_SHADER_READ
static float blf_glyph_set_variation_weight(const FontBLF *font, FT_Fixed coords[], float current_weight, float target_weight)
static GlyphCacheBLF * blf_glyph_cache_new(FontBLF *font)
Definition blf_glyph.cc:99
static void blf_texture_draw(const GlyphBLF *g, const uchar color[4], const FontShadowType shadow, const int x1, const int y1, const int x2, const int y2)
FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode)
Definition blf_glyph.cc:795
static const UnicodeBlock unicode_blocks[]
Definition blf_glyph.cc:472
static FT_GlyphSlot blf_glyph_load(FontBLF *font, const FT_UInt glyph_index, const bool outline_only)
Definition blf_glyph.cc:859
unsigned char uint8_t
Definition BKE_text.h:79
void BLI_rcti_translate(struct rcti *rect, int x, int y)
Definition rct.cc:580
static bool blf_glyph_transform_weight(FT_GlyphSlot glyph, float width, bool monospaced)
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
static int blf_charcode_to_coverage_bit(const uint charcode)
Definition blf_glyph.cc:766
static bool blf_glyph_set_variation_normalized(const FontBLF *font, FT_Fixed coords[], const uint32_t tag, const float factor)
static bool blf_glyph_transform_monospace(FT_GlyphSlot glyph, int width)
static bool blf_glyph_transform_width(FT_GlyphSlot glyph, float factor)
static bool blf_glyph_transform_spacing(FT_GlyphSlot glyph, float factor)
GlyphBLF * blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, const uint charcode, uint8_t subpixel)
static bool blf_glyph_set_variation_optical_size(const FontBLF *font, FT_Fixed coords[], const float points)
static float blf_glyph_set_variation_slant(const FontBLF *font, FT_Fixed coords[], float current_degrees, float target_degrees)
GlyphBLF * blf_glyph_ensure_icon(GlyphCacheBLF *gc, const uint icon_id, bool color, FunctionRef< void(std::string &)> edit_source_cb)
static const UnicodeBlock * blf_charcode_to_unicode_block(const uint charcode)
Definition blf_glyph.cc:734
FontBLF * global_font[BLF_MAX_FONT]
Definition blf.cc:46
static FT_Fixed to_16dot16(const double val)
Definition blf_glyph.cc:66
void GPU_texture_free(gpu::Texture *texture)
static bool blf_glyph_transform_slant(FT_GlyphSlot glyph, float degrees)
signed int int32_t
Definition BKE_text.h:78
static uchar blf_glyph_gamma(const uchar c)
Definition blf_glyph.cc:197
static GlyphCacheBLF * blf_glyph_cache_find(const FontBLF *font)
Definition blf_glyph.cc:85
int ft_pix_to_int(ft_pix v)
static float blf_glyph_set_variation_width(const FontBLF *font, FT_Fixed coords[], float current_width, float target_width)
static void blf_glyph_calc_rect_test(const GlyphBLF *g, const int x, const int y, rcti *r_rect)
bool blf_font_size(FontBLF *font, float size)
Definition blf_font.cc:2332
static const FT_Var_Axis * blf_var_axis_by_tag(const FT_MM_Var *variations, const uint32_t tag, int *r_axis_index)
Definition blf_glyph.cc:955
void blf_glyph_cache_clear(FontBLF *font)
Definition blf_glyph.cc:161
bool BLI_rcti_inside_rcti(const rcti *rct_a, const rcti *rct_b)
Definition rct.cc:200
static void blf_glyph_calc_rect(const GlyphBLF *g, const int x, const int y, rcti *r_rect)
void blf_batch_draw()
Definition blf_font.cc:307
GlyphBLF * blf_glyph_ensure_subpixel(FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, int32_t pen_x)
static GlyphBLF * blf_glyph_cache_add_glyph(GlyphCacheBLF *gc, const FT_GlyphSlot glyph, const uint charcode, const FT_UInt glyph_index, const uint8_t subpixel)
Definition blf_glyph.cc:224
@ BLF_MONOCHROME
Definition BLF_enums.hh:44
@ BLF_DEFAULT
Definition BLF_enums.hh:53
@ BLF_RENDER_SUBPIXELAA
Definition BLF_enums.hh:63
@ BLF_SHADOW
Definition BLF_enums.hh:38
@ BLF_ASPECT
Definition BLF_enums.hh:41
@ BLF_CLIPPING
Definition BLF_enums.hh:37
@ BLF_LAST_RESORT
Definition BLF_enums.hh:55
@ BLF_HINTING_SLIGHT
Definition BLF_enums.hh:46
@ BLF_NO_FALLBACK
Definition BLF_enums.hh:66
@ BLF_HINTING_FULL
Definition BLF_enums.hh:47
@ BLF_MONOSPACED
Definition BLF_enums.hh:51
@ BLF_ITALIC
Definition BLF_enums.hh:49
@ BLF_HINTING_NONE
Definition BLF_enums.hh:45
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
size_t size_t int BLI_wcwidth_or_error(char32_t ucs) ATTR_WARN_UNUSED_RESULT
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
GlyphCacheBLF * glyph_cache
GlyphQuad glyph_data[BLF_BATCH_DRAW_LEN_MAX]
unsigned char shadow_color[4]
unsigned char color[4]
Vector< std::unique_ptr< GlyphCacheBLF > > cache
GlyphCacheBLF * glyph_cache
Map< GlyphCacheKey, std::unique_ptr< GlyphBLF > > glyphs