Blender
V3.3
|
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ft2build.h>
#include "MEM_guardedalloc.h"
#include "DNA_userdef_types.h"
#include "DNA_vec_types.h"
#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BLI_threads.h"
#include "BLF_api.h"
#include "GPU_capabilities.h"
#include "GPU_immediate.h"
#include "blf_internal.h"
#include "blf_internal_types.h"
#include "BLI_math_vector.h"
#include "BLI_strict_flags.h"
#include "BLI_string_utf8.h"
Go to the source code of this file.
Classes | |
struct | eUnicodeBlock |
Functions | |
Internal Utilities | |
static FT_Fixed | to_16dot16 (double val) |
Variations (Multiple Masters) support | |
static FT_Var_Axis * | blf_var_axis_by_tag (FT_MM_Var *variations, uint tag, int *axis_index) |
static FT_Fixed | blf_factor_to_coordinate (FT_Var_Axis *axis, float factor) |
static bool | blf_glyph_set_variation_normalized (FontBLF *font, FT_Fixed coords[], uint tag, float factor) |
static bool | blf_glyph_set_variation_float (FontBLF *font, FT_Fixed coords[], uint tag, float value) |
Glyph Transformations | |
static bool | blf_glyph_transform_weight (FT_GlyphSlot glyph, float factor, bool monospaced) |
static bool | blf_glyph_transform_slant (FT_GlyphSlot glyph, float factor) |
static bool | blf_glyph_transform_width (FT_GlyphSlot glyph, float factor) |
static bool | blf_glyph_transform_spacing (FT_GlyphSlot glyph, float factor) |
static bool | blf_glyph_transform_monospace (FT_GlyphSlot glyph, int width) |
Glyph Access (Ensure/Free) | |
static FT_GlyphSlot | blf_glyph_render (FontBLF *settings_font, FontBLF *glyph_font, FT_UInt glyph_index, uint charcode, int fixed_width) |
GlyphBLF * | blf_glyph_ensure (FontBLF *font, GlyphCacheBLF *gc, uint charcode) |
void | blf_glyph_free (GlyphBLF *g) |
Glyph Bounds Calculation | |
static void | blf_glyph_calc_rect (rcti *rect, GlyphBLF *g, const int x, const int y) |
static void | blf_glyph_calc_rect_test (rcti *rect, GlyphBLF *g, const int x, const int y) |
static void | blf_glyph_calc_rect_shadow (rcti *rect, GlyphBLF *g, const int x, const int y, FontBLF *font) |
Glyph Drawing | |
static void | blf_texture_draw (const unsigned char color[4], const int glyph_size[2], const int offset, const int x1, const int y1, const int x2, const int y2) |
static void | blf_texture5_draw (const unsigned char color_in[4], const int glyph_size[2], const int offset, const int x1, const int y1, const int x2, const int y2) |
static void | blf_texture3_draw (const unsigned char color_in[4], const int glyph_size[2], const int offset, const int x1, const int y1, const int x2, const int y2) |
void | blf_glyph_draw (FontBLF *font, GlyphCacheBLF *gc, GlyphBLF *g, const int x, const int y) |
Glyph rendering, texturing and caching. Wraps Freetype and OpenGL functions.
Definition in file blf_glyph.c.
typedef struct eUnicodeBlock eUnicodeBlock |
|
static |
Definition at line 537 of file blf_glyph.c.
References blf_charcode_to_unicode_block(), and eUnicodeBlock::coverage_bit.
Referenced by blf_glyph_index_from_charcode().
|
static |
Definition at line 504 of file blf_glyph.c.
References ARRAY_SIZE, max, min, NULL, and unicode_blocks.
Referenced by blf_charcode_to_coverage_bit().
|
static |
Convert a float factor to a fixed-point design coordinate.
axis | Pointer to a design space axis structure. |
factor | -1 to 1 with 0 meaning "default" |
Definition at line 716 of file blf_glyph.c.
Referenced by blf_glyph_set_variation_normalized().
Definition at line 554 of file blf_glyph.c.
References FontBLF::UnicodeRanges.
Referenced by blf_glyph_index_from_charcode().
GlyphCacheBLF* blf_glyph_cache_acquire | ( | FontBLF * | font | ) |
Definition at line 116 of file blf_glyph.c.
References blf_glyph_cache_find(), blf_glyph_cache_new(), BLI_spin_lock(), FontBLF::dpi, FontBLF::glyph_cache_mutex, and FontBLF::size.
Referenced by blf_font_boundbox(), blf_font_boundbox_foreach_glyph(), blf_font_draw(), blf_font_draw_buffer(), blf_font_draw_mono(), blf_font_fixed_width(), blf_font_width_to_rstrlen(), blf_font_width_to_strlen(), and blf_font_wrap_apply().
|
static |
Add a rendered glyph to a cache.
Definition at line 188 of file blf_glyph.c.
References blf_hash(), BLF_MONOCHROME, BLI_addhead(), GlyphCacheBLF::bucket, FontBLF::flags, usdtokens::g(), glyph, GlyphCacheBLF::glyph_ascii_table, GLYPH_ASCII_TABLE_SIZE, MEM_callocN, and MEM_mallocN.
Referenced by blf_glyph_ensure().
Definition at line 151 of file blf_glyph.c.
References blf_glyph_cache_free(), BLI_pophead(), BLI_spin_lock(), BLI_spin_unlock(), FontBLF::cache, and FontBLF::glyph_cache_mutex.
Referenced by BLF_cache_clear(), and blf_font_free().
|
static |
Definition at line 63 of file blf_glyph.c.
References BLF_BOLD, BLF_ITALIC, GlyphCacheBLF::bold, FontBLF::cache, GlyphCacheBLF::char_slant, FontBLF::char_slant, GlyphCacheBLF::char_spacing, FontBLF::char_spacing, GlyphCacheBLF::char_weight, FontBLF::char_weight, GlyphCacheBLF::char_width, FontBLF::char_width, GlyphCacheBLF::dpi, ListBase::first, FontBLF::flags, GlyphCacheBLF::italic, GlyphCacheBLF::next, NULL, size(), and GlyphCacheBLF::size.
Referenced by blf_glyph_cache_acquire().
|
static |
Try to find a glyph in cache.
Definition at line 169 of file blf_glyph.c.
References blf_hash(), GlyphCacheBLF::bucket, ListBase::first, usdtokens::g(), GlyphCacheBLF::glyph_ascii_table, GLYPH_ASCII_TABLE_SIZE, and NULL.
Referenced by blf_glyph_ensure().
|
static |
Definition at line 134 of file blf_glyph.c.
References ARRAY_SIZE, GlyphCacheBLF::bitmap_result, blf_glyph_free(), BLI_pophead(), GlyphCacheBLF::bucket, usdtokens::g(), GPU_texture_free(), MEM_freeN, and GlyphCacheBLF::texture.
Referenced by blf_glyph_cache_clear().
|
static |
Definition at line 78 of file blf_glyph.c.
References BLF_BOLD, BLF_ITALIC, BLI_addhead(), GlyphCacheBLF::bold, GlyphCacheBLF::bucket, FontBLF::cache, GlyphCacheBLF::char_slant, FontBLF::char_slant, GlyphCacheBLF::char_spacing, FontBLF::char_spacing, GlyphCacheBLF::char_weight, FontBLF::char_weight, GlyphCacheBLF::char_width, FontBLF::char_width, GlyphCacheBLF::dpi, FontBLF::dpi, FontBLF::face, GlyphCacheBLF::fixed_width, FontBLF::flags, GlyphCacheBLF::glyph_ascii_table, GlyphCacheBLF::italic, MEM_callocN, GlyphCacheBLF::next, NULL, GlyphCacheBLF::prev, GlyphCacheBLF::size, and FontBLF::size.
Referenced by blf_glyph_cache_acquire().
Definition at line 129 of file blf_glyph.c.
References BLI_spin_unlock(), and FontBLF::glyph_cache_mutex.
Referenced by blf_font_boundbox(), blf_font_boundbox_foreach_glyph(), blf_font_draw(), blf_font_draw_buffer(), blf_font_draw_mono(), blf_font_fixed_width(), blf_font_width_to_rstrlen(), blf_font_width_to_strlen(), and blf_font_wrap_apply().
Definition at line 1019 of file blf_glyph.c.
References usdtokens::g(), x, rcti::xmax, rcti::xmin, y, rcti::ymax, and rcti::ymin.
Referenced by blf_glyph_calc_rect_shadow(), and blf_glyph_draw().
|
static |
Definition at line 1038 of file blf_glyph.c.
References blf_glyph_calc_rect(), usdtokens::g(), FontBLF::shadow_x, FontBLF::shadow_y, x, and y.
Referenced by blf_glyph_draw().
Definition at line 1027 of file blf_glyph.c.
References ft_pix_to_int(), usdtokens::g(), MIN2, x, rcti::xmax, rcti::xmin, y, rcti::ymax, and rcti::ymin.
Referenced by blf_glyph_draw().
void blf_glyph_draw | ( | FontBLF * | font, |
GlyphCacheBLF * | gc, | ||
GlyphBLF * | g, | ||
const int | x, | ||
const int | y | ||
) |
Definition at line 1108 of file blf_glyph.c.
References GlyphCacheBLF::bitmap_len, GlyphCacheBLF::bitmap_len_alloc, GlyphCacheBLF::bitmap_len_landed, GlyphCacheBLF::bitmap_result, blf_batch_draw(), BLF_CLIPPING, blf_glyph_calc_rect(), blf_glyph_calc_rect_shadow(), blf_glyph_calc_rect_test(), BLF_SHADOW, blf_texture3_draw(), blf_texture5_draw(), blf_texture_draw(), BLI_rcti_inside_rcti(), BLI_rcti_translate(), FontBLF::clip_rec, FontBLF::color, FontBLF::flags, usdtokens::g(), g_batch, BatchBLF::glyph_cache, GPU_max_texture_size(), GPU_R8, GPU_texture_create_2d(), GPU_texture_free(), MEM_reallocN, NULL, FontBLF::pos, FontBLF::shadow, FontBLF::shadow_color, FontBLF::tex_size_max, GlyphCacheBLF::texture, w(), x, rcti::xmax, rcti::xmin, y, rcti::ymax, and rcti::ymin.
Referenced by blf_font_draw_ex(), and blf_font_draw_mono().
GlyphBLF* blf_glyph_ensure | ( | struct FontBLF * | font, |
struct GlyphCacheBLF * | gc, | ||
uint | charcode | ||
) |
Create (or load from cache) a fully-rendered bitmap glyph.
Definition at line 976 of file blf_glyph.c.
References blf_glyph_cache_add_glyph(), blf_glyph_cache_find_glyph(), blf_glyph_index_from_charcode(), blf_glyph_render(), BLI_spin_lock(), BLI_spin_unlock(), GlyphCacheBLF::fixed_width, FontBLF::ft_lib_mutex, usdtokens::g(), and glyph.
Referenced by blf_glyph_from_utf8_and_step().
Definition at line 1005 of file blf_glyph.c.
References usdtokens::g(), and MEM_freeN.
Referenced by blf_glyph_cache_free().
Return a glyph index from charcode
. Not found returns zero, which is a valid printable character (.notdef
or tofu
). Font is allowed to change here.
Definition at line 566 of file blf_glyph.c.
References blf_charcode_to_coverage_bit(), BLF_DEFAULT, blf_font_has_coverage_bit(), BLF_LAST_RESORT, BLF_MAX_FONT, FontBLF::face, FontBLF::flags, global_font, and NULL.
Referenced by blf_glyph_ensure().
|
static |
Load a glyph into the glyph slot of a font's face object.
Definition at line 610 of file blf_glyph.c.
References BLF_HINTING_FULL, BLF_HINTING_NONE, BLF_HINTING_SLIGHT, BLF_MONOCHROME, FontBLF::face, FontBLF::flags, and NULL.
Referenced by blf_glyph_render().
|
static |
Create and return a fully-rendered bitmap glyph.
Definition at line 888 of file blf_glyph.c.
References BLF_BOLD, blf_glyph_load(), blf_glyph_render_bitmap(), blf_glyph_set_variation_float(), blf_glyph_set_variation_normalized(), blf_glyph_transform_monospace(), blf_glyph_transform_slant(), blf_glyph_transform_spacing(), blf_glyph_transform_weight(), blf_glyph_transform_width(), BLF_ITALIC, BLF_MONOSPACED, blf_variation_axis_optsize, blf_variation_axis_slant, blf_variation_axis_spacing, blf_variation_axis_weight, blf_variation_axis_width, BLF_VARIATIONS_MAX, BLI_wcwidth(), FontBLF::char_slant, FontBLF::char_spacing, FontBLF::char_weight, FontBLF::char_width, FontBLF::dpi, FontBLF::face, FontBLF::flags, glyph, NULL, FontBLF::size, FontBLF::variations, and width.
Referenced by blf_glyph_ensure().
Convert a glyph from outlines to a bitmap that we can display.
Definition at line 644 of file blf_glyph.c.
References BLF_MONOCHROME, err, FontBLF::flags, FontBLF::ft_lib, and glyph.
Referenced by blf_glyph_render().
|
static |
Set a face variation axis to an exact float value
coords | array of design coordinates, per axis. |
tag | Axis tag (4-character string as uint), like 'opsz' |
value | New float value. Converted to 16.16 and clamped within allowed range. |
Definition at line 758 of file blf_glyph.c.
References blf_var_axis_by_tag(), BLF_VARIATIONS_MAX, CLAMP, to_16dot16(), and FontBLF::variations.
Referenced by blf_glyph_render().
|
static |
Alter a face variation axis by a factor
coords | array of design coordinates, per axis. |
tag | Axis tag (4-character string as uint), like 'wght' |
factor | -1 to 1 with 0 meaning "default" |
Definition at line 737 of file blf_glyph.c.
References blf_factor_to_coordinate(), blf_var_axis_by_tag(), BLF_VARIATIONS_MAX, and FontBLF::variations.
Referenced by blf_glyph_render().
|
static |
Transform glyph to fit nicely within a fixed column width.
Definition at line 856 of file blf_glyph.c.
References float(), glyph, to_16dot16(), and width.
Referenced by blf_glyph_render().
Adjust the glyphs slant by a factor (making it oblique).
factor | -1 (max negative) <= 0 (no slant) => 1 (max positive). |
Definition at line 811 of file blf_glyph.c.
References glyph, to_16dot16(), and transform().
Referenced by blf_glyph_render().
Change glyph advance to alter letter-spacing (tracking).
factor | -1 (min tightness) <= 0 (normal) => 1 (max looseness). |
Definition at line 843 of file blf_glyph.c.
Referenced by blf_glyph_render().
Adjust the glyphs weight by a factor.
factor | -1 (min stroke width) <= 0 (normal) => 1 (max boldness). |
Definition at line 782 of file blf_glyph.c.
References glyph.
Referenced by blf_glyph_render().
Adjust the glyph width by factor.
factor | -1 (min width) <= 0 (normal) => 1 (max width). |
Definition at line 826 of file blf_glyph.c.
References glyph, and to_16dot16().
Referenced by blf_glyph_render().
|
static |
Definition at line 1092 of file blf_glyph.c.
References blf_texture_draw(), offset, x2, and y1.
Referenced by blf_glyph_draw().
|
static |
Definition at line 1076 of file blf_glyph.c.
References blf_texture_draw(), offset, x2, and y1.
Referenced by blf_glyph_draw().
|
static |
Definition at line 1050 of file blf_glyph.c.
References blf_batch_draw(), BLF_BATCH_DRAW_LEN_MAX, color, copy_v2_v2_int(), copy_v4_fl4(), copy_v4_v4_uchar(), g_batch, BatchBLF::glyph_len, BatchBLF::glyph_size_step, GPU_vertbuf_raw_step(), offset, BatchBLF::ofs, x2, and y1.
Referenced by blf_glyph_draw(), blf_texture3_draw(), and blf_texture5_draw().
|
static |
Return a design axis that matches an identifying tag.
variations | Variation descriptors from FT_Get_MM_Var . |
tag | Axis tag (4-character string as uint), like 'wght' |
axis_index | returns index of axis in variations array. |
Definition at line 694 of file blf_glyph.c.
References NULL.
Referenced by blf_glyph_set_variation_float(), and blf_glyph_set_variation_normalized().
|
static |
Convert a floating point value to a FreeType 16.16 fixed point value.
Definition at line 52 of file blf_glyph.c.
Referenced by blf_glyph_set_variation_float(), blf_glyph_transform_monospace(), blf_glyph_transform_slant(), and blf_glyph_transform_width().
|
static |
Definition at line 244 of file blf_glyph.c.
Referenced by blf_charcode_to_unicode_block().