Skip to main content
Known Participant
January 7, 2024
Answered

InDesign SDK | Need help with hyphenation

  • January 7, 2024
  • 1 reply
  • 811 views

As you can see in the screenshot above, first textframe (on the left) is hyphenating the word "Clean-cut" incorrectly. The text is written in a custom language which uses sample hyphenator plugin from "sdksamples/hyphenator".

The second textframe (on the right) is hyphenating the word correctly without double dashes which is written in built-in language "English: USA".

 

I wonder why the sample plugin is working incorrectly when coming to hyphenating the words with dashes in them.

------

Here I will leave some code snippets from that plugin and debug logs:

 

HypAdapter.cpp, HypAdapter::findHyphenationPoints function has this, maybe something is going wrong here:

// Scan the characters and selectively generate hyphenation points.
for (int32 i = 0; rWord.CharCount() > 0; i++, rWord.RemoveFirst())
{
	Hyp::HyphenQuality hyphenQuality = IHyphenatedWord::kNoHyphenPoint;
	switch (rWord.First().GetValue()) {
	case kTextChar_HyphenMinus:
	case kTextChar_UnicodeHyphen:
	case kTextChar_FigureDash:
	case kTextChar_HorizontalBar:
	case kTextChar_EmDash:
	case kTextChar_EnDash: {
		hyphenQuality = IHyphenatedWord::kHardHyphenPoint;
		break;
	}
	case kTextChar_DiscretionaryHyphen: {
		hyphenQuality = IHyphenatedWord::kDiscretionaryHyphenPoint;
		break;
	}
	case kTextChar_Solidus:
	case kTextChar_ReverseSolidus:
	case kTextChar_Ellipse:
	case kTextChar_FlushSpace:
	case kTextChar_EnSpace:
	case kTextChar_EmSpace:
	case kTextChar_FigureSpace:
	case kTextChar_PunctuationSpace:
	case kTextChar_ThinSpace:
	case kTextChar_HairSpace:
	case kTextChar_HardSpace:
	case kTextChar_ZeroSpaceBreak: {
		hyphenQuality = IHyphenatedWord::kUnpreferredHyphenPoint;
		break;
	}
	}
	if (hyphenQuality == IHyphenatedWord::kNoHyphenPoint) {
		continue;
	}
	hyphenationPoints.push_back(Hyp::HyphenationPoint(i, hyphenQuality));
}

From logs, I can see this:

HypDiagnostic:TraceHyphenatedWord("Clean-cut")-->In
 word(ascii)="Clean-cut"
 nNthPoint, hyphenIndex, hyphenQuality
 0, 5, 90
 hyphenatedWord="Clean--cut"
HypDiagnostic:TraceHyphenatedWord()-->Out

 

Will be waiting for your response, thanks! 

This topic has been closed for replies.
Correct answer Rahul_Rastogi

Hi @jasuryusupov ,

 

It is not a problem of dictionary. I implemented custom hyphenation long time back.

 

You need to tweak the business logic of sdk sample hyphen code.

 

Sample code assumes there are no physical ("-") hyphen present in the code.

 

All functions such as IHyphenatedWord->GetFirstPartOfPoint(), IHyphenatedWord-> GetLastPartOfPoint(), IHphenatedWord->GetPartsOfPoints() and other functions should fill out WideString as if no physical "-" is present in the word.

 

1 reply

Community Expert
January 7, 2024

If I recall correctly then hyphenation depends upon the dictionary. So you might have to set your own dictionary to get it right. looking at the code of the plugin I do see that we have an option to do that in the setDictionaryFolderPath method.

-Manan

-Manan
Known Participant
January 7, 2024

This is crazy.

Is there an option to disable dictionary for hyphenation? I've tried doing

hyphenationService->CheckUserDictionary(kFalse);

at the hyp service installation part, but still getting the same incorrect result.

 

Also, the hyphenation service mode is set to Algorithm, so it shouldn't rely on dictionary lookups I think. Service mode can be seen it from debug trace log:

Hyphenator | HypHyphenationService::Hyphenate(rWord='keyin', serviceMode=Algorithm, nMinTail=1, nMinHead=1, providerHyphStyle=All) | languageID = 348, languageName = Uzbek: Latin

----

Nevertheless I've tried setting valid dictionary file path which is used/managed by custom UserDict manager service, coming from CHLinguistic sample plugin. Added all combinations of words into dict: "clean-cut", "clean" and "cut". Still getting same issue...

----

Built-in English hyphenator is working correctly even when I enter invalid word "Clead-cud". So I don't think its dictionary file related thing..? 

Whereas the uzbek word "baxt-saodat" marked as correct (no red underlines), spellchecked algorithimically in custom speller service, is getting hyphenated incorrectly.

Also, when I open the dictionary and press "Hyphenate", I get same results: "-~" 

 

Rahul_RastogiCorrect answer
Inspiring
January 8, 2024

Hi @jasuryusupov ,

 

It is not a problem of dictionary. I implemented custom hyphenation long time back.

 

You need to tweak the business logic of sdk sample hyphen code.

 

Sample code assumes there are no physical ("-") hyphen present in the code.

 

All functions such as IHyphenatedWord->GetFirstPartOfPoint(), IHyphenatedWord-> GetLastPartOfPoint(), IHphenatedWord->GetPartsOfPoints() and other functions should fill out WideString as if no physical "-" is present in the word.