【问题标题】:How to shrink a text to fit in a given rectangle in Illustrator via javascript?如何通过javascript缩小文本以适合Illustrator中的给定矩形?
【发布时间】:2018-11-30 06:54:23
【问题描述】:

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

【问题讨论】:

    标签: javascript adobe-illustrator


    【解决方案1】:

    您可以创建一个链接到初始 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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-25
      • 1970-01-01
      • 1970-01-01
      • 2019-11-09
      • 2013-07-07
      • 1970-01-01
      • 2021-10-23
      相关资源
      最近更新 更多