Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-2881

Radial and Axial shading steps are calculated incorrectly

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.0
    • Fix Version/s: 2.0.0
    • Component/s: Rendering
    • Labels:

      Description

      I found a shading bug while writing some code to dump all shadings in a PDF. I don't know if this affects PDF rendering within PageDrawer or not.

      RadialShadingContext and AxialShadingContext use the following code in their constructors to calculate the number of steps (pixels) in the shading and build a lookup table for each step:

      // transform the distance to actual pixel space
      // use transform, because xform.getScaleX() does not return correct scaling on 90° rotated matrix
      Point2D point = new Point2D.Double(longestDistance, longestDistance);
      matrix.transform(point);
      xform.transform(point, point);
      factor = (int) Math.max(Math.abs(point.getX()), Math.abs(point.getY()));
      colorTable = calcColorTable();
      

      The variable "factor" is the number of steps and "matrix" is the parent stream's matrix + the pattern matrix, so this code is taking the current scale and assuming that that is equal to the number of pixels. This works when a pattern is painted onto a 0...1 scaled surface, but otherwise it produces incorrect results.

      There's no way to calculate the number of pixels in the device from its scale, or its matrix. Paint#createContext() provides the device bounds Rectangle, which is what we should be using. Indeed, this is handled correctly in the other shading contexts.

        Attachments

          Activity

            People

            • Assignee:
              jahewson John Hewson
              Reporter:
              jahewson John Hewson
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: