//////////////////////////////////////////////////////////////////////////// // ADOBE SYSTEMS INCORPORATED // Copyright 2010 Adobe Systems Incorporated // All Rights Reserved // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the // terms of the Adobe license agreement accompanying it. If you have received this file from a // source other than Adobe, then your use, modification, or distribution of it requires the prior // written permission of Adobe. // Adobe Photoshop QE / DI Pro Tools Team // Email: PS-External-Bugs-Tools@adobe.com // Script File: FontTest.jsx // Script Dev: Kaori Mikawa // Script QE: Kyoko Itoda // HOW TO USE THIS SCRIPT // 1. Place FontTest.jsx file into the following directories: // Win: C:\Program Files\Adobe\Adobe Photoshop CS5\Presets\Scripts\... // Mac: Applications\Adobe Photoshop CS5\Presets\Scripts\... // 2. Launch Photoshop. // 3. Go to Help->Font Testc to run Font Test Script. ///////////////////////////////////////////////////////////////////////////// /* Font Test... help */ #target photoshop; try{ app.bringToFront(); app.displayDialogs = DialogModes.NO; var logPath = "~/Photoshop/FontTest/log/"; var logPathFolder = new Folder (logPath); var logFilePref = new File(logPath + "FontTestPref.log"); var logFileFontTest = new File (logPath + "FontTest.log"); var logFileFontTestDetail = new File (logPath + "FontTestDetail.log"); var myPref = [ ["RulerUnits","Units.INCHES"] , ["TypeUnits","TypeUnits.POINTS"], ["FontPreview","FontPreviewType.MEDIUM"],["MissingGlyphProtection","true"] ]; myPref[0][1] = app.preferences.rulerUnits; myPref[1][1] = app.preferences.typeUnits; myPref[3][1] = getPrefTypeMissingGlyphProtection(); try{ myPref[2][1] = app.preferences.fontPreviewSize; }catch(e){ myPref[2][1] = FontPreviewType.LARGE; } writeState(logFilePref,myPref); var prefMsg = ""; if(!checkPref()){ alert("The script needs to set your units and type preferences in order to run correctly. These will be reverted back to the original state once the script is completed.","Font Test - Preference Setting"); try{ if(app.preferences.fontPreviewSize != FontPreviewType.NONE){ prefMsg += " - Changed Font Preview from "+ app.preferences.fontPreviewSize + " to " + FontPreviewType.NONE +"\n"; } }catch(e){ prefMsg += " - Changed Font Preview to " + FontPreviewType.NONE +"\n"; } try{ app.preferences.fontPreviewSize = FontPreviewType.NONE; }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } setPref(); } $.localize = true; // Enable ZString localiation var errorToQuit = 0; var ui; // dialog resource object var win; var sStartButton = "Start"; var sCacelButton = "Cancel"; var sOKButton = "OK"; var installedFonts = app.fonts; var installedFontsLength = installedFonts.length; //installedFontsLength = 5; //kmikawa debug var layerNum = 0; var layerMaxNum = 100; var totalFontsNumToTest = installedFontsLength; var fontsNumStarted = 0; var fontsNumEnd = totalFontsNumToTest-1; //var curPath = whereAmI(); //var logPath = curPath + "/log/"; var logFileFailedFont = new File (logPath + "FailedFonts.log"); var logFileCountFontStart = new File(logPath + "FontTestStartCount.log"); var logFileCountCanceled = new File(logPath + "FontTestCanceledCount.log"); var logFileCountFontFail = new File(logPath + "FontTestFailCount.log"); var logFileCountFontPass = new File(logPath + "FontTestPassCount.log"); var renamedLogFileName; var renamedLog; getDirectory(logPath); var fontToStartCount; var fontToBeTestedCount; var testResult = ""; var startTime; var endTime; var executionTime; var totalFailCount; var totalPassCount; var scriptComplete = false; var psVersion = parseInt(app.version.split(".")[0]); // 10, 11, 12 var curOS = getCurOS($.os); var csVersion = getCurCSVersion(psVersion); var AdobeFnt_OSFontsFile = new File(); var AdobeFnt_CommonFontsFile = new File(); var AdobeFnt_CMapsFile = new File(); var AdobeFnt_OSFontsFileName = "AdobeFnt_OSFonts.lst"; var AdobeFnt_CommonFontsFileName = "AdobeFnt_CommonFonts.lst"; var AdobeFnt_CMapsFileName = "AdobeFnt_CMaps.lst"; var AdobeFnt12FileName = "AdobeFnt11.lst"; //CoolType overwrite AdobeFnt12.lst var AdobeFnt11FileName = "AdobeFnt11.lst"; var stCancelledOperation = localize("$$$/ScriptingSupport/Error/UserCancelled=User cancelled the operation"); checkStatus(); if(scriptComplete){ closingScript(); showCompleteDialog(); } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } /**************************************** * checkStatus ****************************************/ function checkStatus(){ try{ // ----------------------------------------------- // Get font to test // ----------------------------------------------- fontToStartCount = getCount(logFileCountFontStart); if(fontToStartCount == null){ fontToStartCount = 0; }else if(fontToStartCount != 0){ if(getCount(logFileCountCanceled) == 0){ var fontToStartCountToLog = fontToStartCount++; writeLog(logFileFailedFont," - Font "+ fontToStartCountToLog.toString() + ": " + installedFonts[fontToStartCount].name + " (Photoshop May Have Crashed. Uninstalling font is recommended.)"); incrementCount(logFileCountFontFail); incrementCount(logFileCountFontStart); fontToStartCount += 1; writeLog(logFileFontTestDetail, " ************************************************"); writeLog(logFileFontTestDetail, " - Font Test Result: FAIL - Photoshop May Have Crashed. Uninstalling font is recommended."); writeLog(logFileFontTestDetail, " ************************************************"); }else{ writeLog(logFileFontTestDetail, " ************************************************"); writeLog(logFileFontTestDetail, " - User May Have Canceled the Operation."); writeLog(logFileFontTestDetail, " ************************************************"); } } if(fontToStartCount > totalFontsNumToTest){ setToDefault(); } fontToBeTestedCount = totalFontsNumToTest-fontToStartCount; showDialog (); }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * hasEditBoxOnChange ****************************************/ function hasEditBoxOnChange(){ try{ var isNumOk = checkInputNum(); if(isNumOk){ setFontCount(); } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * hasStartBtnOnClick ****************************************/ function hasStartBtnOnClick(){ try{ var isNumOk = checkInputNum(); if(isNumOk){ writeCount(logFileCountCanceled,"0"); setFontCount(); var clearFontCacheResult; if(win.gCheckbox.cbClearCache.enabled == true){ clearFontCacheResult = clearFontCache(win.gCheckbox.cbClearCache.value); }else{ clearFontCacheResult = true; } if(clearFontCacheResult == true){ win.hide(); fontTest(); }else{ alertClearCache(clearFontCacheResult + "\rPlease delete the files manually to clear font cache."); } } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * hasOpenLogBtnOnClick ****************************************/ function hasOpenLogBtnOnClick(){ try{ renamedLog.execute(); }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * checkInputNum ****************************************/ function checkInputNum(){ try{ var numCheckStart = parseInt(win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.text ); var numCheckEnd = parseInt(win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.text); if((0layerMaxNum){ closeDoc(docRef); docRef = app.documents.add(valueWidth, valueHeight); layerNum = 0; } var curFontFamily = installedFonts[fontToStartCount].family; var curFontName = installedFonts[fontToStartCount].name; var curFontParent = installedFonts[fontToStartCount].parent; var curFontPostScriptName = installedFonts[fontToStartCount].postScriptName; var curFontStyle = installedFonts[fontToStartCount].style; var curFontTypeName = installedFonts[fontToStartCount].typename; var fontToStartCountToLog = fontToStartCount+1; writeLog(logFileFontTestDetail, "Font " + fontToStartCountToLog + "\n" + " Font family: " + curFontFamily + "\n" + " Font name: " + curFontName + "\n" + " Font parent: " + curFontParent + "\n" + " Font postScriptName: " + curFontPostScriptName + "\n" + " Font style: " + curFontStyle + "\n" + " Font typename: " + curFontTypeName + "\n"); //alert(fontToStartCount); //kmikawa debug var fontToStartCountToLog = fontToStartCount+1; var valueTextContent = fontToStartCountToLog + " : " + curFontName.replace(/\"/g,"").replace(/\'/g,"") + " : " + valueTextContentString; var valueFontName = "CourierNewPSMT"; var myTextLayer = docRef.artLayers.add(); myTextLayer.kind = LayerKind.TEXT; myTextLayer.textItem.contents = valueTextContent; myTextLayer.textItem.position = Array(docRef.width*0.03, docRef.height*0.7); myTextLayer.textItem.size = valueFontSize; myTextLayer.textItem.font = curFontPostScriptName; myTextLayer.textItem.color = mySolidTextColor; writeLog(logFileFontTestDetail, " - Created text layer."); writeLog(logFileFontTestDetail, " - Font applied: " + myTextLayer.textItem.font); // ----------------------------------------------- // Test Verification // ----------------------------------------------- var isFontFail = 0; var errorMsg = ""; var failErrorMsg = ""; if(myTextLayer.textItem.font != curFontPostScriptName){ isFontFail++; errorMsg += "\n The typed font is not " + curFontPostScriptName + "."; failErrorMsg = "Font error"; } if(myTextLayer.textItem.size != valueFontSize){ isFontFail++; errorMsg += "\n The typed font size (" + myTextLayer.textItem.size + ") is not expected font size (" + valueFontSize + ")."; failErrorMsg = "Font size error"; } if(myTextLayer.textItem.contents != valueTextContent){ isFontFail++; errorMsg += "\n The typed font contents is different from expected strings."; errorMsg += "\n The typed font contents: "+myTextLayer.textItem.contents; errorMsg += "\n The expected strings: "+valueTextContent; failErrorMsg = "Typed contents error"; } if(!isFontFail == 0){ writeLog(logFileFontTestDetail, " ************************************************"); writeLog(logFileFontTestDetail, " - Font Test Result: FAIL" + errorMsg); writeLog(logFileFontTestDetail, " ************************************************"); incrementCount(logFileCountFontFail); var fontToStartCountToLog = fontToStartCount+1; writeLog(logFileFailedFont," - Font "+ fontToStartCountToLog.toString() + ": " + installedFonts[fontToStartCount].name + " (" + failErrorMsg +")"); }else{ writeLog(logFileFontTestDetail, " - Font Test Result: PASS"); incrementCount(logFileCountFontStart); incrementCount(logFileCountFontPass); } // ----------------------------------------------- }catch(e){ if(e.toString().match(stCancelledOperation)){ cancelScript(); } writeLog(logFileFontTestDetail, " ************************************************"); writeLog(logFileFontTestDetail, " - Font Test Result: FAIL" + e); writeLog(logFileFontTestDetail, " ************************************************"); incrementCount(logFileCountFontFail); var fontToStartCountToLog = fontToStartCount+1; writeLog(logFileFailedFont," - Font "+ fontToStartCountToLog.toString() + ": " + installedFonts[fontToStartCount].name + " (" + e +")"); } } //for // ----------------------------------------------- // Write footer log // ----------------------------------------------- endTime = new Date(); executionTime = (endTime.getTime() - startTime.getTime())/1000 ; writeLog(logFileFontTest, "End Time: " + endTime); writeLog(logFileFontTest, "Execution Time: " + executionTime + " seconds"); writeLog(logFileFontTest, "-----------------------------------------"); // ----------------------------------------------- // Complete Dialog // ----------------------------------------------- totalFailCount = getCount(logFileCountFontFail); if(totalFailCount != 0){ testResult = "FAIL"; }else{ testResult = "PASS"; } totalPassCount = getCount(logFileCountFontPass); totalFontsNumToTest = totalPassCount+totalFailCount; writeLog(logFileFontTest, "The number of fonts installed: " + installedFontsLength); writeLog(logFileFontTest, "The number of fonts tested: " + totalFontsNumToTest); writeLog(logFileFontTest, "The number of fonts passed: " + totalPassCount); writeLog(logFileFontTest, "The number of fonts failed: " + totalFailCount); writeLog(logFileFontTest, "-----------------------------------------"); if(!totalFailCount == 0){ writeLog(logFileFontTest, "*****************************************"); writeLog(logFileFontTest, "Test Result: FAIL"); writeLog(logFileFontTest, "*****************************************\n"); writeLog(logFileFontTest, "Failed Font(s) Found. If the error seems to be the font related issue, please send this log to PS-External-Bugs-Tools@adobe.com.\n\n" + getLogContents(logFileFailedFont)); }else{ writeLog(logFileFontTest, "Test Result: PASS"); } scriptComplete = true; }catch(e){ if(e.toString().match("cancelScript")){ //For when hitting Esc key alert(stCancelledOperation); writeCount(logFileCountCanceled,"1"); }else{ alert(e); } } } /**************************************** * checkPref ****************************************/ function checkPref(){ try{ var diff = 0; if(app.preferences.rulerUnits != Units.PIXELS){ diff++; } if(app.preferences.typeUnits != TypeUnits.POINTS){ diff++; } try{ if(app.preferences.fontPreviewSize != FontPreviewType.NONE){ diff++; } }catch(e){ diff++; } if(getPrefTypeMissingGlyphProtection()){ diff++; } if(diff != 0){ return false; } return true; }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * setPref ****************************************/ function setPref(){ try{ setPrefTypeRulerUnits(Units.PIXELS); setPrefTypeTypeUnits(TypeUnits.POINTS); //setPrefTypeFontPreviewSize(FontPreviewType.NONE); setPrefTypeMissingGlyphProtection(false); if(prefMsg != ""){ prefMsg = "Set Units and Type Preferences: These change(s) will be reverted back to the original states at the end of testing unless the script is interrupted.\n" + prefMsg; prefMsg += "\n-----------------------------------------\n"; writeLog(logFileFontTestDetail,prefMsg); prefMsg = ""; } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * setOriginalPref ****************************************/ function setOriginalPref(){ try{ prefMsg = ""; var myOriginalPref = getLogContents(logFilePref).split(":"); if(myOriginalPref != ""){ myOriginalPref[0] = myOriginalPref[0].split(","); myOriginalPref[1] = myOriginalPref[1].split(","); myOriginalPref[2] = myOriginalPref[2].split(","); myOriginalPref[3] = myOriginalPref[3].split(","); }else{ myOriginalPref = [ ["RulerUnits","Units.INCHES"] , ["TypeUnits","TypeUnits.POINTS"], ["FontPreview","FontPreviewType.MEDIUM"],["MissingGlyphProtection","true"] ]; } setPrefTypeRulerUnits(eval(myOriginalPref[0][1])); setPrefTypeTypeUnits(eval(myOriginalPref[1][1])); setPrefTypeFontPreviewSize(eval(myOriginalPref[2][1])); //setPrefTypeMissingGlyphProtection(eval(myOriginalPref[3][1])); if(myOriginalPref[3][1].match("false")){ setPrefTypeMissingGlyphProtection(false); }else{ setPrefTypeMissingGlyphProtection (true); } if(prefMsg != ""){ writeLog(logFileFontTestDetail,"\n-----------------------------------------\nSet Units and Type Preferences:\n"+prefMsg); //alert(prefMsg,"Font Test - Preference Setting"); prefMsg = ""; } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * whereAmI ****************************************/ function whereAmI(){ var where try { app.documents.test(); } catch (err){ where = File(err.fileName); } return where.path; } /**************************************** * getDirectory ****************************************/ function getDirectory(logPath){ try{ var logFolder = new Folder(logPath); if(!logFolder.exists){ logFolder.create(); } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * getCount ****************************************/ function getLogContents(logFile){ try{ var logContents = new String(); var line = ""; if(logFile.exists){ logFile.open("r"); while ( ! logFile.eof ) { line = logFile.readln(); logContents += line + "\n"; line = ""; } logFile.close(); return logContents; } return ""; } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * getCount ****************************************/ function getCount(countFile){ try{ var line = ""; if(countFile.exists){ countFile.open("r"); while ( ! countFile.eof ) { line = countFile.readln(); } countFile.close(); var curCount = parseInt(line); if(!isNaN(curCount)){ return curCount; } } writeLog(countFile,"0"); return 0; } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * incrementCount ****************************************/ function incrementCount(countFile){ try{ var line = ""; if(countFile.exists){ countFile.open("r"); while ( ! countFile.eof ) { line = countFile.readln(); } countFile.close(); var curCount = parseInt(line); if(!isNaN(curCount)){ curCount += 1; writeCount(countFile,curCount.toString()); }else{ writeCount(countFile,"1"); } }else{ writeCount(countFile,"1"); } } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * writeLog ****************************************/ function writeLog(logFile, log){ try { if(logFile.exists) { logFile.open ("e"); logFile.seek (0,2); // move to EOF } else { logFile.open ("w"); logFile.encoding = "UTF8"; logFile.write("\uFEFF"); // Unicode marker } logFile.writeln( log ); logFile.close(); logFile.open("a"); //flushing the contents logFile.close(); } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } finally { } return; } /**************************************** * writeCount ****************************************/ function writeCount(logFile, log){ try { if(logFile.exists) { logFile.open ("e"); } else { logFile.open ("w"); logFile.encoding = "UTF8"; logFile.write("\uFEFF"); // Unicode marker } if(!isNaN(log)){ logFile.writeln( log.toString() ); }else{ alertScriptError(log + " is not a number."); } logFile.close(); logFile.open("a"); //flushing the contents logFile.close(); } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } finally { } return; } /**************************************** * writeState ****************************************/ function writeState(logFile, log){ try { if(logFile.exists) { logFile.open ("e"); } else { logFile.open ("w"); logFile.encoding = "UTF8"; logFile.write("\uFEFF"); // Unicode marker } logFile.writeln( log.join(":") ); logFile.close(); logFile.open("a"); //flushing the contents logFile.close(); } catch (e) { alert("Line: " + e.line +" - "+ e); } finally { } return; } /**************************************** * deleteLogFiles ****************************************/ function deleteCountLogFiles(){ try{ if(logFileCountFontStart.exists){ logFileCountFontStart.remove(); } if(logFileCountFontFail.exists){ logFileCountFontFail.remove(); } if(logFileCountCanceled.exists){ logFileCountCanceled.remove(); } if(logFileFontTest.exists){ logFileFontTest.remove(); } if(logFileFailedFont.exists){ logFileFailedFont.remove(); } if(logFileCountFontPass.exists){ logFileCountFontPass.remove(); } if(logFileFontTestDetail.exists){ logFileFontTestDetail.remove(); } if(logFilePref.exists){ logFilePref.remove(); } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * copyLogFile ****************************************/ function copyLogFile(newName){ try{ if(logFileFontTest.exists){ logFileFontTest.copy(newName); } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * convertDateToFileName ****************************************/ function convertDateToFileName(date){ try{ var h = date.getHours(); if(h < 0) h = 0; // avoid bug on getHours() return negative number. var s = date.getFullYear() + "" + fillZero(date.getMonth()+1,2) + "" + fillZero(date.getDate(),2) + "_"; s += fillZero(h, 2) + "" + fillZero(date.getMinutes(), 2) + "" + fillZero(date.getSeconds(),2); return s; } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * isoDateString ****************************************/ function fillZero(num, digit) { try{ var src = new String(num); var cnt = digit - src.length; if (0 < cnt){ while (0 < cnt--) src = "0" + src; } return src; } catch (e) { alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * showDialog ****************************************/ function showDialog(){ try{ // ----------------------------------------------- // Dialog // ----------------------------------------------- ui = // dialog resource object "dialog { \ alignChildren: 'fill', \ text: 'Font Test',\ rowGroup:Group {\ alignChildren: 'left', \ orientation:'column',\ testDetailGroup:Group {\ orientation:'row',\ titleGroup: Group { \ orientation:'column',\ stTotalTitle: StaticText { \ orientation: 'row', \ alignment: 'left' }, \ stTestedTitle: StaticText { \ orientation: 'row', \ alignment: 'left' }, \ stFontNumToTestTitle: StaticText { \ orientation: 'row', \ alignment: 'left' }, \ stRemainingTitle: StaticText { \ orientation: 'row', \ alignment: 'left' }, \ }\ numGroup: Group { \ orientation:'column',\ stTotalNum: StaticText { \ orientation: 'row', \ alignment: 'right' }, \ stTestedNum: StaticText { \ orientation: 'row', \ alignment: 'right' }, \ numFontCountGroup: Group { \ stTestedTotal: StaticText { \ orientation: 'row', \ alignment: 'right' }, \ etToTestStartNum: EditText { \ orientation: 'row', \ alignment: 'right' }, \ stToTestKigoNum: StaticText { \ orientation: 'row', \ alignment: 'right' }, \ etToTestEndNum: EditText { \ orientation: 'row', \ alignment: 'right' }, \ }\ stRemainingNum: StaticText { \ orientation: 'row', \ alignment: 'right' }, \ }\ }\ }\ gCheckbox: Group { \ orientation: 'row', alignment: 'right', \ cbClearCache: Checkbox { text: 'Clear Font Cache', alignment: 'left', properties:{name:'clearcache'}, helpTip:'Delete font caches (lst files).' }, \ } \ gButtons: Group { \ orientation: 'row', alignment: 'right', \ startBtn: Button { text:'Start', properties:{name:'start'} }, \ cancelBtn: Button { text:'Cancel', properties:{name:'cancel'} } \ } \ }"; win = new Window (ui); // new window object with UI resource if(psVersion >10){ // match our dialog background color to the host application win.graphics.backgroundColor = win.graphics.newBrush (win.graphics.BrushType.THEME_COLOR, "appDialogBackground"); } win.rowGroup.testDetailGroup.titleGroup.stTotalTitle.text = "The number of fonts installed: "; win.rowGroup.testDetailGroup.titleGroup.stTestedTitle.text = "The number of fonts tested: "; win.rowGroup.testDetailGroup.titleGroup.stFontNumToTestTitle.text = "The font item numbers to test: "; win.rowGroup.testDetailGroup.titleGroup.stRemainingTitle.text = "The number of fonts to be tested: "; win.rowGroup.testDetailGroup.numGroup.stTotalNum.text = installedFontsLength; win.rowGroup.testDetailGroup.numGroup.stTotalNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.stTestedNum.text = fontToStartCount; win.rowGroup.testDetailGroup.numGroup.stTestedNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.text = fontToStartCount+1; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.alignment = "right"; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.stToTestKigoNum.text = "~"; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.text = fontsNumEnd+1; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.alignment = "right"; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.stRemainingNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.stRemainingNum.text = fontToBeTestedCount; if(fontToStartCount != 0){ win.gButtons.startOverBtn = win.gButtons.add('button', undefined, 'Start Over', {name:'startover'}); win.gButtons.startOverBtn.helpTip = "Start testing all fonts installed."; win.gButtons.startOverBtn.onClick = hasstartOverBtnOnClick; if(getCount(logFileCountCanceled) == 0){ win.rowGroup.add('statictext', undefined, 'The last tested font (' + installedFonts[fontToStartCount-1].name + ') might have a problem. Click Start to continue testing.', {name:'stLastFailedFontNumMsg'}); var alertMsg = win.rowGroup.stLastFailedFontNumMsg.graphics; //alertMsg.font = ScriptUI.newFont("Arial",ScriptUI.FontStyle.REGULAR,12); alertMsg.foregroundColor =alertMsg.newPen (alertMsg.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1); } win.gCheckbox.cbClearCache.value = false; win.gCheckbox.cbClearCache.enabled = false; }else{ win.gCheckbox.cbClearCache.enabled = true; win.gCheckbox.cbClearCache.value = true; } win.gButtons.startBtn.helpTip = "Start testing fonts. ";//Press Esc key to stop testing."; win.gButtons.cancelBtn.helpTip = "Cancel testing."; win.gButtons.startBtn.text = sStartButton; win.gButtons.cancelBtn.text = sCacelButton; win.gButtons.cancelBtn.onClick = hasCancelBtnOnClick; win.gButtons.startBtn.onClick = hasStartBtnOnClick; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.onChange = hasEditBoxOnChange; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.onChange = hasEditBoxOnChange; win.center(); // move to center before if(errorToQuit == 0){ var fontTestDialog = win.show(); // dialog display } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * showCompleteDialog ****************************************/ function showCompleteDialog(){ try{ win = new Window (ui); // new window object with UI resource if(psVersion >10){ win.graphics.backgroundColor = win.graphics.newBrush (win.graphics.BrushType.THEME_COLOR, "appDialogBackground"); } win.text = "Font Test Completed: " + testResult; win.rowGroup.testDetailGroup.titleGroup.stTotalTitle.text = "The number of fonts installed: "; win.rowGroup.testDetailGroup.titleGroup.stFontNumToTestTitle.text = "The number of fonts tested and item number (Last Run): "; win.rowGroup.testDetailGroup.titleGroup.stTestedTitle.text = "The number of fonts passed: "; win.rowGroup.testDetailGroup.titleGroup.stRemainingTitle.text = "The number of fonts failed: "; win.rowGroup.testDetailGroup.numGroup.stTotalNum.text = installedFontsLength; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.stTestedTotal.text = totalFontsNumToTest; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.text = fontsNumStarted+1; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.enabled = false; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestStartNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.stToTestKigoNum.text = "~"; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.text = fontsNumEnd+1; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.enabled = false; win.rowGroup.testDetailGroup.numGroup.numFontCountGroup.etToTestEndNum.preferredSize.width = 50; win.rowGroup.testDetailGroup.numGroup.stTestedNum.text = totalPassCount; win.rowGroup.testDetailGroup.numGroup.stRemainingNum.text = totalFailCount; win.gCheckbox.cbClearCache.enabled = false; win.gButtons.startBtn.hide(); win.gButtons.cancelBtn.text = sOKButton; renamedLog = new File(renamedLogFileName); win.gButtons.openLogBtn = win.gButtons.add('button', undefined, 'Open Log', {name:'openlog'}); win.gButtons.openLogBtn.helpTip = "Open Test Result log file (" + renamedLog.fsName + ")."; win.gButtons.openLogBtn.onClick = hasOpenLogBtnOnClick; if(totalFailCount !=0){ win.rowGroup.stErrorFileMsg = win.rowGroup.add('statictext', undefined, totalFailCount + ' error(s) found.', {name:'logError'}); var errorMsg = win.rowGroup.stErrorFileMsg.graphics; //errorMsg.font = ScriptUI.newFont("Arial",ScriptUI.FontStyle.BOLD,12); errorMsg.foregroundColor =errorMsg.newPen (errorMsg.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1); var errorCount = win.rowGroup.testDetailGroup.numGroup.stRemainingNum.graphics; //errorCount.font = ScriptUI.newFont("Arial",ScriptUI.FontStyle.BOLD,12); errorCount.foregroundColor =errorCount.newPen (errorCount.PenType.SOLID_COLOR, [1.00, 0.00, 0.00, 1],lineWidth=1); } win.rowGroup.stLogPath = win.rowGroup.add('statictext', undefined, 'Log File: ' + renamedLog.fsName, {name:'stLogPath'}); win.center(); // move to center before if(errorToQuit == 0){ var ret = win.show(); // dialog display } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * closingScript ****************************************/ function closingScript(){ try{ setOriginalPref(); writeLog(logFileFontTest, "-----------------------------------------"); writeLog(logFileFontTest, getLogContents(logFileFontTestDetail)); writeLog(logFileFontTest, "-----------------------------------------"); writeLog(logFileFontTest, "\n\n"); writeLog(logFileFontTest, "-----------------------------------------"); writeLog(logFileFontTest, "System Information"); writeLog(logFileFontTest, "-----------------------------------------"); var psSystemInfo = app.systemInformation; writeLog(logFileFontTest,psSystemInfo); renamedLogFileName = logPath + "FontTestLog_" + convertDateToFileName(endTime) + ".txt"; copyLogFile(renamedLogFileName); deleteCountLogFiles(); }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * closeAllDocuments ****************************************/ function closeDoc(myDoc){ try{ myDoc.close(SaveOptions.DONOTSAVECHANGES); } catch (e) { alert ( e ); } } /**************************************** * clearFontCache ****************************************/ function clearFontCache(cbClearCacheValue){ try{ var errorMsg = "Failed to delete following files: \n"; var failCount = 0; if(cbClearCacheValue == true){ writeLog(logFileFontTestDetail, "Clear Font Cache: ON"); var getCacheFilesResult = getCacheFiles(); if(getCacheFilesResult){ if(AdobeFnt_OSFontsFile.exists){ try{ AdobeFnt_OSFontsFile.remove(); writeLog(logFileFontTestDetail, " - Deleted (Cleared): " + AdobeFnt_OSFontsFile.fsName); }catch(e){ errorMsg += AdobeFnt_OSFontsFile.fsName; failCount++; } }else{ writeLog(logFileFontTestDetail, " - File Not Found (Cleared): " + AdobeFnt_OSFontsFile.fsName); } if(AdobeFnt_CommonFontsFile.exists){ try{ AdobeFnt_CommonFontsFile.remove(); writeLog(logFileFontTestDetail, " - Deleted (Cleared): " + AdobeFnt_CommonFontsFile.fsName); }catch(e){ errorMsg += AdobeFnt_CommonFontsFile.fsName; failCount++; } }else{ writeLog(logFileFontTestDetail, " - File Not Found (Cleared): " + AdobeFnt_CommonFontsFile.fsName); } if(AdobeFnt_CMapsFile.exists){ try{ AdobeFnt_CMapsFile.remove(); writeLog(logFileFontTestDetail, " - Deleted (Cleared): " + AdobeFnt_CMapsFile.fsName); }catch(e){ errorMsg += AdobeFnt_CMapsFile.fsName; failCount++; } }else{ writeLog(logFileFontTestDetail, " - File Not Found (Cleared): " + AdobeFnt_CMapsFile.fsName); } if(failCount !=0){ return errorMsg; }else{ writeLog(logFileFontTestDetail, "-----------------------------------------"); return true; } }else{ writeLog(logFileFontTestDetail, "-----------------------------------------"); var fontCacheFileNames = " - " + AdobeFnt_OSFontsFile.fsName +"\n - "+ AdobeFnt_CommonFontsFile.fsName +"\n - "+ AdobeFnt_CMapsFile.fsName; return "Failed to get the path for font cache files:\n\n" + fontCacheFileNames + "\n"; } }else{ writeLog(logFileFontTestDetail, "Clear Font Cache: OFF"); writeLog(logFileFontTestDetail, "-----------------------------------------"); return true; } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * getCurCSVersion ****************************************/ function getCurCSVersion(psVersion){ try{ var myCsVersion; switch (psVersion) { case 10: myCsVersion = 'CS3'; return myCsVersion; case 11: myCsVersion = 'CS4'; return myCsVersion; case 12: myCsVersion = 'CS5'; return myCsVersion; default: return false; } return false; }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * getCurOS ****************************************/ function getCurOS(curOS){ try{ var myOS; if(curOS.match("Macintosh")){ myOS = "mac"; }else if(curOS.match("XP")){ myOS = "winxp"; }else if(curOS.match("Vista")){ myOS = "winvista"; }else{ myOS = "win7"; } return myOS; }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * getCacheFiles ****************************************/ function getCacheFiles(){ try{ if(curOS.match("mac")){ var macCacheDirName = "~/Library/Caches/Adobe/"; var macCacheTypeSupportDirName = macCacheDirName + "TypeSupport/"; var macCacheFontDirName = macCacheDirName + "Fonts/"; var macCacheCMapDirName = macCacheTypeSupportDirName + "CMaps/"; switch(psVersion){ case 12: AdobeFnt_OSFontsFile = new File(macCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_OSFontsFileName); AdobeFnt_CommonFontsFile = new File(macCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_CommonFontsFileName); AdobeFnt_CMapsFile = new File(macCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_CMapsFileName); return true; case 11: AdobeFnt_OSFontsFile = new File(macCacheTypeSupportDirName + AdobeFnt12FileName); //AdobeFnt12.lst is CoolType version AdobeFnt_CommonFontsFile = new File(macCacheFontDirName + AdobeFnt12FileName); AdobeFnt_CMapsFile = new File(macCacheCMapDirName + AdobeFnt12FileName); return true; case 10: AdobeFnt_OSFontsFile = new File(macCacheTypeSupportDirName+ AdobeFnt11FileName); //AdobeFnt11.lst is CoolType version AdobeFnt_CommonFontsFile = new File(macCacheFontDirName + AdobeFnt11FileName); AdobeFnt_CMapsFile = new File(macCacheCMapDirName + AdobeFnt11FileName); return true; default: return false; } }else if(curOS.match("win")){ var winCacheDirName = "~/AppData/Local/Adobe/"; if(curOS == "winxp"){ winCacheDirName = "~/Local Settings/Application Data/Adobe/"; } var winCacheTypeSupportDirName = winCacheDirName + "TypeSupport/"; var winCacheFontDirName = winCacheDirName + "Fonts/"; var winCacheCMapDirName = winCacheFontDirName + "CMaps/"; switch(psVersion){ case 12: AdobeFnt_OSFontsFile = new File(winCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_OSFontsFileName); AdobeFnt_CommonFontsFile = new File(winCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_CommonFontsFileName); AdobeFnt_CMapsFile = new File(winCacheTypeSupportDirName + csVersion+"/" + AdobeFnt_CMapsFileName); return true; case 11: AdobeFnt_OSFontsFile = new File(winCacheTypeSupportDirName + AdobeFnt12FileName); //AdobeFnt12.lst is CoolType version AdobeFnt_CommonFontsFile = new File(winCacheFontDirName + AdobeFnt12FileName); AdobeFnt_CMapsFile = new File(winCacheCMapDirName + AdobeFnt12FileName); return true; case 10: AdobeFnt_OSFontsFile = new File(winCacheTypeSupportDirName+ AdobeFnt11FileName); //AdobeFnt11.lst is CoolType version AdobeFnt_CommonFontsFile = new File(winCacheFontDirName + AdobeFnt11FileName); AdobeFnt_CMapsFile = new File(winCacheCMapDirName + AdobeFnt11FileName); return true; default: return false; } }else{ return false; } }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * alertClearCache ****************************************/ function alertClearCache(msg){ try{ alert(msg, "Font Test Error"); }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } } /**************************************** * alertScriptError ****************************************/ function alertScriptError(msg){ try{ //alert(msg+ "\rDeleting all log files in " + logPathFolder.fsName + " may solve the problem.", "Font Test Error"); //logPathFolder.execute(); alert(msg + "\nDeleting log files in " + logPathFolder.fsName + " may solve the problem.","Font Test Error"); errorToQuit++; }catch(e){ alert(e); } } /**************************************** * setPrefTypeRulerUnits ****************************************/ function setPrefTypeRulerUnits(valUnits){ try{ if(app.preferences.rulerUnits != valUnits){ prefMsg += " - Changed Ruler Units from "+ app.preferences.rulerUnits + " to " + valUnits +"\n"; app.preferences.rulerUnits = valUnits; } }catch(e){ var targetPref = "Ruler Units"; alertScriptError("Failed to change " +targetPref+ " to " +valUnits.toString()+ ". Please go to Preference->Units & Rulers and set " +targetPref+ " to " +valUnits.toString()+ " manually and start again."+"\r\rLine: " + e.line +" - "+ e); } } /**************************************** * setPrefTypeTypeUnits ****************************************/ function setPrefTypeTypeUnits(valUnits){ try{ if(app.preferences.typeUnits != valUnits){ prefMsg += " - Changed Type Units from "+ app.preferences.typeUnits + " to " + valUnits +"\n"; app.preferences.typeUnits = valUnits; } }catch(e){ var targetPref = "Type Units"; alertScriptError("Failed to set " +targetPref+ " to " +valUnits.toString()+ ". Please go to Preference->Units & Rulers and set " +targetPref+ " to " +valUnits.toString()+ " manually and start again."+"\r\rLine: " + e.line +" - "+ e); } } /**************************************** * setPrefTypeFontPreviewSize ****************************************/ function setPrefTypeFontPreviewSize(valUnits){ try{ //myPref[2][1] = app.preferences.fontPreviewSize; if(app.preferences.fontPreviewSize != valUnits){ //prefMsg += " - Changed Font Preview from "+ app.preferences.fontPreviewSize + " to " + valUnits +"\n"; //app.preferences.fontPreviewSize = valUnits; prefMsg += " - Please go to Preference->Type and set Font Preview Size to " +valUnits.toString()+ " manually\n"; } }catch(e){ var targetPref = "Font Preview Size"; alertScriptError("Failed to set " +targetPref+ " to " +valUnits+ ". Please go to Preference->Type and set " +targetPref+ " to " +"OFF"+ " manually and start again."+"\r\rLine: " + e.line +" - "+ e); } } /**************************************** * prefPreview ****************************************/ function setPrefTypeMissingGlyphProtection(valUnits){ try{ var curVal = getPrefTypeMissingGlyphProtection(); if(curVal != valUnits){ prefMsg += " - Changed Missing Glyph Protection Option from "+ curVal + " to " + valUnits; var idsetd = charIDToTypeID( "setd" ); var desc27 = new ActionDescriptor(); var idnull = charIDToTypeID( "null" ); var ref17 = new ActionReference(); var idPrpr = charIDToTypeID( "Prpr" ); var idtypePreferences = stringIDToTypeID( "typePreferences" ); ref17.putProperty( idPrpr, idtypePreferences ); var idcapp = charIDToTypeID( "capp" ); var idOrdn = charIDToTypeID( "Ordn" ); var idTrgt = charIDToTypeID( "Trgt" ); ref17.putEnumerated( idcapp, idOrdn, idTrgt ); desc27.putReference( idnull, ref17 ); var idT = charIDToTypeID( "T " ); var desc28 = new ActionDescriptor(); var idenableFontFallback = stringIDToTypeID( "enableFontFallback" ); desc28.putBoolean( idenableFontFallback, valUnits ); var idtypePreferences = stringIDToTypeID( "typePreferences" ); desc27.putObject( idT, idtypePreferences, desc28 ); executeAction( idsetd, desc27, DialogModes.NO ); } }catch(e){ var targetPref = "Missing Glyph Protection Option"; alertScriptError("Failed to set " +targetPref+ " to " +"OFF"+ ". Please go to Preference->Type and set " +targetPref+ " to " +"OFF"+ " manually and start again."+"\r\rLine: " + e.line +" - "+ e); } } /**************************************** * getPrefTypeMissingGlyphProtection ****************************************/ function getPrefTypeMissingGlyphProtection(){ try{ var idtypePreferences = stringIDToTypeID( "typePreferences" ); var idenableFontFallback = stringIDToTypeID( "enableFontFallback" ); var ref1 = new ActionReference(); var idPrpr = charIDToTypeID( "Prpr" ); var idCchP = charIDToTypeID( "CchP" ); // ref1.putProperty( idPrpr, idCchP ); ref1.putProperty( idPrpr, idtypePreferences ); var idcapp = charIDToTypeID( "capp" ); var idOrdn = charIDToTypeID( "Ordn" ); var idTrgt = charIDToTypeID( "Trgt" ); ref1.putEnumerated( idcapp, idOrdn, idTrgt ); var desc1 = executeActionGet( ref1); var desc2 = desc1.getObjectValue(idtypePreferences); var enableFontFallback = desc2.getBoolean(idenableFontFallback); return enableFontFallback; }catch(e){ alertScriptError("Line: " + e.line +" - "+ e); } }