Problem scaling 'backgrounds' using external-graphic inside absolute block-container

View: New views
2 Messages — Rating Filter:   Alert me  

Problem scaling 'backgrounds' using external-graphic inside absolute block-container

by JonathanHeard :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi All,
    This is only my first post on this forum and only my second day of writing XSL:FO and using FOP - I am trying to produce a services catalogue for a friend who runs a small training business and my design goal is to maintain one copy of the catalogue in XML with both Web and PDF rendering. I'm using Ken Holman's 'Definitive XSL-FO' as a reference as well as Michael Key's "XSLT2.0 and XPath2.0 Programmer's Reference' to assist me with this.

I would very much like to be able to put a rounded rectangle box (or other SVG frame) around blocks of text with varying size. I know that using 'background-image' has no support for scaling (unless I could afford XEP which appears to have an extension for this)  - So I then though I was on to a winner by using the following:

 40 <fo:block-container overflow="hidden">
 41         <fo:block-container absolute-position="absolute" height="auto" width="auto" border="1px solid blue">
 42         <fo:block border="2px solid green">
 43         <fo:external-graphic src="url("box3.svg")" overflow="hidden" border="1px dashed black" content-height="    scale-to-fit" width="100%" height="100%" content-width="scale-to-fit" scaling="non-uniform" />
 44         </fo:block>
 45         </fo:block-container>
 46
 47         <fo:block border="3px solid yellow">
 48         <xsl:apply-templates select="title"/>
 49         <xsl:apply-templates select="duration"/>
 50         <xsl:apply-templates select="coursedesc"/>
 51         </fo:block>
 52
 53 </fo:block-container>
 
Please bear in mind that I've been messing with the properties of each object, so my choices above may not appear completely sane. Also the 'border' properties are there purely for me to see and debug the layout.

What I'm finding is that the blocks inserted by the templates 'title', 'duration' and 'coursedesc' grow the block on line 47 to the size of the text (as I want them to) and that the block-container at line 40 also grows just as big as the text.
However, the block-container at line 41 (positioned absolutely to allow it to sit behind the text content) always displays at the native size of the svg image and overflows the main block-container at line 40.

I'm really keen to know if anyone has a solution for this issue as it seems a reasonably key function to be able to dynamically scale a background image (I've hit exactly the same issue before with XHTML + CSS).
If there's some way I can explicitly set the height of the block-container at line 41 to be based on the final calculated height of it's parent or sibling then I'd probably be fine. But I see no way of achieving this?

Any advice would be very much appreciated on any way that I might achieve this effect.

Many Thanks
Jonathan

Re: Problem scaling 'backgrounds' using external-graphic inside absolute block-container

by Andreas Delmelle-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Jun 24, 2008, at 09:12, JonathanHeard wrote:

Hi

Apologies for the late reply

<snip />

> I would very much like to be able to put a rounded rectangle box  
> (or other
> SVG frame) around blocks of text with varying size. I know that using
> 'background-image' has no support for scaling (unless I could  
> afford XEP
> which appears to have an extension for this)  - So I then though I  
> was on to
> a winner by using the following:
>
>  40 <fo:block-container>
>  41         <fo:block-container absolute-position="absolute"  
> height="auto"
> width="auto" border="1px solid blue">
>  42         <fo:block border="2px solid green">
>  43         <fo:external-graphic src="url("box3.svg")"
> overflow="hidden" border="1px dashed black" content-height="
> scale-to-fit" width="100%" height="100%" content-width="scale-to-fit"
> scaling="non-uniform" />
>  44         </fo:block>
>  45         </fo:block-container>
>  46
>  47         <fo:block border="3px solid yellow">
>  48         <xsl:apply-templates select="title"/>
>  49         <xsl:apply-templates select="duration"/>
>  50         <xsl:apply-templates select="coursedesc"/>
>  51         </fo:block>
>  52
>  53 </fo:block-container>
>
> Bear in mind that I've been messing around a lot with the various  
> properties
> of each object, so my choices may not appear completely sane. Also the
> 'border' properties are there purely for me to see and debug the  
> layout.
> What I'm finding is that the blocks inserted by the templates 'title',
> 'duration' and 'coursedesc' force the block on line 47 to grow to  
> the size
> of the text, but because the block-container at line 41 is positioned
> absolutely to allow it to sit behind the text content, it has no  
> way of
> basing its size on the quantity of text.

One to achieve this, could be to use:
- one normal block-container (no absolute-position) to contain the whole
- one nested normal block-container with borders, surrounding the  
produced block
- four absolutely positioned block-containers containing the rounded  
corners

Both surrounding block-container's heights will grow to fit the block.
If the four block-containers for the corners then, are children of  
the first block-container (siblings to the b-c containing the block),  
their positions will be 'absolute' in that block-container, and you  
should be able to do something like:

<fo:block-container absolute-position="absolute" top="0" left="0">
...
<fo:block-container absolute-position="absolute" top="0" left="100%">
...
<fo:block-container absolute-position="absolute" top="100%" left="0">
...
<fo:block-container absolute-position="absolute" top="100%" left="100%">

This is roughly the idea. It will obviously still take some fiddling  
with those values to get the corners to align correctly with the  
borders of the block-container and overpaint the regular corners, but  
it definitely seems worth a shot.

HTH!

Cheers

Andreas

---------------------------------------------------------------------
To unsubscribe, e-mail: fop-users-unsubscribe@...
For additional commands, e-mail: fop-users-help@...