summaryrefslogtreecommitdiff
path: root/Build/source/texk/web2c/luatexdir/image
diff options
context:
space:
mode:
authorLuigi Scarso <luigi.scarso@gmail.com>2019-01-06 18:57:01 +0000
committerLuigi Scarso <luigi.scarso@gmail.com>2019-01-06 18:57:01 +0000
commit0c14fd18747b9f6fbbecb75ba8beef6d449c460a (patch)
tree6c60915cf22ba35f9f4fff0048ebe3a6c073662d /Build/source/texk/web2c/luatexdir/image
parent2a4260012f7ef1890dd351aabe4befd60922d5a6 (diff)
luatex 1.09.2; r-mpost alias of mpost -restricted
git-svn-id: svn://tug.org/texlive/trunk@49614 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/web2c/luatexdir/image')
-rw-r--r--Build/source/texk/web2c/luatexdir/image/epdf.h3
-rw-r--r--Build/source/texk/web2c/luatexdir/image/image.h4
-rw-r--r--Build/source/texk/web2c/luatexdir/image/pdftoepdf.c150
-rw-r--r--Build/source/texk/web2c/luatexdir/image/writeimg.c131
4 files changed, 179 insertions, 109 deletions
diff --git a/Build/source/texk/web2c/luatexdir/image/epdf.h b/Build/source/texk/web2c/luatexdir/image/epdf.h
index 9c32c06b795..d0cd7f79ee0 100644
--- a/Build/source/texk/web2c/luatexdir/image/epdf.h
+++ b/Build/source/texk/web2c/luatexdir/image/epdf.h
@@ -145,7 +145,8 @@ int luaopen_epdf(lua_State * L);
typedef struct InObj InObj;
struct InObj {
- ppref *ref; /* ref in original PDF */
+ /* int version; */ /* old object number in included PDF */
+ int objnum; /* old version number in included PDF, we can do without */
int num; /* new object number in output PDF */
InObj *next; /* next entry in list of indirect objects */
} ;
diff --git a/Build/source/texk/web2c/luatexdir/image/image.h b/Build/source/texk/web2c/luatexdir/image/image.h
index 985f53d06eb..687aa2bdf85 100644
--- a/Build/source/texk/web2c/luatexdir/image/image.h
+++ b/Build/source/texk/web2c/luatexdir/image/image.h
@@ -129,6 +129,8 @@ typedef struct {
int luaref ;
boolean keepopen;
boolean nolength;
+ boolean notype;
+ boolean nobbox;
int errorlevel;
int pdfmajorversion;
int pdfminorversion;
@@ -177,7 +179,9 @@ typedef struct {
# define img_flags(N) ((N)->flags)
# define img_luaref(N) ((N)->luaref)
# define img_keepopen(N) ((N)->keepopen)
+# define img_nobbox(N) ((N)->nobbox)
# define img_nolength(N) ((N)->nolength)
+# define img_notype(N) ((N)->notype)
# define img_errorlevel(N) ((N)->errorlevel)
# define img_pdfmajorversion(N) ((N)->pdfmajorversion)
# define img_pdfminorversion(N) ((N)->pdfminorversion)
diff --git a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
index b29493b073d..664bfef18c9 100644
--- a/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
+++ b/Build/source/texk/web2c/luatexdir/image/pdftoepdf.c
@@ -23,6 +23,11 @@ with LuaTeX; if not, see <http://www.gnu.org/licenses/>.
#define __STDC_FORMAT_MACROS /* for PRId64 etc. */
#include "image/epdf.h"
+#include "luatexcallbackids.h"
+
+/* to be sorted out, we cannot include */
+
+#define xfree(a) do { free(a); a = NULL; } while (0)
/* Conflict with pdfgen.h */
@@ -270,31 +275,37 @@ PdfDocument *refMemStreamPdfDocument(char *docstream, unsigned long long streams
typedef struct ObjMap ObjMap ;
struct ObjMap {
- ppref * in;
+ /* int version; */ /* not really needed */
+ int objnum;
int out_num;
};
static int CompObjMap(const void *pa, const void *pb, void *p)
{
- const ppref *a = (((const ObjMap *) pa)->in);
- const ppref *b = (((const ObjMap *) pb)->in);
- if (a->number > b->number)
+ const ObjMap *a = (((const ObjMap *) pa));
+ const ObjMap *b = (((const ObjMap *) pb));
+ if (a->objnum > b->objnum)
return 1;
- else if (a->number < b->number)
+ else if (a->objnum < b->objnum)
return -1;
+ /*
else if (a->version == b->version)
return 0;
else if (a->version < b->version)
return -1;
return 1;
+ */
+ return 0;
}
static ObjMap *findObjMap(PdfDocument * pdf_doc, ppref * in)
{
ObjMap *obj_map, tmp;
- if (pdf_doc->ObjMapTree == NULL)
+ if (pdf_doc->ObjMapTree == NULL) {
return NULL;
- tmp.in = in;
+ }
+ tmp.objnum = in->number;
+ /* tmp.version = in->version; */
obj_map = (ObjMap *) avl_find(pdf_doc->ObjMapTree, &tmp);
return obj_map;
}
@@ -302,10 +313,12 @@ static ObjMap *findObjMap(PdfDocument * pdf_doc, ppref * in)
static void addObjMap(PdfDocument * pdf_doc, ppref * in, int out_num)
{
ObjMap *obj_map = NULL;
- if (pdf_doc->ObjMapTree == NULL)
+ if (pdf_doc->ObjMapTree == NULL) {
pdf_doc->ObjMapTree = avl_create(CompObjMap, NULL, &avl_xallocator);
+ }
obj_map = (ObjMap*)xmalloc(sizeof(ObjMap));
- obj_map->in = in;
+ /* obj_map->version = in->version; */
+ obj_map->objnum = in->number;
obj_map->out_num = out_num;
avl_probe(pdf_doc->ObjMapTree, obj_map);
}
@@ -332,7 +345,8 @@ static int addInObj(PDF pdf, PdfDocument * pdf_doc, ppref * ref)
return obj_map->out_num;
}
n = (InObj*)xmalloc(sizeof(InObj));
- n->ref = ref;
+ n->objnum = ref->number;
+ /* n->version = ref->version; */
n->next = NULL;
n->num = pdf_create_obj(pdf, obj_type_others, 0);
addObjMap(pdf_doc, ref, n->num);
@@ -408,7 +422,7 @@ static void copyDict(PDF pdf, PdfDocument * pdf_doc, ppdict *dict)
pdf_end_dict(pdf);
}
-static void copyStreamStream(PDF pdf, ppstream * stream, int decode)
+static void copyStreamStream(PDF pdf, ppstream * stream, int decode, int callback_id)
{
uint8_t *data = NULL;
size_t size = 0;
@@ -419,7 +433,18 @@ static void copyStreamStream(PDF pdf, ppstream * stream, int decode)
} else {
data = ppstream_all(stream,&size,decode);
if (data != NULL) {
- pdf_out_block(pdf, (const char *) data, size);
+ /*tex We only do this when we recompress in which case we fetch the whole stream. */
+ if (callback_id == 1) {
+ callback_id = callback_defined(process_pdf_image_content_callback);
+ }
+ if (callback_id) {
+ char *result = NULL;
+ run_callback(callback_id, "S->S",(char *) data,&result);
+ pdf_out_block(pdf, (const char *) (uint8_t *) result, size);
+ xfree(result);
+ } else {
+ pdf_out_block(pdf, (const char *) data, size);
+ }
}
}
ppstream_done(stream);
@@ -429,38 +454,57 @@ static void copyStream(PDF pdf, PdfDocument * pdf_doc, ppstream * stream)
{
ppdict *dict = stream->dict; /* bug in: stream_dict(stream) */
if (pdf->compress_level == 0 || pdf->recompress) {
- const char *ignoredkeys[] = {
- "Filter", "Decode", "Length", "DL", NULL
- };
- int i;
- int n = dict->size;
- pdf_begin_dict(pdf);
- for (i=0; i<n; ++i) {
- const char *key = ppdict_key(dict,i);
- int okay = 1;
+ ppobj * obj = ppdict_get_obj (dict, "Filter");
+ int known = 0;
+ if (obj != NULL && obj->type == PPNAME) {
+ const char *codecs[] = {
+ "ASCIIHexDecode", "ASCII85Decode", "RunLengthDecode",
+ "FlateDecode", "LZWDecode", NULL
+ };
int k;
- for (k = 0; ignoredkeys[k] != NULL; k++) {
- if (strcmp(key,ignoredkeys[k]) == 0) {
- okay = 0;
+ const char *val = ppobj_get_name(obj);
+ for (k = 0; codecs[k] != NULL; k++) {
+ if (strcmp(val,codecs[k]) == 0) {
+ known = 1;
break;
}
}
- if (okay) {
- pdf_add_name(pdf, key);
- copyObject(pdf, pdf_doc, ppdict_at(dict,i));
+ }
+ if (known) {
+ /*tex recompress or keep uncompressed */
+ const char *ignoredkeys[] = {
+ "Filter", "DecodeParms", "Length", "DL", NULL
+ };
+ int i;
+ pdf_begin_dict(pdf);
+ for (i=0; i<dict->size; ++i) {
+ const char *key = ppdict_key(dict,i);
+ int copy = 1;
+ int k;
+ for (k = 0; ignoredkeys[k] != NULL; k++) {
+ if (strcmp(key,ignoredkeys[k]) == 0) {
+ copy = 0;
+ break;
+ }
+ }
+ if (copy) {
+ pdf_add_name(pdf, key);
+ copyObject(pdf, pdf_doc, ppdict_at(dict,i));
+ }
}
+ pdf_dict_add_streaminfo(pdf);
+ pdf_end_dict(pdf);
+ pdf_begin_stream(pdf);
+ copyStreamStream(pdf, stream, 1, 0);
+ pdf_end_stream(pdf);
+ return ;
}
- pdf_dict_add_streaminfo(pdf);
- pdf_end_dict(pdf);
- pdf_begin_stream(pdf);
- copyStreamStream(pdf, stream, 1);
- pdf_end_stream(pdf);
- } else {
- copyDict(pdf, pdf_doc, dict);
- pdf_begin_stream(pdf);
- copyStreamStream(pdf, stream, 0);
- pdf_end_stream(pdf);
}
+ /* copy as-is */
+ copyDict(pdf, pdf_doc, dict);
+ pdf_begin_stream(pdf);
+ copyStreamStream(pdf, stream, 0, 0);
+ pdf_end_stream(pdf);
}
static void copyObject(PDF pdf, PdfDocument * pdf_doc, ppobj * obj)
@@ -505,12 +549,16 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc)
{
InObj *r, *n;
ppobj * obj;
+ ppref * ref ;
+ ppxref * xref = ppdoc_xref (pdf_doc->pdfe);
for (r = pdf_doc->inObjList; r != NULL;) {
- obj = ppref_obj(r->ref);
- if (obj->type == PPSTREAM)
+ ref = ppxref_find (xref, (ppuint) r->objnum);
+ obj = ppref_obj(ref);
+ if (obj->type == PPSTREAM) {
pdf_begin_obj(pdf, r->num, OBJSTM_NEVER);
- else
+ } else {
pdf_begin_obj(pdf, r->num, 2);
+ }
copyObject(pdf, pdf_doc, obj);
pdf_end_obj(pdf);
n = r->next;
@@ -520,6 +568,7 @@ static void writeRefs(PDF pdf, PdfDocument * pdf_doc)
}
}
+
/* get the pagebox coordinates according to the pagebox_spec */
static void somebox(ppdict *page, const char * key, pprect * box)
@@ -578,11 +627,6 @@ static ppdict * get_pdf_page_dict(ppdoc *pdfe, int n)
return NULL;
}
-// static ppdict * get_pdf_page_dict(ppdoc *pdfe, int n)
-// {
-// return ppref_obj(ppdoc_page(pdfe,n))->dict;
-// }
-
void read_pdf_info(image_dict * idict)
{
PdfDocument *pdf_doc = NULL;
@@ -592,7 +636,7 @@ void read_pdf_info(image_dict * idict)
ppint rotate = 0;
int pdf_major_version_found = 1;
int pdf_minor_version_found = 3;
- float xsize, ysize, xorig, yorig;
+ double xsize, ysize, xorig, yorig;
if (img_type(idict) == IMG_TYPE_PDF) {
pdf_doc = refPdfDocument(img_filepath(idict), FE_FAIL, img_userpassword(idict), img_ownerpassword(idict));
} else if (img_type(idict) == IMG_TYPE_PDFMEMSTREAM) {
@@ -851,12 +895,12 @@ void write_epdf(PDF pdf, image_dict * idict, int suppress_optional_info)
Write the Page contents.
*/
content = ppdict_rget_obj(pageDict, "Contents");
- if (content->type == PPSTREAM) {
+ if (content && content->type == PPSTREAM) {
if (pdf->compress_level == 0 || pdf->recompress) {
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
- copyStreamStream(pdf, content->stream,1); /* decompress */
+ copyStreamStream(pdf, content->stream, 1, 1); /* decompress */
} else {
/* copies compressed stream */
ppstream * stream = content->stream;
@@ -878,18 +922,18 @@ void write_epdf(PDF pdf, image_dict * idict, int suppress_optional_info)
}
*/
}
- pdf_end_dict(pdf);
+ pdf_end_dict(pdf);
pdf_begin_stream(pdf);
- copyStreamStream(pdf, stream,0);
+ copyStreamStream(pdf, stream, 0, 0);
} else {
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
pdf_begin_stream(pdf);
- copyStreamStream(pdf, stream,1);
+ copyStreamStream(pdf, stream, 1, 0);
}
}
pdf_end_stream(pdf);
- } else if (content->type == PPARRAY) {
+ } else if (content && content->type == PPARRAY) {
/* listens to compresslevel */
pdf_dict_add_streaminfo(pdf);
pdf_end_dict(pdf);
@@ -913,7 +957,7 @@ void write_epdf(PDF pdf, image_dict * idict, int suppress_optional_info)
} else {
b = 1;
}
- copyStreamStream(pdf, (ppstream *) o->stream,1);
+ copyStreamStream(pdf, (ppstream *) o->stream, 1, 0);
}
}
}
diff --git a/Build/source/texk/web2c/luatexdir/image/writeimg.c b/Build/source/texk/web2c/luatexdir/image/writeimg.c
index e3e3f608fea..7fe8444bced 100644
--- a/Build/source/texk/web2c/luatexdir/image/writeimg.c
+++ b/Build/source/texk/web2c/luatexdir/image/writeimg.c
@@ -541,53 +541,68 @@ scaled_whd scale_img(image_dict * idict, scaled_whd alt_rule, int transform)
/*tex natural size corresponding to image resolution */
scaled_whd nat;
int default_res;
- if ((img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
- || img_type(idict) == IMG_TYPE_PDFSTREAM) && img_is_bbox(idict)) {
- /*tex dimensions from image.bbox */
- x = img_xsize(idict) = img_bbox(idict)[2] - img_bbox(idict)[0];
- y = img_ysize(idict) = img_bbox(idict)[3] - img_bbox(idict)[1];
- img_xorig(idict) = img_bbox(idict)[0];
- img_yorig(idict) = img_bbox(idict)[1];
- } else {
- /*tex dimensions, resolutions from image file */
- x = img_xsize(idict);
- y = img_ysize(idict);
- }
- xr = img_xres(idict);
- yr = img_yres(idict);
- if (x <= 0 || y <= 0 || xr < 0 || yr < 0)
- normal_error("pdf backend","invalid image dimensions");
- if (xr > 65535 || yr > 65535) {
- xr = 0;
- yr = 0;
- normal_warning("pdf backend","too large image resolution ignored");
- }
- if (((transform - img_rotation(idict)) & 1) == 1) {
- tmp = x;
- x = y;
- y = tmp;
- tmp = xr;
- xr = yr;
- yr = tmp;
- }
- /*tex always for images */
nat.dp = 0;
- if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
- || img_type(idict) == IMG_TYPE_PDFSTREAM) {
- nat.wd = x;
- nat.ht = y;
+ nat.wd = 0;
+ nat.ht = 0;
+ if (img_nobbox(idict)) {
+ if (img_is_bbox(idict)) {
+ x = img_xsize(idict) = img_bbox(idict)[2] - img_bbox(idict)[0];
+ y = img_ysize(idict) = img_bbox(idict)[3] - img_bbox(idict)[1];
+ img_xorig(idict) = img_bbox(idict)[0];
+ img_yorig(idict) = img_bbox(idict)[1];
+ nat.wd = x;
+ nat.ht = y;
+ } else {
+ normal_error("pdf backend","use boundingbox to pass dimensions");
+ }
} else {
- default_res = fix_int(pdf_image_resolution, 0, 65535);
- if (default_res > 0 && (xr == 0 || yr == 0)) {
- xr = default_res;
- yr = default_res;
+ if ((img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
+ || img_type(idict) == IMG_TYPE_PDFSTREAM) && img_is_bbox(idict)) {
+ /*tex dimensions from image.bbox */
+ x = img_xsize(idict) = img_bbox(idict)[2] - img_bbox(idict)[0];
+ y = img_ysize(idict) = img_bbox(idict)[3] - img_bbox(idict)[1];
+ img_xorig(idict) = img_bbox(idict)[0];
+ img_yorig(idict) = img_bbox(idict)[1];
+ } else {
+ /*tex dimensions, resolutions from image file */
+ x = img_xsize(idict);
+ y = img_ysize(idict);
+ }
+ xr = img_xres(idict);
+ yr = img_yres(idict);
+ if (x <= 0 || y <= 0 || xr < 0 || yr < 0)
+ normal_error("pdf backend","invalid image dimensions");
+ if (xr > 65535 || yr > 65535) {
+ xr = 0;
+ yr = 0;
+ normal_warning("pdf backend","too large image resolution ignored");
+ }
+ if (((transform - img_rotation(idict)) & 1) == 1) {
+ tmp = x;
+ x = y;
+ y = tmp;
+ tmp = xr;
+ xr = yr;
+ yr = tmp;
}
- if (xr > 0 && yr > 0) {
- nat.wd = ext_xn_over_d(one_hundred_inch, x, 100 * xr);
- nat.ht = ext_xn_over_d(one_hundred_inch, y, 100 * yr);
+ /*tex always for images */
+ if (img_type(idict) == IMG_TYPE_PDF || img_type(idict) == IMG_TYPE_PDFMEMSTREAM
+ || img_type(idict) == IMG_TYPE_PDFSTREAM) {
+ nat.wd = x;
+ nat.ht = y;
} else {
- nat.wd = ext_xn_over_d(one_hundred_inch, x, 7200);
- nat.ht = ext_xn_over_d(one_hundred_inch, y, 7200);
+ default_res = fix_int(pdf_image_resolution, 0, 65535);
+ if (default_res > 0 && (xr == 0 || yr == 0)) {
+ xr = default_res;
+ yr = default_res;
+ }
+ if (xr > 0 && yr > 0) {
+ nat.wd = ext_xn_over_d(one_hundred_inch, x, 100 * xr);
+ nat.ht = ext_xn_over_d(one_hundred_inch, y, 100 * yr);
+ } else {
+ nat.wd = ext_xn_over_d(one_hundred_inch, x, 7200);
+ nat.ht = ext_xn_over_d(one_hundred_inch, y, 7200);
+ }
}
}
return tex_scale(nat, alt_rule);
@@ -642,26 +657,32 @@ void pdf_write_image(PDF pdf, int n)
void check_pdfstream_dict(image_dict * idict)
{
- if (!img_is_bbox(idict))
+ if (!img_is_bbox(idict) && !img_nobbox(idict)) {
normal_error("pdf backend","image.stream: no bbox given");
- if (img_state(idict) < DICT_FILESCANNED)
+ }
+ if (img_state(idict) < DICT_FILESCANNED) {
img_state(idict) = DICT_FILESCANNED;
+ }
}
void write_pdfstream(PDF pdf, image_dict * idict)
{
pdf_begin_obj(pdf, img_objnum(idict), OBJSTM_NEVER);
pdf_begin_dict(pdf);
- pdf_dict_add_name(pdf, "Type", "XObject");
- pdf_dict_add_name(pdf, "Subtype", "Form");
- pdf_dict_add_int(pdf, "FormType", 1);
- pdf_add_name(pdf, "BBox");
- pdf_begin_array(pdf);
- pdf_add_real(pdf, sp2bp(img_bbox(idict)[0]));
- pdf_add_real(pdf, sp2bp(img_bbox(idict)[1]));
- pdf_add_real(pdf, sp2bp(img_bbox(idict)[2]));
- pdf_add_real(pdf, sp2bp(img_bbox(idict)[3]));
- pdf_end_array(pdf);
+ if (!img_notype(idict)) {
+ pdf_dict_add_name(pdf, "Type", "XObject");
+ pdf_dict_add_name(pdf, "Subtype", "Form");
+ pdf_dict_add_int(pdf, "FormType", 1);
+ }
+ if (!img_nobbox(idict)) {
+ pdf_add_name(pdf, "BBox");
+ pdf_begin_array(pdf);
+ pdf_add_real(pdf, sp2bp(img_bbox(idict)[0]));
+ pdf_add_real(pdf, sp2bp(img_bbox(idict)[1]));
+ pdf_add_real(pdf, sp2bp(img_bbox(idict)[2]));
+ pdf_add_real(pdf, sp2bp(img_bbox(idict)[3]));
+ pdf_end_array(pdf);
+ }
if (img_attr(idict) != NULL && strlen(img_attr(idict)) > 0) {
pdf_printf(pdf, "\n%s\n", img_attr(idict));
}