You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Alexander (Jira)" <ji...@apache.org> on 2021/06/01 09:39:00 UTC

[jira] [Commented] (PDFBOX-5093) Pass PDFRenderer to PDFPrintable constructor

    [ https://issues.apache.org/jira/browse/PDFBOX-5093?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17354972#comment-17354972 ] 

Alexander commented on PDFBOX-5093:
-----------------------------------

Java bug fixes only rounding issue when text is printed using Graphics Path (GDI BeginPath/MoveTo/LineTo... methods on Windows).
It is still better to use Graphics2D.drawString() method for small text which calls GDI TextOut method and uses special font rendering optimizations.

Let's look at this from another way. There is the CustomPageDrawer example where MyPageDrawer extends PageDrawer and overrides showGlyph() method. It calls super.showGlyph(...) and saves and restores graphics.getClip() and graphics.getColor().
[CustomPageDrawer.java#L116|https://github.com/apache/pdfbox/blob/f2e5dccac4bbd3eba9e7eb71f46a6d2138bde394/examples/src/main/java/org/apache/pdfbox/examples/rendering/CustomPageDrawer.java#L116]

Should it be possible for a developer to use the same clip and paint as it is used by PageDrawer implementation?
For example, some text needs to be drawn in different way and in this case a custom text drawing is used and  super.showGlyph(...) is not called. What is the way to set a proper clip and paint in this case?
May be there should be some protected methods which provide clip and paint so both PageDrawer.showGlyph() and a custom code can use?
 

> Pass PDFRenderer to PDFPrintable constructor
> --------------------------------------------
>
>                 Key: PDFBOX-5093
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-5093
>             Project: PDFBox
>          Issue Type: Improvement
>          Components: Rendering
>    Affects Versions: 2.0.22
>            Reporter: Alexander
>            Assignee: Tilman Hausherr
>            Priority: Minor
>             Fix For: 2.0.24, 3.0.0 PDFBox
>
>
> I prepared a simple example for PDFBOX-4709 "PDFBox prints text poorly in comparison to Adobe, Chrome, other apps" which uses a custom PDF renderer and PageDrawer to draw a text using Graphics2D.drawString(...) method to print a low DPI text with good quality.
>   https://github.com/AlexanderScherbatiy/pdfbox/commit/b806d44f9514a7b5fededfa49c98ad2858b93a92
> The sample is prepared for tag 2.0.22. It consists of org.apache.pdfbox.examples.strprinting.StringPrinting sample which sets a custom StringPDFPageable. StringPDFPageable just a copy of PDFPageable (PDFPageable is a final class, it is not possible to override it) where getPrintable(int i) method sets a custom StringPDFRenderer to PDFPrintable.
> StringPDFRenderer just returns a custom StringPageDrawer which is subclass of PageDrawer.
> The aim if StringPageDrawer is an illustration how Graphics2D.drawString(...) can be used.
> Only two fonts PDType0Font and PDType1Font are handled by StringPageDrawer. The code for PDFont AwtFont  handling just a copy from PDFBOX 1.8.
> There are a few things which PDFBOX does not provide as a public API.
> The current request is to provide a way to set a custom PDF renderer to PDFPrintable.
> Here is patch which illustrate how it can look like:
>   https://github.com/AlexanderScherbatiy/pdfbox/commit/212a78b2b65ada117c0e9ae65c3ae6054ca5fa61
> The other two things are private setClip() and getNonStrokingPaint() methods from PageDrawer.  The idea of the sample was to draw a text in the same way as PDFBOX  renderingMode.isFill() (the same transform, clip and paint) only changing graphics.fill(glyph) to graphics.drawString(str, 0, 0).
> Is it possible to make setClip()  and getNonStrokingPaint() public in some way or it is necessary just to copy them as is?



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

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