2 Replies Latest reply on Aug 10, 2017 12:43 AM by s_ashok

    Need illustrator javascript to Check and fix the dynamically over flow text

    s_ashok Level 1

      I want to dynamically fit over flow text in a specific txt frame in Illustrator by changing the font size. Is there a way to do this with JavaScript and set a minimum font size that does this action and in case there is still text is over flow show a pop

        • 1. Re: Need illustrator javascript to Check and fix the dynamically over flow text
          williamadowling Level 4

          Do you have some code written that you want help with, or are you looking to have the code written?

          • 2. Re: Need illustrator javascript to Check and fix the dynamically over flow text
            s_ashok Level 1

            Thanks for the reply,

            Below script was based on dataset this will move all the multiline text to single line text by reducing font size without changing the text frame size. But I need code to find the data set with overset text and reduce the font size to fit overset text.

             

            #target illustrator

            function DealWithOversetText_SingleLine(){

            function recordFontSize(){

            for (var i = 0; i < doc.textFrames.length; i++) {

            var t = doc.textFrames[i];

            if(t.kind == TextType.AREATEXT && t.editable && !t.locked && !t.hidden){

            1. t.note = t.textRange.characterAttributes.size;

            }

            };

            }

            function removeNotesOnText(){

            for (var i = 0; i < doc.textFrames.length; i++) {

            var t = doc.textFrames[i];

            1. t.note = "";

            }

            }

            function isOverset(textBox){

            if(textBox.lines.length > 0){

            if(textBox.lines[0].characters.length < textBox.characters.length){

            return true;

            } else {

            return false;

            }

            } else if(textBox.characters.length > 0){

            return true;

            }

            }

            function shrinkFont(textBox){

            var totalCharCount = textBox.characters.length;

            var lineCount = textBox.lines.length;

            if(textBox.lines.length > 0){

            var firstLineCharCount = textBox.lines[0].characters.length;

            if(isOverset(textBox)){

            var inc = 0.01;

            while(isOverset(textBox)){

            1. textBox.textRange.characterAttributes.size -= inc;

            }

            }

            } else if(textBox.characters.length > 0){

            var inc = 0.01;

            while(isOverset(textBox)){

            1. textBox.textRange.characterAttributes.size -= inc;

            }

            }

            }

            function resetSize(textAreaBox){

            var t = textAreaBox;

            if(t.contents != ""){

            if(t.note != ""){

            1. t.textRange.characterAttributes.size = (t.note * 1);

            }

            }

            }

            function resetAllTextBoxes(){

            for (var i = 0; i < doc.textFrames.length; i++) {

            var t = doc.textFrames[i];

            if(t.kind == TextType.AREATEXT && t.editable && !t.locked && !t.hidden){

            resetSize(t);

            }

            };

            }

            function shrinkAllTextBoxes(){

            for (var i = 0; i < doc.textFrames.length; i++) {

            var t = doc.textFrames[i];

            if(t.kind == TextType.AREATEXT && t.editable && !t.locked && !t.hidden){

            shrinkFont(t);

            }

            };

            }

             

            if(app.documents.length > 0){

            var doc = app.activeDocument;

            if(doc.activeDataSet == doc.dataSets[0]){

            recordFontSize();

            }

             

            resetAllTextBoxes();

            shrinkAllTextBoxes();

             

            if(doc.activeDataSet == doc.dataSets[doc.dataSets.length - 1]){

            removeNotesOnText();

            }

            }

            }

            DealWithOversetText_SingleLine();

             

            Regards

            ashok