Bug 37136 - external-graphic dimensions and rendering
Summary: external-graphic dimensions and rendering
Status: NEEDINFO
Alias: None
Product: Fop - Now in Jira
Classification: Unclassified
Component: images (show other bugs)
Version: 0.20.5
Hardware: PC Windows XP
: P3 normal
Target Milestone: ---
Assignee: fop-dev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-10-18 09:23 UTC by Rune Johansen
Modified: 2012-04-18 07:01 UTC (History)
1 user (show)



Attachments
shows size problems with bmp and rendering differences with the same svg (130.23 KB, application/x-zip-compressed)
2006-02-24 14:49 UTC, ninouffff
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Rune Johansen 2005-10-18 09:23:33 UTC
==========================================================================
Sample1: The image will not be sized to the specified dimensions
==========================================================================

<fo:block-container position="absolute" left="66.00mm" top="72.00mm" 
width="100.00mm" height="75.00mm">
  <fo:block>
    <fo:external-graphic src="file:your_image.jpg" width="100.00mm" 
height="75.00mm"/>
  </fo:block>
</fo:block-container>

==========================================================================
Sample2: The rendered PDF file fails to load, and fop reports exceptions

java.lang.RuntimeException: Some content could not fit into a line/page after 
50 attempts. Giving up to avoid an endless loop.
Exception
javax.xml.transform.TransformerException: java.lang.RuntimeException: Some 
content could not fit into a line/page after 50 attempts. Giving up to avoid an 
endless loop.

==========================================================================

<fo:block height="75.00mm">
  <fo:external-graphic src="file:your_image.jpg" width="100.00mm"/>
</fo:block>
Comment 1 Manuel Mall 2005-10-18 09:35:07 UTC
Have you tried to use the content-height="scale-to-fit" and content-
width="scale-to-fit" on the fo:external-graphic?

FOP 1.0dev is attempting to be much more strict in applying the spec and will 
only scale if told to do so.
Comment 2 Jeremias Maerki 2005-10-18 09:38:34 UTC
(In reply to comment #0)
> ==========================================================================
> Sample1: The image will not be sized to the specified dimensions
> ==========================================================================
> 
> <fo:block-container position="absolute" left="66.00mm" top="72.00mm" 
> width="100.00mm" height="75.00mm">
>   <fo:block>
>     <fo:external-graphic src="file:your_image.jpg" width="100.00mm" 
> height="75.00mm"/>
>   </fo:block>
> </fo:block-container>

This is something we've had a number of times now. The new FOP is much more
strict about the interpretation of the XSL specification and has much less wrong
behaviour than FOP 0.20.5. Under 0.20.5 the above probably did what you expected
it to do but it was a faulty interpretation of the specification. width and
height only specify the size of the box for the image, not the size of the
image. If you want to scale the image so that it fits into the prepared box you
will now have to add content-width="scale-to-fit". Otherwise, the image will be
painted in its intrinsic size. It is no bug in FOP.

> ==========================================================================
> Sample2: The rendered PDF file fails to load, and fop reports exceptions
> 
> java.lang.RuntimeException: Some content could not fit into a line/page after 
> 50 attempts. Giving up to avoid an endless loop.
> Exception
> javax.xml.transform.TransformerException: java.lang.RuntimeException: Some 
> content could not fit into a line/page after 50 attempts. Giving up to avoid an 
> endless loop.
> 
> ==========================================================================
> 
> <fo:block height="75.00mm">
>   <fo:external-graphic src="file:your_image.jpg" width="100.00mm"/>
> </fo:block>

You get the above error message if an element on a page (in your case the image)
doesn't fit onto a page. The layout engine is then trying to put the element on
the next page and if it still doesn't fit on the next and so on. After 50
attempts it gives up and reports this. You will have to make sure that FOP is
able to fit the image into a page. Without a complete example to run it myself
it's difficult for me to tell you exactly what needs to be done. Try making the
image smaller to begin with.

BTW, the height property does not apply to the fo:block element. Your height
there will be ignored! Better specify the height on the external-graphic and use
content-width="scale-to-fit" as shown above.

If you don't manage with this information please reopen the bug and attach a
complete example file.
Comment 3 M.H. 2005-11-02 14:30:57 UTC
Even though I added this content-width="scale-to-fit" to our external-grpahic:

      <fo:block padding-bottom="5mm">
         <fo:external-graphic content-width="scale-to-fit" 
height="{$LogoHeightValue}" src="{$Logo}"/>
      </fo:block>

the error still occurs (FOP 1.0dev from 01.11.2005):

javax.xml.transform.TransformerException: java.lang.RuntimeException: Some 
content could not fit into a line/page after 50 attempts. Giving up to avoid an 
endless loop.


Anyway: what does "50 attempts" mean? Running my example 50 times also doesn't 
help anyfurther ... ;-)
Comment 4 M.H. 2005-11-02 14:45:53 UTC
I noticed that we also have svg images imported and that code is causing this 
(same) error message:


    <fo:instream-foreign-object >
        <svg:svg width="120mm" height="130mm" 
