Skip to main content
K.Daube
Community Expert
Community Expert
July 2, 2022
Answered

How to find an Automatic Hyphen in text

  • July 2, 2022
  • 1 reply
  • 274 views

Dear friends and experts,

I want to find automatic hyphens in a selected text.

It turns out that both oDoc.GetTextForRange and object.GetText eliminate these characters which are in the text (e.g. they are are present in MIF) - char code \x06.

In the example output from GetText such characters are expected at the end of lines 1 and 2:

 

 

Far far away, behind the word mountains, far from the coun
tries Vokalia and Consonantia, there live the blind texts. Sepa
rated they live in Bookmarksgrove right at the coast of the 
Semantics, a large language ocean

 

 

Of course they can be found with the Find method and the following Find parameters:

 

oPropVal2.propIdent.num   = Constants.FS_FindObject;
oPropVal2.propVal.valType = Constants.FT_Integer;
oPropVal2.propVal.ival = Constants.FV_FindAutomaticHyphen ;

 

Any ideas?

I imagine a brute force method:

  • Save the document prophylactically (mhm, the user might not like this).
  • Get the start location of the text range.
  • Insert an End-of-flow character after the text location.
  • Issue an ordinary Search at the start location.
  • Memorise the found text range (if found).
  • Remove the end-of-flow charcter.
  • Select the memorised text range to indicate the find.
This topic has been closed for replies.
Correct answer K.Daube

Bob, You may be correct - although the Char SoftHyphen appears in the MIF...

But on the other side: the final TextRange is just a TextLocation (Begin = End). Hence I make it visible by a trick with FCode execution:

 

aTi = oDoc.GetTextForRange (oTR, Constants.FTI_PgfBegin);
for (j = 0; j < aTi.length; j++) {
  oPgf = aTi[j].obj;
  aPgfs.push (oPgf);
}
for (j = 0; j < aPgfs.length; j++) {
  oPgf = aPgfs[j];
  oTL  = new TextLoc (oPgf, 0);
  oDoc.TextSelection = new TextRange (oTL, oTL); // req. in FindSomething
  oTR = KLD_F.FindSomething ("AUTHYP", "", 0, false, false, false); // takes TextSelection
  if (oTR != undefined) {
    oDoc.TextSelection = oTR;
    KLD_F.ExecuteFCodes(["SelectPreviousCharacter"]); // indicate selection
    return oTR;
  }
}
return undefined;

 

 

1 reply

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthor
Community Expert
July 3, 2022

After poking around I found the probable relevant constant for in GetTextInRange: 

FTI_HyphenLineEnd 

This finally leads to this snippet:

  } else if (sFType == "AUTHYP") { // just jump
    aTi =  oDoc.GetTextForRange (oTR, Constants.FTI_LineEnd);
    for (j = 0; j < aTi.length; j++) {
      if (aTi[j].idata == Constants.FTI_HyphenLineEnd) { 
        var jOffset = aTi[j].offset;
        break;
      }
    }
    oTL = new TextLoc (oTR.beg.obj, jOffset-1); 
    var oTL2 = new TextLoc (oTL.obj, jOffset);
    oTRfound = new TextRange(oTL,oTL2);
    return oTRfound;

The final text selection comprises the last character before the automatic hyphen and the hyphen. I have not found a method to just select the hyphen...

Bob_Niland
Community Expert
Community Expert
July 3, 2022

I always turn off hyphenation, so haven't studied the feature at all, but if I needed to find them, I would first want to be sure that they exist in the document data structure.

It strikes me as possible that they are strictly a render-time phenomenon - to screen for author, and to output data structures (Ps, PDF, HTML, etc.) at publish.

It doesn't take much to cause every hyphenation to change: font metrics, MP text frame size. Given FM's origins on fairly slow computers, I could see software architects of the time wanting to avoid having to compute the layout changes until some page was actually rendered.

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthorCorrect answer
Community Expert
July 7, 2022

Bob, You may be correct - although the Char SoftHyphen appears in the MIF...

But on the other side: the final TextRange is just a TextLocation (Begin = End). Hence I make it visible by a trick with FCode execution:

 

aTi = oDoc.GetTextForRange (oTR, Constants.FTI_PgfBegin);
for (j = 0; j < aTi.length; j++) {
  oPgf = aTi[j].obj;
  aPgfs.push (oPgf);
}
for (j = 0; j < aPgfs.length; j++) {
  oPgf = aPgfs[j];
  oTL  = new TextLoc (oPgf, 0);
  oDoc.TextSelection = new TextRange (oTL, oTL); // req. in FindSomething
  oTR = KLD_F.FindSomething ("AUTHYP", "", 0, false, false, false); // takes TextSelection
  if (oTR != undefined) {
    oDoc.TextSelection = oTR;
    KLD_F.ExecuteFCodes(["SelectPreviousCharacter"]); // indicate selection
    return oTR;
  }
}
return undefined;