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 Rob Sargent <rs...@xmission.com> on 2011/12/13 05:43:55 UTC

Cannot set parameters when generating IF

I'm using fop-1.0 compile a year or so ago.  Perhaps I just need to
download the trunk?  Certainly happy to do that given a glimmer of hope
that it will solve my problem.

I think I've hit a catch-22 when generating IF
(application/X-fop-areatree) output. To generate this format I believe
one is forced to use "factory.newTransformer.transform(xsltSource)" as
opposed to the no-arg constructor.  And once one has done that one
cannot use transformer.setParameter(key, value).

This makes using <xsl:param> in the IF-generating style-sheet neigh
impossible. Or I'm off my rocker (again).


            Transformer transformer = null;
            TransformerFactory factory = TransformerFactory.newInstance();

            if (xsltSource == null) {
                // Not generating IF
                transformer = factory.newTransformer();
            }
            else {
                // Generating IF, xsltSource is
                transformer = factory.newTransformer(xsltSource);
            }
            if (xsltParameterMap != null) {
                // The values in the map are not applied when making IF
                // I suspect because the stylesheet has already been read
                applyXsltParameterMap(transformer); //Iterates on map:
transformer.setParameter(k,v)
            }
            transformer.transform(src, result);
            resultBytes = out.toByteArray();

Where xsltSource is constructed via

            xslUrl = new URL("jar:file://" + getBundlePath() +
                              "/lib/book-printing-core.jar!/" +
xsltFilename); // <== something.xsl
            inputstream = xslUrl.openStream();
            BufferedInputStream bis = new BufferedInputStream(inputstream);
           
            xsltSource = new StreamSource(bis);

If I don't use the second form of the constructor (with stylesheet) I do
not get the IF.  Indeed it's an error condition because the transformer
expect fo not xsl as the source.


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


Re: Cannot set parameters when generating IF

Posted by Craig Ringer <ri...@ringerc.id.au>.
On 13/12/11 12:43, Rob Sargent wrote:
>             xslUrl = new URL("jar:file://" + getBundlePath() +
>                               "/lib/book-printing-core.jar!/" +
> xsltFilename); // <== something.xsl

On a side-note, it's probably nicer to get your stylesheets using the
ClassLoader's getResourceAsStream(...) method, rather than indirectly by
constructing an absolute jar: URL.

Anyway, I can verify that at least in my environment (JBoss AS 7.1-pre,
Sun JDK 7, FOP 1.0), parameters ARE applied to the stylesheet when
setParameter(...) is called on a Transformer instance created using
TransformerFactory.newTransformer(stylesheet) . Are you sure your
'applyXsltParameterMap' method is really doing what you think it's
doing? Are you sure it's getting passed the parameters you think it's
being passed? Have you checked for oddities like trailing spaces or
similar in the parameter names, either in the stylesheet or param map?

--
Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Craig Ringer <ri...@ringerc.id.au>.
On 13/12/11 13:20, Rob Sargent wrote:
> I didn't mention that I'm developing on linux, in part because most
> users are on Windows and Macs.  I did mention that I'm running fop-1.0
> from code I downloaded about a year ago.  It's the official 1.0 release
> I believe. Certainly not from svn.
My bad; I'm blind.

> I'm just using the generate IF to get the size of a particular
> fop-table.  I use that value to dynamically size region-before or
> region-after.  Because I'm not using the IF to generate a pdf, I don't
> need to mimic.
OK, so you throw the IF output away, fine. You're still eventually
producing  a PDF (or some other output) via fop, right?

If you are, then unless you mimic the correct output format your sizing
calculations may be based on *incorrect* inputs, because the font
metrics fop is using for the IF you're doing your calculations on may be
different to the font metrics used in the output of the final document.

Imagine if you wanted to size a particular piece of text to a region, so
you produced intermediate format to get an idea of how big it was going
to be then tweaked your leading and font size so the text would fit.
What would happen if you used Helvetica Regular for the sizing
estimation, then actually typeset the PDF using Helvetica Light or
Helvetica Condensed Regular?

> And it's been a while but I'm pretty sure using mimic in
> my case just blows up.  Again, because I don't want to go past IF
> generation.
You can generate IF when mimicing a renderer then throw it away, no
problem. At least I can confirm that's true for the PDF renderer - and I
don't see how the ability to generate and work with area-tree IF would
be useful _without_ that capability, really.

--
Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Rob Sargent <rs...@xmission.com>.
I didn't mention that I'm developing on linux, in part because most
users are on Windows and Macs.  I did mention that I'm running fop-1.0
from code I downloaded about a year ago.  It's the official 1.0 release
I believe. Certainly not from svn.

