Skip to main content
Known Participant
November 3, 2023
Answered

CEP extension to access text hyphenation and spelling features

  • November 3, 2023
  • 3 replies
  • 1558 views

I wanted to add hyphenation and spelling for specific language, I wonder if there is an option to achieve this using CEP. I mean the built-in hyphenation and spelling functionalities that InDesign has.

 

I've conducted some research and read some articles about this topic and found out that language specific hyphenation and spelling can be added to InDesign with dictionary files like "en_US.dic" and "hyph_en_US.dic".  I assume these are developed with hunspell/aspell programs and no CEP extensions are needed for them to run.

But as I know, this approach is static, by static I mean, once user downloads these files, he/she can use and distribute them freely.  But in my case, I want them to be expired after some time and become no longer usable, until new package is downloaded.

 

So I was thinking of making these as a third-party service where service launches locally at some port, and extension interacts with it via http protocol, providing dictionary and hyphenation dynamically to InDesign.

So I was interested if CEP has access to these built-in hyphenation and spelling features.

 

Another approach would be "DIY" approach where I create a "spellcheck" and "hyphenate" buttons in the extension window and process text inside TextFrames when buttons are clicked.  But this approach comes with many difficulties:

 

Hyphenation:

I need to be calculating TextFrame dimensions, word positions inside TextFrame and deciding which words to hyphenate. 

 

Spelling: 

Fetching all text, processing it, returning wrongly spelled words with their suggestions, and mapping them correctly, so that InDesign draws red underlines properly and when right-clicked to the "red-underlined" word, suggestions pop-up in context-menu.

I'm afraid that these fields can't be accessed by CEP extension, but I'm hoping for.

This topic has been closed for replies.
Correct answer Manan Joshi

No these things are not accessible to the scripting interface so not viable via CEP as well afaik. To dive into this you will have to create a C++ plugin

-Manan

3 replies

Manan JoshiCommunity ExpertCorrect answer
Community Expert
November 5, 2023

No these things are not accessible to the scripting interface so not viable via CEP as well afaik. To dive into this you will have to create a C++ plugin

-Manan

-Manan
Known Participant
November 5, 2023

Hello Manan, thanks for clarifying. I appreciate the suggestion to develop a plugin in C++. Initially I was trying to create a C++ plugin using the InDesign SDK, but I wanted to share some of the challenges I've encountered while exploring this path. Maybe you can provide some insights or solutions to these issues: 

 

SDK Documentation: The SDK documentation is somewhat challenging to navigate, and it can be misleading and unintuitive at times, especially for someone coming from a Python and Golang background. One issue I've encountered is the lack of specific guidance on configuring Visual Studio's 'include' directories. My IDE was full of red underlines, but the build was still succeeding. This led to some confusion, and I had to dig deeper to resolve these issues.

Additionally, the documentation often provides interfaces for classes without specifying how to import the actual class for use. This can be confusing, especially for those new to C++ and the InDesign SDK.

Another aspect is that the API is scattered across various folders, which requires importing multiple header files from different directories. It might be due to my limited knowledge of C++, but in other languages, you can generally import one root package, and the IDE will show all available classes and methods. The lack of this convenience adds complexity to the development process. Do you have any tips or resources that could help me bridge this gap?

 

Visual Studio IDE: While I understand that C++ development in Visual Studio is common, I've been having some difficulties compared to working with IDEs like PyCharm, which offer excellent auto-completion and method listing. It's possible that I might have misconfigured my Visual Studio for C++ development. Do you have any suggestions or configurations that could enhance the development experience?

 

Incomplete Tutorials: One specific issue I've encountered is that the SDK documentation's tutorials often stop at creating a simple widget, but they don't explain how to build other things. I'm not sure if I'm missing something or if there are additional resources that can help bridge this gap.

 

I'd love to hear your thoughts and any advice you might have to overcome these challenges in developing InDesign plugins with C++.

Community Expert
November 10, 2023