xmlns:xlink="http://www.w3.org/2000/svg">
            <svg:image width="120mm" height="130mm" 
xlink:href="{$chart_C_AssetSectorStructure2_H}"/>
        </svg:svg>
        </fo:instream-foreign-object>


leads to:

javax.xml.transform.TransformerException: java.lang.RuntimeException: Some 
content could not fit into a line/page after 50 attempts. Giving up to avoid an 
endless loop.

I checked it when I removed just this section of code, the message disappeard 
(and also the SVG ;-). Repasting it back reproduces the error message. 
Unfortunately,   content-width="scale-to-fit"    doesn't work with <svg:svg> 
and <svg:image>.
Comment 5 Manuel Mall 2005-11-02 14:58:45 UTC
<fo:external-graphic content-width="scale-to-fit" 
height="{$LogoHeightValue}" src="{$Logo}"/>

This will scale such that the logo fits into the width provided by the 
enclosing element. The error is more likely to be caused by the height not 
fitting into the area available. Have you tried using 'content-height="scale-to-
fit"'? If that fixes your problem please close the bug. If not please attach a 
small sample fo and image which exhibits the problem.
Comment 6 M.H. 2005-11-02 15:11:12 UTC
Please see response #4 for the SVG example.
Comment 7 Manuel Mall 2005-11-02 15:15:42 UTC
Comment #4 is not a working example showing the problem. It is just a snippet 
from your XML file. For us to investigate this we need the XSL-FO file (as 
small as possible just enough to show the problem) together with any related 
files (svg, jpeg, ...)
Comment 8 Manuel Mall 2005-11-02 15:18:55 UTC
Forgot to add:
If you don't know how to just generate the XSL-FO file from the XML see here: 
http://xmlgraphics.apache.org/fop/trunk/running.html#check-input
Comment 9 Andreas L. Delmelle 2005-11-02 19:40:49 UTC
In reply to comment #4:

See recent post on fop-users: specify content-height and content-width on the fo:instream-foreign-
object, not on the svg element.
Comment 10 ninouffff 2006-02-24 14:49:34 UTC
Created attachment 17794 [details]
shows size problems with bmp and rendering differences with the same svg
Comment 11 suresh koya 2006-05-25 03:56:50 UTC
Specifying the content-width and content-height in a FO document does not render
the image with the proper dimensions:
<fo:external-graphic content-height="82px" content-width="294px"
                 src="http://onjava.com/images/onjava/onjava_logo.jpg"/>
Comment 12 Jeremias Maerki 2006-06-12 09:02:38 UTC
(In reply to comment #11)
> Specifying the content-width and content-height in a FO document does not render
> the image with the proper dimensions:
> <fo:external-graphic content-height="82px" content-width="294px"
>                  src="http://onjava.com/images/onjava/onjava_logo.jpg"/>
> 

Specifying sizes in pixels is generally bad practice in documents to be printed.
The width of a pixel depends on the resolution used by the interpreting
application. Some use 72dpi, some use 96 dpi as a default. FOP uses 72dpi by
default but that can be changed in the configuration file or on the FopFactory.
If you leave out content-height and content-width the image will be painted at
its natural size.
Comment 13 Glenn Adams 2012-04-01 19:02:20 UTC
the attached test file does not contain the referenced external graphics or referenced setup.svg file; please provide in order to keep this bug open; otherwise, it will be moved to resolved+wontfix
Comment 14 Glenn Adams 2012-04-07 01:43:37 UTC
resetting P2 open bugs to P3 pending further review