* @param parentPage parent page used to lookup any resources.
     */
    public void paintPattern(Graphics2D g, Page parentPage) {
        if (patternPaint == null) {
//            final AffineTransform matrixInv = getInvMatrix();

            int width = (int) bBoxMod.getWidth();
            int height = (int) bBoxMod.getHeight();

            // corner cases where some bBoxes don't have a dimension.
            if (width == 0) {
                width = 1;
            }
            if (height == 0) {
                height = 1;
            }

            // create the new image to write too.
            final BufferedImage bi = new BufferedImage(width, height,
                    BufferedImage.TYPE_INT_ARGB);
            Graphics2D canvas = bi.createGraphics();

            // create the pattern paint before  we paint encase there
            // is some recursive calls during the paint PDF-436
            patternPaint = new TexturePaint(bi, bBoxMod);
            g.setPaint(patternPaint);

            // apply current hints
            canvas.setRenderingHints(g.getRenderingHints());
            // copy over the rendering hints
            // get shapes and paint them.
            final Shapes tilingShapes = getShapes();

            // add clip for bBoxMod, needed for some shapes painting.
            canvas.setClip(0, 0, (int) bBoxMod.getWidth(), (int) bBoxMod.getHeight());

            // paint the pattern
            paintPattern(canvas, tilingShapes, bBox);

            // show it in a frame
//            final JFrame f = new JFrame("Test");
//            f.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
//            f.getContentPane().add(new JComponent() {
//                @Override
//                public void paint(Graphics g_) {
//                    super.paint(g_);
//                    paintPattern((Graphics2D)g_, tilingShapes);
//                }
//            });
//            f.setSize(new Dimension(800, 800));
//            f.setVisible(true);
            // post paint cleanup
            canvas.dispose();
            bi.flush();
        } else {
            g.setPaint(patternPaint);
        }
    }