[sfnt] Modularize `sfnt_get_ps_name'. * src/sfnt/sfdriver.c (sfnt_get_ps_name): Split off some functionality into... (IS_WIN, IS_APPLE): ... New macros. (get_win_string, get_apple_string): ... New functions.
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
diff --git a/ChangeLog b/ChangeLog
index 3c9d4bf..8b715c8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2017-02-23 Werner Lemberg <wl@gnu.org>
+ [sfnt] Modularize `sfnt_get_ps_name'.
+
+ * src/sfnt/sfdriver.c (sfnt_get_ps_name): Split off some
+ functionality into...
+ (IS_WIN, IS_APPLE): ... New macros.
+ (get_win_string, get_apple_string): ... New functions.
+
+2017-02-23 Werner Lemberg <wl@gnu.org>
+
[truetype] Minor improvement.
* src/truetype/ttgload.c (TT_Process_Simple_Glyph,
diff --git a/src/sfnt/sfdriver.c b/src/sfnt/sfdriver.c
index a70f9a2..a7bde16 100644
--- a/src/sfnt/sfdriver.c
+++ b/src/sfnt/sfdriver.c
@@ -220,114 +220,134 @@
*
*/
+ /* handling of PID/EID 3/0 and 3/1 is the same */
+#define IS_WIN( n ) ( (n)->platformID == 3 && \
+ ( (n)->encodingID == 1 || (n)->encodingID == 0 ) && \
+ (n)->languageID == 0x409 )
+
+#define IS_APPLE( n ) ( (n)->platformID == 1 && \
+ (n)->encodingID == 0 && \
+ (n)->languageID == 0 )
+
static const char*
- sfnt_get_ps_name( TT_Face face )
+ get_win_string( FT_Memory memory,
+ FT_Stream stream,
+ TT_Name entry )
{
- FT_Int n, found_win, found_apple;
- const char* result = NULL;
+ FT_Error error = FT_Err_Ok;
+ const char* result;
+ FT_String* r;
+ FT_Char* p;
+ FT_UInt len;
- /* shouldn't happen, but just in case to avoid memory leaks */
- if ( face->postscript_name )
- return face->postscript_name;
+ FT_UNUSED( error );
- /* scan the name table to see whether we have a Postscript name here, */
- /* either in Macintosh or Windows platform encodings */
- found_win = -1;
- found_apple = -1;
- for ( n = 0; n < face->num_names; n++ )
+ if ( FT_ALLOC( result, entry->stringLength / 2 + 1 ) )
+ return NULL;
+
+ if ( FT_STREAM_SEEK( entry->stringOffset ) ||
+ FT_FRAME_ENTER( entry->stringLength ) )
{
- TT_Name name = face->name_table.names + n;
+ FT_FREE( result );
+ entry->stringLength = 0;
+ entry->stringOffset = 0;
+ FT_FREE( entry->string );
+ return NULL;
+ }
- if ( name->nameID == 6 && name->stringLength > 0 )
- {
- /* handling of PID/EID 3/0 and 3/1 is the same */
- if ( name->platformID == 3 &&
- ( name->encodingID == 1 || name->encodingID == 0 ) &&
- name->languageID == 0x409 )
- found_win = n;
+ r = (FT_String*)result;
+ p = (FT_Char*)stream->cursor;
- if ( name->platformID == 1 &&
- name->encodingID == 0 &&
- name->languageID == 0 )
- found_apple = n;
- }
+ for ( len = entry->stringLength / 2; len > 0; len--, p += 2 )
+ {
+ if ( p[0] == 0 && p[1] >= 32 )
+ *r++ = p[1];
}
+ *r = '\0';
- if ( found_win != -1 )
- {
- FT_Memory memory = face->root.memory;
- TT_Name name = face->name_table.names + found_win;
- FT_UInt len = name->stringLength / 2;
- FT_Error error = FT_Err_Ok;
+ FT_FRAME_EXIT();
- FT_UNUSED( error );
+ return result;
+ }
- if ( !FT_ALLOC( result, name->stringLength + 1 ) )
- {
- FT_Stream stream = face->name_table.stream;
- FT_String* r = (FT_String*)result;
- FT_Char* p;
+ static const char*
+ get_apple_string( FT_Memory memory,
+ FT_Stream stream,
+ TT_Name entry )
+ {
+ FT_Error error = FT_Err_Ok;
+ const char* result;
- if ( FT_STREAM_SEEK( name->stringOffset ) ||
- FT_FRAME_ENTER( name->stringLength ) )
- {
- FT_FREE( result );
- name->stringLength = 0;
- name->stringOffset = 0;
- FT_FREE( name->string );
+ FT_UNUSED( error );
- goto Exit;
- }
- p = (FT_Char*)stream->cursor;
+ if ( FT_ALLOC( result, entry->stringLength + 1 ) )
+ return NULL;
- for ( ; len > 0; len--, p += 2 )
- {
- if ( p[0] == 0 && p[1] >= 32 )
- *r++ = p[1];
- }
- *r = '\0';
+ if ( FT_STREAM_SEEK( entry->stringOffset ) ||
+ FT_STREAM_READ( result, entry->stringLength ) )
+ {
+ FT_FREE( result );
+ entry->stringOffset = 0;
+ entry->stringLength = 0;
+ FT_FREE( entry->string );
- FT_FRAME_EXIT();
- }
- goto Exit;
+ return NULL;
}
- if ( found_apple != -1 )
- {
- FT_Memory memory = face->root.memory;
- TT_Name name = face->name_table.names + found_apple;
- FT_UInt len = name->stringLength;
- FT_Error error = FT_Err_Ok;
+ ((char*)result)[entry->stringLength] = '\0';
- FT_UNUSED( error );
+ return result;
+ }
- if ( !FT_ALLOC( result, len + 1 ) )
- {
- FT_Stream stream = face->name_table.stream;
+ static const char*
+ sfnt_get_ps_name( TT_Face face )
+ {
+ FT_Int n, found_win, found_apple;
+ const char* result = NULL;
- if ( FT_STREAM_SEEK( name->stringOffset ) ||
- FT_STREAM_READ( result, len ) )
- {
- name->stringOffset = 0;
- name->stringLength = 0;
- FT_FREE( name->string );
- FT_FREE( result );
- goto Exit;
- }
- ((char*)result)[len] = '\0';
+ if ( face->postscript_name )
+ return face->postscript_name;
+
+ /* scan the name table to see whether we have a Postscript name here, */
+ /* either in Macintosh or Windows platform encodings */
+ found_win = -1;
+ found_apple = -1;
+
+ for ( n = 0; n < face->num_names; n++ )
+ {
+ TT_Name name = face->name_table.names + n;
+
+
+ if ( name->nameID == 6 && name->stringLength > 0 )
+ {
+ if ( IS_WIN( name ) )
+ found_win = n;
+
+ if ( IS_APPLE( name ) )
+ found_apple = n;
}
}
- Exit:
+ /* prefer Windows entries over Apple */
+ if ( found_win != -1 )
+ result = get_win_string( face->root.memory,
+ face->name_table.stream,
+ face->name_table.names + found_win );
+ else if ( found_apple != -1 )
+ result = get_apple_string( face->root.memory,
+ face->name_table.stream,
+ face->name_table.names + found_apple );
+
face->postscript_name = result;
+
return result;
}