ICEpdf
  1. ICEpdf
  2. PDF-436

ICE-PDF Viewer freezes when trying to view specific PDF

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.3.2
    • Fix Version/s: 4.3.3
    • Component/s: Viewer RI
    • Labels:
      None
    • Environment:
      windows 7

      Description

       When trying to view a specific pdf, ICE-PDF viewer displays only a white page and seems to freeze up. (was: Wehn trying to view a specific pdf, ICE-PDF viewer displays only a white page and seems to freeze up.)
      1. ausschnitt.pdf
        264 kB
        Norbert Pfistner
      2. TilingPattern.java
        16 kB
        Wen Wu
      1. ICEpdf Viewer - Auschnitt.png
        46 kB
      2. result.jpg
        20 kB

        Activity

        Hide
        Norbert Pfistner added a comment -

        The tested PDF which causes the freeze

        Show
        Norbert Pfistner added a comment - The tested PDF which causes the freeze
        Hide
        Norbert Pfistner added a comment -

        Screenshot displaying the white page when viewing the PDF.

        Show
        Norbert Pfistner added a comment - Screenshot displaying the white page when viewing the PDF.
        Hide
        Norbert Pfistner added a comment -

        The bug was reproduced using
        1. ICEpdf-pro-4.3.2-src.zip download
        2. unzip
        3. cd ICEpdf-pro-4.3.2-src/icepdf
        4. ant build.all
        5. cd lib/
        6. java -jar icepdf-viewer.jar
        7. open auschnitt.pdf

        Show
        Norbert Pfistner added a comment - The bug was reproduced using 1. ICEpdf-pro-4.3.2-src.zip download 2. unzip 3. cd ICEpdf-pro-4.3.2-src/icepdf 4. ant build.all 5. cd lib/ 6. java -jar icepdf-viewer.jar 7. open auschnitt.pdf
        Hide
        Wen Wu added a comment - - edited

        The bug has been modified, Test ok。

        Modify TilingPattern.java

        1. public void init() {

        if (inited)

        { return; }

        //Modify bug by wuwen.55@gmail.com, see bug PDF-436
        inited = true;
        //Modify bug by wuwen.55@gmail.com end.

        ...

        }

        2. public void paintPattern(Graphics2D g, Page parentPage) {
        if (patternPaint == null) {
        AffineTransform matrixInv = getInvMatrix();
        Rectangle2D bBoxMod = matrix.createTransformedShape(bBox).getBounds2D();

        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();
        // apply current hints
        canvas.setRenderingHints(g.getRenderingHints());
        // copy over the rendering hints
        // get shapes and paint them.
        Shapes tilingShapes = getShapes();

        //Modify bug by wuwen.55@gmail.com, see bug PDF-436
        // finally paint the graphic using the current gs.
        patternPaint = new TexturePaint(bi, bBoxMod);
        g.setPaint(patternPaint);
        //Modify by wuwen.55@gmail.com end.

        if (tilingShapes != null) {
        // setup resource parent
        tilingShapes.setPageParent(parentPage);
        canvas.setClip(0, 0, width, height);
        // apply the pattern space
        canvas.setTransform(matrix);
        // move it back by any shear/rotation distance.
        canvas.translate(matrixInv.getTranslateX(),
        matrixInv.getTranslateY());

        if (paintType == TilingPattern.PAINTING_TYPE_UNCOLORED_TILING_PATTERN)

        { canvas.setColor(unColored); }

        // paint the pattern content stream.
        tilingShapes.paint(canvas);

        // do a little tiling if there is a shear so that we
        // don't end up with any white space around the rotate
        // pattern cell. Java texture paint can't take a transform
        // when painting so this will have to do.
        if (matrix.getShearX() > 0 ||
        matrix.getShearY() > 0)

        { canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(0, -bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(-bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(-bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(0, bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(0, bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); }

        // release the page parent
        tilingShapes.setPageParent(null);
        }

        // 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_); // g_.drawImage(bi, 0, 0, f); // }

        // });
        // f.setSize(new Dimension(800, 800));
        // f.setVisible(true);
        // post paint cleanup
        canvas.dispose();
        bi.flush();
        } else

        { g.setPaint(patternPaint); }

        }

        Show
        Wen Wu added a comment - - edited The bug has been modified, Test ok。 Modify TilingPattern.java 1. public void init() { if (inited) { return; } //Modify bug by wuwen.55@gmail.com, see bug PDF-436 inited = true; //Modify bug by wuwen.55@gmail.com end. ... } 2. public void paintPattern(Graphics2D g, Page parentPage) { if (patternPaint == null) { AffineTransform matrixInv = getInvMatrix(); Rectangle2D bBoxMod = matrix.createTransformedShape(bBox).getBounds2D(); 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(); // apply current hints canvas.setRenderingHints(g.getRenderingHints()); // copy over the rendering hints // get shapes and paint them. Shapes tilingShapes = getShapes(); //Modify bug by wuwen.55@gmail.com, see bug PDF-436 // finally paint the graphic using the current gs. patternPaint = new TexturePaint(bi, bBoxMod); g.setPaint(patternPaint); //Modify by wuwen.55@gmail.com end. if (tilingShapes != null) { // setup resource parent tilingShapes.setPageParent(parentPage); canvas.setClip(0, 0, width, height); // apply the pattern space canvas.setTransform(matrix); // move it back by any shear/rotation distance. canvas.translate(matrixInv.getTranslateX(), matrixInv.getTranslateY()); if (paintType == TilingPattern.PAINTING_TYPE_UNCOLORED_TILING_PATTERN) { canvas.setColor(unColored); } // paint the pattern content stream. tilingShapes.paint(canvas); // do a little tiling if there is a shear so that we // don't end up with any white space around the rotate // pattern cell. Java texture paint can't take a transform // when painting so this will have to do. if (matrix.getShearX() > 0 || matrix.getShearY() > 0) { canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(0, -bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(-bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(-bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(0, bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(0, bBox.getHeight()); tilingShapes.paint(canvas); canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); canvas.translate(bBox.getWidth(), 0); tilingShapes.paint(canvas); } // release the page parent tilingShapes.setPageParent(null); } // 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_); // g_.drawImage(bi, 0, 0, f); // } // }); // f.setSize(new Dimension(800, 800)); // f.setVisible(true); // post paint cleanup canvas.dispose(); bi.flush(); } else { g.setPaint(patternPaint); } }
        Hide
        Wen Wu added a comment -

        result.jpg is my test result.
        TilingPattern.java is my modify.

        Show
        Wen Wu added a comment - result.jpg is my test result. TilingPattern.java is my modify.
        Hide
        Patrick Corless added a comment -

        The PDF in question is a bit odd in that it defines a tilling pattern that references the tiling pattern that it is trying to create. I'm pretty sure there a note in the specification that this should never happen. The provided code identifies two issues.

        1.) For some reason we where not setting the initialized flag once the pattern had be initialized. The initialized flag is used to avoid having to reinitialize the object if it used more then one in the PDF content stream.
        2.) Because this PDF has a Pattern definition that paints using the same pattern we where getting into an infinite loop during the paintPattern method. Essentially a call to tilingShapes.paint(canvas); would cause the paintPattern to be called again. The fix for this condition is to make sure the patternPaint instance variable is set before the tilingShapes are taken into consideration, not after.

        Show
        Patrick Corless added a comment - The PDF in question is a bit odd in that it defines a tilling pattern that references the tiling pattern that it is trying to create. I'm pretty sure there a note in the specification that this should never happen. The provided code identifies two issues. 1.) For some reason we where not setting the initialized flag once the pattern had be initialized. The initialized flag is used to avoid having to reinitialize the object if it used more then one in the PDF content stream. 2.) Because this PDF has a Pattern definition that paints using the same pattern we where getting into an infinite loop during the paintPattern method. Essentially a call to tilingShapes.paint(canvas); would cause the paintPattern to be called again. The fix for this condition is to make sure the patternPaint instance variable is set before the tilingShapes are taken into consideration, not after.
        Hide
        Patrick Corless added a comment -

        Verified the community members code and applied a patched based on their suggestion. Appears to be a fairly low risk fix.

        Show
        Patrick Corless added a comment - Verified the community members code and applied a patched based on their suggestion. Appears to be a fairly low risk fix.

          People

          • Assignee:
            Patrick Corless
            Reporter:
            Norbert Pfistner
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: