summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLászló Németh <nemeth@numbertext.org>2013-09-25 23:46:22 +0200
committerNémeth László <nemeth@numbertext.org>2013-09-26 08:33:39 +0000
commit968f4d72a23bb28d097a7694d66f0b866b3b33f0 (patch)
tree2e0d3da5478ed3acc249816d9ef2059cd730add5
parent6a3cf741d1d4d9e700c14da6d6ae386d3aa372f8 (diff)
fdo#56392 fix hyphenation of words with punctuation
Change-Id: I17e094fa93a7ba6a554f4bc2dfd353f718f1a500 Reviewed-on: https://gerrit.libreoffice.org/6040 Reviewed-by: Németh László <nemeth@numbertext.org> Tested-by: Németh László <nemeth@numbertext.org>
-rw-r--r--i18npool/source/breakiterator/breakiterator_unicode.cxx29
1 files changed, 26 insertions, 3 deletions
diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx b/i18npool/source/breakiterator/breakiterator_unicode.cxx
index 0e64343e476c..4c08a5f63d9b 100644
--- a/i18npool/source/breakiterator/breakiterator_unicode.cxx
+++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx
@@ -373,12 +373,28 @@ LineBreakResults SAL_CALL BreakIterator_Unicode::getLineBreak(
lbr.breakIndex = nStartPos;
lbr.breakType = BreakType::WORDBOUNDARY;
} else if (hOptions.rHyphenator.is()) { //Hyphenation break
- Boundary wBoundary = getWordBoundary( Text, nStartPos, rLocale,
- WordType::DICTIONARY_WORD, false);
+ sal_Int32 boundary_with_punctuation = (line.aBreakIterator->next() != BreakIterator::DONE) ? line.aBreakIterator->current() : 0;
+ line.aBreakIterator->preceding(nStartPos + 1); // reset to check correct hyphenation of "word-word"
+
+ sal_Int32 nStartPosWordEnd = nStartPos;
+ while (line.aBreakIterator->current() < nStartPosWordEnd && u_ispunct((sal_uInt32)Text[nStartPosWordEnd])) // starting punctuation
+ nStartPosWordEnd --;
+
+ Boundary wBoundary = getWordBoundary( Text, nStartPosWordEnd, rLocale,
+ WordType::DICTIONARY_WORD, false);
+
+ nStartPosWordEnd = wBoundary.endPos + 1;
+ while (nStartPosWordEnd < Text.getLength() && (u_ispunct((sal_uInt32)Text[nStartPosWordEnd]))) // ending punctuation
+ nStartPosWordEnd ++;
+ nStartPosWordEnd = nStartPosWordEnd - wBoundary.endPos - 1;
+ if (hOptions.hyphenIndex - wBoundary.startPos < nStartPosWordEnd) nStartPosWordEnd = hOptions.hyphenIndex - wBoundary.startPos;
+#define SPACE 0x0020
+ while (boundary_with_punctuation > wBoundary.endPos && Text[--boundary_with_punctuation] == SPACE);
+ if (boundary_with_punctuation != 0) boundary_with_punctuation += 1 - wBoundary.endPos;
uno::Reference< linguistic2::XHyphenatedWord > aHyphenatedWord;
aHyphenatedWord = hOptions.rHyphenator->hyphenate(Text.copy(wBoundary.startPos,
wBoundary.endPos - wBoundary.startPos), rLocale,
- (sal_Int16) (hOptions.hyphenIndex - wBoundary.startPos), hOptions.aHyphenationOptions);
+ (sal_Int16) (hOptions.hyphenIndex - wBoundary.startPos - nStartPosWordEnd), hOptions.aHyphenationOptions);
if (aHyphenatedWord.is()) {
lbr.rHyphenatedWord = aHyphenatedWord;
if(wBoundary.startPos + aHyphenatedWord->getHyphenationPos() + 1 < nMinBreakPos )
@@ -386,6 +402,13 @@ LineBreakResults SAL_CALL BreakIterator_Unicode::getLineBreak(
else
lbr.breakIndex = wBoundary.startPos; //aHyphenatedWord->getHyphenationPos();
lbr.breakType = BreakType::HYPHENATION;
+
+ // check not optimal hyphenation of "word-word" (word with hyphens)
+ if (lbr.breakIndex > -1 && wBoundary.startPos + aHyphenatedWord->getHyphenationPos() < line.aBreakIterator->current()) {
+ lbr.breakIndex = line.aBreakIterator->current();
+ lbr.breakType = BreakType::WORDBOUNDARY;
+ }
+
} else {
lbr.breakIndex = line.aBreakIterator->preceding(nStartPos);
lbr.breakType = BreakType::WORDBOUNDARY;;