From: Simon Pepping Date: Sat, 4 Dec 2010 08:30:47 +0000 (+0000) Subject: Allow for words consisting of only soft hyphens; fixes bug 49837 X-Git-Tag: fop-1_1rc1old~396 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=24e2fad7e1416bd1878e3474f710af2c15edd8fb;p=xmlgraphics-fop.git Allow for words consisting of only soft hyphens; fixes bug 49837 git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1042115 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FOTreeBuilder.java b/src/java/org/apache/fop/fo/FOTreeBuilder.java index c848eb4f1..451481eb8 100644 --- a/src/java/org/apache/fop/fo/FOTreeBuilder.java +++ b/src/java/org/apache/fop/fo/FOTreeBuilder.java @@ -398,7 +398,9 @@ public class FOTreeBuilder extends DefaultHandler { FOValidationEventProducer eventProducer = FOValidationEventProducer.Provider.get( userAgent.getEventBroadcaster()); - eventProducer.unknownFormattingObject(this, currentFObj.getName(), + String name = (currentFObj != null ? currentFObj.getName() + : "{" + namespaceURI + "}" + localName); + eventProducer.unknownFormattingObject(this, name, new QName(namespaceURI, localName), getEffectiveLocator()); } diff --git a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java index 05cf979de..498fd1265 100644 --- a/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java +++ b/src/java/org/apache/fop/layoutmgr/inline/TextLayoutManager.java @@ -770,11 +770,8 @@ public class TextLayoutManager extends LeafNodeLayoutManager { while (lastIndex > 0 && foText.charAt(lastIndex - 1) == CharUtilities.SOFT_HYPHEN) { lastIndex--; } - final boolean endsWithHyphen = checkEndsWithHyphen - && foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN; Font font = FontSelector .selectFontForCharactersInText(foText, thisStart, lastIndex, foText, this); - int wordLength = lastIndex - thisStart; boolean kerning = font.hasKerning(); MinOptMax wordIPD = MinOptMax.ZERO; for (int i = thisStart; i < lastIndex; i++) { @@ -801,23 +798,31 @@ public class TextLayoutManager extends LeafNodeLayoutManager { } } } + boolean endsWithHyphen = checkEndsWithHyphen + && foText.charAt(lastIndex) == CharUtilities.SOFT_HYPHEN; if (kerning && breakOpportunity && !TextLayoutManager.isSpace(ch) && lastIndex > 0 && endsWithHyphen) { - final int kern = font.getKernValue(foText.charAt(lastIndex - 1), ch); + int kern = font.getKernValue(foText.charAt(lastIndex - 1), ch); if (kern != 0) { addToLetterAdjust(lastIndex, kern); //TODO: add kern to wordIPD? } } - int letterSpaces = wordLength - 1; - // if there is a break opportunity and the next one - // is not a space, it could be used as a line end; - // add one more letter space, in case other text follows - if (breakOpportunity && !TextLayoutManager.isSpace(ch)) { - letterSpaces++; + // shy+chars at start of word: wordLength == 0 && breakOpportunity + // shy only characters in word: wordLength == 0 && !breakOpportunity + int wordLength = lastIndex - thisStart; + int letterSpaces = 0; + if (wordLength != 0) { + letterSpaces = wordLength - 1; + // if there is a break opportunity and the next one + // is not a space, it could be used as a line end; + // add one more letter space, in case other text follows + if (breakOpportunity && !TextLayoutManager.isSpace(ch)) { + letterSpaces++; + } } assert letterSpaces >= 0; wordIPD = wordIPD.plus(letterSpaceIPD.mult(letterSpaces)); diff --git a/test/layoutengine/standard-testcases/word_lonely_shy.xml b/test/layoutengine/standard-testcases/word_lonely_shy.xml new file mode 100644 index 000000000..557ceea90 --- /dev/null +++ b/test/layoutengine/standard-testcases/word_lonely_shy.xml @@ -0,0 +1,98 @@ + + + + + +

+ This test checks that a word consisting of one or more Soft Hyphens is rendered as an empty word. +

+
+ + + + + + + + + + Name: hy (hyphen), Unicode: U+002D (45) + - + Name: shy (soft hyphen = discretionary hyphen), Unicode: U+00AD (173) + ­ ­ ­­ ­­­ ­­­­ a ­ b ­­ c ­­­ d ­­­­ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+