3 % Copyright
2009-2010 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
/>.
25 void place_img
(PDF pdf
, image_dict
* idict
, scaled_whd dim
, int transform
)
27 float a
[6]; /* transformation matrix
*/
28 float xoff
, yoff
, tmp
;
29 pdfstructure
*p
= pdf-
>pstruct
;
30 scaledpos pos
= pdf-
>posstruct-
>pos
;
31 int r
; /* number of digits after the decimal point
*/
35 int groupref
; /* added from web for
1.40.8 */
38 if
(img_type
(idict
) == IMG_TYPE_PDF || img_type
(idict
) == IMG_TYPE_PDFMEMSTREAM
39 || img_type
(idict
) == IMG_TYPE_PDFSTREAM
) {
40 a
[0] /= (float
) img_xsize
(idict
);
41 a
[3] /= (float
) img_ysize
(idict
);
42 xoff
= (float
) img_xorig
(idict
) / (float
) img_xsize
(idict
);
43 yoff
= (float
) img_yorig
(idict
) / (float
) img_ysize
(idict
);
46 /* added from web for
1.40.8 */
47 if
(img_type
(idict
) == IMG_TYPE_PNG
) {
48 groupref
= img_group_ref
(idict
);
49 if
((groupref
> 0) && (pdf->img_page_group_val == 0))
50 pdf-
>img_page_group_val
= groupref
;
53 a
[0] /= (float
) one_hundred_bp
;
58 if
((transform
& 7) > 3) { /* mirror cases */
62 switch
((transform
+ img_rotation
(idict
)) & 3) {
63 case
0: /* no transform
*/
65 case
1: /* rot.
90 deg.
(counterclockwise
) */
73 case
2: /* rot.
180 deg.
(counterclockwise
) */
79 case
3: /* rot.
270 deg.
(counterclockwise
) */
89 xoff
*= (float
) dim.wd
;
90 yoff
*= (float
) (dim.ht
+ dim.dp
);
91 a
[0] *= (float
) dim.wd
;
92 a
[1] *= (float
) (dim.ht
+ dim.dp
);
93 a
[2] *= (float
) dim.wd
;
94 a
[3] *= (float
) (dim.ht
+ dim.dp
);
95 a
[4] = (float
) pos.h
- xoff
;
96 a
[5] = (float
) pos.v
- yoff
;
97 k
= transform
+ img_rotation
(idict
);
98 if
((transform
& 7) > 3)
101 case
0: /* no transform
*/
103 case
1: /* rot.
90 deg.
(counterclockwise
) */
104 a
[4] += (float
) dim.wd
;
106 case
2: /* rot.
180 deg.
*/
107 a
[4] += (float
) dim.wd
;
108 a
[5] += (float
) (dim.ht
+ dim.dp
);
110 case
3: /* rot.
270 deg.
*/
111 a
[5] += (float
) (dim.ht
+ dim.dp
);
115 /* the following is a kludge
, TODO
: use pdfpage.c functions
*/
116 setpdffloat
(cm
[0], i64round
(a
[0]), r
);
117 setpdffloat
(cm
[1], i64round
(a
[1]), r
);
118 setpdffloat
(cm
[2], i64round
(a
[2]), r
);
119 setpdffloat
(cm
[3], i64round
(a
[3]), r
);
120 tmppos.h
= round
(a
[4]);
121 tmppos.v
= round
(a
[5]);
122 pdf_goto_pagemode
(pdf
);
123 (void
) calc_pdfpos
(p
, tmppos
);
126 if
(pdf-
>img_page_group_val
== 0)
127 pdf-
>img_page_group_val
= img_group_ref
(idict
); /* added from web for
1.40.8 */
128 pdf_puts
(pdf
, "q\n");
129 pdf_print_cm
(pdf
, cm
);
130 pdf_puts
(pdf
, "/Im");
131 pdf_print_int
(pdf
, img_index
(idict
));
132 pdf_print_resname_prefix
(pdf
);
133 pdf_puts
(pdf
, " Do\nQ\n");
134 addto_page_resources
(pdf
, obj_type_ximage
, img_objnum
(idict
));
135 if
(img_state
(idict
) < DICT_OUTIMG
)
136 img_state
(idict
) = DICT_OUTIMG
;
139 @ for normal output
, see \.
{pdflistout.w
}
142 void pdf_place_image
(PDF pdf
, halfword p
)
145 image_dict
*idict
= idict_array
[rule_index
(p
)];
149 place_img
(pdf
, idict
, dim
, rule_transform
(p
));