I'm just using the generate IF to get the size of a particular
fop-table.  I use that value to dynamically size region-before or
region-after.  Because I'm not using the IF to generate a pdf, I don't
need to mimic.  And it's been a while but I'm pretty sure using mimic in
my case just blows up.  Again, because I don't want to go past IF
generation.

On 12/12/2011 10:08 PM, Craig Ringer wrote:
> On 13/12/11 13:00, Rob Sargent wrote:
>> Well thanks Craig.  That might be good news, indeed. Are you positive
>> the value of the param isn't defaulted when you're generating IF, not
>> pdf. They sure don't kick in for me, but I'm not using the "mimic"
>> stuff. Is that the crux of the issue?
> Yes, I'm absolutely certain the parameters are properly applied. If they
> were not then none of the images would get inserted into my PDFs as the
> main parameter given is used, among other things, as a prefix for image
> URIs.
>
> As for mimic: As per the documentation, you must tell the IF renderer to
> mimic a particular output format if you want the layout generated for
> the IF to be appropriate for feeding back into fop to generate the final
> format later. Otherwise, because different output formats have different
> fonts with different font metrics, you'll get funky spacing issues in
> your text. I guess it might be OK to go without if you don't intend to
> feed the IF back into fop at all, but I'd still want to know which
> format's metrics I was using.
>
> What's your environment? Which version of fop are you using? (You should
> always mention this sort of thing when asking any kind of question).
>
> --
> Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Craig Ringer <ri...@ringerc.id.au>.
On 12/13/2011 02:15 PM, Rob Sargent wrote:
> Craig is right. I'm wrong.  I do get my parameters set (but only if the
> stylesheet compiles, funnily enough).
>
> Sorry for the noise.
No problem; I'm glad it's sorted out. I *really* wish my current issues 
with fonts were that well behaved, as I'm tearing my hair out wrangling 
20MB of mostly-overlapping embedded subsets of common fonts in a 25MB 
document...

--
Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Rob Sargent <rs...@xmission.com>.
Craig is right. I'm wrong.  I do get my parameters set (but only if the
stylesheet compiles, funnily enough).

Sorry for the noise.

rjs


On 12/12/2011 10:32 PM, Rob Sargent wrote:
> It's the fonts and font sizes I wish to send in a parameters, among
> other things.  I definitely need to know which fonts are in play to size
> correctly.
>
> And before I forget: Thanks for correcting the URL handling.  Been a
> thorn for some time.
>
> As for mimic: As per the documentation, you must tell the IF renderer to
>> mimic a particular output format if you want the layout generated for
>> the IF to be appropriate for feeding back into fop to generate the final
>> format later. Otherwise, because different output formats have different
>> fonts with different font metrics, you'll get funky spacing issues in
>> your text. I guess it might be OK to go without if you don't intend to
>> feed the IF back into fop at all, but I'd still want to know which
>> format's metrics I was using.
>>
>> What's your environment? Which version of fop are you using? (You should
>> always mention this sort of thing when asking any kind of question).
>>
>> --
>> Craig Ringer
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>

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


Re: Cannot set parameters when generating IF

Posted by Rob Sargent <rs...@xmission.com>.
It's the fonts and font sizes I wish to send in a parameters, among
other things.  I definitely need to know which fonts are in play to size
correctly.

And before I forget: Thanks for correcting the URL handling.  Been a
thorn for some time.

As for mimic: As per the documentation, you must tell the IF renderer to
> mimic a particular output format if you want the layout generated for
> the IF to be appropriate for feeding back into fop to generate the final
> format later. Otherwise, because different output formats have different
> fonts with different font metrics, you'll get funky spacing issues in
> your text. I guess it might be OK to go without if you don't intend to
> feed the IF back into fop at all, but I'd still want to know which
> format's metrics I was using.
>
> What's your environment? Which version of fop are you using? (You should
> always mention this sort of thing when asking any kind of question).
>
> --
> Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Craig Ringer <ri...@ringerc.id.au>.
On 13/12/11 13:00, Rob Sargent wrote:
> Well thanks Craig.  That might be good news, indeed. Are you positive
> the value of the param isn't defaulted when you're generating IF, not
> pdf. They sure don't kick in for me, but I'm not using the "mimic"
> stuff. Is that the crux of the issue?

Yes, I'm absolutely certain the parameters are properly applied. If they
were not then none of the images would get inserted into my PDFs as the
main parameter given is used, among other things, as a prefix for image
URIs.

As for mimic: As per the documentation, you must tell the IF renderer to
mimic a particular output format if you want the layout generated for
the IF to be appropriate for feeding back into fop to generate the final
format later. Otherwise, because different output formats have different
fonts with different font metrics, you'll get funky spacing issues in
your text. I guess it might be OK to go without if you don't intend to
feed the IF back into fop at all, but I'd still want to know which
format's metrics I was using.

What's your environment? Which version of fop are you using? (You should
always mention this sort of thing when asking any kind of question).

--
Craig Ringer

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


Re: Cannot set parameters when generating IF

Posted by Rob Sargent <rs...@xmission.com>.
Well thanks Craig.  That might be good news, indeed. Are you positive
the value of the param isn't defaulted when you're generating IF, not
pdf. They sure don't kick in for me, but I'm not using the "mimic"
stuff. Is that the crux of the issue?

On 12/12/2011 09:48 PM, Craig Ringer wrote:
> On 12/13/2011 12:43 PM, Rob Sargent wrote:
>> I'm using fop-1.0 compile a year or so ago.  Perhaps I just need to
>> download the trunk?  Certainly happy to do that given a glimmer of hope
>> that it will solve my problem.
>>
>> I think I've hit a catch-22 when generating IF
>> (application/X-fop-areatree) output. To generate this format I believe
>> one is forced to use "factory.newTransformer.transform(xsltSource)" as
>> opposed to the no-arg constructor.  And once one has done that one
>> cannot use transformer.setParameter(key, value).
>
> What?
>
> Why not?
>
>> This makes using<xsl:param>  in the IF-generating style-sheet neigh
>> impossible. Or I'm off my rocker (again).
>
> It's certainly possible to set XSLT params. Here's some code almost
> verbatim from what I'm working on. It makes references to a `conf'
> object which holds pre-configured XSLT transformer factories etc, but
> you're probably just going to allocate the factory directory.
>
>
>             FopFactory fopFactory = conf.getFopFactory();
>
>             // Create a user agent (a fop processor, really) to do the
> work.
>             FOUserAgent userAgent = fopFactory.newFOUserAgent();
>
>             //Create an instance of the target renderer so the
> XMLRenderer can use its font setup
>             Renderer targetRenderer =
> userAgent.getRendererFactory().createRenderer(
>                     userAgent, outMimeType);
>
>             //Create the XMLRenderer to create the area tree XML
>             XMLRenderer xmlRenderer = new XMLRenderer();
>             xmlRenderer.setUserAgent(userAgent);
>             // TODO, probably only in fop svn:
>             // use setTransformerHandler to output directly to W3C DOM
> insead of
>             // serializing to file.
>
>             //Tell the XMLRenderer to mimic the target renderer
>             xmlRenderer.mimicRenderer(targetRenderer);
>
>             //Make sure the prepared XMLRenderer is used
>             userAgent.setRendererOverride(xmlRenderer);
>             userAgent.setURIResolver(uriResolver);
>
>             // Construct fop (the MIME type here is unimportant due to
> the override
>             // on the user agent)
>             Fop fop = fopFactory.newFop(null, userAgent, atOutStream);
>
>             // Setup XSLT
>             TransformerFactory transformerFactory =
> conf.getTransformerFactory();
>             Transformer transformer =
> transformerFactory.newTransformer( xsltSource );
>             transformer.setParameter("classadSection", classadSection);
>
>             // Resulting SAX events (the generated FO) must be piped
> through to FOP
>             Result res = new SAXResult(fop.getDefaultHandler());
>
>             File f = File.createTempFile("xslfo", ".xml");
>             FileOutputStream fos = new FileOutputStream(f);
>             Result res2 = new StreamResult(fos);
>             transformer.transform( xmlInStream, res2 );
>             fos.close();
>>
>>
>>              Transformer transformer = null;
>>              TransformerFactory factory =
>> TransformerFactory.newInstance();
>>
>>              if (xsltSource == null) {
>>                  // Not generating IF
>>                  transformer = factory.newTransformer();
>>              }
>>              else {
>>                  // Generating IF, xsltSource is
>>                  transformer = factory.newTransformer(xsltSource);
>>              }
>>              if (xsltParameterMap != null) {
>>                  // The values in the map are not applied when making IF
>>                  // I suspect because the stylesheet has already been
>> read
>>                  applyXsltParameterMap(transformer); //Iterates on map:
>> transformer.setParameter(k,v)
>>              }
>>              transformer.transform(src, result);
>>              resultBytes = out.toByteArray();
>>
>> Where xsltSource is constructed via
>>
>>              xslUrl = new URL("jar:file://" + getBundlePath() +
>>                                "/lib/book-printing-core.jar!/" +
>> xsltFilename); //<== something.xsl
>>              inputstream = xslUrl.openStream();
>>              BufferedInputStream bis = new
>> BufferedInputStream(inputstream);
>>
>>              xsltSource = new StreamSource(bis);
>>
>> If I don't use the second form of the constructor (with stylesheet) I do
>> not get the IF.  Indeed it's an error condition because the transformer
>> expect fo not xsl as the source.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
>> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>>
>

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


