aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fonts
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/fonts')
-rw-r--r--src/java/org/apache/fop/fonts/CIDFull.java13
-rw-r--r--src/java/org/apache/fop/fonts/CIDSet.java14
-rw-r--r--src/java/org/apache/fop/fonts/CIDSubset.java18
-rw-r--r--src/java/org/apache/fop/fonts/CustomFont.java12
-rw-r--r--src/java/org/apache/fop/fonts/MultiByteFont.java18
-rw-r--r--src/java/org/apache/fop/fonts/SingleByteFont.java12
6 files changed, 86 insertions, 1 deletions
diff --git a/src/java/org/apache/fop/fonts/CIDFull.java b/src/java/org/apache/fop/fonts/CIDFull.java
index ee062a2bb..1130459b7 100644
--- a/src/java/org/apache/fop/fonts/CIDFull.java
+++ b/src/java/org/apache/fop/fonts/CIDFull.java
@@ -57,6 +57,18 @@ public class CIDFull implements CIDSet {
}
/** {@inheritDoc} */
+ @Override
+ public char getUnicodeFromGID(int glyphIndex) {
+ return ' ';
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public int getGIDFromChar(char ch) {
+ return ch;
+ }
+
+ /** {@inheritDoc} */
public char getUnicode(int index) {
initGlyphIndices();
if (glyphIndices.get(index)) {
@@ -109,5 +121,4 @@ public class CIDFull implements CIDSet {
public int[] getWidths() {
return font.getWidths();
}
-
}
diff --git a/src/java/org/apache/fop/fonts/CIDSet.java b/src/java/org/apache/fop/fonts/CIDSet.java
index 7530ea6e7..acfc705c8 100644
--- a/src/java/org/apache/fop/fonts/CIDSet.java
+++ b/src/java/org/apache/fop/fonts/CIDSet.java
@@ -44,6 +44,20 @@ public interface CIDSet {
char getUnicode(int index);
/**
+ * Gets the unicode character from the original font glyph index
+ * @param glyphIndex The original glyph index of the character in the font
+ * @return The character represented by the passed GID
+ */
+ char getUnicodeFromGID(int glyphIndex);
+
+ /**
+ * Returns the glyph index from the original font from a character
+ * @param ch The character
+ * @return The glyph index in the original font.
+ */
+ int getGIDFromChar(char ch);
+
+ /**
* Maps a character to a character selector for a font subset. If the character isn't in the
* subset, yet, it is added and a new character selector returned. Otherwise, the already
* allocated character selector is returned from the existing map/subset.
diff --git a/src/java/org/apache/fop/fonts/CIDSubset.java b/src/java/org/apache/fop/fonts/CIDSubset.java
index f442c13ed..01b8495f8 100644
--- a/src/java/org/apache/fop/fonts/CIDSubset.java
+++ b/src/java/org/apache/fop/fonts/CIDSubset.java
@@ -53,6 +53,12 @@ public class CIDSubset implements CIDSet {
*/
private Map<Integer, Character> usedCharsIndex = new HashMap<Integer, Character>();
+ /**
+ * A map between the original character and it's GID in the original font.
+ */
+ private Map<Character, Integer> charToGIDs = new HashMap<Character, Integer>();
+
+
private final MultiByteFont font;
public CIDSubset(MultiByteFont mbf) {
@@ -93,6 +99,7 @@ public class CIDSubset implements CIDSet {
usedGlyphs.put(glyphIndex, selector);
usedGlyphsIndex.put(selector, glyphIndex);
usedCharsIndex.put(selector, unicode);
+ charToGIDs.put(unicode, glyphIndex);
usedGlyphsCount++;
return selector;
} else {
@@ -106,6 +113,17 @@ public class CIDSubset implements CIDSet {
}
/** {@inheritDoc} */
+ public char getUnicodeFromGID(int glyphIndex) {
+ int selector = usedGlyphs.get(glyphIndex);
+ return usedCharsIndex.get(selector);
+ }
+
+ /** {@inheritDoc} */
+ public int getGIDFromChar(char ch) {
+ return charToGIDs.get(ch);
+ }
+
+ /** {@inheritDoc} */
public char[] getChars() {
char[] charArray = new char[usedGlyphsCount];
for (int i = 0; i < usedGlyphsCount; i++) {
diff --git a/src/java/org/apache/fop/fonts/CustomFont.java b/src/java/org/apache/fop/fonts/CustomFont.java
index fffb429ed..6f325d96d 100644
--- a/src/java/org/apache/fop/fonts/CustomFont.java
+++ b/src/java/org/apache/fop/fonts/CustomFont.java
@@ -568,4 +568,16 @@ public abstract class CustomFont extends Typeface
this.strikeoutThickness = strikeoutThickness;
}
+ /**
+ * Returns a Map of used Glyphs.
+ * @return Map Map of used Glyphs
+ */
+ public abstract Map<Integer, Integer> getUsedGlyphs();
+
+ /**
+ * Returns the character from it's original glyph index in the font
+ * @param glyphIndex The original index of the character
+ * @return The character
+ */
+ public abstract char getUnicodeFromGID(int glyphIndex);
}
diff --git a/src/java/org/apache/fop/fonts/MultiByteFont.java b/src/java/org/apache/fop/fonts/MultiByteFont.java
index 296c86de2..22b5116bb 100644
--- a/src/java/org/apache/fop/fonts/MultiByteFont.java
+++ b/src/java/org/apache/fop/fonts/MultiByteFont.java
@@ -426,6 +426,24 @@ public class MultiByteFont extends CIDFont implements Substitutable, Positionabl
}
/**
+ * Returns the character from it's original glyph index in the font
+ * @param glyphIndex The original index of the character
+ * @return The character
+ */
+ public char getUnicodeFromGID(int glyphIndex) {
+ return cidSet.getUnicodeFromGID(glyphIndex);
+ }
+
+ /**
+ * Gets the original glyph index in the font from a character.
+ * @param ch The character
+ * @return The glyph index in the font
+ */
+ public int getGIDFromChar(char ch) {
+ return cidSet.getGIDFromChar(ch);
+ }
+
+ /**
* Establishes the glyph definition table.
* @param gdef the glyph definition table to be used by this font
*/
diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java
index e12da81cc..e3037a524 100644
--- a/src/java/org/apache/fop/fonts/SingleByteFont.java
+++ b/src/java/org/apache/fop/fonts/SingleByteFont.java
@@ -63,6 +63,7 @@ public class SingleByteFont extends CustomFont {
private LinkedHashMap<Integer, String> usedGlyphNames;
private Map<Integer, Integer> usedGlyphs;
private Map<Integer, Character> usedCharsIndex;
+ private Map<Character, Integer> charGIDMappings;
public SingleByteFont(InternalResourceResolver resourceResolver) {
super(resourceResolver);
@@ -76,6 +77,7 @@ public class SingleByteFont extends CustomFont {
usedGlyphNames = new LinkedHashMap<Integer, String>();
usedGlyphs = new HashMap<Integer, Integer>();
usedCharsIndex = new HashMap<Integer, Character>();
+ charGIDMappings = new HashMap<Character, Integer>();
// The zeroth value is reserved for .notdef
usedGlyphs.put(0, 0);
@@ -234,6 +236,7 @@ public class SingleByteFont extends CustomFont {
int selector = usedGlyphsCount;
usedGlyphs.put(glyphIndex, selector);
usedCharsIndex.put(selector, unicode);
+ charGIDMappings.put(unicode, glyphIndex);
usedGlyphsCount++;
return selector;
} else {
@@ -519,6 +522,15 @@ public class SingleByteFont extends CustomFont {
return getUnicode(selector);
}
+ public int getGIDFromChar(char ch) {
+ return charGIDMappings.get(ch);
+ }
+
+ public char getUnicodeFromGID(int glyphIndex) {
+ int selector = usedGlyphs.get(glyphIndex);
+ return usedCharsIndex.get(selector);
+ }
+
public void mapUsedGlyphName(int gid, String value) {
usedGlyphNames.put(gid, value);
}