From: Jeremias Maerki Date: Wed, 2 Feb 2011 10:19:18 +0000 (+0000) Subject: Bugzilla #50699: X-Git-Tag: fop-1_1rc1old~338 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d42674784ff6bda51cf4b28b377414b059cbcfd7;p=xmlgraphics-fop.git 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 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 --- 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 unencodedCharacters; private List additionalEncodings; + private Map 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(); + } 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; } diff --git a/status.xml b/status.xml index c0c759763..2ba48dc80 100644 --- a/status.xml +++ b/status.xml @@ -59,6 +59,10 @@ documents. Example: the fix of marks layering will be such a case when it's done. --> + + Added support for lookup of alternative glyphs when additional single-byte encodings are + used, ex. replacing "Omegagreek" by "Omega" and vice versa. + Added support for resolution of relative URIs against a specified xml:base during property refinement.