xs/render_page.xs

filter: Statementstmt 10.5% 8 / 76 Branchbran 22.5% 14 / 62 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 15.9% 22 / 138 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/signature.xs ↑ Summary src/pdfmake_glyphlist.c »
1 MODULE = PDF::Make::RenderPage PACKAGE = PDF::Make::RenderPage
2  
3 PROTOTYPES: DISABLE
4  
5 SV *
6 render_page(reader_sv, page_num, opts_hv = NULL)
7 SV *reader_sv
8 int page_num
9 HV *opts_hv
10 PREINIT:
11 pdfmake_reader_t *reader;
12 pdfmake_render_opts_t opts;
13 pdfmake_page_render_t result;
14 pdfmake_err_t err;
15 CODE:
16 {
17 0 ▶ if (!sv_isobject(reader_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(reader_sv)) { 0 0 0
18 0 croak("Expected PDF::Make::Reader object");
19 }
20
21 /* Get reader pointer */
22 0 IV tmp = SvIV(SvRV(reader_sv));
23 0 reader = INT2PTR(pdfmake_reader_t *, tmp);
24 0 ▶ if (!reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (!reader) { 0 0 0
25 0 croak("Invalid reader object");
26 }
27
28 /* Convert options */
29 0 hv_to_render_opts(aTHX_ opts_hv, &opts);
30
31 /* Render page */
32 0 err = pdfmake_render_page_to_pixels(reader, page_num, &opts, &result);
33 0 ▶ if (err != PDFMAKE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (err != PDFMAKE_OK) { 0 0 0
34 0 croak("Failed to render page %d: error %d", page_num, (int)err);
35 }
36
37 /* Build result hash */
38 0 HV *rv = newHV();
39
40 /* Pixels as packed binary string */
41 0 size_t pixel_bytes = result.width * result.height * sizeof(uint32_t);
42 0 SV *pixels_sv = newSVpvn((char *)result.pixels, pixel_bytes);
43 0 hv_stores(rv, "pixels", pixels_sv);
44
45 /* Dimensions */
46 0 hv_stores(rv, "width", newSViv(result.width));
47 0 hv_stores(rv, "height", newSViv(result.height));
48 0 hv_stores(rv, "stride", newSViv(result.stride));
49
50 /* Page info */
51 0 hv_stores(rv, "page_width", newSVnv(result.page_width));
52 0 hv_stores(rv, "page_height", newSVnv(result.page_height));
53 0 hv_stores(rv, "effective_dpi", newSVnv(result.effective_dpi));
54
55 /* Statistics */
56 0 hv_stores(rv, "text_objects", newSViv(result.text_objects));
57 0 hv_stores(rv, "path_objects", newSViv(result.path_objects));
58 0 hv_stores(rv, "image_objects", newSViv(result.image_objects));
59 0 hv_stores(rv, "render_time_ms", newSVnv(result.render_time_ms));
60 0 hv_stores(rv, "error_count", newSViv(result.error_count));
61
62 0 ▶ if (result.error_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (result.error_count > 0) { 0 0 0
63 0 hv_stores(rv, "error_msg", newSVpv(result.error_msg, 0));
64 }
65
66 /* Free the pixel buffer */
67 0 pdfmake_page_render_free(&result);
68
69 0 RETVAL = newRV_noinc((SV *)rv);
70 }
71 OUTPUT:
72 RETVAL
73  
74 SV *
75 render_page_region(reader_sv, page_num, region_x, region_y, region_w, region_h, opts_hv = NULL)
76 SV *reader_sv
77 int page_num
78 double region_x
79 double region_y
80 double region_w
81 double region_h
82 HV *opts_hv
83 PREINIT:
84 pdfmake_reader_t *reader;
85 pdfmake_render_opts_t opts;
86 pdfmake_page_render_t result;
87 pdfmake_err_t err;
88 CODE:
89 {
90 0 ▶ if (!sv_isobject(reader_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(reader_sv)) { 0 0 0
91 0 croak("Expected PDF::Make::Reader object");
92 }
93
94 0 IV tmp = SvIV(SvRV(reader_sv));
95 0 reader = INT2PTR(pdfmake_reader_t *, tmp);
96 0 ▶ if (!reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (!reader) { 0 0 0
97 0 croak("Invalid reader object");
98 }
99
100 0 hv_to_render_opts(aTHX_ opts_hv, &opts);
101
102 0 err = pdfmake_render_page_region(reader, page_num,
103 region_x, region_y, region_w, region_h,
104 &opts, &result);
105 0 ▶ if (err != PDFMAKE_OK) {
Branch: 1 branch
BranchTrueFalseTotal
if (err != PDFMAKE_OK) { 0 0 0
106 0 croak("Failed to render page region: error %d", (int)err);
107 }
108
109 0 HV *rv = newHV();
110
111 0 size_t pixel_bytes = result.width * result.height * sizeof(uint32_t);
112 0 hv_stores(rv, "pixels", newSVpvn((char *)result.pixels, pixel_bytes));
113 0 hv_stores(rv, "width", newSViv(result.width));
114 0 hv_stores(rv, "height", newSViv(result.height));
115 0 hv_stores(rv, "stride", newSViv(result.stride));
116 0 hv_stores(rv, "page_width", newSVnv(result.page_width));
117 0 hv_stores(rv, "page_height", newSVnv(result.page_height));
118 0 hv_stores(rv, "effective_dpi", newSVnv(result.effective_dpi));
119 0 hv_stores(rv, "render_time_ms", newSVnv(result.render_time_ms));
120
121 0 pdfmake_page_render_free(&result);
122
123 0 RETVAL = newRV_noinc((SV *)rv);
124 }
125 OUTPUT:
126 RETVAL
127  
128 void
129 get_page_render_size(reader_sv, page_num, dpi)
130 SV *reader_sv
131 int page_num
132 double dpi
133 PREINIT:
134 pdfmake_reader_t *reader;
135 int width, height;
136 PPCODE:
137 {
138 0 ▶ if (!sv_isobject(reader_sv)) {
Branch: 1 branch
BranchTrueFalseTotal
if (!sv_isobject(reader_sv)) { 0 0 0
139 0 croak("Expected PDF::Make::Reader object");
140 }
141
142 0 IV tmp = SvIV(SvRV(reader_sv));
143 0 reader = INT2PTR(pdfmake_reader_t *, tmp);
144 0 ▶ if (!reader) {
Branch: 1 branch
BranchTrueFalseTotal
if (!reader) { 0 0 0
145 0 croak("Invalid reader object");
146 }
147
148 0 pdfmake_page_get_render_size(reader, page_num, dpi, &width, &height);
149
150 0 ▶ EXTEND(SP, 2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 2); 0 0 0
151 0 PUSHs(sv_2mortal(newSViv(width)));
152 0 PUSHs(sv_2mortal(newSViv(height)));
153 }
154  
155 int
156 SCALE_NEAREST()
157 CODE:
158 0 ▶ RETVAL = PDFMAKE_SCALE_NEAREST;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_SCALE_NEAREST; 0 0 0
159 OUTPUT:
160 RETVAL
161  
162 int
163 SCALE_BILINEAR()
164 CODE:
165 0 ▶ RETVAL = PDFMAKE_SCALE_BILINEAR;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_SCALE_BILINEAR; 0 0 0
166 OUTPUT:
167 RETVAL
168  
169 int
170 SCALE_BICUBIC()
171 CODE:
172 0 ▶ RETVAL = PDFMAKE_SCALE_BICUBIC;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_SCALE_BICUBIC; 0 0 0
173 OUTPUT:
174 RETVAL
175  
176 int
177 ROTATE_0()
178 CODE:
179 0 ▶ RETVAL = PDFMAKE_ROTATE_0;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_ROTATE_0; 0 0 0
180 OUTPUT:
181 RETVAL
182  
183 int
184 ROTATE_90()
185 CODE:
186 0 ▶ RETVAL = PDFMAKE_ROTATE_90;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_ROTATE_90; 0 0 0
187 OUTPUT:
188 RETVAL
189  
190 int
191 ROTATE_180()
192 CODE:
193 0 ▶ RETVAL = PDFMAKE_ROTATE_180;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_ROTATE_180; 0 0 0
194 OUTPUT:
195 RETVAL
196  
197 int
198 ROTATE_270()
199 CODE:
200 0 ▶ RETVAL = PDFMAKE_ROTATE_270;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = PDFMAKE_ROTATE_270; 0 0 0
201 OUTPUT:
202 RETVAL
203  
204 BOOT:
205 {
206 104 HV *stash = gv_stashpv("PDF::Make::RenderPage", GV_ADD);
207 104 ▶ PDFMAKE_REGISTER_CONST(stash, "SCALE_NEAREST", PDFMAKE_SCALE_NEAREST);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "SCALE_NEAREST", PDFMAKE_SCALE_NEAREST); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "SCALE_NEAREST", PDFMAKE_SCALE_NEAREST); 104 0 104
208 104 ▶ PDFMAKE_REGISTER_CONST(stash, "SCALE_BILINEAR", PDFMAKE_SCALE_BILINEAR);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "SCALE_BILINEAR", PDFMAKE_SCALE_BILINEAR); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "SCALE_BILINEAR", PDFMAKE_SCALE_BILINEAR); 104 0 104
209 104 ▶ PDFMAKE_REGISTER_CONST(stash, "SCALE_BICUBIC", PDFMAKE_SCALE_BICUBIC);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "SCALE_BICUBIC", PDFMAKE_SCALE_BICUBIC); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "SCALE_BICUBIC", PDFMAKE_SCALE_BICUBIC); 104 0 104
210 104 ▶ PDFMAKE_REGISTER_CONST(stash, "ROTATE_0", PDFMAKE_ROTATE_0);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "ROTATE_0", PDFMAKE_ROTATE_0); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "ROTATE_0", PDFMAKE_ROTATE_0); 104 0 104
211 104 ▶ PDFMAKE_REGISTER_CONST(stash, "ROTATE_90", PDFMAKE_ROTATE_90);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "ROTATE_90", PDFMAKE_ROTATE_90); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "ROTATE_90", PDFMAKE_ROTATE_90); 104 0 104
212 104 ▶ PDFMAKE_REGISTER_CONST(stash, "ROTATE_180", PDFMAKE_ROTATE_180);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "ROTATE_180", PDFMAKE_ROTATE_180); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "ROTATE_180", PDFMAKE_ROTATE_180); 104 0 104
213 104 ▶ PDFMAKE_REGISTER_CONST(stash, "ROTATE_270", PDFMAKE_ROTATE_270);
Branch: 2 branches
BranchTrueFalseTotal
PDFMAKE_REGISTER_CONST(stash, "ROTATE_270", PDFMAKE_ROTATE_270); 104 0 104
PDFMAKE_REGISTER_CONST(stash, "ROTATE_270", PDFMAKE_ROTATE_270); 104 0 104
214 }
« xs/signature.xs ↑ Summary src/pdfmake_glyphlist.c »