Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6de9019

Browse filesBrowse files
committed
Handle Unicode characters in Postscript Type 42 fonts by creating hybrid Type 42/Type 3 fonts.
svn path=/branches/v1_0_maint/; revision=8822
1 parent 632220d commit 6de9019
Copy full SHA for 6de9019

File tree

Expand file treeCollapse file tree

3 files changed

+68
-21
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+68
-21
lines changed

‎ttconv/pprdrv.h

Copy file name to clipboardExpand all lines: ttconv/pprdrv.h
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ class TTException {
8484
** code you want to have included.
8585
*/
8686
#ifdef DEBUG
87-
#define DEBUG_TRUETYPE /* truetype fonts, conversion to Postscript */
87+
#define DEBUG_TRUETYPE /* truetype fonts, conversion to Postscript */
8888
#endif
8989

9090
/* Do not change anything below this line. */
9191

9292
enum font_type_enum {
9393
PS_TYPE_3 = 3,
9494
PS_TYPE_42 = 42,
95+
PS_TYPE_42_3_HYBRID = 43,
9596
PDF_TYPE_3 = -3
9697
};
9798

‎ttconv/pprdrv_tt.cpp

Copy file name to clipboardExpand all lines: ttconv/pprdrv_tt.cpp
+56-19Lines changed: 56 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
345345
** specification on which the font is based and the
346346
** font manufacturer's revision number for the font.
347347
*/
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)
349350
{
350351
stream.printf("%%!PS-TrueTypeFont-%d.%d-%d.%d\n",
351352
font->TTVersion.whole, font->TTVersion.fraction,
@@ -368,11 +369,13 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
368369
/* We created this file. */
369370
if( font->target_type == PS_TYPE_42 )
370371
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");
371374
else
372-
stream.putline("%%Creator: Converted from TrueType by PPR");
375+
stream.putline("%%Creator: Converted from TrueType to type 3 by PPR");
373376

374377
/* 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)
376379
{
377380
VMMin = (int)getULONG( font->post_table + 16 );
378381
VMMax = (int)getULONG( font->post_table + 20 );
@@ -382,7 +385,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
382385

383386
/* Start the dictionary which will eventually */
384387
/* become the font. */
385-
if( font->target_type != PS_TYPE_3 )
388+
if(font->target_type == PS_TYPE_42)
386389
{
387390
stream.putline("15 dict begin");
388391
}
@@ -403,13 +406,17 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
403406
stream.printf("/FontName /%s def\n",font->PostName);
404407
stream.putline("/PaintType 0 def");
405408

406-
if(font->target_type == PS_TYPE_42)
409+
if(font->target_type == PS_TYPE_42 || font->target_type == PS_TYPE_42_3_HYBRID)
407410
stream.putline("/FontMatrix[1 0 0 1 0 0]def");
408411
else
409412
stream.putline("/FontMatrix[.001 0 0 .001 0 0]def");
410413

411414
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+
}
413420
} /* end of ttfont_header() */
414421

415422
/*-------------------------------------------------------------
@@ -420,7 +427,7 @@ void ttfont_header(TTStreamWriter& stream, struct TTFONT *font)
420427
-------------------------------------------------------------*/
421428
void ttfont_encoding(TTStreamWriter& stream, struct TTFONT *font, std::vector<int>& glyph_ids, font_type_enum target_type)
422429
{
423-
if (target_type == PS_TYPE_3) {
430+
if (target_type == PS_TYPE_3 || target_type == PS_TYPE_42_3_HYBRID) {
424431
stream.printf("/Encoding [ ");
425432

426433
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
605612
int c;
606613
ULONG total=0; /* running total of bytes written to table */
607614
int x;
615+
bool loca_is_local=false;
608616

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

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

616626
/* Seek to proper position in the file. */
617627
fseek( font->file, oldoffset, SEEK_SET );
@@ -661,8 +671,10 @@ void sfnts_glyf_table(TTStreamWriter& stream, struct TTFONT *font, ULONG oldoffs
661671

662672
}
663673

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

667679
/* Pad out to full length from table directory */
668680
while( total < correct_total_length )
@@ -953,9 +965,9 @@ void ttfont_CharStrings(TTStreamWriter& stream, struct TTFONT *font, std::vector
953965

954966
/* Emmit one key-value pair for each glyph. */
955967
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 */
959971
{
960972
stream.printf("/%s %d def\n",ttfont_CharStrings_getname(font, *i), *i);
961973
}
@@ -980,7 +992,7 @@ void ttfont_trailer(TTStreamWriter& stream, struct TTFONT *font)
980992
{
981993
/* If we are generating a type 3 font, we need to provide */
982994
/* 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)
984996
{
985997
stream.put_char('\n');
986998

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

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

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

@@ -1177,7 +1211,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
11771211
/* If we are generating a Type 3 font, we will need to */
11781212
/* have the 'loca' and 'glyf' tables arround while */
11791213
/* 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)
11811216
{
11821217
BYTE *ptr; /* We need only one value */
11831218
ptr = GetTable(&font, "hhea");
@@ -1198,7 +1233,8 @@ void read_font(const char *filename, font_type_enum target_type, std::vector<int
11981233
for (int x = 0; x < font.numGlyphs; ++x) {
11991234
glyph_ids.push_back(x);
12001235
}
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) {
12021238
ttfont_add_glyph_dependencies(&font, glyph_ids);
12031239
}
12041240

@@ -1222,7 +1258,8 @@ void insert_ttfont(const char *filename, TTStreamWriter& stream,
12221258

12231259
/* If we are generating a type 42 font, */
12241260
/* 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)
12261263
ttfont_sfnts(stream, &font);
12271264

12281265
/* Emmit the CharStrings array. */

‎ttconv/pprdrv_tt2.cpp

Copy file name to clipboardExpand all lines: ttconv/pprdrv_tt2.cpp
+10-1Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,15 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
709709
stream.printf("%d 0 %d %d %d %d d1\n",
710710
topost(advance_width),
711711
topost(llx), topost(lly), topost(urx), topost(ury) );
712-
} else
712+
} else if (font->target_type == PS_TYPE_42_3_HYBRID) {
713+
stream.printf("pop gsave .001 .001 scale %d 0 %d %d %d %d setcachedevice\n",
714+
topost(advance_width),
715+
topost(llx), topost(lly), topost(urx), topost(ury) );
716+
} else {
713717
stream.printf("%d 0 %d %d %d %d _sc\n",
714718
topost(advance_width),
715719
topost(llx), topost(lly), topost(urx), topost(ury) );
720+
}
716721

717722
/* If it is a simple glyph, convert it, */
718723
/* otherwise, close the stack business. */
@@ -725,6 +730,10 @@ GlyphToType3::GlyphToType3(TTStreamWriter& stream, struct TTFONT *font, int char
725730
do_composite(stream, font, glyph);
726731
}
727732

733+
if (font->target_type == PS_TYPE_42_3_HYBRID) {
734+
stream.printf("\ngrestore\n");
735+
}
736+
728737
stack_end(stream);
729738
}
730739

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.