Uploaded image for project: 'XMLGraphicsCommons'
  1. XMLGraphicsCommons
  2. XGC-45

[PATCH] FOP with SVG - gradient fill opacity incorrectly inherits stroke opacity of previous svg element

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Resolution: Fixed
    • 2.6
    • None
    • java2D
    • None
    • Operating System: Windows Vista
      Platform: PC

    Description

      To reproduce:

      1) Have an FO file in which an SVG (I have only tested with external-graphics)

      2) Inside the SVG, have a gradient defined and two elements e.g. rectangles. Set the stroke opacity of the first element to a value near 0. NOTE: The order is important - the stroke opacity must be set on the element preceding the gradient filled element.

      3) Make the second element have a gradient fill.

      RESULT: The second element's gradient fill will have the same opacity as the stroke of the preceding element.

        • Possible cause **
          This is due to Batik's GraphicContext.setPaint() method replacing the "foreground" Color attribute if it receives a Color instance as a parameter (due to a "paint instanceof Color" check). The "foreground" of the GraphicsContext is later used to set the fill opacity in the line inside PDFGraphics2D.fill() method:

      applyAlpha(c.getAlpha(), OPAQUE);

      However in this case, batik's GraphicContext.setPaint() is receiving a LinearGradientPaint object which does not inherit from Color. Thus it does not set the "foreground" attribute, meaning that an alpha from a previous setPaint() will be used - in this case, the stroke opacity of the preceding SVG elemnt.

        • Possible hack **
          Since the applyAlpha line in PDFGraphics2D.fill() will not be correct when the paint returned by getPaint() is a gradient, I added an instanceof check so that it only runs when getPaint() returns an instance of Color. This is not a thouroughly thought-out fix and therefore should just be regarded as a workaround hack.

      Attaching SVG file and FO, plus hack (most likely not suitable as fix) to get around issue.

      Attachments

        1. setpaint.svg
          0.9 kB
          dleung
        2. setpaint.fo
          1 kB
          dleung
        3. setpaint.pdf
          6 kB
          dleung
        4. setpaint-fixed.pdf
          6 kB
          dleung
        5. setpaint.patch
          0.7 kB
          dleung
        6. setpaint.patch
          1 kB
          dleung
        7. commons-bug49516.patch
          3 kB
          Luis Bernardo

        Activity

          People

            general@xmlgraphics.apache.org XML Graphics Project Mailing List
            dleung@iress.com.au dleung
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: