int _ExportEPS(FILE *eps,SplineChar *sc, int layer, int preview) { DBounds b; time_t now; struct tm *tm; int ret; char oldloc[24]; const char *author = GetAuthor(); strcpy( oldloc,setlocale(LC_NUMERIC,NULL) ); setlocale(LC_NUMERIC,"C"); fprintf( eps, "%%!PS-Adobe-3.0 EPSF-3.0\n" ); SplineCharLayerFindBounds(sc,layer,&b); fprintf( eps, "%%%%BoundingBox: %g %g %g %g\n", (double) b.minx, (double) b.miny, (double) b.maxx, (double) b.maxy ); fprintf( eps, "%%%%Pages: 0\n" ); fprintf( eps, "%%%%Title: %s from %s\n", sc->name, sc->parent->fontname ); fprintf( eps, "%%%%Creator: FontForge\n" ); if ( author!=NULL ) fprintf( eps, "%%%%Author: %s\n", author); time(&now); tm = localtime(&now); fprintf( eps, "%%%%CreationDate: %d:%02d %d-%d-%d\n", tm->tm_hour, tm->tm_min, tm->tm_mday, tm->tm_mon+1, 1900+tm->tm_year ); if ( sc->parent->multilayer ) { int ly, had_grad=0, had_pat=0; for ( ly=ly_fore; ly<sc->layer_cnt; ++ly ) { if ( sc->layers[ly].fill_brush.gradient!=NULL || sc->layers[ly].stroke_pen.brush.gradient!=NULL ) { had_grad = true; break; } if ( sc->layers[ly].fill_brush.gradient!=NULL || sc->layers[ly].stroke_pen.brush.gradient!=NULL ) had_pat = true; } if ( had_grad ) fprintf( eps, "%%%%LanguageLevel: 3\n" ); else if ( had_pat ) fprintf( eps, "%%%%LanguageLevel: 2\n" ); } fprintf( eps, "%%%%EndComments\n" ); if ( preview ) EpsGeneratePreview(eps,sc,layer,&b); fprintf( eps, "%%%%EndProlog\n" ); fprintf( eps, "%%%%Page \"%s\" 1\n", sc->name ); fprintf( eps, "gsave newpath\n" ); SC_PSDump((void (*)(int,void *)) fputc,eps,sc,true,false,layer); if ( sc->parent->multilayer ) fprintf( eps, "grestore\n" ); else if ( sc->parent->strokedfont ) fprintf( eps, "%g setlinewidth stroke grestore\n", (double) sc->parent->strokewidth ); else fprintf( eps, "fill grestore\n" ); fprintf( eps, "%%%%EOF\n" ); ret = !ferror(eps); setlocale(LC_NUMERIC,oldloc); return( ret ); }
int _ExportPDF(FILE *pdf,SplineChar *sc,int layer) { /* TODO: Note, maybe this routine can be combined with print.c dump_pdfprologue() */ DBounds b; time_t now; struct tm *tm; int ret; char oldloc[24]; int _objlocs[8], xrefloc, streamstart, streamlength, resid = 0, nextobj; int *objlocs = _objlocs; const char *author = GetAuthor(); int i; SFUntickAll(sc->parent); locale_t tmplocale; locale_t oldlocale; // Declare temporary locale storage. switch_to_c_locale(&tmplocale, &oldlocale); // Switch to the C locale temporarily and cache the old locale. fprintf( pdf, "%%PDF-1.4\n%%\201\342\202\203\n" ); /* Header comment + binary comment */ /* Every document contains a catalog which points to a page tree, which */ /* in our case, points to a single page */ objlocs[1] = ftell(pdf); fprintf( pdf, "1 0 obj\n << /Type /Catalog\n /Pages 2 0 R\n /PageMode /UseNone\n >>\nendobj\n" ); objlocs[2] = ftell(pdf); fprintf( pdf, "2 0 obj\n << /Type /Pages\n /Kids [ 3 0 R ]\n /Count 1\n >>\nendobj\n" ); /* And our single page points to its contents */ objlocs[3] = ftell(pdf); fprintf( pdf, "3 0 obj\n" ); fprintf( pdf, " << /Type /Page\n" ); fprintf( pdf, " /Parent 2 0 R\n" ); fprintf( pdf, " /Resources " ); if ( sc->parent->multilayer ) { resid = ftell(pdf); fprintf( pdf, "000000 0 R\n" ); } else fprintf( pdf, "<< >>\n" ); SplineCharLayerFindBounds(sc,layer,&b); fprintf( pdf, " /MediaBox [%g %g %g %g]\n", (double) b.minx, (double) b.miny, (double) b.maxx, (double) b.maxy ); fprintf( pdf, " /Contents 4 0 R\n" ); fprintf( pdf, " >>\n" ); fprintf( pdf, "endobj\n" ); /* And the contents are the interesting stuff */ objlocs[4] = ftell(pdf); fprintf( pdf, "4 0 obj\n" ); fprintf( pdf, " << /Length 5 0 R >> \n" ); fprintf( pdf, " stream \n" ); streamstart = ftell(pdf); SC_PSDump((void (*)(int,void *)) fputc,pdf,sc,true,true,layer); if ( sc->parent->multilayer ) /* Already filled or stroked */; else if ( sc->parent->strokedfont ) fprintf( pdf, "%g w S\n", (double) sc->parent->strokewidth ); else fprintf( pdf, "f\n" ); streamlength = ftell(pdf)-streamstart; fprintf( pdf, " endstream\n" ); fprintf( pdf, "endobj\n" ); objlocs[5] = ftell(pdf); fprintf( pdf, "5 0 obj\n" ); fprintf( pdf, " %d\n", (int) streamlength ); fprintf( pdf, "endobj\n" ); /* Optional Info dict */ objlocs[6] = ftell(pdf); fprintf( pdf, "6 0 obj\n" ); fprintf( pdf, " <<\n" ); fprintf( pdf, " /Creator (FontForge)\n" ); time(&now); tm = localtime(&now); fprintf( pdf, " /CreationDate (D:%04d%02d%02d%02d%02d%02d", 1900+tm->tm_year, tm->tm_mon+1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec ); #ifdef _NO_TZSET fprintf( pdf, "Z)\n" ); #else tzset(); if ( timezone==0 ) fprintf( pdf, "Z)\n" ); else { if ( timezone<0 ) /* fprintf bug - this is a kludge to print +/- in front of a %02d-padded value */ fprintf( pdf, "-" ); else fprintf( pdf, "+" ); fprintf( pdf, "%02d'%02d')\n", (int)(timezone/3600),(int)(timezone/60-(timezone/3600)*60) ); } #endif fprintf( pdf, " /Title (%s from %s)\n", sc->name, sc->parent->fontname ); if ( author!=NULL ) fprintf( pdf, " /Author (%s)\n", author ); fprintf( pdf, " >>\n" ); nextobj = 7; if ( sc->parent->multilayer ) { PI pi; int resobj; memset(&pi,0,sizeof(pi)); pi.out = pdf; pi.max_object = 100; pi.object_offsets = malloc(pi.max_object*sizeof(int)); memcpy(pi.object_offsets,objlocs,nextobj*sizeof(int)); pi.next_object = nextobj; resobj = PdfDumpGlyphResources(&pi,sc); nextobj = pi.next_object; objlocs = pi.object_offsets; fseek(pdf,resid,SEEK_SET); fprintf(pdf,"%06d", resobj ); fseek(pdf,0,SEEK_END); } xrefloc = ftell(pdf); fprintf( pdf, "xref\n" ); fprintf( pdf, " 0 %d\n", nextobj ); fprintf( pdf, "0000000000 65535 f \n" ); for ( i=1; i<nextobj; ++i ) fprintf( pdf, "%010d %05d n \n", (int) objlocs[i], 0 ); fprintf( pdf, "trailer\n" ); fprintf( pdf, " <<\n" ); fprintf( pdf, " /Size %d\n", nextobj ); fprintf( pdf, " /Root 1 0 R\n" ); fprintf( pdf, " /Info 6 0 R\n" ); fprintf( pdf, " >>\n" ); fprintf( pdf, "startxref\n" ); fprintf( pdf, "%d\n", (int) xrefloc ); fprintf( pdf, "%%%%EOF\n" ); if ( objlocs!=_objlocs ) free(objlocs); ret = !ferror(pdf); switch_to_old_locale(&tmplocale, &oldlocale); // Switch to the cached locale. return( ret ); }