summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipdfm-x/cmap_write.c
diff options
context:
space:
mode:
authorAkira Kakuto <kakuto@fuk.kindai.ac.jp>2018-08-16 22:45:32 +0000
committerAkira Kakuto <kakuto@fuk.kindai.ac.jp>2018-08-16 22:45:32 +0000
commit782ad0de9c74750a257e739156305682532a2e94 (patch)
treed9730b8fcf557880ca7b83b4c0002d3f6dd19ea9 /Build/source/texk/dvipdfm-x/cmap_write.c
parent8a76770f246ae3adb341b873bf6cdb25d0114ef2 (diff)
Fix a bug that CMapName in CMap resource is not properly written (S. Hirata).
git-svn-id: svn://tug.org/texlive/trunk@48418 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/dvipdfm-x/cmap_write.c')
-rw-r--r--Build/source/texk/dvipdfm-x/cmap_write.c85
1 files changed, 80 insertions, 5 deletions
diff --git a/Build/source/texk/dvipdfm-x/cmap_write.c b/Build/source/texk/dvipdfm-x/cmap_write.c
index 58dff36126b..88036b57298 100644
--- a/Build/source/texk/dvipdfm-x/cmap_write.c
+++ b/Build/source/texk/dvipdfm-x/cmap_write.c
@@ -1,6 +1,6 @@
/* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
- Copyright (C) 2002-2016 by Jin-Hwan Cho and Shunsaku Hirata,
+ Copyright (C) 2002-2018 by Jin-Hwan Cho and Shunsaku Hirata,
the dvipdfmx project team.
This program is free software; you can redistribute it and/or modify
@@ -238,6 +238,72 @@ write_map (mapDef *mtab, int count,
return count;
}
+/* duplicated from pdfobj.c */
+static void
+write_string (char **outptr, char *endptr, const char *string)
+{
+ char *s, *p;
+ int i, length;
+
+ s = (char *) string;
+ length = string ? strlen(string) : 0;
+ p = *outptr;
+
+ *p++ = '(';
+ for (i = 0; i < length; i++) {
+ unsigned char ch;
+
+ ch = s[i];
+ if (ch < 32 || ch > 126) {
+ p += sprintf(p, "\\%03o", ch);
+ } else {
+ switch (ch) {
+ case '(': case ')': case '\\':
+ *p++ = '\\';
+ *p++ = ch;
+ break;
+ default:
+ *p++ = ch;
+ break;
+ }
+ }
+ }
+ *p++ = ')';
+
+ *outptr = p;
+}
+
+static void
+write_name (char **outptr, char *endptr, const char *name)
+{
+ char *s, *p;
+ int i, length;
+
+ s = (char *) name;
+ length = name ? strlen(name) : 0;
+ p = *outptr;
+#ifndef is_delim
+ /* Avoid '{' and '}' for PostScript compatibility? */
+#define is_delim(c) ((c) == '(' || (c) == ')' || \
+ (c) == '/' || \
+ (c) == '<' || (c) == '>' || \
+ (c) == '[' || (c) == ']' || \
+ (c) == '{' || (c) == '}' || \
+ (c) == '%')
+#endif
+ *p++ = '/';
+ for (i = 0; i < length; i++) {
+ if (s[i] < '!' || s[i] > '~' || s[i] == '#' || is_delim(s[i])) {
+ /* ^ "space" is here. */
+ *p++ = '#';
+ sputx(s[i], &p, endptr);
+ } else {
+ *p++ = s[i];
+ }
+ }
+ *outptr = p;
+}
+
#define CMAP_BEGIN "\
/CIDInit /ProcSet findresource begin\n\
12 dict begin\n\
@@ -346,7 +412,7 @@ CMap_create_stream (CMap *cmap)
}
}
-#define WBUF_SIZE 4096
+#define WBUF_SIZE 40960
wbuf.buf = NEW(WBUF_SIZE, char);
codestr = NEW(cmap->profile.maxBytesIn, unsigned char);
memset(codestr, 0, cmap->profile.maxBytesIn);
@@ -358,7 +424,9 @@ CMap_create_stream (CMap *cmap)
/* Start CMap */
pdf_add_stream(stream, (const void *) CMAP_BEGIN, strlen(CMAP_BEGIN));
- wbuf.curptr += sprintf(wbuf.curptr, "/CMapName /%s def\n", cmap->name);
+ wbuf.curptr += sprintf(wbuf.curptr, "/CMapName ");
+ write_name(&wbuf.curptr, wbuf.limptr, cmap->name);
+ wbuf.curptr += sprintf(wbuf.curptr, " def\n");
wbuf.curptr += sprintf(wbuf.curptr, "/CMapType %d def\n" , cmap->type);
if (cmap->wmode != 0 &&
cmap->type != CMAP_TYPE_TO_UNICODE)
@@ -369,8 +437,15 @@ CMap_create_stream (CMap *cmap)
/Ordering (%s)\n\
/Supplement %d\n\
>> def\n"
- wbuf.curptr += sprintf(wbuf.curptr, CMAP_CSI_FMT,
- csi->registry, csi->ordering, csi->supplement);
+ wbuf.curptr += sprintf(wbuf.curptr, "/CIDSystemInfo <<\n");
+ wbuf.curptr += sprintf(wbuf.curptr, " /Registry ");
+ write_string(&wbuf.curptr, wbuf.limptr, csi->registry);
+ wbuf.curptr += sprintf(wbuf.curptr, "\n");
+ wbuf.curptr += sprintf(wbuf.curptr, " /Ordering ");
+ write_string(&wbuf.curptr, wbuf.limptr, csi->ordering);
+ wbuf.curptr += sprintf(wbuf.curptr, "\n");
+ wbuf.curptr += sprintf(wbuf.curptr, " /Supplement %d\n>> def\n",
+ csi->supplement);
pdf_add_stream(stream, wbuf.buf, (int)(wbuf.curptr - wbuf.buf));
wbuf.curptr = wbuf.buf;