Skip to content

Commit e32f0a2

Browse files
committed
Add clip_fixed function to API
1 parent f21506d commit e32f0a2

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

jspdf.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,25 @@ var jsPDF = (function (global) {
13791379
out('S') // stroke path; necessary for clip to work
13801380
};
13811381

1382+
/**
1383+
* This fixes the previous function clip(). Perhaps the 'stroke path' hack was due to the missing 'n' instruction?
1384+
* We introduce the fixed version so as to not break API.
1385+
* @param fillRule
1386+
*/
1387+
API.clip_fixed = function (fillRule) {
1388+
// Call .clip() after calling drawing ops with a style argument of null
1389+
// W is the PDF clipping op
1390+
if ('evenodd' === fillRule) {
1391+
out('W*');
1392+
} else {
1393+
out('W');
1394+
}
1395+
// End the path object without filling or stroking it.
1396+
// This operator is a path-painting no-op, used primarily for the side effect of changing the current clipping path
1397+
// (see Section 4.4.3, “Clipping Path Operators”)
1398+
out('n');
1399+
};
1400+
13821401
/**
13831402
* Adds series of curves (straight lines or cubic bezier curves) to canvas, starting at `x`, `y` coordinates.
13841403
* All data points in `lines` are relative to last line origin.

0 commit comments

Comments
 (0)