summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMoazin Khatti <moazinkhatri@gmail.com>2019-06-23 14:47:34 +0500
committerMoazin Khatti <moazinkhatri@gmail.com>2019-07-11 14:09:43 +0500
commit72eb3b3a9db1fe99dc6aa012adf4b134b4901973 (patch)
tree633801a5a4f246825aaecc34151556511be00fd6
parentaec7ec2a622b4b00fbac83cd9374211c1c8a6204 (diff)
downloadfreetype2-72eb3b3a9db1fe99dc6aa012adf4b134b4901973.tar.gz
Properly free memory of SVG document referenced in `slot->other'.
* include/freetype/freetype.h: Add `FT_FACE_FLAG_SVG' to indicate the presence of an SVG table in the face. * src/base/ftobjs.c (ft_glyphslot_init): Allocate memory for `FT_SVG_Document' in `slot->other' if an SVG table exists in the face. (ft_glyphslot_clear): Clear `slot->other' only if the font doesn't have an SVG table. (ft_glyphslot_done): Free the memory at `slot->other' if the face has an SVG table. * src/base/ttsvg.c (tt_face_load_svg): Set `FT_FACE_FLAG_SVG'. (tt_face_load_svg_doc): Don't allocate the memory.
-rw-r--r--include/freetype/freetype.h4
-rw-r--r--src/base/ftobjs.c18
-rw-r--r--src/sfnt/ttsvg.c7
3 files changed, 24 insertions, 5 deletions
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index a6bb667e3..8d28cb7f4 100644
--- a/include/freetype/freetype.h
+++ b/include/freetype/freetype.h
@@ -1206,6 +1206,9 @@ FT_BEGIN_HEADER
* altered with @FT_Set_MM_Design_Coordinates,
* @FT_Set_Var_Design_Coordinates, or @FT_Set_Var_Blend_Coordinates.
* This flag is unset by a call to @FT_Set_Named_Instance.
+ *
+ * FT_FACE_FLAG_SVG ::
+ * Set if the current face has an SVG table.
*/
#define FT_FACE_FLAG_SCALABLE ( 1L << 0 )
#define FT_FACE_FLAG_FIXED_SIZES ( 1L << 1 )
@@ -1223,6 +1226,7 @@ FT_BEGIN_HEADER
#define FT_FACE_FLAG_TRICKY ( 1L << 13 )
#define FT_FACE_FLAG_COLOR ( 1L << 14 )
#define FT_FACE_FLAG_VARIATION ( 1L << 15 )
+#define FT_FACE_FLAG_SVG ( 1L << 16 )
/**************************************************************************
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index cc0badd30..49b63bd18 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -318,6 +318,15 @@
if ( !error && clazz->init_slot )
error = clazz->init_slot( slot );
+ /* check if SVG table exists allocate the space in slot->other */
+ if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
+ {
+ FT_SVG_Document document;
+ if ( FT_NEW( document ) )
+ goto Exit;
+ slot->other = document;
+ }
+
Exit:
return error;
}
@@ -552,7 +561,8 @@
slot->subglyphs = NULL;
slot->control_data = NULL;
slot->control_len = 0;
- slot->other = NULL;
+ if ( !( slot->face->face_flags & FT_FACE_FLAG_SVG ) )
+ slot->other = NULL;
slot->format = FT_GLYPH_FORMAT_NONE;
slot->linearHoriAdvance = 0;
@@ -570,6 +580,11 @@
FT_Memory memory = driver->root.memory;
+ if ( slot->face->face_flags & FT_FACE_FLAG_SVG )
+ {
+ FT_FREE( slot->other );
+ }
+
if ( clazz->done_slot )
clazz->done_slot( slot );
@@ -588,6 +603,7 @@
FT_FREE( slot->internal );
}
+
}
diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c
index 4901b2206..85aa27e3a 100644
--- a/src/sfnt/ttsvg.c
+++ b/src/sfnt/ttsvg.c
@@ -91,6 +91,8 @@
face->svg = svg;
+ face->root.face_flags |= FT_FACE_FLAG_SVG;
+
return FT_Err_Ok;
InvalidTable:
@@ -182,7 +184,7 @@
FT_Memory memory = face->root.memory;
Svg* svg = face->svg;
- FT_SVG_Document svg_document;
+ FT_SVG_Document svg_document = glyph->other;
/* handle svg being 0x0 situation here */
doc_list = svg->svg_doc_list;
@@ -227,9 +229,6 @@
return FT_Err_Ok;
}
- if ( FT_NEW( svg_document ) )
- return FT_THROW( Out_Of_Memory );
-
svg_document->svg_document = doc_list;
svg_document->svg_document_length = doc_length;
svg_document->metrics = glyph->face->size->metrics;