From 44ea26254312aafa91e30a154d83c5c46246adeb Mon Sep 17 00:00:00 2001 From: Marcelo Date: Sun, 4 Oct 2020 21:46:41 -0300 Subject: [PATCH 1/4] Fix links break on new page with different width/heigth --- src/modules/annotations.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index 4e44fdb12..2900c38f8 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -216,13 +216,13 @@ import { jsPDF } from "../jspdf.js"; rect = "/Rect [" + - getHorizontalCoordinateString(anno.x) + + anno.finalBounds.x + " " + - getVerticalCoordinateString(anno.y) + + anno.finalBounds.y + " " + - getHorizontalCoordinateString(anno.x + anno.w) + + anno.finalBounds.w + " " + - getVerticalCoordinateString(anno.y + anno.h) + + anno.finalBounds.h + "] "; line = ""; @@ -325,11 +325,16 @@ import { jsPDF } from "../jspdf.js"; */ jsPDFAPI.link = function(x, y, w, h, options) { var pageInfo = this.internal.getCurrentPageInfo(); + var getHorizontalCoordinateString = this.internal.getCoordinateString; + var getVerticalCoordinateString = this.internal.getVerticalCoordinateString; + pageInfo.pageContext.annotations.push({ - x: x, - y: y, - w: w, - h: h, + finalBounds: { + x: getHorizontalCoordinateString(x), + y: getVerticalCoordinateString(y), + w: getHorizontalCoordinateString(x + w), + h: getVerticalCoordinateString(y + h) + }, options: options, type: "link" }); From 09a8c9986ec75134b9e52b0a310ba85de27e8087 Mon Sep 17 00:00:00 2001 From: Marcelo Date: Mon, 5 Oct 2020 21:32:41 -0300 Subject: [PATCH 2/4] Add test for fix bug addPage with links --- test/reference/insertLinkAddPage.pdf | Bin 0 -> 3680 bytes test/specs/insertLinkAddPage.spec.js | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 test/reference/insertLinkAddPage.pdf create mode 100644 test/specs/insertLinkAddPage.spec.js diff --git a/test/reference/insertLinkAddPage.pdf b/test/reference/insertLinkAddPage.pdf new file mode 100644 index 0000000000000000000000000000000000000000..cad870e6be49b4f5ab0e6608f29dc6204b68a7a7 GIT binary patch literal 3680 zcmcIn+iv4F5Pj!YOdo> zOl6V-!*3^qPGqLG=|X0}cZQ$kG79_Z0j^CnaMv~5>cxcs+cb?ELVHP~@(ivI0SXJy z>2{tM0WYKE55N$M9IlyVSkErb&=F=UD()SZf$tiYS6yifumm^!>OxP58=!raE@isQ z)Wr85V69W2zf4BEkJH;czt7%NdLO1?92?;SJ%jUe{3BSvKqWask%3*5jz*a*HDdaG zha91oGFj)hz?esHL6)a7+z``1U_AItO!$%XXM_d}mLt*8iR;$nB?Peg z=lBW-*DuNGM;XToKC3id{%{7fJ9078*_H9jJe{XJzrDkb?-<;xWbAPdgv|^gDn{Yj zRlwXDVEVlQnAHYgf(yfODkH-jRsa^LbQ9(uKD-K+9{9#~$O!!@TH+Av%`yQE=md&N zx41{RuAs!)d-^#k!47bI2tfkS(l9H!~DaTp-4Mlx*y1;43p$bBKc^o+S zH7sV)MrNIf+Js39!%(H(mvPv|Z-*Axaa!DkALU^jEn2AmI5i&XZ!L-A?D%_lzZ&8R zFb{J)bLzzSrbB=qXTRy=X0GCI^z!%7JF9wa^7J6YZJ^d#gs)L@ zmk5mSWzt({-+LW`sv!Re$u^D=UA^`)d{kR(!8nlv6>m35CC)=CS12&KMa-uQT*t8- zSi#=r`3R4`Alciv%aO>R+e}kKU9(vn;jGzg9~)h>xfXV;W)rCB>o!#KbsJ;4tWnm^COj?`?v*~G=P8o6-hHn8H{Z}{UjZ{WurRMfS&TzE}? zzEi0;Ps1oi`JlJeH2O>G{?dt3s7lM-GD=noiqXX#FdD)&bcc@X`Q8BM((4U { + beforeAll(loadGlobals); + it("insert link after add page", () => { + const doc = new jsPDF({ + unit: "px", + format: [200, 300], + }); + + doc.textWithLink("Hello world!", 10, 10, { + url: "https://parall.ax/", + }); + + doc.addPage("a4"); + + doc.text("Format??", 10, 10); + + comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations"); + }); +}); From 4c5a60c0fa2b6afce388ca25b6b67ae3bce2f108 Mon Sep 17 00:00:00 2001 From: Marcelo Date: Mon, 5 Oct 2020 23:59:31 -0300 Subject: [PATCH 3/4] fix reference file insertLinkAddPage --- test/reference/insertLinkAddPage.pdf | Bin 3680 -> 3680 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/reference/insertLinkAddPage.pdf b/test/reference/insertLinkAddPage.pdf index cad870e6be49b4f5ab0e6608f29dc6204b68a7a7..b4218d8c32bdf8a76066b77c665dd20b432a6efa 100644 GIT binary patch delta 149 zcmaDL^FU@p7`LW@9uR7B={pytCYEI8=eZ=7q$+5*SQ%Pcm>U`y8bE-yfx+f_?q;Sq qC?6+fr(lCq4k}@%5X)s}$5mXCSX5F`l$yq6Y+z>0rK;-c?*;(e3L`E6 delta 149 zcmaDL^FU@p7`LX8o}r$hCYQc*QEFmIW`3SaVo9okhKrSvfsuisfq^NIHZ!!;H89>> z&)v)v=VEGRZfWielrnd8u{1F>ax`=^v~aUDHMMkgGd6RyQ?MbdB$mt0j;pvNv8be? SC^e1C*ucz~OI6j?-wgn5M Date: Tue, 6 Oct 2020 08:49:05 -0300 Subject: [PATCH 4/4] fix insert link after add page unit test --- test/reference/insertLinkAddPage.pdf | Bin 3680 -> 3508 bytes test/specs/annotations.spec.js | 17 +++++++++++++++++ test/specs/insertLinkAddPage.spec.js | 24 ------------------------ 3 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 test/specs/insertLinkAddPage.spec.js diff --git a/test/reference/insertLinkAddPage.pdf b/test/reference/insertLinkAddPage.pdf index b4218d8c32bdf8a76066b77c665dd20b432a6efa..523e3fd8bf216764a2926274e5f0073065367076 100644 GIT binary patch delta 617 zcmZvY!Ab)$5Qb?*(4f$RP(craQ1BEplWa1f(2M9v^wNVTp={H2u`RMK6ucDQz_Ksk zJLs#3SD(OVaNASaIH&OE|G)g1pVQBixBG@$W!)n%3Z?eoSb7bbNqWEfowlqOy`GrO zi!hi7C8>OG9-kTL-v|YnKrQv!ZKZY4ABywKah^WGB$VHcbdP}zO7`VL^Pp!-Cg}(p* delta 842 zcmcIiyGjE=6eU(NB7%*D79$ui&1CMq^SFaxKuEL**leMd1QK6t5?BK%gO#naKVh$b z;ZOJ_;+SgKsXf(l=FBy%FlmI~*4T?CCSqCyWMLyAyVM&ZC zq(UG4-e)TSFHTRz)1sP;ra~)p&da6H@?4x1qB{TyP8PQUSW!s9kse0fod8m47*XsM zJE^3Vb8Mr2ERHWGWjUA2c~y=NJF=+9t(zmC_WM}HHRyUTV|0v7I%G#tZ zSXh@G%&X~W(d)&ckD_1H_pRNJYU5{f&j*(J4{|2O`a`2bs$aI+E5gt`(i_@% diff --git a/test/specs/annotations.spec.js b/test/specs/annotations.spec.js index f053df7c3..b13f52493 100644 --- a/test/specs/annotations.spec.js +++ b/test/specs/annotations.spec.js @@ -55,4 +55,21 @@ describe("Module: Annotations", () => { }); comparePdf(doc.output(), "freetext.pdf", "annotations"); }); + it("should draw a link on the text with link after add page", () => { + const doc = new jsPDF({ + unit: "px", + format: [200, 300], + floatPrecision: 2 + }); + + doc.textWithLink("Click me!", 10, 10, { + url: "https://parall.ax/", + }); + + doc.addPage("a4"); + + doc.text("New page with difference size", 10, 10); + + comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations"); + }); }); diff --git a/test/specs/insertLinkAddPage.spec.js b/test/specs/insertLinkAddPage.spec.js deleted file mode 100644 index 5e62ce074..000000000 --- a/test/specs/insertLinkAddPage.spec.js +++ /dev/null @@ -1,24 +0,0 @@ -/* global describe, it, jsPDF, comparePdf, loadBinaryResource */ -/** - * Standard spec tests - */ - -describe("Module: Insert Link after AddPage", () => { - beforeAll(loadGlobals); - it("insert link after add page", () => { - const doc = new jsPDF({ - unit: "px", - format: [200, 300], - }); - - doc.textWithLink("Hello world!", 10, 10, { - url: "https://parall.ax/", - }); - - doc.addPage("a4"); - - doc.text("Format??", 10, 10); - - comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations"); - }); -});