deri pushed a commit to branch master
in repository groff.

commit dd63af83c106a6a44dbb15ab36d5f3e211515ca5
Author: Deri James <d...@chuzzlewit.myzen.co.uk>
AuthorDate: Sat Jun 22 18:33:49 2024 +0100

    Fix invalid pdf when using certain sizes of
    dashed ellipse in pic.
    
    * src/devices/gropdf/gropdf.pl: For short dashes on flat part
    of ellipse some v. small numbers written in form n.nnnE-n which
    is invalid for pdfs. Also rather than split each arc always into
    4 pieces, split into number of quadrants described between start
    and end angle. If arc describes a straight line, use line segment
    rather than bezier curve. (grops does this as well)
    
    Fixes https://savannah.gnu.org/bugs/index.php?65901
    
    Thanks to Morten Bo Johansen for reporting this issue.
---
 ChangeLog                    | 16 ++++++++++++
 src/devices/gropdf/gropdf.pl | 60 ++++++++++++++++++++++++++++----------------
 2 files changed, 55 insertions(+), 21 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index cec91f58e..e9c4c568f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2024-06-22  Deri James  <d...@chuzzlewit.myzen.co.uk>
+
+       [gropdf] Fix invalid pdf when using certain sizes of
+       dashed ellipse in pic.
+
+       * src/devices/gropdf/gropdf.pl: For short dashes on flat part
+       of ellipse some v. small numbers written in form n.nnnE-n which
+       is invalid for pdfs. Also rather than split each arc always into
+       4 pieces, split into number of quadrants described between start
+       and end angle. If arc describes a straight line, use line segment
+       rather than bezier curve. (grops does this as well)
+
+       Fixes https://savannah.gnu.org/bugs/index.php?65901
+
+       Thanks to Morten Bo Johansen for reporting this issue.
+
 2024-06-21  G. Branden Robinson <g.branden.robin...@gmail.com>
 
        * src/roff/troff/env.cpp (environment::possibly_break_line):
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index df645c4e0..85a3a5e0f 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -3922,7 +3922,7 @@ sub do_D
     }
     elsif ($Dcmd eq 'a')
     {
-       # Arc
+       # Arc : h1 v1 h2 v2
        $par=substr($par,1);
        my (@p)=split(' ',$par);
        my $rad180=3.14159;
@@ -3941,25 +3941,43 @@ sub do_D
 
        my ($startang,$r)=RtoP(-$centre->[0],$centre->[1]);
        my 
($endang,$r2)=RtoP(($p[0]+$p[2])-$centre->[0],-($p[1]+$p[3]-$centre->[1]));
-       $endang+=$rad360 if $endang < $startang;
-       my $totang=($endang-$startang)/4;       # do it in 4 pieces
 
-       # Now 1 piece
-
-       my $x0=cos($totang/2);
-       my $y0=sin($totang/2);
-       my $x3=$x0;
-       my $y3=-$y0;
-       my $x1=(4-$x0)/3;
-       my $y1=((1-$x0)*(3-$x0))/(3*$y0);
-       my $x2=$x1;
-       my $y2=-$y1;
-
-       # Rotate to start position and draw 4 pieces
-
-       foreach my $j (0..3)
+       if (abs($endang-$startang) < 0.004)
+       {
+           if ($frot)
+           {
+               $stream.="q $ypos ".GraphY($xpos)." m ".($ypos+$p[1]+$p[3])." 
".GraphY($xpos+$p[0]+$p[2])." l S Q\n";
+           }
+           else
+           {
+               $stream.="q $xpos ".GraphY($ypos)." m ".($xpos+$p[0]+$p[2])." 
".GraphY($ypos+$p[1]+$p[3])." l S Q\n";
+           }
+       }
+       else
        {
-           
PlotArcSegment($totang/2+$startang+$j*$totang,$r,$xpos+$centre->[0],GraphY($ypos+$centre->[1]),$x0,$y0,$x1,$y1,$x2,$y2,$x3,$y3);
+           $endang+=$rad360 if $endang < $startang;
+           my $pieces=int(($endang-$startang) / $rad90)+1;
+           my $totang=($endang-$startang)/$pieces;       # do it in pieces
+           print STDERR "Pieces=$pieces, P=",join(',',@p),"\n";
+
+           # Now 1 piece
+
+           my $x0=cos($totang/2);
+           my $y0=sin($totang/2);
+           return if !$y0;
+           my $x3=$x0;
+           my $y3=-$y0;
+           my $x1=(4-$x0)/3;
+           my $y1=((1-$x0)*(3-$x0))/(3*$y0);
+           my $x2=$x1;
+           my $y2=-$y1;
+
+           # Rotate to start position and draw pieces
+
+           foreach my $j (0..$pieces-1)
+           {
+               
PlotArcSegment($totang/2+$startang+$j*$totang,$r,d3($xpos+$centre->[0]),d3(GraphY($ypos+$centre->[1])),d3($x0),d3($y0),d3($x1),d3($y1),d3($x2),d3($y2),d3($x3),d3($y3));
+           }
        }
 
        $xpos+=$p[0]+$p[2];
@@ -4001,7 +4019,7 @@ sub adjust_arc_centre
     }
     else
     {
-       return(undef);
+       return([0,0]);
     }
 }
 
@@ -4009,8 +4027,8 @@ sub adjust_arc_centre
 sub PlotArcSegment
 {
     my ($ang,$r,$transx,$transy,$x0,$y0,$x1,$y1,$x2,$y2,$x3,$y3)=@_;
-    my $cos=cos($ang);
-    my $sin=sin($ang);
+    my $cos=sprintf("%0.5f",cos($ang));
+    my $sin=sprintf("%0.5f",sin($ang));
     my @mat=($cos,$sin,-$sin,$cos,0,0);
     my $lw=$lwidth/$r;
 

_______________________________________________
Groff-commit mailing list
Groff-commit@gnu.org
https://lists.gnu.org/mailman/listinfo/groff-commit

Reply via email to