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;
* 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();
}
+ 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) {
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;
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
*/
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);
// 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),
&& 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;