View Issue Details

IDProjectCategoryView StatusLast Update
0010517ScribusUsabilitypublic2021-06-08 08:11
Reportercezaryece Assigned To 
PrioritynormalSeverityfeatureReproducibilityN/A
Status newResolutionopen 
Product Version1.4.1.svn 
Summary0010517: [PATCH] disabling hyphenation for word by inserting softhyphen before it
DescriptionThis 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 InformationSolution 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.
Tagshyphenation, patch
PatchYes

Relationships

related to 0004676 acknowledged feature to mark words as "do not hyphenate" 

Activities

ale

2012-01-14 18:46

manager   ~0027541

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.

cezaryece

2012-01-14 20:28

developer  

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();
stopHyphenateWords2.patch (4,334 bytes)   

cezaryece

2012-01-14 20:37

developer   ~0027542

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().

ale

2012-03-06 12:03

manager   ~0027780

it would be nice if somebody would have a look at this patch and eventually include it into trunk + 1.4.1 ...

ale

2012-10-03 13:59

manager   ~0029018

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.

ale

2020-10-27 11:09

manager   ~0048227

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.

Issue History

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