Re: Help needed in converting XML to Tiff

2006-09-19 Thread Oliver Hernàndez Valls

You can use this to instantiate the FOP object:

Fop fop = fopFactory.newFop(MimeConstants.MIME_TIFF, userAgent, mtiff);


where userAgent is a FOUserAgent instance that you can use to configure 
your tiff and mtiff is the OutputStream where you want the image to be 
generated.


For further configuration (different image compressions) currently 
there's a developement on the trunk version of FOP and 
xmlgraphics-commons. That I think will be available soon.


Salut!

En/na Richard S ha escrit:
I need to convert a XML or XSL file to tiff format. Is there any direct 
or indirect ways to do that.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Help needed in converting XML to Tiff

2006-09-19 Thread Oliver Hernàndez Valls
	public byte[] generateImage(InputStream xml, InputStream xslt) throws 
BuilderException

{

// OUTPUT STREAM CREATION
// we use a ByteArray because we don't want to generate any file
		ByteArrayOutputStream mtiff= new ByteArrayOutputStream(); // don't 
need to be closed


//don't need finally statement
		if(logger.isDebugEnabled()) logger.debug(Memòria màxima 
inici:+Runtime.getRuntime().maxMemory()/1048576d);
		if(logger.isDebugEnabled()) logger.debug(Memòria lliure 
inici:+Runtime.getRuntime().freeMemory()/1048576d);
		if(logger.isDebugEnabled()) logger.debug(Memòria total 
inici:+Runtime.getRuntime().totalMemory()/1048576d);


// CONFIG
TransformerFactory transfFactory= 
TransformerFactory.newInstance();
Transformer transformer= null;
try
{
transformer= transfFactory.newTransformer(new 
StreamSource(xslt));
}
catch (TransformerConfigurationException e)
{
throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e);
}
Source src= new StreamSource(xml);

// FOP CREATION
// desired output format
FopFactory fopFactory= FopFactory.newInstance();
FOUserAgent userAgent= new FOUserAgent(fopFactory);

userAgent.setTargetResolution(ImageProperties.MTIFF_TARGET_RESOLUTION);

Fop fop;
try
{
fop = fopFactory.newFop(MimeConstants.MIME_TIFF, 
userAgent, mtiff);
}
catch (FOPException e2)
{
e2.printStackTrace();
throw new BuilderException(No s'ha pogut construir 
l'objecte Fop., e2);
}

// RESULT OBJECT CREATION
Result res= null;
try
{
DefaultHandler dh= fop.getDefaultHandler();
res= new SAXResult(dh);
}
catch (FOPException e1)
{
throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e1);  
}

// TRANSFORMATION AND TIFF GENERATION
try
{
transformer.transform(src, res);
}
catch (TransformerException e)
{
throw new 
BuilderException(EXCEPCION_GENERANDO_IMAGEN,e);   
}
		if(logger.isDebugEnabled()) logger.debug(Memòria màxima 
fi:+Runtime.getRuntime().maxMemory()/1048576d);
		if(logger.isDebugEnabled()) logger.debug(Memòria lliure 
fi:+Runtime.getRuntime().freeMemory()/1048576d);
		if(logger.isDebugEnabled()) logger.debug(Memòria total 
fi:+Runtime.getRuntime().totalMemory()/1048576d);

return mtiff.toByteArray();
}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: outputting TIFF-G images

2006-09-15 Thread Oliver Hernàndez Valls
Ok, yesterday I solved this problem by intalling jai tools. My error was 
that I installed jai lib, but this doesn't supply any new service 
provider, actually I don't know if this libs are really necessary.


Today I'll find a way to pass the page iterator to the tiff codec.

Salut!

En/na Oliver Hernàndez Valls ha escrit:
I keep trying to make the TIFFRenderer work with CCITT T.6 bilevel 
compression (CCITT Group 4 facsimile compression). But can't make it work.


When the outputStream flushes I have this exception:
Caused by: java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:808)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:820)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:805)
at 
org.apache.xmlgraphics.image.writer.imageio.ImageIOImageWriter.writeImage(ImageIOImageWriter.java:73) 

