[
https://issues.apache.org/jira/browse/FOP-2156?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149673#comment-18149673
]
Rafael Witak commented on FOP-2156:
-----------------------------------
h2. Still reproducible with FOP 2.12 / xmlgraphics-commons 2.12: root cause and
workaround
Reproduced with FOP 2.12 and xmlgraphics-commons 2.12 (Java 17). The FO
contains one {{fo:external-graphic}} per generated PNG:
||PNG (IHDR)||RTF, default||RTF, INFINITE penalty on ImageLoaderRawPNG||RTF,
preloader config from XGC-97||RTF, workaround below||PDF||
|RGB, 8 bit|"does not support png - image type"|image missing|"does not support
png"|embedded|embedded|
|Grayscale, 8 bit|"does not support png - image type"|image missing|"does not
support png"|embedded|embedded|
|Palette, 8 bit|"does not support png - image type"|image missing|"does not
support png"|embedded|embedded|
|Palette, 8 bit, with tRNS|embedded|embedded|"does not support
png"|embedded|embedded|
|Grayscale, 16 bit|embedded|embedded|"does not support png"|embedded|embedded|
|RGBA, 8 bit|embedded|embedded|"does not support png"|embedded|embedded|
*Why only some PNGs fail:* {{ImageLoaderFactoryRaw.isSupported()}} sends a PNG
to {{ImageLoaderRawPNG}} only if it is
* 8 bit
* non-interlaced and
* has no alpha (a palette with tRNS counts as alpha).
All other PNGs go through ImageIO and {{{}ImageConverterRendered2PNG{}}}, which
writes a complete PNG file, so they work.
*With {{PreloaderRawPNG}} (XGC-97) every PNG fails:* this preloader attaches no
ImageIO metadata. Without metadata, {{ImageLoaderFactoryRaw.isSupported()}}
skips the bit depth and alpha checks and returns {{{}true{}}}. With the penalty
configuration from XGC-97's description ({{{}PreloaderRawPNG{}}} at -1000), all
six PNGs above fail in RTF, including RGBA and 16 bit. This may also explain
why XGC-99 reports that "any PNG" fails.
h3. Root cause
{{RTFHandler.putGraphic()}} requests {{{}RAW_EMF{}}}, {{RAW_PNG}} or
{{RAW_JPEG}} and copies {{ImageRawStream.createInputStream()}} unchanged into
{{{}RtfExternalGraphic.setImageData(){}}}. For {{RAW_PNG}} the only direct
loader is {{{}ImageLoaderRawPNG{}}}. Its {{ImageRawPNG}} stream holds only the
concatenated IDAT data, without signature and IHDR. That is intended for
PDF/PostScript (see Luis Bernardo's comment on XGC-99). {{RtfExternalGraphic}}
detects the format from the leading bytes, finds no PNG signature and throws.
The "png" in the message is the file extension taken from the URL, not the
detected format.
So I think the fix belongs in {{RTFHandler}} rather than in {{PNGFile}}
(XGC-99). Returning the whole file from {{getImageRawPNG()}} would change the
data the PDF/PostScript path relies on. I have not verified the XGC-99 patch
against PDF output. For example, {{RTFHandler}} could reject {{ImageRawPNG}}
and load the image as {{RENDERED_IMAGE}} instead, then encode it as PNG.
*The INFINITE penalty suggested above (2013) is not enough on its own:* no
loader for {{RAW_PNG}} is left, FOP does not fall back to a converter pipeline,
and the image is dropped ("no suitable loader/converter combination available").
h3. *+Workaround+* without patching FOP
Register a loader that provides the complete original file as {{RAW_PNG}} and
block {{{}ImageLoaderRawPNG{}}}. The registry belongs to the {{ImageManager}}
of one {{{}FopFactory{}}}, so this can be limited to the factory used for RTF
and leaves PDF untouched. With it, all six cases above are embedded
byte-identical to the source file, with or without the XGC-97 preloader
configuration.
{code:java}
static class WholeFilePngLoaderFactory extends AbstractImageLoaderFactory {
public String[] getSupportedMIMETypes() { return new String[]
{"image/png"}; }
public ImageFlavor[] getSupportedFlavors(String mime) { return new
ImageFlavor[] {ImageFlavor.RAW_PNG}; }
public ImageLoader newImageLoader(ImageFlavor flavor) { return new
ImageLoaderRaw(ImageFlavor.RAW_PNG); }
public boolean isAvailable() { return true; }
}
// only on the FopFactory used for RTF output
ImageImplRegistry registry = fopFactory.getImageManager().getRegistry();
registry.registerLoaderFactory(new WholeFilePngLoaderFactory());
registry.setAdditionalPenalty(ImageLoaderRawPNG.class.getName(),
Penalty.INFINITE_PENALTY);
{code}
A self-contained reproduction ([^Repro.java], a single Java file that generates
the test PNGs and covers all columns above) is attached.
??Created by Claude Code (Opus 5.5 high), checked by me??
> PNG and GIF image generation fails in RTF documents
> ---------------------------------------------------
>
> Key: FOP-2156
> URL: https://issues.apache.org/jira/browse/FOP-2156
> Project: FOP
> Issue Type: Bug
> Components: renderer/rtf
> Affects Versions: 1.1
> Environment: Operating System: All
> Platform: PC
> Reporter: Carl Zetterberg
> Attachments: Repro.java
>
>
> Tomcat 6
> java 1.7
> Fop 1.1
> xmlgraphics-commons-1.5.jar
> <fo:external-graphic src="file:logotypes/{head/logotype}"
> width="auto"
> height="auto" content-width="80%" content-height="auto" />
> will produce:
> org.apache.fop.render.rtf.rtflib.rtfdoc.RtfExternalGraphic$ExternalGraphicException:
> The tag <fo:external-graph ic> does not support gif - image type
> both for PNG and GIF files when producing RTF documents
> The same environment and XSL produce PDF that are ok.
> Switching back to fop 1.0 and xmlgraphics-commons-1.4.jar resolves the
> problem.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)