Skip to content

Commit 6416d2f

Browse files
committed
Merged revisions 8822 via svnmerge from
https://matplotlib.svn.sf.net/svnroot/matplotlib/branches/v1_0_maint ........ r8822 | mdboom | 2010-12-10 09:01:00 -0500 (Fri, 10 Dec 2010) | 2 lines Handle Unicode characters in Postscript Type 42 fonts by creating hybrid Type 42/Type 3 fonts. ........ svn path=/trunk/matplotlib/; revision=8823
1 parent 7c7d909 commit 6416d2f

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

ttconv/pprdrv.h

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class TTException {
9494
enum font_type_enum {
9595
PS_TYPE_3 = 3,
9696
PS_TYPE_42 = 42,
97+
PS_TYPE_42_3_HYBRID = 43,
9798
PDF_TYPE_3 = -3
9899
};
99100

ttconv/pprdrv_tt.cpp

+56-19
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
347347
** specification on which the font is based and the
348348
** font manufacturer's revision number for the font.
349349
*/
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)
351352
{
352353
stream.printf("%%!PS-TrueTypeFont-%d.%d-%d.%d\n",
353354
font->TTVersion.whole, font->TTVersion.fraction,
@@ -370,11 +371,13 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
370371
/* We created this file. */
371372
if( font->target_type == PS_TYPE_42 )
372373
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");
373376
else
374-
stream.putline("%%Creator: Converted from TrueType by PPR");
377+
stream.putline("%%Creator: Converted from TrueType to type 3 by PPR");
375378

376379
/* 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)
378381
{
379382
VMMin = (int)getULONG( font->post_table + 16 );
380383
VMMax = (int)getULONG( font->post_table + 20 );
@@ -384,7 +387,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
384387

385388
/* Start the dictionary which will eventually */
386389
/* become the font. */
387-
if( font->target_type != PS_TYPE_3 )
390+
if(font->target_type == PS_TYPE_42)
388391
{
389392
stream.putline("15 dict begin");
390393
}
@@ -405,13 +408,17 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
405408
stream.printf("/FontName /%s def\n",font->PostName);
406409
stream.putline("/PaintType 0 def");
407410

408-
if(font->target_type == PS_TYPE_42)
411+
if(font->target_type == PS_TYPE_42 || font->target_type == PS_TYPE_42_3_HYBRID)
409412
stream.putline("/FontMatrix[1 0 0 1 0 0]def");
410413
else
411414
stream.putline("/FontMatrix[.001 0 0 .001 0 0]def");
412415

413416
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+
}
415422
} /* end of ttfont_header() */
416423

417424
/*-------------------------------------------------------------
@@ -422,7 +429,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
422429
-------------------------------------------------------------*/
423430
void ttfont_encoding(TTStreamWriter& stream, struct TTFONT *font, std::vector<int>& glyph_ids, font_type_enum target_type)
424431
{
425-
if (target_type == PS_TYPE_3) {
432+
if (target_type == PS_TYPE_3 || target_type == PS_TYPE_42_3_HYBRID) {
426433
stream.printf("/Encoding [ ");
427434

428435
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
607614
int c;
608615
ULONG total=0; /* running total of bytes written to table */
609616
int x;
617+
bool loca_is_local=false;
610618

611619
#ifdef DEBUG_TRUETYPE
612620
debug("sfnts_glyf_table(font,%d)", (int)correct_total_length);
613621
#endif
614622

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+
}
617627

618628
/* Seek to proper position in the file. */
619629
fseek( font->file, oldoffset, SEEK_SET );
@@ -663,8 +673,10 @@ void sfnts_glyf_table(TTStreamWriter& stream, struct TTFONT *font, ULONG oldoffs
663673

664674
}
665675

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+
}
668680

669681
/* Pad out to full length from table directory */
670682
while( total < correct_total_length )
@@ -955,9 +967,9 @@ void ttfont_CharStrings(TTStreamWriter& stream, struct TTFONT *font, std::vector
955967

956968
/* Emmit one key-value pair for each glyph. */
957969
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 */
961973
{
962974
stream.printf("/%s %d def\n",ttfont_CharStrings_getname(font, *i), *i);
963975
}
@@ -982,7 +994,7 @@ void ttfont_trailer(TTStreamWriter& stream, struct TTFONT *font)
982994
{
983995
/* If we are generating a type 3 font, we need to provide */
984996
/* 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)
986998
{
987999
stream.put_char('\n');
9881000

@@ -1012,7 +1024,7 @@ void ttfont_trailer(TTStreamWriter& stream, struct TTFONT *font)
10121024
/* I found out how to do this by examining a TrueType font */
10131025
/* generated by a Macintosh. That is where the TrueType interpreter */
10141026
/* 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)
10161028
{
10171029
stream.put_char('\n');
10181030

@@ -1113,6 +1125,28 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
11131125
/* Decide what type of PostScript font we will be generating. */
11141126
font.target_type = target_type;
11151127

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+
11161150
/* Save the file name for error messages. */
11171151
font.filename=filename;
11181152

@@ -1179,7 +1213,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
11791213
/* If we are generating a Type 3 font, we will need to */
11801214
/* have the 'loca' and 'glyf' tables arround while */
11811215
/* 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)
11831218
{
11841219
BYTE *ptr; /* We need only one value */
11851220
ptr = GetTable(&font, "hhea");
@@ -1200,7 +1235,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
12001235
for (int x = 0; x < font.numGlyphs; ++x) {
12011236
glyph_ids.push_back(x);
12021237
}
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) {
12041240
ttfont_add_glyph_dependencies(&font, glyph_ids);
12051241
}
12061242

@@ -1224,7 +1260,8 @@ void insert_ttfont(const char *filename, TTStreamWriter& stream,
12241260

12251261
/* If we are generating a type 42 font, */
12261262
/* 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)
12281265
ttfont_sfnts(stream, &font);
12291266

12301267
/* Emmit the CharStrings array. */

ttconv/pprdrv_tt2.cpp

+10-1
Original file line numberDiff line numberDiff line change
@@ -711,10 +711,15 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
711711
stream.printf("%d 0 %d %d %d %d d1\n",
712712
topost(advance_width),
713713
topost(llx), topost(lly), topost(urx), topost(ury) );
714-
} else
714+
} else if (font->target_type == PS_TYPE_42_3_HYBRID) {
715+
stream.printf("pop gsave .001 .001 scale %d 0 %d %d %d %d setcachedevice\n",
716+
topost(advance_width),
717+
topost(llx), topost(lly), topost(urx), topost(ury) );
718+
} else {
715719
stream.printf("%d 0 %d %d %d %d _sc\n",
716720
topost(advance_width),
717721
topost(llx), topost(lly), topost(urx), topost(ury) );
722+
}
718723

719724
/* If it is a simple glyph, convert it, */
720725
/* otherwise, close the stack business. */
@@ -727,6 +732,10 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
727732
do_composite(stream, font, glyph);
728733
}
729734

735+
if (font->target_type == PS_TYPE_42_3_HYBRID) {
736+
stream.printf("\ngrestore\n");
737+
}
738+
730739
stack_end(stream);
731740
}
732741

0 commit comments

Comments
 (0)