Skip to content

Commit

Permalink
Convert negative fractions properly
Browse files Browse the repository at this point in the history
Previously converted `-1/2` to `½` due to error trying to
handle `3-1/2`.

Bug noticed during GG2 development.
  • Loading branch information
windymilla committed Jun 6, 2024
1 parent ea5be11 commit d3c9e02
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/Guiguts/CharacterTools.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,8 @@ sub fractionconvert {
$infraction =~ /^-?(\d+)$anyslash(\d+)/;

# If character before fraction was a letter, don't convert, e.g. "B1/2"
if ( $textwindow->get( $start . '-1c', $start ) =~ /[[:alpha:]]/ ) {
my $chbefore = $textwindow->get( $start . '-1c', $start );
if ( $chbefore =~ /[[:alpha:]]/ ) {
$start = $end;
next;
}
Expand All @@ -1186,6 +1187,11 @@ sub fractionconvert {
tr/0123456789/\x{2080}\x{2081}\x{2082}\x{2083}\x{2084}\x{2085}\x{2086}\x{2087}\x{2088}\x{2089}/;
$outfraction = "$numerator$fracslash$denominator";
}

# Add hyphen back if it's actually a minus sign for a negative fraction (not a hyphen in 1-3/4)
if ( substr( $infraction, 0, 1 ) eq '-' and $chbefore !~ /[0-9]/ ) {
$outfraction = '-' . $outfraction;
}
if ($outfraction) {
my $advance = '+' . length($outfraction) . 'c';
$textwindow->insert( $start, $outfraction ); # insert first to avoid page marker slippage
Expand Down

0 comments on commit d3c9e02

Please sign in to comment.