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.
This commit is contained in:
Werner Lemberg 2023-05-15 15:44:36 +02:00
parent 872a759b46
commit 416d4c25f1
5 changed files with 21 additions and 8 deletions

View File

@ -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.
======================================================================

View File

@ -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 )
/* */

View File

@ -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,

View File

@ -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 ||

View File

@ -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;