Added `FT_CONFIG_OPTION_SVG'.

This commit is contained in:
Moazin Khatti 2019-07-17 12:22:47 +05:00
parent 41a1572f33
commit def48796f4
13 changed files with 80 additions and 22 deletions

View File

@ -493,6 +493,15 @@ FT_BEGIN_HEADER
#undef FT_CONFIG_OPTION_USE_MODULE_ERRORS #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 * Error Strings

View File

@ -1227,7 +1227,9 @@ FT_BEGIN_HEADER
#define FT_FACE_FLAG_TRICKY ( 1L << 13 ) #define FT_FACE_FLAG_TRICKY ( 1L << 13 )
#define FT_FACE_FLAG_COLOR ( 1L << 14 ) #define FT_FACE_FLAG_COLOR ( 1L << 14 )
#define FT_FACE_FLAG_VARIATION ( 1L << 15 ) #define FT_FACE_FLAG_VARIATION ( 1L << 15 )
#ifdef FT_CONFIG_OPTION_SVG
#define FT_FACE_FLAG_SVG ( 1L << 16 ) #define FT_FACE_FLAG_SVG ( 1L << 16 )
#endif
/************************************************************************** /**************************************************************************

View File

@ -223,6 +223,7 @@ FT_BEGIN_HEADER
} FT_OutlineGlyphRec; } FT_OutlineGlyphRec;
#ifdef FT_CONFIG_OPTION_SVG
/************************************************************************** /**************************************************************************
* *
* @type: * @type:
@ -292,6 +293,7 @@ FT_BEGIN_HEADER
/* TODO: (OT-SVG) Maybe put a transformation matrix here */ /* TODO: (OT-SVG) Maybe put a transformation matrix here */
} FT_SvgGlyphRec; } FT_SvgGlyphRec;
#endif
/************************************************************************** /**************************************************************************
* *

View File

@ -419,7 +419,9 @@ FT_BEGIN_HEADER
*/ */
#define FT_GLYPH_OWN_BITMAP 0x1U #define FT_GLYPH_OWN_BITMAP 0x1U
#ifdef FT_CONFIG_OPTION_SVG
#define FT_GLYPH_OWN_GZIP_SVG 0x2U #define FT_GLYPH_OWN_GZIP_SVG 0x2U
#endif
typedef struct FT_Slot_InternalRec_ typedef struct FT_Slot_InternalRec_
{ {
@ -921,8 +923,9 @@ FT_BEGIN_HEADER
FT_Int refcount; FT_Int refcount;
#ifdef FT_CONFIG_OPTION_SVG
void* svg_renderer_state; void* svg_renderer_state;
#endif
} FT_LibraryRec; } FT_LibraryRec;

View File

@ -1645,8 +1645,10 @@ FT_BEGIN_HEADER
void* cpal; void* cpal;
void* colr; void* colr;
#ifdef FT_CONFIG_OPTION_SVG
/* OpenType SVG Glyph Support */ /* OpenType SVG Glyph Support */
void* svg; void* svg;
#endif
} TT_FaceRec; } TT_FaceRec;

View File

@ -28,6 +28,7 @@
#error "so that freetype.h of FreeType 2 is found first." #error "so that freetype.h of FreeType 2 is found first."
#endif #endif
#ifdef FT_CONFIG_OPTION_SVG
FT_BEGIN_HEADER FT_BEGIN_HEADER
/************************************************************************** /**************************************************************************
@ -255,5 +256,5 @@ FT_BEGIN_HEADER
typedef struct FT_SVG_DocumentRec_* FT_SVG_Document; typedef struct FT_SVG_DocumentRec_* FT_SVG_Document;
FT_END_HEADER FT_END_HEADER
#endif /* FT_CONFIG_OPTION_SVG */
#endif #endif

View File

@ -276,6 +276,7 @@
ft_outline_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */ 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 */ ft_svg_glyph_prepare /* FT_Glyph_PrepareFunc glyph_prepare */
) )
#endif
/*************************************************************************/ /*************************************************************************/
/*************************************************************************/ /*************************************************************************/
@ -543,9 +544,11 @@
else if ( format == FT_GLYPH_FORMAT_OUTLINE ) else if ( format == FT_GLYPH_FORMAT_OUTLINE )
clazz = &ft_outline_glyph_class; clazz = &ft_outline_glyph_class;
#ifdef FT_CONFIG_OPTION_SVG
/* if it is a SVG glyph */ /* if it is a SVG glyph */
else if ( format == FT_GLYPH_FORMAT_SVG ) else if ( format == FT_GLYPH_FORMAT_SVG )
clazz = &ft_svg_glyph_class; clazz = &ft_svg_glyph_class;
#endif
else else
{ {
@ -716,7 +719,6 @@
const FT_Glyph_Class* clazz; const FT_Glyph_Class* clazz;
FT_Library library; FT_Library library;
FT_Memory memory;
/* check argument */ /* check argument */
@ -728,7 +730,6 @@
clazz = glyph->clazz; clazz = glyph->clazz;
library = glyph->library; library = glyph->library;
memory = library->memory;
if ( !library || !clazz ) if ( !library || !clazz )
goto Bad; goto Bad;
@ -767,10 +768,13 @@
if ( !error ) if ( !error )
{ {
error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode ); error = FT_Render_Glyph_Internal( glyph->library, &dummy, render_mode );
#ifdef FT_CONFIG_OPTION_SVG
if ( clazz == &ft_svg_glyph_class ) if ( clazz == &ft_svg_glyph_class )
{ {
FT_Memory memory = library->memory;
FT_FREE( dummy.other ); FT_FREE( dummy.other );
} }
#endif
} }
#if 1 #if 1

View File

@ -318,6 +318,7 @@
if ( !error && clazz->init_slot ) if ( !error && clazz->init_slot )
error = clazz->init_slot( slot ); error = clazz->init_slot( slot );
#ifdef FT_CONFIG_OPTION_SVG
/* check if SVG table exists allocate the space in slot->other */ /* check if SVG table exists allocate the space in slot->other */
if ( slot->face->face_flags & FT_FACE_FLAG_SVG ) if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
{ {
@ -326,6 +327,7 @@
goto Exit; goto Exit;
slot->other = document; slot->other = document;
} }
#endif
Exit: Exit:
return error; return error;
@ -561,7 +563,9 @@
slot->subglyphs = NULL; slot->subglyphs = NULL;
slot->control_data = NULL; slot->control_data = NULL;
slot->control_len = 0; slot->control_len = 0;
#ifndef FT_CONFIG_OPTION_SVG
slot->other = NULL;
#else
if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) ) if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) )
slot->other = NULL; slot->other = NULL;
else else
@ -574,6 +578,7 @@
slot->internal->load_flags &= ~FT_GLYPH_OWN_GZIP_SVG; slot->internal->load_flags &= ~FT_GLYPH_OWN_GZIP_SVG;
} }
} }
#endif
slot->format = FT_GLYPH_FORMAT_NONE; slot->format = FT_GLYPH_FORMAT_NONE;
@ -592,6 +597,7 @@
FT_Memory memory = driver->root.memory; FT_Memory memory = driver->root.memory;
#ifdef FT_CONFIG_OPTION_SVG
if ( slot->face->face_flags & FT_FACE_FLAG_SVG ) if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
{ {
/* free memory in case svg was there */ /* free memory in case svg was there */
@ -603,6 +609,7 @@
} }
FT_FREE( slot->other ); FT_FREE( slot->other );
} }
#endif
if ( clazz->done_slot ) if ( clazz->done_slot )
clazz->done_slot( slot ); clazz->done_slot( slot );
@ -873,11 +880,13 @@
if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY ) if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
load_flags &= ~FT_LOAD_RENDER; load_flags &= ~FT_LOAD_RENDER;
#ifdef FT_CONFIG_OPTION_SVG
if ( ( load_flags & FT_LOAD_COLOR ) && if ( ( load_flags & FT_LOAD_COLOR ) &&
( ttface->svg ) ) ( ttface->svg ) )
{ {
FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE); FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE);
} }
#endif
/* /*
* Determine whether we need to auto-hint or not. * Determine whether we need to auto-hint or not.
@ -4445,10 +4454,12 @@
render->render = clazz->render_glyph; render->render = clazz->render_glyph;
} }
#ifdef FT_CONFIG_OPTION_SVG
if ( clazz->glyph_format == FT_GLYPH_FORMAT_SVG ) if ( clazz->glyph_format == FT_GLYPH_FORMAT_SVG )
{ {
render->render = clazz->render_glyph; render->render = clazz->render_glyph;
} }
#endif
/* add to list */ /* add to list */
node->data = module; node->data = module;
@ -5592,6 +5603,7 @@
return 0; return 0;
} }
#ifdef FT_CONFIG_OPTION_SVG
FT_EXPORT_DEF( FT_Error ) FT_EXPORT_DEF( FT_Error )
FT_Set_Svg_Hooks( FT_Library library, FT_Set_Svg_Hooks( FT_Library library,
SVG_Lib_Init_Func init_svg, SVG_Lib_Init_Func init_svg,
@ -5617,5 +5629,6 @@
get_buffer_size ); get_buffer_size );
return FT_Err_Ok; return FT_Err_Ok;
} }
#endif
/* END */ /* END */

View File

@ -347,6 +347,7 @@
if ( load_flags & FT_LOAD_SBITS_ONLY ) if ( load_flags & FT_LOAD_SBITS_ONLY )
return FT_THROW( Invalid_Argument ); return FT_THROW( Invalid_Argument );
#ifdef FT_CONFIG_OPTION_SVG
/* check for OT-SVG */ /* check for OT-SVG */
if ( ( load_flags & FT_LOAD_COLOR ) && if ( ( load_flags & FT_LOAD_COLOR ) &&
( ((TT_Face)glyph->root.face)->svg ) ) ( ((TT_Face)glyph->root.face)->svg ) )
@ -359,6 +360,7 @@
return error; return error;
} }
} }
#endif
/* if we have a CID subfont, use its matrix (which has already */ /* if we have a CID subfont, use its matrix (which has already */
/* been multiplied with the root matrix) */ /* been multiplied with the root matrix) */

View File

@ -37,7 +37,9 @@
#include "ttcpal.h" #include "ttcpal.h"
#endif #endif
#ifdef FT_CONFIG_OPTION_SVG
#include "ttsvg.h" /* OpenType SVG support */ #include "ttsvg.h" /* OpenType SVG support */
#endif
#ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES
#include "ttpost.h" #include "ttpost.h"
@ -1210,6 +1212,12 @@
#define PUT_EMBEDDED_BITMAPS( a ) NULL #define PUT_EMBEDDED_BITMAPS( a ) NULL
#endif #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 #ifdef TT_CONFIG_OPTION_COLOR_LAYERS
#define PUT_COLOR_LAYERS( a ) a #define PUT_COLOR_LAYERS( a ) a
#else #else
@ -1297,9 +1305,12 @@
tt_face_get_name, /* TT_Get_Name_Func get_name */ tt_face_get_name, /* TT_Get_Name_Func get_name */
sfnt_get_name_id, /* TT_Get_Name_ID_Func get_name_id */ sfnt_get_name_id, /* TT_Get_Name_ID_Func get_name_id */
tt_face_load_svg, /* TT_Load_Table_Func load_svg */ PUT_SVG_SUPPORT( tt_face_load_svg ),
tt_face_free_svg, /* TT_Free_Table_Func free_svg */ /* TT_Load_Table_Func load_svg */
tt_face_load_svg_doc /* TT_Load_Svg_Doc_Func load_svg_doc */ 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 */
) )

View File

@ -751,7 +751,6 @@
FT_Bool is_apple_sbix; FT_Bool is_apple_sbix;
FT_Bool has_CBLC; FT_Bool has_CBLC;
FT_Bool has_CBDT; FT_Bool has_CBDT;
FT_Bool has_SVG = FALSE; /* for OT-SVG */
FT_Bool ignore_typographic_family = FALSE; FT_Bool ignore_typographic_family = FALSE;
FT_Bool ignore_typographic_subfamily = FALSE; FT_Bool ignore_typographic_subfamily = FALSE;
@ -954,12 +953,13 @@
LOAD_( colr ); LOAD_( colr );
} }
#ifdef FT_CONFIG_OPTION_SVG
/* opentype svg colored glyph support */ /* opentype svg colored glyph support */
/* no If statement because the function always exists for now */ if ( sfnt->load_svg )
LOAD_( svg ); {
LOAD_( svg );
if( face->svg ) }
has_SVG = TRUE; #endif
/* consider the pclt, kerning, and gasp tables as optional */ /* consider the pclt, kerning, and gasp tables as optional */
LOAD_( pclt ); LOAD_( pclt );
@ -1380,9 +1380,11 @@
sfnt->free_cpal( face ); sfnt->free_cpal( face );
sfnt->free_colr( face ); sfnt->free_colr( face );
} }
#ifdef FT_CONFIG_OPTION_SVG
/* free svg data */ /* free svg data */
sfnt->free_svg( face ); if ( sfnt->free_svg )
sfnt->free_svg( face );
#endif
} }
#ifdef TT_CONFIG_OPTION_BDF #ifdef TT_CONFIG_OPTION_BDF

View File

@ -31,6 +31,7 @@
#include FT_GZIP_H #include FT_GZIP_H
#include FT_SVG_RENDER_H #include FT_SVG_RENDER_H
#ifdef FT_CONFIG_OPTION_SVG
#include "ttsvg.h" #include "ttsvg.h"
@ -187,8 +188,6 @@
FT_ULong uncomp_size; FT_ULong uncomp_size;
FT_Byte* uncomp_buffer; FT_Byte* uncomp_buffer;
FT_Bool is_gzip_encoded = FALSE;
FT_Error error = FT_Err_Ok; FT_Error error = FT_Err_Ok;
TT_Face face = (TT_Face)glyph->face; TT_Face face = (TT_Face)glyph->face;
FT_Memory memory = face->root.memory; FT_Memory memory = face->root.memory;
@ -212,8 +211,6 @@
if( ( doc_list[0] == 0x1F ) && ( doc_list[1] == 0x8B ) if( ( doc_list[0] == 0x1F ) && ( doc_list[1] == 0x8B )
&& ( doc_list[2] == 0x08 ) ) && ( doc_list[2] == 0x08 ) )
{ {
is_gzip_encoded = TRUE;
/* get the size of the orignal document. This helps in alotting the /* get the size of the orignal document. This helps in alotting the
* buffer to accomodate the uncompressed version. The last 4 bytes * buffer to accomodate the uncompressed version. The last 4 bytes
* of the compressed document are equal to orignal_size modulo 2^32. * of the compressed document are equal to orignal_size modulo 2^32.
@ -254,3 +251,10 @@
return FT_Err_Ok; 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 */

View File

@ -2781,7 +2781,7 @@
{ {
FT_Error error; FT_Error error;
TT_LoaderRec loader; TT_LoaderRec loader;
SFNT_Service sfnt;
FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index )); FT_TRACE1(( "TT_Load_Glyph: glyph index %d\n", glyph_index ));
@ -2892,9 +2892,11 @@
goto Exit; goto Exit;
} }
#ifdef FT_CONFIG_OPTION_SVG
/* check for OT-SVG */ /* check for OT-SVG */
if ( ( load_flags & FT_LOAD_COLOR ) && ( ((TT_Face)glyph->face)->svg ) ) if ( ( load_flags & FT_LOAD_COLOR ) && ( ((TT_Face)glyph->face)->svg ) )
{ {
SFNT_Service sfnt;
sfnt = (SFNT_Service)((TT_Face)glyph->face)->sfnt; sfnt = (SFNT_Service)((TT_Face)glyph->face)->sfnt;
error = sfnt->load_svg_doc( glyph, glyph_index ); error = sfnt->load_svg_doc( glyph, glyph_index );
if( error == FT_Err_Ok ) if( error == FT_Err_Ok )
@ -2903,6 +2905,7 @@
return error; return error;
} }
} }
#endif
if ( load_flags & FT_LOAD_SBITS_ONLY ) if ( load_flags & FT_LOAD_SBITS_ONLY )
{ {