From 57de10b2fdd6e6f0bbca3aac03bce84d82cfaba3 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Sat, 16 Feb 2008 12:28:48 +0000 Subject: Extracted most of the code in CodePointMapping (generated by XSLT) into a base class for easier maintenance and proper Javadocs. Deprecated FOP's copy of Glyphs.java. Took a different approach at handling mapping alternatives for single-byte fonts. The AFM now only lists the main character. Substitution is done through Glyphs.java later in CodePointMapping. Fixed a problem in Type1FontLoader where the PFM overrides asc/desc/cap/x even though the AFM provides the values. It showed itself because the URW Symbol font has wrong values in the PFM. Added a note to myself in Type1FontLoader to implement the "Flags" value. The whole thing still seems to work without that part. Added a glyph name list to the CodePointMapping so we can work with the original list from the AFM. Otherwise, various mapping operations to and from resulted in unwanted mappings (because the mappings are not necessarily 1:1) and in the end the PDF received an incorrect Encoding map. Now there's no such problem anymore. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@628280 13f79535-47bb-0310-9956-ffa450edef68 --- src/codegen/fonts/code-point-mapping.xsl | 170 +++++++++++++++---------------- 1 file changed, 80 insertions(+), 90 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/fonts/code-point-mapping.xsl b/src/codegen/fonts/code-point-mapping.xsl index c82ca0104..55b84c742 100644 --- a/src/codegen/fonts/code-point-mapping.xsl +++ b/src/codegen/fonts/code-point-mapping.xsl @@ -40,100 +40,19 @@ package org.apache.fop.fonts; -import java.util.Arrays; import java.util.Map; import java.util.Collections; -import org.apache.fop.util.CharUtilities; - -public class CodePointMapping { +public class CodePointMapping extends AbstractCodePointMapping { - private String name; - private char[] latin1Map; - private char[] characters; - private char[] codepoints; - private char[] unicodeMap; //code point to Unicode char - public CodePointMapping(String name, int[] table) { - this.name = name; - int nonLatin1 = 0; - latin1Map = new char[256]; - unicodeMap = new char[256]; - Arrays.fill(unicodeMap, CharUtilities.NOT_A_CHARACTER); - for (int i = 0; i < table.length; i += 2) { - char unicode = (char)table[i + 1]; - if (unicode < 256) { - if (latin1Map[unicode] == 0) { - latin1Map[unicode] = (char) table[i]; - } - } else { - ++nonLatin1; - } - if (unicodeMap[table[i]] == CharUtilities.NOT_A_CHARACTER) { - unicodeMap[table[i]] = unicode; - } - } - characters = new char[nonLatin1]; - codepoints = new char[nonLatin1]; - int top = 0; - for (int i = 0; i < table.length; i += 2) { - char c = (char) table[i + 1]; - if (c >= 256) { - ++top; - for (int j = top - 1; j >= 0; --j) { - if (j > 0 && characters[j - 1] >= c) { - characters[j] = characters[j - 1]; - codepoints[j] = codepoints[j - 1]; - } else { - characters[j] = c; - codepoints[j] = (char) table[i]; - break; - } - } - } - } - } - - public String getName() { - return this.name; - } - - public final char mapChar(char c) { - if (c < 256) { - return latin1Map[c]; - } else { - int bot = 0, top = characters.length - 1; - while (top >= bot) { - int mid = (bot + top) / 2; - char mc = characters[mid]; - - if (c == mc) { - return codepoints[mid]; - } else if (c < mc) { - top = mid - 1; - } else { - bot = mid + 1; - } - } - return 0; - } - } - - public final char getUnicodeForIndex(int idx) { - return this.unicodeMap[idx]; + super(name, table); } - public final char[] getUnicodeCharMap() { - char[] copy = new char[this.unicodeMap.length]; - System.arraycopy(this.unicodeMap, 0, copy, 0, this.unicodeMap.length); - return copy; - } - - /** {@inheritDoc} */ - public String toString() { - return getName(); + public CodePointMapping(String name, int[] table, String[] charNameMap) { + super(name, table, charNameMap); } private static Map mappings; @@ -146,13 +65,10 @@ public class CodePointMapping { if (mapping != null) { return mapping; } - //TODO: Implement support for Expert and ExpertSubset encoding - else if (encoding.startsWith("Expert")) { - throw new UnsupportedOperationException(encoding + " not implemented yet"); - } throw new UnsupportedOperationException("Unknown encoding: " + encoding); } + } @@ -160,7 +76,7 @@ public class CodePointMapping { else if (encoding.equals()) { - mapping = new CodePointMapping(, enc); + mapping = new CodePointMapping(, enc, names); mappings.put(, mapping); return mapping; } @@ -178,4 +94,78 @@ public class CodePointMapping { }; + + + private static final String[] names + = { + + + + }; + + + + + + + + + + + + + + + + + + /**/ + + + + + + + "" + + null + + + + , + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit v1.2.3