at 
org.apache.fop.render.bitmap.TIFFRenderer.stopRenderer(TIFFRenderer.java:196) 

at 
org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:240)
at 
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:422)

at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:170)
at 
org.apache.xml.serializer.ToXMLSAXHandler.endDocument(ToXMLSAXHandler.java:182) 

at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1287) 


... 43 more

I think the problem I have is that the IIORegistry has no service 
providers for image/tiff mime types. And I don't know how to register 
one. Neither I know where to find one.
Does somebody know how to make IIORegistry provide an encoder for 
tiff images??


thanks a lot in advance!

this is the TIFFRenderer.java I have at present:
/*
 * Copyright 1999-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: TIFFRenderer.java 391332 2006-04-04 15:15:23Z jeremias $ */

package org.apache.fop.render.bitmap;

// Code originaly contributed by Oleg Tkachenko of Multiconn 
International Ltd

// ([EMAIL PROTECTED]).

import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.java2d.Java2DRenderer;
import org.apache.xmlgraphics.image.GraphicsUtil;
import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam;
import org.apache.xmlgraphics.image.rendered.FormatRed;
import org.apache.xmlgraphics.image.writer.ImageWriter;
import org.apache.xmlgraphics.image.writer.ImageWriterParams;
import org.apache.xmlgraphics.image.writer.imageio.ImageIOTIFFImageWriter;

/**
 * p
 * This class represents renderer to TIFF (Tagged Image File Format) 
format. It
 * is one of the most popular and flexible of the current public domain 
raster
 * file formats, which was is primarily designed for raster data 
interchange.

 * Supported compression types are:
 * ul
 * liRaw noncompressed data/li
 * liByte-oriented run-length encoding PackBits compression./li
 * liModified Huffman Compression (CCITT Group 3 1D facsimile 
compression)/li
 * liCCITT T.4 bilevel compression (CCITT Group 3 2D facsimile 
compression)/li
 * liCCITT T.6 bilevel compression (CCITT Group 4 facsimile 
compression)/li

 * liJPEG-in-TIFF compression/li
 * liDEFLATE lossless compression (also known as Zip-in-TIFF)/li
 * liLZW compression/li
 * TODO
 * p
 * This class actually does not render itself, instead it extends
 * codeorg.apache.fop.render.java2D.Java2DRenderer/code and just encode
 * rendering results into TIFF format using Batik's image codec
 */
public class TIFFRenderer extends Java2DRenderer {

/** The MIME type for tiff-Rendering */
public static final String MIME_TYPE = MimeConstants.MIME_TIFF;

/** */
//private TIFFEncodeParam renderParams;
private ImageWriterParams iwParams= null;

private OutputStream outputStream;

/** @see org.apache.fop.render.AbstractRenderer */
public String getMimeType() {
return MIME_TYPE

Re: outputting TIFF-G images

2006-09-14 Thread Oliver Hernàndez Valls
I keep trying to make the TIFFRenderer work with CCITT T.6 bilevel 
compression (CCITT Group 4 facsimile compression). But can't make it work.


When the outputStream flushes I have this exception:
Caused by: java.util.NoSuchElementException
at javax.imageio.spi.FilterIterator.next(ServiceRegistry.java:808)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:820)
at javax.imageio.ImageIO$ImageWriterIterator.next(ImageIO.java:805)
	at 
org.apache.xmlgraphics.image.writer.imageio.ImageIOImageWriter.writeImage(ImageIOImageWriter.java:73)
	at 
org.apache.fop.render.bitmap.TIFFRenderer.stopRenderer(TIFFRenderer.java:196)
	at 
org.apache.fop.area.RenderPagesModel.endDocument(RenderPagesModel.java:240)
	at 
org.apache.fop.area.AreaTreeHandler.endDocument(AreaTreeHandler.java:422)

at org.apache.fop.fo.FOTreeBuilder.endDocument(FOTreeBuilder.java:170)
	at 
org.apache.xml.serializer.ToXMLSAXHandler.endDocument(ToXMLSAXHandler.java:182)
	at 
org.apache.xalan.transformer.TransformerImpl.transformNode(TransformerImpl.java:1287)

... 43 more

