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 Patrick Dean Rusk <Pa...@attbi.com> on 2003/01/24 01:19:51 UTC

How can I force a space in rendered output?

I have a need to put copyright symbols in my rendered text from time to
time, and I like to follow them with a space.  Because of some of the
transformation logic required when I do this, I can't easily ensure that an
actual space will appear in the event stream that FOP processes.  In other
words, I can't do the following:

<fo:character character="&#x00A9;"/> <fo:inline>2003</fo:inline>

What I'm looking for is a FO element that I can put between the
<fo:character> above and the <fo:inline>.  I thought that

<fo:character character=" "/>

would work, but it does not.

Does anyone know of an element that I can use?

Patrick Rusk


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


Re: How can I force a space in rendered output?

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Patrick Dean Rusk wrote:
> 	It doesn't work in the sense that the result of using the
> <fo:character character=" ">
> is visually indistinguishable from leaving it out.

Ah, yes there is indeed a bug there:
LineArea.java
     public int addCharacter(char data, LinkSet ls, boolean ul) {
     ...
             // if whitespace-collapse == true, discard character
             if (Character.isSpaceChar(data)
                     && whiteSpaceCollapse == WhiteSpaceCollapse.TRUE) {
                 return org.apache.fop.fo.flow.Character.OK;
             }
Bad idea... (should use addText, which also handles text decoration,
links and other stuff)

> 		<fo:block font-family="serif" font-size="8pt">
> 			<fo:character character="C"/>
> 			<xsl:value-of select="."/>
> 		</fo:block>
[snip]
> 	Note the three blocks above.  If I had to look at that and guess for each
> whether there would be a space after the "C", I would say the following:
> 
> 1) Don't know.  Depends upon whether the new line is collapsed into a space.
> 
> 2) I would give a higher probability of there being a space after the "C",
> because of the explicit extra spaces put in.
> 
Well it pays off to learn the details of the tools you
are using. In this case, its XSLT's whitespace handling
in style sheets, well specified in
  file:///C:/cygwin/home/pietsch/dnload/REC-xslt-19991116.html#strip

If you need whitespace in the transformation result,
use something like
   <xsl:text> </xsl:text>

J.Pietschmann


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


RE: How can I force a space in rendered output?

Posted by Patrick Dean Rusk <Pa...@attbi.com>.
> > What I'm looking for is a FO element that I can put between the
> > <fo:character> above and the <fo:inline>.  I thought that
> >
> > <fo:character character=" "/>
> >
> > would work, but it does not.
>
> In what sense it doesn't work? Also, if you can ensure an element
> follows the copyright character, you should be able to (unconditionally)
> put a space there too. Usually consecutive spaces are collapsed into
> one, therefore it shouldn't matter whether you get additional spaces
> form various sources at this point.
> If all fails, try a non-breaking space, &#xA0;

	It doesn't work in the sense that the result of using the
<fo:character character=" ">
is visually indistinguishable from leaving it out.

	Start with this XML:

----------- cut here --------------
<?xml version="1.0" encoding="utf-8"?>
<root>
	<copy>2003 Patrick Dean Rusk</copy>
</root>
----------- cut here --------------

	Process it with this XSL:

----------- cut here --------------
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fo="http://www.w3.org/1999/XSL/Format"
	version="1.0">

	<xsl:template match="root">
		<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
			<fo:layout-master-set>
				<fo:simple-page-master master-name="pg">
					<fo:region-body/>
				</fo:simple-page-master>
			</fo:layout-master-set>
			<fo:page-sequence master-reference="pg">
				<fo:flow flow-name="xsl-region-body">
					<xsl:apply-templates select="copy"/>
				</fo:flow>
			</fo:page-sequence>
		</fo:root>
	</xsl:template>

	<xsl:template match="copy">
		<fo:block font-family="serif" font-size="8pt">
			<fo:character character="C"/>
			<xsl:value-of select="."/>
		</fo:block>
		<!-- Extra spaces after the <fo:character> tag -->
		<fo:block font-family="serif" font-size="8pt">
			<fo:character character="C"/>
			<xsl:value-of select="."/>
		</fo:block>
		<fo:block font-family="serif" font-size="8pt">
			<fo:character character="C"/>
			<fo:character character=" "/>
			<xsl:value-of select="."/>
		</fo:block>	</xsl:template>

