Blender  V3.3
Classes
blf_glyph.c File Reference
#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)
 
GlyphBLFblf_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 Cache

typedef struct eUnicodeBlock eUnicodeBlock
 
static eUnicodeBlock unicode_blocks []
 
static GlyphCacheBLFblf_glyph_cache_find (FontBLF *font, float size, unsigned int dpi)
 
static GlyphCacheBLFblf_glyph_cache_new (FontBLF *font)
 
GlyphCacheBLFblf_glyph_cache_acquire (FontBLF *font)
 
void blf_glyph_cache_release (FontBLF *font)
 
static void blf_glyph_cache_free (GlyphCacheBLF *gc)
 
void blf_glyph_cache_clear (FontBLF *font)
 
static GlyphBLFblf_glyph_cache_find_glyph (GlyphCacheBLF *gc, uint charcode)
 
static GlyphBLFblf_glyph_cache_add_glyph (FontBLF *font, GlyphCacheBLF *gc, FT_GlyphSlot glyph, uint charcode, FT_UInt glyph_index)
 
static eUnicodeBlockblf_charcode_to_unicode_block (uint charcode)
 
static int blf_charcode_to_coverage_bit (uint charcode)
 
static bool blf_font_has_coverage_bit (FontBLF *font, int coverage_bit)
 
static FT_UInt blf_glyph_index_from_charcode (FontBLF **font, const uint charcode)
 
static FT_GlyphSlot blf_glyph_load (FontBLF *font, FT_UInt glyph_index)
 
static bool blf_glyph_render_bitmap (FontBLF *font, FT_GlyphSlot glyph)
 

Detailed Description

Glyph rendering, texturing and caching. Wraps Freetype and OpenGL functions.

Definition in file blf_glyph.c.

Typedef Documentation

◆ eUnicodeBlock

typedef struct eUnicodeBlock eUnicodeBlock

Function Documentation

◆ blf_charcode_to_coverage_bit()

static int blf_charcode_to_coverage_bit ( uint  charcode)
static

◆ blf_charcode_to_unicode_block()

