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 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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="1.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. package org.apache.fop.fonts;
  23. import java.util.Map;
  24. import java.util.Collections;
  25. public class CodePointMapping {
  26. private char[] latin1Map;
  27. private char[] characters;
  28. private char[] codepoints;
  29. private CodePointMapping(int [] table) {
  30. int nonLatin1 = 0;
  31. latin1Map = new char[256];
  32. for(int i = 0; i &lt; table.length; i += 2) {
  33. if(table[i+1] &lt; 256)
  34. latin1Map[table[i+1]] = (char) table[i];
  35. else
  36. ++nonLatin1;
  37. }
  38. characters = new char[nonLatin1];
  39. codepoints = new char[nonLatin1];
  40. int top = 0;
  41. for(int i = 0; i &lt; table.length; i += 2) {
  42. char c = (char) table[i+1];
  43. if(c >= 256) {
  44. ++top;
  45. for(int j = top - 1; j >= 0; --j) {
  46. if(j > 0 &amp;&amp; characters[j-1] >= c) {
  47. characters[j] = characters[j-1];
  48. codepoints[j] = codepoints[j-1];
  49. } else {
  50. characters[j] = c;
  51. codepoints[j] = (char) table[i];
  52. break;
  53. }
  54. }
  55. }
  56. }
  57. }
  58. public final char mapChar(char c) {
  59. if(c &lt; 256) {
  60. return latin1Map[c];
  61. } else {
  62. int bot = 0, top = characters.length - 1;
  63. while(top >= bot) {
  64. int mid = (bot + top) / 2;
  65. char mc = characters[mid];
  66. if(c == mc)
  67. return codepoints[mid];
  68. else if(c &lt; mc)
  69. top = mid - 1;
  70. else
  71. bot = mid + 1;
  72. }
  73. return 0;
  74. }
  75. }
  76. private static Map mappings;
  77. static {
  78. mappings = Collections.synchronizedMap(new java.util.HashMap());
  79. }
  80. public static CodePointMapping getMapping(String encoding) {
  81. CodePointMapping mapping = (CodePointMapping) mappings.get(encoding);
  82. if(mapping != null) {
  83. return mapping;
  84. } <xsl:apply-templates mode="get"/>
  85. else {
  86. return null;
  87. }
  88. }
  89. <xsl:apply-templates mode="table"/>
  90. }
  91. </xsl:template>
  92. <xsl:template match="encoding" mode="get">
  93. else if(encoding.equals("<xsl:value-of select="@id"/>")) {
  94. mapping = new CodePointMapping(enc<xsl:value-of select="@id"/>);
  95. mappings.put("<xsl:value-of select="@id"/>", mapping);
  96. return mapping;
  97. }
  98. </xsl:template>
  99. <xsl:template match="encoding" mode="table">
  100. <xsl:variable name="glyphlist-name" select="@glyphlist"/>
  101. <xsl:variable name="glyphlist"
  102. select="$glyphlists/glyphlist[@id=$glyphlist-name]"/>
  103. private static final int[] enc<xsl:value-of select="@id"/>
  104. = {<xsl:for-each select="glyph">
  105. <xsl:variable name="codepoint" select="@codepoint"/>
  106. <xsl:variable name="name" select="@name"/><xsl:for-each select="$glyphlist/glyph[@name=$name]">
  107. 0x<xsl:value-of select="$codepoint"/>, 0x<xsl:value-of select="@codepoint"/>, // <xsl:value-of select="$name"/>
  108. </xsl:for-each></xsl:for-each>
  109. };
  110. </xsl:template>
  111. </xsl:stylesheet>