@@ -345,7 +345,8 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
345
345
** specification on which the font is based and the
346
346
** font manufacturer's revision number for the font.
347
347
*/
348
- if ( font->target_type == PS_TYPE_42 )
348
+ if ( font->target_type == PS_TYPE_42 ||
349
+ font->target_type == PS_TYPE_42_3_HYBRID)
349
350
{
350
351
stream.printf (" %%!PS-TrueTypeFont-%d.%d-%d.%d\n " ,
351
352
font->TTVersion .whole , font->TTVersion .fraction ,
@@ -368,11 +369,13 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
368
369
/* We created this file. */
369
370
if ( font->target_type == PS_TYPE_42 )
370
371
stream.putline (" %%Creator: Converted from TrueType to type 42 by PPR" );
372
+ else if (font->target_type == PS_TYPE_42_3_HYBRID)
373
+ stream.putline (" %%Creator: Converted from TypeType to type 42/type 3 hybrid by PPR" );
371
374
else
372
- stream.putline (" %%Creator: Converted from TrueType by PPR" );
375
+ stream.putline (" %%Creator: Converted from TrueType to type 3 by PPR" );
373
376
374
377
/* If VM usage information is available, print it. */
375
- if ( font->target_type == PS_TYPE_42 )
378
+ if ( font->target_type == PS_TYPE_42 || font-> target_type == PS_TYPE_42_3_HYBRID )
376
379
{
377
380
VMMin = (int )getULONG ( font->post_table + 16 );
378
381
VMMax = (int )getULONG ( font->post_table + 20 );
@@ -382,7 +385,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
382
385
383
386
/* Start the dictionary which will eventually */
384
387
/* become the font. */
385
- if ( font->target_type != PS_TYPE_3 )
388
+ if (font->target_type == PS_TYPE_42 )
386
389
{
387
390
stream.putline (" 15 dict begin" );
388
391
}
@@ -403,13 +406,17 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
403
406
stream.printf (" /FontName /%s def\n " ,font->PostName );
404
407
stream.putline (" /PaintType 0 def" );
405
408
406
- if (font->target_type == PS_TYPE_42)
409
+ if (font->target_type == PS_TYPE_42 || font-> target_type == PS_TYPE_42_3_HYBRID )
407
410
stream.putline (" /FontMatrix[1 0 0 1 0 0]def" );
408
411
else
409
412
stream.putline (" /FontMatrix[.001 0 0 .001 0 0]def" );
410
413
411
414
stream.printf (" /FontBBox[%d %d %d %d]def\n " ,font->llx ,font->lly ,font->urx ,font->ury );
412
- stream.printf (" /FontType %d def\n " , font->target_type );
415
+ if (font->target_type == PS_TYPE_42 || font->target_type == PS_TYPE_42_3_HYBRID) {
416
+ stream.printf (" /FontType 42 def\n " , font->target_type );
417
+ } else {
418
+ stream.printf (" /FontType 3 def\n " , font->target_type );
419
+ }
413
420
} /* end of ttfont_header() */
414
421
415
422
/* -------------------------------------------------------------
@@ -420,7 +427,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
420
427
-------------------------------------------------------------*/
421
428
void ttfont_encoding (TTStreamWriter& stream, struct TTFONT *font, std::vector<int >& glyph_ids, font_type_enum target_type)
422
429
{
423
- if (target_type == PS_TYPE_3) {
430
+ if (target_type == PS_TYPE_3 || target_type == PS_TYPE_42_3_HYBRID ) {
424
431
stream.printf (" /Encoding [ " );
425
432
426
433
for (std::vector<int >::const_iterator i = glyph_ids.begin ();
@@ -605,13 +612,16 @@ void sfnts_glyf_table(TTStreamWriter& stream, struct TTFONT *font, ULONG oldoffs
605
612
int c;
606
613
ULONG total=0 ; /* running total of bytes written to table */
607
614
int x;
615
+ bool loca_is_local=false ;
608
616
609
617
#ifdef DEBUG_TRUETYPE
610
618
debug (" sfnts_glyf_table(font,%d)" , (int )correct_total_length);
611
619
#endif
612
620
613
- assert (font->loca_table == NULL );
614
- font->loca_table = GetTable (font," loca" );
621
+ if (font->loca_table == NULL ) {
622
+ font->loca_table = GetTable (font," loca" );
623
+ loca_is_local = true ;
624
+ }
615
625
616
626
/* Seek to proper position in the file. */
617
627
fseek ( font->file , oldoffset, SEEK_SET );
@@ -661,8 +671,10 @@ void sfnts_glyf_table(TTStreamWriter& stream, struct TTFONT *font, ULONG oldoffs
661
671
662
672
}
663
673
664
- free (font->loca_table );
665
- font->loca_table = NULL ;
674
+ if (loca_is_local) {
675
+ free (font->loca_table );
676
+ font->loca_table = NULL ;
677
+ }
666
678
667
679
/* Pad out to full length from table directory */
668
680
while ( total < correct_total_length )
@@ -953,9 +965,9 @@ void ttfont_CharStrings(TTStreamWriter& stream, struct TTFONT *font, std::vector
953
965
954
966
/* Emmit one key-value pair for each glyph. */
955
967
for (std::vector<int >::const_iterator i = glyph_ids.begin ();
956
- i != glyph_ids.end (); ++i)
957
- {
958
- if (font-> target_type == PS_TYPE_42) /* type 42 */
968
+ i != glyph_ids.end (); ++i) {
969
+ if ((font-> target_type == PS_TYPE_42 || font-> target_type == PS_TYPE_42_3_HYBRID)
970
+ && *i < 256 ) /* type 42 */
959
971
{
960
972
stream.printf (" /%s %d def\n " ,ttfont_CharStrings_getname (font, *i), *i);
961
973
}
@@ -980,7 +992,7 @@ void ttfont_trailer(TTStreamWriter& stream, struct TTFONT *font)
980
992
{
981
993
/* If we are generating a type 3 font, we need to provide */
982
994
/* a BuildGlyph and BuildChar proceedures. */
983
- if ( font->target_type == PS_TYPE_3 )
995
+ if (font->target_type == PS_TYPE_3 || font-> target_type == PS_TYPE_42_3_HYBRID )
984
996
{
985
997
stream.put_char (' \n ' );
986
998
@@ -1010,7 +1022,7 @@ void ttfont_trailer(TTStreamWriter& stream, struct TTFONT *font)
1010
1022
/* I found out how to do this by examining a TrueType font */
1011
1023
/* generated by a Macintosh. That is where the TrueType interpreter */
1012
1024
/* setup instructions and part of BuildGlyph came from. */
1013
- else if ( font->target_type == PS_TYPE_42 )
1025
+ if ( font->target_type == PS_TYPE_42 || font-> target_type == PS_TYPE_42_3_HYBRID )
1014
1026
{
1015
1027
stream.put_char (' \n ' );
1016
1028
@@ -1111,6 +1123,28 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
1111
1123
/* Decide what type of PostScript font we will be generating. */
1112
1124
font.target_type = target_type;
1113
1125
1126
+ if (font.target_type == PS_TYPE_42) {
1127
+ bool has_low = false ;
1128
+ bool has_high = false ;
1129
+
1130
+ for (std::vector<int >::const_iterator i = glyph_ids.begin ();
1131
+ i != glyph_ids.end (); ++i) {
1132
+ if (*i > 255 ) {
1133
+ has_high = true ;
1134
+ if (has_low) break ;
1135
+ } else {
1136
+ has_low = true ;
1137
+ if (has_high) break ;
1138
+ }
1139
+ }
1140
+
1141
+ if (has_high && has_low) {
1142
+ font.target_type = PS_TYPE_42_3_HYBRID;
1143
+ } else if (has_high && !has_low) {
1144
+ font.target_type = PS_TYPE_3;
1145
+ }
1146
+ }
1147
+
1114
1148
/* Save the file name for error messages. */
1115
1149
font.filename =filename;
1116
1150
@@ -1177,7 +1211,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
1177
1211
/* If we are generating a Type 3 font, we will need to */
1178
1212
/* have the 'loca' and 'glyf' tables arround while */
1179
1213
/* we are generating the CharStrings. */
1180
- if (font.target_type == PS_TYPE_3 || font.target_type == PDF_TYPE_3)
1214
+ if (font.target_type == PS_TYPE_3 || font.target_type == PDF_TYPE_3 ||
1215
+ font.target_type == PS_TYPE_42_3_HYBRID)
1181
1216
{
1182
1217
BYTE *ptr; /* We need only one value */
1183
1218
ptr = GetTable (&font, " hhea" );
@@ -1198,7 +1233,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
1198
1233
for (int x = 0 ; x < font.numGlyphs ; ++x) {
1199
1234
glyph_ids.push_back (x);
1200
1235
}
1201
- } else if (font.target_type == PS_TYPE_3) {
1236
+ } else if (font.target_type == PS_TYPE_3 ||
1237
+ font.target_type == PS_TYPE_42_3_HYBRID) {
1202
1238
ttfont_add_glyph_dependencies (&font, glyph_ids);
1203
1239
}
1204
1240
@@ -1222,7 +1258,8 @@ void insert_ttfont(const char *filename, TTStreamWriter& stream,
1222
1258
1223
1259
/* If we are generating a type 42 font, */
1224
1260
/* emmit the sfnts array. */
1225
- if ( font.target_type == PS_TYPE_42 )
1261
+ if (font.target_type == PS_TYPE_42 ||
1262
+ font.target_type == PS_TYPE_42_3_HYBRID)
1226
1263
ttfont_sfnts (stream, &font);
1227
1264
1228
1265
/* Emmit the CharStrings array. */
0 commit comments