You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-users@xmlgraphics.apache.org by lmhelp <lm...@wanadoo.fr> on 2008/09/16 20:17:13 UTC

scale-to-fit, svg group

Hi everyone,

Thank you for reading my post.
Suppose that I have something like that in a xsl stylesheet:
=========================================================
...
<fo:block>
  <fo:instream-foreign-object>
    <svg:svg width="4cm" height="4cm">
      <svg:g stroke="#FF0000">
        <line x1="0cm" y1="0cm" x2="4cm" y2="4cm" />
        <line x1="1cm" y1="1cm" x2="5cm" y2="5cm" />
        <line x1="2cm" y1="2cm" x2="6cm" y2="6cm" />
      </svg:g>
    </svg:svg>
  </fo:instream-foreign-object>
</fo:block>
...
=========================================================
As you can see, the svg lines are not small enough to fit into the 
4cm x 4cm square I have defined.

(This is a simple example in which all the elements in the svg group
are known. Suppose that in the general case they are not).

How could I make the svg group fit into a 4cm x 4cm block?

Probably by doing a dilatation (homothety) of the svg group...

I considered using the fo:instream-foreign-object properties:
content-width="scale-to-fit"
content-height="scale-to-fit"
scaling="uniform"
(or any other one that would be more appropriated of course!)

But:
- I am not sure that this is at the fo:instream-foreign-object level
  that a transform has to be applied to the svg group. Maybe it has 
  to be done at the svg level... I don't know.
- If the fo:instream-foreign-object properties I mentioned above are the 
  right ones to use, can you tell which values would be ok...

I would greatly appreciate your help.
Thanks in advance.

--
Lmhelp
-- 
View this message in context: http://www.nabble.com/scale-to-fit%2C-svg-group-tp19517624p19517624.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: scale-to-fit, svg group

Posted by lmhelp <lm...@wanadoo.fr>.
Thank you for your answer.

> Unfortunately, I know too little SVG to be able to tell off-hand what  
> the expected result is if the viewbox is too small to fit the content  
> (clipping?) 

I am not sure this is the proper way to put it but according to me, 
the overflowing content is hidden. You can only see through the viewbox... 
just as if you were looking through a keyhole.

"scale-to-fit" works well with an "external-graphic" fo element:
========================================================
<fo:external-graphic content-height="scale-to-fit" 
                     content-width="scale-to-fit" 
                     scaling="non-uniform" 
                     height="4cm" 
                     width="4cm" src="an_image.jpg"/>
========================================================

But unfortunately, it doesn't work when I use an i-f-o with "svg:svg",
"svg:g", "svg:line" 
elements inside.

Thank you for your explanations about "uniform", "non-uniform", the
specification without units, 
auto value for "content-width" and "content-height" and "scale-down-to-fit".

Do you think there could be a restriction?
The impossibility to scale an svg group of elements to fit a i-f-o with
fixed dimensions?
Any other ideas?

Thank you very much for your help.

(i-f-o = instream-foreign-object)

--
Lmhelp
-- 
View this message in context: http://www.nabble.com/scale-to-fit%2C-svg-group-tp19517624p19519558.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: scale-to-fit, svg group

Posted by Andreas Delmelle <an...@telenet.be>.
On Sep 16, 2008, at 20:17, lmhelp wrote:

Hi

> <snip />
> How could I make the svg group fit into a 4cm x 4cm block?
>
> Probably by doing a dilatation (homothety) of the svg group...
>
> I considered using the fo:instream-foreign-object properties:
> content-width="scale-to-fit"
> content-height="scale-to-fit"
> scaling="uniform"
> (or any other one that would be more appropriated of course!)

Unfortunately, I know too little SVG to be able to tell off-hand what  
the expected result is if the viewbox is too small to fit the content  
(clipping?)

Anyway, you're on the right track, I think.
Regardless of the dimensions specified in the SVG, all you would need  
in FO is:

<fo:instream-foreign-object
   height="4cm" width="4cm"
   content-height="scale-to-fit" content-width="scale-to-fit">

Whether you need uniform or non-uniform scaling depends on whether  
the SVG canvas is defined to be square (width=height, like the  
instream-foreign-object) or rectangular. To fit a rectangular shape  
into a square box, the aspect ratio obviously cannot be maintained.

