Participating Frequently
January 27, 2024
Answered
Performance problem with variable font script
- January 27, 2024
- 5 replies
- 2375 views
Hey there, I've been playing around with variable fonts and extend script and wrote a script that makes each character in a text block slowly go from sans to serif, I have attached the result as a screenshot. This works fine in theory but I have found that the processing time scales up exponentially. So 20 characters take 1,4 seconds to process while 120 characters already take 1 minute to process. My inital goal was to do this on whole pages or even on books and I understand that this is gonna take some time but it seems weird that its gonna increase drastically with more characters
This is my code so far:
app.scriptPreferences.enableRedraw = false;
app.doScript(variable_transition, ScriptLanguage.javascript, undefined, UndoModes.FAST_ENTIRE_SCRIPT, "Script Action");
app.scriptPreferences.enableRedraw = true;
function variable_transition() {
var doc = app.activeDocument;
var text = doc.textFrames.item(0).characters;
for (var x = 0; x < text.length; x++) {
text.item(x).setNthDesignAxis(2, map_range(x, 0, text.length, 0, 1));
}
function map_range(value, low1, high1, low2, high2) {
return low2 + (high2 - low2) * (value - low1) / (high1 - low1);
}
}
Any help on this would be greatly appreciated


