// Make an InDesign character map for a font // Original script by Eric Menninga, Adobe Systems Inc. // Modified and expanded by Chuck Weger, Elara Systems, LLC // Version 1.1, May 2009 // Version 1.2, October 2013 - fixed a problem wherein the file failed to import into InDesign CC due to it having a Mac-based line-ending. Also fixed a runtime error if the user cancels the dialog. // General flow: // 1. Show a dialog prompting the user for font, starting and ending glyphs // 2. Build a temporary file with InDesign Tagged Text codes for every glyph between starting and ending values // 3. Make an InDesign document and import the tagged text file into a text frame // ---------------------------------------------------------------------------------------------------------- // "main" program var result = showUI(); if (result) { var taggedTextFile = createGlyphFile(result["fontName"], result["fontStyle"], parseInt(result["beginGlyph"]), parseInt(result["endGlyph"])); if (taggedTextFile != null) { createInDesignDocFromTaggedText(taggedTextFile); taggedTextFile.remove(); } } // ---------------------------------------------------------------------------------------------------------- // Create an InDesign tagged text file with "cSpecialGlyph" codes function createGlyphFile(fontName, fontStyle, beginGlyph, endGlyph) { var tempFile = new File(Folder.temp + "/glyphmap.txt"); // this file lives in the user's temporary folder if (tempFile) { if (getPlatform() == "MAC") { tempFile.lineFeed = "Unix"; // added 10-18-13 by Chuck Weger. Otherwise the file import fails in CC } tempFile.remove(); // clear out any old one tempFile.open("w"); tempFile.writeln (""); tempFile.writeln (">"); tempFile.writeln (">"); tempFile.write(""); for (i = beginGlyph; i <= endGlyph; ++i) { num = String(i); tempFile.write("<0xFFFD> "); } tempFile.close(); return(tempFile); } else { return(null); // we couldn't create the temp file for some reason } } // ---------------------------------------------------------------------------------------------------------- // Make an InDesign document, make a text frame, and import the file we created earlier function createInDesignDocFromTaggedText(myFile) { myDoc = app.documents.add(true); myDoc.viewPreferences.properties = {horizontalMeasurementUnits:MeasurementUnits.inches, verticalMeasurementUnits:MeasurementUnits.inches}; myDoc.documentPreferences.properties = {pagesPerDocument:1, pageWidth: "8.5in", pageHeight: "11 in", facingPages:false, pageOrientation:PageOrientation.portrait}; myFrame = myDoc. textFrames.add(myDoc.layers[0], undefined, undefined, {geometricBounds:[0.5, 0.5, 10.5, 8], textFramePreferences:{firstBaselineOffset:FirstBaseline.ascentOffset}, }); myFrame.insertionPoints[-1].place(myFile); } // ---------------------------------------------------------------------------------------------------------- // Everything below here has to do with showing the dialog box function showUI() { var fontList = getFontList(); var myDialog = app.dialogs.add({name:"Font Table",canCancel:true}); with(myDialog) { with(dialogColumns.add()) { with (dialogRows.add()) { staticTexts.add({staticLabel:"Font:"}); var fontMenu = dropdowns.add ({stringList:fontList, selectedIndex:0}); } with (dialogRows.add()) { staticTexts.add({staticLabel:"Beginning Glyph ID:"}); var beginId = integerEditboxes.add({editContents:"1", minWidth:80, minimumValue:0, maximumValue:65535}); } with (dialogRows.add()) { staticTexts.add({staticLabel:"Ending Glyph ID:"}); var endId = integerEditboxes.add({editContents:"10", minWidth:80, minimumValue:0, maximumValue:65535}); } } } //Display the dialog box: var myResult = myDialog.show(); if(myResult == true){ var fontSplit = fontList[fontMenu.selectedIndex].split(" - "); var reply = {fontName: fontSplit[0], fontStyle: fontSplit[1], beginGlyph: beginId.editValue, endGlyph: endId.editValue}; } else { var reply = null; myDialog.destroy(); } return (reply); } // ---------------------------------------------------------------------------------------------------------- // Build a list of fonts active in InDesign function getFontList() { var fontList = new Array(); var myFonts = CollectionToArray(app.fonts); for (var i = 0; i < myFonts.length; i++) { var thisFont = myFonts[i]; if (thisFont.status == FontStatus.INSTALLED) { var s = thisFont.fontFamily + " - " + thisFont.fontStyleName; fontList.push(s); } } return(fontList); } // ---------------------------------------------------------------------------------------------------------- // Iterating over a collection is very slow in ExtendScript. // This technique, which turns a collection into an array, is courtesty // of Peter Truskier and Jim Birkenseer of Premedia Systems function CollectionToArray(theCollection) { return theCollection.everyItem().getElements().slice(0); } // ---------------------------------------------------------------------------------------------------------- // Figure out whether we're on a Mac, PC, or Atari function getPlatform() { // returns "MAC" or "WIN" depending upon the barometric pressure var os = $.os; if (os.indexOf("Mac", 0) >= 0) { var platform = "MAC"; } else { var platform = "WIN"; } return(platform); }