From 9b7c3d1df9715757f987a8641a95c07fac7d389e Mon Sep 17 00:00:00 2001 From: Moazin Khatti Date: Fri, 7 Jun 2019 19:27:32 +0500 Subject: [PATCH] Created Svg type and the load/free funcs inside sfnt interface --- include/freetype/internal/sfnt.h | 11 ++- include/freetype/internal/tttypes.h | 2 + src/sfnt/sfdriver.c | 6 +- src/sfnt/sfnt.c | 1 + src/sfnt/sfobjs.c | 11 +++ src/sfnt/ttsvg.c | 115 ++++++++++++++++++++++++++++ src/sfnt/ttsvg.h | 35 +++++++++ 7 files changed, 178 insertions(+), 3 deletions(-) create mode 100644 src/sfnt/ttsvg.c create mode 100644 src/sfnt/ttsvg.h diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h index b19241c30..94f512270 100644 --- a/include/freetype/internal/sfnt.h +++ b/include/freetype/internal/sfnt.h @@ -778,6 +778,9 @@ FT_BEGIN_HEADER TT_Get_Name_Func get_name; TT_Get_Name_ID_Func get_name_id; + /* Open Type SVG Support */ + TT_Load_Table_Func load_svg; + TT_Free_Table_Func free_svg; } SFNT_Interface; @@ -824,7 +827,9 @@ FT_BEGIN_HEADER colr_blend_, \ get_metrics_, \ get_name_, \ - get_name_id_ ) \ + get_name_id_, \ + load_svg_, \ + free_svg_ ) \ static const SFNT_Interface class_ = \ { \ goto_table_, \ @@ -864,7 +869,9 @@ FT_BEGIN_HEADER colr_blend_, \ get_metrics_, \ get_name_, \ - get_name_id_ \ + get_name_id_, \ + load_svg_, \ + free_svg_ \ }; diff --git a/include/freetype/internal/tttypes.h b/include/freetype/internal/tttypes.h index 23db240e7..42a921fe7 100644 --- a/include/freetype/internal/tttypes.h +++ b/include/freetype/internal/tttypes.h @@ -1645,6 +1645,8 @@ FT_BEGIN_HEADER void* cpal; void* colr; + /* OpenType SVG Glyph Support */ + void* svg; } TT_FaceRec; diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c index 261168528..11148b2cf 100644 --- a/src/sfnt/sfdriver.c +++ b/src/sfnt/sfdriver.c @@ -37,6 +37,8 @@ #include "ttcpal.h" #endif +#include "ttsvg.h" /* OpenType SVG support */ + #ifdef TT_CONFIG_OPTION_POSTSCRIPT_NAMES #include "ttpost.h" #endif @@ -1294,7 +1296,9 @@ tt_face_get_metrics, /* TT_Get_Metrics_Func get_metrics */ 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 */ + tt_face_free_svg /* TT_Free_Table_Func free_svg */ ) diff --git a/src/sfnt/sfnt.c b/src/sfnt/sfnt.c index b4faf34a3..16ba899a7 100644 --- a/src/sfnt/sfnt.c +++ b/src/sfnt/sfnt.c @@ -27,6 +27,7 @@ #include "ttcmap.c" #include "ttcolr.c" #include "ttcpal.c" +#include "ttsvg.c" #include "ttkern.c" #include "ttload.c" diff --git a/src/sfnt/sfobjs.c b/src/sfnt/sfobjs.c index 6edf3ae1d..6cd62b24a 100644 --- a/src/sfnt/sfobjs.c +++ b/src/sfnt/sfobjs.c @@ -751,6 +751,7 @@ FT_Bool is_apple_sbix; FT_Bool has_CBLC; FT_Bool has_CBDT; + FT_Bool has_SVG = FALSE; /* For OpenType SVG fonts */ FT_Bool ignore_typographic_family = FALSE; FT_Bool ignore_typographic_subfamily = FALSE; @@ -953,6 +954,13 @@ 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; + /* consider the pclt, kerning, and gasp tables as optional */ LOAD_( pclt ); LOAD_( gasp ); @@ -1372,6 +1380,9 @@ sfnt->free_cpal( face ); sfnt->free_colr( face ); } + + /* free svg data */ + sfnt->free_svg( face ); } #ifdef TT_CONFIG_OPTION_BDF diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c new file mode 100644 index 000000000..0ebe162e7 --- /dev/null +++ b/src/sfnt/ttsvg.c @@ -0,0 +1,115 @@ +/**************************************************************************** + * + * ttsvg.h + * + * OpenType SVG Color (specification). + * + * Copyright (C) 2018-2019 by + * David Turner, Robert Wilhelm, and Werner Lemberg. + * + * This file is part of the FreeType project, and may only be used, + * modified, and distributed under the terms of the FreeType project + * license, LICENSE.TXT. By continuing to use, modify, or distribute + * this file you indicate that you have read the license and + * understand and accept it fully. + * + */ + + + /************************************************************************** + * + * `SVG' table specification: + * + * https://docs.microsoft.com/en-us/typography/opentype/spec/svg + * + */ + +#include +#include FT_INTERNAL_STREAM_H +#include FT_TRUETYPE_TAGS_H + + +#include "ttsvg.h" + + typedef struct Svg_ + { + FT_UShort version; /* Table version (starting at 0) */ + FT_UShort num_entries; /* Number of SVG document records */ + /* Pointer to the starting of SVG Document List */ + FT_Byte* svg_doc_list; + /* Memory that backs up SVG */ + void* table; + FT_ULong table_size; + } Svg; + + + FT_LOCAL_DEF( FT_Error ) + tt_face_load_svg( TT_Face face, + FT_Stream stream ) + { + FT_Error error; + FT_Memory memory = face->root.memory; + + FT_ULong table_size; + FT_Byte* table = NULL; + FT_Byte* p = NULL; + + Svg* svg = NULL; + + FT_ULong offsetToSVGDocumentList; + + + error = face->goto_table( face, TTAG_SVG, stream, &table_size ); + if( error ) + goto NoSVG; + + if( FT_FRAME_EXTRACT( table_size, table )) + goto NoSVG; + + /* Allocate the memory for the Svg object */ + if( FT_NEW( svg ) ) + goto NoSVG; + + p = table; + svg->version = FT_NEXT_USHORT( p ); + offsetToSVGDocumentList = FT_NEXT_ULONG( p ); + + if( offsetToSVGDocumentList == 0 ) + goto InvalidTable; + + svg->svg_doc_list = (FT_Byte*)( table + offsetToSVGDocumentList ); + + p = svg->svg_doc_list; + svg->num_entries = FT_NEXT_USHORT( p ); + + svg->table = table; + svg->table_size = table_size; + + face->svg = svg; + + return FT_Err_Ok; + + InvalidTable: + error = FT_THROW( Invalid_Table ); + + NoSVG: + FT_FRAME_RELEASE( table ); + FT_FREE( svg ); + face->svg = NULL; + + return error; + } + + FT_LOCAL_DEF( void ) + tt_face_free_svg( TT_Face face ) + { + FT_Memory memory = face->root.memory; + FT_Stream stream = face->root.stream; + + Svg* svg = (Svg*) face->svg; + if( svg ) + { + FT_FRAME_RELEASE( svg->table ); + FT_FREE( svg ); + } + } diff --git a/src/sfnt/ttsvg.h b/src/sfnt/ttsvg.h new file mode 100644 index 000000000..1c6413be5 --- /dev/null +++ b/src/sfnt/ttsvg.h @@ -0,0 +1,35 @@ +/**************************************************************************** + * + * ttsvg.h + * + * OpenType SVG Color (specification). + * + * Copyright (C) 2018-2019 by + * David Turner, Robert Wilhelm, and Werner Lemberg. + * + * This file is part of the FreeType project, and may only be used, + * modified, and distributed under the terms of the FreeType project + * license, LICENSE.TXT. By continuing to use, modify, or distribute + * this file you indicate that you have read the license and + * understand and accept it fully. + * + */ + +#ifndef __TTSVG_H__ +#define __TTSVG_H__ + +#include + +FT_BEGIN_HEADER + + FT_LOCAL( FT_Error ) + tt_face_load_svg( TT_Face face, + FT_Stream stream ); + + FT_LOCAL( void ) + tt_face_free_svg( TT_Face face ); + +FT_END_HEADER + +#endif /* __TTSVG_H__ */ +/* END */