Uploaded image for project: 'Batik'
  1. Batik
  2. BATIK-1071

Not being adjusted the hint about scaling of .svg using "PNGTranscoder" for converting .svg to .png

Attach filesAttach ScreenshotAdd voteVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments


    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 1.7
    • Fix Version/s: None
    • Component/s: SVG Rasterizer
    • Labels:
    • Environment:
      Not important


      In case of converting ".svg" to ".png",
      it occurs not to be applied the hints about scaling of ".png" using PNGTranscoder.
      For instance of the codes occurring bugs, here it is.
      (Some not important codes are omitted..)

      PNGTranscoder tr = new PNGTranscoder();
      tr.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(w) );
      tr.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, new Float(h) );
      tr.addTranscodingHint(PNGTranscoder.KEY_AOI, new Rectangle(0,0,svgRealWidth,svgRealHeight ) );

      TranscoderInput trIn = new TranscoderInput(svgDoc);
      TranscoderOutput trOut = new TranscoderOutput(new FileOutputStream("xx.png", true) );

      tr.transcode(trIn, trOut);

      After running these codes, you will be able to get the terrible image(.png).
      The png image will be a part of the original svg image.

      So I checked the classes "PNGTranscoder", "ImageTranscoder", "SVGAbstractTranscoder" among the involved classes.
      And then, I found the wrong point from them.

      On "SVGAbstractTranscoder" class
      especially line 289 "this.root = gvtRoot;
      => If the instance of CanvasGraphicsNode is not null, the instance of CanvasGraphicsNode obviously has the transforming information which referred the 'Px' variable(especially "AffineTransform")
      And then, the "AffineTransform" instance is initialized.(the line 284)
      => But on the line 289, 'this.root' is assigned 'gvtRoot' that doesn't have the transforming information which referred the 'Px'(the instance of 'AffineTransform').
      So, the child class "ImageTranscoder" can't get the transforming information(especially scale). Because the variable "curTxf" is already initialized by the parent class.(Refer to the line 103 "renderer.setTransform(curTxf );")

      So, as a result, I think the line 289 codes on "SVGAbstractTranscoder" need to be changed like the below codes..
      => this.root = cgn;

      And the line 103 codes on "ImageTranscoder" also need to be changed like the below codes
      => renderer.setTransform(this.root.getTransform() );

      I hope this bug reporting will be useful to improve Apache Batik project.
      If there are some wrong in my reporting, plz let me know..




            • Assignee:
              urtaq DongSoo,Lee


              • Created:

                Issue deployment