如何通过javascript在Illustrator中缩小文本以适合给定的矩形?

如何通过javascript在Illustrator中缩小文本以适合给定的矩形?,javascript,adobe-illustrator,Javascript,Adobe Illustrator,我在Illustrator中通过javascript创建了一个areaText,并希望将文本以最大可能的大小放入给定的框中。如何做到这一点?您可以创建一个链接到初始区域文本的溢出区域,并缩小大小,直到该区域不再有文本 示例: var docRef = documents.add(null,1080,1080); var piRef = activeDocument.pathItems; var textRefs = activeDocument.textFrames; var pathRef

我在Illustrator中通过javascript创建了一个areaText,并希望将文本以最大可能的大小放入给定的框中。如何做到这一点?

您可以创建一个链接到初始区域文本的溢出区域,并缩小大小,直到该区域不再有文本

示例:

var docRef = documents.add(null,1080,1080);
var piRef = activeDocument.pathItems;
var textRefs = activeDocument.textFrames;

var pathRef = piRef.add();

// target text area
var textArea = piRef.rectangle(940, 140, 800, 600);
var text = textRefs.areaText(textArea);

// maximum Font size, use something big to shrink down from
var maxFontSize = 200

text.textRange.characterAttributes.size = maxFontSize;

// create an overflow box
var overflowArea = piRef.rectangle(940, 140, 800, 600);
var overflowText = textRefs.areaText(overflowArea, TextOrientation.HORIZONTAL, text);

text.contents = "This text should fit in the box.";

// shrink text size until the overflow box is empty.
var fontSize = maxFontSize;
while (overflowText.words.length > 0 && fontSize > 0)
{
    text.textRange.characterAttributes.size = --fontSize;
    overflowText.textRange.characterAttributes.size = --fontSize;
}