summaryrefslogtreecommitdiff
path: root/Build/source/texk/dvipdfm-x/spc_pdfm.c
diff options
context:
space:
mode:
Diffstat (limited to 'Build/source/texk/dvipdfm-x/spc_pdfm.c')
-rw-r--r--Build/source/texk/dvipdfm-x/spc_pdfm.c159
1 files changed, 104 insertions, 55 deletions
diff --git a/Build/source/texk/dvipdfm-x/spc_pdfm.c b/Build/source/texk/dvipdfm-x/spc_pdfm.c
index aa80a6ba59a..f084243cba9 100644
--- a/Build/source/texk/dvipdfm-x/spc_pdfm.c
+++ b/Build/source/texk/dvipdfm-x/spc_pdfm.c
@@ -198,6 +198,51 @@ spc_pdfm_at_end_document (void)
return spc_handler_pdfm__clean(sd);
}
+/* Why should we have this kind of things? */
+static int
+safeputresdent (pdf_obj *kp, pdf_obj *vp, void *dp)
+{
+ char *key;
+
+ ASSERT(kp && vp && dp);
+
+ key = pdf_name_value(kp);
+ if (pdf_lookup_dict(dp, key))
+ WARN("Object \"%s\" already defined in dict! (ignored)", key);
+ else {
+ pdf_add_dict(dp,
+ pdf_link_obj(kp), pdf_link_obj(vp));
+ }
+ return 0;
+}
+
+static int
+safeputresdict (pdf_obj *kp, pdf_obj *vp, void *dp)
+{
+ char *key;
+ pdf_obj *dict;
+
+ ASSERT(kp && vp && dp);
+
+ key = pdf_name_value(kp);
+ dict = pdf_lookup_dict(dp, key);
+
+ if (pdf_obj_typeof(vp) == PDF_INDIRECT) {
+ pdf_add_dict(dp, pdf_new_name(key), pdf_link_obj(vp));
+ } else if (pdf_obj_typeof(vp) == PDF_DICT) {
+ if (dict)
+ pdf_foreach_dict(vp, safeputresdent, dict);
+ else {
+ pdf_add_dict(dp, pdf_new_name(key), pdf_link_obj(vp));
+ }
+ } else {
+ WARN("Invalid type (not DICT) for page/form resource dict entry: key=\"%s\"", key);
+ return -1;
+ }
+
+ return 0;
+}
+
static
int putpageresources (pdf_obj *kp, pdf_obj *vp, void *dp)
{
@@ -206,7 +251,7 @@ int putpageresources (pdf_obj *kp, pdf_obj *vp, void *dp)
ASSERT(kp && vp);
resource_name = pdf_name_value(kp);
- pdf_doc_add_page_resource(dp, resource_name, pdf_ref_obj(vp));
+ pdf_doc_add_page_resource(dp, resource_name, pdf_link_obj(vp));
return 0;
}
@@ -214,16 +259,65 @@ int putpageresources (pdf_obj *kp, pdf_obj *vp, void *dp)
static
int forallresourcecategory (pdf_obj *kp, pdf_obj *vp, void *dp)
{
+ int r = -1;
char *category;
ASSERT(kp && vp);
category = pdf_name_value(kp);
- if (!PDF_OBJ_DICTTYPE(vp)) {
- return -1;
+ switch (pdf_obj_typeof(vp)) {
+ case PDF_DICT:
+ r = pdf_foreach_dict(vp, putpageresources, category);
+ break;
+ case PDF_INDIRECT:
+ {
+ /* In case pdf:pageresouces << /Category @res >> */
+ pdf_obj *obj;
+ obj = pdf_deref_obj(vp);
+ if (!obj) {
+ WARN("Can't deref object for page resource: %s", category);
+ r = -1;
+ } else if (pdf_obj_typeof(obj) != PDF_DICT) {
+ WARN("Invalid object type for page resource: %s", category);
+ r = -1;
+ } else {
+ pdf_obj *res_dict, *dict;
+
+ res_dict = pdf_doc_current_page_resources();
+ dict = pdf_lookup_dict(res_dict, category);
+ if (!dict) {
+ pdf_add_dict(res_dict, pdf_new_name(category), pdf_link_obj(vp));
+ } else {
+ if (pdf_obj_typeof(dict) == PDF_INDIRECT) {
+ dict = pdf_deref_obj(dict);
+ pdf_release_obj(dict); /* FIXME: jus to decrement link counter */
+ }
+#if 1
+ /* This will leave garbage (object "res") since object "res"
+ * supplied as resource dictionary will have label but we copy the
+ * content of res here and never use reference to it.
+ */
+ pdf_foreach_dict(obj, safeputresdent, dict);
+#else
+ /* With the below code resource dictionary is replaced by user
+ * supplied one, @res. However, there is a problem that all
+ * resources including internally generated one may go into single
+ * dictionary referenced by @res, and will be visible from any
+ * subsequent pages.
+ */
+ pdf_foreach_dict(dict, safeputresdent, obj);
+ pdf_add_dict(res_dict, pdf_new_name(category), pdf_link_obj(vp));
+#endif
+ }
+ pdf_release_obj(obj);
+ }
+ }
+ break;
+ default:
+ WARN("Invalid object type for page resource specified for \"%s\"", category);
}
- return pdf_foreach_dict(vp, putpageresources, category);
+ return r;
}
int
@@ -268,56 +362,6 @@ spc_handler_pdfm_eop (struct spc_env *spe, struct spc_arg *args)
#define streamfiltered(o) \
(pdf_lookup_dict(pdf_stream_dict((o)), "Filter") ? 1 : 0)
-/* Why should we have this kind of things? */
-static int
-safeputresdent (pdf_obj *kp, pdf_obj *vp, void *dp)
-{
- char *key;
-
- ASSERT(kp && vp && dp);
-
- key = pdf_name_value(kp);
- if (pdf_lookup_dict(dp, key))
- WARN("Object \"%s\" already defined in dict! (ignored)", key);
- else {
- pdf_add_dict(dp,
- pdf_link_obj(kp), pdf_link_obj(vp));
- }
- return 0;
-}
-
-#ifndef pdf_obj_isaref
-#define pdf_obj_isaref(o) (pdf_obj_typeof((o)) == PDF_INDIRECT)
-#endif
-
-static int
-safeputresdict (pdf_obj *kp, pdf_obj *vp, void *dp)
-{
- char *key;
- pdf_obj *dict;
-
- ASSERT(kp && vp && dp);
-
- key = pdf_name_value(kp);
- dict = pdf_lookup_dict(dp, key);
-
- if (pdf_obj_isaref(vp)) {
- pdf_add_dict(dp, pdf_new_name(key), pdf_link_obj(vp));
- } else if (pdf_obj_typeof(vp) == PDF_DICT) {
- if (dict)
- pdf_foreach_dict(vp, safeputresdent, dict);
- else {
- pdf_add_dict(dp, pdf_new_name(key), pdf_link_obj(vp));
- }
- } else {
- WARN("Invalid type (not DICT) for page/form resource dict entry: key=\"%s\"", key);
- return -1;
- }
-
- return 0;
-}
-
-
/* Think what happens if you do
*
* pdf:put @resources << /Font << >> >>
@@ -1716,7 +1760,8 @@ spc_handler_pdfm_bform (struct spc_env *spe, struct spc_arg *args)
static int
spc_handler_pdfm_eform (struct spc_env *spe, struct spc_arg *args)
{
- pdf_obj *attrib = NULL;
+ pdf_obj *attrib = NULL;
+ struct spc_pdf_ *sd = &_pdf_stat;
skip_white(&args->curptr, args->endptr);
@@ -1727,6 +1772,10 @@ spc_handler_pdfm_eform (struct spc_env *spe, struct spc_arg *args)
attrib = NULL;
}
}
+ /* pageresources here too */
+ if (sd->pageresources) {
+ pdf_foreach_dict(sd->pageresources, forallresourcecategory, NULL);
+ }
pdf_doc_end_grabbing(attrib);
return 0;