'content-height' and 'content-width' indicate what should happen with  
the intrinsic dimensions of the SVG. (Note that these could be  
specified without units, as device-dependent pixels --in that case,  
you can use the 'source-resolution' entry in the user-configuration  
to determine the dpi ratio when interpreting these; default is the  
same as 'target-resolution', or 72; see [FOP_DIR]/conf/fop.xconf)

If they are 'auto' or not specified, then:
- if the SVG is wider/higher than 4cm, it will overflow or be clipped  
(depending on the 'overflow' property; to clip, set  
'overflow="hidden"' on the i-f-o)
- if it is narrower/lower, then 'display-align' (vertical) and 'text- 
align' (horizontal) should determine where/how the image is placed  
inside the 4x4 viewbox
- if the dimensions are equal, nothing worth mentioning

A value of 'scale-to-fit' will grow or shrink the intrinsic height/ 
width. Values of 'scale-down-to-fit' and 'scale-up-to-fit' (XSL 1.1;  
implemented in FOP Trunk, IIC; not sure about 0.95) will respectively  
shrink or grow the image if it is larger or smaller, but leave it  
unmeddled if it already fits.


HTH!

Cheers

Andreas

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


Re: scale-to-fit, svg group

Posted by lmhelp <lm...@wanadoo.fr>.
Hi,

Andreas, thank you for your contribution!

> it took me a while to figure out the intended effect...
> Changing the stroke-color for each of the three lines 
> does show that scaling works like a charm here.

This is all my fault!!!!!! I'm sorry!!!
I wanted a simple example to explain my problem
and I found (by chance) one that was misleading!!!

Like that, it is better:

<fo:instream-foreign-object
 height="4cm" width="4cm"
 content-height="scale-to-fit" content-width="scale-to-fit"
 scaling="uniform">
  <svg:svg width="60" height="60">
    <svg:g>
      <svg:line x1="0" y1="0" x2="0" y2="40" stroke="#FF0000" />
      <svg:line x1="4" y1="0" x2="4" y2="50" stroke="#00FF00" />
      <svg:line x1="8" y1="0" x2="8" y2="60" stroke="#0000FF" />
    </svg:g>
  </svg:svg>
</fo:instream-foreign-object>

Oh what a misfortune!

And your solution works!
That's great.
Thank a lot.

See you.

--
Lmhelp
-- 
View this message in context: http://www.nabble.com/scale-to-fit%2C-svg-group-tp19517624p19541150.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: scale-to-fit, svg group

Posted by Andreas Delmelle <an...@telenet.be>.
On Sep 16, 2008, at 22:44, lmhelp wrote:

Hi

> Thank you for you answer Jeremias.
> Doing what you suggest I get something very small
> and which definitely doesn't fit into the 4cmx4cm square as expected.
> You may be right about omitting "cm"...
>
> Any other idea?

Hmm, I was completely unaware of any issues with scaling of instream- 
foreign-objects.

Having run some tests here, how about something like:

<fo:instream-foreign-object
   height="4cm" width="4cm"
   content-height="scale-to-fit" content-width="scale-to-fit"
   scaling="uniform">
     <svg:svg width="60" height="60">
       <svg:g stroke="#FF0000">
         <svg:line x1="0" y1="0" x2="40" y2="40" />
         <svg:line x1="10" y1="10" x2="50" y2="50" />
         <svg:line x1="20" y1="20" x2="60" y2="60" />
       </svg:g>
     </svg:svg>
</fo:instream-foreign-object>

This seems to work nicely, although, it took me a while to figure out  
the intended effect...
Changing the stroke-color for each of the three lines does show that  
scaling works like a charm here.

With the above, the instrinsic width/height of the SVG will be  
computed as:

60 pixels * 1/72 dots-per-inch = 0.8333in = 21.167mm

The image will be scaled up to fit the viewport-area of the instream- 
foreign-object, and you will get a rather thick line (large pixels).

Setting the width and height to 600 pixels OTOH (and, of course,  
multiplying the x- and y-coordinates for the lines) produces a much  
thinner line in the output. All depends on what quality/precision you  
need. Seen that we're dealing with vector graphics, the difference is  
literally limited to the extra zeroes in the input... :-)



