From 09358aa7f255d1cd8d47dd152c480d4818cb24cf Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 15 Apr 2004 08:50:04 +0000 Subject: [PATCH] Put the document's version IDs into comments in the PS and PDF output files. git-svn-id: svn://svn.tartarus.org/sgt/halibut@4079 cda61777-01e9-0310-a592-d414129be87e --- bk_paper.c | 3 +-- bk_pdf.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- bk_ps.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) diff --git a/bk_paper.c b/bk_paper.c index 68ebc83..2065151 100644 --- a/bk_paper.c +++ b/bk_paper.c @@ -12,8 +12,6 @@ /* * TODO in future work: * - * - include the version IDs. - * * - linearised PDF, perhaps? * * - compression of output files. For the actual text display, @@ -72,6 +70,7 @@ * * a hyphen in a word by itself might prefer to be an en-dash * * (Americans might even want a convenient way to use an * em-dash) + * * DON'T DO ANY OF THE ABOVE WITHIN \c OR \cw! * * substituting `minus' for `hyphen' in the standard encoding * is probably preferable in Courier, though certainly not in * the main text font diff --git a/bk_pdf.c b/bk_pdf.c index b68598c..fe10894 100644 --- a/bk_pdf.c +++ b/bk_pdf.c @@ -62,6 +62,7 @@ static void make_pages_node(object *node, object *parent, page_data *first, page_data *last, object *resources); static int make_outline(object *parent, outline_element *start, int n, int open); +static int pdf_versionid(FILE *fp, word *words); void pdf_backend(paragraph *sourceform, keywordlist *keywords, indexdata *idx, void *vdoc) { @@ -372,9 +373,13 @@ void pdf_backend(paragraph *sourceform, keywordlist *keywords, } /* - * Header + * Header. I'm going to put the version IDs in the header as + * well, simply in PDF comments. */ fileoff = fprintf(fp, "%%PDF-1.3\n"); + for (p = sourceform; p; p = p->next) + if (p->type == para_VersionID) + fileoff += pdf_versionid(fp, p->words); /* * Body @@ -660,3 +665,47 @@ static int make_outline(object *parent, outline_element *items, int n, return totalcount; } + +static int pdf_versionid(FILE *fp, word *words) +{ + int ret; + + ret = fprintf(fp, "%% "); + + for (; words; words = words->next) { + char *text; + int type; + + switch (words->type) { + case word_HyperLink: + case word_HyperEnd: + case word_UpperXref: + case word_LowerXref: + case word_XrefEnd: + case word_IndexRef: + continue; + } + + type = removeattr(words->type); + + switch (type) { + case word_Normal: + text = utoa_dup(words->text); + break; + case word_WhiteSpace: + text = dupstr(" "); + break; + case word_Quote: + text = dupstr("'"); + break; + } + + fputs(text, fp); + ret += strlen(text); + sfree(text); + } + + ret += fprintf(fp, "\n"); + + return ret; +} diff --git a/bk_ps.c b/bk_ps.c index 77b0ab5..c9f4223 100644 --- a/bk_ps.c +++ b/bk_ps.c @@ -6,6 +6,8 @@ #include "halibut.h" #include "paper.h" +static void ps_versionid(FILE *fp, word *words); + paragraph *ps_config_filename(char *filename) { paragraph *p; @@ -74,6 +76,14 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, fprintf(fp, "%%%%EndProlog\n"); fprintf(fp, "%%%%BeginSetup\n"); + + /* + * This is as good a place as any to put version IDs. + */ + for (p = sourceform; p; p = p->next) + if (p->type == para_VersionID) + ps_versionid(fp, p->words); + /* * Re-encode and re-metric the fonts. */ @@ -169,3 +179,42 @@ void ps_backend(paragraph *sourceform, keywordlist *keywords, sfree(filename); } + +static void ps_versionid(FILE *fp, word *words) +{ + fprintf(fp, "%% "); + + for (; words; words = words->next) { + char *text; + int type; + + switch (words->type) { + case word_HyperLink: + case word_HyperEnd: + case word_UpperXref: + case word_LowerXref: + case word_XrefEnd: + case word_IndexRef: + continue; + } + + type = removeattr(words->type); + + switch (type) { + case word_Normal: + text = utoa_dup(words->text); + break; + case word_WhiteSpace: + text = dupstr(" "); + break; + case word_Quote: + text = dupstr("'"); + break; + } + + fputs(text, fp); + sfree(text); + } + + fprintf(fp, "\n"); +} -- 2.11.0