freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] GSoC-2019-moazin 204329b 13/32: [ot-svg] Create an SVG Docum


From: Moazin Khatti
Subject: [freetype2] GSoC-2019-moazin 204329b 13/32: [ot-svg] Create an SVG Document structure for use in `other' field
Date: Thu, 11 Jul 2019 05:10:04 -0400 (EDT)

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

    [ot-svg] Create an SVG Document structure for use in `other' field
    of `FT_GlyphSlot'.
---
 include/freetype/svgrenderer.h | 32 ++++++++++++++++++++++++++++++++
 src/base/ftobjs.c              |  6 ++++++
 src/cff/cffgload.c             | 13 +++++++++++++
 src/sfnt/ttsvg.c               | 28 +++++++++++++++++-----------
 4 files changed, 68 insertions(+), 11 deletions(-)

diff --git a/include/freetype/svgrenderer.h b/include/freetype/svgrenderer.h
index 1ab23aa..57ea365 100644
--- a/include/freetype/svgrenderer.h
+++ b/include/freetype/svgrenderer.h
@@ -148,6 +148,38 @@ FT_BEGIN_HEADER
                     SVG_Lib_Free    free_hook,
                     SVG_Lib_Render  render_hook );
 
+  /**************************************************************************
+   *
+   * @struct:
+   *   FT_SVG_DocumentRec_
+   *
+   * @description:
+   *   A structure that models one SVG document.
+   *
+   * @fields:
+   *   svg_document ::
+   *     A pointer to the SVG document string.
+   *
+   *   svg_document_length ::
+   *     The length of the SVG document string.
+   */
+
+  typedef struct FT_SVG_DocumentRec_
+  {
+    FT_Byte*  svg_document;
+    FT_ULong  svg_document_length;
+  } FT_SVG_DocumentRec;
+
+  /**************************************************************************
+   *
+   * @type:
+   *   FT_SVG_Document
+   *
+   * @description:
+   *   A handle to a FT_SVG_DocumentRec object.
+   */
+  typedef struct FT_SVG_DocumentRec_*  FT_SVG_Document;
+
 FT_END_HEADER
 
 #endif
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index aa09628..569fc2f 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -838,6 +838,12 @@
     if ( load_flags & FT_LOAD_BITMAP_METRICS_ONLY )
       load_flags &= ~FT_LOAD_RENDER;
 
+    if ( ( load_flags & FT_LOAD_COLOR ) &&
+         ( ((TT_Face)face)->svg ) )
+    {
+      FT_Load_Glyph( face, glyph_index, FT_LOAD_DEFAULT );
+    }
+
     /*
      * Determine whether we need to auto-hint or not.
      * The general rules are:
diff --git a/src/cff/cffgload.c b/src/cff/cffgload.c
index 36aa7d1..9edcf12 100644
--- a/src/cff/cffgload.c
+++ b/src/cff/cffgload.c
@@ -347,6 +347,19 @@
     if ( load_flags & FT_LOAD_SBITS_ONLY )
       return FT_THROW( Invalid_Argument );
 
+    /* check for OT-SVG */
+    if ( ( load_flags & FT_LOAD_COLOR ) &&
+         ( ((TT_Face)glyph->root.face)->svg ) )
+    {
+      SFNT_Service  sfnt = (SFNT_Service)((TT_Face)glyph->root.face)->sfnt;
+      error = sfnt->load_svg_doc( (FT_GlyphSlot)glyph, glyph_index );
+      if( error == FT_Err_Ok )
+      {
+        glyph->root.format = FT_GLYPH_FORMAT_SVG;
+        return error;
+      }
+    }
+
     /* if we have a CID subfont, use its matrix (which has already */
     /* been multiplied with the root matrix)                       */
 
diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c
index fa2ce58..f13f2eb 100644
--- a/src/sfnt/ttsvg.c
+++ b/src/sfnt/ttsvg.c
@@ -28,6 +28,7 @@
 #include FT_INTERNAL_STREAM_H
 #include FT_TRUETYPE_TAGS_H
 #include FT_GZIP_H
+#include FT_SVG_RENDERER_H
 
 
 #include "ttsvg.h"
@@ -39,7 +40,7 @@
     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;      
+    FT_Byte*   svg_doc_list;
     /* Memory that backs up SVG */
     void*     table;
     FT_ULong  table_size;
@@ -68,7 +69,7 @@
 
     if( FT_FRAME_EXTRACT( table_size, table ))
       goto NoSVG;
-     
+
     /* Allocate the memory for the Svg object */
     if( FT_NEW( svg ) )
       goto NoSVG;
@@ -114,7 +115,7 @@
     {
       FT_FRAME_RELEASE( svg->table );
       FT_FREE( svg );
-    }   
+    }
   }
 
   FT_Error
@@ -159,12 +160,10 @@
   }
 
   FT_LOCAL_DEF(FT_Error)
-  tt_face_load_svg_doc( FT_GlyphSlot  glyph_,
+  tt_face_load_svg_doc( FT_GlyphSlot  glyph,
                         FT_UInt       glyph_index )
   {
 
-    TT_GlyphSlot glyph = (TT_GlyphSlot) glyph_;
-
     /* TODO: (OT-SVG) properly clean stuff here on errors */
 
     FT_Byte*   doc_list;             /* Pointer to the Svg Document List */
@@ -179,10 +178,12 @@
     FT_Bool    is_gzip_encoded = FALSE;
 
     FT_Error   error  = FT_Err_Ok;
-    TT_Face    face   = (TT_Face)glyph->root.face;
+    TT_Face    face   = (TT_Face)glyph->face;
     FT_Memory  memory = face->root.memory;
     Svg*       svg    = face->svg;
 
+    FT_SVG_Document  svg_document;
+
     /* handle svg being 0x0 situation here */
     doc_list     = svg->svg_doc_list;
     num_entries  = FT_NEXT_USHORT( doc_list );
@@ -221,12 +222,17 @@
         return error;
       }
 
-      glyph->svg_document        = uncomp_buffer;
-      glyph->svg_document_length = uncomp_size;
+      doc_list   = uncomp_buffer;
+      doc_length = uncomp_size;
       return FT_Err_Ok;
     }
 
-    glyph->svg_document        = doc_list;
-    glyph->svg_document_length = doc_length;
+    if ( FT_NEW( svg_document ) )
+      return FT_THROW( Out_Of_Memory );
+
+    svg_document->svg_document        = doc_list;
+    svg_document->svg_document_length = doc_length;
+
+    glyph->other = svg_document;
     return FT_Err_Ok;
   }



reply via email to

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