You are on page 1of 2

#target illustrator

if (app.documents.length > 0) {

var docRef = app.activeDocument;


var allTextFrames = docRef.textFrames;
var splittedRows = [
['AriaLmT','PolOcEF-Regular'],
['MyriaDpro-Regular','AriAl-BoldMT'],
['BeMbo','PolOCEF-Regular','U+1234','U+4321'],
['PoloSt11K-Buch','PoloCEF-REgular','U+666','U+876']
];
var autoSubList = ['ArialMT','PoloST11K-Buch','Bembo'];

changeFontAndGlyphs();

// replace unicode glyphs based on changelist


function changeFontAndGlyphs() {
for (var i=0 ; i<allTextFrames.length; i++) {
var allCharacters = allTextFrames[i].characters;
for (var t=0; t<allCharacters.length; t++) {
var charFontName = allCharacters[t].textFont.name;
var thisChar = allCharacters[t];

for (var c=0; c<splittedRows.length; c++) {


var thisCLFont = splittedRows[c][0];
var newCLFont = splittedRows[c][1];

for (var a=0; a<autoSubList.length; a++) {


var thisASLFont = autoSubList[a];

if (thisASLFont.toUpperCase() == thisCLFont.toUpperCase() && charFontName.toUpperCase()


== thisCLFont.toUpperCase()) {
// if AutoSubList font is on changeListFont && character font has same name as changeListFont
thisChar.textFont = app.textFonts.getByName(newCLFont); //change character font to new
changeList font
if (splittedRows[c].length > 2) { // changelist row >2 ==> has Glyphs to change
var thisGlyph = splittedRows[c][2];
var thisSubGlyph = splittedRows[c][3];
thisSplitArray = thisGlyph.split('\+');
thisSplitArray.shift(); //remove first array element
thisSubSplitArray = thisSubGlyph.split('\+');
thisSubSplitArray.shift(); //remove first array element
thisUcode = String.fromCharCode(parseInt(thisSplitArray,16)); //parse value to string
newUcode = String.fromCharCode(parseInt(thisSubSplitArray,16)); //parse value to string
fakeCode = "xxx"; //to avoid issues with unknown unicode characters replace with common

thisChar.contents = thisChar.contents.replace( thisUcode, fakeCode );//to avoid issues with


unknown unicode characters in different fonts replace with common
thisChar.textFont = app.textFonts.getByName(newCLFont);//change font a second time
thisChar.contents = thisChar.contents.replace( fakeCode, newUcode );//change to new unicode
} else {}
} else {}
}
}
}
}
}
}

You might also like