HTH!

Andreas

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


Re: scale-to-fit, svg group

Posted by lmhelp <lm...@wanadoo.fr>.
Thank you for you answer Jeremias.
Doing what you suggest I get something very small 
and which definitely doesn't fit into the 4cmx4cm square as expected.
You may be right about omitting "cm"...

Any other idea?
Thanks.

--
Lmhelp
-- 
View this message in context: http://www.nabble.com/scale-to-fit%2C-svg-group-tp19517624p19520224.html
Sent from the FOP - Users mailing list archive at Nabble.com.


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


Re: FOP with Spring MVC

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
I've only run through a tutorial of Spring MVC so I'm no specialist. But
as far as I know it's easy to add arbitrary servlets to the application
that you can refer to from your Spring MVC application. I'd simply embed
FOP is a servlet. HTH

On 16.09.2008 22:39:27 Chris Mizelle wrote:
> Has anyone used FOP with Spring MVC?  We have an application that uses XML
> and FOP to create PDS reports.  We are developing a new version using the
> Spring Framework (specifically Spring MVC) and would like to utilize the
> existing XSL.
> 
> Thanks.
> 




Jeremias Maerki


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


FOP with Spring MVC

Posted by Chris Mizelle <ch...@cox.net>.
Has anyone used FOP with Spring MVC?  We have an application that uses XML
and FOP to create PDS reports.  We are developing a new version using the
Spring Framework (specifically Spring MVC) and would like to utilize the
existing XSL.

Thanks.



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


Re: scale-to-fit, svg group

Posted by Jeremias Maerki <de...@jeremias-maerki.ch>.
On 16.09.2008 20:17:13 lmhelp wrote:
> 
> Hi everyone,
> 
> Thank you for reading my post.
> Suppose that I have something like that in a xsl stylesheet:
> =========================================================
> ...
> <fo:block>
>   <fo:instream-foreign-object>
>     <svg:svg width="4cm" height="4cm">
>       <svg:g stroke="#FF0000">
>         <line x1="0cm" y1="0cm" x2="4cm" y2="4cm" />
>         <line x1="1cm" y1="1cm" x2="5cm" y2="5cm" />
>         <line x1="2cm" y1="2cm" x2="6cm" y2="6cm" />
>       </svg:g>
>     </svg:svg>
>   </fo:instream-foreign-object>
> </fo:block>
> ...
> =========================================================
> As you can see, the svg lines are not small enough to fit into the 
> 4cm x 4cm square I have defined.
> 
> (This is a simple example in which all the elements in the svg group
> are known. Suppose that in the general case they are not).
> 
> How could I make the svg group fit into a 4cm x 4cm block?

I think the right way would be not to use "cm" inside the SVG content.
Instead you should define a viewBox="0 0 6 6" on the SVG element. The
thing would then look like this:

    <svg:svg width="4cm" height="4cm" viewBox="0 0 6 6">
      <svg:g stroke="#FF0000">
        <line x1="0" y1="0" x2="4" y2="4" />
        <line x1="1" y1="1" x2="5" y2="5" />
        <line x1="2" y1="2" x2="6" y2="6" />
      </svg:g>
    </svg:svg>

Maybe that helps.

> Probably by doing a dilatation (homothety) of the svg group...
> 
> I considered using the fo:instream-foreign-object properties:
> content-width="scale-to-fit"
> content-height="scale-to-fit"
> scaling="uniform"
> (or any other one that would be more appropriated of course!)
> 
> But:
> - I am not sure that this is at the fo:instream-foreign-object level
>   that a transform has to be applied to the svg group. Maybe it has 
>   to be done at the svg level... I don't know.
> - If the fo:instream-foreign-object properties I mentioned above are the 
>   right ones to use, can you tell which values would be ok...
> 
> I would greatly appreciate your help.
> Thanks in advance.
> 
> --
> Lmhelp
> -- 
> View this message in context: http://www.nabble.com/scale-to-fit%2C-svg-group-tp19517624p19517624.html
> Sent from the FOP - Users mailing list archive at Nabble.com.
> 



Jeremias Maerki


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