Luce Ian
Luce Ian

Reputation: 257

How to set global font-family in Apache FOP?

This is what I've used before:

 <fo:block font-family="Tahoma">Text</fo:block>

How can I specify that "Tahoma" is the font-family for the entire document?

I am looking for an equivalent of CSS's

body {
  font-family: "Tahoma";
}

Upvotes: 8

Views: 14066

Answers (4)

D Mo
D Mo

Reputation: 121

you can use the node fo:wrapper to inherit properties to its content-childs

<fo:page-sequence master-reference="A4-portrait">
    <fo:flow flow-name="xsl-region-body">
        <fo:wrapper font-size="10pt" font-family="Tahoma">
            <fo:block>
                Text <xsl:value-of select="name"/>
            </fo:block>
            <fo:block>
                Another text
            </fo:block>
        </fo:wrapper>
    </fo:flow>   
</fo:page-sequence>

Upvotes: 4

Michał Krzemiński
Michał Krzemiński

Reputation: 1251

If you want to set default font for whole document you can set it in fo:root. It should get inherited by every child-node without specified font-family.

<fo:root font-family="Tahoma">
    <!-- rest of document -->
</fo:root>

Upvotes: 17

bwa-
bwa-

Reputation: 139

There is no way to do this the way it is done in CSS if you do not actually HAVE an element to match for your particular font. If all you want is set a font for everything but some exception, setting it on <fo:root> then changing it when you need to should do the trick. Whether the font is a default font or defined via your config file does not make a difference.

Edit:

The equivalent of

body {   font-family: "Tahoma"; }

would be

<xsl:template match="body">
    <fo:block font-family="Tahoma">
        Content
    </fo:block>
</xsl:template>

Upvotes: 0

stanlyF
stanlyF

Reputation: 266

  <fonts>
    <referenced-fonts>
      <match font-family="Tahoma"/>
    </referenced-fonts>
  </fonts>

OR

<fo:page-sequence master-reference="A4-portrait">
  <fo:flow flow-name="xsl-region-body">
    <fo:block font-size="10pt" font-family="Tahoma">
      Text <xsl:value-of select="name"/>
    </fo:block>
  </fo:flow>   
</fo:page-sequence>

Upvotes: 0

Related Questions