X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/halibut/blobdiff_plain/7d7f8de9b0c38fc510a09b62e3bdf7574f06592f..51d05cd0a6de05c0adc8986e1d534e426d6f582c:/bk_ps.c diff --git a/bk_ps.c b/bk_ps.c index 46652e9..95c0451 100644 --- a/bk_ps.c +++ b/bk_ps.c @@ -13,7 +13,6 @@ #define PS_MAXWIDTH 255 static void ps_comment(FILE *fp, char const *leader, word *words); -static void ps_token(FILE *fp, int *cc, char const *fmt, ...); static void ps_string_len(FILE *fp, int *cc, char const *str, int len); static void ps_string(FILE *fp, int *cc, char const *str); @@ -49,7 +48,10 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, } } - fp = fopen(filename, "w"); + if (!strcmp(filename, "-")) + fp = stdout; + else + fp = fopen(filename, "w"); if (!fp) { error(err_cantopenw, filename); return; @@ -68,12 +70,12 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, fprintf(fp, "%%%%DocumentNeededResources:\n"); for (fe = doc->fonts->head; fe; fe = fe->next) /* XXX This may request the same font multiple times. */ - if (!fe->font->info->fp) + if (!fe->font->info->fontfile) fprintf(fp, "%%%%+ font %s\n", fe->font->info->name); fprintf(fp, "%%%%DocumentSuppliedResources: procset Halibut 0 3\n"); for (fe = doc->fonts->head; fe; fe = fe->next) /* XXX This may request the same font multiple times. */ - if (fe->font->info->fp) + if (fe->font->info->fontfile) fprintf(fp, "%%%%+ font %s\n", fe->font->info->name); fprintf(fp, "%%%%EndComments\n"); @@ -198,15 +200,12 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, for (fe = doc->fonts->head; fe; fe = fe->next) { /* XXX This may request the same font multiple times. */ - if (fe->font->info->fp) { - char buf[512]; - size_t len; + if (fe->font->info->fontfile) { fprintf(fp, "%%%%BeginResource: font %s\n", fe->font->info->name); - rewind(fe->font->info->fp); - do { - len = fread(buf, 1, sizeof(buf), fe->font->info->fp); - fwrite(buf, 1, len, fp); - } while (len == sizeof(buf)); + if (fe->font->info->filetype == TYPE1) + pf_writeps(fe->font->info, fp); + else + sfnt_writeps(fe->font->info, fp); fprintf(fp, "%%%%EndResource\n"); } else { fprintf(fp, "%%%%IncludeResource: font %s\n", @@ -230,8 +229,7 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, ps_token(fp, &cc, "{1 index /FID ne {def} {pop pop} ifelse} forall\n"); ps_token(fp, &cc, "/Encoding [\n"); for (i = 0; i < 256; i++) - ps_token(fp, &cc, "/%s", - fe->vector[i] ? fe->vector[i] : ".notdef"); + ps_token(fp, &cc, "/%s", glyph_extern(fe->vector[i])); ps_token(fp, &cc, "] def\n"); ps_token(fp, &cc, "currentdict end\n"); ps_token(fp, &cc, "/fontname-%s exch definefont /%s exch def\n", @@ -309,7 +307,8 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, fprintf(fp, "%%%%EOF\n"); - fclose(fp); + if (fp != stdout) + fclose(fp); sfree(filename); } @@ -356,7 +355,7 @@ static void ps_comment(FILE *fp, char const *leader, word *words) { fprintf(fp, "\n"); } -static void ps_token(FILE *fp, int *cc, char const *fmt, ...) { +void ps_token(FILE *fp, int *cc, char const *fmt, ...) { va_list ap; va_start(ap, fmt);