Commit 7a1639bc1ee3ab8d79bfd7b58270c2f3eb908269

Nikhil Ramakrishnan 2019-06-30T20:01:20

[woff2] Get known tags from function. Change `KnownTags' to a function (`woff2_known_tags'). This avoids introducing a global constant array. This function returns the specified index without *any* checks. The caller must ensure that `index' is within array limits. * src/sfnt/sfwoff2.c (woff2_open_font): Change `KnownTags[...]' notation to `woff2_known_tags( ... )'. * src/sfnt/woff2tags.c: Perform changes. * src/sfnt/woff2tags.h: Update definitions.

diff --git a/ChangeLog b/ChangeLog
index f89194b..ff6f840 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,21 @@
 2019-08-27  Nikhil Ramakrishnan  <ramakrishnan.nikhil@gmail.com>
 
+	[woff2] Get known tags from function.
+
+	Change `KnownTags' to a function (`woff2_known_tags').  This avoids
+	introducing a global constant array.  This function returns the
+	specified index without *any* checks.  The caller must ensure that
+	`index' is within array limits.
+
+	* src/sfnt/sfwoff2.c (woff2_open_font): Change `KnownTags[...]'
+	notation to `woff2_known_tags( ...  )'.
+
+	* src/sfnt/woff2tags.c: Perform changes.
+
+	* src/sfnt/woff2tags.h: Update definitions.
+
+2019-08-27  Nikhil Ramakrishnan  <ramakrishnan.nikhil@gmail.com>
+
 	[woff2] Minor.
 
 	* src/sfnt/sfwoff2.c (woff2_uncompress): Add error message
diff --git a/src/sfnt/sfwoff2.c b/src/sfnt/sfwoff2.c
index 614c99b..545f7ed 100644
--- a/src/sfnt/sfwoff2.c
+++ b/src/sfnt/sfwoff2.c
@@ -360,7 +360,7 @@
           goto Exit;
       }
       else
-        table->Tag = KnownTags[table->FlagByte & 0x3f];
+        table->Tag = woff2_known_tags( table->FlagByte & 0x3f );
 
       flags = 0;
       xform_version = ( table->FlagByte >> 6 ) & 0x03;
diff --git a/src/sfnt/woff2tags.c b/src/sfnt/woff2tags.c
index 6a84d29..5b274d5 100644
--- a/src/sfnt/woff2tags.c
+++ b/src/sfnt/woff2tags.c
@@ -19,72 +19,80 @@
 #include "sfwoff.h"
 #include FT_TRUETYPE_TAGS_H
 
-/* Known table tags in the order given in WOFF2 specification. */
-const FT_ULong KnownTags[63] = {
-  FT_MAKE_TAG('c', 'm', 'a', 'p'),  /*  0  */
-  FT_MAKE_TAG('h', 'e', 'a', 'd'),  /*  1  */
-  FT_MAKE_TAG('h', 'h', 'e', 'a'),  /*  2  */
-  FT_MAKE_TAG('h', 'm', 't', 'x'),  /*  3  */
-  FT_MAKE_TAG('m', 'a', 'x', 'p'),  /*  4  */
-  FT_MAKE_TAG('n', 'a', 'm', 'e'),  /*  5  */
-  FT_MAKE_TAG('O', 'S', '/', '2'),  /*  6  */
-  FT_MAKE_TAG('p', 'o', 's', 't'),  /*  7  */
-  FT_MAKE_TAG('c', 'v', 't', ' '),  /*  8  */
-  FT_MAKE_TAG('f', 'p', 'g', 'm'),  /*  9  */
-  FT_MAKE_TAG('g', 'l', 'y', 'f'),  /*  10 */
-  FT_MAKE_TAG('l', 'o', 'c', 'a'),  /*  11 */
-  FT_MAKE_TAG('p', 'r', 'e', 'p'),  /*  12 */
-  FT_MAKE_TAG('C', 'F', 'F', ' '),  /*  13 */
-  FT_MAKE_TAG('V', 'O', 'R', 'G'),  /*  14 */
-  FT_MAKE_TAG('E', 'B', 'D', 'T'),  /*  15 */
-  FT_MAKE_TAG('E', 'B', 'L', 'C'),  /*  16 */
-  FT_MAKE_TAG('g', 'a', 's', 'p'),  /*  17 */
-  FT_MAKE_TAG('h', 'd', 'm', 'x'),  /*  18 */
-  FT_MAKE_TAG('k', 'e', 'r', 'n'),  /*  19 */
-  FT_MAKE_TAG('L', 'T', 'S', 'H'),  /*  20 */
-  FT_MAKE_TAG('P', 'C', 'L', 'T'),  /*  21 */
-  FT_MAKE_TAG('V', 'D', 'M', 'X'),  /*  22 */
-  FT_MAKE_TAG('v', 'h', 'e', 'a'),  /*  23 */
-  FT_MAKE_TAG('v', 'm', 't', 'x'),  /*  24 */
-  FT_MAKE_TAG('B', 'A', 'S', 'E'),  /*  25 */
-  FT_MAKE_TAG('G', 'D', 'E', 'F'),  /*  26 */
-  FT_MAKE_TAG('G', 'P', 'O', 'S'),  /*  27 */
-  FT_MAKE_TAG('G', 'S', 'U', 'B'),  /*  28 */
-  FT_MAKE_TAG('E', 'B', 'S', 'C'),  /*  29 */
-  FT_MAKE_TAG('J', 'S', 'T', 'F'),  /*  30 */
-  FT_MAKE_TAG('M', 'A', 'T', 'H'),  /*  31 */
-  FT_MAKE_TAG('C', 'B', 'D', 'T'),  /*  32 */
-  FT_MAKE_TAG('C', 'B', 'L', 'C'),  /*  33 */
-  FT_MAKE_TAG('C', 'O', 'L', 'R'),  /*  34 */
-  FT_MAKE_TAG('C', 'P', 'A', 'L'),  /*  35 */
-  FT_MAKE_TAG('S', 'V', 'G', ' '),  /*  36 */
-  FT_MAKE_TAG('s', 'b', 'i', 'x'),  /*  37 */
-  FT_MAKE_TAG('a', 'c', 'n', 't'),  /*  38 */
-  FT_MAKE_TAG('a', 'v', 'a', 'r'),  /*  39 */
-  FT_MAKE_TAG('b', 'd', 'a', 't'),  /*  40 */
-  FT_MAKE_TAG('b', 'l', 'o', 'c'),  /*  41 */
-  FT_MAKE_TAG('b', 's', 'l', 'n'),  /*  42 */
-  FT_MAKE_TAG('c', 'v', 'a', 'r'),  /*  43 */
-  FT_MAKE_TAG('f', 'd', 's', 'c'),  /*  44 */
-  FT_MAKE_TAG('f', 'e', 'a', 't'),  /*  45 */
-  FT_MAKE_TAG('f', 'm', 't', 'x'),  /*  46 */
-  FT_MAKE_TAG('f', 'v', 'a', 'r'),  /*  47 */
-  FT_MAKE_TAG('g', 'v', 'a', 'r'),  /*  48 */
-  FT_MAKE_TAG('h', 's', 't', 'y'),  /*  49 */
-  FT_MAKE_TAG('j', 'u', 's', 't'),  /*  50 */
-  FT_MAKE_TAG('l', 'c', 'a', 'r'),  /*  51 */
-  FT_MAKE_TAG('m', 'o', 'r', 't'),  /*  52 */
-  FT_MAKE_TAG('m', 'o', 'r', 'x'),  /*  53 */
-  FT_MAKE_TAG('o', 'p', 'b', 'd'),  /*  54 */
-  FT_MAKE_TAG('p', 'r', 'o', 'p'),  /*  55 */
-  FT_MAKE_TAG('t', 'r', 'a', 'k'),  /*  56 */
-  FT_MAKE_TAG('Z', 'a', 'p', 'f'),  /*  57 */
-  FT_MAKE_TAG('S', 'i', 'l', 'f'),  /*  58 */
-  FT_MAKE_TAG('G', 'l', 'a', 't'),  /*  59 */
-  FT_MAKE_TAG('G', 'l', 'o', 'c'),  /*  60 */
-  FT_MAKE_TAG('F', 'e', 'a', 't'),  /*  61 */
-  FT_MAKE_TAG('S', 'i', 'l', 'l'),  /*  62 */
-};
+  /* Return tag from index in the order given in WOFF2 specification. */
+  FT_LOCAL_DEF( FT_ULong )
+  woff2_known_tags( FT_Byte  index )
+  {
+    const FT_ULong  known_tags[63] =
+    {
+      FT_MAKE_TAG('c', 'm', 'a', 'p'),  /*  0  */
+      FT_MAKE_TAG('h', 'e', 'a', 'd'),  /*  1  */
+      FT_MAKE_TAG('h', 'h', 'e', 'a'),  /*  2  */
+      FT_MAKE_TAG('h', 'm', 't', 'x'),  /*  3  */
+      FT_MAKE_TAG('m', 'a', 'x', 'p'),  /*  4  */
+      FT_MAKE_TAG('n', 'a', 'm', 'e'),  /*  5  */
+      FT_MAKE_TAG('O', 'S', '/', '2'),  /*  6  */
+      FT_MAKE_TAG('p', 'o', 's', 't'),  /*  7  */
+      FT_MAKE_TAG('c', 'v', 't', ' '),  /*  8  */
+      FT_MAKE_TAG('f', 'p', 'g', 'm'),  /*  9  */
+      FT_MAKE_TAG('g', 'l', 'y', 'f'),  /*  10 */
+      FT_MAKE_TAG('l', 'o', 'c', 'a'),  /*  11 */
+      FT_MAKE_TAG('p', 'r', 'e', 'p'),  /*  12 */
+      FT_MAKE_TAG('C', 'F', 'F', ' '),  /*  13 */
+      FT_MAKE_TAG('V', 'O', 'R', 'G'),  /*  14 */
+      FT_MAKE_TAG('E', 'B', 'D', 'T'),  /*  15 */
+      FT_MAKE_TAG('E', 'B', 'L', 'C'),  /*  16 */
+      FT_MAKE_TAG('g', 'a', 's', 'p'),  /*  17 */
+      FT_MAKE_TAG('h', 'd', 'm', 'x'),  /*  18 */
+      FT_MAKE_TAG('k', 'e', 'r', 'n'),  /*  19 */
+      FT_MAKE_TAG('L', 'T', 'S', 'H'),  /*  20 */
+      FT_MAKE_TAG('P', 'C', 'L', 'T'),  /*  21 */
+      FT_MAKE_TAG('V', 'D', 'M', 'X'),  /*  22 */
+      FT_MAKE_TAG('v', 'h', 'e', 'a'),  /*  23 */
+      FT_MAKE_TAG('v', 'm', 't', 'x'),  /*  24 */
+      FT_MAKE_TAG('B', 'A', 'S', 'E'),  /*  25 */
+      FT_MAKE_TAG('G', 'D', 'E', 'F'),  /*  26 */
+      FT_MAKE_TAG('G', 'P', 'O', 'S'),  /*  27 */
+      FT_MAKE_TAG('G', 'S', 'U', 'B'),  /*  28 */
+      FT_MAKE_TAG('E', 'B', 'S', 'C'),  /*  29 */
+      FT_MAKE_TAG('J', 'S', 'T', 'F'),  /*  30 */
+      FT_MAKE_TAG('M', 'A', 'T', 'H'),  /*  31 */
+      FT_MAKE_TAG('C', 'B', 'D', 'T'),  /*  32 */
+      FT_MAKE_TAG('C', 'B', 'L', 'C'),  /*  33 */
+      FT_MAKE_TAG('C', 'O', 'L', 'R'),  /*  34 */
+      FT_MAKE_TAG('C', 'P', 'A', 'L'),  /*  35 */
+      FT_MAKE_TAG('S', 'V', 'G', ' '),  /*  36 */
+      FT_MAKE_TAG('s', 'b', 'i', 'x'),  /*  37 */
+      FT_MAKE_TAG('a', 'c', 'n', 't'),  /*  38 */
+      FT_MAKE_TAG('a', 'v', 'a', 'r'),  /*  39 */
+      FT_MAKE_TAG('b', 'd', 'a', 't'),  /*  40 */
+      FT_MAKE_TAG('b', 'l', 'o', 'c'),  /*  41 */
+      FT_MAKE_TAG('b', 's', 'l', 'n'),  /*  42 */
+      FT_MAKE_TAG('c', 'v', 'a', 'r'),  /*  43 */
+      FT_MAKE_TAG('f', 'd', 's', 'c'),  /*  44 */
+      FT_MAKE_TAG('f', 'e', 'a', 't'),  /*  45 */
+      FT_MAKE_TAG('f', 'm', 't', 'x'),  /*  46 */
+      FT_MAKE_TAG('f', 'v', 'a', 'r'),  /*  47 */
+      FT_MAKE_TAG('g', 'v', 'a', 'r'),  /*  48 */
+      FT_MAKE_TAG('h', 's', 't', 'y'),  /*  49 */
+      FT_MAKE_TAG('j', 'u', 's', 't'),  /*  50 */
+      FT_MAKE_TAG('l', 'c', 'a', 'r'),  /*  51 */
+      FT_MAKE_TAG('m', 'o', 'r', 't'),  /*  52 */
+      FT_MAKE_TAG('m', 'o', 'r', 'x'),  /*  53 */
+      FT_MAKE_TAG('o', 'p', 'b', 'd'),  /*  54 */
+      FT_MAKE_TAG('p', 'r', 'o', 'p'),  /*  55 */
+      FT_MAKE_TAG('t', 'r', 'a', 'k'),  /*  56 */
+      FT_MAKE_TAG('Z', 'a', 'p', 'f'),  /*  57 */
+      FT_MAKE_TAG('S', 'i', 'l', 'f'),  /*  58 */
+      FT_MAKE_TAG('G', 'l', 'a', 't'),  /*  59 */
+      FT_MAKE_TAG('G', 'l', 'o', 'c'),  /*  60 */
+      FT_MAKE_TAG('F', 'e', 'a', 't'),  /*  61 */
+      FT_MAKE_TAG('S', 'i', 'l', 'l'),  /*  62 */
+    };
+
+
+    return known_tags[index];
+  }
 
 
 /* END */
diff --git a/src/sfnt/woff2tags.h b/src/sfnt/woff2tags.h
index 97b7f9c..6579b85 100644
--- a/src/sfnt/woff2tags.h
+++ b/src/sfnt/woff2tags.h
@@ -27,14 +27,15 @@
 FT_BEGIN_HEADER
 
 
-/* Leave the first byte open to store flag_byte. */
+  /* Leave the first byte open to store flag_byte. */
 #define WOFF2_FLAGS_TRANSFORM   1 << 8
 
 #define WOFF2_SFNT_HEADER_SIZE  12
 #define WOFF2_SFNT_ENTRY_SIZE   16
 
-/* Known table tags. */
-extern const FT_ULong KnownTags[];
+  FT_LOCAL( FT_ULong )
+  woff2_known_tags( FT_Byte  index );
+
 
 FT_END_HEADER