Skip to content

Instantly share code, notes, and snippets.

@typomedia
Created April 5, 2016 12:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save typomedia/5be49c1f4cd0ddc94f707eb7e95118a0 to your computer and use it in GitHub Desktop.
Save typomedia/5be49c1f4cd0ddc94f707eb7e95118a0 to your computer and use it in GitHub Desktop.
Adobe InDesign Script for Font Catalog
/*
Adobe InDesign Script - FontCatalog.jsx
Erstellt einen Schriftartenkatalog
Designstudio, Philipp Speck - www.destio.de
Copyright (c) 2012 Designstudio, Philipp Speck
*/
var doc=app.documents.add();
var appFonts=app.fonts;
if (File.fs == "Windows") {
var sysRoot=Folder.system.parent.fsName;
var sysFontDir=sysRoot+"\\Fonts\\";
var appFontDir=Folder.startup.fsName+"\\Fonts\\";
} else {
var sysRoot=Folder.system.fsName;
var libFontDir="/Library/Fonts/";
var sysFontDir=sysRoot+"/Library/Fonts/";
var appFontDir=Folder.startup.fsName+"/Fonts/";
}
var sampleTitle="Typography";
var sampleText="Letterforms have tone, timbre, character, just as words and sentences do. The moment a text and a typeface are chosen, two streams of thought, two rhythmical systems, two sets of habits, or if you like, two personalities intersect. They must not live together contentedly forever, but they must not as rule collide.";
var sampleLetters="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&0123456789$€!?@#%§.;:,{}";
fontCatalog();
function fontCatalog() {
setupDocument();
setupMasterSpread();
skipCount=-1;
docCount=0;
insertTextFrame();
getFontList();
}
function setupDocument() {
// Einheiten auf Millimeter setzen
with (doc.viewPreferences) {
horizontalMeasurementUnits=MeasurementUnits.MILLIMETERS;
verticalMeasurementUnits=MeasurementUnits.MILLIMETERS;
rulerOrigin=RulerOrigin.PAGE_ORIGIN;
}
// A4 Dokument ertsellen
with (doc.documentPreferences) {
pageWidth="210mm";
pageHeight="297mm";
}
// Farben hinzufügen
doc.colors.add( {
name: "Dunkelrot",
model: ColorModel.PROCESS,
colorValue: [0, 100, 60, 40]
} );
// Zeichenformate setzen
doc.characterStyles.add({name:"Fußzeile"});
with (doc.characterStyles.item("Fußzeile")) {
pointSize=10;
fillColor = "Black";
}
doc.characterStyles.add({name:"Pagina"});
with (doc.characterStyles.item("Pagina")) {
pointSize=10;
fillColor = "Black";
}
// Absatzformate setzen
doc.paragraphStyles.add({name:"Schriftname"});
with (doc.paragraphStyles.item("Schriftname")) {
pointSize=12;
justification=Justification.leftAlign;
fillColor = "Black";
spaceAfter = "3mm";
ruleBelow=true;
ruleBelowOffset="2mm";
ruleBelowColor="Dunkelrot";
}
doc.paragraphStyles.add({name:"Schriftinfo"});
with (doc.paragraphStyles.item("Schriftinfo")) {
pointSize=8;
justification=Justification.leftAlign;
}
doc.paragraphStyles.add({name:"Typografie"});
with (doc.paragraphStyles.item("Typografie")) {
pointSize=24;
fillColor = "Black";
spaceAfter = "2mm";
hyphenation = false;
leading=24;
}
doc.paragraphStyles.add({name:"Schriftmuster"});
with (doc.paragraphStyles.item("Schriftmuster")) {
pointSize=10;
fillColor = "Black";
justification=Justification.LEFT_JUSTIFIED;
spaceAfter = "2mm";
hyphenation = false;
}
doc.paragraphStyles.add({name:"Zeichensatz"});
with (doc.paragraphStyles.item("Zeichensatz")) {
pointSize=14;
justification=Justification.leftAlign;
fillColor = "Black";
}
}
function setupMasterSpread() {
with(doc.masterSpreads.item(0)) {
with (pages.item(0).marginPreferences) {
top=15;
right=15;
bottom=20;
left=20;
}
with (textFrames.add()) {
geometricBounds = [285, 20, 280, 140];
textFramePreferences.verticalJustification=VerticalJustification.BOTTOM_ALIGN;
insertionPoints.item(0).contents = "Designstudio Typeface Library | www.destio.de/typo";
parentStory.appliedCharacterStyle="Fußzeile";
}
with (textFrames.add()) {
geometricBounds = [285, 180, 280, 195];
textFramePreferences.verticalJustification=VerticalJustification.BOTTOM_ALIGN;
insertionPoints.item(0).contents = SpecialCharacters.autoPageNumber;
insertionPoints.item(0).contents = SpecialCharacters.THIN_SPACE;
insertionPoints.item(0).contents = String.fromCharCode(0x25A0);
paragraphs.item(0).justification = Justification.rightAlign;
parentStory.appliedCharacterStyle="Pagina";
}
}
}
function getFontList() {
for ( i = 0 ; i < appFonts.length; i++) {
appFont=appFonts[i];
fontName=appFont.name;
fontLocation=appFont.location;
fontVersion=appFont.version;
fontType=appFont.fontType;
if (File.fs == "Windows") {
fontVersion=appFont.version.substr(0, fontVersion.indexOf(';'));
fontFilename=fontLocation.substr(fontLocation.lastIndexOf('\\')+1, fontLocation.length);
fontFilepath=fontLocation.replace(fontFilename, '');
(fontFilepath === sysFontDir) ? delete appFont : insertFontList();
} else {
fontVersion=appFont.version.substr(0, fontVersion.indexOf(';'));
fontFilename=fontLocation.substr(fontLocation.lastIndexOf('/')+1, fontLocation.length);
fontFilepath=fontLocation.replace(fontFilename, '');
(fontFilepath === sysFontDir || fontFilepath === libFontDir ) ? delete appFont : insertFontList();
}
}
function insertFontList() {
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=fontName.replace(/\t/, ' ')+"\r";
paragraphs.item(skipCount).appliedParagraphStyle="Schriftname";
}
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=fontVersion+", "+getFontType(appFont)+", "+fontFilename+"\r";
paragraphs.item(skipCount).appliedParagraphStyle="Schriftinfo";
}
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=sampleTitle+"\r";
paragraphs.item(skipCount).appliedParagraphStyle="Typografie";
paragraphs.item(skipCount).appliedFont=fontName;
}
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=sampleText+"\r";
paragraphs.item(skipCount).appliedParagraphStyle="Schriftmuster";
paragraphs.item(skipCount).appliedFont=fontName;
}
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=sampleLetters+"\r";
paragraphs.item(skipCount).appliedParagraphStyle="Zeichensatz";
paragraphs.item(skipCount).appliedFont=fontName;
}
skipCount++;
with (doc.pages[docCount].textFrames.item(0).parentStory) {
insertionPoints.item(-1).contents=" \r";
paragraphs.item(skipCount).pointSize=10;
}
if(doc.pages[docCount].textFrames.item(0).overflows) {
with (doc.pages[docCount].textFrames.item(0).parentStory.paragraphs) {
item(skipCount-1).remove();
item(skipCount-2).remove();
item(skipCount-3).remove();
item(skipCount-4).remove();
item(skipCount-5).remove();
item(skipCount-6).remove();
}
doc.pages.add();
docCount++;
insertTextFrame();
skipCount=-1;
}
}
}
function insertTextFrame() {
with (doc.pages[docCount].textFrames.add()) {
geometricBounds=[15, 20, 277, 195];
}
}
function getFontType(appFont) {
switch(appFont.fontType) {
case FontTypes.TYPE_1:
return "PostScript Type 1";
case FontTypes.CID:
return "PostScript CID";
case FontTypes.OCF:
return "PostScript OCF";
case FontTypes.OPENTYPE_CFF:
return "OpenType CFF";
case FontTypes.OPENTYPE_CID:
return "OpenType CID";
case FontTypes.OPENTYPE_TT:
return "OpenType TT";
case FontTypes.TRUETYPE:
return "TrueType";
case FontTypes.BITMAP:
return "Bitmap";
case FontTypes.ATC:
return "Bitmap ATC";
case FontTypes.UNKNOWN:
return "Unknown Type";
default:
return "Unknown Type";
}
}
@lfcorullon
Copy link

Hello, Philipp. May I contact you to ask a few questions about this code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment