You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by db...@bergqvist.se on 2015/12/29 02:01:13 UTC

Why is addPolygon, drawPolygon and fillPolygon depricated?

The methods addPolygon, drawPolygon and fillPolygon in 
PDPageContentStream is depricated and I don't see why.


Why is it better to write:



for (int i = 0; i < x.length; i++)
{
     if (i == 0)
     {
         contentStream.moveTo(x[i], y[i]);
     }
     else
     {
         contentStream.lineTo(x[i], y[i]);
     }
}
contentStream.closeSubPath();
contentStream.fill();



than simply write:



contentStream.fillPolygon(x, y);



I ask since I want to understand the intention behind depricating these 
methods. The result of depricating them is that you end up with a for 
loop anywhere you want to draw a polygon.

Kind regards,
Daniel

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Why is addPolygon, drawPolygon and fillPolygon depricated?

Posted by John Hewson <jo...@jahewson.com>.
> On 28 Dec 2015, at 17:01, db123@bergqvist.se wrote:
> 
> The methods addPolygon, drawPolygon and fillPolygon in PDPageContentStream is depricated and I don't see why.

PDPageContentStream provides drawing methods which represent those available in the PDF format - polygon drawing isn't a native part of PDF so it was removed. AWT has its own drawing primitives and mixing those with PDF isn't desirable.

> Why is it better to write:
> 
> 
> 
> for (int i = 0; i < x.length; i++)
> {
>    if (i == 0)
>    {
>        contentStream.moveTo(x[i], y[i]);
>    }
>    else
>    {
>        contentStream.lineTo(x[i], y[i]);
>    }
> }
> contentStream.closeSubPath();
> contentStream.fill();
> 
> 
> 
> than simply write:
> 
> 
> 
> contentStream.fillPolygon(x, y);

In the second example you're missing the methods which build the polygon in the first place - so it's hardly a fair comparison.

> I ask since I want to understand the intention behind depricating these methods. The result of depricating them is that you end up with a for loop anywhere you want to draw a polygon

You can write a method to draw an AWT GeneralPath to a PDPageContentStream via a PathIterator and then simply call that once.

-- John

> Kind regards,
> Daniel
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org