i18n-postprocess_template.xsl 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. Copyright © 2004-2006 by Idiom Technologies, Inc. All rights reserved.
  4. IDIOM is a registered trademark of Idiom Technologies, Inc. and WORLDSERVER
  5. and WORLDSTART are trademarks of Idiom Technologies, Inc. All other
  6. trademarks are the property of their respective owners.
  7. IDIOM TECHNOLOGIES, INC. IS DELIVERING THE SOFTWARE "AS IS," WITH
  8. ABSOLUTELY NO WARRANTIES WHATSOEVER, WHETHER EXPRESS OR IMPLIED, AND IDIOM
  9. TECHNOLOGIES, INC. DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING
  10. BUT NOT LIMITED TO WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  11. PURPOSE AND WARRANTY OF NON-INFRINGEMENT. IDIOM TECHNOLOGIES, INC. SHALL NOT
  12. BE LIABLE FOR INDIRECT, INCIDENTAL, SPECIAL, COVER, PUNITIVE, EXEMPLARY,
  13. RELIANCE, OR CONSEQUENTIAL DAMAGES (INCLUDING BUT NOT LIMITED TO LOSS OF
  14. ANTICIPATED PROFIT), ARISING FROM ANY CAUSE UNDER OR RELATED TO OR ARISING
  15. OUT OF THE USE OF OR INABILITY TO USE THE SOFTWARE, EVEN IF IDIOM
  16. TECHNOLOGIES, INC. HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
  17. Idiom Technologies, Inc. and its licensors shall not be liable for any
  18. damages suffered by any person as a result of using and/or modifying the
  19. Software or its derivatives. In no event shall Idiom Technologies, Inc.'s
  20. liability for any damages hereunder exceed the amounts received by Idiom
  21. Technologies, Inc. as a result of this transaction.
  22. These terms and conditions supersede the terms and conditions in any
  23. licensing agreement to the extent that such terms and conditions conflict
  24. with those set forth herein.
  25. This file is part of the DITA Open Toolkit project hosted on Sourceforge.net.
  26. See the accompanying license.txt file for applicable licenses.
  27. -->
  28. <!-- UPDATES: 20100524: SF Bug 2385466, disallow font-family="inherit" due to
  29. lack of support in renderers. -->
  30. <xsl:stylesheet version="2.0"
  31. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  32. xmlns:opentopic-i18n="http://www.idiominc.com/opentopic/i18n"
  33. xmlns:fo="http://www.w3.org/1999/XSL/Format"
  34. xmlns:x="adobe:ns:meta/"
  35. exclude-result-prefixes="opentopic-i18n x">
  36. <xsl:import href="plugin:org.dita.base:xsl/common/output-message.xsl"/>
  37. <dita:extension id="dita.xsl.xslfo.i18n-postprocess"
  38. behavior="org.dita.dost.platform.ImportXSLAction"
  39. xmlns:dita="http://dita-ot.sourceforge.net"
  40. />
  41. <xsl:param name="debug-enabled" select="'false'"/>
  42. <!-- Deprecated since 2.3 -->
  43. <xsl:variable name="msgprefix" select="'PDFX'"/>
  44. <xsl:variable name="font-mappings" select="document('cfg:fo/font-mappings.xml')/font-mappings"/>
  45. <xsl:variable name="default-font" select="$font-mappings/font-table/aliases/alias[. = 'Normal']/@name"/>
  46. <xsl:template match="fo:bookmark | fo:bookmark-label | fo:bookmark-title" priority="+10">
  47. <xsl:copy>
  48. <xsl:copy-of select="@*"/>
  49. <xsl:apply-templates/>
  50. </xsl:copy>
  51. </xsl:template>
  52. <xsl:template match="fo:bookmark//opentopic-i18n:text-fragment" priority="+10">
  53. <xsl:value-of select="."/>
  54. </xsl:template>
  55. <xsl:template match="*[@font-family][not(@font-family='inherit')]" priority="+1">
  56. <xsl:variable name="currFontFam" select="@font-family"/>
  57. <xsl:variable name="realFontName">
  58. <xsl:choose>
  59. <xsl:when test="$font-mappings/font-table/logical-font[@name=$currFontFam]">
  60. <xsl:value-of select="$currFontFam"/>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <!--Try search this name within font aliases-->
  64. <xsl:variable name="aliasValue" select="$font-mappings/font-table/aliases/alias[@name=$currFontFam]/."/>
  65. <xsl:if test="not($aliasValue)">
  66. <xsl:call-template name="output-message">
  67. <xsl:with-param name="id" select="'PDFX008W'"/>
  68. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$currFontFam"/></xsl:with-param>
  69. </xsl:call-template>
  70. </xsl:if>
  71. <xsl:value-of select="$aliasValue"/>
  72. </xsl:otherwise>
  73. </xsl:choose>
  74. </xsl:variable>
  75. <xsl:variable name="phys-font" select="$font-mappings/font-table/logical-font[@name=normalize-space($realFontName)]/physical-font[@char-set='default']"/>
  76. <xsl:variable name="physical-font-family">
  77. <xsl:variable
  78. name="font"
  79. select="$phys-font/font-face"/>
  80. <xsl:choose>
  81. <xsl:when test="$font">
  82. <xsl:value-of select="$font"/>
  83. </xsl:when>
  84. <xsl:otherwise>
  85. <xsl:value-of select="$default-font"/>
  86. </xsl:otherwise>
  87. </xsl:choose>
  88. </xsl:variable>
  89. <xsl:if test="$debug-enabled = 'true'">
  90. <xsl:comment>
  91. currFontFam = <xsl:value-of select="$currFontFam"/>
  92. physFontFam = <xsl:value-of select="normalize-space($physical-font-family)"/>
  93. </xsl:comment>
  94. </xsl:if>
  95. <xsl:copy>
  96. <xsl:copy-of select="@*[not(name() = 'font-family')]"/>
  97. <xsl:attribute name="line-height-shift-adjustment">disregard-shifts</xsl:attribute>
  98. <xsl:attribute name="font-family"><xsl:value-of select="normalize-space($physical-font-family)"/></xsl:attribute>
  99. <xsl:apply-templates/>
  100. </xsl:copy>
  101. </xsl:template>
  102. <xsl:template match="*[opentopic-i18n:text-fragment]">
  103. <xsl:copy>
  104. <xsl:apply-templates select="@*"/>
  105. <xsl:attribute name="line-height-shift-adjustment">disregard-shifts</xsl:attribute>
  106. <xsl:apply-templates/>
  107. </xsl:copy>
  108. </xsl:template>
  109. <xsl:template match="fo:instream-foreign-object//opentopic-i18n:text-fragment" priority="100">
  110. <xsl:apply-templates/>
  111. </xsl:template>
  112. <!-- FIXME: this should be in org.dita.pdf2.fop, but the dita.xsl.xslfo.i18n-postprocess extension point cannot be used for xsl:include -->
  113. <xsl:template match="x:xmpmeta//opentopic-i18n:text-fragment" priority="100">
  114. <xsl:apply-templates/>
  115. </xsl:template>
  116. <xsl:template match="x:xmpmeta//*[opentopic-i18n:text-fragment]" priority="100">
  117. <xsl:copy>
  118. <xsl:apply-templates select="@* | node()"/>
  119. </xsl:copy>
  120. </xsl:template>
  121. <xsl:template match="opentopic-i18n:text-fragment">
  122. <xsl:variable name="fontFace" select="ancestor::*[@font-family][not(@font-family = 'inherit')][1]/@font-family"/>
  123. <xsl:variable name="charSet" select="@char-set"/>
  124. <xsl:variable name="realFontName">
  125. <xsl:choose>
  126. <xsl:when test="$font-mappings/font-table/logical-font[@name=$fontFace]">
  127. <xsl:value-of select="$fontFace"/>
  128. </xsl:when>
  129. <xsl:otherwise>
  130. <!--Try search this name within font aliases-->
  131. <xsl:variable name="aliasValue" select="$font-mappings/font-table/aliases/alias[@name=$fontFace]/."/>
  132. <xsl:if test="not($aliasValue)">
  133. <xsl:call-template name="output-message">
  134. <xsl:with-param name="id" select="'PDFX008W'"/>
  135. <xsl:with-param name="msgparams">%1=<xsl:value-of select="$fontFace"/></xsl:with-param>
  136. </xsl:call-template>
  137. </xsl:if>
  138. <xsl:value-of select="$aliasValue"/>
  139. </xsl:otherwise>
  140. </xsl:choose>
  141. </xsl:variable>
  142. <xsl:variable name="logical-font" select="$font-mappings/font-table/logical-font[@name = normalize-space($realFontName)]"/>
  143. <xsl:variable name="phys-font.charset">
  144. <xsl:choose>
  145. <xsl:when test="$logical-font/physical-font[@char-set = $charSet]">
  146. <xsl:value-of select="$charSet"/>
  147. </xsl:when>
  148. <xsl:otherwise>default</xsl:otherwise>
  149. </xsl:choose>
  150. </xsl:variable>
  151. <xsl:variable name="phys-font" select="$logical-font/physical-font[@char-set = $phys-font.charset]"/>
  152. <xsl:variable name="font-style" select="$phys-font/font-style"/>
  153. <xsl:variable name="baseline-shift" select="$phys-font/baseline-shift"/>
  154. <xsl:variable name="override-size" select="$phys-font/override-size"/>
  155. <xsl:variable name="physical-font-family">
  156. <xsl:variable
  157. name="font"
  158. select="$phys-font/font-face"/>
  159. <xsl:choose>
  160. <xsl:when test="$font">
  161. <xsl:value-of select="$font"/>
  162. </xsl:when>
  163. <xsl:otherwise>
  164. <xsl:value-of select="$default-font"/>
  165. </xsl:otherwise>
  166. </xsl:choose>
  167. </xsl:variable>
  168. <xsl:if test="$debug-enabled = 'true'">
  169. <xsl:comment>
  170. currFontFam = <xsl:value-of select="$fontFace"/>
  171. physFontFam = <xsl:value-of select="normalize-space($physical-font-family)"/>
  172. </xsl:comment>
  173. </xsl:if>
  174. <fo:inline line-height="100%">
  175. <xsl:attribute name="font-family"><xsl:value-of select="normalize-space($physical-font-family)"/></xsl:attribute>
  176. <xsl:if test="$font-style">
  177. <xsl:attribute name="font-style"><xsl:value-of select="normalize-space($font-style)"/></xsl:attribute>
  178. </xsl:if>
  179. <xsl:if test="$baseline-shift">
  180. <xsl:attribute name="baseline-shift"><xsl:value-of select="normalize-space($baseline-shift)"/></xsl:attribute>
  181. </xsl:if>
  182. <xsl:if test="$override-size">
  183. <xsl:attribute name="font-size"><xsl:value-of select="normalize-space($override-size)"/></xsl:attribute>
  184. </xsl:if>
  185. <xsl:apply-templates/>
  186. </fo:inline>
  187. </xsl:template>
  188. <xsl:template match="*" priority="-1">
  189. <xsl:copy>
  190. <xsl:apply-templates select="@* | node()" />
  191. </xsl:copy>
  192. </xsl:template>
  193. <xsl:template match="@*|comment()|processing-instruction()" priority="-1">
  194. <xsl:copy />
  195. </xsl:template>
  196. <!-- XEP doesn't like to see font-family="inherit", though it's allowed by the XSLFO spec. -->
  197. <xsl:template match="@font-family[. = 'inherit']"/>
  198. </xsl:stylesheet>