Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to get a kerning value in JavaScript

Guest
Nov 22, 2011 Nov 22, 2011

How to get a kerning value(distance between two characters) using javascript?

TOPICS
SDK
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2011 Nov 25, 2011

@Raykor11:
It would be best to move that question to scripting forum for InDesign.

But one solution could be:

1. Read out the property kerningValue from the insertion point between the two characters:

//if two characters are selected:

var _kerningValue = app.selection[0].insertionPoints[1].kerningValue;

2. Measure the exact distance between the characters, so you can decide if you want to increase or decrease the distance

//Two characters are selected:

var _twoCharacters = app.selection[0];

var _charLeft = _twoCharacters.characters[0];

var _charRight = _twoCharacters.characters[1];

var _temp1 = _charLeft.createOutlines(false) //false = does NOT delete original

var _bounds1 = _temp1[0].visibleBounds;

var _temp2 = _charRight.createOutlines(false) //false = does NOT delete original

var _bounds2 = _temp2[0].visibleBounds;

var _distance = _bounds2[1]-_bounds1[3];

_temp1[0].remove();

_temp2[0].remove();

alert("Distance between: "+_distance);

Be aware that there are a lot of other factors that will apply to character distance if you change the kerning value (like tracking, kerning method, composer, desiredGlyphScaling, desiredLetterSpacing, horizontalScale … just to mention a few), especially if the paragraph justification is set to JUSTIFIED or FULLY_JUSTIFIED.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2011 Nov 25, 2011
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 25, 2011 Nov 25, 2011
LATEST

Oh wait, Uwe already mentioned that 🙂

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines