3
Copyright 2009 Taco Hoekwater <taco@luatex.org>
5
This file is part of LuaTeX.
7
LuaTeX is free software; you can redistribute it and/or modify it under
8
the terms of the GNU General Public License as published by the Free
9
Software Foundation; either version 2 of the License, or (at your
10
option) any later version.
12
LuaTeX is distributed in the hope that it will be useful, but WITHOUT
13
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
15
License for more details.
17
You should have received a copy of the GNU General Public License along
18
with LuaTeX; if not, see <http://www.gnu.org/licenses/>. */
20
static const char __svn_version[] =
21
"$Id: pdfimage.c 3261 2009-12-18 11:38:21Z taco $"
22
"$URL: http://foundry.supelec.fr/svn/luatex/tags/beta-0.50.0/source/texk/web2c/luatexdir/pdf/pdfimage.c $";
26
void place_img(PDF pdf, image_dict * idict, scaled_whd dim, int transform)
28
float a[6]; /* transformation matrix */
29
float xoff, yoff, tmp;
30
pdfstructure *p = pdf->pstruct;
31
scaledpos pos = pdf->posstruct->pos;
32
int r; /* number of digits after the decimal point */
36
int groupref; /* added from web for 1.40.8 */
41
if (img_type(idict) == IMG_TYPE_PDF
42
|| img_type(idict) == IMG_TYPE_PDFSTREAM) {
43
a[0] /= img_xsize(idict);
44
a[3] /= img_ysize(idict);
45
xoff = (float) img_xorig(idict) / img_xsize(idict);
46
yoff = (float) img_yorig(idict) / img_ysize(idict);
49
/* added from web for 1.40.8 */
50
if (img_type(idict) == IMG_TYPE_PNG) {
51
groupref = img_group_ref(idict);
52
if ((groupref > 0) && (pdf->img_page_group_val == 0))
53
pdf->img_page_group_val = groupref;
56
a[0] /= one_hundred_bp;
61
if ((transform & 7) > 3) { // mirror cases
65
switch ((transform + img_rotation(idict)) & 3) {
66
case 0: /* no transform */
68
case 1: /* rot. 90 deg. (counterclockwise) */
76
case 2: /* rot. 180 deg. (counterclockwise) */
82
case 3: /* rot. 270 deg. (counterclockwise) */
93
yoff *= dim.ht + dim.dp;
95
a[1] *= dim.ht + dim.dp;
97
a[3] *= dim.ht + dim.dp;
100
k = transform + img_rotation(idict);
101
if ((transform & 7) > 3)
104
case 0: /* no transform */
106
case 1: /* rot. 90 deg. (counterclockwise) */
109
case 2: /* rot. 180 deg. */
111
a[5] += dim.ht + dim.dp;
113
case 3: /* rot. 270 deg. */
114
a[5] += dim.ht + dim.dp;
118
/* the following is a kludge, TODO: use pdfpage.c functions */
119
setpdffloat(cm[0], round(a[0]), r);
120
setpdffloat(cm[1], round(a[1]), r);
121
setpdffloat(cm[2], round(a[2]), r);
122
setpdffloat(cm[3], round(a[3]), r);
123
tmppos.h = round(a[4]);
124
tmppos.v = round(a[5]);
125
pdf_goto_pagemode(pdf);
126
(void) calc_pdfpos(p, tmppos);
129
if (pdf->img_page_group_val == 0)
130
pdf->img_page_group_val = img_group_ref(idict); /* added from web for 1.40.8 */
131
pdf_printf(pdf, "q\n");
132
pdf_print_cm(pdf, cm);
133
pdf_printf(pdf, "/Im");
134
pdf_print_int(pdf, img_index(idict));
135
pdf_print_resname_prefix(pdf);
136
pdf_printf(pdf, " Do\nQ\n");
137
if (lookup_object_list(pdf, obj_type_ximage, img_objnum(idict)) == NULL)
138
append_object_list(pdf, obj_type_ximage, img_objnum(idict));
139
if (img_state(idict) < DICT_OUTIMG)
140
img_state(idict) = DICT_OUTIMG;
143
/* for normal output, see pdflistout.c */
145
void pdf_place_image(PDF pdf, halfword p)
148
image_dict *idict = idict_array[pdf_ximage_index(p)];
149
assert(idict != NULL);
153
place_img(pdf, idict, dim, pdf_ximage_transform(p));