freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] GSoC-2019-moazin 395de16 1/2: Created `Svg_doc' private stru


From: Moazin Khatti
Subject: [freetype2] GSoC-2019-moazin 395de16 1/2: Created `Svg_doc' private struct.
Date: Thu, 25 Jul 2019 07:25:00 -0400 (EDT)

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

    Created `Svg_doc' private struct.
    
    Inside the SVG Document List, four fields exist. It's
    better to create a struct to hold at one place instead
    of 4 variables. Also created `compare_svg_doc' which
    will be helpful in writing binary search later.
---
 src/sfnt/ttsvg.c | 56 ++++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 40 insertions(+), 16 deletions(-)

diff --git a/src/sfnt/ttsvg.c b/src/sfnt/ttsvg.c
index 925b0b1..eea3d25 100644
--- a/src/sfnt/ttsvg.c
+++ b/src/sfnt/ttsvg.c
@@ -123,6 +123,37 @@
     }
   }
 
+  typedef struct Svg_doc_
+  {
+    FT_UShort  start_glyph_id;
+    FT_UShort  end_glyph_id;
+    FT_ULong   cur_doc_offset;
+    FT_ULong   cur_doc_length;
+  } Svg_doc;
+
+  Svg_doc
+  extract_svg_doc( FT_Byte*  stream )
+  {
+    Svg_doc  doc;
+    doc.start_glyph_id = FT_NEXT_USHORT( stream );
+    doc.end_glyph_id   = FT_NEXT_USHORT( stream );
+    doc.cur_doc_offset = FT_NEXT_ULONG( stream );
+    doc.cur_doc_length = FT_NEXT_ULONG( stream );
+    return doc;
+  }
+
+  FT_Int
+  compare_svg_doc( Svg_doc  doc,
+                   FT_UInt  glyph_index )
+  {
+    if ( glyph_index < doc.start_glyph_id )
+      return -1;
+    else if ( glyph_index > doc.end_glyph_id )
+      return 1;
+    else
+      return 0;
+  }
+
   FT_Error
   find_doc( FT_Byte*   stream,
             FT_UShort  num_entries,
@@ -133,38 +164,31 @@
             FT_UShort  *end_glyph )
   {
     FT_Error   error;
-    FT_UShort  start_glyph_id;
-    FT_UShort  end_glyph_id;
-    FT_ULong   cur_doc_offset;
-    FT_ULong   cur_doc_length;
+    Svg_doc    cur_doc;
 
     FT_Bool    found = FALSE;
     FT_UInt    i     = 0;
 
     /* TODO: (OT-SVG) Convert to efficient search algorithm        */
-    /* TODO: (OT-SVG) Use Frame Fields here instead of `FT_NEXT_*' */
     for ( i = 0; i < num_entries; i++)
     {
-      start_glyph_id = FT_NEXT_USHORT( stream );
-      end_glyph_id   = FT_NEXT_USHORT( stream );
-      cur_doc_offset = FT_NEXT_ULONG( stream );
-      cur_doc_length = FT_NEXT_ULONG( stream );
-
-      if ( ( glyph_index >= start_glyph_id) &&
-           ( glyph_index <= end_glyph_id  ) )
+      cur_doc = extract_svg_doc( stream );
+      stream += 12;
+      if ( compare_svg_doc( cur_doc, glyph_index ) == 0 )
       {
         found = TRUE;
-        *doc_offset = cur_doc_offset;
-        *doc_length = cur_doc_length;
+        *doc_offset = cur_doc.cur_doc_offset;
+        *doc_length = cur_doc.cur_doc_length;
         break;
       }
     }
+
     if ( found != TRUE )
       error = FT_THROW( Invalid_Glyph_Index );
     else
     {
-      *start_glyph = start_glyph_id;
-      *end_glyph   = end_glyph_id;
+      *start_glyph = cur_doc.start_glyph_id;
+      *end_glyph   = cur_doc.end_glyph_id;
       error = FT_Err_Ok;
     }
     return error;



reply via email to

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