3 # this needs to be kept in sync with the array of hatches in fills.c
5 qw/check1x1 check2x2 check4x4 vline1 vline2 vline4
6 hline1 hline2 hline4 slash1 slosh1 slash2 slosh2
7 grid1 grid2 grid4 dots1 dots4 dots16 stipple weave cross1 cross2
8 vlozenge hlozenge scalesdown scalesup scalesleft scalesright stipple2
11 @hatch_types{@hatch_types} = 0..$#hatch_types;
14 my ($class, %hsh) = @_;
16 my $self = bless { }, $class;
19 if (UNIVERSAL::isa($hsh{solid}, 'Imager::Color')) {
20 $self->{fill} = Imager::i_new_fill_solid($hsh{solid}, $hsh{combine});
22 elsif (UNIVERSAL::isa($hsh{colid}, 'Imager::Color::Float')) {
23 $self->{fill} = Imager::i_new_fill_solidf($hsh{solid}, $hsh{combine});
26 $Imager::ERRSTR = "solid isn't a color";
30 elsif (defined $hsh{hatch}) {
33 $hsh{fg} ||= Imager::Color->new(0, 0, 0);
34 if (ref $hsh{hatch}) {
35 $hsh{cust_hatch} = pack("C8", @{$hsh{hatch}});
38 elsif ($hsh{hatch} =~ /\D/) {
39 unless (exists($hatch_types{$hsh{hatch}})) {
40 $Imager::ERRSTR = "Unknown hatch type $hsh{hatch}";
43 $hsh{hatch} = $hatch_types{$hsh{hatch}};
45 if (UNIVERSAL::isa($hsh{fg}, 'Imager::Color')) {
46 $hsh{bg} ||= Imager::Color->new(255, 255, 255);
48 Imager::i_new_fill_hatch($hsh{fg}, $hsh{bg}, $hsh{combine},
49 $hsh{hatch}, $hsh{cust_hatch},
52 elsif (UNIVERSAL::isa($hsh{bg}, 'Imager::Color::Float')) {
53 $hsh{bg} ||= Imager::Color::Float->new(1, 1, 1);
55 Imager::i_new_fill_hatchf($hsh{fg}, $hsh{bg}, $hsh{combine},
56 $hsh{hatch}, $hsh{cust_hatch},
60 $Imager::ERRSTR = "fg isn't a color";
64 elsif (defined $hsh{fountain}) {
65 # make sure we track the filter's defaults
66 my $fount = $Imager::filters{fountain};
67 my $def = $fount->{defaults};
68 my $names = $fount->{names};
70 $hsh{ftype} = $hsh{fountain};
71 # process names of values
72 for my $name (keys %$names) {
73 if (defined $hsh{$name} && exists $names->{$name}{$hsh{$name}}) {
74 $hsh{$name} = $names->{$name}{$hsh{$name}};
79 my @parms = @{$fount->{callseq}};
81 for my $name (@parms) {
82 unless (defined $hsh{$name}) {
84 "required parameter '$name' not set for fountain fill";
90 Imager::i_new_fill_fount($hsh{xa}, $hsh{ya}, $hsh{xb}, $hsh{yb},
91 $hsh{ftype}, $hsh{repeat}, $hsh{combine}, $hsh{super_sample},
92 $hsh{ssample_param}, $hsh{segments});
95 $Imager::ERRSTR = "No fill type specified";
111 Imager::Fill - general fill types
115 my $fill1 = Imager::Fill->new(solid=>$color, combine=>$combine);
116 my $fill2 = Imager::Fill->new(hatch=>'vline2', fg=>$color1, bg=>$color2,
121 Creates fill objects for use by some drawing functions, currently just
122 the Imager box() method.
124 The currently available fills are:
138 fountain (similar to gradients in paint software)
142 =head1 Common options
148 If this is non-zero the fill combines the given colors or samples (if
149 the fill is an image) with the underlying image.
151 This this is missing or zero then the target image pixels are simply
156 In general colors can be specified as Imager::Color or
157 Imager::Color::Float objects. The fill object will typically store
158 both types and convert from one to the other. If a fill takes 2 color
159 objects they should have the same type.
163 my $fill = Imager::Fill->new(solid=>$color, $combine =>$combine)
165 Creates a solid fill, the only required parameter is C<solid> which
166 should be the color to fill with.
170 my $fill = Imager::Fill->new(hatch=>$type, fg=>$fgcolor, bg=>$bgcolor,
173 Creates a hatched fill. You can specify the following keywords:
179 The type of hatch to perform, this can either be the numeric index of
180 the hatch (not recommended), the symbolic name of the hatch, or an
181 array of 8 integers which specify the pattern of the hatch.
183 Hatches are represented as cells 8x8 arrays of bits, which limits their
186 Current hatch names are:
190 =item check1x1, check2x2, check4x4
192 checkerboards at varios sizes
194 =item vline1, vline2, vline4
196 1, 2, or 4 vertical lines per cell
198 =item hline1, hline2, hline4
200 1, 2, or 4 horizontal lines per cell
204 1 or 2 / lines per cell.
208 1 or 2 \ lines per cell
210 =item grid1, grid2, grid4
212 1, 2, or 4 vertical and horizontal lines per cell
214 =item dots1, dots4, dots16
216 1, 4 or 16 dots per cell
218 =item stipple, stipple2
224 I hope this one is obvious.
228 2 densities of crosshatch
230 =item vlozenge, hlozenge
232 something like lozenge tiles
234 =item scalesdown, scalesup, scalesleft, scalesright
236 Vaguely like fish scales in each direction.
248 The fg color is rendered where bits are set in the hatch, and the bg
249 where they are clear. If you use a transparent fg or bg, and set
250 combine, you can overlay the hatch onto an existing image.
252 fg defaults to black, bg to white.
258 An offset into the hatch cell. Both default to zero.
262 You can call Imager::Fill->hatches for a list of hatch names.
264 =head2 Fountain fills
266 my $fill = Imager::Fill->new(fountain=>$ftype,
267 xa=>$xa, ya=>$ya, xb=>$xb, yb=>$yb,
268 segment=>$segments, repeat=>$repeat, combine=>$combine,
269 super_sample=>$super_sample, ssample_param=>$ssample_param);
271 This fills the given region with a fountain fill. This is exactly the
272 same fill as the C<fountain> filter, but is restricted to the shape
273 you are drawing, and the fountain parameter supplies the fill type,
278 I'm planning on adding the following types of fills:
288 combines 2 other fills in a checkerboard
292 combines 2 other fills using the levels of an image
296 uses the transform2() register machine to create fills
302 Tony Cook <tony@develop-help.com>