Skip to content
Merged

C2d #404

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions jspdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ var jsPDF = (function(global) {
},
API = {},
events = new PubSub(API),
lastTextWasStroke = false,

/////////////////////
// Private functions
Expand Down Expand Up @@ -963,7 +964,17 @@ var jsPDF = (function(global) {
'getNumberOfPages' : function() {
return pages.length - 1;
},
'pages' : pages
'pages' : pages,
'out' : out,
'f2' : f2,
'getPageInfo' : function(pageNumberOneBased){
var objId = (pageNumberOneBased - 1) * 2 + 3;
return {objId:objId, pageNumber:pageNumberOneBased};
},
'getCurrentPageInfo' : function(){
var objId = (currentPage - 1) * 2 + 3;
return {objId:objId, pageNumber:currentPage};
}
};

/**
Expand Down Expand Up @@ -1055,7 +1066,23 @@ var jsPDF = (function(global) {
flags.noBOM = true;
if (!('autoencode' in flags))
flags.autoencode = true;


//TODO this might not work after object block changes
// It would be better to pass in a page context
var strokeOption = '';
if (true === flags.stroke){
if (this.lastTextWasStroke !== true){
strokeOption = '1 Tr\n';
this.lastTextWasStroke = true;
}
}
else{
if (this.lastTextWasStroke){
strokeOption = '0 Tr\n';
}
this.lastTextWasStroke = false;
}

if (typeof text === 'string') {
text = ESC(text);
} else if (text instanceof Array) {
Expand Down Expand Up @@ -1085,6 +1112,7 @@ var jsPDF = (function(global) {
'BT\n/' +
activeFontKey + ' ' + activeFontSize + ' Tf\n' + // font face, style, size
(activeFontSize * lineHeightProportion) + ' TL\n' + // line spacing
strokeOption +// stroke option
textColor +
'\n' + xtra + f2(x * k) + ' ' + f2((pageHeight - y) * k) + ' ' + mode + '\n(' +
text +
Expand Down
6 changes: 3 additions & 3 deletions jspdf.plugin.annotations.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@
line = '<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /A <</S /URI /URI (' + anno.options.url + ') >>';
} else if (anno.options.pageNumber) {
// first page is 0
var pageObjId = anno.options.pageNumber * 2 + 1;
line = '<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /Dest [' + pageObjId + " 0 R";
var info = this.internal.getPageInfo(anno.options.pageNumber);
line = '<</Type /Annot /Subtype /Link ' + rect + '/Border [0 0 0] /Dest [' + info.objId + " 0 R";
anno.options.magFactor = anno.options.magFactor || "XYZ";
switch (anno.options.magFactor) {
case 'Fit':
Expand Down Expand Up @@ -153,7 +153,7 @@
*/
jsPDFAPI.link = function(x,y,w,h,options) {
'use strict';
this.annotationPlugin.annotations[this.internal.getNumberOfPages()].push({
this.annotationPlugin.annotations[this.internal.getCurrentPageInfo().pageNumber].push({
x : x,
y : y,
w : w,
Expand Down
Loading