Skip to content

Commit 6ab14fc

Browse files
committed
Optimized stroked text logic
1 parent 9d65cb8 commit 6ab14fc

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

jspdf.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ var jsPDF = (function(global) {
199199
},
200200
API = {},
201201
events = new PubSub(API),
202+
lastTextWasStroke = false,
202203

203204
/////////////////////
204205
// Private functions
@@ -1062,12 +1063,20 @@ var jsPDF = (function(global) {
10621063
if (!('autoencode' in flags))
10631064
flags.autoencode = true;
10641065

1066+
//TODO this might not work after object block changes
1067+
// It would be better to pass in a page context
10651068
var strokeOption = '';
10661069
if (true === flags.stroke){
1067-
strokeOption = '1 Tr\n';
1070+
if (this.lastTextWasStroke !== true){
1071+
strokeOption = '1 Tr\n';
1072+
this.lastTextWasStroke = true;
1073+
}
10681074
}
10691075
else{
1070-
strokeOption = '0 Tr\n';
1076+
if (this.lastTextWasStroke){
1077+
strokeOption = '0 Tr\n';
1078+
}
1079+
this.lastTextWasStroke = false;
10711080
}
10721081

10731082
if (typeof text === 'string') {

test/test_context2d.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@
6060
ctx.strokeText("Hello PDF", 20, y + 50);
6161
y += 50 + pad;
6262

63+
ctx.setFont("20pt courier bold");
64+
ctx.strokeText("Hello PDF", 20, y + 20);
65+
y += 20 + pad;
66+
67+
ctx.setFont("20pt courier bold");
68+
ctx.fillText("Hello PDF", 20, y + 20);
69+
y += 20 + pad;
70+
6371
ctx.restore();
6472

6573
//

0 commit comments

Comments
 (0)