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

Another JSXBIN question.

Advisor ,
Jun 30, 2016 Jun 30, 2016

Hi all. 

I have a Fit text to Frame script that works great.  However it adjusts the Fonts by .001 increments is there a way to change this to .02?  I know JSXBIN files cannot be edited but can another script running the Bin file override the font size?

TOPICS
Scripting
1.3K
Translate
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

correct answers 1 Correct answer

Guide , Jul 04, 2016 Jul 04, 2016

Hi Oleh,

Sorry, my mistake.

Two changes must be done to use my code:

1. Use 'pointSize' instead of 'horizontalScale' in parameter.

2. Remove the 1 != s.lines.length condition in the wrong() function (in the original script we had to handle single-line frames.)

The final snippet looks like

(function(/*Item[]*/a,/*str*/k,/*uint*/MIN,/*uint*/MAX, /*num*/PRECISION) 

    var t, s, v, w, m = [], 

        wrong = function(){ return +t.overflows };

    while( t=a.pop() ) 

    { 

        if( 'TextFrame'!=t._

...
Translate
Engaged ,
Jun 30, 2016 Jun 30, 2016

Are you talking about script from in-tools?

Try to contact a script author and ask if he can help...

Translate
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
Advisor ,
Jun 30, 2016 Jun 30, 2016

I'll contact the author.  I don't want to infringe on his/her work.  Thank you..  and yes this is from in-tools.  Its a great script. 

Translate
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
Engaged ,
Jun 30, 2016 Jun 30, 2016

here's my version, but it requires testing

//DESCRIPTION: Fit each text line to the frame width

/*

    Oleh Melnyk <oleh.melnyk[at]gmail.com>

    30 June 2016

    alpha v.0.1

*/

#target:indesign;

app.doScript(doUndoWrapper, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Fit text");

function doUndoWrapper()

{

    var pointStep = 2; // pt   

    if(app.selection[0] && app.selection[0].hasOwnProperty("parentStory")){   

        var text = app.selection[0].parentStory;

               

        if(text.contents.length == 0){

            exit(alert("Empty text frame selected!", "Error", 1));

        }else{

            // replace space to fixed width space (\u202F).

            // But since fixed width space is non-breakable - we add discretionary line break (\u200B) before and after

            text.contents = text.contents.replace(/ /g, "\u200B\u202F\u200B");           

        }

       

        app.selection[0].textFramePreferences.firstBaselineOffset = FirstBaseline.CAP_HEIGHT;

        app.selection[0].textFramePreferences.verticalJustification = VerticalJustification.JUSTIFY_ALIGN;

       

        text.hyphenation = false;

        text.justification = Justification.FULLY_JUSTIFIED;       

        var lines = app.selection[0].parentStory.lines.length;

        for(var i = 0; i < lines; i++){

            // increasing text size till it break to the next line

            while(app.selection[0].parentStory.lines.length == lines){

               app.selection[0].parentStory.lines.pointSize += pointStep;

            };

            // roll back (to the last acceptable text size)

            app.selection[0].parentStory.lines.pointSize -= pointStep;

        }

   

        app.selection[0].fit(FitOptions.frameToContent);

    }else{

        exit(alert("Select text frame first!", "Error", 1));

    }

}

Translate
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
Guide ,
Jul 04, 2016 Jul 04, 2016

A generic fit-text-to-frame is reviewed here:

Indiscripts :: InDesign Scripting Forum Roundup #8

It is fast and flexible. Any text property can be made adjustable.

@+

Marc

Translate
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
Engaged ,
Jul 04, 2016 Jul 04, 2016

Hi Mark,

The link you provided is pointed to HORIZONTAL TEXT SCALE and here we are looking for text size change (fit text to frame), not horizontal text scale...

And your script seems not working, or I'm doing something wrong - nothing changes, and there are no errors

Translate
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
Guide ,
Jul 04, 2016 Jul 04, 2016

Hi Oleh,

Sorry, my mistake.

Two changes must be done to use my code:

1. Use 'pointSize' instead of 'horizontalScale' in parameter.

2. Remove the 1 != s.lines.length condition in the wrong() function (in the original script we had to handle single-line frames.)

The final snippet looks like

(function(/*Item[]*/a,/*str*/k,/*uint*/MIN,/*uint*/MAX, /*num*/PRECISION) 

    var t, s, v, w, m = [], 

        wrong = function(){ return +t.overflows };

    while( t=a.pop() ) 

    { 

        if( 'TextFrame'!=t.__class__ ) continue; 

 

        // Init 

        // --- 

        v = (s=t.parentStory)

        m[0] = MIN; 

        m[1] = MAX; 

 

        // Try extremum and quit if status doesn't change 

        // --- 

        s = m[1-(w=wrong())]; 

        if( w==wrong() ){ s=v; continue; } 

 

        // Binary search 

        // --- 

        while( m[1]-m[0] > PRECISION ){ m[w=wrong()] = s = (m[0]+m[1])/2; } 

        w && (s = m[0]); 

    } 

     

})(app.properties.selection||[], 'pointSize', 6, 36, .1);

Does it work better?

@+

Marc

Translate
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
Engaged ,
Jul 04, 2016 Jul 04, 2016
LATEST

Mark, your script works now, but not at the expected way (for me). Seems your script just increase font size to fill the frame with text.

And, personally, I expected to increase each line of text to the frame width, like in a screenshot below...

img-2016-07-04-17-16-28.png

I think that's what Fit text to frame should do. But looks like your script just do what topic starter was looking for - let's wait and see

Translate
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