Skip to main content
Known Participant
October 11, 2019
Question

Read H&J violation through script

  • October 11, 2019
  • 2 replies
  • 946 views

Is it possible to read the amount/degree/... of H&J violation on a given line of text through InDesign Script?

I don't see the property in the documentation – Only an option to highlight the violations.

This topic has been closed for replies.

2 replies

Jongware
Community Expert
Community Expert
October 11, 2019

The value of a J violation can be calculated if you have at least a single space in your test line. Measure it, and compare against the 'regular' space width for that font. (Which you need to know in advance, so run this once on a non-justified line to get your base value. At the end, it should say that the space width is 100%.) The result is the space *difference* in percents, which you can compare directly against the min/max percentages in the Desired Word Spacing dialog: anything below or above is a violation.

 

/* 1. use the current line */
ln = app.selection[0].lines[0];
/* 2. find, then measure, any space */
spaceWidth = 0;
spaceSize = 0;
for (i=0; i<ln.characters.length; i++)
{
 if (ln.characters[i].contents == ' ')
 {
  spaceWidth = ln.characters[i+1].horizontalOffset - ln.characters[i].horizontalOffset;
  spaceSize = ln.characters[i].pointSize*ln.characters[i].horizontalScale/100;
  break;
 }
}
/* 3. .. in 1000ths, so recalc */
switch (app.activeDocument.viewPreferences.horizontalMeasurementUnits)
{
 case MeasurementUnits.POINTS: break;
 case MeasurementUnits.PICAS: spaceWidth*=12; break;
 case MeasurementUnits.INCHES: spaceWidth*=72; break;
 case MeasurementUnits.INCHES_DECIMAL: spaceWidth*=72; break;
 case MeasurementUnits.MILLIMETERS: spaceWidth/=25.4; spaceWidth*=72; break;
 case MeasurementUnits.CENTIMETERS: spaceWidth/=2.54; spaceWidth*=72; break;
 default: alert ('oh really!');exit();
}
spaceWidth /= spaceSize;
spaceWidth *= 1000;
/* 4. now you have a width: */
alert (spaceWidth);
/* 5. you need a value for *normal* spaces so run this once on a non-justified line to get... */
regularSpaceWidth = 250.0; /* for example, with Times New Roman */
/* 6. now you know how much yours deviates: */
difference = spaceWidth*100/regularSpaceWidth;
alert ('Space width: '+difference+'%');

 

 
H violations are much harder to check though -- I am not even sure what counts as such. Count succesively broken lines? [But I remember from the old days (a month ago -- it seems longer) that there were a ton of exactly the same questions by a single author on how/why/where to count these. I don't know if anyone actually *answered* any of these as the umpteenth Doubt About The Same really started to annoy me.]
Known Participant
October 11, 2019
Thank you so much for that! It is a great starting point for me!
Legend
October 11, 2019

Hi, 

This is not available through scripting. If you are up for a bit C++ plugin work, you can find this value by looking at IWaxLine and the value will be found in waxLine->GetJustificationViolationAmt

P.

Known Participant
October 11, 2019
Thanks! I will look into that.