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