Commit f48b60ed59b3de5b08d8139ba8c3cfc662b7615a

David Turner 2007-01-08T15:15:32

* include/freetype/ftgasp.h, src/base/ftgasp.c: adding a new API FT_Get_Gasp to return entries of the GASP table corresponding to a given character pixel size. * src/sfnt/ttload.c: add version check for the GASP table, in order to be better future-proof * include/freetype/config/ftheader.h: add definition of FT_GASP_H, corresponding to <freetype/ftgasp.h> * src/base/rules.mk, src/base/Jamfile, modules.cfg, builds/win32/visualc/freetype.dsp, builds/win32/visualc/freetype.vcproj: Adding src/base/ftgasp.c to the default build

diff --git a/ChangeLog b/ChangeLog
index f26ab93..26c7226 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2007-01-08  David Turner  <david@freetype.org>
+
+	* include/freetype/ftgasp.h, src/base/ftgasp.c: adding a
+	new API FT_Get_Gasp to return entries of the GASP table
+	corresponding to a given character pixel size.
+
+	* src/sfnt/ttload.c: add version check for the GASP table,
+	in order to be better future-proof
+
+	* include/freetype/config/ftheader.h: add definition of
+	FT_GASP_H, corresponding to <freetype/ftgasp.h>
+
+	* src/base/rules.mk, src/base/Jamfile, modules.cfg,
+	builds/win32/visualc/freetype.dsp,
+	builds/win32/visualc/freetype.vcproj: Adding src/base/ftgasp.c
+	to the default build
+
 2007-01-07  Werner Lemberg  <wl@gnu.org>
 
 	* src/cid/cidparse.c (cid_parser_new): Improve error message for
diff --git a/builds/win32/visualc/freetype.dsp b/builds/win32/visualc/freetype.dsp
index fb1f1a9..07e3552 100644
--- a/builds/win32/visualc/freetype.dsp
+++ b/builds/win32/visualc/freetype.dsp
@@ -226,6 +226,10 @@ SOURCE=..\..\..\src\base\ftbitmap.c
 # End Source File
 # Begin Source File
 
+SOURCE=..\..\..\src\base\ftgasp.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\..\..\src\cache\ftcache.c
 # SUBTRACT CPP /Fr
 # End Source File
diff --git a/builds/win32/visualc/freetype.vcproj b/builds/win32/visualc/freetype.vcproj
index 1f7109b..dc68555 100644
--- a/builds/win32/visualc/freetype.vcproj
+++ b/builds/win32/visualc/freetype.vcproj
@@ -675,6 +675,10 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\..\src\base\ftgasp.c"
+				>
+			</File>
+			<File
 				RelativePath="..\..\..\src\cache\ftcache.c"
 				>
 				<FileConfiguration
diff --git a/include/freetype/config/ftheader.h b/include/freetype/config/ftheader.h
index 1265191..0bec850 100644
--- a/include/freetype/config/ftheader.h
+++ b/include/freetype/config/ftheader.h
@@ -677,6 +677,19 @@
    */
 #define FT_LCD_FILTER_H    <freetype/ftlcdfil.h>
 
+
+  /*************************************************************************
+   *
+   * @macro:
+   *   FT_GASP_H
+   *
+   * @description:
+   *   A macro used in #include statements to name the file containing the
+   *   FreeType 2 API which returns entries from the TrueType GASP table
+   */
+#define FT_GASP_H    <freetype/ftgasp.h>
+
+
   /* */
 
 #define FT_ERROR_DEFINITIONS_H  <freetype/fterrdef.h>
