]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #50699:
authorJeremias Maerki <jeremias@apache.org>
Wed, 2 Feb 2011 10:19:18 +0000 (10:19 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 2 Feb 2011 10:19:18 +0000 (10:19 +0000)
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

src/java/org/apache/fop/fonts/SingleByteFont.java
status.xml

index d798db1bb3d566811113ddf5e7e1a499e46be338..b832eec2bcd25fe27176b3febeb50a3b436c4d4f 100644 (file)
@@ -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;
     }
 
index c0c759763a2d571ea8122b7a53f1cce3db558376..2ba48dc80ac077a7f435f943f4c65c54cf035c53 100644 (file)
       documents. Example: the fix of marks layering will be such a case when it's done.
     -->
     <release version="FOP Trunk" date="TBD">
+      <action context="Fonts" dev="JM" type="add" fixes-bug="50699" due-to="Alexandros Papadakis">
+        Added support for lookup of alternative glyphs when additional single-byte encodings are
+        used, ex. replacing "Omegagreek" by "Omega" and vice versa.
+      </action>
       <action context="Code" dev="AD" type="add" fixes-bug="48334">
         Added support for resolution of relative URIs against a specified xml:base during
         property refinement.