</xsl:stylesheet>
----------- cut here --------------

	Note the three blocks above.  If I had to look at that and guess for each
whether there would be a space after the "C", I would say the following:

1) Don't know.  Depends upon whether the new line is collapsed into a space.

2) I would give a higher probability of there being a space after the "C",
because of the explicit extra spaces put in.

3) I would definitely expect at least one space between the "C" and the text
of the "copy" node, forced by the <fo:character character=" "/>

	When I generate the .fo file directly with xalan, I get a two line file.
The first line is the <?xml> directive.  The second lines contains all of
the other elements, with *no* spaces between any of them.  Understanding
that none of the line breaks (beyond the first line) exist in the actual
file, here are the results:

----------- cut here --------------
<?xml version="1.0" encoding="UTF-8"?>
<fo:root
xmlns:fo="http://www.w3.org/1999/XSL/Format"><fo:layout-master-set><fo:simpl
e-page-master
master-name="pg"><fo:region-body/></fo:simple-page-master></fo:layout-master
-set><fo:page-sequence master-reference="pg"><fo:flow
flow-name="xsl-region-body"><fo:block font-size="8pt"
font-family="serif"><fo:character character="C"/>2003 Patrick Dean
Rusk</fo:block><fo:block font-size="8pt" font-family="serif"><fo:character
character="C"/>2003 Patrick Dean Rusk</fo:block><fo:block font-size="8pt"
font-family="serif"><fo:character character="C"/><fo:character character="
"/>2003 Patrick Dean Rusk</fo:block></fo:flow></fo:page-sequence></fo:root>
----------- cut here --------------

	Looking at this file, then, I would assume that the first two blocks would
not have a space after the "C", but I would still think the third block
would have the space.  However, all three do not have any space.

	In the last few minutes, I have figured out what I can do.  Rather than use
the <fo:character character="C"> tag, I can do

	<fo:inline>C </fo:inline>

or, in the case of my real use of the copyright symbol,

	<fo:inline>&#x00A9; </fo:inline>

	So, I have a workaround, but it sure seems to me like
<fo:character character=" "/>
is effectively being ignored.  I would guess that the spec does not intend
that.


	If I had to take a stab at guessing why this happens, I would suspect the
following.

<fo:character character="x"/> could essentially be translated to
<fo:inline>x</fo:inline>

Done for space, then, the result would be:
<fo:inline> </fo:inline>

I've noticed that XSLT treats that as semantically the same as:
<fo:inline/>
which generates nothing in rendered output.

	However, since the XSLT part of things is already done at this point, that
would suggest that the issue is in FOP's area tree handling or some other
such downstream process, so I'm not sure my speculation holds much water.

	So, Joerg, I'll leave it to your better judgement to decide whether this is
a bug in the handling of <fo:character character=" ">.

Pat


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


Re: How can I force a space in rendered output?

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Patrick Dean Rusk wrote:
> I have a need to put copyright symbols in my rendered text from time to
> time, and I like to follow them with a space.  Because of some of the
> transformation logic required when I do this, I can't easily ensure that an
> actual space will appear in the event stream that FOP processes.  In other
> words, I can't do the following:
> 
> <fo:character character="&#x00A9;"/> <fo:inline>2003</fo:inline>
> 
> What I'm looking for is a FO element that I can put between the
> <fo:character> above and the <fo:inline>.  I thought that
> 
> <fo:character character=" "/>
> 
> would work, but it does not.

In what sense it doesn't work? Also, if you can ensure an element
follows the copyright character, you should be able to (unconditionally)
put a space there too. Usually consecutive spaces are collapsed into
one, therefore it shouldn't matter whether you get additional spaces
form various sources at this point.
If all fails, try a non-breaking space, &#xA0;

J.Pietschmann


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