Skip to content

Commit

Permalink
CopyCutter: More control over cutting
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruno Herfst committed Feb 18, 2018
1 parent d4c8df6 commit c3dd20d
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 21 deletions.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
71 changes: 50 additions & 21 deletions Text_2_breakFrame.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,54 @@
// A Jongware script 7-Aug-2011
// w/Thanks to SebastiaoV to find a working version

// Updated 2018 by Bruno Herfst to use findGrep() instead of changeGrep()
// Updated 2018 by Bruno Herfst
// - Use findGrep() instead of changeGrep()
// - Add single undo
// - Move any RegEx

if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1)
{
app.selection[0].insertionPoints[0].contents = "\r";
app.selection[0].insertionPoints[-1].contents = "\r";
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = "^.+$";
app.selection[0].findGrep();
p = app.selection[0].parentTextFrames[0];
lh = (p.lines[-1].baseline - p.lines[0].baseline) / (p.lines.length-1);
top = app.selection[0].lines[0].baseline - lh;
while (app.selection[0].length > 0)
{
f = app.activeDocument.layoutWindows[0].activePage.textFrames.add ({geometricBounds:[top, p.geometricBounds[3]+2*lh, top+lh, 2*(lh+p.geometricBounds[3])-p.geometricBounds[1] ]});
app.selection[0].lines[0].move (LocationOptions.AFTER, f.texts[0]);
top += lh;
}
app.selection[0].insertionPoints[-1].contents = "";
} else
alert ("please select some text to shred");
var regex = "^(.+\n?)+$"; // Paragraphs
var toSide = true;

// Run script with single undo if supported
if (parseFloat(app.version) < 6) {
main();
} else {
app.doScript(main, ScriptLanguage.JAVASCRIPT, undefined, UndoModes.ENTIRE_SCRIPT, "Expand State Abbreviations");
};

function main() {
try {
if (app.selection.length == 1 && app.selection[0].hasOwnProperty("baseline") && app.selection[0].length > 1) {
app.findGrepPreferences = null;
app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = regex;
var result = app.selection[0].findGrep();
var i = result.length;
while ( i-- ) {
app.select(result[i]);
var ptf = app.selection[0].parentTextFrames[0];
var txt = app.selection[0].texts[0];
var topBL = txt.characters[0].baseline;
var botBL = txt.characters[-1].baseline;
// [ y1 , x1 , y2 , x2 ]
if( toSide ) {
var bnds = [ topBL, ptf.geometricBounds[3], botBL+500, ptf.geometricBounds[3]+(ptf.geometricBounds[3]-ptf.geometricBounds[1]) ];
} else {
var bnds = [ topBL, ptf.geometricBounds[1], botBL+500, ptf.geometricBounds[3] ];
}
var f = app.activeDocument.layoutWindows[0].activePage.textFrames.add ({geometricBounds:bnds});
txt.move (LocationOptions.AFTER, f.texts[0]);
var nbl = f.characters[0].baseline;
var offset = nbl - topBL;
bnds[0] -= offset;
bnds[2] -= 500;
f.geometricBounds = bnds;
}
} else {
alert ("please select some text to shred");
};
// Global error reporting
} catch ( error ) {
alert( error + " (Line " + error.line + " in file " + error.fileName + ")");
};
};

0 comments on commit c3dd20d

Please sign in to comment.