The document contains code to replace fonts and unicode glyphs in Illustrator documents. It loops through all text frames and characters, checks if the current font matches one in the change list, and if so replaces the font and any unicode glyphs specified in the change list. It handles unicode conversion and uses a placeholder character to avoid issues replacing glyphs in mismatched fonts. The code performs find and replace operations on the character contents and font to implement the changes specified in the change lists.
The document contains code to replace fonts and unicode glyphs in Illustrator documents. It loops through all text frames and characters, checks if the current font matches one in the change list, and if so replaces the font and any unicode glyphs specified in the change list. It handles unicode conversion and uses a placeholder character to avoid issues replacing glyphs in mismatched fonts. The code performs find and replace operations on the character contents and font to implement the changes specified in the change lists.
The document contains code to replace fonts and unicode glyphs in Illustrator documents. It loops through all text frames and characters, checks if the current font matches one in the change list, and if so replaces the font and any unicode glyphs specified in the change list. It handles unicode conversion and uses a placeholder character to avoid issues replacing glyphs in mismatched fonts. The code performs find and replace operations on the character contents and font to implement the changes specified in the change lists.
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 {} } } } } } }