/** ****************************************************************************** * * PIXOPOLIS BOOK DESIGNER * * Book page and cover creator * * (C) Kjell Post kjepo@yahoo.com * ****************************************************************************** */ isCS2 = function() { return app.version.match(/^9\./); }; var ui = "dialog { \ alignChildren: 'fill', \ bookPanel: Panel { \ orientation: 'row', alignChildren: 'left', \ text: 'Book', \ ddg: Group { \ orientation: 'row', alignChildren: 'left', \ }, \ }, \ bg: Group { \ orientation: 'row', alignment: 'right', \ pageButton: Button { text: 'Blank page' }, \ coverButton: Button { text: 'Blank cover' }, \ closeButton: Button { text: 'Close' }, \ } \ }"; var pbdwin = new Window(ui); if (isCS2()) { pbdwin.frameLocation = [200, 200]; } var pageOptions = []; pageOptions[ 0] = " 24 pages"; pageOptions[ 1] = " 32 pages"; pageOptions[ 2] = " 40 pages"; pageOptions[ 3] = " 48 pages"; pageOptions[ 4] = " 56 pages"; pageOptions[ 5] = " 64 pages"; pageOptions[ 6] = " 72 pages"; pageOptions[ 7] = " 80 pages"; pageOptions[ 8] = " 88 pages"; pageOptions[ 9] = " 96 pages" pageOptions[10] = "104 pages"; pageOptions[11] = "112 pages"; var lightPageOption = " 20 pages"; var giantPageOptions = []; giantPageOptions[ 0] = " 48 pages"; giantPageOptions[ 1] = " 50 pages"; giantPageOptions[ 2] = " 52 pages"; giantPageOptions[ 3] = " 54 pages"; giantPageOptions[ 4] = " 56 pages"; giantPageOptions[ 5] = " 58 pages"; giantPageOptions[ 6] = " 60 pages"; giantPageOptions[ 7] = " 62 pages"; giantPageOptions[ 8] = " 64 pages"; giantPageOptions[ 9] = " 66 pages"; giantPageOptions[10] = " 68 pages"; giantPageOptions[11] = " 70 pages"; giantPageOptions[12] = " 72 pages"; giantPageOptions[13] = " 74 pages"; giantPageOptions[14] = " 76 pages"; giantPageOptions[15] = " 78 pages"; giantPageOptions[16] = " 80 pages"; giantPageOptions[17] = " 82 pages"; giantPageOptions[18] = " 84 pages"; giantPageOptions[19] = " 86 pages"; giantPageOptions[20] = " 88 pages"; giantPageOptions[21] = " 90 pages"; giantPageOptions[22] = " 92 pages"; giantPageOptions[23] = " 94 pages"; giantPageOptions[24] = " 96 pages"; giantPageOptions[25] = " 98 pages"; giantPageOptions[26] = "100 pages"; giantPageOptions[27] = "102 pages"; giantPageOptions[28] = "104 pages"; giantPageOptions[29] = "106 pages"; giantPageOptions[30] = "108 pages"; giantPageOptions[31] = "110 pages"; giantPageOptions[32] = "112 pages"; var helixPageOptions = []; helixPageOptions[ 0] = " 24 pages"; helixPageOptions[ 1] = " 36 pages"; helixPageOptions[ 2] = " 48 pages"; helixPageOptions[ 3] = " 60 pages"; helixPageOptions[ 4] = " 72 pages"; helixPageOptions[ 5] = " 84 pages"; helixPageOptions[ 6] = " 96 pages"; var BOOK_HARDCOVER = 0; var BOOK_SQUARE = 1; var BOOK_LIGHT = 2; var BOOK_GIANT = 3; var BOOK_SOFTCOVER = 4; var BOOK_POCKETHOR = 5; var BOOK_POCKETVER = 6; var BOOK_HELIX = 7; var BOOK_SQUAREXL = 8; var bookOptions = []; bookOptions[BOOK_HARDCOVER] = "Hardcover"; bookOptions[BOOK_SQUARE] = "Square"; bookOptions[BOOK_LIGHT] = "Light"; bookOptions[BOOK_GIANT] = "GIANT"; bookOptions[BOOK_SOFTCOVER] = "Softcover"; bookOptions[BOOK_POCKETHOR] = "Pocket horizontal"; bookOptions[BOOK_POCKETVER] = "Pocket vertical"; bookOptions[BOOK_HELIX] = "Helix"; // Don't activate Square XL until correct spine information for 58, 60, 62 pages // are known. // bookOptions[BOOK_SQUAREXL] = "Square XL"; var pageWidth = [], pageHeight = []; var coverWidth = [], coverHeight = []; /** * Page width and height in pixels */ pageWidth[BOOK_HARDCOVER] = 4843; pageHeight[BOOK_HARDCOVER] = 3307; pageWidth[BOOK_SQUARE] = 4843; pageHeight[BOOK_SQUARE] = 2459; pageWidth[BOOK_LIGHT] = 4913; pageHeight[BOOK_LIGHT] = 3307; pageWidth[BOOK_GIANT] = 9520; pageHeight[BOOK_GIANT] = 3307; pageWidth[BOOK_SOFTCOVER] = 3323; pageHeight[BOOK_SOFTCOVER] = 2252; pageWidth[BOOK_POCKETHOR] = 4843; pageHeight[BOOK_POCKETHOR] = 1370; pageWidth[BOOK_POCKETVER] = 2669; pageHeight[BOOK_POCKETVER] = 2551; pageWidth[BOOK_HELIX] = 4654; pageHeight[BOOK_HELIX] = 3319; pageWidth[BOOK_SQUAREXL] = 6071; pageHeight[BOOK_SQUAREXL] = 3307; /* Cover width and height */ coverWidth[BOOK_HARDCOVER] = 5492; coverHeight[BOOK_HARDCOVER] = 3732; coverWidth[BOOK_SQUARE] = 5492; coverHeight[BOOK_SQUARE] = 2846; // fixed coverWidth[BOOK_LIGHT] = 4913; coverHeight[BOOK_LIGHT] = 3378; coverWidth[BOOK_GIANT] = 10642; coverHeight[BOOK_GIANT] = 3732; coverWidth[BOOK_SOFTCOVER] = 5031; coverHeight[BOOK_SOFTCOVER] = 3378; coverWidth[BOOK_POCKETHOR] = 5492; coverHeight[BOOK_POCKETHOR] = 1772; coverWidth[BOOK_POCKETVER] = 3319; coverHeight[BOOK_POCKETVER] = 2976; coverWidth[BOOK_HELIX] = 5409; coverHeight[BOOK_HELIX] = 3732; coverWidth[BOOK_SQUAREXL] = 7075; coverHeight[BOOK_SQUAREXL] = 3685; /* Spine width in pixels for Softcover book */ var softinset = []; softinset[ 24] = 35; softinset[ 32] = 45; softinset[ 40] = 52; softinset[ 48] = 59; softinset[ 56] = 69; softinset[ 64] = 76; softinset[ 72] = 83; softinset[ 80] = 92; softinset[ 88] = 99; softinset[ 96] = 106; softinset[104] = 116; softinset[112] = 123; var myPageOption = -1; var myBookOption = -1; var item; /* ============================== */ pbdwin.bookPanel.booklist = pbdwin.bookPanel.add("dropdownlist", undefined, "test"); for (var i = 0; i < bookOptions.length; i++) { item = pbdwin.bookPanel.booklist.add('item', "" + bookOptions[i]); } pbdwin.bookPanel.booklist.onChange = function() { myBookOption = parseInt(this.selection); updatePage(pbdwin.bookPanel.pagelist, myBookOption); }; pbdwin.bookPanel.booklist.selection = pbdwin.bookPanel.booklist.items[0]; /* ============================== */ pbdwin.bookPanel.pagelist = pbdwin.bookPanel.add("dropdownlist", undefined, "test"); pbdwin.bookPanel.pagelist.onChange = function() { myPageOption = parseInt(this.selection.toString()); }; activatePages(0, pageOptions.length); /* ============================== */ pbdwin.bg.pageButton.onClick = function() { makeBlankPage(myBookOption); pbdwin.close(0); } pbdwin.bg.coverButton.onClick = function() { makeCover(myBookOption, myPageOption); pbdwin.close(0); } pbdwin.bg.closeButton.onClick = function() { pbdwin.close(0); } pbdwin.show(); /** * Real code... * */ function activatePages(lo, hi) { var p = pbdwin.bookPanel.pagelist; for (var i = lo; i < hi; i++) { item = p.add('item', "" + pageOptions[i]); } p.selection = p.items[0]; } function activateLightPage() { var p = pbdwin.bookPanel.pagelist; item = p.add('item', "" + lightPageOption); p.selection = p.items[0]; } function activateGiantPages(lo, hi) { var p = pbdwin.bookPanel.pagelist; for (var i = lo; i < hi; i++) { item = p.add('item', "" + giantPageOptions[i]); } p.selection = p.items[0]; } function activateHelixPages(lo, hi) { var p = pbdwin.bookPanel.pagelist; for (var i = lo; i < hi; i++) { item = p.add('item', "" + helixPageOptions[i]); } p.selection = p.items[0]; } function updatePage(pagelist, booknr) { pagelist.removeAll(); switch (booknr) { case BOOK_HARDCOVER: case BOOK_SQUARE: case BOOK_SOFTCOVER: case BOOK_POCKETHOR: case BOOK_POCKETVER: activatePages(0, pageOptions.length); break; case BOOK_LIGHT: activateLightPage(); break; case BOOK_GIANT: case BOOK_SQUAREXL: /* Square XL has page options like Giant */ activateGiantPages(0, giantPageOptions.length); break; case BOOK_HELIX: activateHelixPages(0, helixPageOptions.length); break; } } function verticalGuide(offset) { var id5 = charIDToTypeID( "Mk " ); var desc2 = new ActionDescriptor(); var id6 = charIDToTypeID( "Nw " ); var desc3 = new ActionDescriptor(); var id7 = charIDToTypeID( "Pstn" ); var id8 = charIDToTypeID( "#Pxl" ); desc3.putUnitDouble( id7, id8, offset); var id9 = charIDToTypeID( "Ornt" ); var id10 = charIDToTypeID( "Ornt" ); var id11 = charIDToTypeID( "Vrtc" ); desc3.putEnumerated( id9, id10, id11 ); var id12 = charIDToTypeID( "Gd " ); desc2.putObject( id6, id12, desc3 ); executeAction( id5, desc2, DialogModes.NO ); } function horizontalGuide(offset) { var id13 = charIDToTypeID( "Mk " ); var desc4 = new ActionDescriptor(); var id14 = charIDToTypeID( "Nw " ); var desc5 = new ActionDescriptor(); var id15 = charIDToTypeID( "Pstn" ); var id16 = charIDToTypeID( "#Pxl" ); desc5.putUnitDouble( id15, id16, offset); var id17 = charIDToTypeID( "Ornt" ); var id18 = charIDToTypeID( "Ornt" ); var id19 = charIDToTypeID( "Hrzn" ); desc5.putEnumerated( id17, id18, id19 ); var id20 = charIDToTypeID( "Gd " ); desc4.putObject( id14, id20, desc5 ); executeAction( id13, desc4, DialogModes.NO ); } function makeBlankPage(bookIndex) { var ru = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var w = pageWidth[bookIndex]; var h = pageHeight[bookIndex]; var inset3mm = 35; /* 3mm = 35px in 300 dpi */ app.documents.add(w, h, 300, "Page", NewDocumentMode.RGB, DocumentFill.WHITE); switch (bookIndex) { case BOOK_SOFTCOVER: verticalGuide(inset3mm); verticalGuide(w - inset3mm); horizontalGuide(inset3mm); horizontalGuide(h - inset3mm); verticalGuide(w/2 - inset3mm); verticalGuide(w/2 + inset3mm); break; case BOOK_HELIX: verticalGuide(inset3mm); verticalGuide(w - inset3mm); horizontalGuide(inset3mm); horizontalGuide(h - inset3mm); verticalGuide(w/2 - 189/2); verticalGuide(w/2 + 189/2); verticalGuide(w/2 - 70/2); verticalGuide(w/2 + 70/2); break; default: verticalGuide(inset3mm); verticalGuide(w - inset3mm); verticalGuide(w/2); horizontalGuide(inset3mm); horizontalGuide(h - inset3mm); break; } app.preferences.rulerUnits = ru; } function makeCover(bookIndex, pages) { var ru = app.preferences.rulerUnits; app.preferences.rulerUnits = Units.PIXELS; var w = coverWidth[bookIndex]; var h = coverHeight[bookIndex]; var inset16mm = 188; /* 16mm = 188px in 300 dpi */ var inset3mm = 35; /* 3mm = 35px in 300 dpi */ app.documents.add(w, h, 300, "Cover", NewDocumentMode.RGB, DocumentFill.WHITE); switch (bookIndex) { case BOOK_HARDCOVER: case BOOK_SQUARE: case BOOK_POCKETHOR: case BOOK_POCKETVER: verticalGuide(inset16mm); verticalGuide(w - inset16mm); horizontalGuide(inset16mm); horizontalGuide(h - inset16mm); if (pages <= 56) { verticalGuide(w/2 - 83/2); verticalGuide(w/2 + 83/2); } else { verticalGuide(w/2 - 130/2); verticalGuide(w/2 + 130/2); } break; case BOOK_LIGHT: verticalGuide(inset3mm); verticalGuide(w - inset3mm); horizontalGuide(inset3mm); horizontalGuide(h - inset3mm); verticalGuide(w/2); break; case BOOK_GIANT: case BOOK_SQUAREXL: verticalGuide(inset16mm); verticalGuide(w - inset16mm); horizontalGuide(inset16mm); horizontalGuide(h - inset16mm); if (pages <= 56) { verticalGuide(w/2 - 83/2); verticalGuide(w/2 + 83/2); } else { verticalGuide(w/2 - 130/2); verticalGuide(w/2 + 130/2); } verticalGuide(w/2 - 600/2); verticalGuide(w/2 + 600/2); break; case BOOK_SOFTCOVER: verticalGuide(inset3mm); verticalGuide(w - inset3mm); horizontalGuide(inset3mm); horizontalGuide(h - inset3mm); verticalGuide(w/2 - softinset[pages]/2); verticalGuide(w/2 + softinset[pages]/2); break; case BOOK_HELIX: verticalGuide(inset16mm); verticalGuide(w - inset16mm); horizontalGuide(inset16mm); horizontalGuide(h - inset16mm); verticalGuide(w/2 - 177/2); verticalGuide(w/2 + 177/2); break; } app.preferences.rulerUnits = ru; }