Regarding autocompletion and the red lines you see. Nothing much can be done about it. Adobe themselves mention this in the SDK that this is an issue so we need to live with it unless we try to fix it ourselves. I quote from SDK below

"IntelliSense has never worked very well for InDesign code, and you may find that IntelliSense red squiggles appear under nearly every InDesign type or API, despite your project compiling successfully."

 

Regarding including packages as a whole, that is not how things work in C++. You need to include the header files individually unless we have an umbrella header file including multiple files within it. The SDK is designed in terms of interfaces defined in each header file to make it better organised so you include only the header you need.

 

Regarding the help in SDK, well that is a tricky one. The only documentation we have is the programming guides shipped with the SDK, see under the docs/html folder. Open any html and then browse the left hand navigation pane of the page to access the programming guides. It is quite comprehensive but still a lot remains which needs to be unravelled by experimentation. The only way is to understand how the object model is setup, what are boss classes, what are interfaces, how objects are created at the runtime, how you get reference to an interface, commands, observers, responders, services etc. Once you get a hang of it then you will be able to make some good guesses as to which areas to investigate to approach a problem. The real problem then would be to find an interface that would do what you want, and then figure out a way on how to get a reference to it. The blockers would be if the interface which exposes the functionality you need is not public. 

 

I hope this helps you rather than confuse you more. C++ SDK development is a very time consuming task so you need to be super patient to even make a little headway into it.

-Manan

 

-Manan
rob day
Community Expert
Community Expert
November 4, 2023

I wanted to add hyphenation and spelling for specific language, I wonder if there is an option to achieve this using CEP.

 

Hi @jasuryusupov , I might not understand on what you are trying to do, but I’m not sure it has to be that complicated.

 

Just to clarify: spell checking and hyphenation depend on the Language property applied to the text—Language is a character property, so we can set different languges in a single document.  So before getting into coding here‘s an example:

 

All of the texts in the two columns have English: USA assigned as their Language property. The text in the right column is a spanish translation of the english text and the Dynamic Spell Checker highlights most of the texts and hyphenations as wrong

 

 

If I change the Language property of the spanish text to Spanish the Dynamic Spell Check works and the hyphenation is correct. So assuming a normal InDesign installation, I don’t think you have to worry about Dictionaries—you just have to make sure the texts have the correct language applied, which can be scripted.

 

Robert at ID-Tasker
Legend
November 4, 2023

I think OP wants to create CUSTOM Hyphenation and Spelling rules? 

 

 

Robert at ID-Tasker
Legend
November 3, 2023

So, in short, you want to create a paid hyphenation / spelling service?

 

With spelling - like you've suggested - export whole text for Spelling - user won't be able to used it again without paying again.

 

With hyphenation - once used you "can't" undo it ... you can use discretionary hyphens - so you would have to just replace all words that you'll have on your list with new "versions" with dscretionary hyphens placed at the right places.

 

Known Participant
November 4, 2023

Hi Robert, thanks for the "discretionary hyphens" trick for hyphenation, initially I got too excited seeing the results of iserting those "soft hyphens" into words, InDesign was handling them perfectly when I resize the TextFrame.

But, then I've realized that it comes with bunch of drawbacks:

  • When user copies the custom "hyphenated" text, text gets copied with messy "soft hyphen" (\u00AD) characters in it, unlike with the text, auto-hyphenated with built-in hyphenation functionality
  • When user does "word navigation" - pressing the arrow keys (left or right) iterating through word letters. The cursor moves from one word character to another but also counts the invisible "soft hyphen" as a character. 

I wonder if there are any solutions for these issues. Or I might be doing something wrong in the programming side - replacing the TextFrame contents directly: "tf.contents = newText"

 

Coming to the spelling, I couldn't find any method for drawing curvy red underlines through CEP

 

 

Robert at ID-Tasker
Legend
November 4, 2023

Unless you do it "the right way" - there always be some drawbacks. 

 

NEVER EVER replace contents of the TextFrame this way - and few other text objects - unless you want to get a mess with the formatting....