[
https://issues.apache.org/jira/browse/PDFBOX-2141?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14041157#comment-14041157
]
Petr Slaby commented on PDFBOX-2141:
------------------------------------
I see. Why not do the same, then - apply the transform to the path instead of
the graphics? The following works like magic on your test file. I am just not
sure whether it might negatively affect performance and I tested it with this
single file only (pattern-shading-2-4-idMatrix.pdf).
Alternatively, we might either be able to compute the right transformation from
the deviceBounds/userBounds in AxialShadingPaint#createContext() (I am not
sure, I just think the information we need might be in there), or use a custom
rendering hint key and pass the additional transform along with the rendering
hints.
{noformat}
private void drawGlyph2D(Glyph2D glyph2D, int[] codePoints, AffineTransform
at) throws IOException
{
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
for (int i = 0; i < codePoints.length; i++)
{
GeneralPath path = glyph2D.getPathForCharacterCode(codePoints[i]);
if (path != null)
{
if (!at.isIdentity())
{
path = (GeneralPath) path.clone();
path.transform(at);
}
graphics.fill(path);
}
}
}
{noformat}
> Shading not applied to text
> ---------------------------
>
> Key: PDFBOX-2141
> URL: https://issues.apache.org/jira/browse/PDFBOX-2141
> Project: PDFBox
> Issue Type: Bug
> Components: Rendering
> Affects Versions: 1.8.5, 1.8.6, 1.8.7, 2.0.0
> Reporter: Petr Slaby
> Priority: Minor
> Attachments: 000004_ShadingPatternTextPDF.pdf, PDFBOX-1917.pdf-1.png,
> PDFBOX-1917.pdf-1.png-diff.png, PDFBOX-1917.pdf-9.png,
> PDFBOX-1917.pdf-9.png-diff.png, PDFBOX-2135.pdf-2.png,
> PDFBOX-2135.pdf-2.png-diff.png, PageDrawer.writeFont.java.patch,
> pattern-shading-2-4-idMatrix.pdf, pattern-shading-2-4-idMatrix.pdf,
> pattern-shading-2-4-idMatrix1.jpg, pattern-shading-2-4-noMatrix.pdf,
> pattern-shading-2-4.ps, pattern-shading-2-4.ps
>
>
> The attached PDF draws a text filled with horizontal shading going from red
> to blue. When rendered via PDFBox, the text is completely filled with red.
> The problem is that AxialShadingContext#getRaster() gets called with
> positions that completely fell outside of the range stored in its coords[]
> field. The fix seems to be to set glyph transform rather than graphics2d
> transform in PageDrawer#writeText() as shown in the attached patch.
--
This message was sent by Atlassian JIRA
(v6.2#6252)