//TextRytm. /*This tool has been created within a workshop week in ECAL,Lausanne Vincent Delaleu, Guillaume Chabot, Hugo Hoppman, Olga Prader. Jonathan Puckey & Jürg Lehni. */ // Define the default values, to be passed to the // new Palette() constructor var values = { font: 'Helvetica Regular',//app.fonts[0][0].toString(); font2: 'Arial Regular',//app.fonts[0][0].toString(); fontStrectch:false, verticalscale:100, verticalscale2:100, horizontalscale:100, horizontalscale2:100, growing: 0, grotate:0, beginletter:0, type: 'letter', randomfont :false, fontHr:false, fontSi: false, fontGr: false, firstfont: 10, highfont: 10, hfirstfont:0, hhighfont: 0, rotate:0, }; var fontLookup = { // Empty Object to be filled with font name -> weight lookup entries }; // Define the palette items var div = ''; var items = { //Choose fonts font: { type: 'list', label: 'Even Font ', options: getFonts() }, font2: { type: 'list', label: 'Odd fond ', options: getFonts() }, //Random Fonts randomfont: { type:'checkbox', label:'Randomize fonts', }, //Choose Selection type: { type: 'list', label: 'Type', options: ['word', 'letter', 'select letter','select word'] }, //Stretch fontStrectch:{ type:'checkbox', label:'Strecth', }, verticalscale: { type: 'number', label: 'Odd y stretch', range: [-600, 600], units: 'percent' }, verticalscale2: { type: 'number', label: 'Even y stretch', range: [-600, 600], units:'percent', onChange: function() { modifChar(); } }, horizontalscale: { type: 'number', label: 'Odd x stretch', range: [-600, 600], units: 'percent' }, horizontalscale2: { type: 'number', label: 'Even x strech', range: [-600, 600], units:'percent', onChange: function() { modifChar(); } }, // Growing Type fontSi: { type:'checkbox', label:'Font growing' }, beginletter: { type:'number', label:'First letter size', range: [0, 48], units:'point', }, growing: { type: 'number', label: 'Grow by', range: [-100, 100], units:'percent', onChange: function() { modifChar(); } }, // Vertical Wave (using type point) fontGr: { type:'checkbox', label:'Use vertical wave ', }, firstfont:{ type:'number', label:'Wave low point ', range: [0, 48], units:'point', }, highfont:{ type:'number', label:'Wave high point ', range: [0, 120], units:'point', }, // Horizontal Wave (using horizontal stretch) fontHr: { type:'checkbox', label:'Use horizontal wave ', }, hfirstfont:{ type:'number', label:'Wave low stetch ', range: [-10,10], units:'point', }, hhighfont:{ type:'number', label:'Wave high stretch ', range: [-10, 10], units:'point', }, // Rotation rotate: { type: 'slider', label: 'Rotate letters', range: [0, 360], onChange: function() { modifChar(); }, }, // Growing Rotation growR: { type:'checkbox', label:'Growing rotation', }, grotate: { type: 'number', label: 'Grow by', range: [-100, 100], units:'percent', onChange: function() { modifChar(); } }, // Apply Button create: { type: 'button', value: 'Apply', onClick: function() { if (document.selectedItems.length > 0){ modifChar(); } else if (document.selectedItems.length == 0) { print("no text selected, click on a text box to act on the text."); } } } } // Now create the palette window var palette = new Palette('TextRythm Palette', items, values); function modifChar() { var textItem = document.selectedItems[0]; // We use similar functionality as in the previous // example, with the added randomized center point. // var characters = textItem.range; var characters = values.type; //print(characters); if (characters == 'word') { characters =textItem.range.words; } else if (characters == 'letter') { characters =textItem.range.characters; } else if (characters == 'select letter') { characters = textItem.selection.characters; } else if (characters == 'select word') { characters = textItem.selection.words; } var font = getFontByName(values.font); var font2 = getFontByName(values.font2); var j = values.firstfont; var countUp = true; var e = values.hfirstfont/100; var TestUp = true; for (var i = 0; i < characters.length; i++) { var deci=i*values.growing/100; if (countUp) { j +=1; } else { j -= 1; } if (j > values.highfont) { countUp = false; } else if (j <= values.firstfont) { countUp = true; } if (TestUp) { e += 1; } else { e-= 1; } if (e > values.hhighfont) { TestUp = false; } else if (e < values.hfirstfont) { TestUp = true; } var charRange = characters[i]; charRange.characterStyle.autoLeading = true; //charRange.characterStyle.leading = 20; var randomIndex = Math.floor(Math.random() * app.fonts.length); var myFont = app.fonts[randomIndex]; if((i).isOdd()) { myFont = app.fonts[i]; } var fontchoice = font if((i).isOdd()) { fontchoice = font2; } var verticalScale = values.verticalscale; if (i.isOdd()) { verticalScale = values.verticalscale2; } var horizontalScale = values.horizontalscale; var beginfont=values.beginletter; if (i.isOdd()) { horizontalScale = values.horizontalscale2; } if (values.fontSi) { charRange.characterStyle.fontSize = beginfont+deci; } if (values.fontGr) { charRange.characterStyle.fontSize = j; } if(values.fontHr){ charRange.characterStyle.horizontalScale =e; } if(values.fontStrectch){ charRange.characterStyle.verticalScale = verticalScale/100; charRange.characterStyle.horizontalScale = horizontalScale/100; } if(values.randomfont){ charRange.characterStyle.font =myFont; }else{ charRange.characterStyle.font =fontchoice; } var growrotate=i+values.grotate/100; var rotation=values.rotate; charRange.characterStyle.rotation = rotation; //.toRadians(); if(values.growR){ charRange.characterStyle.rotation = growrotate; } } } function setKerning(range, kerning) { var characters = range.characters; for (var i = 0; i < characters.length; i++) { var charRange = characters[i]; charRange.kerning = kerning; } } function getFonts() { var fonts = []; for (var i = 0; i < app.fonts.length; i++) { var font = app.fonts[i]; for (var j = 0; j < font.length; j++) { var weight = font[j]; var name = weight.toString(); fonts.push(name); fontLookup[name] = weight; } } return fonts; } function getFontByName(name) { return fontLookup[name]; }