freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[freetype2] GSoC-2019-moazin 93cb43f 03/47: Created Svg type and the loa


From: Moazin Khatti
Subject: [freetype2] GSoC-2019-moazin 93cb43f 03/47: Created Svg type and the load/free funcs inside sfnt interface
Date: Fri, 26 Jul 2019 10:01:56 -0400 (EDT)

branch: GSoC-2019-moazin
commit 93cb43f9a21280c67b7fbb896e0d846fe8e08754
Author: Moazin Khatti <address@hidden>
Commit: Moazin Khatti <address@hidden>

    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/{sfnt.c => ttsvg.h}        |  31 +++++-----
 7 files changed, 157 insertions(+), 20 deletions(-)

diff --git a/include/freetype/internal/sfnt.h b/include/freetype/internal/sfnt.h
index b19241c..94f5122 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 23db240..42a921f 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 2611685..11148b2 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 b4faf34..16ba899 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 6edf3ae..6cd62b2 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 0000000..0ebe162
--- /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 <ft2build.h>
+#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/sfnt.c b/src/sfnt/ttsvg.h
similarity index 56%
copy from src/sfnt/sfnt.c
copy to src/sfnt/ttsvg.h
index b4faf34..1c6413b 100644
--- a/src/sfnt/sfnt.c
+++ b/src/sfnt/ttsvg.h
@@ -1,10 +1,10 @@
 /****************************************************************************
  *
- * sfnt.c
+ * ttsvg.h
  *
- *   Single object library component.
+ *   OpenType SVG Color (specification).
  *
- * Copyright (C) 1996-2019 by
+ * 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,
@@ -15,24 +15,21 @@
  *
  */
 
+#ifndef __TTSVG_H__
+#define __TTSVG_H__
 
-#define FT_MAKE_OPTION_SINGLE_OBJECT
 #include <ft2build.h>
 
-#include "pngshim.c"
-#include "sfdriver.c"
-#include "sfobjs.c"
-#include "sfwoff.c"
-#include "ttbdf.c"
-#include "ttcmap.c"
-#include "ttcolr.c"
-#include "ttcpal.c"
+FT_BEGIN_HEADER
 
-#include "ttkern.c"
-#include "ttload.c"
-#include "ttmtx.c"
-#include "ttpost.c"
-#include "ttsbit.c"
+  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 */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]