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 Andreia Oliveira <an...@reitoria.uminho.pt> on 2006/03/07 13:42:07 UTC

Fonts

Hi. I am a newbie in FOP and I am struggling with a question regarding
fonts.
 
I inherited a project from a colleague and I am a bit lost.
 
We want to generate pdf files. For that, currently (and until we have a
complete database structure built / and the .net engine that will generate
these pdf files), we are doing some tests to understand if we will be able
to generate the files as requested using fop.
 
An xml file, a xsd and a xslt were created.
The xml file has a special tag that we called XMLContent because it will
contain tags like <strong> and <em> inside the text. 
(Example: <field1>Here is my text. It will be <strong>difficult</strong> to
get it <em>formatted</em> correctly</field1>)
The xsd defined the proper fields as being of type XMLContent: 

<xs:element name="field1" type="um:XMLContent"/>

The xslt has a section were it tries to handle these xml tags.

<xsl:template name="XMLContent">
<xsl:apply-templates select="node()" />
<xsl:value-of select="text()" />
</xsl:template>
<xsl:template match="//em/text() | //strong/text()">
<fo:inline>
<xsl:if test="ancestor::em">
<xsl:attribute name="color">rgb(0,255,0)</xsl:attribute>
</xsl:if>
<xsl:if test="ancestor::strong">
<xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:if>
<xsl:value-of select="."/>
</fo:inline>
</xsl:template>

But, when I try to generate the pdf (using command line), the tags are
completely ignored (no text is output in bold or italic)
Also, in the log fop generates on the screen it does not return any error
regarding the fonts. It outputs "[INFO] setting up fonts" and continues...
 
Can someone help?
 
Thanks,
 
--------------------------------------
Andreia Oliveira
andreia@reitoria.uminho.pt
---------------------------------------
 

Re: Fonts

Posted by Andreas L Delmelle <a_...@pandora.be>.
On Mar 7, 2006, at 19:26, Andreia Oliveira wrote:

Hi,

> This new approach was attempted (separate templates as suggested).
> The result is the text inside field1 is not touched at all (as  
> before). It
> remains as before without any tranformation.
> It seems to me that fop is not even applying the template despite  
> the fact
> that the xml file as references to <em> and <strong> elements.

Just to get this straight: FOP never applies templates. That's the  
XSLT processor's job (Xalan, Saxon...).

> Maybe I did not explain myself clearly about my purpose:
> Inside one XML field  (fo:block) some <em> and <strong> tags may  
> appear.
> If so, fop, when generating the should generate the text inside the  
> <em> and
> <strong> tags in italic and bold.

Starting from something like:

<field>
   Unformatted text with some <em>italic</em> and
   <strong>bold</strong>, maybe some
   <strong><em>bold-italic</em></strong>, or even
   <em><strong>italic-bold</strong></em>?
</field>

Use this template for the 'field' nodes:

<xsl:template match="field">
   <fo:block>
     <xsl:apply-templates />
   </fo:block>
</xsl:template>

and the following two for the 'em' and 'strong' nodes:

<xsl:template match="em">
   <fo:wrapper font-style="italic">
     <xsl:apply-templates />
   </fo:wrapper>
</xsl:template>

<xsl:template match="strong">
   <fo:wrapper font-weight="bold">
     <xsl:apply-templates />
   </fo:wrapper>
</xsl:template>

would lead to the output (indented for readability)

<fo:block>
   Unformatted text with some
   <fo:wrapper font-style="italic">italic</
    and
   <fo:wrapper font-weight="bold">bold</
   , maybe some
   <fo:wrapper font-weight="bold">
     <fo:wrapper font-style="italic">bold-italic</
   </
   , or even
   <fo:wrapper font-style="italic">
     <fo:wrapper font-weight="bold">italic-bold</
   </
   ?
</

which FOP renders without any problems.

Should do the job nicely, unless there is another error hidden  
somewhere...

Cheers,

Andreas


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


RE: Fonts

Posted by Andreia Oliveira <an...@reitoria.uminho.pt>.
Hi.
This new approach was attempted (separate templates as suggested).
The result is the text inside field1 is not touched at all (as before). It
remains as before without any tranformation.
It seems to me that fop is not even applying the template despite the fact
that the xml file as references to <em> and <strong> elements.

Maybe I did not explain myself clearly about my purpose:
Inside one XML field  (fo:block) some <em> and <strong> tags may appear.
If so, fop, when generating the should generate the text inside the <em> and
<strong> tags in italic and bold.

Is this the correct approach for this process?

-----Original Message-----
From: J.Pietschmann [mailto:j3322ptm@yahoo.de] 
Sent: terça-feira, 7 de Março de 2006 15:15
To: fop-users@xmlgraphics.apache.org
Subject: Re: Fonts

Andreia Oliveira wrote:
...
> An xml file, a xsd and a xslt were created.
Fortunately, schema definitions (XSD) are irrelevant for FOP.

> (Example: <field1>Here is my text. It will be 
> <strong>difficult</strong> to get it <em>formatted</em> 
> correctly</field1>)

> <xsl:template name="XMLContent">
This matches elements with the name "XMLContent". There are no such elements
in your source file, because XMLContent is a *type*, therefore this template
never triggered. In you case this makes not much of a difference, because
you basically want the default template behaviour anyway.
You can't match types unless you are using a XSLT2 processor.

> <xsl:apply-templates select="node()" /> <xsl:value-of select="text()" 
> />
    ^^^^^^^^^
This will duplicate the first text node of the element, because all child
nodes (including all text nodes) have already been processed by the
apply-templates above.

> <xsl:template match="//em/text() | //strong/text()">
You should never start a template match with a "//".

> <fo:inline>
> <xsl:if test="ancestor::em">
Matching multiple elements and then dispatching again inside a template is
considered bad style.

You should have written two templates:
<xsl:template match="em">
   <fo:wrapper color="rgb(0,255,0)">
      <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

<xsl:template match="strong">
   <fo:wrapper font-weight="bold">
      <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

Note further that you should use fo:wrapper instead of fo:inline, unless you
really want to generate inline areas.

J.Pietschmann

---------------------------------------------------------------------
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: Fonts

Posted by "J.Pietschmann" <j3...@yahoo.de>.
Andreia Oliveira wrote:
...
> An xml file, a xsd and a xslt were created.
Fortunately, schema definitions (XSD) are irrelevant for FOP.

> (Example: <field1>Here is my text. It will be <strong>difficult</strong> to
> get it <em>formatted</em> correctly</field1>)

> <xsl:template name="XMLContent">
This matches elements with the name "XMLContent". There are no
such elements in your source file, because XMLContent is a *type*,
therefore this template never triggered. In you case this makes not
much of a difference, because you basically want the default template
behaviour anyway.
You can't match types unless you are using a XSLT2 processor.

> <xsl:apply-templates select="node()" />
> <xsl:value-of select="text()" />
    ^^^^^^^^^
This will duplicate the first text node of the element, because
all child nodes (including all text nodes) have already been processed
by the apply-templates above.

> <xsl:template match="//em/text() | //strong/text()">
You should never start a template match with a "//".

> <fo:inline>
> <xsl:if test="ancestor::em">
Matching multiple elements and then dispatching again inside
a template is considered bad style.

You should have written two templates:
<xsl:template match="em">
   <fo:wrapper color="rgb(0,255,0)">
      <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

<xsl:template match="strong">
   <fo:wrapper font-weight="bold">
      <xsl:apply-templates/>
   </fo:inline>
</xsl:template>

Note further that you should use fo:wrapper instead of fo:inline, unless
you really want to generate inline areas.

J.Pietschmann

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