freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] GSoC-2018-parth 9f4eef0 2/2: [pk] Change `cmap' encoding sch


From: Parth Wazurkar
Subject: [freetype2] GSoC-2018-parth 9f4eef0 2/2: [pk] Change `cmap' encoding scheme.
Date: Sun, 12 Aug 2018 13:49:40 -0400 (EDT)

branch: GSoC-2018-parth
commit 9f4eef0a67a4ea9fd4a6188ec522e35d37c2ad36
Author: Parth Wazurkar <address@hidden>
Commit: Parth Wazurkar <address@hidden>

    [pk] Change `cmap' encoding scheme.
    
    * src/pk/pkdrivr.c(PK_Face_Init):
      - Change `pk_cmap_class' functions to use new encoding
        scheme.
      - Set charmap to `0: synthetic, platform 0, encoding  0
        language 0' values.
---
 src/gf/gfdrivr.h |   3 +-
 src/pk/pkdrivr.c | 137 +++++++++++++++++++++++++++++++++++++++++--------------
 src/pk/pkdrivr.h |  14 ++++++
 src/pk/pklib.c   |  22 +++++++--
 4 files changed, 135 insertions(+), 41 deletions(-)

diff --git a/src/gf/gfdrivr.h b/src/gf/gfdrivr.h
index 5df04e9..122940d 100644
--- a/src/gf/gfdrivr.h
+++ b/src/gf/gfdrivr.h
@@ -31,7 +31,7 @@ FT_BEGIN_HEADER
   typedef struct  GF_EncodingRec_
   {
     FT_Long   enc;
-    FT_UShort  glyph;
+    FT_UShort glyph;
 
   } GF_EncodingRec, *GF_Encoding;
 
@@ -44,7 +44,6 @@ FT_BEGIN_HEADER
     FT_Byte         *bitmap;
     FT_UInt         raster;
     FT_UShort       code;
-    FT_ULong        nglyphs;
 
   } GF_BitmapRec, *GF_Bitmap;
 
diff --git a/src/pk/pkdrivr.c b/src/pk/pkdrivr.c
index 4baf616..bbb4b93 100644
--- a/src/pk/pkdrivr.c
+++ b/src/pk/pkdrivr.c
@@ -43,9 +43,9 @@
 
   typedef struct  PK_CMapRec_
   {
-    FT_CMapRec        cmap;
-    FT_UInt32         bc;       /* Beginning Character */
-    FT_UInt32         ec;       /* End Character */
+    FT_CMapRec      cmap;
+    FT_ULong        num_encodings;
+    PK_Encoding     encodings;
   } PK_CMapRec, *PK_CMap;
 
 
@@ -57,8 +57,8 @@
     PK_Face  face = (PK_Face)FT_CMAP_FACE( cmap );
     FT_UNUSED( init_data );
 
-    cmap->bc     = face->pk_glyph->code_min;
-    cmap->ec     = face->pk_glyph->code_max;
+    cmap->num_encodings = face->pk_glyph->nencodings;
+    cmap->encodings     = face->pk_glyph->encodings;
 
     return FT_Err_Ok;
   }
@@ -69,54 +69,98 @@
   {
     PK_CMap  cmap = (PK_CMap)pkcmap;
 
-    cmap->bc     =  0;
-    cmap->ec     = -1;
+    cmap->encodings     = NULL;
+    cmap->num_encodings = 0;
   }
 
 
   FT_CALLBACK_DEF( FT_UInt )
   pk_cmap_char_index(  FT_CMap    pkcmap,
-                       FT_UInt32  char_code )
+                       FT_UInt32  charcode )
   {
-    FT_UInt  gindex = 0;
-    PK_CMap  cmap   = (PK_CMap)pkcmap;
+    PK_CMap       cmap      = (PK_CMap)pkcmap;
+    PK_Encoding   encodings = cmap->encodings;
+    FT_ULong      min, max, mid;
+    FT_UInt       result    = 0;
 
-    char_code -= cmap->bc;
+    min = 0;
+    max = cmap->num_encodings;
 
-    if ( char_code < cmap->ec - cmap->bc + 1 )
-      gindex = (FT_UInt)( char_code );
+    while ( min < max )
+    {
+      FT_ULong  code;
+
+
+      mid  = ( min + max ) >> 1;
+      code = (FT_ULong)encodings[mid].enc;
 
-    return gindex;
+      if ( charcode == code )
+      {
+        result = encodings[mid].glyph;
+        break;
+      }
+
+      if ( charcode < code )
+        max = mid;
+      else
+        min = mid + 1;
+    }
+
+    return result;
   }
 
 
   FT_CALLBACK_DEF( FT_UInt )
   pk_cmap_char_next(  FT_CMap    pkcmap,
-                       FT_UInt32  *achar_code )
+                       FT_UInt32  *acharcode )
   {
-    PK_CMap    cmap   = (PK_CMap)pkcmap;
-    FT_UInt    gindex = 0;
-    FT_UInt32  result = 0;
-    FT_UInt32  char_code = *achar_code + 1;
+    PK_CMap       cmap      = (PK_CMap)pkcmap;
+    PK_Encoding   encodings = cmap->encodings;
+    FT_ULong      min, max, mid;
+    FT_ULong      charcode  = *acharcode + 1;
+    FT_UInt       result    = 0;
 
 
-    if ( char_code <= cmap->bc )
-    {
-      result = cmap->bc;
-      gindex = 1;
-    }
-    else
+    min = 0;
+    max = cmap->num_encodings;
+
+    while ( min < max )
     {
-      char_code -= cmap->bc;
-      if ( char_code < cmap->ec - cmap->bc + 1 )
+      FT_ULong  code;
+
+
+      mid  = ( min + max ) >> 1;
+      code = (FT_ULong)encodings[mid].enc;
+
+      if ( charcode == code )
       {
-        result = char_code;
-        gindex = (FT_UInt)( char_code );
+        result = encodings[mid].glyph + 1;
+        goto Exit;
       }
+
+      if ( charcode < code )
+        max = mid;
+      else
+        min = mid + 1;
     }
 
-    *achar_code = result;
-    return gindex;
+    charcode = 0;
+    if ( min < cmap->num_encodings )
+    {
+      charcode = (FT_ULong)encodings[min].enc;
+      result   = encodings[min].glyph ;
+    }
+
+  Exit:
+    if ( charcode > 0xFFFFFFFFUL )
+    {
+      FT_TRACE1(( "gf_cmap_char_next: charcode 0x%x > 32bit API" ));
+      *acharcode = 0;
+      /* XXX: result should be changed to indicate an overflow error */
+    }
+    else
+      *acharcode = (FT_UInt32)charcode;
+    return result;
   }
 
 
@@ -268,15 +312,38 @@
                                          y_res );
     }
 
+    /* set up charmap */
+    {
+      /* FT_Bool     unicode_charmap ; */
+
+      /*
+       * XXX: TO-DO
+       * Currently the unicode_charmap is set to `0'
+       * The functionality of extracting coding scheme
+       * from `xxx' and `yyy' commands will be used to
+       * set the unicode_charmap.
+      */
+    }
+
     /* Charmaps */
     {
       FT_CharMapRec  charmap;
+      FT_Bool        unicode_charmap = 0;
 
-      /* Unicode Charmap */
-      charmap.encoding    = FT_ENCODING_UNICODE;
-      charmap.platform_id = TT_PLATFORM_MICROSOFT;
-      charmap.encoding_id = TT_MS_ID_UNICODE_CS;
       charmap.face        = FT_FACE( face );
+      charmap.encoding    = FT_ENCODING_NONE;
+      /* initial platform/encoding should indicate unset status? */
+      charmap.platform_id = TT_PLATFORM_APPLE_UNICODE;
+      charmap.encoding_id = TT_APPLE_ID_DEFAULT;
+
+      if( unicode_charmap )
+      {
+        /* Unicode Charmap */
+        charmap.encoding    = FT_ENCODING_UNICODE;
+        charmap.platform_id = TT_PLATFORM_MICROSOFT;
+        charmap.encoding_id = TT_MS_ID_UNICODE_CS;
+      }
+
 
       error = FT_CMap_New( &pk_cmap_class, NULL, &charmap, NULL );
 
diff --git a/src/pk/pkdrivr.h b/src/pk/pkdrivr.h
index 7c8fb38..da2b01c 100644
--- a/src/pk/pkdrivr.h
+++ b/src/pk/pkdrivr.h
@@ -27,6 +27,14 @@
 
 FT_BEGIN_HEADER
 
+
+  typedef struct  PK_EncodingRec_
+  {
+    FT_Long   enc;
+    FT_UShort glyph;
+
+  } PK_EncodingRec, *PK_Encoding;
+
   typedef struct PK_BitmapRec_
   {
     FT_Int          bbx_width, bbx_height;
@@ -34,6 +42,7 @@ FT_BEGIN_HEADER
     FT_Int          mv_x,  mv_y;
     FT_Byte         *bitmap;
     FT_UInt         raster;
+    FT_UShort       code;
 
   } PK_BitmapRec, *PK_Bitmap;
 
@@ -45,6 +54,11 @@ FT_BEGIN_HEADER
     FT_UInt         font_bbx_w, font_bbx_h;
     FT_UInt         font_bbx_xoff, font_bbx_yoff;
 
+    FT_ULong        nencodings;
+    PK_Encoding     encodings;
+
+    FT_ULong        nglyphs;
+
   } PK_GlyphRec, *PK_Glyph;
 
   typedef struct  PK_FaceRec_
