svg to png behavior

Poster Content
nk4um User
Posts: 131
August 25, 2008 13:22code is not complete function
I meant to say of course that the relevant part of the function looks like that ...

Regards,
Tom
Like · Post Reply
nk4um User
Posts: 131
August 25, 2008 13:20svg to png behavior
Greetings,
I''ve been experimenting with active:imageSVG2PNG.
However, I could not get it to work as I wanted in Internet Explorer (don''t know if the browser matters, but who knows). This is my SVG
<svg xmlns="http://www.w3.org/2000/svg" version="1.1">
  <circlecx="45" cy="45" r="40" stroke="black" stroke-width="2" fill="red" />
  <textstyle="font-size:20;font-family:verdana" text-anchor="middle" x="45" y="50">Busy</text>
</svg>

Simple red Busy sign 80 pixels across.
Anyways, when using the imageSVG2PNG it shows an image of 80 pixels across, with somewhere in the top left corner, very small, my sign.

I''m probably missing some required SVG parameter that indicates the size of my canvas, but instead of looking for that, I coded the KEY_AOI (area of interest) into the accessor ;-). The IURRepresentation function then looks as follows :
protected com.ten60.netkernel.urii.IURRepresentation source(XAHelper aHelper) throws Exception
   {  String width="100";
      String aoitlx="0";
      String aoitly="0";
      String aoitrx="100";
      String aoitry="100";
      
      if(aHelper.getOperator().getXDA().isTrue("/SVG2PNG/width"))
      {   width=aHelper.getOperator().getXDA().getText("/SVG2PNG/width", true);
      }

      if(aHelper.getOperator().getXDA().isTrue("/SVG2PNG/aoitlx"))
      {   aoitlx=aHelper.getOperator().getXDA().getText("/SVG2PNG/aoitlx", true);
      }
      
      if(aHelper.getOperator().getXDA().isTrue("/SVG2PNG/aoitly"))
      {   aoitly=aHelper.getOperator().getXDA().getText("/SVG2PNG/aoitly", true);
      }
      
      if(aHelper.getOperator().getXDA().isTrue("/SVG2PNG/aoitrx"))
      {   aoitrx=aHelper.getOperator().getXDA().getText("/SVG2PNG/aoitrx", true);
      }
      
      if(aHelper.getOperator().getXDA().isTrue("/SVG2PNG/aoitry"))
      {   aoitry=aHelper.getOperator().getXDA().getText("/SVG2PNG/aoitry", true);
      }

      
      // create a PNG transcoder
        PNGTranscoder t=new PNGTranscoder();
      t.addTranscodingHint(PNGTranscoder.KEY_WIDTH, new Float(width));
      t.addTranscodingHint(PNGTranscoder.KEY_AOI,  new Rectangle(new Integer(aoitlx),new Integer(aoitly),new Integer(aoitrx),new Integer(aoitry)));


You also need the following import to provide for the Rectangle-class
import java.awt.*;


And the conversion xml document to add then looks like
<SVG2PNG>
  <width>80</width>
  <aoitlx>4</aoitlx>
  <aoitly>4</aoitly>
  <aoitrx>84</aoitrx>
  <aoitry>84</aoitry>
</SVG2PNG>


Works like a charm ;-)

Might be something to add in a future release.
Regards,
Tom
Like · Post Reply