summaryrefslogtreecommitdiff
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
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
-rw-r--r--Build/source/texk/dvipdfm-x/ChangeLog12
-rw-r--r--Build/source/texk/dvipdfm-x/cmap_write.c85
-rw-r--r--Build/source/texk/dvipdfm-x/pdfencrypt.c7
-rw-r--r--Build/source/texk/dvipdfm-x/spc_pdfm.c67
-rw-r--r--Build/source/texk/dvipdfm-x/spc_pdfm.h4
-rw-r--r--Build/source/texk/dvipdfm-x/specials.c5
-rw-r--r--Build/source/texk/dvipdfm-x/tt_cmap.c16
-rw-r--r--Build/source/texk/dvipdfm-x/tt_cmap.h3
-rw-r--r--Build/source/texk/dvipdfm-x/type0.c1
9 files changed, 175 insertions, 25 deletions
diff --git a/Build/source/texk/dvipdfm-x/ChangeLog b/Build/source/texk/dvipdfm-x/ChangeLog
index 94519ddff63..bed3e492eb4 100644
--- a/Build/source/texk/dvipdfm-x/ChangeLog
+++ b/Build/source/texk/dvipdfm-x/ChangeLog
@@ -1,3 +1,15 @@
+2018-08-17 Shunsaku Hirata <shunsaku.hirata74@gmail.com>
+
+ * cmap_write.c, tt_cmap.[ch], type0.c: Fixed a bug that
+ CMapName in CMap resource is not properly written.
+ Not correctly handles PostScript name and string objects.
+ Use CMapName constructed from font's BaseFont entry.
+ * spc_pdfm.c, spc_pdfm.h, specials.c: Added new special command
+ pdf:pageresources similar to pdfTeX \pdfpageresources
+ primitive.
+ * pdfencrypt.c: Adobe extension for AES 256-bit encryption is
+ not necessary for PDF version 2.0.
+
2018-05-23 Akira Kakuto <kakuto@fuk.kindai.ac.jp>
* dvi.c: First search for an input file with a suffix .xdv
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;
diff --git a/Build/source/texk/dvipdfm-x/pdfencrypt.c b/Build/source/texk/dvipdfm-x/pdfencrypt.c
index d5cb1cf046e..3fc80eae1a2 100644
--- a/Build/source/texk/dvipdfm-x/pdfencrypt.c
+++ b/Build/source/texk/dvipdfm-x/pdfencrypt.c
@@ -72,6 +72,7 @@ static struct pdf_sec {
struct {
int use_aes;
int encrypt_metadata;
+ int need_adobe_extension;
} setting;
struct {
@@ -106,6 +107,7 @@ pdf_enc_init (int use_aes, int encrypt_metadata)
srand(current_time); /* For AES IV */
p->setting.use_aes = use_aes;
p->setting.encrypt_metadata = encrypt_metadata;
+ p->setting.need_adobe_extension = 0;
}
#define PRODUCER \
@@ -475,6 +477,9 @@ check_version (struct pdf_sec *p, int version)
" (plus Adobe Extension Level 3).");
p->V = 4;
}
+ if (p->V == 5 && version < 20) {
+ p->setting.need_adobe_extension = 1;
+ }
}
/* Dummy routine for stringprep - NOT IMPLEMENTED YET
@@ -786,7 +791,7 @@ pdf_encrypt_obj (void)
}
#ifdef USE_ADOBE_EXTENSION
- if (p->R > 5) {
+ if (p->R > 5 && p->setting.need_adobe_extension != 0) {
pdf_obj *catalog = pdf_doc_catalog();
pdf_obj *ext = pdf_new_dict();
pdf_obj *adbe = pdf_new_dict();
diff --git a/Build/source/texk/dvipdfm-x/spc_pdfm.c b/Build/source/texk/dvipdfm-x/spc_pdfm.c
index b9ce71ee4dd..f67b1e600f7 100644
--- a/Build/source/texk/dvipdfm-x/spc_pdfm.c
+++ b/Build/source/texk/dvipdfm-x/spc_pdfm.c
@@ -75,13 +75,15 @@ struct spc_pdf_
int lowest_level; /* current min level of outlines */
struct ht_table *resourcemap; /* see remark below (somewhere) */
struct tounicode cd; /* For to-UTF16-BE conversion :( */
+ pdf_obj *pageresources; /* Add to all page resource dict */
};
static struct spc_pdf_ _pdf_stat = {
NULL,
255,
NULL,
- { -1, 0, NULL }
+ { -1, 0, NULL },
+ NULL
};
/* PLEASE REMOVE THIS */
@@ -148,6 +150,7 @@ spc_handler_pdfm__init (void *dp)
pdf_add_array(sd->cd.taintkeys,
pdf_new_name(default_taintkeys[i]));
}
+ sd->pageresources = NULL;
return 0;
}
@@ -172,6 +175,9 @@ spc_handler_pdfm__clean (void *dp)
if (sd->cd.taintkeys)
pdf_release_obj(sd->cd.taintkeys);
sd->cd.taintkeys = NULL;
+ if (sd->pageresources)
+ pdf_release_obj(sd->pageresources);
+ sd->pageresources = NULL;
return 0;
}
@@ -191,6 +197,45 @@ spc_pdfm_at_end_document (void)
return spc_handler_pdfm__clean(sd);
}
+static
+int putpageresources (pdf_obj *kp, pdf_obj *vp, void *dp)
+{
+ char *resource_name;
+
+ ASSERT(kp && vp);
+
+ resource_name = pdf_name_value(kp);
+ pdf_doc_add_page_resource(dp, resource_name, pdf_ref_obj(vp));
+
+ return 0;
+}
+
+static
+int forallresourcecategory (pdf_obj *kp, pdf_obj *vp, void *dp)
+{
+ char *category;
+
+ ASSERT(kp && vp);
+
+ category = pdf_name_value(kp);
+ if (!PDF_OBJ_DICTTYPE(vp)) {
+ return -1;
+ }
+
+ return pdf_foreach_dict(vp, putpageresources, category);
+}
+
+int
+spc_pdfm_at_end_page (void)
+{
+ struct spc_pdf_ *sd = &_pdf_stat;
+
+ if (sd->pageresources) {
+ pdf_foreach_dict(sd->pageresources, forallresourcecategory, NULL);
+ }
+
+ return 0;
+}
/* Dvipdfm specials */
static int
@@ -1862,6 +1907,24 @@ spc_handler_pdfm_tounicode (struct spc_env *spe, struct spc_arg *args)
return 0;
}
+static int
+spc_handler_pdfm_pageresources (struct spc_env *spe, struct spc_arg *args)
+{
+ struct spc_pdf_ *sd = &_pdf_stat;
+ pdf_obj *dict;
+
+ dict = parse_pdf_object(&args->curptr, args->endptr, NULL);
+ if (!dict) {
+ spc_warn(spe, "Dictionary object expected but not found.");
+ return -1;
+ }
+
+ if (sd->pageresources)
+ pdf_release_obj(sd->pageresources);
+ sd->pageresources = dict;
+
+ return 0;
+}
static struct spc_handler pdfm_handlers[] = {
{"annotation", spc_handler_pdfm_annot},
@@ -1973,6 +2036,8 @@ static struct spc_handler pdfm_handlers[] = {
{"minorversion", spc_handler_pdfm_do_nothing},
{"majorversion", spc_handler_pdfm_do_nothing},
{"encrypt", spc_handler_pdfm_do_nothing},
+
+ {"pageresources", spc_handler_pdfm_pageresources},
};
int
diff --git a/Build/source/texk/dvipdfm-x/spc_pdfm.h b/Build/source/texk/dvipdfm-x/spc_pdfm.h
index 1172f0bde91..a27556a298c 100644
--- a/Build/source/texk/dvipdfm-x/spc_pdfm.h
+++ b/Build/source/texk/dvipdfm-x/spc_pdfm.h
@@ -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.
Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
@@ -28,6 +28,8 @@
extern int spc_pdfm_at_begin_document (void);
extern int spc_pdfm_at_end_document (void);
+extern int spc_pdfm_at_end_page (void);
+
extern int spc_pdfm_check_special (const char *buffer, int size);
extern int spc_pdfm_setup_handler (struct spc_handler *handle,
struct spc_env *spe, struct spc_arg *args);
diff --git a/Build/source/texk/dvipdfm-x/specials.c b/Build/source/texk/dvipdfm-x/specials.c
index 138df2cbfc5..e931fdb4eed 100644
--- a/Build/source/texk/dvipdfm-x/specials.c
+++ b/Build/source/texk/dvipdfm-x/specials.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.
Copyright (C) 1998, 1999 by Mark A. Wicks <mwicks@kettering.edu>
@@ -371,7 +371,7 @@ static struct {
spc_pdfm_at_begin_document,
spc_pdfm_at_end_document,
NULL,
- NULL,
+ spc_pdfm_at_end_page,
spc_pdfm_check_special,
spc_pdfm_setup_handler
},
@@ -595,4 +595,3 @@ spc_exec_special (const char *buffer, int32_t size,
return error;
}
-
diff --git a/Build/source/texk/dvipdfm-x/tt_cmap.c b/Build/source/texk/dvipdfm-x/tt_cmap.c
index 86689d677af..a32f1752136 100644
--- a/Build/source/texk/dvipdfm-x/tt_cmap.c
+++ b/Build/source/texk/dvipdfm-x/tt_cmap.c
@@ -1198,6 +1198,7 @@ static cmap_plat_enc_rec cmap_plat_encs[] = {
pdf_obj *
otf_create_ToUnicode_stream (const char *font_name,
int ttc_index, /* 0 for non-TTC */
+ const char *basefont,
const char *used_chars,
int cmap_id)
{
@@ -1214,19 +1215,8 @@ otf_create_ToUnicode_stream (const char *font_name,
ULONG offset = 0;
int i, cmap_type;
- /* replace slash in map name with dash to make the output cmap name valid,
- * happens when XeTeX embeds full font path
- * https://sourceforge.net/p/xetex/bugs/52/
- */
- normalized_font_name = NEW(strlen(font_name)+1, char);
- strcpy(normalized_font_name, font_name);
- for (i = 0; i < strlen(font_name); ++i) {
- if (normalized_font_name[i] == '/')
- normalized_font_name[i] = '-';
- }
-
- cmap_name = NEW(strlen(font_name)+strlen("-UTF16")+5, char);
- sprintf(cmap_name, "%s,%03d-UTF16", normalized_font_name, ttc_index);
+ cmap_name = NEW(strlen(basefont)+strlen("-UTF16")+1, char);
+ sprintf(cmap_name, "%s-UTF16", basefont);
res_id = pdf_findresource("CMap", cmap_name);
if (res_id >= 0) {
diff --git a/Build/source/texk/dvipdfm-x/tt_cmap.h b/Build/source/texk/dvipdfm-x/tt_cmap.h
index ca74de81792..8fd51581a8f 100644
--- a/Build/source/texk/dvipdfm-x/tt_cmap.h
+++ b/Build/source/texk/dvipdfm-x/tt_cmap.h
@@ -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
@@ -68,6 +68,7 @@ extern void tt_cmap_release (tt_cmap *cmap);
/* Indirect reference */
extern pdf_obj *otf_create_ToUnicode_stream (const char *map_name,
int ttc_index,
+ const char *basefont,
const char *used_chars,
int cmap_id);
/* CMap ID */
diff --git a/Build/source/texk/dvipdfm-x/type0.c b/Build/source/texk/dvipdfm-x/type0.c
index 4a0f6ec016d..7c6c9ffaf88 100644
--- a/Build/source/texk/dvipdfm-x/type0.c
+++ b/Build/source/texk/dvipdfm-x/type0.c
@@ -154,6 +154,7 @@ Type0Font_create_ToUnicode_stream(Type0Font *font) {
CIDFont *cidfont = font->descendant;
return otf_create_ToUnicode_stream(CIDFont_get_ident(cidfont),
CIDFont_get_opt_index(cidfont),
+ CIDFont_get_fontname(cidfont),
Type0Font_get_usedchars(font),
font->cmap_id);
}