static eUnicodeBlock* blf_charcode_to_unicode_block ( uint  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().

◆ blf_factor_to_coordinate()

static FT_Fixed blf_factor_to_coordinate ( FT_Var_Axis *  axis,
float  factor 
)
static

Convert a float factor to a fixed-point design coordinate.

Parameters
axisPointer 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().

◆ blf_font_has_coverage_bit()

static bool blf_font_has_coverage_bit ( FontBLF font,
int  coverage_bit 
)
static

Definition at line 554 of file blf_glyph.c.

References FontBLF::UnicodeRanges.

Referenced by blf_glyph_index_from_charcode().

◆ blf_glyph_cache_acquire()

GlyphCacheBLF* blf_glyph_cache_acquire ( FontBLF font)

◆ blf_glyph_cache_add_glyph()

static GlyphBLF* blf_glyph_cache_add_glyph ( FontBLF font,
GlyphCacheBLF gc,
FT_GlyphSlot  glyph,
uint  charcode,
FT_UInt  glyph_index 
)
static

◆ blf_glyph_cache_clear()

void blf_glyph_cache_clear ( FontBLF font)

◆ blf_glyph_cache_find()

static GlyphCacheBLF* blf_glyph_cache_find ( FontBLF font,
float  size,
unsigned int  dpi 
)
static

◆ blf_glyph_cache_find_glyph()

static GlyphBLF* blf_glyph_cache_find_glyph ( GlyphCacheBLF gc,
uint  charcode 
)
static

Try to find a glyph in cache.

Returns
NULL if not found.

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().

◆ blf_glyph_cache_free()

static void blf_glyph_cache_free ( GlyphCacheBLF gc)
static

◆ blf_glyph_cache_new()

static GlyphCacheBLF* blf_glyph_cache_new ( FontBLF font)
static

◆ blf_glyph_cache_release()

void blf_glyph_cache_release ( FontBLF font)

◆ blf_glyph_calc_rect()

static void blf_glyph_calc_rect ( rcti rect,
GlyphBLF g,
const int  x,
const int  y 
)
static

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().

◆ blf_glyph_calc_rect_shadow()

static void blf_glyph_calc_rect_shadow ( rcti rect,
GlyphBLF g,
const int  x,
const int  y,
FontBLF font 
)
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().

◆ blf_glyph_calc_rect_test()

static void blf_glyph_calc_rect_test ( rcti rect,
GlyphBLF g,
const int  x,
const int  y 
)
static

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().

◆ blf_glyph_draw()

void blf_glyph_draw ( FontBLF font,
GlyphCacheBLF gc,
GlyphBLF g,
const int  x,
const int  y 
)

◆ blf_glyph_ensure()

GlyphBLF* blf_glyph_ensure ( struct FontBLF font,
struct GlyphCacheBLF gc,
uint  charcode 
)

◆ blf_glyph_free()

void blf_glyph_free ( GlyphBLF g)

Definition at line 1005 of file blf_glyph.c.

References usdtokens::g(), and MEM_freeN.

Referenced by blf_glyph_cache_free().

◆ blf_glyph_index_from_charcode()

static FT_UInt blf_glyph_index_from_charcode ( FontBLF **  font,
const uint  charcode 
)
static

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().

◆ blf_glyph_load()

static FT_GlyphSlot blf_glyph_load ( FontBLF font,
FT_UInt  glyph_index 
)
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().

◆ blf_glyph_render()

static FT_GlyphSlot blf_glyph_render ( FontBLF settings_font,
FontBLF glyph_font,
FT_UInt  glyph_index,
uint  charcode,
int  fixed_width 
)
static

◆ blf_glyph_render_bitmap()

static bool blf_glyph_render_bitmap ( FontBLF font,
FT_GlyphSlot  glyph 
)
static

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().

◆ blf_glyph_set_variation_float()

static bool blf_glyph_set_variation_float ( FontBLF font,
FT_Fixed  coords[],
uint  tag,
float  value 
)
static

Set a face variation axis to an exact float value

Parameters
coordsarray of design coordinates, per axis.
tagAxis tag (4-character string as uint), like 'opsz'
valueNew 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().

◆ blf_glyph_set_variation_normalized()

static bool blf_glyph_set_variation_normalized ( FontBLF font,
FT_Fixed  coords[],
uint  tag,
float  factor 
)
static

Alter a face variation axis by a factor

Parameters
coordsarray of design coordinates, per axis.
tagAxis 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().

◆ blf_glyph_transform_monospace()

static bool blf_glyph_transform_monospace ( FT_GlyphSlot  glyph,
int  width 
)
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().

◆ blf_glyph_transform_slant()

static bool blf_glyph_transform_slant ( FT_GlyphSlot  glyph,
float  factor 
)
static

Adjust the glyphs slant by a factor (making it oblique).

Parameters
factor-1 (max negative) <= 0 (no slant) => 1 (max positive).
Note
that left-leaning italics are possible in some RTL writing systems.

Definition at line 811 of file blf_glyph.c.

References glyph, to_16dot16(), and transform().

Referenced by blf_glyph_render().

◆ blf_glyph_transform_spacing()

static bool blf_glyph_transform_spacing ( FT_GlyphSlot  glyph,
float  factor 
)
static

Change glyph advance to alter letter-spacing (tracking).

Parameters
factor-1 (min tightness) <= 0 (normal) => 1 (max looseness).

Definition at line 843 of file blf_glyph.c.

References glyph, and size().

Referenced by blf_glyph_render().

◆ blf_glyph_transform_weight()

static bool blf_glyph_transform_weight ( FT_GlyphSlot  glyph,
float  factor,
bool  monospaced 
)
static

Adjust the glyphs weight by a factor.

Parameters
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().

◆ blf_glyph_transform_width()

static bool blf_glyph_transform_width ( FT_GlyphSlot  glyph,
float  factor 
)
static

Adjust the glyph width by factor.

Parameters
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().

◆ blf_texture3_draw()

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 
)
static

Definition at line 1092 of file blf_glyph.c.

References blf_texture_draw(), offset, x2, and y1.

Referenced by blf_glyph_draw().

◆ blf_texture5_draw()

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

Definition at line 1076 of file blf_glyph.c.

References blf_texture_draw(), offset, x2, and y1.

Referenced by blf_glyph_draw().

◆ blf_texture_draw()

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

◆ blf_var_axis_by_tag()

static FT_Var_Axis* blf_var_axis_by_tag ( FT_MM_Var *  variations,
uint  tag,
int *  axis_index 
)
static

Return a design axis that matches an identifying tag.

Parameters
variationsVariation descriptors from FT_Get_MM_Var.
tagAxis tag (4-character string as uint), like 'wght'
axis_indexreturns 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().

◆ to_16dot16()

static FT_Fixed to_16dot16 ( double  val)
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().

Variable Documentation

◆ unicode_blocks

eUnicodeBlock unicode_blocks[]
static

Definition at line 244 of file blf_glyph.c.

Referenced by blf_charcode_to_unicode_block().