How to change the font for <package> on PDF generation

Here should go questions about transforming XML with XSLT and FOP.
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

How to change the font for <package> on PDF generation

Post by dleal »

Dear members,

I can configurate the font family for HTML generation process, because you only have to redefine the style, for example:

Code: Select all

.package {
font-family:"Courier New", Courier, monospace
}
on *.css file, but how can I do the same for PDF generation. On the generation properties I don't see such configuration property.

Thanks in advance,

David
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

For PDF output you can set the font family for the body text with the body.font.family parameter and the body font size with the body.font.master parameter. You can find an example in the article "How to Add a Font to the <oXygen/> Built-in FO processor" available on the Documentation page.


Regards,
Sorin
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

Thanks again for your fast reply. Following your recomendation I am not sure if I have explained well on my last post the problem, becuase I just want to change the font only for <package> node not for body font.

On your replay the properties to set look quite general for all body text. I don't see where I have to set that for example whenerer it will find <package>com.abc.x</package> I will obtain the text of com.abc.x in courier font for the generated document for example.

Thanks in advance,

David
pkthree
Posts: 4
Joined: Mon Apr 23, 2007 9:20 pm

Post by pkthree »

You could add this to your XSL customization layer:

<xsl:template match="package">
<fo:inline font-family="YourFont">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

Make sure your font is already added as previously discussed.
[url=http://docbook.theblog.ca[/url]DocBook case study[/url]
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Sorin,

Thanks again, I don't need to generate a new font becuase courier was defined. About the definition on the configuration file, your solution works only if you define the root node like this:

Code: Select all

<xsl:stylesheet version="1.0" xmlns:fo="http://www.w3.org/1999/XSL/Format">
otherwise you have to specify the long name:

Code: Select all

<xsl:template match="package">
<fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format font-family="Courier">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
Regards,

David
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

I want to do the same process for for <foreignphrase> in order to use a different length:

Code: Select all

<xsl:template match="foreignphrase">
<fo:inline font-family="Modern">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
it works for Courier font, but for Modern it doesn't. I have found the font names on location:

Code: Select all

C:\WINDOWS\Fonts
I have tried also with: Arial Narrow, Times New Roman, such fonts are very common, so I guess it should be built-in.

I am doing something wrong?

Where do I can find the fonts provided?


Thanks,

David
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

You have to register Modern, Arial Narrow or Times New Roman in a FOP configuration file which you must set for FOP in Options -> Preferences -> XML -> XSLT/FO/XQuery -> FO Processors. See the article about registering fonts in FOP on the Documentation page.


Regards,
Sorin
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

I am following the steps you recomend, I have generated the times and arial xml files using the ttconverter.bat.

My fopConfiguration.xml file looks like this:

Code: Select all

<?xml version="1.0"  encoding="iso-8859-1"?>
<configuration>
<fonts>
<font metrics-file="arial.xml" kerning="yes" embed-file="file:C:/Windows/Fonts/Arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
<font metrics-file="times.xml" kerning="yes" embed-file="file:C:/Windows/Fonts/times.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
</fonts>
</configuration>
I am assuming the location of *.ttf file has to be my local location of: C:/Windows/Fonts. I have added as external FO processor file on Oxygen configuration.

I didn't change the property body.font.family, because I don't want to change the default font, instead just to use Aria font for my: foreignphrase:

Code: Select all

<xsl:template match="foreignphrase">
<fo:inline font-family="Arial">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
¿What I am doing wrong?

Thanks,

David
pkthree
Posts: 4
Joined: Mon Apr 23, 2007 9:20 pm

Post by pkthree »

embed-file="file:C:/Windows/Fonts/Arial.ttf"

is the "file" necessary? Couldn't you just use:

embed-file="C:/Windows/Fonts/Arial.ttf"

or perhaps

embed-file="C:\Windows\Fonts\Arial.ttf"
[url=http://docbook.theblog.ca[/url]DocBook case study[/url]
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

I have tried both solutions and it doesn't work. Can you tellme another built-in font, except "courier" and "serif", for using on this case without adding new font.

Thanks,

David
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,
dleal wrote:

Code: Select all

<?xml version="1.0"  encoding="iso-8859-1"?>
<configuration>
...
<font-triplet name="Arial" style="normal" weight="normal"/>
...
<font-triplet name="Arial" style="normal" weight="normal"/>
...
</configuration>
You used the same name for both fonts in the attribute name. You should use different names.


Regards,
Sorin
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

Thanks again, I have modified, the fopConfiguration.xml, now I have:

Code: Select all


<?xml version="1.0"  encoding="iso-8859-1"?>
<configuration>
<fonts>
<font metrics-file="arial.xml" kerning="yes" embed-file="C:\Windows\Fonts\Arial.ttf">
<font-triplet name="Arial" style="normal" weight="normal"/>
</font>
<font metrics-file="times.xml" kerning="yes" embed-file="C:\Windows\Fonts\Times.ttf">
<font-triplet name="Times" style="normal" weight="normal"/>
</font>
</fonts>
</configuration>
and on the customization file I have:

Code: Select all

 <xsl:template match="foreignphrase">
<fo:inline font-family="Times">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
but I don't get times on foreignphrase...

Do you have any suggestion, thans in advance,

David
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

In order to reduce possible errors, I have moved the *.ttf to the same location of fopConfiguration.xml, so now I don't have the problem about the path on the XML, but the result is the same, it doesn't take into account the Arial/Time fonts.

Because it works with built-in fonts (I have tested it for Courier), please could you tell me another different font name that comes with Oxygen?

Thanks,

David
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post by sorin_ristache »

Hello,

The oXygen installer does not install or copy font files to your computer. The fonts that you can set in oXygen are the ones that the Java virtual machine can find on your computer. I think it is a FOP problem and probably you can get more help from Apache FOP experts on the FOP mailing list.


Regards,
Sorin
dleal
Posts: 41
Joined: Fri Dec 15, 2006 8:09 pm
Location: Madrid
Contact:

Post by dleal »

Dear Sorin,

Thanks again, just to higthlight, that it is also an Oxygen problem, because following the steps on the document "How to add a new font", I can't obtain the expected result. I am going to ask on such mailing list, if I find any solution, I will post on this forum.

Thanks again for your help,

David
Post Reply