added the FT_Attach_File function to enable AFM parsing. Also, changed the API for FT_Open_Face to allow broader stream descriptions..
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
diff --git a/src/base/ftobjs.c b/src/base/ftobjs.c
index d46692f..6320e20 100644
--- a/src/base/ftobjs.c
+++ b/src/base/ftobjs.c
@@ -935,6 +935,60 @@
}
+ /***************************************************************************
+ *
+ * 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> */
@@ -976,31 +1030,14 @@
FT_Long face_index,
FT_Face *aface )
{
- FT_Stream stream;
- FT_Memory memory;
- FT_Error error;
-
-
- memory = library->memory;
- if ( ALLOC( stream, sizeof ( *stream ) ) )
- goto Fail;
-
- stream->memory = memory;
-
- error = FT_New_Stream( pathname, stream );
- if (error) goto Fail_Stream;
-
- error = FT_Open_Face( library, stream, face_index, aface );
- if ( !error )
- return error;
-
- /* close stream in case of error */
- stream->close( stream );
-
- Fail_Stream:
- FREE( stream );
- Fail:
- return error;
+ FT_Open_Args args;
+
+ args.memory_base = 0;
+ args.memory_size = 0;
+ args.stream = 0;
+ args.pathname = (FT_Byte*)pathname;
+
+ return FT_Open_Face( library, &args, face_index, aface );
}
@@ -1011,45 +1048,39 @@
FT_Long face_index,
FT_Face* face )
{
- FT_Stream stream;
- FT_Memory memory;
- FT_Error error;
-
- memory = library->memory;
- if ( ALLOC( stream, sizeof(*stream) ) )
- goto Fail;
-
- stream->memory = memory;
+ FT_Open_Args args;
- FT_New_Memory_Stream( library, (void*)file_base, file_size, stream );
+ args.memory_base = file_base;
+ args.memory_size = file_size;
+ args.pathname = 0;
+ args.stream = 0;
- error = FT_Open_Face( library, stream, face_index, face );
- if (!error)
- return error;
-
- FREE(stream);
- Fail:
- return error;
+ return FT_Open_Face( library, &args, face_index, face );
}
EXPORT_FUNC
- FT_Error FT_Open_Face( FT_Library library,
- FT_Stream stream,
- FT_Long face_index,
- FT_Face* aface )
+ FT_Error FT_Open_Face( FT_Library library,
+ FT_Open_Args* args,
+ FT_Long face_index,
+ FT_Face* aface )
{
FT_Error error;
FT_Driver driver;
FT_Memory memory;
+ FT_Stream stream;
FT_Face face = 0;
FT_ListNode node = 0;
*aface = 0;
- if ( !library || !stream )
+ if ( !library )
return FT_Err_Invalid_Handle;
+ /* create input stream */
+ error = ft_new_input_stream( library, args, &stream );
+ if (error) goto Exit;
+
memory = library->memory;
{
@@ -1060,6 +1091,7 @@
for ( ; cur < limit; cur++ )
{
driver = *cur;
+ /* not all drivers directly support face object, so check.. */
if (driver->interface.face_object_size)
{
error = open_face( driver, stream, face_index, &face );
@@ -1067,30 +1099,21 @@
goto Success;
if ( error != FT_Err_Unknown_File_Format )
- goto Bad_Resource;
+ goto Fail;
}
}
/* no driver is able to handle this format */
error = FT_Err_Unknown_File_Format;
- goto Bad_Resource;
+ goto Fail;
}
Success:
- /****************************************************************/
- /* if we were simply checking the font format, discard the face */
- /* object, then return successfully. */
- if ( face_index < 0 )
- {
- driver->interface.done_face( face );
- FREE( face );
- goto Exit;
- }
FT_TRACE4(( "FT_New_Face: New face object, adding to list\n" ));
/****************************************************************/
- /* Otherwise add the face object to its driver's list */
+ /* add the face object to its driver's list */
if ( ALLOC( node, sizeof ( *node ) ) )
goto Fail;
@@ -1123,8 +1146,6 @@
Fail:
FT_Done_Face( face );
- Bad_Resource:
-
Exit:
FT_TRACE4(( "FT_Open_Face: Return %d\n", error ));
return error;