i18n-postprocess.xsl 9.6 KB

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