Какой рейтинг вас больше интересует?
|
Главная / Каталог блогов / Cтраница блогера Flash Ripper | ru - flash, flex, air, swf, flv, mpeg4, fla, ruby / Запись в блоге
Как изменить все шрифты в файле FLA2014-07-18 14:32:27 (читать в оригинале)JSFL всех нас переживет: получил благодарность в твиттере за пост 2007 года на ActionScript.org — до сих пор актуальная инструкция. Так что перевожу на русский и делюсь по новой. Задача: есть масса чужих FLA файлов с кучей анимации на таймлайне. Нужно изменить все шрифты на новые. Решение: сценарий на JSFL. Он заменяет шрифты, строит и сохраняет отчет о каждой замене. Скрипт рекурсивно обходит весь документ, пока не найдет все текстовые элементы. Для каждого текстового элемента строится его путь, создается массив текстовых элементов документа для будущего использования. Итак, в первом JSFL-файле по адресу "\Documents and Settings\[]\Local Settings\Application Data\Adobe\Flash X\en\Configuration\Commands\[FR] Replace Fonts.jsfl" происходит замена и создание отчета: var dom = fl.getDocumentDOM(); dom.editScene(0); //dom.selection = dom.getTimeline().layers[0].frames[0].elements; fl.outputPanel.clear(); fl.trace("********************************************************************"); fl.trace(" START OF FONT REPLACEMENT REPORT\n"); fl.trace(" FONT REPLACEMENT UTILITY"); fl.trace(" v 1.0.2"); fl.trace(" Author: Rostislav Siryk"); fl.trace(" http://flash-ripper.com/"); fl.trace("********************************************************************"); fl.trace("\nFILE NAME:\t" + dom.name + ".fla"); fl.trace("FILE PATH:\t" + dom.path + "\n"); //fl.saveDocumentAs(.documents[0].path); // Font to be replaced var font_select = new Array("MyLifeSans", "MyLifeSer", "Myriad", "Myriad-Bold", "Myriad-Roman", "Frutiger 45 Light", "Frutiger 55 Roman", "Garamond Book", "ArialNarrow-Bold", "Avenir LT Std 65 Medium", "Helvetica", "Verdana", "Arial Black", "Arial Narrow", "Myriad Roman" ); var textElements = new Array(); var numTotalRuns = 0; var strOutput = ""; var fontsFound = new Array(); var strFoundFonts = ""; var numTextItemsTotal = 0; var numTextItemsReplaced = 0; var strLayerName = ""; var strItemFullPath = ""; var strItemHumanPath = ""; // Delimiters used to create element paths var strTimelinesDelimiter = ".libraryItem.timeline"; var strLayerDelimiter = ".layers"; var strFrameDelimiter = ".frames"; var strElementDelimiter = ".elements"; var BR_O = "["; var BR_C = "]"; findTextElements = function(theTimeline) { if(theTimeline && theTimeline.layers.length > 0) { var theLayers = theTimeline.layers; for(var numLayer = 0; numLayer < theLayers.length; numLayer++) { // Parse FRAMES of the LAYER var theFrames = theLayers[numLayer].frames; for(var numFrame = 0; numFrame < theFrames.length; numFrame++) { // Parse only KEY Frames. I said PARSE ONLY \KEY/ FRAMES. if (numFrame == theFrames[numFrame].startFrame) { // Parse ELEMENTS of the KEYFRAME var theElements = theFrames[numFrame].elements; for(var numElement=0; numElement < theElements.length; numElement++) { numTotalRuns ++; var foundElement = theElements[numElement]; // if element is not text but instance if(foundElement.elementType == "instance") { // Add LAYER to the item full path strItemFullPath += strLayerDelimiter + BR_O + numLayer + BR_C; strLayerName = "." + theLayers[numLayer].name; strItemHumanPath += strLayerName; // Add FRAME, ELEMENT and TIMELINE to the item full path strItemFullPath += strFrameDelimiter + BR_O + numFrame + BR_C + strElementDelimiter + BR_O + numElement + BR_C + strTimelinesDelimiter; strItemHumanPath += "[fr" + numFrame + "]" + (foundElement.name || "(unnamed)"); findTextElements(foundElement.libraryItem.timeline); } else if (foundElement.elementType == "text") { // Add LAYER to the item full path strItemFullPath += strLayerDelimiter + BR_O + numLayer + BR_C; strLayerName = "." + theLayers[numLayer].name; strItemHumanPath += strLayerName; // Add FRAME and ELEMENT to the full path and FINALIZE path strItemFullPath += strFrameDelimiter + BR_O + numFrame + BR_C + strElementDelimiter + BR_O + numElement + BR_C; strItemHumanPath += "[fr" + numFrame + "]" + (foundElement.name || "(unnamed)"); textElements.push({theElement: foundElement, itemID: numTextItemsTotal, itemPath: strItemFullPath, itemHumanPath: strItemHumanPath }); // Reset the paths for the next iteration strItemFullPath = "";//strLayerDelimiter + BR_O + numLayer + BR_C; strItemHumanPath = ""; numTextItemsTotal++; /* numElement = theElements.length; numFrame = theFrames.length; numLayer = theLayers.length; break;*/ } } } else { // NO KEYFRAME ACTION } } } } } /*for(var i=0; i < dom.library.items.length; i++) { fl.trace("LIBITITEM."); findTextElements(dom.library.items[i].timeline) }*/ function enumerateAllTextElements() { for(var numTe = 0; numTe < textElements.length; numTe++) { var te = textElements[numTe]; strOutput += "\n\tTEXT #" + te.itemID + "\n\tFont:\t" + te.theElement.getTextAttr("face") + "\n\tPath:\t" + te.itemPath //+ "\n\tSeek:\t" + te.itemHumanPath + "\n\tText:\t" + te.theElement.getTextString() + "\n"; } } function replaceAllFonts() { for(i=0; i < font_select.length; i++) { font_replaced = font_select[i]; font_replacement = "Arial"; if(font_replaced == "Garamond Book") { font_replacement = "Times New Roman"; } for(var te = 0; te < textElements.length; te++) { replaceFont(textElements[te]); } } } function replaceFont(objText) { var textElement = objText.theElement; //fl.trace("TE= " + textElement.theElement); if(textElement.getTextAttr("face")) { var oldFont = textElement.getTextAttr("face"); var oldSize = textElement.getTextAttr("size"); var txt = textElement.getTextString(); addFoundFont(oldFont); if(oldFont == font_replaced) { numTextItemsReplaced++; textElement.setTextAttr("face", font_replacement); var strSizeChange = ""; if(!isNaN(oldSize) && (oldFont == "FullLifeSans" || oldFont == "FullLifeSer")) { newSize = oldSize * 0.85 || Math.floor(oldSize * 0.85); textElement.setTextAttr("size", newSize); strSizeChange = "\n\tOLD Size:\t" + oldSize + "\n\tNEW Size:\t" + newSize; } strOutput += "\n\tREPLACE #" + objText.itemID + "\n\tOLD Font:\t" + oldFont + "\n\tNEW Font:\t" + font_replacement + strSizeChange + "\n\tPath:\t" + objText.itemPath //+ "\n\tSeek:\t" + objText.itemHumanPath + "\n\tText:\t" + txt + "\n" } else { //strOutput += "\t[NO CHANGES TO FONT]\n"; } } } function addFoundFont(fontName) { isInFontsFoundAlready = false; for(var i=0; i < fontsFound.length; i++) { if(fontsFound[i] == fontName) { isInFontsFoundAlready = true; break; } } if(!isInFontsFoundAlready) { fontsFound.push(fontName); strFoundFonts += "\n\t" + fontsFound.length + "\t" + fontName; } } /*font_replaced = "FullLifeSer"; font_replacement = "Arial";*/ findTextElements(dom.getTimeline()); strOutput += "FOUND TEXT FIELDS:\t" + numTextItemsTotal + "\n"; strOutput += "******************\n"; enumerateAllTextElements(); strOutput += "\n\nREPLACEMENTS MADE:\t" /*+ numTextItemsReplaced*/ + "\n"; strOutput += "******************\n"; replaceAllFonts(); fl.trace("TOTAL RUNS:\t" + numTotalRuns); fl.trace("ITEMS FOUND:\t" + numTextItemsTotal); fl.trace("ITEMS REPLACED:\t" + numTextItemsReplaced); fl.trace("FONTS FOUND:\t" + fontsFound.length + strFoundFonts + "\n"); fl.trace("DETAILS:"); fl.trace("********"); fl.trace("\n" + strOutput + "\n\n"); fl.trace("********************************************************************"); fl.trace(" END OF FONT REPLACEMENT REPORT"); fl.trace("********************************************************************"); // Saving created report to as file fl.outputPanel.save("file:///d|/Projects/eLearn2/reports/" + dom.name + "-report.txt"); fl.outputPanel.clear(); // NOW WRITE SOME INFO JUST ABOUT FONTS FOR STATISTICS fl.trace("\n=========================="); fl.trace("FONTS INFO FOR FILE:\t" + dom.name + ".fla"); fl.trace("FILE PATH:\t" + dom.path + "\n"); fl.trace("FONTS FOUND:\t" + fontsFound.length + strFoundFonts + "\n"); // Append font report to file fl.outputPanel.save("file:///d|/Projects/eLearn2/reports/global-font-report.txt", true); dom.publish(); dom.saveAndCompact(); dom.close(); Второй JSFL-файл управляет работой первого для процессинга нескольких FLAОн запускает первый на каждом из исходных FLA: 2. "\Documents and Settings\[]\Local Settings\Application Data\Adobe\Flash X\en\Configuration\Commands\[FR] Batch Replace Fonts.jsfl"fl.outputPanel.clear(); fl.trace("******************************************************"); fl.trace(" BATCH REPLACE FONTS IN MULTIPLE FILES"); fl.trace(" Author: Rostislav Siryk"); fl.trace(" http://flash-ripper.com/"); fl.trace("******************************************************\n"); function getDuration(tEnd, tStart) { var msecsDur = tEnd - tStart; var msecs = String(msecsDur).substr(String(msecsDur).length - 3); var secs = Math.floor(msecsDur / 1000); var mins = Math.floor(msecsDur / 60000); var hrs = Math.floor(msecsDur / 3600000); if (hrs < 10) hrs = "0" + hrs; if (mins < 10) mins = "0" + mins if (secs < 10) secs = "0" + secs; if (msecs < 10) msecs = "00" + msecs; else if (msecs < 100) msecs = "0" + msecs; return {durString: hrs + ":" + mins + ":" + secs + "." + msecs, durValue:msecsDur}; } function getTimeString(aDate) { time = aDate.getTime(); hours = aDate.getHours(); minutes = aDate.getMinutes(); seconds = aDate.getSeconds(); milliseconds = aDate.getMilliseconds(); if (minutes < 10) minutes = "0" + minutes if (seconds < 10) seconds = "0" + seconds; if (milliseconds < 10) milliseconds = "00" + milliseconds; else if (milliseconds < 100) milliseconds = "0" + milliseconds; return hours + ":" + minutes + ":" + seconds + ":" + milliseconds; } function getCurrentTime() { var dateNow = new Date(); return {timeString: getTimeString(dateNow), timeValue:time}; } var timeStart = getCurrentTime().timeString; var timeStartValue = getCurrentTime().timeValue; var numErrors = 0; scriptFile="file:///c|/Documents and Settings/rost/Local Settings/Application Data/Macromedia/Flash 8/en/Configuration/Commands/[FR] Replace Fonts.jsfl" // ADVANCED COURSE FILES LIST strPathsAdv = "file:///d|/Projects/eLearn2/Fla/sec01/s02_01_01.fla#" + "file:///d|/Projects/eLearn2/Fla/sec01/s02_01_02.fla#" + "file:///d|/Projects/eLearn2/Fla/sec01/s02_01_03.fla#" + "file:///d|/Projects/eLearn2Fla/site_files/ssecondary_4.fla#"; // BASIC COURSE FILES LIST strPathsBasic = "file:///d|/Projects/eLearn2/Fla/sec01/s01_01_01.fla#"+ "file:///d|/Projects/eLearn2/Fla/sec01/s01_01_02.fla#"+ "file:///d|/Projects/eLearn2/Fla/sec01/s01_01_03.fla#"+ "file:///d|/Projects/eLearn2/Fla/site_files/ssecondary_4.fla" fileStr = strPathsAdv + strPathsBasic; if(fileStr.length > 0 && scriptFile.length > 0) { var files = fileStr.split("#") var numFiles = files.length for(var f = 0; f < numFiles; ++f) { if(fl.fileExists(files[f])) { var tStart = getCurrentTime().timeString; var tStartValue = getCurrentTime().timeValue; fl.trace("Open File:\t" + files[f]); fl.openDocument(files[f]) fl.runScript(scriptFile) fl.trace("\tFILE COMPLETE"); fl.trace("\tSTART TIME:\t" + tStart + "\t(" + tStartValue + " msec)"); fl.trace("\tEND TIME:\t" + getCurrentTime().timeString + "\t(" + getCurrentTime().timeValue + " msec)"); fl.trace("\tDURATION:\t" + getDuration(getCurrentTime().timeValue, tStartValue).durString + "\t(" + getDuration(getCurrentTime().timeValue, tStartValue).durValue + " msec)\n"); } else { fl.trace("ERROR OPENING FILE: File doesn't exist:\t"+ files[f] + "\n"); numErrors++; } } } fl.trace("\n******************************************************"); fl.trace("FILES TOTAL:\t" + numFiles); fl.trace("ERRORS TOTAL:\t" + numErrors); fl.trace("\nSTART TIME:\t" + timeStart + "\t(" + timeStartValue + " msec)"); fl.trace("END TIME:\t" + getCurrentTime().timeString + "\t(" + getCurrentTime().timeValue + " msec)"); fl.trace("DURATION TOTAL:\t" + getDuration(getCurrentTime().timeValue, timeStartValue).durString + "\t(" + getDuration(getCurrentTime().timeValue, timeStartValue).durValue + " msec)"); fl.trace("******************************************************"); // Save report to file fl.outputPanel.save("file:///d|/Projects/eLearn2/reports/batch-font-replace-report.txt"); Когда-то JSFL стал моим первым шагом в JavaScript :) Тэги: jsfl Automation fonts FLA javascript
|
Категория «Мобильная техника»
Взлеты Топ 5
Падения Топ 5
Популярные за сутки
|
Загрузка...
взяты из открытых общедоступных источников и являются собственностью их авторов.