diff --git a/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java b/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java index eabc3fd..094ff96 100644 --- a/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java +++ b/src/main/java/de/rototor/pdfbox/graphics2d/PdfBoxGraphics2DPaintApplier.java @@ -27,6 +27,7 @@ import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; import java.io.IOException; +import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.List; import java.util.*; @@ -149,6 +150,9 @@ else if (simpleName.equals("PatternPaint")) { applyPatternPaint(paint, state); } + else if(simpleName.equals("TilingPaint")) { + applyTilingPaint(paint, state); + } else if (paint instanceof GradientPaint) { return shadingCache.makeUnqiue(buildGradientShading((GradientPaint) paint, state)); @@ -248,6 +252,23 @@ private void applyPatternPaint(Paint paint, PaintApplierState state) throws IOEx state.contentStream.setStrokingColor(patternColor); } + /* + * Apache PDFBox Tiling Paint + */ + private void applyTilingPaint(Paint paint, PaintApplierState state) + { + try + { + Paint tilingPaint = getPrivateFieldValue(paint, "paint"); + applyPaint(tilingPaint, state); + } + catch (Exception e) + { + System.err.println("PdfBoxGraphics2DPaintApplier error while drawing Tiling Paint"); + e.printStackTrace(); + } + } + private void applyComposite(PaintApplierState state) { /* @@ -828,6 +849,41 @@ protected static T getPropertyValue(Object obj, String propertyGetter) } } + /** + * Get the value of a private field from the specified object. + * + * @param obj The object containing the field. + * @param fieldName The name of the field. + * @param The field type. + * @return The private field value. + */ + @SuppressWarnings({ "unchecked", "WeakerAccess" }) + protected static T getPrivateFieldValue(Object obj, String fieldName) + { + try + { + Class c = obj.getClass(); + while (c != null) + { + try + { + Field f = c.getDeclaredField(fieldName); + f.setAccessible(true); + return (T) f.get(obj); + } + catch (NoSuchFieldException ignored) + { + } + c = c.getSuperclass(); + } + throw new NullPointerException("Field " + fieldName + " not found!"); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + private static abstract class COSResourceCacheBase { private Map> states = new HashMap>();