Re: Cannot set parameters when generating IF

Posted by Craig Ringer <ri...@ringerc.id.au>.
On 12/13/2011 12:43 PM, Rob Sargent wrote:
> I'm using fop-1.0 compile a year or so ago.  Perhaps I just need to
> download the trunk?  Certainly happy to do that given a glimmer of hope
> that it will solve my problem.
>
> I think I've hit a catch-22 when generating IF
> (application/X-fop-areatree) output. To generate this format I believe
> one is forced to use "factory.newTransformer.transform(xsltSource)" as
> opposed to the no-arg constructor.  And once one has done that one
> cannot use transformer.setParameter(key, value).

What?

Why not?

> This makes using<xsl:param>  in the IF-generating style-sheet neigh
> impossible. Or I'm off my rocker (again).

It's certainly possible to set XSLT params. Here's some code almost 
verbatim from what I'm working on. It makes references to a `conf' 
object which holds pre-configured XSLT transformer factories etc, but 
you're probably just going to allocate the factory directory.


             FopFactory fopFactory = conf.getFopFactory();

             // Create a user agent (a fop processor, really) to do the 
work.
             FOUserAgent userAgent = fopFactory.newFOUserAgent();

             //Create an instance of the target renderer so the 
XMLRenderer can use its font setup
             Renderer targetRenderer = 
userAgent.getRendererFactory().createRenderer(
                     userAgent, outMimeType);

             //Create the XMLRenderer to create the area tree XML
             XMLRenderer xmlRenderer = new XMLRenderer();
             xmlRenderer.setUserAgent(userAgent);
             // TODO, probably only in fop svn:
             // use setTransformerHandler to output directly to W3C DOM 
insead of
             // serializing to file.

             //Tell the XMLRenderer to mimic the target renderer
             xmlRenderer.mimicRenderer(targetRenderer);

             //Make sure the prepared XMLRenderer is used
             userAgent.setRendererOverride(xmlRenderer);
             userAgent.setURIResolver(uriResolver);

             // Construct fop (the MIME type here is unimportant due to 
the override
             // on the user agent)
             Fop fop = fopFactory.newFop(null, userAgent, atOutStream);

             // Setup XSLT
             TransformerFactory transformerFactory = 
conf.getTransformerFactory();
             Transformer transformer = 
transformerFactory.newTransformer( xsltSource );
             transformer.setParameter("classadSection", classadSection);

             // Resulting SAX events (the generated FO) must be piped 
through to FOP
             Result res = new SAXResult(fop.getDefaultHandler());

             File f = File.createTempFile("xslfo", ".xml");
             FileOutputStream fos = new FileOutputStream(f);
             Result res2 = new StreamResult(fos);
             transformer.transform( xmlInStream, res2 );
             fos.close();
>
>
>              Transformer transformer = null;
>              TransformerFactory factory = TransformerFactory.newInstance();
>
>              if (xsltSource == null) {
>                  // Not generating IF
>                  transformer = factory.newTransformer();
>              }
>              else {
>                  // Generating IF, xsltSource is
>                  transformer = factory.newTransformer(xsltSource);
>              }
>              if (xsltParameterMap != null) {
>                  // The values in the map are not applied when making IF
>                  // I suspect because the stylesheet has already been read
>                  applyXsltParameterMap(transformer); //Iterates on map:
> transformer.setParameter(k,v)
>              }
>              transformer.transform(src, result);
>              resultBytes = out.toByteArray();
>
> Where xsltSource is constructed via
>
>              xslUrl = new URL("jar:file://" + getBundlePath() +
>                                "/lib/book-printing-core.jar!/" +
> xsltFilename); //<== something.xsl
>              inputstream = xslUrl.openStream();
>              BufferedInputStream bis = new BufferedInputStream(inputstream);
>
>              xsltSource = new StreamSource(bis);
>
> If I don't use the second form of the constructor (with stylesheet) I do
> not get the IF.  Indeed it's an error condition because the transformer
> expect fo not xsl as the source.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: fop-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: fop-users-help@xmlgraphics.apache.org
>


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