freetype-commit
[Top][All Lists]
Advanced

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

[freetype2] master 588e38e 2/8: [truetype] Make `TT_Set_MM_Blend' set na


From: Werner LEMBERG
Subject: [freetype2] master 588e38e 2/8: [truetype] Make `TT_Set_MM_Blend' set named instance index.
Date: Mon, 6 Mar 2017 14:47:01 -0500 (EST)

branch: master
commit 588e38e0707a427b940d61de0d6dbfbae88629e9
Author: Werner Lemberg <address@hidden>
Commit: Werner Lemberg <address@hidden>

    [truetype] Make `TT_Set_MM_Blend' set named instance index.
    
    * src/truetype/ttgxvar.h (GX_Blend): New array
    `normalized_stylecoords'.
    
    * src/truetype/ttgxvar.c (TT_Get_MM_Var): Allocate and fill
    `normalized_stylecoords'.
    (TT_Set_MM_Blend): Check instance tuple and adjust `face_index'
    accordingly.
---
 ChangeLog              | 12 ++++++++++++
 src/truetype/ttgxvar.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++---
 src/truetype/ttgxvar.h |  3 +++
 3 files changed, 62 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d1003b3..af5b343 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2017-03-04  Werner Lemberg  <address@hidden>
+
+       [truetype] Make `TT_Set_MM_Blend' set named instance index.
+
+       * src/truetype/ttgxvar.h (GX_Blend): New array
+       `normalized_stylecoords'.
+
+       * src/truetype/ttgxvar.c (TT_Get_MM_Var): Allocate and fill
+       `normalized_stylecoords'.
+       (TT_Set_MM_Blend): Check instance tuple and adjust `face_index'
+       accordingly.
+
 2017-03-02  Werner Lemberg  <address@hidden>
 
        [truetype] Split off designer/normalized conversion routines.
diff --git a/src/truetype/ttgxvar.c b/src/truetype/ttgxvar.c
index 22297df..50da2ea 100644
--- a/src/truetype/ttgxvar.c
+++ b/src/truetype/ttgxvar.c
@@ -1933,6 +1933,7 @@
     FT_Int               i, j;
     FT_MM_Var*           mmvar = NULL;
     FT_Fixed*            next_coords;
+    FT_Fixed*            nsc;
     FT_String*           next_name;
     FT_Var_Axis*         a;
     FT_Var_Named_Style*  ns;
@@ -2018,7 +2019,7 @@
       if ( FT_NEW( face->blend ) )
         goto Exit;
 
-      /* cannot overflow 32-bit arithmetic because of limits above */
+      /* cannot overflow 32-bit arithmetic because of the validity check */
       face->blend->mmvar_len =
         sizeof ( FT_MM_Var ) +
         fvar_head.axisCount * sizeof ( FT_Var_Axis ) +
@@ -2108,7 +2109,20 @@
 
       FT_TRACE5(( "\n" ));
 
-      ns = mmvar->namedstyle;
+      if ( fvar_head.instanceCount )
+      {
+        /* named instance coordinates are stored as design coordinates; */
+        /* we have to convert them to normalized coordinates also       */
+        if ( FT_NEW_ARRAY( face->blend->normalized_stylecoords,
+                           fvar_head.axisCount * fvar_head.instanceCount ) )
+          goto Exit;
+
+        if ( !face->blend->avar_checked )
+          ft_var_load_avar( face );
+      }
+
+      ns  = mmvar->namedstyle;
+      nsc = face->blend->normalized_stylecoords;
       for ( i = 0; i < fvar_head.instanceCount; i++, ns++ )
       {
         /* PostScript names add 2 bytes to the instance record size */
@@ -2125,6 +2139,12 @@
         if ( usePsName )
           ns->psid = FT_GET_USHORT();
 
+        ft_var_to_normalized( face,
+                              fvar_head.axisCount,
+                              ns->coords,
+                              nsc );
+        nsc += fvar_head.axisCount;
+
         FT_FRAME_EXIT();
       }
 
@@ -2216,7 +2236,7 @@
     FT_Error    error = FT_Err_Ok;
     GX_Blend    blend;
     FT_MM_Var*  mmvar;
-    FT_UInt     i;
+    FT_UInt     i, j;
     FT_Bool     is_default_instance = 1;
     FT_Memory   memory = face->root.memory;
 
@@ -2342,6 +2362,30 @@
       }
     }
 
+    /* check whether the current variation tuple coincides */
+    /* with a named instance                               */
+
+    for ( i = 0; i < blend->mmvar->num_namedstyles; i++ )
+    {
+      FT_Fixed*  nsc = blend->normalized_stylecoords + i * blend->num_axis;
+      FT_Fixed*  ns  = blend->normalizedcoords;
+
+
+      for ( j = 0; j < blend->num_axis; j++, nsc++, ns++ )
+      {
+        if ( *nsc != *ns )
+          break;
+      }
+
+      if ( j == blend->num_axis )
+        break;
+    }
+
+    /* adjust named instance index */
+    face->root.face_index &= 0xFFFF;
+    if ( i < blend->mmvar->num_namedstyles )
+      face->root.face_index |= ( i + 1 ) << 16;
+
     face->is_default_instance = is_default_instance;
 
   Exit:
diff --git a/src/truetype/ttgxvar.h b/src/truetype/ttgxvar.h
index e431983..c59d528 100644
--- a/src/truetype/ttgxvar.h
+++ b/src/truetype/ttgxvar.h
@@ -232,6 +232,9 @@ FT_BEGIN_HEADER
     FT_MM_Var*      mmvar;
     FT_Offset       mmvar_len;
 
+    FT_Fixed*       normalized_stylecoords;
+                      /* normalized_stylecoords[num_namedstyles][num_axis] */
+
     FT_Bool         avar_checked;
     GX_AVarSegment  avar_segment;
 



reply via email to

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