| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package PDF::Make::Render; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
77733
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
32
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
38
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Carp qw(croak); |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
96
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.03'; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# Load the XS module |
|
10
|
|
|
|
|
|
|
require PDF::Make; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
PDF::Make::Render - Native path rendering for PDF content |
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use PDF::Make::Render; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Create a render context |
|
21
|
|
|
|
|
|
|
my $ctx = PDF::Make::Render->new(800, 600); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Set up graphics state |
|
24
|
|
|
|
|
|
|
$ctx->save; |
|
25
|
|
|
|
|
|
|
$ctx->set_fill_color(1, 0, 0); # Red |
|
26
|
|
|
|
|
|
|
$ctx->set_stroke_color(0, 0, 0); |
|
27
|
|
|
|
|
|
|
$ctx->set_line_width(2); |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Build a path |
|
30
|
|
|
|
|
|
|
$ctx->move_to(100, 100); |
|
31
|
|
|
|
|
|
|
$ctx->line_to(200, 100); |
|
32
|
|
|
|
|
|
|
$ctx->line_to(200, 200); |
|
33
|
|
|
|
|
|
|
$ctx->close_path; |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# Render |
|
36
|
|
|
|
|
|
|
$ctx->fill; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
$ctx->restore; |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# Get pixel data |
|
41
|
|
|
|
|
|
|
my $pixels = $ctx->get_pixels; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
PDF::Make::Render provides a native path rendering engine for PDF content. |
|
46
|
|
|
|
|
|
|
It implements PDF's imaging model including paths, fills, strokes, clipping, |
|
47
|
|
|
|
|
|
|
and transformations. |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 METHODS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 new($width, $height) |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Create a new render context with the specified dimensions. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 width / height |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Get the dimensions of the render context. |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head2 clear($r, $g, $b, $a) |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Clear the context to the specified color. |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 save / restore |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Save or restore graphics state. |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head2 Path Building |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=over 4 |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=item move_to($x, $y) |
|
72
|
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
Begin a new subpath. |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item line_to($x, $y) |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Add a line segment. |
|
78
|
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=item curve_to($x1, $y1, $x2, $y2, $x3, $y3) |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Add a cubic Bezier curve. |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=item close_path |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Close the current subpath. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item rectangle($x, $y, $w, $h) |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Add a rectangle to the path. |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 Path Painting |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=over 4 |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=item fill |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Fill the current path using non-zero winding rule. |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item stroke |
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Stroke the current path. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item fill_stroke |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Fill and stroke the current path. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item clip |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Clip to the current path. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head2 Color |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=over 4 |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item set_fill_color($r, $g, $b, $a) |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Set the fill color. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=item set_stroke_color($r, $g, $b, $a) |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Set the stroke color. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=back |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head2 Line Properties |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=over 4 |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=item set_line_width($width) |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Set the line width. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=item set_line_cap($cap) |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Set line cap style (0=butt, 1=round, 2=square). |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item set_line_join($join) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Set line join style (0=miter, 1=round, 2=bevel). |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item set_miter_limit($limit) |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Set the miter limit. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=back |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
=head2 Transformations |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=over 4 |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=item set_matrix($a, $b, $c, $d, $e, $f) |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
Set the current transformation matrix. |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item concat_matrix($a, $b, $c, $d, $e, $f) |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
Concatenate a matrix with the current CTM. |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=back |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head2 Output |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=over 4 |
|
168
|
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=item get_pixels |
|
170
|
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
Get the raw pixel data as a scalar (RGBA format). |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=item get_pixel($x, $y) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Get a single pixel as ($r, $g, $b, $a). |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=back |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 CONSTANTS |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head2 Line Cap |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
PDFMAKE_LINE_CAP_BUTT = 0 |
|
184
|
|
|
|
|
|
|
PDFMAKE_LINE_CAP_ROUND = 1 |
|
185
|
|
|
|
|
|
|
PDFMAKE_LINE_CAP_SQUARE = 2 |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head2 Line Join |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
PDFMAKE_LINE_JOIN_MITER = 0 |
|
190
|
|
|
|
|
|
|
PDFMAKE_LINE_JOIN_ROUND = 1 |
|
191
|
|
|
|
|
|
|
PDFMAKE_LINE_JOIN_BEVEL = 2 |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# Export constants |
|
196
|
|
|
|
|
|
|
use constant { |
|
197
|
1
|
|
|
|
|
138
|
LINE_CAP_BUTT => 0, |
|
198
|
|
|
|
|
|
|
LINE_CAP_ROUND => 1, |
|
199
|
|
|
|
|
|
|
LINE_CAP_SQUARE => 2, |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
LINE_JOIN_MITER => 0, |
|
202
|
|
|
|
|
|
|
LINE_JOIN_ROUND => 1, |
|
203
|
|
|
|
|
|
|
LINE_JOIN_BEVEL => 2, |
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
FILL_RULE_NONZERO => 0, |
|
206
|
|
|
|
|
|
|
FILL_RULE_EVENODD => 1, |
|
207
|
1
|
|
|
1
|
|
4
|
}; |
|
|
1
|
|
|
|
|
1
|
|
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
# Nothing else needed - XS provides all the methods |
|
210
|
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
1; |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
__END__ |