+
+ int num = font->num_glyphs<256-32?font->num_glyphs:256-32;
+ if(type3) {
+ int fontid = 0;
+ if(!gfxfontlist_hasfont(i->fontlist, font)) {
+
+ static int fontnr = 1;
+ char fontname[32];
+ sprintf(fontname, "font%d", fontnr++);
+ int l = strlen(fontname);
+ char fontname2[64];
+ int t;
+ for(t=0;t<l+1;t++) {
+ fontname2[t*2+0] = fontname[t];
+ fontname2[t*2+1] = 0;
+ }
+
+ PDF_begin_font(i->p, fontname2, l*2, 1.0, 0.0, 0.0, -1.0, 0.0, 0.0, "");
+ for(t=0;t<num;t++) {
+ gfxglyph_t*g = &font->glyphs[t];
+ gfxbbox_t bbox = gfxline_getbbox(g->line);
+ char name[32];
+ sprintf(name, "chr%d", t+32);
+ PDF_encoding_set_char(i->p, fontname, t+32, name, 0);
+ PDF_begin_glyph(i->p, name, g->advance, bbox.xmin/64.0, bbox.ymin/64.0, bbox.xmax/64.0, bbox.ymax/64.0);
+ if(mkline(g->line, i->p, 0, 0, 1.0/64.0, 1))
+ PDF_fill(i->p);
+ PDF_end_glyph(i->p);
+ }
+ PDF_end_font(i->p);
+ fontid = PDF_load_font(i->p, fontname2, l*2, fontname, "");
+
+ i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid);
+ }
+ } else if(ttf) {
+ int fontid = 0;
+ if(!gfxfontlist_hasfont(i->fontlist, font)) {
+ char fontname[32],filename[32],fontname2[64];
+ static int fontnr = 1;
+ sprintf(fontname, "font%d", fontnr);
+ sprintf(filename, "font%d.ttf", fontnr);
+ fontnr++;
+ const char*old_id = font->id;
+ font->id = fontname;
+ int t;
+ for(t=0;t<num;t++) {
+ font->glyphs[t].unicode = 32+t;
+ }
+ font->max_unicode = 0;
+ font->unicode2glyph = 0;
+ gfxfont_save(font, filename);
+ font->id=old_id;
+
+#ifdef RUN_TTX
+ /* for testing the generated fonts: run everything through ttx (fonttools) */
+ char cmd[256];
+ sprintf(cmd, "mv %s.ttf test.ttf", fontname);system(cmd);
+ system("rm -f test.ttx");
+ if(system("ttx test.ttf")&0xff00) exit(1);
+ sprintf(cmd, "mv test.ttf %s.old.ttf", fontname, fontname);system(cmd);
+ sprintf(cmd, "ttx test.ttx;mv test.ttf %s.ttf", fontname);system(cmd);
+ sprintf(cmd, "rm -f test.ttx");system(cmd);
+#endif
+
+ int l = strlen(fontname);
+ for(t=0;t<l+1;t++) {
+ fontname2[t*2+0] = fontname[t];
+ fontname2[t*2+1] = 0;
+ }
+
+ fontid = PDF_load_font(i->p, fontname2, l*2, "host", "embedding=true");
+ i->fontlist = gfxfontlist_addfont2(i->fontlist, font, (void*)(ptroff_t)fontid);
+ unlink(filename);
+ }
+ }