+
+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, CS_ASCII);
+ 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;
+}
+
+static void pdf_string_len(void (*add)(object *, char const *),
+ object *o, char const *str, int len)
+{
+ char const *p;
+
+ add(o, "(");
+ for (p = str; len > 0; p++, len--) {
+ char c[10];
+ if (*p < ' ' || *p > '~') {
+ sprintf(c, "\\%03o", 0xFF & (int)*p);
+ } else {
+ int n = 0;
+ if (*p == '\\' || *p == '(' || *p == ')')
+ c[n++] = '\\';
+ c[n++] = *p;
+ c[n] = '\0';
+ }
+ add(o, c);
+ }
+ add(o, ")");
+}
+
+static void pdf_string(void (*add)(object *, char const *),
+ object *o, char const *str)
+{
+ pdf_string_len(add, o, str, strlen(str));
+}