summaryrefslogtreecommitdiff
path: root/app-text/fop-corefonts-metrics/files/config.xsl
blob: 0d3eae3555aae07b6d9b11edbdea1618cb8d070d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
 
 <xsl:output
  method="xml" version="1.0"
  encoding="utf-8"
  indent="yes"
  omit-xml-declaration="yes"
  media-type="text/xml" />

 <xsl:param name="ttfdir"/>
 <xsl:param name="xmldir"/>
 <xsl:param name="destdir"/>
 <xsl:param name="aliasfile"/>

 <xsl:variable name="aliases" select="document($aliasfile)"/>

 <xsl:template match="/">
  <configuration>
   <fonts>
    <xsl:apply-templates select="/fonts"/>
   </fonts>
  </configuration>
 </xsl:template>

 <xsl:template match="font">
  <xsl:variable name="x" select="document(concat($xmldir,'/',@name,'.xml'))"/>
  <xsl:variable name="fn" select="$x/font-metrics/font-name"/>
  <xsl:comment>font-name: <xsl:value-of select="$fn"/></xsl:comment>
  <font metrics-file="{$destdir}/{@name}.xml" kerning="yes" embed-file="{$ttfdir}/{@name}.ttf">
   <xsl:variable name="n"><!-- font name -->
    <xsl:choose>
	 <xsl:when test="contains($fn,',')">
	  <xsl:value-of select="substring-before($fn,',')"/>
	 </xsl:when>
	 <xsl:when test="$fn">
	  <xsl:value-of select="$fn"/>
	 </xsl:when>
	 <xsl:otherwise>
	  <xsl:value-of select="@name"/>
	 </xsl:otherwise>
	</xsl:choose>
   </xsl:variable>
   <xsl:variable name="a"><!-- attributes -->
	<xsl:if test="contains($fn,',')">
	 <xsl:value-of select="substring-after($fn,',')"/>
	</xsl:if>
   </xsl:variable>
   <xsl:variable name="style">
	<xsl:choose>
	 <xsl:when test="contains($a,'Italic')">italic</xsl:when>
	 <xsl:otherwise>normal</xsl:otherwise>
	</xsl:choose>
   </xsl:variable>
   <xsl:variable name="weight">
	<xsl:choose>
	 <xsl:when test="contains($a,'Bold')">bold</xsl:when>
	 <xsl:otherwise>normal</xsl:otherwise>
	</xsl:choose>
   </xsl:variable>
   <xsl:variable name="nn" select="@name"/>
   <xsl:for-each select="$aliases/fonts/font[@name=$n or @name=$nn]/alias[text()!=$n and text()!=$nn]">
	<font-triplet name="{./text()}" style="{$style}" weight="{$weight}"/>
   </xsl:for-each>
   <font-triplet name="{$n}" style="{$style}" weight="{$weight}"/>
   <font-triplet name="{@name}" style="normal" weight="normal"/>
  </font>
 </xsl:template>

</xsl:stylesheet>