From 3b62e9dc9d09a5db4052b2488909c27dd95bd8ab Mon Sep 17 00:00:00 2001 From: Moazin Khatti Date: Wed, 17 Jul 2019 12:22:47 +0500 Subject: [PATCH] Added `FT_CONFIG_OPTION_SVG'. --- include/freetype/config/ftoption.h | 9 +++++++++ include/freetype/freetype.h | 2 ++ include/freetype/ftglyph.h | 2 ++ include/freetype/internal/ftobjs.h | 5 ++++- include/freetype/internal/tttypes.h | 2 ++ include/freetype/svgrender.h | 3 ++- src/base/ftglyph.c | 10 +++++++--- src/base/ftobjs.c | 15 ++++++++++++++- src/cff/cffgload.c | 2 ++ src/sfnt/sfdriver.c | 17 ++++++++++++++--- src/sfnt/sfobjs.c | 18 +++++++++--------- src/sfnt/ttsvg.c | 12 ++++++++---- src/truetype/ttgload.c | 5 ++++- 13 files changed, 79 insertions(+), 23 deletions(-) diff --git a/include/freetype/config/ftoption.h b/include/freetype/config/ftoption.h index ca47c03f6..1a375248d 100644 --- a/include/freetype/config/ftoption.h +++ b/include/freetype/config/ftoption.h @@ -493,6 +493,15 @@ FT_BEGIN_HEADER #undef FT_CONFIG_OPTION_USE_MODULE_ERRORS + /************************************************************************** + * + * OpenType SVG Glyph Support + * + * If this macro is set, OpenType SVG glyphs will be supported. + */ +#define FT_CONFIG_OPTION_SVG + + /************************************************************************** * * Error Strings diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h index d715f28a3..4d1f47482 100644 --- a/include/freetype/freetype.h +++ b/include/freetype/freetype.h @@ -1227,7 +1227,9 @@ FT_BEGIN_HEADER #define FT_FACE_FLAG_TRICKY ( 1L << 13 ) #define FT_FACE_FLAG_COLOR ( 1L << 14 ) #define FT_FACE_FLAG_VARIATION ( 1L << 15 ) +#ifdef FT_CONFIG_OPTION_SVG #define FT_FACE_FLAG_SVG ( 1L << 16 ) +#endif /************************************************************************** diff --git a/include/freetype/ftglyph.h b/include/freetype/ftglyph.h index 8b1e3f6b6..b71c5472f 100644 --- a/include/freetype/ftglyph.h +++ b/include/freetype/ftglyph.h @@ -223,6 +223,7 @@ FT_BEGIN_HEADER } FT_OutlineGlyphRec; +#ifdef FT_CONFIG_OPTION_SVG /************************************************************************** * * @type: @@ -292,6 +293,7 @@ FT_BEGIN_HEADER /* TODO: (OT-SVG) Maybe put a transformation matrix here */ } FT_SvgGlyphRec; +#endif /************************************************************************** * diff --git a/include/freetype/internal/ftobjs.h b/include/freetype/internal/ftobjs.h index e6aa4d88f..652349c73 100644 --- a/include/freetype/internal/ftobjs.h +++ b/include/freetype/internal/ftobjs.h @@ -419,7 +419,9 @@ FT_BEGIN_HEADER */ #define FT_GLYPH_OWN_BITMAP 0x1U +#ifdef FT_CONFIG_OPTION_SVG #define FT_GLYPH_OWN_GZIP_SVG 0x2U +#endif typedef struct FT_Slot_InternalRec_ { @@ -921,8 +923,9 @@ FT_BEGIN_HEADER FT_Int refcount; +#ifdef FT_CONFIG_OPTION_SVG void* svg_renderer_state; - +#endif } FT_LibraryRec; diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h index 42a921fe7..c772d0ca2 100644 --- a/include/freetype/internal/tttypes.h +++ b/include/freetype/internal/tttypes.h @@ -1645,8 +1645,10 @@ FT_BEGIN_HEADER void* cpal; void* colr; +#ifdef FT_CONFIG_OPTION_SVG /* OpenType SVG Glyph Support */ void* svg; +#endif } TT_FaceRec; diff --git a/include/freetype/svgrender.h b/include/freetype/svgrender.h index 218054120..b2f14c3aa 100644 --- a/include/freetype/svgrender.h +++ b/include/freetype/svgrender.h @@ -28,6 +28,7 @@ #error "so that freetype.h of FreeType 2 is found first." #endif +#ifdef FT_CONFIG_OPTION_SVG FT_BEGIN_HEADER /************************************************************************** @@ -255,5 +256,5 @@ FT_BEGIN_HEADER typedef struct FT_SVG_DocumentRec_* FT_SVG_Document; FT_END_HEADER - +#endif /* FT_CONFIG_OPTION_SVG */ #endif diff --git a/src/base/ftglyph.c b/src/base/ftglyph.c index f088b38fd..57603f1e7 100644 --- a/src/base/ftglyph.c +++ b/src/base/ftglyph.c @@ -276,6 +276,7 @@ ft_outline_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */ ) +#ifdef FT_CONFIG_OPTION_SVG /*************************************************************************/ /*************************************************************************/ /**** ****/ @@ -441,7 +442,7 @@ ft_svg_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */ ) - +#endif /*************************************************************************/ /*************************************************************************/ @@ -543,9 +544,11 @@ else if ( format == FT_GLYPH_FORMAT_OUTLINE ) clazz = &ft_outline_glyph_class; +#ifdef FT_CONFIG_OPTION_SVG /* if it is a SVG glyph */ else if ( format == FT_GLYPH_FORMAT_SVG ) clazz = &ft_svg_glyph_class; +#endif else { @@ -716,7 +719,6 @@ const FT_Glyph_Class* clazz; FT_Library library; - FT_Memory memory; /* check argument */ @@ -728,7 +730,6 @@ clazz = glyph->clazz; library = glyph->library; - memory = library->memory; if ( !library || !clazz ) goto Bad; @@ -767,10 +768,13 @@ if ( !error ) { error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode ); +#ifdef FT_CONFIG_OPTION_SVG if ( clazz == &ft_svg_glyph_class ) { + FT_Memory memory = library->memory; FT_FREE( dummy.other ); } +#endif } #if 1 diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c index 349fcca84..88944fb92 100644 --- a/src/base/ftobjs.c +++ b/src/base/ftobjs.c @@ -318,6 +318,7 @@ if ( !error && clazz->init_slot ) error = clazz->init_slot( slot ); +#ifdef FT_CONFIG_OPTION_SVG /* check if SVG table exists allocate the space in slot->other */ if ( slot->face->face_flags & FT_FACE_FLAG_SVG ) { @@ -326,6 +327,7 @@ goto Exit; slot->other = document; } +#endif Exit: return error; @@ -561,7 +563,9 @@ slot->subglyphs = NULL; slot->control_data = NULL; slot->control_len = 0; - +#ifndef FT_CONFIG_OPTION_SVG + slot->other = NULL; +#else if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) ) slot->other = NULL; else @@ -574,6 +578,7 @@ slot->internal->load_flags &= ~FT_GLYPH_OWN_GZIP_SVG; } } +#endif slot->format = FT_GLYPH_FORMAT_NONE; @@ -592,6 +597,7 @@ FT_Memory memory = driver->root.memory; +#ifdef FT_CONFIG_OPTION_SVG if ( slot->face->face_flags & FT_FACE_FLAG_SVG ) { /* free memory in case svg was there */ @@ -603,6 +609,7 @@ } FT_FREE( slot->other ); } +#endif if ( clazz->done_slot ) clazz->done_slot( slot ); @@ -873,11 +880,13 @@ if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) load_flags &= ~FT_LOAD_RENDER; +#ifdef FT_CONFIG_OPTION_SVG if ( ( load_flags & FT_LOAD_COLOR ) && ( ttface->svg ) ) { FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE); } +#endif /* * Determine whether we need to auto-hint or not. @@ -4445,10 +4454,12 @@ render->render = clazz->render_glyph; } +#ifdef FT_CONFIG_OPTION_SVG if ( clazz->glyph_format == FT_GLYPH_FORMAT_SVG ) { render->render = clazz->render_glyph; } +#endif /* add to list */ node->data = module; @@ -5592,6 +5603,7 @@ return 0; } +#ifdef FT_CONFIG_OPTION_SVG FT_EXPORT_DEF( FT_Error ) FT_Set_Svg_Hooks( FT_Library library, SVG_Lib_Init_Func init_svg, @@ -5617,5 +5629,6 @@ get_buffer_size ); return FT_Err_Ok; } +#endif /* END */ diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c index 9edcf12cf..58ba300ab 100644 --- a/src/cff/cffgload.c +++ b/src/cff/cffgload.c @@ -347,6 +347,7 @@ if ( load_flags & FT_LOAD_SBITS_ONLY ) return FT_THROW( Invalid_Argument ); +#ifdef FT_CONFIG_OPTION_SVG /* check for OT-SVG */ if ( ( load_flags & FT_LOAD_COLOR ) && ( ((TT_Face)glyph->root.face)->svg ) ) @@ -359,6 +360,7 @@ return error; } } +#endif /* if we have a CID subfont, use its matrix (which has already */ /* been multiplied with the root matrix) */ diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index b131bf4f1..f16c96b6f 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -37,7 +37,9 @@ #include "ttcpal.h" #endif +#ifdef FT_CONFIG_OPTION_SVG #include "ttsvg.h" /* OpenType SVG support */ +#endif #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #include "ttpost.h" @@ -1210,6 +1212,12 @@ #define PUT_EMBEDDED_BITMAPS( a ) NULL #endif +#ifdef FT_CONFIG_OPTION_SVG +#define PUT_SVG_SUPPORT( a ) a +#else +#define PUT_SVG_SUPPORT( a ) NULL +#endif + #ifdef TT_CONFIG_OPTION_COLOR_LAYERS #define PUT_COLOR_LAYERS( a ) a #else @@ -1297,9 +1305,12 @@ tt_face_get_name, /* TT_Get_Name_Func get_name */ sfnt_get_name_id, /* TT_Get_Name_ID_Func get_name_id */ - tt_face_load_svg, /* TT_Load_Table_Func load_svg */ - tt_face_free_svg, /* TT_Free_Table_Func free_svg */ - tt_face_load_svg_doc /* TT_Load_Svg_Doc_Func load_svg_doc */ + PUT_SVG_SUPPORT( tt_face_load_svg ), + /* TT_Load_Table_Func load_svg */ + PUT_SVG_SUPPORT( tt_face_free_svg ), + /* TT_Free_Table_Func free_svg */ + PUT_SVG_SUPPORT( tt_face_load_svg_doc ) + /* TT_Load_Svg_Doc_Func load_svg_doc */ ) diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 67b1aa9bc..3c8323e67 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -751,7 +751,6 @@ FT_Bool is_apple_sbix; FT_Bool has_CBLC; FT_Bool has_CBDT; - FT_Bool has_SVG = FALSE; /* for OT-SVG */ FT_Bool ignore_typographic_family = FALSE; FT_Bool ignore_typographic_subfamily = FALSE; @@ -954,12 +953,11 @@ LOAD_( colr ); } - /* opentype svg colored glyph support */ - /* no If statement because the function always exists for now */ - LOAD_( svg ); - - if( face->svg ) - has_SVG = TRUE; +#ifdef FT_CONFIG_OPTION_SVG + /* opentype svg glyph support */ + if ( sfnt->load_svg ) + LOAD_( svg ); +#endif /* consider the pclt, kerning, and gasp tables as optional */ LOAD_( pclt ); @@ -1380,9 +1378,11 @@ sfnt->free_cpal( face ); sfnt->free_colr( face ); } - +#ifdef FT_CONFIG_OPTION_SVG /* free svg data */ - sfnt->free_svg( face ); + if ( sfnt->free_svg ) + sfnt->free_svg( face ); +#endif } #ifdef TT_CONFIG_OPTION_BDF diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c index c4b8c260a..925b0b109 100644 --- a/src/sfnt/ttsvg.c +++ b/src/sfnt/ttsvg.c @@ -31,6 +31,7 @@ #include FT_GZIP_H #include FT_SVG_RENDER_H +#ifdef FT_CONFIG_OPTION_SVG #include "ttsvg.h" @@ -187,8 +188,6 @@ FT_ULong uncomp_size; FT_Byte* uncomp_buffer; - FT_Bool is_gzip_encoded = FALSE; - FT_Error error = FT_Err_Ok; TT_Face face = (TT_Face)glyph->face; FT_Memory memory = face->root.memory; @@ -212,8 +211,6 @@ if( ( doc_list[0] == 0x1F ) && ( doc_list[1] == 0x8B ) && ( doc_list[2] == 0x08 ) ) { - is_gzip_encoded = TRUE; - /* get the size of the orignal document. This helps in alotting the * buffer to accomodate the uncompressed version. The last 4 bytes * of the compressed document are equal to orignal_size modulo 2^32. @@ -254,3 +251,10 @@ return FT_Err_Ok; } + +#else /* !FT_CONFIG_OPTION_SVG */ + + /* ANSI C doesn't like empty source files */ + typedef int _tt_cpal_dummy; + +#endif /* !FT_CONFIG_OPTION_SVG */ diff --git a/src/truetype/ttgload.c b/src/truetype/ttgload.c index 77c74a6d5..f65e00385 100644 --- a/src/truetype/ttgload.c +++ b/src/truetype/ttgload.c @@ -2796,7 +2796,7 @@ { FT_Error error; TT_LoaderRec loader; - SFNT_Service sfnt; + FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index )); @@ -2907,9 +2907,11 @@ goto Exit; } +#ifdef FT_CONFIG_OPTION_SVG /* check for OT-SVG */ if ( ( load_flags & FT_LOAD_COLOR ) && ( ((TT_Face)glyph->face)->svg ) ) { + SFNT_Service sfnt; sfnt = (SFNT_Service)((TT_Face)glyph->face)->sfnt; error = sfnt->load_svg_doc( glyph, glyph_index ); if( error == FT_Err_Ok ) @@ -2918,6 +2920,7 @@ return error; } } +#endif if ( load_flags & FT_LOAD_SBITS_ONLY ) {