aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop
diff options
context:
space:
mode:
authorJeremias Maerki <jeremias@apache.org>2011-02-02 10:19:18 +0000
committerJeremias Maerki <jeremias@apache.org>2011-02-02 10:19:18 +0000
commitd42674784ff6bda51cf4b28b377414b059cbcfd7 (patch)
tree93af589d4a6fd11dc46d650fd4528c261da08f80 /src/java/org/apache/fop
parente1d2e4628bf358cfe74681722013292668517779 (diff)
downloadxmlgraphics-fop-d42674784ff6bda51cf4b28b377414b059cbcfd7.tar.gz
xmlgraphics-fop-d42674784ff6bda51cf4b28b377414b059cbcfd7.zip
Bugzilla #50699:
Added support for lookup of alternative glyphs when additional single-byte encodings are used, ex. replacing "Omegagreek" by "Omega" and vice versa. Submitted by: Alexandros Papadakis <alpapad.at.gmail.com> Changes to patch: - fixed a couple of typos - code formatting - a little code optimization git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1066400 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/fop')
-rw-r--r--src/java/org/apache/fop/fonts/SingleByteFont.java68
1 files changed, 63 insertions, 5 deletions
diff --git a/src/java/org/apache/fop/fonts/SingleByteFont.java b/src/java/org/apache/fop/fonts/SingleByteFont.java
index d798db1bb..b832eec2b 100644
--- a/src/java/org/apache/fop/fonts/SingleByteFont.java
+++ b/src/java/org/apache/fop/fonts/SingleByteFont.java
@@ -29,6 +29,8 @@ import java.util.TreeSet;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.xmlgraphics.fonts.Glyphs;
+
/**
* Generic SingleByte font
*/
@@ -44,6 +46,7 @@ public class SingleByteFont extends CustomFont {
private Map<Character, UnencodedCharacter> unencodedCharacters;
private List<SimpleSingleByteEncoding> additionalEncodings;
+ private Map<Character, Character> alternativeCodes;
/**
@@ -99,19 +102,69 @@ public class SingleByteFont extends CustomFont {
return arr;
}
- /** {@inheritDoc} */
- @Override
- public char mapChar(char c) {
- notifyMapOperation();
+ /**
+ * Lookup a character using its alternative names. If found, cache it so we
+ * can speed up lookups.
+ * @param c the character
+ * @return the suggested alternative character present in the font
+ */
+ private char findAlternative(char c) {
+ char d;
+ if (alternativeCodes == null) {
+ alternativeCodes = new java.util.HashMap<Character, Character>();
+ } else {
+ Character alternative = alternativeCodes.get(c);
+ if (alternative != null) {
+ return alternative;
+ }
+ }
+ String charName = Glyphs.charToGlyphName(c);
+ String[] charNameAlternatives = Glyphs.getCharNameAlternativesFor(charName);
+ if (charNameAlternatives != null && charNameAlternatives.length > 0) {
+ for (int i = 0; i < charNameAlternatives.length; i++) {
+ if (log.isDebugEnabled()) {
+ log.debug("Checking alternative for char " + c + " (charname="
+ + charName + "): " + charNameAlternatives[i]);
+ }
+ String s = Glyphs.getUnicodeSequenceForGlyphName(charNameAlternatives[i]);
+ if (s != null) {
+ d = lookupChar(s.charAt(0));
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ alternativeCodes.put(c, d);
+ return d;
+ }
+ }
+ }
+ }
+
+ return SingleByteEncoding.NOT_FOUND_CODE_POINT;
+ }
+
+ private char lookupChar(char c) {
char d = mapping.mapChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
}
- //Check unencoded characters which are available in the font by character name
+ // Check unencoded characters which are available in the font by
+ // character name
d = mapUnencodedChar(c);
+ return d;
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public char mapChar(char c) {
+ notifyMapOperation();
+ char d = lookupChar(c);
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return d;
+ } else {
+ // Check for alternative
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return d;
+ }
}
this.warnMissingGlyph(c);
return Typeface.NOT_FOUND;
@@ -162,6 +215,11 @@ public class SingleByteFont extends CustomFont {
if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
return true;
}
+ // Check if an alternative exists
+ d = findAlternative(c);
+ if (d != SingleByteEncoding.NOT_FOUND_CODE_POINT) {
+ return true;
+ }
return false;
}