View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0010517 | Scribus | Usability | public | 2012-01-13 10:45 | 2021-06-08 08:11 |
Reporter | cezaryece | Assigned To | |||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | new | Resolution | open | ||
Product Version | 1.4.1.svn | ||||
Summary | 0010517: [PATCH] disabling hyphenation for word by inserting softhyphen before it | ||||
Description | This patch bring small but very useful feature (at least for me). After it when you insert soft hyphen at beginning of some word then this word will not be hyphenated. | ||||
Additional Information | Solution is achieved by add new bool variable "disableHyph" to text layout routine. If softhyphen is found and previous character is not letter or number (or it is first character in story) then disableHyph is set to true. If next character which is not letter on number will be found then disableHyph is reset to false. Next this variable is used in conditions for inserting hyphens and setting break positions. | ||||
Tags | hyphenation, patch | ||||
Patch | Yes | ||||
related to | 0004676 | acknowledged | feature to mark words as "do not hyphenate" |
|
there seems to already by some code for this in scribus... i've try to test it, but i can't get any reliable results. sometimes the starting soft hyphen seems to be respected other times not... if the patch by cezary works, i guess it should be applied and the current code (if there is some!) removed. |
|
stopHyphenateWords2.patch (4,334 bytes)
Index: scribus/pageitem_textframe.cpp =================================================================== --- scribus/pageitem_textframe.cpp (wersja 17197) +++ scribus/pageitem_textframe.cpp (kopia robocza) @@ -1137,6 +1137,7 @@ current.rightMargin = 0.0; current.mustLineEnd = current.colRight; current.restartX = 0; + bool disableHyph = false; for (int a = firstInFrame(); a < itemText.length(); ++a) { @@ -1152,7 +1153,17 @@ double scaleV = charStyle.scaleV() / 1000.0; double scaleH = charStyle.scaleH() / 1000.0; double offset = hlcsize10 * (charStyle.baselineOffset() / 1000.0); + + //avoid hyphenation for words with softhyphen at it beginning + if (hl->ch == SpecialChars::SHYPHEN && !disableHyph) + { + if ((a == 0) || !itemText.item(a - 1)->ch.isLetterOrNumber()) + disableHyph = true; + } + else if (disableHyph && !hl->ch.isLetterOrNumber()) + disableHyph = false; + if (chstr.isEmpty()) chstr = SpecialChars::ZWNBSPACE; if (style.lineSpacingMode() == ParagraphStyle::AutomaticLineSpacing) @@ -1735,7 +1746,7 @@ double overflowWidth = 0.0; double hyphWidth = 0.0; bool inOverflow = false; - if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN) + if ((hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN) && !disableHyph) hyphWidth = charStyle.font().charWidth('-', hlcsize10) * (charStyle.scaleH() / 1000.0); if ((current.isEndOfLine(style.rightMargin() + hyphWidth)) || current.isEndOfCol(realDesc) || SpecialChars::isBreak(hl->ch, Cols > 1) || (current.xPos - current.maxShrink + hyphWidth) >= current.mustLineEnd) { @@ -1803,8 +1814,11 @@ charEnd = static_cast<int>(ceil(current.xPos - current.maxShrink) + hyphWidth); } if (legacy && - (((hl->ch == '-' || (hl->effects() & ScStyle_HyphenationPossible)) && (current.hyphenCount < m_Doc->HyCount || m_Doc->HyCount == 0)) - || hl->ch == SpecialChars::SHYPHEN)) + ((hl->ch == '-') + || (!disableHyph + && ( ((hl->effects() & ScStyle_HyphenationPossible) + && (current.hyphenCount < m_Doc->HyCount || m_Doc->HyCount == 0)) + || hl->ch == SpecialChars::SHYPHEN)))) { if (hl->effects() & ScStyle_HyphenationPossible || hl->ch == SpecialChars::SHYPHEN) { @@ -1908,7 +1922,7 @@ } // hyphenation - if (((hl->effects() & ScStyle_HyphenationPossible) || (hl->ch == '-') || hl->ch == SpecialChars::SHYPHEN) && (!outs) && !itemText.text(a-1).isSpace() ) + if ( !disableHyph && ((hl->effects() & ScStyle_HyphenationPossible) || (hl->ch == '-') || hl->ch == SpecialChars::SHYPHEN) && (!outs) && !itemText.text(a-1).isSpace() ) { breakPos = current.xPos; if (hl->ch != '-') @@ -2074,7 +2088,7 @@ current.finishLine(EndX); hyphWidth = 0.0; - if ((hl->effects() & ScStyle_HyphenationPossible) || hl->ch == SpecialChars::SHYPHEN) + if (!disableHyph && ((hl->effects() & ScStyle_HyphenationPossible) || hl->ch == SpecialChars::SHYPHEN)) { // insert hyphen if (current.lastInRowLine) Index: scribus/hyphenator.cpp =================================================================== --- scribus/hyphenator.cpp (wersja 17197) +++ scribus/hyphenator.cpp (kopia robocza) @@ -218,20 +218,22 @@ firstC = text.indexOf(wordBoundary, firstC+Ccount); if (firstC < 0) break; - if (firstC > 0 && text.at(firstC-1) == SpecialChars::SHYPHEN) - { - Ccount = 1; - continue; - } +//FIX ME: if this not for avoiding hyphenation by inserting SoftHyphen at begin of word uncomment these lines +// if (firstC > 0 && text.at(firstC-1) == SpecialChars::SHYPHEN) +// { +// Ccount = 1; +// continue; +// } lastC = text.indexOf(whiteSpace, firstC); if (lastC < 0) lastC = signed(text.length()); Ccount = lastC - firstC; - if (lastC < signed(text.length()) && text.at(lastC) == SpecialChars::SHYPHEN) - { - ++Ccount; - continue; - } +//FIX ME: if this not for avoiding hyphenation by inserting SoftHyphen at end of word uncomment these lines +// if (lastC < signed(text.length()) && text.at(lastC) == SpecialChars::SHYPHEN) +// { +// ++Ccount; +// continue; +// } if (Ccount > MinWordLen-1) { found = text.mid(firstC, Ccount).toLower(); |
|
As Ale mentioned above, seems there is some code that try to give same feature in hyphenator code, but it is not working good. I prepared new patch with commented out that code. Advantage of my solution is that effect of inserting SoftHyphen appears immediately. Previous solution worked (sometimes) after dehyphenating and hypehanting text again. Disadvantage is that only SoftHyphen before word is working as hyphenation blocker. But I think this is same behaviour like other DTP applications. My solution is independent from hyphenator code as local control of hyphenation for single words is moved to PageItem_TextFrame::layout(). |
|
it would be nice if somebody would have a look at this patch and eventually include it into trunk + 1.4.1 ... |
|
please replace isLetterOrNumber by !isSpace and !isLetterOrNumber by isSpace when applying the patch. in this way one could control the way an url is hyphenated (which is often a pain). please tell me if you need a new patch or you can do the change when applying it. |
|
not to self: btw, a soft hyphen in front of the word should not avoid all hyphenation, just disable the automatic hyphenation for the given word. |
Date Modified | Username | Field | Change |
---|---|---|---|
2012-01-13 10:45 | cezaryece | New Issue | |
2012-01-13 10:45 | cezaryece | File Added: stopHyphenateWords.patch | |
2012-01-14 18:46 | ale | Note Added: 0027541 | |
2012-01-14 20:28 | cezaryece | File Added: stopHyphenateWords2.patch | |
2012-01-14 20:37 | cezaryece | Note Added: 0027542 | |
2012-03-06 12:03 | ale | Note Added: 0027780 | |
2012-10-03 13:19 | ale | Summary | [new feature patch] disabling hyphenation for word by inserting softhyphen before it => [PATCH] disabling hyphenation for word by inserting softhyphen before it |
2012-10-03 13:22 | ale | File Deleted: stopHyphenateWords.patch | |
2012-10-03 13:59 | ale | Note Added: 0029018 | |
2014-01-23 12:06 | JLuc | Tag Attached: patch | |
2014-10-24 23:00 | Kunda | Patch | => Yes |
2020-10-27 11:09 | ale | Note Added: 0048227 | |
2021-06-08 08:11 | JLuc | Tag Attached: hyphenation | |
2021-06-08 08:11 | JLuc | Relationship added | related to 0004676 |