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