I am trying to scale an SVG image, by using external-graphic with the content-width and content-height attributes set. Unfortunately whether I use "scale-to-fit" (to fit the width/height attributes), or an explicit length, the graphic itself is not scaled. I was not 100% sure that content-width and content-height should scale the image, so I looked at the "XHTML to XSL formatting objects" example XSLT file at http://www.antennahouse.com/axf11sampleEN.htm. From there it looks like I'm generating the right XSL, and FOP is not scaling the images as it should. I have seen the example of a scaled image in the FOP documentation. It uses an instream-foreign-object SVG, which references the external SVG using "svg:image" and explicitly set width and height. This does rescale the image, but unfortunately there is no way to have the image size determined from the layout context. For example, XSL sizes such as "80%" to show an image with 80% of the width of the current reference port do not work. I am stuck working around this problem by using explicit sizes, and the instream-foreign-object method for rescaling the image. It would be nice if content-width and content-height were honoured. cheers, -- Jamie
Yes, these properties are ignored, see bug 3279. To scale an image using external-graphic, put it into a table-cell of appropriate width. The height will then be scaled automatically.
Unfortunately I didn't have much luck with that. The image was scaled but positioned wrongly, off the bottom of its area instead of in the area. I have tried to fix content-width and content-height and I've had some luck. ("scale-to-fit" now works). However now I don't have the image at the correct horizontal position, and I don't really understand the flow of position data well enough. content-width="scale-to-fit" width="80%" doesn't work (it produces a bad PDF containing "NaN"), which of course is really what I want to do.
Created attachment 846 [details] This patch makes content-width work to some extent
The above patch makes content-width (and height) accept "scale-to-fit", and does scale an SVG image if they are used. Absolute sizes also work. Percentage sizes in content-width/height should work (they are percentage of the image intrinsic size), but I haven't tried them. I have only tested instream-foreign-object containing an SVG. It's entirely possible that external-graphic doesn't scale properly. Specifying only one dimension to hasn't been properly coded (for calculating the surrounding area size while preserving the image aspect ratio), and I've no particular intention of doing that. Specifying "width='80%' content-width='scale-to-fit'" doesn't work. It generates a bad PDF containing "NaN". I don't understand how widths are propagated through the area hierarchy so I won't be fixing this. The image, though scaled nicely (on a PDF), is rendered at the wrong position. There's a hack (x -= width/2) to move it which does help, but that's still wrong. I have no idea how to get the right position. (It's taken me 3 weeks to understand Fop well enough to get this patch going, which is too long for me so I'm giving up). Hope the patch helps.
*** Bug 2867 has been marked as a duplicate of this bug. ***
We had the same problem. Using width instead of content-width seems to fix the problem...
Bugzilla cleanup: Should be fixed in FOP 0.93/Trunk, where there is fully compliant support for the respective properties height, width, content-height and content-width on any fo:external-graphic or fo:instream-foreign- object.
batch transition pre-FOP1.0 resolved+fixed bugs to closed+fixed