You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-dev@xmlgraphics.apache.org by Terry Lurie <te...@ADGISTICS.com> on 2005/08/17 19:03:37 UTC

FW: Batik 1.6 , PDFTranscoder and flowRoot

Hi, it occurred to me that the questions may be more related to dev activity.
 
Using the new Batik 1.6 , flowRoot elements do not transcode to PDF correctly.
 
Using a simple main wrapper [below] and a simple input file [further below] the output pdf will be different from the squiggle rendering. The file batik-1.6/samples/tests/spec12/text/flowRegionBreak.svg also highlights the problem.
 
It seems that the text baseline gets set to the top of the PDF and that the wrapping no longer works. That is, flowLine does not cause a new line. You will be able to see the descending part of the 'j' at the top left of the generated pdf.
 
I code java all day, and so I could fix this if I had a few pointers/ time from my boss. If advice is forthcoming, I could probably get him to agree to letting me fix it on company time [and release patches of course].
 
Thanks,
 
Terry.
 
-------------------
A simple wrapper around the methods. Pass the input file as the first argument, pass the output file as the second. All batik 1.6 jars needed on classpath as well as log4j (sorry)
 
 
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.Reader;
import java.io.StringWriter;
import org.apache.batik.dom.svg.SAXSVGDocumentFactory;
import org.apache.batik.dom.util.DOMUtilities;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.fop.svg.PDFTranscoder;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.w3c.dom.svg.SVGDocument;
public class PdfTranscode {
 static Logger LOG = Logger.getLogger(PdfTranscode.class);
 
 public static void main(String[] args) {
  BasicConfigurator.configure();
  try{
   FileInputStream fileInputStream = new FileInputStream(args[0]); //input file arg 0
   FileOutputStream fileOutputStream = new FileOutputStream(args[1]); //output file arg 1
   
   Reader domReader = DOMUtilities.createXMLDocumentReader(fileInputStream);
 
   SAXSVGDocumentFactory SAX_DOCUMENT_FACTORY = new SAXSVGDocumentFactory("org.apache.xerces.parsers.SAXParser");
 
   SVGDocument w3cDocument = SAX_DOCUMENT_FACTORY.createSVGDocument(null , domReader);
   
   PDFTranscoder pdfTranscoder = new PDFTranscoder();
   TranscoderInput tInput = new TranscoderInput(w3cDocument);
//   TranscoderOutput tOutput = new TranscoderOutput(System.out);
   TranscoderOutput tOutput = new TranscoderOutput(fileOutputStream);
   
   pdfTranscoder.transcode(tInput,tOutput);
     
  }
  catch(Throwable e){
   String errorText="There was some sort of exception";
   LOG.error(errorText,e);
  }
 }
}

 
--------------------------
sample input:
 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.2//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xml="http://www.w3.org/XML/1998/namespace" width="742.6771734" height="969.4488284" version="1.2" xml:space="preserve">
<g >
<rect x="38.5590578" y="461.57122261" width="287" height="30" fill="rgb(51,82,143)" />
<flowRoot font-size="8" xml:space="preserve">
 <flowRegion >
  <rect x="38.5590578" y="461.57122261" width="287" height="30"/>
 </flowRegion>
 <flowDiv >
  <flowPara><flowSpan  font-family="ADG0020" font-size="20" fill="rgb(0,0,0)" >j</flowSpan></flowPara>
 </flowDiv>
</flowRoot>
</g></svg>

Re: FW: Batik 1.6 , PDFTranscoder and flowRoot

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Terry,

Terry Lurie wrote:

> Hi, it occurred to me that the questions may be more related to dev 
> activity.
>  
> Using the new Batik 1.6 , flowRoot elements do not transcode to PDF 
> correctly.

    Hmm, you are correct, very surprising.

> The file batik-1.6/samples/tests/spec12/text/flowRegionBreak.svg also 
> highlights the problem.

   Yes actually our standard rasterizer has the problem as well.

> It seems that the text baseline gets set to the top of the PDF and that 
> the wrapping no longer works. That is, flowLine does not cause a new 
> line. You will be able to see the descending part of the 'j' at the top 
> left of the generated pdf.

    The problem is that the PDF transcoder installs a TextPainter.
The original intent of this interface was to enable output modules
(like the PDF transcoder) to handle the rendering of text in special
ways.  However in practice this hasn't really materialized.

    Anyway the quickest solution (untested) is to remove the lines:
from xml-fop/src/java/org/apache/fop/svg/PDFTranscoder.java (line 177):

         textPainter = new StrokingTextPainter();
         ctx.setTextPainter(textPainter);

> I code java all day, and so I could fix this if I had a few pointers/ 
> time from my boss. If advice is forthcoming, I could probably get him to 
> agree to letting me fix it on company time [and release patches of course].

    The real fix is to allow the FlowTextPainter to wrap the Text painter
that is passed to it's 'setTextPainter' method.  This is a bit tricky
since the implementation of FlowTextPainter relies on
StrokingTextPainter methods which may not be available on the passed
in TextPainter (in which case you probably need to wire the calls to
the singleton StrokingTextPainter instance).

    Or else refactor the interface entirely ;)

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-dev-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-dev-help@xmlgraphics.apache.org