[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2] GSoC-2019-moazin 438ece4 2/6: Properly free memory of SVG do
From: |
Moazin Khatti |
Subject: |
[freetype2] GSoC-2019-moazin 438ece4 2/6: Properly free memory of SVG document referenced in `slot->other'. |
Date: |
Sun, 23 Jun 2019 15:37:44 -0400 (EDT) |
branch: GSoC-2019-moazin
commit 438ece4e79692469c4458927af6df0508ed7c9c4
Author: Moazin Khatti <address@hidden>
Commit: Moazin Khatti <address@hidden>
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.
---
include/freetype/freetype.h | 4 ++++
src/base/ftobjs.c | 18 +++++++++++++++++-
src/sfnt/ttsvg.c | 7 +++----
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/include/freetype/freetype.h b/include/freetype/freetype.h
index 2f7863c..7328db0 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 cc0badd..49b63bd 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 4901b22..85aa27e 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;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2] GSoC-2019-moazin 438ece4 2/6: Properly free memory of SVG document referenced in `slot->other'.,
Moazin Khatti <=