I’ve given the current implantation of tiling patterns an overhaul so that it 
supports uncoloured tilings
and to simplify the existing code.

However, the scaling issues are not resolved. I’ve use the same approach to 
scaling the pattern as
in Tilman’s patch, it is indeed correct to apply the CTM to the new page. 
However, the issue with AWT
paint cannot be resolved. The issue is that AWT calls PaintContext#getRaster(x, 
y, w, h) with the same
values irrespective of the DPI which we are rendering at. So, when we render a 
page at 144dpi AWT is
asking its PaintContext to generate a raster at 72dpi and then it is upscaling 
it to 144dpi, which causes
it to become pixelated.

To confirm that AWT is the problem I created custom PaintContext which returned 
a raster with alternating
red and black 1px stripes. When rendering at 72dpi the stripes are 1px wide, 
but when rendering at 144dpi
the stripes are 2px wide, meaning that the raster was upscaled by AWT after it 
was rendered.

-- John

On 24 Feb 2014, at 13:54, Tilman Hausherr <[email protected]> wrote:

> You have been using the version of the trunk, which has a scaling problem. If 
> you use my proposed patch it looks much better (see the images I attached). I 
> didn't check it in because Andreas had assigned the issue to himself. I might 
> do it after having updated my local version to the current trunk, unless 
> there is protest.
> 
> Tilman
> 
> Am 24.02.2014 20:45, schrieb John Hewson:
>> Hi All
>> 
>> There’s been lots of work recently on shading and tiling patterns and I’ve 
>> been testing out some
>> of the new rendering capabilities. However, I think I’ve discovered a 
>> fundamental problem with
>> using AWT’s PaintContext for drawing.
>> 
>> I noticed that the PDF from PDFBOX-1094 looks fine when rendered at the 
>> default 72dpi however
>> if I render it at 144dpi then the tiling patterns appear pixelated. As 
>> expected, RenderUtil creates a
>> proportionally larger BufferedImage to render to and then calls 
>> graphics#scale(x,y) so that everything
>> drawn to the graphics is scaled. This seems to work as expected for vectors 
>> and drawImage, we get
>> nice crisp graphics at large scales. However, for our custom PaintContext 
>> classes we get pixellated
>> graphics.
>> 
>> I decided to instrument the calls to ColoredTilingContext#getRaster(x, y, w, 
>> h) at 72 and 144 dpi to see
>> if the problem is caused by up-scaling of paint *after* it is rendered to a 
>> raster. This is indeed, the cause
>> and I observed the following calls for the PDFBOX-1094 file:
>> 
>> 72 DPI
>> ----------
>>                  x     y     w   h
>> getRaster 302 586 76 76
>> getRaster 396 586 76 76
>> getRaster 344 662 86 86
>> getRaster 340 623 94 82
>> getRaster 302 317 76 76
>> getRaster 396 317 76 76
>> getRaster 344 393 86 87
>> getRaster 340 355 94 82
>> 
>> 144 DPI
>> —————
>>                  x     y     w   h
>> getRaster 302 586 76 76
>> getRaster 396 586 76 76
>> getRaster 344 662 86 86
>> getRaster 340 623 94 82
>> getRaster 302 317 76 76
>> getRaster 396 317 76 76
>> getRaster 344 393 86 87
>> getRaster 340 355 94 82
>> 
>> Perhaps there is some rendering hint or Graphics setting we’re not aware of? 
>> If not we will have to migrate
>> away from using PaintContext and do the painting ourselves using a clipping 
>> path. :-(
>> 
>> -- John
>> 
>> 
> 

Reply via email to