15
15
* limitations under the License.
18
/* $Id: CIDSubset.java 828516 2009-10-22 09:16:37Z jeremias $ */
18
/* $Id: CIDSubset.java 1099857 2011-05-05 15:55:20Z jeremias $ */
20
20
package org.apache.fop.fonts;
22
22
import java.util.BitSet;
23
23
import java.util.Collections;
24
import java.util.Iterator;
24
import java.util.HashMap;
25
25
import java.util.Map;
27
27
import org.apache.fop.util.CharUtilities;
43
43
* usedGlyphs contains orginal, new glyph index (glyph index -> char selector)
45
private Map/*<Integer, Integer>*/ usedGlyphs = new java.util.HashMap();
45
private Map<Integer, Integer> usedGlyphs = new HashMap<Integer, Integer>();
48
48
* usedGlyphsIndex contains new glyph, original index (char selector -> glyph index)
50
private Map/*<Integer, Integer>*/ usedGlyphsIndex = new java.util.HashMap();
50
private Map<Integer, Integer> usedGlyphsIndex = new HashMap<Integer, Integer>();
51
51
private int usedGlyphsCount = 0;
54
54
* usedCharsIndex contains new glyph, original char (char selector -> Unicode)
56
private Map/*<Integer, Character>*/ usedCharsIndex = new java.util.HashMap();
56
private Map<Integer, Character> usedCharsIndex = new HashMap<Integer, Character>();
59
* Default constructor.
58
61
public CIDSubset() {
62
* Adds the initial 3 glyphs which are the same for all CID subsets.
65
* Adds the first glyph which is reserved for .notdef for all CID subsets.
64
public void setupFirstThreeGlyphs() {
65
// Make sure that the 3 first glyphs are included
66
usedGlyphs.put(new Integer(0), new Integer(0));
67
usedGlyphsIndex.put(new Integer(0), new Integer(0));
69
usedGlyphs.put(new Integer(1), new Integer(1));
70
usedGlyphsIndex.put(new Integer(1), new Integer(1));
72
usedGlyphs.put(new Integer(2), new Integer(2));
73
usedGlyphsIndex.put(new Integer(2), new Integer(2));
67
public void setupFirstGlyph() {
68
usedGlyphs.put(Integer.valueOf(0), Integer.valueOf(0));
69
usedGlyphsIndex.put(Integer.valueOf(0), Integer.valueOf(0));
81
77
* @return the original index (or -1 if no glyph index is available for the subset index)
83
79
public int getGlyphIndexForSubsetIndex(int subsetIndex) {
84
Integer glyphIndex = (Integer)usedGlyphsIndex.get(new Integer(subsetIndex));
80
Integer glyphIndex = usedGlyphsIndex.get(Integer.valueOf(subsetIndex));
85
81
if (glyphIndex != null) {
86
82
return glyphIndex.intValue();
96
92
* @return the Unicode value or "NOT A CHARACTER" (0xFFFF)
98
94
public char getUnicodeForSubsetIndex(int subsetIndex) {
99
Character mapValue = (Character)usedCharsIndex.get(new Integer(subsetIndex));
95
Character mapValue = usedCharsIndex.get(Integer.valueOf(subsetIndex));
100
96
if (mapValue != null) {
101
97
return mapValue.charValue();
115
111
public int mapSubsetChar(int glyphIndex, char unicode) {
116
112
// Reencode to a new subset font or get the reencoded value
117
113
// IOW, accumulate the accessed characters and build a character map for them
118
Integer subsetCharSelector = (Integer)usedGlyphs.get(new Integer(glyphIndex));
114
Integer subsetCharSelector = usedGlyphs.get(Integer.valueOf(glyphIndex));
119
115
if (subsetCharSelector == null) {
120
116
int selector = usedGlyphsCount;
121
usedGlyphs.put(new Integer(glyphIndex),
122
new Integer(selector));
123
usedGlyphsIndex.put(new Integer(selector),
124
new Integer(glyphIndex));
125
usedCharsIndex.put(new Integer(selector),
126
new Character(unicode));
117
usedGlyphs.put(Integer.valueOf(glyphIndex),
118
Integer.valueOf(selector));
119
usedGlyphsIndex.put(Integer.valueOf(selector),
120
Integer.valueOf(glyphIndex));
121
usedCharsIndex.put(Integer.valueOf(selector),
122
Character.valueOf(unicode));
127
123
usedGlyphsCount++;
136
132
* character selector (i.e. the subset index in this case).
137
133
* @return Map Map<Integer, Integer> of the font subset
139
public Map/*<Integer, Integer>*/ getSubsetGlyphs() {
135
public Map<Integer, Integer> getSubsetGlyphs() {
140
136
return Collections.unmodifiableMap(this.usedGlyphs);
167
163
public BitSet getGlyphIndexBitSet() {
168
164
BitSet bitset = new BitSet();
169
Iterator iter = usedGlyphsIndex.keySet().iterator();
170
while (iter.hasNext()) {
171
Integer cid = (Integer)iter.next();
165
for (Integer cid : usedGlyphs.keySet()) {
172
166
bitset.set(cid.intValue());