Skip to content

Commit f37eaa6

Browse files
authored
Merge pull request #368 from basiljs/dev-pasteinto
adding pasteInto()
2 parents fd61fc8 + 90b3464 commit f37eaa6

File tree

5 files changed

+135
-4
lines changed

5 files changed

+135
-4
lines changed

basil.js

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,7 +2663,7 @@ var isString = pub.isString = function(str) {
26632663
};
26642664

26652665
/**
2666-
* @summary Checks wether a var is an InDesign text object.
2666+
* @summary Checks whether a var is an InDesign text object.
26672667
* @description Checks whether a var is an InDesign text object, returns `true` if this is the case.
26682668
* NB: a InDesign text frame will return `false` as it is just a container holding text. So you could say that `isText()` refers to all the things inside a text frame.
26692669
*
@@ -4009,6 +4009,71 @@ pub.objectStyle = function(itemOrName, props) {
40094009
return style;
40104010
};
40114011

4012+
/**
4013+
* @summary Paste one page item into another.
4014+
* @description Paste the source page item into the destination item, which then acts like a clipping mask. Optionally, set to a variable, to immediately access the new page item inside your destination.
4015+
*
4016+
* @cat Document
4017+
* @subcat Page Items
4018+
* @method pasteInto
4019+
*
4020+
* @param {PageItem} source The page item to copy.
4021+
* @param {PageItem} destination The page item to paste the source into.
4022+
* @return {Object} The new page item inside the destination.
4023+
*
4024+
* @example <caption>Use ellipse as clipping mask for textframe.</caption>
4025+
* noStroke();
4026+
* textSize(50);
4027+
*
4028+
* fill(0);
4029+
* var myText = text(LOREM, 0, 0, width, height);
4030+
*
4031+
* noFill();
4032+
* var myMask = ellipse(width / 2, height / 2, width / 2, height / 2);
4033+
*
4034+
* myMaskItem = pasteInto(myText, myMask);
4035+
*
4036+
* property(myMaskItem, 'fillColor', color(0, 255, 0));
4037+
*
4038+
* @example <caption>Use ellipse as clipping mask for rect.</caption>
4039+
* noStroke();
4040+
*
4041+
* fill(255, 0, 0);
4042+
* var myRect = rect(0, 0, width / 2, height / 2);
4043+
*
4044+
* fill(0, 0, 255);
4045+
* var myMask = ellipse(width / 2, height / 2, width / 2, height / 2);
4046+
*
4047+
* myMaskItem = pasteInto(myRect, myMask);
4048+
*
4049+
* property(myMaskItem, 'fillColor', color(255, 0, 255));
4050+
*/
4051+
pub.pasteInto = function(source, destination) {
4052+
checkNull(source);
4053+
checkNull(destination);
4054+
4055+
// temp store previous selection
4056+
var tempSelection = app.selection;
4057+
4058+
// set source to app clipboard
4059+
app.selection = source;
4060+
app.copy();
4061+
4062+
// paste source into destination
4063+
app.selection = destination;
4064+
app.pasteInto();
4065+
4066+
// return selection
4067+
app.selection = tempSelection;
4068+
4069+
// return new pageItem inside destination
4070+
if(destination.pageItems[0].hasOwnProperty('texts')){
4071+
return destination.pageItems[0].texts[0];
4072+
}else{
4073+
return destination.pageItems[0];
4074+
}
4075+
};
4076+
40124077
/**
40134078
* @summary Returns the first selected object or selects an object.
40144079
* @description If no argument is given, returns the first currently selected object. If a page item is given as argument, the page item will be selected.
@@ -4940,7 +5005,7 @@ pub.SCRIPTNAME = scriptName;
49405005
* @subcat Constants
49415006
* @property VERSION {String}
49425007
*/
4943-
pub.VERSION = "2.0.0-beta";
5008+
pub.VERSION = "2.0.0-beta 2021-01-04";
49445009

