Added support for the "attach_file" format-specific driver interface, used to implement FT_Attach_File. Note, this is currently very lightly tested..
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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
diff --git a/src/base/ftdriver.h b/src/base/ftdriver.h
index 2091913..ff8e6b2 100644
--- a/src/base/ftdriver.h
+++ b/src/base/ftdriver.h
@@ -118,6 +118,18 @@
typedef void* FT_FormatInterface;
+ /*************************************************************************/
+ /* */
+ /* <FuncType> */
+ /* FT_Attach_Reader */
+ /* */
+ /* <Description> */
+ /* This function is associated to the "attach_file" driver-specific */
+ /* interface. It is used to read additional data for a given face */
+ /* from another input stream/file. For example, it is used to */
+ /* attach a Type 1 AFM file to a given Type 1 face.. */
+ /* */
+ typedef FT_Error (*FT_Attach_Reader)( FT_Face face, FT_Stream stream );
/*************************************************************************/
/*************************************************************************/
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index 6320e20..ae9f014 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -209,6 +209,79 @@
}
+ /***************************************************************************
+ *
+ * ft_new_input_stream:
+ *
+ * create a new input stream object from a FT_Open_Args structure..
+ *
+ **************************************************************************/
+ static
+ FT_Error ft_new_input_stream( FT_Library library,
+ FT_Open_Args* args,
+ FT_Stream *astream )
+ {
+ FT_Error error;
+ FT_Memory memory;
+ FT_Stream stream;
+
+ memory = library->memory;
+ if ( ALLOC( stream, sizeof(*stream) ) )
+ return error;
+
+ stream->memory = memory;
+
+ /* is it a memory stream ------------------------- ? */
+ if (args->memory_base && args->memory_size)
+ {
+ FT_New_Memory_Stream( library,
+ args->memory_base,
+ args->memory_size,
+ stream );
+ }
+
+ /* do we have an 8-bit pathname ------------------ ? */
+ else if (args->pathname)
+ error = FT_New_Stream( args->pathname, stream );
+
+ /* do we have a custom stream -------------------- ? */
+ else if (args->stream)
+ {
+ /* copy the content of the argument stream into the new stream object */
+ *stream = *(args->stream);
+ stream->memory = memory;
+ }
+ else
+ error = FT_Err_Invalid_Argument;
+
+ if (error)
+ FREE(stream);
+
+ *astream = stream;
+ return error;
+ }
+
+
+ /***************************************************************************
+ *
+ * ft_done_stream:
+ *
+ * closes and destroys a stream object.
+ *
+ **************************************************************************/
+ static
+ void ft_done_stream( FT_Stream* astream )
+ {
+ FT_Stream stream = *astream;
+ FT_Memory memory = stream->memory;
+
+ if (stream->close)
+ stream->close( stream );
+
+ FREE( stream );
+ *astream = 0;
+ }
+
/*************************************************************************/
/*************************************************************************/
@@ -259,6 +332,9 @@
if ( face->generic.finalizer )
face->generic.finalizer( face );
+ /* close the stream for this face */
+ ft_done_stream( &face->stream );
+
/* get rid of it */
FREE( face );
}
@@ -935,60 +1011,6 @@
}
- /***************************************************************************
- *
- * ft_new_input_stream:
- *
- * create a new input stream object from a FT_Open_Args structure..
- *
- **************************************************************************/
- static
- FT_Error ft_new_input_stream( FT_Library library,
- FT_Open_Args* args,
- FT_Stream *astream )
- {
- FT_Error error;
- FT_Memory memory;
- FT_Stream stream;
-
- memory = library->memory;
- if ( ALLOC( stream, sizeof(*stream) ) )
- return error;
-
- stream->memory = memory;
-
- /* is it a memory stream ------------------------- ? */
- if (args->memory_base && args->memory_size)
- {
- FT_New_Memory_Stream( library,
- args->memory_base,
- args->memory_size,
- stream );
- }
-
- /* do we have an 8-bit pathname ------------------ ? */
- else if (args->pathname)
- error = FT_New_Stream( args->pathname, stream );
-
- /* do we have a custom stream -------------------- ? */
- else if (args->stream)
- {
- /* copy the content of the argument stream into the new stream object */
- *stream = *(args->stream);
- stream->memory = memory;
- }
- else
- error = FT_Err_Invalid_Argument;
-
- if (error)
- FREE(stream);
-
- *astream = stream;
- return error;
- }
-
-
-
/*************************************************************************/
/* */
/* <Function> */
@@ -1024,19 +1046,20 @@
/* `*face'. Its return value should be 0 if the resource is */
/* recognized, or non-zero if not. */
/* */
+
+ static
+ const FT_Open_Args ft_default_open_args =
+ { 0, 0, 0, 0, 0 };
+
EXPORT_FUNC
FT_Error FT_New_Face( FT_Library library,
const char* pathname,
FT_Long face_index,
FT_Face *aface )
{
- FT_Open_Args args;
-
- args.memory_base = 0;
- args.memory_size = 0;
- args.stream = 0;
- args.pathname = (FT_Byte*)pathname;
+ FT_Open_Args args = ft_default_open_args;
+ args.pathname = (FT_Byte*)pathname;
return FT_Open_Face( library, &args, face_index, aface );
}
@@ -1048,13 +1071,10 @@
FT_Long face_index,
FT_Face* face )
{
- FT_Open_Args args;
+ FT_Open_Args args = ft_default_open_args;
args.memory_base = file_base;
args.memory_size = file_size;
- args.pathname = 0;
- args.stream = 0;
-
return FT_Open_Face( library, &args, face_index, face );
}
@@ -1083,6 +1103,23 @@
memory = library->memory;
+ /* if the font driver is specified in the args structure, use */
+ /* it. Otherwise, we'll scan the list of registered drivers.. */
+ if (args->driver)
+ {
+ driver = args->driver;
+ /* not all drivers directly support face objects, so check.. */
+ if (driver->interface.face_object_size)
+ {
+ error = open_face( driver, stream, face_index, &face );
+ if (!error) goto Success;
+ }
+ else
+ error = FT_Err_Invalid_Handle;
+
+ goto Fail;
+ }
+
{
/* check each font driver for an appropriate format */
FT_Driver* cur = library->drivers;
@@ -1091,7 +1128,7 @@
for ( ; cur < limit; cur++ )
{
driver = *cur;
- /* not all drivers directly support face object, so check.. */
+ /* not all drivers directly support face objects, so check.. */
if (driver->interface.face_object_size)
{
error = open_face( driver, stream, face_index, &face );
@@ -1155,6 +1192,112 @@
/*************************************************************************/
/* */
/* <Function> */
+ /* FT_Attach_File */
+ /* */
+ /* <Description> */
+ /* "Attach" a given font file to an existing face. This is usually */
+ /* to read additionnal information for a single face object. For */
+ /* example, it is used to read the AFM files that come with Type 1 */
+ /* fonts in order to add kerning data and other metrics.. */
+ /* */
+ /* <Input> */
+ /* face :: target face object */
+ /* */
+ /* filepathname :: an 8-bit pathname naming the 'metrics' file. */
+ /* */
+ /* <Return> */
+ /* Error code. 0 means success. */
+ /* */
+ /* <Note> */
+ /* If your font file is in memory, or if you want to provide your */
+ /* own input stream object, see FT_Attach_Stream. */
+ /* */
+ /* The meaning of the "attach" (i.e. what really happens when the */
+ /* new file is read) is not fixed by FreeType itself. It really */
+ /* depends on the font format (and thus the font driver). */
+ /* */
+ /* Client applications are expected to know what they're doing */
+ /* when invoking this function. Most drivers simply do not implement */
+ /* file attachments.. */
+ /* */
+ EXPORT_FUNC
+ FT_Error FT_Attach_File( FT_Face face,
+ const char* filepathname )
+ {
+ FT_Open_Args open = ft_default_open_args;
+
+ open.pathname = (char*)filepathname;
+ return FT_Attach_Stream( face, &open );
+ }
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
+ /* FT_Attach_Stream */
+ /* */
+ /* <Description> */
+ /* This function is similar to FT_Attach_File with the exception */
+ /* that it reads the attachment from an arbitrary stream. */
+ /* */
+ /* <Input> */
+ /* face :: target face object */
+ /* */
+ /* args :: a pointer to an FT_Open_Args structure used to describe */
+ /* the input stream to FreeType */
+ /* <Return> */
+ /* Error code. 0 means success. */
+ /* */
+ /* The meaning of the "attach" (i.e. what really happens when the */
+ /* new file is read) is not fixed by FreeType itself. It really */
+ /* depends on the font format (and thus the font driver). */
+ /* */
+ /* Client applications are expected to know what they're doing */
+ /* when invoking this function. Most drivers simply do not implement */
+ /* file attachments.. */
+ /* */
+ EXPORT_DEF
+ FT_Error FT_Attach_Stream( FT_Face face,
+ FT_Open_Args* parameters )
+ {
+ FT_Stream stream;
+ FT_Error error;
+ FT_Driver driver;
+
+ FTDriver_getInterface get_interface;
+
+ if ( !face || !face->driver )
+ return FT_Err_Invalid_Handle;
+
+ driver = face->driver;
+ error = ft_new_input_stream( driver->library, parameters, &stream );
+ if (error) goto Exit;
+
+ /* we implement FT_Attach_Stream in each driver through the */
+ /* "attach_file" interface.. */
+ error = FT_Err_Unimplemented_Feature;
+
+ get_interface = driver->interface.get_interface;
+ if (get_interface)
+ {
+ FT_Attach_Reader reader;
+
+ reader = (FT_Attach_Reader)get_interface( driver, "attach_file" );
+ if (reader)
+ error = reader( face, stream );
+ }
+
+ /* close the attached stream */
+ ft_done_stream( &stream );
+
+ Exit:
+ return error;
+ }
+
+
+
+ /*************************************************************************/
+ /* */
+ /* <Function> */
/* FT_Done_Face */
/* */
/* <Description> */