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

Script - font weight/thickness changes in a fluid dynamic gradient

Community Beginner ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Hello, I'm looking for a specific script that would create a fluid gradient change in thickness in a typeface, for example per line or per page? I would like to achieve the “wave”association, would anyone be so kind as share it with me? I know it exists since I used to have it. 

TOPICS
Scripting , Type

Views

398

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

correct answers 1 Correct answer

Community Expert , Feb 21, 2022 Feb 21, 2022

By gradient do you mean a change in font weight (not color)?

 

Variable font weights can be scripted. This example changes the weight and width axes of a line of selected text set in Acumin Variable Concept:

 

 

 

app.selection[0].appliedFont = "Acumin Variable Concept	Regular"
var selectedText = app.selection[0].characters;
var t = selectedText[0];

var myDesignAxesName = t.appliedFont.designAxesName;
var myDesignAxesRange = t.appliedFont.designAxesRange;
var myDesignAxesValues = t.appliedFont.
...

Votes

Translate

Translate
Community Expert ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Can you create an example and post a screen capture?

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

My first thought is that this is something better/more easily accomplished in lllustrator. It would be a meticulous line-by-line tweak in ID, with the text wanting to reflow as it was expanded.

 


╟ Word & InDesign to Kindle & EPUB: a Guide to Pro Results (Amazon) ╢

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

By gradient do you mean a change in font weight (not color)?

 

Variable font weights can be scripted. This example changes the weight and width axes of a line of selected text set in Acumin Variable Concept:

 

 

 

app.selection[0].appliedFont = "Acumin Variable Concept	Regular"
var selectedText = app.selection[0].characters;
var t = selectedText[0];

var myDesignAxesName = t.appliedFont.designAxesName;
var myDesignAxesRange = t.appliedFont.designAxesRange;
var myDesignAxesValues = t.appliedFont.designAxesValues;
var wrange = myDesignAxesRange[0];
var w0 = wrange[0];
var w1 = wrange[1];
var wstep = (w1-w0)/selectedText.length;
var crange = myDesignAxesRange[1];
var c0 = crange[0];
var c1 = crange[1];
var cstep = (c1-c0)/selectedText.length;

for (s=0; s<selectedText.length; s++){
    myDesignAxesValues[0]=(w0+wstep*s);
    myDesignAxesValues[1]=(c0+cstep*s);
    selectedText[s].designAxes=myDesignAxesValues;
}

 

 

 

A line of text set with Acumin Variable:

 

Screen Shot 7.png

 

Screen Shot 6.png

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 Beginner ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Just saw the answer now, thank you so much for sharing! Super cool 

 

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 Beginner ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Im wondering if there is something similar for normal fonts as well

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Normal fonts don’t typically have enough weight variations to create the gradation effect. Size and leading adjustments can be scripted. This blends point size and leading:

 

 

 

//an ease amount for the blend—a number between .1 and .9
var ease = .8

//visual line space (not leading)
var vs = 2

//the selected text
var sel = app.activeDocument.selection[0];
var sl = sel.lines

//blend the selected text
blendLines(sel, ease, vs);

//adjust for reflows
for (var i = 0; i < sl.length; i++){
    if (sl[i].characters[0].pointSize != sl[i].characters[-1].pointSize) {
        blendLines(sel, ease, vs);
    } 
};   

/**
* Blends point size and leading 
*  the selected text 
*  an ease amount number between .1 and .9 
*  visual space between lines 
*  void 
* 
*/
function blendLines(s, e, vs){
    var doc = app.activeDocument;
    var oPL = doc.textPreferences.useParagraphLeading;
    doc.textPreferences.useParagraphLeading = false;
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    
    if (e > .9) {
        e=.9
    } else if (e < .1) {
        e=.1
    }
    
    var x = s.lines;
    var psize = x[0].pointSize;
    var c = x.length;
    var pp = (1/c)*psize;

    for (var i = 1; i < x.length; i++){
        x[i].pointSize = psize - ((pp * i) * e)
    };

    for (var j = 1; j < x.length; j++){
        var d = x[j-1].descent;
        var a = x[j].ascent;
        x[j].leading = d+a+vs;
    };  

    doc.textPreferences.useParagraphLeading = oPL;
};

 

 

