Skip to content

Commit

Permalink
all AA plotting is supported internally
Browse files Browse the repository at this point in the history
Prima::Drawable::Antialias is not used anymore for the emulated AA drawing
  • Loading branch information
dk committed Jul 29, 2024
1 parent ad49387 commit 4a346a0
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 33 deletions.
6 changes: 4 additions & 2 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ Revision history for Perl module Prima

1.74 2024-XX-XX
- implement antialiased polygon fill in C, use it in the
AA emulation in Prima::Drawable::Alntialias instead of the old algorithm
- add kb:: definitions for internet keyboards
AA emulation in Prima::Drawable::Antialias instead of the old algorithm
- all AA plotting is supported internally, Prima::Drawable::Antialias is
not used for the emulated AA drawing
- add kb:: definitions for the internet keyboards

1.73 2024-05-07
- add Prima::Image::Exif, support jpeg tags
Expand Down
2 changes: 1 addition & 1 deletion Prima.pm
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ L<Prima::Dialog::PrintDialog> - standard printer setup dialog
=item Drawing helpers
L<Prima::Drawable::Antialias> - plot antialiased shapes
L<Prima::Drawable::Antialias> - alternative API for antialiased shapes
L<Prima::Drawable::CurvedText> - fit text to path
Expand Down
11 changes: 8 additions & 3 deletions Prima/Drawable/Antialias.pm
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ sub polyline
$solid_line = 1;
}

