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

Auto Size Text But Opposite in 2024

Explorer ,
May 02, 2024 May 02, 2024

Copy link to clipboard

Copied

There is a feature where you can automatically size the text-box to the text under Area Type Options > Auto Size.

 

Is there a feature that does exactly this but the opposite? Meaning the text changes size to fit the text-box. I've laid out an example of what I mean.

Screen Shot 2024-05-02 at 2.58.07 PM.png

 The reason I ask is whenever I lay out text, I already have an idea of how big I want the box to be. Once I put in text, then I have to waste time figuring out a font-size that makes all the text fit the box appropriately. It would be a God Send if there were an Auto Size feature for changing text-size and not the text-box.

 

Other Threads With My Issue Please Read
https://old.reddit.com/r/AdobeIllustrator/comments/n5b3n4/autosize_text_to_fit_textframe_i_found_how...

https://community.adobe.com/t5/illustrator-discussions/auto-change-text-size-to-size-of-text-box/td-...

 

I'm hoping after 2-3 years someone has created a script or an update implements this.

 

Please do not hesitate to ask for clarification.

TOPICS
Feature request , How-to , Scripting

Views

149

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
Adobe
Engaged ,
May 06, 2024 May 06, 2024

Copy link to clipboard

Copied

// fit_text_to_frame.jsx

// resizes text larger/smaller to fit the selected text frame(s)
// (the text frame must be fully selected; point text and non-text items are ignored)
// current limitations: this assumes all characters are same size; leading is not adjusted

(function() {

var MIN_SIZE = 1, MAX_SIZE = 1296 // practical limits, in pts
var MIN_STEP = 0.1 // the smaller this is, the more precise (and slower) the fit

function fitTextToFrame(textFrame) {
    // textFrame : TextFrame -- path or area text
    if (textFrame.typename !== 'TextFrame' || textFrame.kind === TextType.POINTTEXT) { return }
    var length = textFrame.contents.replace(/\s+$/, "").length // length of printable text (ignores trailing whitespace)
    if (length === 0) { return } // skip empty text frame
    // overflow checker; this checks length of printable text to index of last visible character in frame
    var hasOverflow = function() {
        var lastLine = textFrame.lines[textFrame.lines.length-1]
        if (!lastLine) { return true } // no lines visible (frame is too small)
        var visibleLength = (lastLine.characters[0].characterOffset + lastLine.length - 1)
        return visibleLength < length
    }
    // word count checker; assuming no overflow, this detects large words that are force-wrapped onto >1 line
    var hasSplitWords = function() {
      var wc = 0
      for (var i = 0; i < textFrame.lines.length; i++) {
	      wc += textFrame.lines[i].words.length
      }
      return wc > textFrame.words.length
    }
    // (caution: do not use JS’s +=, -=, *=, /= operators on AI properties as JSX doesn't handle them right)
    var style = textFrame.textRange.characterAttributes
    var size = style.size
    // 1. resize text so it is just overflowing
    while ((hasOverflow() || hasSplitWords()) && size >= MIN_SIZE * 2) { // decrease size until no overflow
        size /= 2.0
        style.size = size
    }
    if ((hasOverflow() || hasSplitWords())) { return } // hit minimum size and it's still overflowing, so give up
    while (!(hasOverflow() || hasSplitWords()) && size <= MAX_SIZE / 2) { // increase size until text overflows
        size *= 2.0
        style.size = size
    }
    if (!(hasOverflow() || hasSplitWords())) { return } // hit maximum size and it hasn't overflowed, so give up
    // 2. now do binary search for the largest size that will just fit the text frame
    var step = size / 2.0
    while (step > MIN_STEP) {
        step /= 2.0
        size += (hasOverflow() || hasSplitWords()) ? -step : step
        style.size = size
    }
    // 3. if text ends up overflowing after last step, step it back down
    while ((hasOverflow() || hasSplitWords())) { 
        style.size = size - step
        step *= 1.1
    }
}

var items = app.activeDocument.selection
for (var i = 0; i < items.length; i++) { // iterate over currently selected items
    fitTextToFrame(items[i])
}

})()

Votes

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
Community Expert ,
May 07, 2024 May 07, 2024

Copy link to clipboard

Copied

LATEST

Adobe Express is closer to the behavior you are looking for. That may help.

Votes

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