opensagres / xdocreport

XDocReport means XML Document reporting. It's Java API to merge XML document created with MS Office (docx) or OpenOffice (odt), LibreOffice (odt) with a Java model to generate report and convert it if you need to another format (PDF, XHTML...).
https://github.com/opensagres/xdocreport
1.23k stars 374 forks source link

TIFF not recognized in newer versions of xdocreport #696

Open alexanderveit opened 3 days ago

alexanderveit commented 3 days ago

It seems that at some time after version 1.0.3 support for TIFF images has been gone away.

In 1.0.3 it has been handled by fr.opensagres.xdocreport.document.images.SimpleImageInfo.processStream(InputStream)

private void processStream( InputStream is )
    throws IOException
{
    int c1 = is.read();
    int c2 = is.read();
    int c3 = is.read();

    mimeType = null;
    width = height = -1;

    if ( c1 == 'G' && c2 == 'I' && c3 == 'F' )
    { // GIF...
    }
    // ...
    else
    {
        int c4 = is.read();
        if ( ( c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42 ) || ( c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0 ) )
        { // TIFF
            boolean bigEndian = c1 == 'M';
            int ifd = 0;
            int entries;
            ifd = readInt( is, 4, bigEndian );
            is.skip( ifd - 8 );
            entries = readInt( is, 2, bigEndian );
            for ( int i = 1; i <= entries; i++ )
            {
                int tag = readInt( is, 2, bigEndian );
                int fieldType = readInt( is, 2, bigEndian );
                long count = readInt( is, 4, bigEndian );
                int valOffset;
                if ( ( fieldType == 3 || fieldType == 8 ) )
                {
                    valOffset = readInt( is, 2, bigEndian );
                    is.skip( 2 );
                }
                else
                {
                    valOffset = readInt( is, 4, bigEndian );
                }
                if ( tag == 256 )
                {
                    width = valOffset;
                }
                else if ( tag == 257 )
                {
                    height = valOffset;
                }
                if ( width != -1 && height != -1 )
                {
                    mimeType = ImageFormat.tiff;
                    break;
                }
            }
        }
    }
    if ( mimeType == null )
    {
        throw new IOException( "Unsupported image type" );
    }
}

In the current version of SimpleImageInfo there is no sign for TIFF support anymore. https://github.com/opensagres/xdocreport/blob/02ca6b545f1867c29162ec4096bb1fa05ebb98ac/document/fr.opensagres.xdocreport.document/src/main/java/fr/opensagres/xdocreport/document/images/SimpleImageInfo.java

After updating to a newer version (1.0.6) this leads to the following exception when processing TIFF images.

java.io.IOException: Unable to read image info.
 at fr.opensagres.xdocreport.document.images.AbstractInputStreamImageProvider.loadImageInfo(AbstractInputStreamImageProvider.java:89) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageProvider.getImageInfo(AbstractImageProvider.java:186) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageProvider.getHeight(AbstractImageProvider.java:142) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
 at fr.opensagres.xdocreport.document.images.AbstractImageRegistry.getHeight(AbstractImageRegistry.java:282) ~[fr.opensagres.xdocreport.document-1.0.6.jar:1.0.6]
angelozerr commented 3 days ago

Any contribution are welcome !