diff --git a/include/freetype/ftgasp.h b/include/freetype/ftgasp.h
new file mode 100644
index 0000000..f6c14f7
--- /dev/null
+++ b/include/freetype/ftgasp.h
@@ -0,0 +1,65 @@
+#ifndef _FT_GASP_H_
+#define _FT_GASP_H_
+
+#include <ft2build.h>
+#include FT_FREETYPE_H
+
+/**
+ * @enum: FT_GASP_XXX
+ *
+ * @description:
+ *   a list of values and/or bit-flags returned by the
+ *   @FT_Get_Gasp function.
+ *
+ * @values:
+ *   FT_GASP_NO_TABLE ::
+ *     this special value means that there is no GASP table
+ *     in this face. It's up to the client to decide what to
+ *     do
+ *
+ *   FT_GASP_DO_GRIDFIT ::
+ *     indicates that grid-fitting/hinting should be
+ *     performed at the specified ppem. This *really*
+ *     means TrueType bytecode interpretation
+ *
+ *   FT_GASP_DO_GRAY ::
+ *     indicates that anti-aliased rendering should be
+ *     performed at the specified ppem
+ *
+ *   FT_GASP_SYMMETRIC_SMOOTHING ::
+ *     indicates that smoothing along multiple axis
+ *     must be used with ClearType.
+ *
+ *   FT_GASP_SYMMETRIC_GRIDFIT ::
+ *     indicates that grid-fitting must be used with
+ *     ClearType's symmetric smoothing
+ */
+#define  FT_GASP_NO_TABLE               -1
+#define  FT_GASP_DO_GRIDFIT           0x01
+#define  FT_GASP_DO_GRAY              0x02
+#define  FT_GASP_SYMMETRIC_SMOOTHING  0x08
+#define  FT_GASP_SYMMETRIC_GRIDFIT    0x10
+
+ /**
+  * @func: FT_Get_Gasp
+  *
+  * @description:
+  *   read the GASP table from a TrueType or OpenType font file
+  *   and return the entry corresponding to a given character
+  *   pixel size
+  *
+  * @input:
+  *   face :: source face handle
+  *   ppem :: vertical character pixel size
+  *
+  * @return:
+  *   bit flags, or @FT_GASP_NO_TABLE is there is no GASP table
+  *   in the face.
+  */
+  FT_EXPORT( FT_Int )
+  FT_Get_Gasp( FT_Face    face,
+               FT_UInt    ppem );
+
+/* */
+
+#endif /* _FT_GASP_H_ */
diff --git a/modules.cfg b/modules.cfg
index 26a7506..6c924c0 100644
--- a/modules.cfg
+++ b/modules.cfg
@@ -216,6 +216,10 @@ BASE_EXTENSIONS += ftxf86.c
 # See include/freetype/ftlcdfil.h for the API.
 BASE_EXTENSIONS += ftlcdfil.c
 
+# Support for GASP table queries
+#
+# See include/freetype/ftgasp.h for the API
+BASE_EXTENSIONS += ftgasp.c
 
 ####
 #### The components `ftsystem.c' (for memory allocation and stream I/O
diff --git a/src/base/Jamfile b/src/base/Jamfile
index c6ac6b3..70fbbe8 100644
--- a/src/base/Jamfile
+++ b/src/base/Jamfile
@@ -34,7 +34,7 @@ SubDir  FT2_TOP $(FT2_SRC_DIR) base ;
   local  _sources =  system  init    glyph  mm      bdf
                      bbox    debug   xf86   type1   pfr
                      stroke  winfnt  otval  bitmap  synth
-                     gxval   lcdfil
+                     gxval   lcdfil  gasp
                      ;
 
   Library  $(FT2_LIB) : ft$(_sources).c ;
diff --git a/src/base/ftgasp.c b/src/base/ftgasp.c
new file mode 100644
index 0000000..27797bb
--- /dev/null
+++ b/src/base/ftgasp.c
@@ -0,0 +1,38 @@
+#include <ft2build.h>
+#include FT_GASP_H
+#include FT_INTERNAL_TRUETYPE_TYPES_H
+
+  FT_EXPORT_DEF( FT_Int )
+  FT_Get_Gasp( FT_Face    face,
+               FT_UInt    ppem )
+  {
+    FT_Int  result = FT_GASP_NO_TABLE;
+
+    if ( face && FT_IS_SFNT(face) )
+    {
+      TT_Face  ttface = (TT_Face)face;
+
+      if ( ttface->gasp.numRanges > 0 )
+      {
+        TT_GaspRange  range     = ttface->gasp.gaspRanges;
+        TT_GaspRange  range_end = range + ttface->gasp.numRanges;
+
+        while ( ppem > range->maxPPEM )
+        {
+          range++;
+          if ( range >= range_end )
+            goto Exit;
+        }
+
+        result = range->gaspFlag;
+
+        /* ensure we don't have spurious bits */
+        if ( ttface->gasp.version == 0 )
+          result &= 3;
+      }
+    }
+  Exit:
+    return result;
+  }
+
+
diff --git a/src/base/rules.mk b/src/base/rules.mk
index c947ba9..a3a5ac0 100644
--- a/src/base/rules.mk
+++ b/src/base/rules.mk
@@ -44,6 +44,7 @@ BASE_SRC := $(BASE_DIR)/ftcalc.c   \
             $(BASE_DIR)/ftrfork.c  \
             $(BASE_DIR)/ftstream.c \
             $(BASE_DIR)/fttrigon.c \
+            $(BASE_DIR)/ftgasp.c   \
             $(BASE_DIR)/ftutil.c
 
 # Base layer `extensions' sources
diff --git a/src/sfnt/ttload.c b/src/sfnt/ttload.c
index c81f80d..0801f83 100644
--- a/src/sfnt/ttload.c
+++ b/src/sfnt/ttload.c
@@ -1138,6 +1138,14 @@
 
     FT_FRAME_EXIT();
 
+    /* only support versions 0 and 1 of the table */
+    if ( face->gasp.version >= 2 )
+    {
+      face->gasp.numRanges = 0;
+      error = FT_Err_Invalid_Table;
+      goto Exit;
+    }
+
     num_ranges = face->gasp.numRanges;
     FT_TRACE3(( "numRanges: %u\n", num_ranges ));