Dégradé approche texte

New Here ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

Bonjour,

 

Je cherche une solution pour réaliser des textes sur une affiche avec une approche du texte en dégradé, sans se casser la tête... (voir image jointe)

 

Jusqu'à présent, j'effectuais la manip en y insérant des espaces, mais ça prend un peu de temps.. Il y aurait-il une fonction qui permettrait de réaliser ceci?

 

Merci pour votre aide!

 

Meilleures salutations,

SimonBildschirmfoto 2021-04-06 um 20.58.23.png

TOPICS
Draw and design, How to, Scripting, Tools

Views

122

Likes

translate

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
Enthusiast ,
Apr 06, 2021 Apr 06, 2021

Copy link to clipboard

Copied

This is a basic idea

var string1 = selection[0].contents.replace(/ /g, "          ");
selection[0].contents = string1;
var paragraphz = selection[0].paragraphs;
for (var i = 0; i < paragraphz.length; i++) {
    var wordz = paragraphz[i].words;
    for (var j = 0; j < wordz.length; j++) {
        var characterz = wordz[j].characters;
        for (var k = 0, l = characterz.length - 1; l > 0; k += 1 + l, l--) {
            for (var n = 0; n < l; n++) {
                characterz.add(" ", characterz[k]);
            }
        }
    }
}

Untitled.png

Likes

translate

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
Engaged ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Here's my version, using tracking. It can do left- and right- justified text. It's a bit messy and have only tested on basic text frames but hopefully gives you something else to try, as well as femkeblanco's script. Note: after applying the tracking, you can copy the text out and into another shape text frame to achieve the curve in your example.

 

// these are just examples that modify the tracking you can make your own or change these
var exampleAdjustment1 = function (n) { return n + 30 };
var exampleAdjustment2 = function (n) { return (n + 10) * 1.1 };


// call the spaceOut function on the selected item (must be a TextFrame)
spaceOut(selection[0], exampleAdjustment1);



function spaceOut(txtFrame, adjustment, baseTrackAmount) {
    if (!txtFrame) return false;
    if (txtFrame.typename != 'TextFrame') throw 'spaceOut requires TextFrame item';
    txtFrame.textRanges[0].paragraphAttributes.hyphenate = false;
    if (baseTrackAmount == undefined) baseTrackAmount = 0;

    // make an array of lines, containing an array of characters
    var _lines = [];
    for (var i = txtFrame.story.lines.length - 1; i >= 0; i--) {
        // first add line break after the line so it doesn't wrap
        txtFrame.story.lines[i].contents += '\n';

        _lines[i] = [];
        for (var j = 0; j < txtFrame.story.lines[i].characters.length; j++) {
            _lines[i][j] = txtFrame.story.lines[i].characters[j];
        }
    }

    // get font size, used for calculating text box width expansion
    var fontSize = _lines[0][0].characterAttributes.size;

    // get justification
    var isJustifiedLeft = txtFrame.paragraphs[0].paragraphAttributes.justification == Justification.LEFT;

    var start, end, step;
    var longestLineAddedSpace = 0;
    // loop over lines
    for (var i = 0; i < _lines.length; i++) {
        var trackAmount = baseTrackAmount, total = 0;

        // these determine the looping order
        if (isJustifiedLeft) {
            start = 0, end = _lines[i].length, step = 1;
        } else {
            // right justified, start at last character, going backwards
            start = _lines[i].length, end = 0, step = -1;
        }

        // loop over characters
        for (var j = start; j != end; j += step) {
            var ch = _lines[i][j];
            if (!ch) continue; // empty line
            if (ch.length > 1) ch = ch.characters[ch.length - 1]; // had to do this due to unexpected value of j=0, but don't know why!

            // apply tracking
            ch.tracking = trackAmount;

            // keep record of running total for this line
            total += trackAmount;

            // update track amount according to function
            trackAmount = adjustment(trackAmount);
        }
        longestLineAddedSpace = Math.max(longestLineAddedSpace, total)
    }

    // adjust width of text box to accommodate added space
    try {
        addedSpaceInPts = (longestLineAddedSpace / 1000) * fontSize;
        txtFrame.textPath.width += addedSpaceInPts;
        if (!isJustifiedLeft) txtFrame.textPath.left -= addedSpaceInPts;
    } catch (error) {
        $.writeln(error);
    }
}

Likes

translate

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
Enthusiast ,
Apr 08, 2021 Apr 08, 2021

Copy link to clipboard

Copied

Very nice.

Likes

translate

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