	I think the problem I have is that the IIORegistry has no service 
providers for image/tiff mime types. And I don't know how to register 
one. Neither I know where to find one.
	Does somebody know how to make IIORegistry provide an encoder for tiff 
images??


thanks a lot in advance!

this is the TIFFRenderer.java I have at present:
/*
 * Copyright 1999-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: TIFFRenderer.java 391332 2006-04-04 15:15:23Z jeremias $ */

package org.apache.fop.render.bitmap;

// Code originaly contributed by Oleg Tkachenko of Multiconn 
International Ltd

// ([EMAIL PROTECTED]).

import java.awt.image.BufferedImage;
import java.awt.image.DataBuffer;
import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.RenderedImage;
import java.awt.image.SampleModel;
import java.awt.image.SinglePixelPackedSampleModel;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;

import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.ConfigurationException;
import org.apache.commons.logging.Log;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.render.java2d.Java2DRenderer;
import org.apache.xmlgraphics.image.GraphicsUtil;
import org.apache.xmlgraphics.image.codec.tiff.TIFFEncodeParam;
import org.apache.xmlgraphics.image.rendered.FormatRed;
import org.apache.xmlgraphics.image.writer.ImageWriter;
import org.apache.xmlgraphics.image.writer.ImageWriterParams;
import org.apache.xmlgraphics.image.writer.imageio.ImageIOTIFFImageWriter;

/**
 * p
 * This class represents renderer to TIFF (Tagged Image File Format) 
format. It
 * is one of the most popular and flexible of the current public domain 
raster
 * file formats, which was is primarily designed for raster data 
interchange.

 * Supported compression types are:
 * ul
 * liRaw noncompressed data/li
 * liByte-oriented run-length encoding PackBits compression./li
 * liModified Huffman Compression (CCITT Group 3 1D facsimile 
compression)/li
 * liCCITT T.4 bilevel compression (CCITT Group 3 2D facsimile 
compression)/li
 * liCCITT T.6 bilevel compression (CCITT Group 4 facsimile 
compression)/li

 * liJPEG-in-TIFF compression/li
 * liDEFLATE lossless compression (also known as Zip-in-TIFF)/li
 * liLZW compression/li
 * TODO
 * p
 * This class actually does not render itself, instead it extends
 * codeorg.apache.fop.render.java2D.Java2DRenderer/code and just encode
 * rendering results into TIFF format using Batik's image codec
 */
public class TIFFRenderer extends Java2DRenderer {

/** The MIME type for tiff-Rendering */
public static final String MIME_TYPE = MimeConstants.MIME_TIFF;

/** */
//private TIFFEncodeParam renderParams;
private ImageWriterParams iwParams= null;

private OutputStream outputStream;

/** @see org.apache.fop.render.AbstractRenderer */
public String getMimeType() {
return MIME_TYPE;
}

/** Creates TIFF renderer. */
public TIFFRenderer() {
//renderParams = new TIFFEncodeParam();
//Default to packbits compression which is widely supported
//renderParams.setCompression(TIFFEncodeParam.COMPRESSION_PACKBITS);
iwParams= new ImageWriterParams();
}

private int 

Re: outputting TIFF-G images

2006-09-13 Thread Oliver Hernàndez Valls

Sorry if these questions are too obvious.


En/na Jeremias Maerki ha escrit:

One more thing: The TIFFRenderer currently uses the internal codecs from
XML Graphics Commons to encode TIFF images. 


I understand you are talking about 
org.apache.xmlgraphics.image.codec.tiff.TIFFImageEncoder in the method 
stopRenderer()


These do not support writing

CCITT-G4 encoded images. We could switch to the ImageWriters I wrote for
Batik and which are now available in XML Graphics Commons. They allow an
abstraction from the underlying codec for image writing. There are
implementations of the ImageWriter that write images through ImageIO


ImageIOTIFFImageWriter?


which might have CCITT-capable codecs available but the code will have
to be extended to choose the compression algorithm. 


So you're talking about subclassing ImageIOTIFFImageWriter (into batik 
or into fop?) or adding code into? to use, for example, TIFFFaxDecoder?


All in all, no easy

solution to your requirement but certainly not much more than half a day
of work.

On 10.09.2006 12:54:46 Jeremias Maerki wrote:

There's a configuration value you can set to modify the compression used
but it's poorly designed (requiring an integer value) and undocumented.
Furthermore, it does not support setting CCITT-G4 compression.
Generating monochrome (1bit) images has also not been implemented, yet.

To implement all this, changes would have to be made in:
- Java2DRenderer.getPageImage(): Extract code into a protected method to
instantiate the BufferedImage that we paint on. Right now, it always
allocates an 24 bit RGB image with an 8-bit alpha channel.


OK


- TIFFRenderer.LazyPageImagesIterator.next(): Code to handle 1bit images.


Uncoment the code for TIFFEncodeParam.COMPRESSION_GROUP4? simply return 
the BufferedImage generated in the protected method above (I think is 
this one)? or some other hack?



- TIFFRenderer.configure(): provide better configuration using names for
compression methods.


What does this method does or have to do? I don't undertand why this 
method exists. It's reason is to log the compression?



- Override the new protected method described above to create the
Buffered image depending on the configuration.


OK



If you don't want to hack FOP code, the work-around is to convert the
generated TIFF file after generation to CCITT format somehow. Obvious,
isn't it? :-)

On 08.09.2006 11:04:22 Oliver Hernàndez Valls wrote:

Hi all,
	I'm working with fop to generate MTIFF text images. At the moment i'm 
using fop-trunk because no justification functionality is working in fop 
0.92 for tiffs.
	Right now I've all the functionality to generate parametrized text 
images implemented. By default fop uses packbits compression and colored 
image coding.
	I'd like to change the tiff coding to TIFF-G because generated images 
with the default tiff coding are very big (around 9000 kB) and 
coloration is not needed for the images I'm generating.
	I'm using the new FOUserAgent parameter setTargetResolution(int), but 
I can't see any way to change the default encoding for tiff images.
	Some time ago I readed this somewhere in the source code: //TODO 
Support output of monochrome bitmaps (fax-style), but don't know if it 
has something to do with changing tiff coding.


Any hint/workarround/documentation please?

Thanks a lot, salut / cheers !


Jeremias Maerki



Jeremias Maerki


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Thanks a lot!

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: outputting TIFF-G images

2006-09-13 Thread Oliver Hernàndez Valls

Hi Jeremias,
I've been working a little with your suggestions.
What I have done is this little work:
1 -Extract code into a protected method to instantiate the BufferedImage 
that we paint on. This methods signature is:


protected BufferedImage getBufferedImage(int bitmapWidth, int bitmapHeight)

2- Modify TIFFRenderer.configure() for selecting the BufferedImage type 
in a new attribute.


3- Override the new protected method described above to create the
Buffered image depending on the configuration.

Here you are the code:


Java2DRenderer
//
//
//
/*
 * Copyright 1999-2006 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the License);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an AS IS BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: Java2DRenderer.java 410308 2006-05-30 15:53:12Z jeremias $ */

package org.apache.fop.render.java2d;

// Java
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.color.ColorSpace;
import java.awt.font.GlyphVector;
import java.awt.geom.AffineTransform;
import java.awt.geom.GeneralPath;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;
import java.awt.image.ComponentColorModel;
import java.awt.image.DataBuffer;
import java.awt.image.DataBufferByte;
import java.awt.image.PixelInterleavedSampleModel;
import java.awt.image.Raster;
import java.awt.image.SampleModel;
import java.awt.image.WritableRaster;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Stack;

import org.w3c.dom.Document;

import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.FOUserAgent;
import org.apache.fop.area.CTM;
import org.apache.fop.area.PageViewport;
import org.apache.fop.area.Trait;
import org.apache.fop.area.inline.Image;
import org.apache.fop.area.inline.InlineArea;
import org.apache.fop.area.inline.Leader;
import org.apache.fop.area.inline.SpaceArea;
import org.apache.fop.area.inline.TextArea;
import org.apache.fop.area.inline.WordArea;
import org.apache.fop.fo.Constants;
import org.apache.fop.fonts.Font;
import org.apache.fop.fonts.FontInfo;
import org.apache.fop.fonts.Typeface;
import org.apache.fop.image.FopImage;
import org.apache.fop.image.ImageFactory;
import org.apache.fop.image.XMLImage;
import org.apache.fop.render.AbstractPathOrientedRenderer;
import org.apache.fop.render.Graphics2DAdapter;
import org.apache.fop.render.RendererContext;
import org.apache.fop.render.pdf.CTMHelper;
import org.apache.fop.util.CharUtilities;

/**
 * The codeJava2DRenderer/code class provides the abstract technical
 * foundation for all rendering with the Java2D API. Renderers like
 * codeAWTRenderer/code subclass it and provide the concrete output 
paths.

 * p
 * A lot of the logic is performed by codeAbstractRenderer/code. The
 * class-variables codecurrentIPPosition/code and
 * codecurrentBPPosition/code hold the position of the currently 
rendered

 * area.
 * p
 * codeJava2DGraphicsState state/code holds the 
codeGraphics2D/code,
 * which is used along the whole rendering. codestate/code also 
acts as a

 * stack (codestate.push()/code and codestate.pop()/code).
 * p
 * The rendering process is basically always the same:
 * p
 * codevoid renderX(Area area) {
 *//calculate the currentPosition
 *state.updateFont(name, size, null);
 *state.updateColor(ct, false, null);
 *state.getGraph.draw(new Shape(args));
 * }/code
 *
 */
