Skip to content

Commit a52028f

Browse files
committed
Adding text rotation feature by dollaruw from parallax#154
1 parent 5fb8f4c commit a52028f

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

jspdf.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ PubSub implementation
11601160
@methodOf jsPDF#
11611161
@name text
11621162
*/
1163-
API.text = function (text, x, y, flags) {
1163+
API.text = function (text, x, y, flags, angle) {
11641164
/**
11651165
* Inserts something like this into PDF
11661166
BT
@@ -1193,6 +1193,17 @@ PubSub implementation
11931193
if (typeof text === 'string' && text.match(/[\n\r]/)) {
11941194
text = text.split(/\r\n|\r|\n/g);
11951195
}
1196+
if(typeof flags === 'number') {
1197+
angle = flags;
1198+
flags = null;
1199+
}
1200+
var xtra = '', mode = 'Td';
1201+
if(angle) {
1202+
angle *= (Math.PI / 180);
1203+
var c = Math.cos(angle), s = Math.sin(angle);
1204+
xtra = [f2(c),f2(s),f2(s*-1),f2(c),,].join(" ");
1205+
mode = 'Tm';
1206+
}
11961207
flags = flags || {};
11971208
if(!('noBOM' in flags)) flags.noBOM = true;
11981209
if(!('autoencode' in flags)) flags.autoencode = true;
@@ -1223,7 +1234,7 @@ PubSub implementation
12231234
activeFontKey + ' ' + activeFontSize + ' Tf\n' + // font face, style, size
12241235
(activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing
12251236
textColor +
1226-
'\n' + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' Td\n(' +
1237+
'\n' + xtra + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' ' + mode + '\n(' +
12271238
text +
12281239
') Tj\nET'
12291240
);

0 commit comments

Comments
 (0)