Javascript for Illustrator new feature: Cap Height

New Here ,
Dec 15, 2020 Dec 15, 2020

Copy link to clipboard

Copied

Hello,

I'm thinking about making a script that would assign the Cap Height to certain values in millimeters. I understand that there is a new feature to "Set font height preference". But is it possible?

I'm sorry if it's pretty vague, but I'm thinking of creating a dropdown list---say if I choose option "A", then the cap height will be sized to 2mm. If "B", then 3mm, and so on. This will be the purpose of the script.

 

Thank you and I would appreciate your feedback.

 

TOPICS
How to, Scripting, Tools, Type

Views

88

Likes

translate

Translate

Translate

Report

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
Enthusiast ,
Dec 19, 2020 Dec 19, 2020

Copy link to clipboard

Copied

Not what you asked for but...

 

var frames = app.activeDocument.textFrames;
var window1 = new Window("dialog", "Cap height");
var group1 = window1.add("group");
var button1 = group1.add("button", undefined, "↑");
var button2 = group1.add("button", undefined, "↓");
var scale = function (addend) {
  for (var i = 0; i < frames.length; i++) {
    var chars = frames[i].textRange.characters;
    for (var j = 0; j < chars.length; j++) {
      if (/[A-Z]/.test(chars[j].contents)) {
        chars[j].characterAttributes.verticalScale = chars[j].characterAttributes.verticalScale + addend;
        redraw();
      }
    }
  }
}
button1.onClick = function () {scale(10)}
button2.onClick = function () {scale(-10)}
window1.show ();

 

You could try calculating the addend (a percentage) from millimeters, which in turn you calculate from points, but given my ignorance of typeface anatomy I will not attempt this. 

Likes

translate

Translate

Translate

Report

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