Skip to content

Commit

Permalink
Fix for zmz case
Browse files Browse the repository at this point in the history
  • Loading branch information
benkasminbullock committed May 1, 2021
1 parent 0c3fd53 commit 27735a2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Revision history for perl module Image::SVG::Path

0.36 2021-04-27

* Tests for arc flag parsing

0.35 2021-04-26

* Improved parsing of flags in arc elements
Expand Down
27 changes: 18 additions & 9 deletions lib/Image/SVG/Path.pm
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ sub extract_path_info
};
}
}
elsif ($ucc eq'L') {
elsif ($ucc eq 'L') {
my $expect_numbers = 2;
# Maintain this check here, even though it's duplicated
# inside build_lineto, because it's specific to the lineto
Expand All @@ -459,7 +459,7 @@ sub extract_path_info
my $position = position_type ($command);
push @path_info, build_lineto ($position, @numbers);
}
elsif ($ucc eq'Z') {
elsif ($ucc eq 'Z') {
if (@numbers > 0) {
croak "Wrong number of values for a Z command " .
scalar @numbers . " in '$path'";
Expand All @@ -472,7 +472,7 @@ sub extract_path_info
svg_key => $command,
}
}
elsif ($ucc eq'Q') {
elsif ($ucc eq 'Q') {
my $expect_numbers = 4;
if (@numbers % $expect_numbers != 0) {
croak "Wrong number of values for a Q command " .
Expand All @@ -491,7 +491,7 @@ sub extract_path_info
}
}
}
elsif ($ucc eq'T') {
elsif ($ucc eq 'T') {
my $expect_numbers = 2;
if (@numbers % $expect_numbers != 0) {
croak "$me: Wrong number of values for an T command " .
Expand All @@ -509,7 +509,7 @@ sub extract_path_info
}
}
}
elsif ($ucc eq'H') {
elsif ($ucc eq 'H') {
my $position = position_type ($command);
for (my $i = 0; $i < @numbers; $i++) {
push @path_info, {
Expand All @@ -521,7 +521,7 @@ sub extract_path_info
};
}
}
elsif ($ucc eq'V') {
elsif ($ucc eq 'V') {
my $position = position_type ($command);
for (my $i = 0; $i < @numbers; $i++) {
push @path_info, {
Expand All @@ -533,7 +533,7 @@ sub extract_path_info
};
}
}
elsif ($ucc eq'A') {
elsif ($ucc eq 'A') {
my $position = position_type ($command);
my $expect_numbers = 7;
if (@numbers % $expect_numbers != 0) {
Expand All @@ -551,7 +551,7 @@ sub extract_path_info
push @path_info, \%arc;
}
}
elsif ($ucc eq'M') {
elsif ($ucc eq 'M') {
my $expect_numbers = 2;
my $position = position_type ($command);
if (@numbers < $expect_numbers) {
Expand All @@ -565,7 +565,7 @@ sub extract_path_info
type => 'moveto',
name => 'moveto',
position => $position,
point => [@numbers[0,1]],
point => [@numbers[0, 1]],
svg_key => $command,
};
# M can be followed by implicit line-to commands, so
Expand Down Expand Up @@ -610,6 +610,15 @@ sub extract_path_info
}
}
@abs_pos = @{$element->{point}};
# It's possible to have a z, followed by an m,
# followed by a z. This occurred with
# https://github.com/edent/SuperTinyIcons/blob/master/images/svg/mailchimp.svg
# as of commit
# https://github.com/edent/SuperTinyIcons/commit/fd79fb48365ee14ace58e8aed5bad046e5b8136c
# So we should always have a valid value in
# @start_drawing, in case someone makes a useless
# "move".
@start_drawing = @abs_pos;
}
elsif ($element->{type} eq 'line-to') {
if ($element->{position} eq 'relative') {
Expand Down
4 changes: 0 additions & 4 deletions t/eaa.t
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,6 @@ my @paths = (
file => 'svelte.svg',
path => 'M395 115c-35-51-106-66-157-34l-89 57a103 103 0 00-46 69 108 108 0 0010 69 103 103 0 00-15 39 109 109 0 0019 82c35 51 106 66 157 34l89-57a103 103 0 0046-69 108 108 0 00-10-69 103 103 0 0015-39 109 109 0 00-19-82',
},
{
file => 'svg.svg',
path => 'M122 157h268v99H122',
},
{
file => 'teamspeak.svg',
path => 'M407 336c5 5 9 18 9 26s0 15-2 21c0 3-6 33-43 51l-23 8-14 3c-64 12-148-3-84-10l17-2a1532 1532 0 0042-10h1a19086 19086 0 0012-4c16-7 33-16 47-29 10-10 19-22 26-37l6-15c0-2 4-3 6-2zm-60-56c17-3 28 5 29 19 1 13-3 25-13 35-8 9-18 13-32 12a249 249 0 01-40-5c-19-5-26-19-14-30 7-7 16-12 25-16l23-9c7-3 15-5 22-6zm-211-15c3-18 18-26 34-18a1135 1135 0 0142 28 141 141 0 0133 39l1 10c-2 10-9 15-18 19l-13 1h-19l-16-2c-15-1-26-7-34-19a77 77 0 01-10-58zm256-153l3 2c4 4 8 9 3 16l-1 1v2l2 2c16 22 27 46 32 73l2 4 2 1c14 7 21 18 21 33v19l-1 21c-4 20-23 33-42 29-6-1-7-6-7-11a11534 11534 0 010-66 150 150 0 00-300-1v69c0 6-4 9-10 9-24 1-40-14-40-38v-27l1-10c2-12 8-21 19-27h1l1-1c2-1 3-3 3-5 5-26 15-50 30-71l2-3v-5c-3-4-1-7 1-11h1c22-25 48-43 80-53 75-23 141-7 197 48z',
Expand Down

0 comments on commit 27735a2

Please sign in to comment.