49455010
// ----------------------------------------
49465011
// src/includes/image.js

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ basil.js x.x.x DAY MONTH YEAR
6060
+ Added saveCSV() to stringify data and save it as CSV file in one step
6161
+ Added CSV.parse() and CSV.stringify() to replace CSV.decode() and CSV.encode()
6262
parse and stringify accept optional 2nd parameter for custom delimiter.
63+
+ Added pasteInto() enabling using page items as clipping masks
6364

6465
* translate(), rotate() and scale() now behave like they do in Processing and change the current matrix
6566
* basil scripts will by default use the user's default units or the current units of the document,

src/includes/data.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ var isString = pub.isString = function(str) {
12001200
};
12011201

12021202
/**
1203-
* @summary Checks wether a var is an InDesign text object.
1203+
* @summary Checks whether a var is an InDesign text object.
12041204
* @description Checks whether a var is an InDesign text object, returns `true` if this is the case.
12051205
* NB: a InDesign text frame will return `false` as it is just a container holding text. So you could say that `isText()` refers to all the things inside a text frame.
12061206
*

src/includes/document.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,71 @@ pub.objectStyle = function(itemOrName, props) {
12181218
return style;
12191219
};
12201220

1221+
/**
1222+
* @summary Paste one page item into another.
1223+
* @description Paste the source page item into the destination item, which then acts like a clipping mask. Optionally, set to a variable, to immediately access the new page item inside your destination.
1224+
*
1225+
* @cat Document
1226+
* @subcat Page Items
1227+
* @method pasteInto
1228+
*
1229+
* @param {PageItem} source The page item to copy.
1230+
* @param {PageItem} destination The page item to paste the source into.
1231+
* @return {Object} The new page item inside the destination.
1232+
*
1233+
* @example <caption>Use ellipse as clipping mask for textframe.</caption>
1234+
* noStroke();
1235+
* textSize(50);
1236+
*
1237+
* fill(0);
1238+
* var myText = text(LOREM, 0, 0, width, height);
1239+
*
1240+
* noFill();
1241+
* var myMask = ellipse(width / 2, height / 2, width / 2, height / 2);
1242+
*
1243+
* myMaskItem = pasteInto(myText, myMask);
1244+
*
1245+
* property(myMaskItem, 'fillColor', color(0, 255, 0));
1246+
*
1247+
* @example <caption>Use ellipse as clipping mask for rect.</caption>
1248+
* noStroke();
1249+
*
1250+
* fill(255, 0, 0);
1251+
* var myRect = rect(0, 0, width / 2, height / 2);
1252+
*
1253+
* fill(0, 0, 255);
1254+
* var myMask = ellipse(width / 2, height / 2, width / 2, height / 2);
1255+
*
1256+
* myMaskItem = pasteInto(myRect, myMask);
1257+
*
1258+
* property(myMaskItem, 'fillColor', color(255, 0, 255));
1259+
*/
1260+
pub.pasteInto = function(source, destination) {
1261+
checkNull(source);
1262+
checkNull(destination);
1263+
1264+
// temp store previous selection
1265+
var tempSelection = app.selection;
1266+
1267+
// set source to app clipboard
1268+
app.selection = source;
1269+
app.copy();
1270+
1271+
// paste source into destination
1272+
app.selection = destination;
1273+
app.pasteInto();
1274+
1275+
// return selection
1276+
app.selection = tempSelection;
1277+
1278+
// return new pageItem inside destination
1279+
if(destination.pageItems[0].hasOwnProperty('texts')){
1280+
return destination.pageItems[0].texts[0];
1281+
}else{
1282+
return destination.pageItems[0];
1283+
}
1284+
};
1285+
12211286
/**
12221287
* @summary Returns the first selected object or selects an object.
12231288
* @description If no argument is given, returns the first currently selected object. If a page item is given as argument, the page item will be selected.

src/includes/environment.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,4 +452,4 @@ pub.SCRIPTNAME = scriptName;
452452
* @subcat Constants
453453
* @property VERSION {String}
454454
*/
455-
pub.VERSION = "2.0.0-beta";
455+
pub.VERSION = "2.0.0-beta 2021-01-04";

0 commit comments

Comments
 (0)