From 416d4c25f1e15d2494d373982a511928f635e705 Mon Sep 17 00:00:00 2001 From: Werner Lemberg Date: Mon, 15 May 2023 15:44:36 +0200 Subject: Add new load flag `FT_LOAD_NO_SVG`. Modern color fonts often contain both an 'SVG' and 'COLR' table. FreeType always preferred 'SVG' over 'COLR' (this was a design decision), however, this might not be the right choice for the user. The new flags makes FreeType ignore the 'SVG' table while loading a glyph. Fixes #1229. * include/freetype/freetype.h (FT_LOAD_NO_SVG): New macro. * src/base/ftobjs.c (FT_Load_Glyph), src/cff/cffgload.c (cff_slot_load), src/truetype/ttgload.c (TT_Load_Glyph): Use it. --- docs/CHANGES | 3 +++ include/freetype/freetype.h | 13 +++++++++---- src/base/ftobjs.c | 3 ++- src/cff/cffgload.c | 6 ++++-- src/truetype/ttgload.c | 4 +++- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/docs/CHANGES b/docs/CHANGES index 105f976e8..7562f10e7 100644 --- a/docs/CHANGES +++ b/docs/CHANGES @@ -5,6 +5,9 @@ CHANGES BETWEEN 2.13.0 and 2.13.1 (2023-XXX-XX) - New function `FT_Get_Default_Named_Instance` to get the index of the default named instance of an OpenType Variation Font. + - A new load flag `FT_LOAD_NO_SVG` to make FreeType ignore glyphs in + an 'SVG ' table. + ====================================================================== diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index 15609e6a2..81f0e86ed 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -3425,10 +3425,11 @@ FT_BEGIN_HEADER * * [Since 2.12] If the glyph index maps to an entry in the face's * 'SVG~' table, load the associated SVG document from this table and - * set the `format` field of @FT_GlyphSlotRec to @FT_GLYPH_FORMAT_SVG. - * Note that FreeType itself can't render SVG documents; however, the - * library provides hooks to seamlessly integrate an external renderer. - * See sections @ot_svg_driver and @svg_fonts for more. + * set the `format` field of @FT_GlyphSlotRec to @FT_GLYPH_FORMAT_SVG + * ([since 2.13.1] provided @FT_LOAD_NO_SVG is not set). Note that + * FreeType itself can't render SVG documents; however, the library + * provides hooks to seamlessly integrate an external renderer. See + * sections @ot_svg_driver and @svg_fonts for more. * * [Since 2.10, experimental] If the glyph index maps to an entry in * the face's 'COLR' table with a 'CPAL' palette table (as defined in @@ -3442,6 +3443,9 @@ FT_BEGIN_HEADER * @FT_Palette_Select instead of setting @FT_LOAD_COLOR for rendering * so that the client application can handle blending by itself. * + * FT_LOAD_NO_SVG :: + * [Since 2.13.1] Ignore SVG glyph data when loading. + * * FT_LOAD_COMPUTE_METRICS :: * [Since 2.6.1] Compute glyph metrics from the glyph data, without the * use of bundled metrics tables (for example, the 'hdmx' table in @@ -3507,6 +3511,7 @@ FT_BEGIN_HEADER #define FT_LOAD_COLOR ( 1L << 20 ) #define FT_LOAD_COMPUTE_METRICS ( 1L << 21 ) #define FT_LOAD_BITMAP_METRICS_ONLY ( 1L << 22 ) +#define FT_LOAD_NO_SVG ( 1L << 24 ) /* */ diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index b7e89540e..abfa3ab0e 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -1019,7 +1019,8 @@ /* elegant. */ /* try to load SVG documents if available */ - if ( FT_HAS_SVG( face ) ) + if ( ( load_flags & FT_LOAD_NO_SVG ) == 0 && + FT_HAS_SVG( face ) ) { error = driver->clazz->load_glyph( slot, face->size, glyph_index, diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c index cfa0aaf2b..c483d1d1a 100644 --- a/src/cff/cffgload.c +++ b/src/cff/cffgload.c @@ -356,14 +356,16 @@ #ifdef FT_CONFIG_OPTION_SVG /* check for OT-SVG */ - if ( ( load_flags & FT_LOAD_COLOR ) && face->svg ) + if ( ( load_flags & FT_LOAD_NO_SVG ) == 0 && + ( load_flags & FT_LOAD_COLOR ) && + face->svg ) { /* * We load the SVG document and try to grab the advances from the * table. For the bearings we rely on the presetting hook to do that. */ - SFNT_Service sfnt = (SFNT_Service)face->sfnt; + SFNT_Service sfnt = (SFNT_Service)face->sfnt; if ( size && (size->root.metrics.x_ppem < 1 || diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index b56db1740..5f15a7f4d 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -2802,7 +2802,9 @@ #ifdef FT_CONFIG_OPTION_SVG /* check for OT-SVG */ - if ( ( load_flags & FT_LOAD_COLOR ) && face->svg ) + if ( ( load_flags & FT_LOAD_NO_SVG ) == 0 && + ( load_flags & FT_LOAD_COLOR ) && + face->svg ) { SFNT_Service sfnt = (SFNT_Service)face->sfnt; -- cgit v1.2.1