From 44187d0d1e9916f2d872f4cb4e73d1209fc65191 Mon Sep 17 00:00:00 2001 From: Jeremias Maerki Date: Mon, 12 Nov 2007 08:52:11 +0000 Subject: [PATCH] Better solution for missing hyphenation character problem. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@594054 13f79535-47bb-0310-9956-ffa450edef68 --- .../fop/fo/properties/CommonHyphenation.java | 46 +++++++++++++++++++ .../inline/CharacterLayoutManager.java | 13 +++--- .../layoutmgr/inline/TextLayoutManager.java | 10 +--- 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java index d08d18312..28f44fbce 100644 --- a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java +++ b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java @@ -19,6 +19,8 @@ package org.apache.fop.fo.properties; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.apache.fop.fo.Constants; import org.apache.fop.fo.PropertyList; import org.apache.fop.fo.expr.PropertyException; @@ -29,6 +31,9 @@ import org.apache.fop.fo.expr.PropertyException; * Public "structure" allows direct member access. */ public final class CommonHyphenation { + + /** Logger */ + protected static Log log = LogFactory.getLog(CommonHyphenation.class); private static final PropertyCache cache = new PropertyCache(); @@ -111,6 +116,47 @@ public final class CommonHyphenation { } + private static final char HYPHEN_MINUS = '-'; + private static final char MINUS_SIGN = '\u2212'; + + /** + * Returns the effective hyphenation character for a font. The hyphenation character specified + * in XSL-FO may be substituted if it's not available in the font. + * @param font the font + * @return the effective hyphenation character. + */ + public char getHyphChar(org.apache.fop.fonts.Font font) { + char hyphChar = hyphenationCharacter.getCharacter(); + char effHyphChar = hyphChar; + if (font.hasChar(effHyphChar)) { + //nop + } else if (font.hasChar(HYPHEN_MINUS)) { + effHyphChar = HYPHEN_MINUS; + } else if (font.hasChar(MINUS_SIGN)) { + effHyphChar = MINUS_SIGN; + } else { + effHyphChar = ' '; + } + if (hyphChar != effHyphChar) { + log.warn("Substituted specified hyphenation character (0x" + + Integer.toHexString(hyphChar) + + ") with 0x" + Integer.toHexString(effHyphChar) + + " because the font doesn't have the specified hyphenation character: " + + font.getFontTriplet()); + } + return effHyphChar; + } + + /** + * Returns the IPD for the hyphenation character for a font. + * @param font the font + * @return the IPD in millipoints for the hyphenation character. + */ + public int getHyphIPD(org.apache.fop.fonts.Font font) { + char hyphChar = getHyphChar(font); + return font.getCharWidth(hyphChar); + } + /** {@inheritDoc */ public boolean equals(Object obj) { if (obj == this) { diff --git a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java index f470e137e..0430eef0c 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/CharacterLayoutManager.java @@ -19,7 +19,12 @@ package org.apache.fop.layoutmgr.inline; +import java.util.LinkedList; +import java.util.List; + +import org.apache.fop.area.Trait; import org.apache.fop.fo.flow.Character; +import org.apache.fop.fo.properties.CommonBorderPaddingBackground; import org.apache.fop.fonts.Font; import org.apache.fop.fonts.FontInfo; import org.apache.fop.fonts.FontTriplet; @@ -32,16 +37,10 @@ import org.apache.fop.layoutmgr.LayoutContext; import org.apache.fop.layoutmgr.LeafPosition; import org.apache.fop.layoutmgr.Position; import org.apache.fop.layoutmgr.TraitSetter; -import org.apache.fop.area.Trait; import org.apache.fop.traits.MinOptMax; import org.apache.fop.traits.SpaceVal; import org.apache.fop.util.CharUtilities; -import java.util.List; -import java.util.LinkedList; -import org.apache.fop.fo.properties.CommonBorderPaddingBackground; -import org.apache.fop.layoutmgr.inline.AlignmentContext; - /** * LayoutManager for the fo:character formatting object */ @@ -70,7 +69,7 @@ public class CharacterLayoutManager extends LeafNodeLayoutManager { font = fi.getFontInstance(fontkeys[0], fobj.getCommonFont().fontSize.getValue(this)); SpaceVal ls = SpaceVal.makeLetterSpacing(fobj.getLetterSpacing()); letterSpaceIPD = ls.getSpace(); - hyphIPD = font.getCharWidth(fobj.getCommonHyphenation().hyphenationCharacter.getCharacter()); + hyphIPD = fobj.getCommonHyphenation().getHyphIPD(font); borderProps = fobj.getCommonBorderPaddingBackground(); setCommonBorderPaddingBackground(borderProps); org.apache.fop.area.inline.TextArea chArea = getCharacterInlineArea(fobj); diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index d446e0e7d..63f11147c 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -195,13 +195,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { // With CID fonts, space isn't neccesary currentFontState.width(32) spaceCharIPD = font.getCharWidth(' '); // Use hyphenationChar property - char hyphChar = foText.getCommonHyphenation().hyphenationCharacter.getCharacter(); - if (font.hasChar(hyphChar)) { - hyphIPD = font.getCharWidth(hyphChar); - } else { - log.warn("Hyphenation character 0x" + Integer.toHexString(hyphChar) - + " is not available for font: " + font.getFontTriplet()); - } + hyphIPD = foText.getCommonHyphenation().getHyphIPD(font); SpaceVal ls = SpaceVal.makeLetterSpacing(foText.getLetterSpacing()); halfLS = new SpaceVal(MinOptMax.multiply(ls.getSpace(), 0.5), @@ -514,7 +508,7 @@ public class TextLayoutManager extends LeafNodeLayoutManager { && i == lastIndex && areaInfo.bHyphenated) { // add the hyphenation character - wordChars.append(foText.getCommonHyphenation().hyphenationCharacter.getCharacter()); + wordChars.append(foText.getCommonHyphenation().getHyphChar(font)); } textArea.addWord(wordChars.toString(), 0, letterAdjust); wordStartIndex = -1; -- 2.39.5