Skip to content

Instantly share code, notes, and snippets.

@quells
Last active August 29, 2015 14:12
Show Gist options
  • Save quells/77e0ba1dd42fffd56929 to your computer and use it in GitHub Desktop.
Save quells/77e0ba1dd42fffd56929 to your computer and use it in GitHub Desktop.
// Set Up Doc
var doc = app.documents.add();
var vp = doc.viewPreferences;
vp.horizontalMeasurementUnits = MeasurementUnits.picas;
vp.verticalMeasurementUnits = MeasurementUnits.picas;
vp.rulerOrigin = RulerOrigin.pageOrigin;
doc.textDefaults.alignToBaseline = true;
doc.textDefaults.hyphenation = false;
var gridPrefs = doc.gridPreferences;
gridPrefs.baselineStart = 0;
gridPrefs.baselineDivision = 1;
gridPrefs.documentGridShown = true;
gridPrefs.horizontalGridlineDivision = 6;
gridPrefs.horizontalGridSubdivision = 6;
gridPrefs.verticalGridlineDivision = 6;
gridPrefs.verticalGridSubdivision = 6;
// Delawie Font and Colors
var delawieFont = getFont( "Delawie");
clearSwatches();
var delawieRed = newColor("Delawie Red", [ 0, 100, 100, 0]);
var delawieBlack = newColor("Delawie Black", [60, 40, 20, 100]);
// Other Fonts
var ProximaNova = getFont("Proxima Nova");
var MuseoSlab = getFont("Myriad Pro");
errorDialog("Manually apply Museo Slab to paragraph styles.");
// Make Master Spread
var masterSpread = doc.masterSpreads.item(0);
for (var i = 0; i < 2; i++) {
var marginPrefs = masterSpread.pages.item(i).marginPreferences;
setMargins(marginPrefs, [3, 6, 7]);
marginPrefs.columnCount = 2;
marginPrefs.columnGutter = 1;
}
// Populate Master Spread
for (var i = 0; i < 2; i++) {
var page = masterSpread.pages.item(i);
var delawieFrame = page.textFrames.add()
with (delawieFrame) { geometricBounds = [60, 33, 60+3, 33+12]; contents = "@delawie"; }
var logo = delawieFrame.paragraphs.item(0);
with (logo) {
appliedFont = delawieFont; pointSize = 36; leading = 36;
justification = Justification.rightAlign; fillColor = doc.colors.item("Delawie Black");
}
delawieFrame.parentStory.characters.item(0).fillColor = doc.colors.item("Delawie Red");
}
var pageNumberFrame = masterSpread.pages.item(0).textFrames.add();
with (pageNumberFrame) {
geometricBounds = [3, 45, 3+3, 45+3]; contents = SpecialCharacters.autoPageNumber;
textFramePreferences.verticalJustification = VerticalJustification.centerAlign;
}
var pageNumber = pageNumberFrame.paragraphs.item(0);
with (pageNumber) { pointSize = 18; justification = Justification.rightAlign; appliedFont = ProximaNova; }
// Paragraph Styles
var generalGroup = doc.paragraphStyleGroups.add({name: "Brochure"});
var pageTitleStyle = newParagraphStyle( "Page Title", generalGroup);
with (pageTitleStyle) { appliedFont = ProximaNova; pointSize = 18; }
var sectionTitleStyle = newParagraphStyle("Section Title", generalGroup);
with (sectionTitleStyle) { appliedFont = ProximaNova; pointSize = 12; leading = 12; baselineShift = 4; }
var bodyStyle = newParagraphStyle( "Body", generalGroup);
with (bodyStyle) { appliedFont = MuseoSlab; pointSize = 9; spaceAfter = 1; }
var captionStyle = newParagraphStyle( "Caption", generalGroup);
with (captionStyle) { appliedFont = ProximaNova; pointSize = 9; }
var resumeGroup = doc.paragraphStyleGroups.add({name: "Resume"});
var resumeNameStyle = newParagraphStyle( "Name", resumeGroup);
with (resumeNameStyle) { appliedFont = ProximaNova; pointSize = 12; leading = 12; }
var resumeTitleStyle = newParagraphStyle( "Title", resumeGroup);
with (resumeTitleStyle) { appliedFont = ProximaNova; pointSize = 10; }
var resumeProjectStyle = newParagraphStyle( "Project Name", resumeGroup);
with (resumeProjectStyle) { appliedFont = MuseoSlab; pointSize = 10; }
var resumeProjectInfoStyle = newParagraphStyle("Project Info", resumeGroup);
with (resumeProjectInfoStyle) { appliedFont = MuseoSlab; pointSize = 10; leftIndent = 1; }
// Utilities
function setMargins(prefs, values) {
prefs.top = values[0]; prefs.right = values[1];
// CSS-style margin syntax.
// If only 2 values are given, [0] will be top and bottom, [1] will be left and right.
// If 3 values are given, [0] will only be top, [1] will be left and right, [2] will only be bottom.
prefs.bottom = (values.length > 2) ? values[2] : values[0];
prefs.left = (values.length > 3) ? values[3] : values[1];
}
function errorDialog(message) {
var dialog = app.dialogs.add({name: "halp"});
with (dialog.dialogColumns.add()) { staticTexts.add({staticLabel: message}); }
dialog.show();
dialog.destroy();
}
function getFont(name) {
font = app.fonts.item(name);
try { test = font.name; }
catch (err) { errorDialog(err); }
return font;
}
function clearSwatches() {
var swatches = doc.unusedSwatches;
for (var s = 0; s < swatches.length; s++) {
swatch = doc.unusedSwatches[0];
if (swatch.name != "") { swatch.remove(); }
}
}
function newColor(name, cmyk) {
color = doc.colors.item(name);
try { test = color.name; }
catch (err) {
color = doc.colors.add({
name: name,
model: ColorModel.process,
colorValue: cmyk
});
}
}
function newParagraphStyle(name, group) {
try { test = group.name; }
catch (err) {
pStyle = doc.paragraphStyles.item(name);
try { test = pStyle.name; }
catch (err) { pStyle = doc.paragraphStyles.add({name: name}); }
pStyle.hyphenation = false;
pStyle.alignToBaseline = true;
return pStyle;
}
pStyle = group.paragraphStyles.item(name);
try { test = pStyle.name; }
catch (err) { pStyle = group.paragraphStyles.add({name: name}); }
pStyle.hyphenation = false;
pStyle.alignToBaseline = true;
return pStyle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment