Commit: 228d79b78977282fcfcfe95a24a97cd023f3dc3f Author: Harley Acheson Date: Mon Jun 27 06:32:30 2022 -0700 Branches: master https://developer.blender.org/rB228d79b78977282fcfcfe95a24a97cd023f3dc3f
Revert 6de0f299505a: BLF: Support for Variable Fonts Reverting for now, breaks on GCC =================================================================== M source/blender/blenfont/intern/blf_font.c M source/blender/blenfont/intern/blf_glyph.c M source/blender/blenfont/intern/blf_internal_types.h =================================================================== diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 038e73cc928..3e2927d581e 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -18,8 +18,7 @@ #include FT_FREETYPE_H #include FT_GLYPH_H -#include FT_TRUETYPE_TABLES_H /* For TT_OS2 */ -#include FT_MULTIPLE_MASTERS_H /* Variable font support. */ +#include FT_TRUETYPE_TABLES_H /* For TT_OS2 */ #include "MEM_guardedalloc.h" @@ -1286,10 +1285,6 @@ FontBLF *blf_font_new(const char *name, const char *filepath) MEM_freeN(mfile); } - if (FT_HAS_MULTIPLE_MASTERS(font->face)) { - FT_Get_MM_Var(font->face, &(font->variations)); - } - font->name = BLI_strdup(name); font->filepath = BLI_strdup(filepath); blf_font_fill(font); @@ -1356,10 +1351,6 @@ FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, int m return NULL; } - if (FT_HAS_MULTIPLE_MASTERS(font->face)) { - FT_Get_MM_Var(font->face, &(font->variations)); - } - font->name = BLI_strdup(name); font->filepath = NULL; blf_font_fill(font); @@ -1374,10 +1365,6 @@ void blf_font_free(FontBLF *font) MEM_freeN(font->kerning_cache); } - if (font->variations) { - FT_Done_MM_Var(ft_lib, font->variations); - } - FT_Done_Face(font->face); if (font->filepath) { MEM_freeN(font->filepath); diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index f1a9816c417..bda6c51bf14 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -19,7 +19,6 @@ #include FT_OUTLINE_H #include FT_BITMAP_H #include FT_ADVANCES_H /* For FT_Get_Advance. */ -#include FT_MULTIPLE_MASTERS_H /* Variable font support. */ #include "MEM_guardedalloc.h" @@ -65,9 +64,7 @@ static GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, float size, unsigned i GlyphCacheBLF *gc = (GlyphCacheBLF *)font->cache.first; while (gc) { if (gc->size == size && gc->dpi == dpi && (gc->bold == ((font->flags & BLF_BOLD) != 0)) && - (gc->italic == ((font->flags & BLF_ITALIC) != 0)) && - (gc->char_weight == font->char_weight) && (gc->char_slant == font->char_slant) && - (gc->char_width == font->char_width) && (gc->char_spacing == font->char_spacing)) { + (gc->italic == ((font->flags & BLF_ITALIC) != 0))) { return gc; } gc = gc->next; @@ -85,10 +82,6 @@ static GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) gc->dpi = font->dpi; gc->bold = ((font->flags & BLF_BOLD) != 0); gc->italic = ((font->flags & BLF_ITALIC) != 0); - gc->char_weight = font->char_weight; - gc->char_slant = font->char_slant; - gc->char_width = font->char_width; - gc->char_spacing = font->char_spacing; memset(gc->glyph_ascii_table, 0, sizeof(gc->glyph_ascii_table)); memset(gc->bucket, 0, sizeof(gc->bucket)); @@ -680,96 +673,6 @@ static bool blf_glyph_render_bitmap(FontBLF *font, FT_GlyphSlot glyph) /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Variations (Multiple Masters) support - * \{ */ - -/** - * Return a design axis that matches an identifying tag. - * - * \param variations: Variation descriptors from `FT_Get_MM_Var`. - * \param tag: Axis tag (4-character string as uint), like 'wght' - * \param axis_index: returns index of axis in variations array. - */ -static FT_Var_Axis *blf_var_axis_by_tag(FT_MM_Var *variations, uint tag, int *axis_index) -{ - *axis_index = -1; - if (!variations) { - return NULL; - } - for (int i = 0; i < (int)variations->num_axis; i++) { - if (variations->axis[i].tag == tag) { - *axis_index = i; - return &(variations->axis)[i]; - break; - } - } - return NULL; -} - -/** - * Convert a float factor to a fixed-point design coordinate. - * - * \param axis: Pointer to a design space axis structure. - * \param factor: -1 to 1 with 0 meaning "default" - */ -static FT_Fixed blf_factor_to_coordinate(FT_Var_Axis *axis, float factor) -{ - FT_Fixed value = axis->def; - if (factor > 0) { - /* Map 0-1 to axis->def - axis->maximum */ - value += (FT_Fixed)((double)(axis->maximum - axis->def) * factor); - } - else if (factor < 0) { - /* Map -1-0 to axis->minimum - axis->def */ - value += (FT_Fixed)((double)(axis->def - axis->minimum) * factor); - } - return value; -} - -/** - * Alter a face variation axis by a factor - * - * \param coords: array of design coordinates, per axis. - * \param tag: Axis tag (4-character string as uint), like 'wght' - * \param factor: -1 to 1 with 0 meaning "default" - */ -static bool blf_glyph_set_variation_normalized(FontBLF *font, - FT_Fixed coords[], - uint tag, - float factor) -{ - int axis_index; - FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); - if (axis && (axis_index < BLF_VARIATIONS_MAX)) { - coords[axis_index] = blf_factor_to_coordinate(axis, factor); - return true; - } - return false; -} - -/** - * Set a face variation axis to an exact float value - * - * \param coords: array of design coordinates, per axis. - * \param tag: Axis tag (4-character string as uint), like 'opsz' - * \param value: New float value. Converted to 16.16 and clamped within allowed range. - */ -static bool blf_glyph_set_variation_float(FontBLF *font, FT_Fixed coords[], uint tag, float value) -{ - int axis_index; - FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); - if (axis && (axis_index < BLF_VARIATIONS_MAX)) { - FT_Fixed int_value = to_16dot16(value); - CLAMP(int_value, axis->minimum, axis->maximum); - coords[axis_index] = int_value; - return true; - } - return false; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Glyph Transformations * \{ */ @@ -823,7 +726,7 @@ static bool blf_glyph_transform_slant(FT_GlyphSlot glyph, float factor) * * \param factor: -1 (min width) <= 0 (normal) => 1 (max width). */ -static bool blf_glyph_transform_width(FT_GlyphSlot glyph, float factor) +static bool UNUSED_FUNCTION(blf_glyph_transform_width)(FT_GlyphSlot glyph, float factor) { if (glyph->format == FT_GLYPH_FORMAT_OUTLINE) { float scale = (factor * 0.4f) + 1.0f; /* 0.6f - 1.4f */ @@ -835,21 +738,6 @@ static bool blf_glyph_transform_width(FT_GlyphSlot glyph, float factor) return false; } -/** - * Change glyph advance to alter letter-spacing (tracking). - * - * \param factor: -1 (min tightness) <= 0 (normal) => 1 (max looseness). - */ -static bool blf_glyph_transform_spacing(FT_GlyphSlot glyph, float factor) -{ - if (glyph->advance.x > 0) { - const int size = glyph->face->size->metrics.height; - glyph->advance.x += (FT_Pos)(factor * (float)size / 6.0f); - return true; - } - return false; -} - /** * Transform glyph to fit nicely within a fixed column width. */ @@ -901,43 +789,6 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font, glyph_font->dpi = settings_font->dpi; } - /* We need to keep track if changes are still needed. */ - bool weight_done = false; - bool slant_done = false; - bool width_done = false; - bool spacing_done = false; - - /* 70% of maximum weight results in the same amount of boldness and horizontal - * expansion as the bold version (DejaVuSans-Bold.ttf) of our default font. - * Worth reevaluating if we change default font. */ - float weight = (settings_font->flags & BLF_BOLD) ? 0.7f : settings_font->char_weight; - - /* 37.5% of maximum rightward slant results in 6 degree slope, matching italic - * version (DejaVuSans-Oblique.ttf) of our current font. But a nice median when - * checking others. Worth reevaluating if we change default font. We could also - * narrow the glyph slightly as most italics do, but this one does not. */ - float slant = (settings_font->flags & BLF_ITALIC) ? 0.375f : settings_font->char_slant; - - float width = settings_font->char_width; - float spacing = settings_font->char_spacing; - - /* Font variations need to be set before glyph loading. Even if new value is zero. */ - - if (glyph_font->variations) { - FT_Fixed coords[BLF_VARIATIONS_MAX]; - /* Load current design coordinates. */ - FT_Get_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]); - /* Update design coordinates with new values. */ - weight_done = blf_glyph_set_variation_normalized(glyph_font, coords, 'wght', weight); - slant_done = blf_glyph_set_variation_normalized(glyph_font, coords, 'slnt', slant); - width_done = blf_glyph_set_variation_normalized(glyph_font, coords, 'wdth', width); - spacing_done = blf_glyph_set_variation_normalized(glyph_font, coords, 'spac', spacing); - /* Optical size, if available, is set to current font size. */ - blf_glyph_set_variation_float(glyph_font, coords, 'opsz', settings_font->size); - /* Save updated design coordinates. */ - FT_Set_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]); - } - FT_GlyphSlot glyph = blf_glyph_load(glyph_font, glyph_index); if (!glyph) { return NULL; @@ -947,21 +798,6 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font, blf_glyph_transform_monospace(glyph, BLI_wcwidth((char32_t)charcode) * fixed_width); } - /* Fallback glyph transforms, but only if required and not yet done. */ - - if (weight != 0.0f && !weight_done) { - blf_glyph_transform_weight(glyph, weight, glyph->face->face_flags & FT_FACE_FLAG_FIXED_WIDTH); - } - if (slant != 0.0f && !slant_done) { - blf_glyph_transform_slant(glyph, slant); - } - if (width != 0.0f && !width_done) { - blf_glyph_transform_width(glyph, width); - } - if (spacing != 0.0f && !spacing_done) { - blf_glyph_transform_spacing(glyph, spacing); - } - if (blf_glyph_render_bitmap(glyph_font, glyph)) { return glyph; } diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 238301b9c4d..998093dae70 1006 @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs