From 782ad0de9c74750a257e739156305682532a2e94 Mon Sep 17 00:00:00 2001 From: Akira Kakuto Date: Thu, 16 Aug 2018 22:45:32 +0000 Subject: 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 --- Build/source/texk/dvipdfm-x/cmap_write.c | 85 ++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 5 deletions(-) (limited to 'Build/source/texk/dvipdfm-x/cmap_write.c') 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; -- cgit v1.2.3