Typophile

OpenType in InDesign via scripting

Miguel Sousa

Hey, I just compiled a list of all the JavaScript commands to apply/remove OpenType features in InDesign through scripting. They should work in both CS2 & CS3, except the ones marked as ’CS3 only’.

myObject can be anything that accepts the properties, from a whole Story to a single Character. So, if you want to apply the properties to the first story in the document, you’ll need to declare ’myObject’ as:
var myObject = app.documents[0].stories[0];

If you only want to change the first line of text in a document, ’myObject’ should be declared like:
var myObject = app.documents[0].stories[0].lines[0];

And if what you want to change is the first character in a document, ’myObject’ should be:
var myObject = app.documents[0].stories[0].characters[0];

The properties can also be applied to paragraphs, text frames, words, etc.

Happy coding!!

################
// All Caps (case+cpsp)
myObject.capitalization = Capitalization.ALL_CAPS;

// Small Caps (smcp)
myObject.capitalization = Capitalization.SMALL_CAPS;

// All Small Caps (c2sc+smcp)
myObject.capitalization = Capitalization.CAP_TO_SMALL_CAP;

// to reset capitalization
myObject.capitalization = Capitalization.NORMAL;

// Ligatures (liga)
myObject.ligatures = false; // to turn off
myObject.ligatures = true; // to turn on

###

// Discretionary Ligatures (dlig+hlig)
myObject.otfDiscretionaryLigature = true;

// Fractions (frac)
myObject.otfFraction = true;

// Ordinal (ordn)
myObject.otfOrdinal = true;

// Swash (swsh+cswh)
myObject.otfSwash = true;

// Titling Alternates (titl)
myObject.otfTitling = true;

// Contextual Alternates (calt+clig)
myObject.otfContextualAlternate = true;

// Slashed Zero (zero)
myObject.otfSlashedZero = true;

// Stylistic Sets (ssXX)
myObject.otfStylisticSets = 8; // to apply Set 3 (ss03)
/*
0 = None
2 = ss01
4 = ss02
6 = ss01+ss02
8 = ss03
10 = ss01+03
12 = ss02+03
14 = ss01+02+03
16 = ss04
32 = ss05
64 = ss06
128 = ss07
...
OR
1 = None
3 = ss01
5 = ss02
7 = ss01+02
9 = ss03
11 = ss01+03
13 = ss02+03
15 = ss01+02+03
17 = ss04
19 = ss01+04
21 = ss02+04
...
*/

// Positional Forms (init, medi, fina, isol) -- CS3 only
//// General Form
myObject.positionalForm = PositionalForms.NONE;
//// Automatic Form
myObject.positionalForm = PositionalForms.CALCULATE;
//// Initial Form
myObject.positionalForm = PositionalForms.INITIAL;
//// Medial Form
myObject.positionalForm = PositionalForms.MEDIAL;
//// Final Form
myObject.positionalForm = PositionalForms.FINAL;
//// Isolated Form
myObject.positionalForm = PositionalForms.ISOLATED;

###

// Superscript/Superior (sups)
myObject.position = Position.OT_SUPERSCRIPT;

// Subscript/Inferior (subs if present, else sinf)
myObject.position = Position.OT_SUBSCRIPT;

// Numerator (numr)
myObject.position = Position.OT_NUMERATOR;

// Denominator (dnom)
myObject.position = Position.OT_DENOMINATOR;

// to reset position
myObject.position = Position.NORMAL;

###

// Tabular Lining (tnum+lnum)
myObject.otfFigureStyle = OTFFigureStyle.TABULAR_LINING;

// Proportional Oldstyle (pnum+onum)
myObject.otfFigureStyle = OTFFigureStyle.PROPORTIONAL_OLDSTYLE;

// Proportional Lining (pnum+lnum)
myObject.otfFigureStyle = OTFFigureStyle.PROPORTIONAL_LINING;

// Tabular Oldstyle (tnum+onum)
myObject.otfFigureStyle = OTFFigureStyle.TABULAR_OLDSTYLE;

// Default Figure Style
myObject.otfFigureStyle = OTFFigureStyle.DEFAULT_VALUE;

### Not available through the UI

// Historical Forms (hist)
myObject.otfHistorical = true;

// Localized Forms (locl) -- CS3 only
myObject.otfLocale = true;

// Mark Positioning, Required Ligatures,
// Glyph Composition / Decomposition
// (mark, mkmk, mset, rlig, ccmp) -- CS3 only
myObject.otfMark = true;

// Access any feature available in the font
// and specify the index of the alternate glyph
myObject.opentypeFeatures = [["salt", 0]]; // default glyph
myObject.opentypeFeatures = [["salt", 1]]; // 1st alternate glyph

Not sure what these do, Miguel, but thanks for sharing!

ChrisL

Hey thanks!

You’re welcome!

BTW, I’ve added a few lines to the Stylistic Sets section.

I’ve added a few lines to the Stylistic Sets section.

You didn’t even give me a chance to ask.  :)  Indeed

2 = ss01  /  4 = ss02  /  6 = ss01+ss02

makes more sense to me than

3 = ss01  /  5 = ss02  /  7 = ss01+02

because 2+4=6 looks fine, while 3+5=7 ...

The list with even numbers is the “official” one (Thanks Eric!). I kept the other list just for the sake of completeness.

Miguel, does opentypeFeatures allow the use of fully arbitrary features such as pcap or unic?

A.

Eric,

which version of InDesign was first to support the opentypeFeatures property?

A.

Yes, you can use any OpenType feature and InDesign will apply them blindly. However, you can have trouble if you apply a feature (example ’swsh’) that InDesign has an alternate way of applying — in this case, InDesign may turn it off. Both GPOS & GSUB features should work. Of course, any 1:many glyph substitutions will still fail.
Also, you can create character or paragraph styles and modify them via scripting to add features using the code above — a style is another “text target” for these commands. Or, you can apply the feature to text and it the “new style” button which will load these attributes into the style, even though the UI doesn’t support them.
WARNING: this is a way to confuse less savvy users who may get the documents later...

There was an older mechanism that was replaced by the syntax above in CS2. I think the older one was “OpenTypeFeatures” (not sure how the capitalization is done between the different scripting systems). It specified 2 integers instead of a string & an integer, so it would be harder to use.
New
myObject.opentypeFeatures = [ ["salt", 0], ["pcap", 0] ];

Old (something like this)
myObject.openTypeFeatures = [0x81617282, 0, 0x7a63617a, 0];

I made up those hexadecimal numbers, but you get the drift.

Captured from web.archive.org on 2 Nov 2008. view this capture