Screen Shot 17.png

 

Screen Shot 16.png

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 Beginner ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

Many thanks Rob!

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 Beginner ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

Hi @rob day thank you for providing this script. I do have a question: is it possible to limit the reduction of the font size, for example to min. of 10 Pt. Could you change that in the script?
Could you explain to me how the code works?
I see that the quotient changes depending on how many lines I apply the script to...But I didn't quite understand it unfortunately. 🙂 Thank you so much. 

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 ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

Hi @piac77508919 I don’t see a way to easily blend the lines to an exact 10 pt last line —there is so much reflow that the number of blended lines isn’t predictable. I can add a blend amount variable, which gives you some control over the difference between the first and last line’s point size.

 

Lower the blend amount number to decrease the change from the first to last line

 

 

 

//an ease amount for the blend—a number between .1 and .9
var ease = .8

//visual line space (not leading)
var vs = 2

//the blend amount. Higher number increases the difference between the first and last line 
var ba = 7

//the selected text
var sel = app.activeDocument.selection[0];
var sl = sel.lines

//blend the selected text
blendLines(sel, ease, vs, ba);

//adjust for reflows
for (var i = 0; i < sl.length; i++){
    if (sl[i].characters[0].pointSize != sl[i].characters[-1].pointSize) {
        blendLines(sel, ease, vs, ba);
    } 
};   


/**
* Blends point size and leading 
* @ selected text 
* @ an ease amount number between .1 and .9 
* @ visual space between lines 
* @ the amount to blend 
* @ return void 
*/

function blendLines(s, e, vs, ba){
    var doc = app.activeDocument;
    var oPL = doc.textPreferences.useParagraphLeading;
    doc.textPreferences.useParagraphLeading = false;
    app.scriptPreferences.measurementUnit = MeasurementUnits.POINTS;
    
    if (e > .9) {
        e=.9
    } else if (e < .1) {
        e=.1
    }
    
    var x = s.lines;
    var psize = x[0].pointSize;
    var pp = ba/psize;

    for (var i = 1; i < x.length; i++){
        x[i].pointSize = psize - ((pp * i) * e)
        
    };

    for (var j = 1; j < x.length; j++){
        var d = x[j-1].descent;
        var a = x[j].ascent;
        x[j].leading = d+a+vs;
    };  

    doc.textPreferences.useParagraphLeading = oPL;
};

 

 

 

 

 

 

 

 

Screen Shot 6.png

 

 

 

Screen Shot 5.png

 

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 Beginner ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

@rob day thanks so much, that's really helpful and looks much better now. I have another question regarding the line spacing: for example, if I apply the script to a text, with 18 pt font size and 21 pt line spacing, the line spacing decreases proportionally significantly from line 2 onwards and it becomes much narrower...is there anything that can be done? I would be interested in two different solutions: A) the ratio of the line spacing of the text field is applied to all lines or B) the line spacing always remains the same.
At the moment, the line spacing does not decrease with the font size but is sometimes larger again in between when a new paragraph comes afterwards. 

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 ,
Apr 06, 2022 Apr 06, 2022

Copy link to clipboard

Copied

LATEST

I’m not seeing that problem here. Just to be clear the line spacing variable is the visual space between the lines—not actual leading. So these variable settings:

 

 

//an ease amount for the blend—a number between .1 and .9
var ease = .8

//visual line space (not leading)
var vs = 22

//the blend amount. Higher number increases the difference between the first and last line 
var ba = 20

 

 

Gives me this:

Screen Shot 8.png

 

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