diff --git a/src/pk/pklib.c b/src/pk/pklib.c
index 05494b0..dd5a23b 100644
--- a/src/pk/pklib.c
+++ b/src/pk/pklib.c
@@ -307,6 +307,7 @@ FT_Byte  bits_table[] = {
     FT_Int     bc, ec, nchars, index, i;
     FT_Error   error  = FT_Err_Ok;
     FT_Memory  memory = extmemory; /* needed for FT_NEW */
+    PK_Encoding   encoding = NULL;
 
     go = NULL;
     nchars = -1;
@@ -388,15 +389,15 @@ FT_Byte  bits_table[] = {
       ec = 255;
     #endif
 
-    nchars = ec - bc + 1;
+    nchars    = ec - bc + 1;
     if( FT_ALLOC(go, sizeof(PK_GlyphRec)) )
       goto Exit;
 
     if( FT_ALLOC_MULT(go->bm_table, sizeof(PK_BitmapRec), nchars) )
       goto Exit;
 
-    for (i = 0; i < nchars; i++)
-      go->bm_table[i].bitmap = NULL;
+    if ( FT_NEW_ARRAY( encoding, nchars ) )
+      return error;
 
     go->ds   = (FT_UInt)ds/(1<<20);
     go->hppp = (FT_UInt)hppp/(1<<16);
@@ -412,6 +413,8 @@ FT_Byte  bits_table[] = {
     if( FT_STREAM_SEEK( gptr ) )
         goto Exit;
 
+    index = 0;
+    go->nglyphs = 0;
     for (;;)
     {
       if ((instr = READ_UINT1( stream )) == PK_POST)
@@ -497,7 +500,6 @@ FT_Byte  bits_table[] = {
           goto Exit;
         }
 
-        index = cc - go->code_min;
         go->bm_table[index].bbx_width  = w;
         go->bm_table[index].bbx_height = h;
         go->bm_table[index].raster = (w+7)/8;
@@ -506,6 +508,12 @@ FT_Byte  bits_table[] = {
         go->bm_table[index].mv_x   = mv_x;
         go->bm_table[index].mv_y   = mv_y;
         go->bm_table[index].bitmap = (unsigned char*)malloc(h*((w+7)/8));
+        go->bm_table[index].code   = cc ; /* For backward compatibility */
+        go->nglyphs               += 1;
+
+        encoding[index].enc   = cc ;
+        encoding[index].glyph = index;
+
 
         if (go->bm_table[index].bitmap == NULL)
         {
@@ -541,8 +549,14 @@ FT_Byte  bits_table[] = {
           go->font_bbx_xoff = -hoff;
         if (go->font_bbx_yoff > (voff - h))
           go->font_bbx_yoff = (voff - h);
+
+        index++;
       }
     }
+
+    go->nencodings = go->nglyphs;
+    go->encodings  = encoding;
+
     *goptr          = go;
     return error;
 



reply via email to

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