Updates to the Type 1 driver Now with a simple AFM parser in order to read the kerning table..
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
diff --git a/src/type1/rules.mk b/src/type1/rules.mk
index 3b6355b..794ea0a 100644
--- a/src/type1/rules.mk
+++ b/src/type1/rules.mk
@@ -103,6 +103,7 @@ T1_DRV_SRC := $(T1_DIR_)t1objs.c \
$(T1_DIR_)t1driver.c \
$(T1_DIR_)t1encode.c \
$(T1_DIR_)t1hinter.c \
+ $(T1_DIR_)t1afm.c \
$(T1_DIR_)t1gload.c
diff --git a/src/type1/t1config.h b/src/type1/t1config.h
index a72b177..7b4119b 100644
--- a/src/type1/t1config.h
+++ b/src/type1/t1config.h
@@ -40,6 +40,13 @@
/* Define T1_CONFIG_OPTION_DISABLE_HINTER if you want to generate */
/* a driver with no hinter. This can be useful to debug the parser */
/* */
-#undef T1_CONFIG_OPTION_DISABLE_HINTER
+#define T1_CONFIG_OPTION_DISABLE_HINTER
+
+/* Define this configuration macro if you want to prevent the */
+/* compilation of "t1afm", which is in charge of reading Type1 */
+/* AFM files into an existing face. Note that when set, the T1 */
+/* driver will be unable to produce kerning distances.. */
+/* */
+#define T1_CONFIG_OPTION_NO_AFM
#endif /* T1CONFIG_H */
diff --git a/src/type1/t1driver.c b/src/type1/t1driver.c
index b137ddc..0f6ee54 100644
--- a/src/type1/t1driver.c
+++ b/src/type1/t1driver.c
@@ -17,6 +17,7 @@
#include <t1driver.h>
#include <t1gload.h>
+#include <t1afm.h>
#include <ftdebug.h>
#include <ftstream.h>
@@ -25,6 +26,97 @@
#undef FT_COMPONENT
#define FT_COMPONENT trace_t1driver
+#ifndef T1_CONFIG_OPTION_NO_AFM
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* Get_Interface */
+ /* */
+ /* <Description> */
+ /* Each driver can provide one or more extensions to the base */
+ /* FreeType API. These can be used to access format specific */
+ /* features (e.g., all TrueType/OpenType resources share a common */
+ /* file structure and common tables which can be accessed through the */
+ /* `sfnt' interface), or more simply generic ones (e.g., the */
+ /* `postscript names' interface which can be used to retrieve the */
+ /* PostScript name of a given glyph index). */
+ /* */
+ /* <InOut> */
+ /* driver :: A handle to a driver object. */
+ /* */
+ /* <Input> */
+ /* interface :: A string designing the interface. Examples are */
+ /* `sfnt', `post_names', `charmaps', etc. */
+ /* */
+ /* <Return> */
+ /* A typeless pointer to the extension's interface (normally a table */
+ /* of function pointers). Returns NULL if the requested extension */
+ /* isn't available (i.e., wasn't compiled in the driver at build */
+ /* time). */
+ /* */
+ static
+ void* Get_Interface)( FT_Driver driver,
+ const FT_String* interface )
+ {
+ if ( strcmp( (const char*)interface, "attach_file" ) == 0 )
+ return T1_Read_AFM;
+
+ return 0;
+ }
+
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* Get_Kerning */
+ /* */
+ /* <Description> */
+ /* A driver method used to return the kerning vector between two */
+ /* glyphs of the same face. */
+ /* */
+ /* <Input> */
+ /* face :: A handle to the source face object. */
+ /* */
+ /* left_glyph :: The index of the left glyph in the kern pair. */
+ /* */
+ /* right_glyph :: The index of the right glyph in the kern pair. */
+ /* */
+ /* <Output> */
+ /* kerning :: The kerning vector. This is in font units for */
+ /* scalable formats, and in pixels for fixed-sizes */
+ /* formats. */
+ /* */
+ /* <Return> */
+ /* FreeType error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* Only horizontal layouts (left-to-right & right-to-left) are */
+ /* supported by this function. Other layouts, or more sophisticated */
+ /* kernings are out of scope of this method (the basic driver */
+ /* interface is meant to be simple). */
+ /* */
+ /* They can be implemented by format-specific interfaces. */
+ /* */
+ static
+ T1_Error Get_Kerning( T1_Face face,
+ T1_UInt left_glyph,
+ T1_UInt right_glyph,
+ T1_Vector* kerning )
+ {
+ T1_AFM* afm;
+
+ kerning->x = 0;
+ kerning->y = 0;
+
+ afm = (T1_AFM*)face->afm_data;
+ if (afm)
+ T1_Get_Kerning( afm, left_glyph, right_glyph, kerning );
+
+ return T1_Err_Ok;
+ }
+#endif
+
/******************************************************************/
/* */
/* <Function> Set_Char_Sizes */
@@ -394,11 +486,21 @@
(FTDriver_initDriver) T1_Init_Driver,
(FTDriver_doneDriver) T1_Done_Driver,
+
+#ifdef T1_CONFIG_OPTION_NO_AFM
(FTDriver_getInterface) 0,
+#else
+ (FTDriver_getInterface) Get_Interface,
+#endif
(FTDriver_initFace) Init_Face,
(FTDriver_doneFace) T1_Done_Face,
+
+#ifdef T1_CONFIG_OPTION_NO_AFM
(FTDriver_getKerning) 0,
+#else
+ (FTDriver_getKerning) Get_Kerning,
+#endif
(FTDriver_initSize) T1_Init_Size,
(FTDriver_doneSize) T1_Done_Size,
diff --git a/src/type1/type1.c b/src/type1/type1.c
index f7058d0..2e7c80d 100644
--- a/src/type1/type1.c
+++ b/src/type1/type1.c
@@ -42,9 +42,14 @@
#include <t1objs.c>
#include <t1load.c> /* table loader */
#include <t1gload.c>
-
#include <t1tokens.c>
#include <t1parse.c>
#include <t1encode.c>
+
+#ifndef T1_CONFIG_OPTION_DISABLE_HINTER
#include <t1hinter.c>
+#endif
+#ifndef T1_CONFIG_OPTION_NO_AFM
+#include <t1afm.c>
+#endif