public abstract class Java2DRenderer extends 
AbstractPathOrientedRenderer implements Printable {


/** The scale factor for the image size, values: ]0 ; 1] */
protected double scaleFactor = 1;

/** The page width in pixels */
protected int pageWidth = 0;

/** The page height in pixels */
protected int pageHeight = 0;

/** List of Viewports */
protected List pageViewportList = new java.util.ArrayList();

/** The 0-based current page number */
private int currentPageNumber = 0;

/** The 0-based total number of rendered pages */
private int 

outputting TIFF-G images

2006-09-08 Thread Oliver Hernàndez Valls

Hi all,
	I'm working with fop to generate MTIFF text images. At the moment i'm 
using fop-trunk because no justification functionality is working in fop 
0.92 for tiffs.
	Right now I've all the functionality to generate parametrized text 
images implemented. By default fop uses packbits compression and colored 
image coding.
	I'd like to change the tiff coding to TIFF-G because generated images 
with the default tiff coding are very big (around 9000 kB) and 
coloration is not needed for the images I'm generating.
	I'm using the new FOUserAgent parameter setTargetResolution(int), but 
I can't see any way to change the default encoding for tiff images.
	Some time ago I readed this somewhere in the source code: //TODO 
Support output of monochrome bitmaps (fax-style), but don't know if it 
has something to do with changing tiff coding.


Any hint/workarround/documentation please?

Thanks a lot, salut / cheers !

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Text justification in MTIFF output

2006-06-09 Thread Oliver Hernàndez Valls

Hi all,
I'm working in a j2ee project where we need to generate text images. We
use FOP 0.91 beta for creating MTIFF text images from dinamically
generated xmls from database.
As this images are inserted into public documents the text must be
justified for a correct layout.
The problem I have is that the document doesn't justify.
For testing I'm using a little document that justifies if I generate
the output as PDF. But when I generate the output as MTIFF with the same
input, the text doesn't justify.
Is there any problem whith justifying in MTIFF?
any workaround?

thanks in advance!!

Oliver HV

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]