You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

code-point-mapping.xsl 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. <!--
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. -->
  15. <!-- $Id$ -->
  16. <xsl:stylesheet version="2.0"
  17. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  18. <xsl:output method="text"/>
  19. <xsl:variable name='glyphlists'
  20. select="document('glyphlist.xml')/glyphlist-set"/>
  21. <xsl:template match="encoding-set"> /*
  22. * Licensed to the Apache Software Foundation (ASF) under one or more
  23. * contributor license agreements. See the NOTICE file distributed with
  24. * this work for additional information regarding copyright ownership.
  25. * The ASF licenses this file to You under the Apache License, Version 2.0
  26. * (the "License"); you may not use this file except in compliance with
  27. * the License. You may obtain a copy of the License at
  28. *
  29. * http://www.apache.org/licenses/LICENSE-2.0
  30. *
  31. * Unless required by applicable law or agreed to in writing, software
  32. * distributed under the License is distributed on an "AS IS" BASIS,
  33. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34. * See the License for the specific language governing permissions and
  35. * limitations under the License.
  36. */
  37. package org.apache.fop.fonts;
  38. import java.util.Map;
  39. import java.util.Collections;
  40. public class CodePointMapping extends AbstractCodePointMapping {
  41. <xsl:apply-templates mode="constant"/>
  42. public CodePointMapping(String name, int[] table) {
  43. super(name, table);
  44. }
  45. public CodePointMapping(String name, int[] table, String[] charNameMap) {
  46. super(name, table, charNameMap);
  47. }
  48. private static Map mappings;
  49. static {
  50. mappings = Collections.synchronizedMap(new java.util.HashMap());
  51. }
  52. public static CodePointMapping getMapping(String encoding) {
  53. CodePointMapping mapping = (CodePointMapping) mappings.get(encoding);
  54. if (mapping != null) {
  55. return mapping;
  56. } <xsl:apply-templates mode="get"/>
  57. throw new UnsupportedOperationException("Unknown encoding: " + encoding);
  58. }
  59. <xsl:apply-templates mode="table"/>
  60. <xsl:apply-templates select="encoding" mode="names"/>
  61. }
  62. </xsl:template>
  63. <xsl:template match="encoding" mode="constant"> public static final String <xsl:value-of select="@constant"/> = "<xsl:value-of select="@id"/>";</xsl:template>
  64. <xsl:template match="encoding" mode="get">
  65. else if (encoding.equals(<xsl:value-of select="@constant"/>)) {
  66. mapping = new CodePointMapping(<xsl:value-of select="@constant"/>, enc<xsl:value-of select="@id"/>, names<xsl:value-of select="@id"/>);
  67. mappings.put(<xsl:value-of select="@constant"/>, mapping);
  68. return mapping;
  69. }
  70. </xsl:template>
  71. <xsl:template match="encoding" mode="table">
  72. <xsl:variable name="glyphlist-name" select="@glyphlist"/>
  73. <xsl:variable name="glyphlist"
  74. select="$glyphlists/glyphlist[@id=$glyphlist-name]"/>
  75. private static final int[] enc<xsl:value-of select="@id"/>
  76. = {<xsl:for-each select="glyph">
  77. <xsl:variable name="codepoint" select="@codepoint"/>
  78. <xsl:variable name="name" select="@name"/><xsl:for-each select="$glyphlist/glyph[@name=$name]">
  79. 0x<xsl:value-of select="$codepoint"/>, 0x<xsl:value-of select="@codepoint"/>, // <xsl:value-of select="$name"/>
  80. </xsl:for-each></xsl:for-each>
  81. };
  82. </xsl:template>
  83. <xsl:template match="encoding" mode="names">
  84. private static final String[] names<xsl:value-of select="@id"/>
  85. = {
  86. <xsl:call-template name="charname">
  87. <xsl:with-param name="idx" select="0"/>
  88. </xsl:call-template>
  89. };
  90. </xsl:template>
  91. <xsl:template name="charname">
  92. <xsl:param name="idx"/>
  93. <xsl:variable name="idxHEXraw">
  94. <xsl:call-template name="toHex">
  95. <xsl:with-param name="decimalNumber" select="$idx"/>
  96. </xsl:call-template>
  97. </xsl:variable>
  98. <xsl:variable name="idxHEX">
  99. <xsl:call-template name="padnumber">
  100. <xsl:with-param name="num" select="$idxHEXraw"/>
  101. </xsl:call-template>
  102. </xsl:variable>
  103. <xsl:variable name="idxhex" select="translate($idxHEX, 'ABCDEF', 'abcdef')"></xsl:variable>
  104. <!--
  105. <xsl:value-of select="$idx"/>-<xsl:value-of select="$idxHEXraw"/>-<xsl:value-of select="$idxHEX"/>-<xsl:value-of select="$idxhex"/>
  106. -->
  107. <xsl:if test="($idx mod 4) = 0">
  108. <xsl:text>&#x0D; /*</xsl:text><xsl:value-of select="$idxHEX"/><xsl:text>*/ </xsl:text>
  109. </xsl:if>
  110. <xsl:variable name="v">
  111. <xsl:value-of select="child::glyph[@codepoint = $idxHEX or @codepoint = $idxhex]/@name"/><!--<xsl:value-of select="glyph[@codepoint = $idxhex]/@name"/>-->
  112. </xsl:variable>
  113. <xsl:choose>
  114. <xsl:when test="string-length($v) > 0">
  115. <xsl:text>"</xsl:text><xsl:value-of select="$v"/><xsl:text>"</xsl:text>
  116. </xsl:when>
  117. <xsl:otherwise>null</xsl:otherwise>
  118. </xsl:choose>
  119. <xsl:if test="$idx &lt; 255">
  120. <xsl:text>, </xsl:text>
  121. <xsl:call-template name="charname">
  122. <xsl:with-param name="idx" select="$idx + 1"/>
  123. </xsl:call-template>
  124. </xsl:if>
  125. </xsl:template>
  126. <xsl:variable name="hexDigits" select="'0123456789ABCDEF'"/>
  127. <xsl:template name="toHex">
  128. <xsl:param name="decimalNumber" />
  129. <xsl:if test="$decimalNumber >= 16">
  130. <xsl:call-template name="toHex">
  131. <xsl:with-param name="decimalNumber" select="floor($decimalNumber div 16)" />
  132. </xsl:call-template>
  133. </xsl:if>
  134. <xsl:value-of select="substring($hexDigits, ($decimalNumber mod 16) + 1, 1)" />
  135. </xsl:template>
  136. <xsl:template name="padnumber">
  137. <xsl:param name="num"/>
  138. <xsl:param name="len" select="2"/>
  139. <!--
  140. <xsl:text> </xsl:text><xsl:value-of select="$num"/>/<xsl:value-of select="$len"/>
  141. -->
  142. <xsl:choose>
  143. <xsl:when test="string-length($num) &lt; $len">
  144. <xsl:call-template name="padnumber">
  145. <xsl:with-param name="num" select="concat('0',$num)"/>
  146. <xsl:with-param name="len" select="$len"/>
  147. </xsl:call-template>
  148. </xsl:when>
  149. <xsl:otherwise><xsl:value-of select="$num"/></xsl:otherwise>
  150. </xsl:choose>
  151. </xsl:template>
  152. </xsl:stylesheet>