Skip to main content
New Participant
March 3, 2020
Answered

variable font progression

  • March 3, 2020
  • 2 replies
  • 2699 views

Hi all

 

For a school project I need to make a variable font start off in one weight, and then have it gradually transition into another weight as the text progresses. 

 

Kind of like this:

[light] the quick brown fox [somewhere around regular] jumps over the lazy dog [bold]

 

Any idea how i might pull this off in inDesign?

 

Thanks!

This topic has been closed for replies.
Correct answer rob day

Looks like that would override all the master page items. If you are OK with that, you can do it via the UI by selecting all the pages in the Pages panel and select override master page items from the Pages fly out menu.

 

Limiting the overrides to the auto page numbers could be scripted.


This would override master page text frames containing an auto number. Note that if the page number is not on its own layer its stacking order might change.

 

//an array ids for masterpage textframes containing auto page numbers
var nid = getPageNumberID("^#")
 
var p = app.documents[0].pages.everyItem().getElements();
var mpi;
for (var i = 0; i < p.length; i++){
    mpi = p[i].masterPageItems;
    for (var j = 0; j < mpi.length; j++){
        if (mpi[j].constructor.name == "TextFrame" ) {
            if (checkItem(nid, mpi[j].id)) {
                mpi[j].override(p[i])
            } 
        } 
    }
};   

/**
* Gets the ID of the found text’s parent frame 
* @ param text to search for 
* @ return an array of text franme ids
*/
function getPageNumberID(fp){
    app.findTextPreferences = app.changeTextPreferences = app.findChangeTextOptions = null;
    app.findChangeTextOptions.properties = { 
        includeMasterPages:true} 
    app.findTextPreferences.findWhat = fp;
    var res = app.activeDocument.findText()
    var ids=[]
    for (var i = 0; i < res.length; i++){
        ids.push(res[i].parentTextFrames[0].id)
    };   
    return ids
}

/**
* Checks if an item is in an array
* @ param the array to check 
* @ param the item to look for 
* @ return true if the item is in the array 
* 
*/
function checkItem(a, obj) {
    for (var i = 0; i < a.length; i++) {
        if (a[i] === obj) {
            return true;
        }
    }
    return false;
}

 

2 replies

Community Expert
April 20, 2023

a very strange thing is happening where the page item textframe is being shifted, in the master page the page item is outside of the margin, when it is overriden, it is moved to the bottom of the text frame

 

This problem is usually caused when a document's page size was changed in the Document Setup window. The document's page coordinates differ from those of the master pages. It could be fixed but you'd have to export the document to IDML, fix the relevant XML file, and rezip the file to create an IDML, then open that in InDesign. Doing what Rob did is probably easier. The problem does not occur (allegedly, never tried) when you resize a document's page size using the Page tool (in the Tools bar).

 

P.

 

TypograafAuthor
New Participant
March 3, 2020

I found this online, however i can't seem to get it to work. My font goes from light to bold on a single axis.

 

if (app.documents.length == 0)
{
alert (“No open documents!”);
exit ();
}
selectedText =app.selection[0].characters;
t=selectedText[0];
myDesignAxesName=t.appliedFont.designAxesName;
myDesignAxesRange=t.appliedFont.designAxesRange;
myDesignAxesValues=t.appliedFont.designAxesValues;
range=myDesignAxesRange[0];
w0=range[0];
w1=range[1];
stepping=(w1-w0)/selectedText.length;
for (s=0; s<selectedText.length; s++)
{
myDesignAxesValues[0]=(w0+stepping*s);
selectedText[s].designAxes=myDesignAxesValues;
}
alert(“Done”);

 

 

rob day
Community Expert
March 3, 2020

The script only has variables set up for the weight axis. If you want both weight and width try this:

 

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;
}

 

Participating Frequently
October 30, 2020

Hi. I'm really interested in this script too. I'm trying to use it on ED Garamond Regular, a variable font from google fonts. When I run Rob's amended script I get an error, see screenshot attached. I'm a real novice with scripts, but is that because EB Garamond only has one variable axis - weight, from 400 to 800? If so, what bit of the script do I need to change to get it to work?

Thanks!