my $render = $canvas->new_path(antialias => 1)->line($poly);
my $render = $canvas->new_path(subpixel => 1)->line($poly);
if ( $solid_line ) {
my $c = $canvas->color;
$canvas->color($canvas->backColor);
Expand Down Expand Up @@ -168,7 +168,7 @@ FALLBACK:
=head1 NAME
Prima::Drawable::Antialias - plot antialiased shapes
Prima::Drawable::Antialias - alternative API for antialiased shapes
=head1 DESCRIPTION
Expand All @@ -179,11 +179,16 @@ The module augments the C<Prima::Drawable> drawing functionality by adding the
C<new_aa_surface> function, which features two plotting methods, C<polyline>
and C<fillpoly>, identical to the ones in C<Prima::Drawable>.
The emulation method in the module used to be the backend and the only
implementation of antialiased shapes, but as Prima now supports that
internally, this module is not used anymore. It is still functional though and
can be used as an alternative.
=head1 SYNOPSIS
$canvas-> new_aa_surface-> polyline([0, 0, 100, 100]);
$canvas-> new_path(antialias => 1)-> ellipse(100,100,100)->fill;
$canvas-> new_path(subpixel => 1)-> ellipse(100,100,100)->fill;
=for podview <img src="Prima/aa.gif">
Expand Down
10 changes: 5 additions & 5 deletions Prima/Drawable/Basic.pm
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ sub stroke_img_primitive
return 1 if $self->linePattern eq lp::Null && $self->rop2 == rop::NoOper;

my $single_pixel = $self->lineWidth < 1.5;
my $path = $self->new_path( antialias => !$single_pixel);
my $path = $self->new_path( subpixel => !$single_pixel);
my $matrix = $self-> get_matrix;
$path->matrix( $matrix );
$path->$request(@_);
Expand Down Expand Up @@ -384,7 +384,7 @@ sub stroke_imgaa_primitive
my $lp = $self->linePattern;
return 1 if $lp eq lp::Null && $self->rop2 == rop::NoOper;

my $path = $self->new_path( antialias => 1 );
my $path = $self->new_path( subpixel => 1 );
$path->$request(@_);
my $path2 = $path->widen(
linePattern => ( $lp eq lp::Null) ? lp::Solid : $lp
Expand Down Expand Up @@ -428,7 +428,7 @@ sub stroke_primitive
return 1 if $lp eq lp::Null && $self->rop2 == rop::NoOper;

my $single_pixel = !$self->antialias && $self->alpha == 255 && $self->lineWidth < 1.5;
my $path = $self->new_path( antialias => !$single_pixel);
my $path = $self->new_path( subpixel => !$single_pixel);
$path->matrix( $self-> matrix );
$path->$request(@_);

Expand All @@ -442,7 +442,7 @@ sub stroke_primitive
linePattern => ( $lp eq lp::Null) ? lp::Solid : $lp,
(!$self->antialias && $self->lineWidth == 0) ? (lineWidth => 1) : (),
);
$path2->antialias( $self-> antialias );
$path2->subpixel( $self-> antialias );
return unless $self->graphic_context_push;
$self-> matrix-> identity;
$self->fillPattern(fp::Solid);
Expand All @@ -454,7 +454,7 @@ sub stroke_primitive
linePattern => lp::Solid,
(!$self->antialias && $self->lineWidth == 0) ? (lineWidth => 1) : (),
);
$path3->antialias( $self-> antialias );
$path3->subpixel( $self-> antialias );
$path3->fill;
$self->color($c);
}
Expand Down
28 changes: 7 additions & 21 deletions Prima/Drawable/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use constant Y => 5;
sub new
{
my ( $class, $canvas, %opt ) = @_;
Carp::cluck("Option 'antialias' is deprecated, use 'subpixel' instead") if exists $opt{antialias};
return bless {
canvas => $canvas,
commands => [],
precision => undef,
subpixel => $opt{antialias} // (($canvas && ref($canvas)) ? $canvas->antialias : 0),
antialias => 0,
subpixel => $opt{subpixel} // (($canvas && ref($canvas)) ? $canvas->antialias : 0),
%opt
}, $class;
}
Expand Down Expand Up @@ -76,7 +76,8 @@ sub moveto { shift->cmd('moveto', shift, shift, 0) }
sub rmoveto { shift->cmd('moveto', shift, shift, 1) }
sub restore { shift->cmd('restore') } # no checks for underflow here, to allow append paths
sub precision { shift->cmd(set => precision => shift) }
sub antialias { $#_ ? $_[0]->{antialias} = $_[1] : $_[0]->{antialias} }
sub subpixel { $#_ ? $_[0]->{subpixel} = $_[1] : $_[0]->{subpixel} }
sub antialias { Carp::cluck("Property 'antialias' is deprecated, use 'subpixel' instead") }

sub reset
{
Expand Down Expand Up @@ -697,14 +698,9 @@ sub _arc
sub stroke
{
return 0 unless $_[0]->{canvas};
my $emulated_aa = $_[0]->{antialias} && !$_[0]->{canvas}->antialias;
for ( $_[0]->points ) {
next if 4 > @$_;
if ( $emulated_aa ) {
return 0 unless $_[0]->{canvas}->new_aa_surface->polyline($_);
} else {
return 0 unless $_[0]->{canvas}->polyline($_);
}
return 0 unless $_[0]->{canvas}->polyline($_);
}
return 1;
}
Expand All @@ -721,11 +717,7 @@ sub fill
}
for ( $self->points ) {
next if 4 > @$_;
if ( $self->{antialias} && !$_[0]->{canvas}->antialias) {
last unless $ok &= $c->new_aa_surface->fillpoly($_);
} else {
last unless $ok &= $c->fillpoly($_);
}
last unless $ok &= $c->fillpoly($_);
}
$c->fillMode($save) if defined $save;
return $ok;
Expand Down Expand Up @@ -1577,12 +1569,6 @@ When applied to 2D coordinates, the transformed coordinates are calculated as
Selects current precision for splines and arcs. See L<Prima::Drawable/spline>, C<precision> entry.
=item antialias BOOLEAN
Turns on and off slow but more visually pleasant antialiased drawing mode.
Default: false
=item restore
Pops the stack entry and replaces the current matrix and graphic properties with it.
Expand All @@ -1607,7 +1593,7 @@ Adds scaling to the current matrix
Turns on and off slow but more precise floating-point calculation mode
Default: depends on canvas antialiasing mode
Default: depends on the canvas antialiasing mode
=item translate X, Y = X
Expand Down
2 changes: 1 addition & 1 deletion examples/antialias.pl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ sub redraw
my ( $self, $canvas) = @_;
$canvas-> clear;
$canvas-> fillPattern(fp::CloseDot);
$canvas-> new_path(antialias => 1)-> ellipse(100,100,100)->fill;
$canvas-> new_path(subpixel => 1)-> ellipse(100,100,100)->fill;
$canvas-> fillPattern(fp::Solid);
$canvas->lineWidth(5);
$canvas-> graphic_context(
Expand Down

0 comments on commit 4a346a0

Please sign in to comment.