|
31 | 31 | #include "pprdrv.h" |
32 | 32 | #include "truetype.h" |
33 | 33 | #include <sstream> |
| 34 | +#include <Python.h> |
34 | 35 |
|
35 | 36 | /*========================================================================== |
36 | 37 | ** Convert the indicated Truetype font file to a type 42 or type 3 |
@@ -166,6 +167,13 @@ BYTE *GetTable(struct TTFONT *font, const char *name) |
166 | 167 |
|
167 | 168 | } /* end of GetTable() */ |
168 | 169 |
|
| 170 | +static void utf16be_to_ascii(char *dst, char *src, size_t length) { |
| 171 | + ++src; |
| 172 | + for (; *src != 0 && length; dst++, src += 2, --length) { |
| 173 | + *dst = *src; |
| 174 | + } |
| 175 | +} |
| 176 | + |
169 | 177 | /*-------------------------------------------------------------------- |
170 | 178 | ** Load the 'name' table, get information from it, |
171 | 179 | ** and store that information in the font structure. |
@@ -311,6 +319,21 @@ void Read_name(struct TTFONT *font) |
311 | 319 | font->PostName[length]=(char)NULL; |
312 | 320 | replace_newlines_with_spaces(font->PostName); |
313 | 321 |
|
| 322 | +#ifdef DEBUG_TRUETYPE |
| 323 | + debug("font->PostName=\"%s\"",font->PostName); |
| 324 | +#endif |
| 325 | + continue; |
| 326 | + } |
| 327 | + |
| 328 | + /* Microsoft-format PostScript name */ |
| 329 | + if ( platform == 3 && nameid == 6 ) |
| 330 | + { |
| 331 | + free(font->PostName); |
| 332 | + font->PostName = (char*)calloc(sizeof(char),length+1); |
| 333 | + utf16be_to_ascii(font->PostName, (char *)strings+offset, length); |
| 334 | + font->PostName[length/2]=(char)NULL; |
| 335 | + replace_newlines_with_spaces(font->PostName); |
| 336 | + |
314 | 337 | #ifdef DEBUG_TRUETYPE |
315 | 338 | debug("font->PostName=\"%s\"",font->PostName); |
316 | 339 | #endif |
@@ -967,6 +990,20 @@ const char *ttfont_CharStrings_getname(struct TTFONT *font, int charindex) |
967 | 990 | char *ptr; |
968 | 991 | ULONG len; |
969 | 992 |
|
| 993 | + Fixed post_format; |
| 994 | + |
| 995 | + /* The 'post' table format number. */ |
| 996 | + post_format = getFixed( font->post_table ); |
| 997 | + |
| 998 | + if ( post_format.whole != 2 || post_format.fraction != 0 ) |
| 999 | + { |
| 1000 | + /* We don't have a glyph name table, so generate a name. |
| 1001 | + This generated name must match exactly the name that is |
| 1002 | + generated by FT2Font in get_glyph_name */ |
| 1003 | + PyOS_snprintf(temp, 80, "uni%08x", charindex); |
| 1004 | + return temp; |
| 1005 | + } |
| 1006 | + |
970 | 1007 | GlyphIndex = (int)getUSHORT( font->post_table + 34 + (charindex * 2) ); |
971 | 1008 |
|
972 | 1009 | if ( GlyphIndex <= 257 ) /* If a standard Apple name, */ |
@@ -1011,11 +1048,6 @@ void ttfont_CharStrings(TTStreamWriter& stream, struct TTFONT *font, std::vector |
1011 | 1048 | /* The 'post' table format number. */ |
1012 | 1049 | post_format = getFixed( font->post_table ); |
1013 | 1050 |
|
1014 | | - if ( post_format.whole != 2 || post_format.fraction != 0 ) |
1015 | | - { |
1016 | | - throw TTException("TrueType fontdoes not have a format 2.0 'post' table"); |
1017 | | - } |
1018 | | - |
1019 | 1051 | /* Emmit the start of the PostScript code to define the dictionary. */ |
1020 | 1052 | stream.printf("/CharStrings %d dict dup begin\n", glyph_ids.size()); |
1021 | 1053 |
|
|
0 commit comments