View Issue Details

IDProjectCategoryView StatusLast Update
0010517ScribusUsabilitypublic2024-03-16 16:01
Reportercezaryece Assigned Toale  
PrioritynormalSeverityfeatureReproducibilityN/A
Status assignedResolutionopen 
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

updater  

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

updater   ~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.

ale

2024-03-16 11:29

manager   ~0051043

the years go by and the scribus code has much changed.

stimulated by jluc's post

https://forums.scribus.net/index.php/topic,5003.msg22999.html

i've found this ticket and tried to figure out if cezary's patch can be useful to finally get this feature into scribus.
i could not recognize the position in the code, where it would have been applied and, as a consequence, i did not even try to fully understand it.
but it helped me to figure out the relevant work to be done and where a patch should be made.

later today, i will be proposing a trivial patch that -- without changing much or completely solving the problem -- brings a big improvement.

since there seems be a lack of knowledge about the ways to avoid the hyphenation of a specific word (typically an "internet address", first let me summarize the current state:

- it is possible to set the smallest word to be hyphenated for a specific word (or a character style) to 99 and avoid the hyphenation of a single word. this seems to be working for both the automatic hyphenation and for "extras > hyphenate text" (as long you're not trying to avoid the hyphenation of a sri lankan email address...)
- when "hyphenating during typing" is enabled, typing a soft hyphen when staring a word will prevent the hyphenation of that word. adding the soft hyphen when some hyphenation already occurred is possible, but the inserted hyphens need to be manually removed by deleting the letter before the automatic hyphen and retyping that letter.
- "extras > hyphenate" simply ignores the soft hyphen in front of a word.

the patch i will be proposing only changes the last behavior described and makes "extras > hyphenate" ignore words that start with a soft hyphen.

ale

2024-03-16 13:50

manager   ~0051045

here is the patch
soft-hyphen.diff (543 bytes)   
diff --git a/scribus/hyphenator.cpp b/scribus/hyphenator.cpp
index 77e3d0f9d..17d2614d5 100644
--- a/scribus/hyphenator.cpp
+++ b/scribus/hyphenator.cpp
@@ -170,6 +170,9 @@ void Hyphenator::slotHyphenate(PageItem* it)
 			QString wordLower = QLocale(style.language()).toLower(word);
 			if (wordLower.contains(SpecialChars::SHYPHEN))
 				continue;
+			// skip words with a soft hyphen in front of them
+			if (firstC > 0 && text.at(firstC - 1) == SpecialChars::SHYPHEN)
+				continue;
 
 			bool ok = loadDict(style.language());
 			if (!ok)
soft-hyphen.diff (543 bytes)   

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
2024-03-16 11:29 ale Note Added: 0051043
2024-03-16 13:50 ale Note Added: 0051045
2024-03-16 13:50 ale File Added: soft-hyphen.diff
2024-03-16 16:01 ale Assigned To => ale
2024-03-16 16:01 ale Status new => assigned