From 49474f5926dc13be0f428922528015fb85ad563d Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Wed, 9 Dec 2020 12:32:24 +0530 Subject: [PATCH 1/7] fix #2938: textWithLink -> link centered correctly --- src/modules/annotations.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index a9207b667..ca275548c 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -363,7 +363,8 @@ import { jsPDF } from "../jspdf.js"; //TODO We really need the text baseline height to do this correctly. // Or ability to draw text on top, bottom, center, or baseline. y += height * 0.2; - this.link(x, y - height, width, height, options); + x += width * 0.5; + this.link(x - width, y - height, width, height, options); return width; }; From 4a78d4d5723de46344a182da4a38e30894a82765 Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Thu, 10 Dec 2020 18:08:30 +0530 Subject: [PATCH 2/7] Fix based on the condition --- src/modules/annotations.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index ca275548c..be94b2212 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -363,8 +363,10 @@ import { jsPDF } from "../jspdf.js"; //TODO We really need the text baseline height to do this correctly. // Or ability to draw text on top, bottom, center, or baseline. y += height * 0.2; - x += width * 0.5; - this.link(x - width, y - height, width, height, options); + if(options.align == 'center'){ + x = x - (width / 2); + } + this.link(x, y - height, width, height, options); return width; }; From 725438eef7793785a6bb4b9aedcd8a1cbce6eab1 Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Fri, 11 Dec 2020 14:59:50 +0530 Subject: [PATCH 3/7] right align added --- src/modules/annotations.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index be94b2212..0ddf6e949 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -366,6 +366,9 @@ import { jsPDF } from "../jspdf.js"; if(options.align == 'center'){ x = x - (width / 2); } + if(options.align == 'right'){ + x = x - width; + } this.link(x, y - height, width, height, options); return width; }; From 64b47329e2517e03441977144744886c82427c83 Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Sun, 13 Dec 2020 20:53:31 +0530 Subject: [PATCH 4/7] comments added to rerun build --- src/modules/annotations.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index 0ddf6e949..c45c3e0cd 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -363,6 +363,7 @@ import { jsPDF } from "../jspdf.js"; //TODO We really need the text baseline height to do this correctly. // Or ability to draw text on top, bottom, center, or baseline. y += height * 0.2; + //handle x position based on the align option if(options.align == 'center'){ x = x - (width / 2); } From 572291454b8167321b6d6eb4f8841310db6d6903 Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Mon, 14 Dec 2020 10:27:56 +0530 Subject: [PATCH 5/7] re-run build --- src/modules/annotations.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index c45c3e0cd..1d0afc876 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -365,7 +365,7 @@ import { jsPDF } from "../jspdf.js"; y += height * 0.2; //handle x position based on the align option if(options.align == 'center'){ - x = x - (width / 2); + x = x - (width / 2); //since starting from center move the x position by half of text width } if(options.align == 'right'){ x = x - width; From 237a9536609d99c91b05a0869bf9fdf056bdc491 Mon Sep 17 00:00:00 2001 From: vbinithyanandamv Date: Mon, 14 Dec 2020 20:43:59 +0530 Subject: [PATCH 6/7] Basic test added --- src/modules/annotations.js | 6 +++--- test/reference/textLinkWithAlignOptions.pdf | Bin 0 -> 4273 bytes test/specs/annotations.spec.js | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 test/reference/textLinkWithAlignOptions.pdf diff --git a/src/modules/annotations.js b/src/modules/annotations.js index 1d0afc876..6f60a0d2d 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -364,10 +364,10 @@ import { jsPDF } from "../jspdf.js"; // Or ability to draw text on top, bottom, center, or baseline. y += height * 0.2; //handle x position based on the align option - if(options.align == 'center'){ - x = x - (width / 2); //since starting from center move the x position by half of text width + if (options.align == "center") { + x = x - width / 2; //since starting from center move the x position by half of text width } - if(options.align == 'right'){ + if (options.align == "right") { x = x - width; } this.link(x, y - height, width, height, options); diff --git a/test/reference/textLinkWithAlignOptions.pdf b/test/reference/textLinkWithAlignOptions.pdf new file mode 100644 index 0000000000000000000000000000000000000000..aa1976bf9df2dd7c0a5dbb7c3c60a68037929bc8 GIT binary patch literal 4273 zcmcgv-A?016u$RUoEx;D3fuEPvqDHDAzfNlppdFn5f@G}38sn7+D?JK%=Q8L1ijpS zv7T`f?EI|AcF9`EnK>NK`R2@berE5o)jlLX^Y%Xd`}yOie?I^1F$f{;-FZhxLHFt2 zLU0+4tcUN+CIt}uZ^sKdHczKn-{wGPg7=$rNjq)X1UIaANK9x*x#zGZpDGW8h3G*4L zX&OdBhsM`6O-Y2jfuNCQ1DnmThd4h0-2D{r61NcC6k~u@kL$JaP!@uZ}PfQ2uOvJ z8bb*cc$|U&XLJK}!F)vitf>^I-wQfHlyz4cr5GsAd`g|aDbc51+ot;%1g%S`uN6 zWvEqJ?8Kwn%`Qa>%nx}^2A6NwvT^POKgR>inJ!m%pd{1OC1*#H`G?~9LvNnP+ekPs zXhgYnBM9Ev@t?Mc`;k|rT9@&O7n~;jbPy*a2!4%|lO&H90_0bm3Hz^2-H^~xaf`J4^ymh&lTsD+@QY#gmc5rfS4D7G_jn=HhX;^5Z4bZ z(%Gz`SS8}z_Kui9su228BrE{z%>Tr7N!vSNcQ~r%?n}Pt#uJ+#cG5|d?0^jQ+P0Yt zGyA(q3gqRaI5U4%VEO6qVE->C#%ljN1MzZh{5`rKwlM$qq5^BpYFgZ?1dx}L-__Hk zmyZAE`t^vq%+mgq#oIxE*BJ=9_7Th5*#z$`jrnhL{(FYCvaEhbM`f$z2!Yp`HU)Pw zZiLO@e8j$Dwj^{xI!BIcG0_YHy#9v)2gnMdM?L}52k(WmiF&*w{_}c_kDo9CH9F$oF=WP zu(02HOG6qGN;tlGsD22=8y3DfsI5xZvvf1UAV^2<<~PE7-u&Wsac`58zFT|IePBmW zyn|#q9;0ua?s@c-PVoRP65CA2(@9dZ^O)HowxE=FRr?B32qs_%a~a_bUE&@{7BWT! zx^h_-hR&rcGUHBSSw^^7`<6)O#}z%r*JWC-t%pur({sLEU5`?1_f~9B9wI%K?NY(k z*OPM12Y8`g+XpptZ9NuZ9u46C5(rX!7H2RBjw+@*>KLk}*sg L>h0~FUbO!MwC0D2 literal 0 HcmV?d00001 diff --git a/test/specs/annotations.spec.js b/test/specs/annotations.spec.js index b13f52493..9abbaf517 100644 --- a/test/specs/annotations.spec.js +++ b/test/specs/annotations.spec.js @@ -72,4 +72,18 @@ describe("Module: Annotations", () => { comparePdf(doc.output(), "insertLinkAddPage.pdf", "annotations"); }); + it("should align text link based on the align option", () => { + var doc = new jsPDF({ + unit: "px", + format: [200, 300], + floatPrecision: 2 + }); + + doc.textWithLink('Left aligned Link', (doc.internal.pageSize.getWidth() / 2), 10, { align: 'left', url: 'https://www.google.com' }); + doc.textWithLink('Center aligned Link', (doc.internal.pageSize.getWidth() / 2), 20, { align: 'center', url: 'https://www.google.com' }); + doc.textWithLink('Justify aligned Link', (doc.internal.pageSize.getWidth() / 2), 30, { align: 'justify', url: 'https://www.google.com' }); + doc.textWithLink('Right aligned Link', (doc.internal.pageSize.getWidth() / 2), 40, { align: 'right', url: 'https://www.google.com' }); + + comparePdf(doc.output(), "textLinkWithAlignOptions.pdf", "annotations"); + }); }); From ef47f97192a94e66d10da8d16c96ab36f3c840c9 Mon Sep 17 00:00:00 2001 From: Lukas Hollaender Date: Mon, 21 Dec 2020 12:33:03 +0100 Subject: [PATCH 7/7] fix textLinkWithAlignOptions reference file - use "===" instead of "==" - run prettier --- src/modules/annotations.js | 4 +-- test/reference/textLinkWithAlignOptions.pdf | Bin 4273 -> 3821 bytes test/specs/annotations.spec.js | 32 ++++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/src/modules/annotations.js b/src/modules/annotations.js index 6f60a0d2d..c65a774fd 100644 --- a/src/modules/annotations.js +++ b/src/modules/annotations.js @@ -364,10 +364,10 @@ import { jsPDF } from "../jspdf.js"; // Or ability to draw text on top, bottom, center, or baseline. y += height * 0.2; //handle x position based on the align option - if (options.align == "center") { + if (options.align === "center") { x = x - width / 2; //since starting from center move the x position by half of text width } - if (options.align == "right") { + if (options.align === "right") { x = x - width; } this.link(x, y - height, width, height, options); diff --git a/test/reference/textLinkWithAlignOptions.pdf b/test/reference/textLinkWithAlignOptions.pdf index aa1976bf9df2dd7c0a5dbb7c3c60a68037929bc8..abd1be73e01b24567f84be7b2fe28cdfd40d120d 100644 GIT binary patch delta 811 zcmZ`%&1zFY7^N7Yj98==DHZW^aj8=L^8L)6pCT#PByI#93R3-VJdM zod-*VC!ctORZ+FtRz(rSMkEFef-(JAI@oX)qk?*iUO=iMU+qeVD(P(L&E3mxwE?LF zalYmyqARETx<`tjQftp@snPDHqigLQ32HhW^I?2ZMdX z0WA!kSHx>GlL^xp>3$1unZjxc?0(VaOyYpJ8Aix#iVsm35pwZ6T-zPG$ZSj|VK zy;~WY9K1X14ksgc*xlwBJPT7Zwum+q#-nqzKIC}szXa2`_gAY%Q$fqS)oaTFF07SFVZ tDV13|WlL%8*3MpYu~)Ahcycw_FdcZ+e6`_tax@<88x?C!QS@H){{W^%tEd0~ literal 4273 zcmcgv-A?016u$RUoEx;D3fuEPvqDHDAzfNlppdFn5f@G}38sn7+D?JK%=Q8L1ijpS zv7T`f?EI|AcF9`EnK>NK`R2@berE5o)jlLX^Y%Xd`}yOie?I^1F$f{;-FZhxLHFt2 zLU0+4tcUN+CIt}uZ^sKdHczKn-{wGPg7=$rNjq)X1UIaANK9x*x#zGZpDGW8h3G*4L zX&OdBhsM`6O-Y2jfuNCQ1DnmThd4h0-2D{r61NcC6k~u@kL$JaP!@uZ}PfQ2uOvJ z8bb*cc$|U&XLJK}!F)vitf>^I-wQfHlyz4cr5GsAd`g|aDbc51+ot;%1g%S`uN6 zWvEqJ?8Kwn%`Qa>%nx}^2A6NwvT^POKgR>inJ!m%pd{1OC1*#H`G?~9LvNnP+ekPs zXhgYnBM9Ev@t?Mc`;k|rT9@&O7n~;jbPy*a2!4%|lO&H90_0bm3Hz^2-H^~xaf`J4^ymh&lTsD+@QY#gmc5rfS4D7G_jn=HhX;^5Z4bZ z(%Gz`SS8}z_Kui9su228BrE{z%>Tr7N!vSNcQ~r%?n}Pt#uJ+#cG5|d?0^jQ+P0Yt zGyA(q3gqRaI5U4%VEO6qVE->C#%ljN1MzZh{5`rKwlM$qq5^BpYFgZ?1dx}L-__Hk zmyZAE`t^vq%+mgq#oIxE*BJ=9_7Th5*#z$`jrnhL{(FYCvaEhbM`f$z2!Yp`HU)Pw zZiLO@e8j$Dwj^{xI!BIcG0_YHy#9v)2gnMdM?L}52k(WmiF&*w{_}c_kDo9CH9F$oF=WP zu(02HOG6qGN;tlGsD22=8y3DfsI5xZvvf1UAV^2<<~PE7-u&Wsac`58zFT|IePBmW zyn|#q9;0ua?s@c-PVoRP65CA2(@9dZ^O)HowxE=FRr?B32qs_%a~a_bUE&@{7BWT! zx^h_-hR&rcGUHBSSw^^7`<6)O#}z%r*JWC-t%pur({sLEU5`?1_f~9B9wI%K?NY(k z*OPM12Y8`g+XpptZ9NuZ9u46C5(rX!7H2RBjw+@*>KLk}*sg L>h0~FUbO!MwC0D2 diff --git a/test/specs/annotations.spec.js b/test/specs/annotations.spec.js index 9abbaf517..e5e364ebd 100644 --- a/test/specs/annotations.spec.js +++ b/test/specs/annotations.spec.js @@ -63,7 +63,7 @@ describe("Module: Annotations", () => { }); doc.textWithLink("Click me!", 10, 10, { - url: "https://parall.ax/", + url: "https://parall.ax/" }); doc.addPage("a4"); @@ -78,11 +78,31 @@ describe("Module: Annotations", () => { format: [200, 300], floatPrecision: 2 }); - - doc.textWithLink('Left aligned Link', (doc.internal.pageSize.getWidth() / 2), 10, { align: 'left', url: 'https://www.google.com' }); - doc.textWithLink('Center aligned Link', (doc.internal.pageSize.getWidth() / 2), 20, { align: 'center', url: 'https://www.google.com' }); - doc.textWithLink('Justify aligned Link', (doc.internal.pageSize.getWidth() / 2), 30, { align: 'justify', url: 'https://www.google.com' }); - doc.textWithLink('Right aligned Link', (doc.internal.pageSize.getWidth() / 2), 40, { align: 'right', url: 'https://www.google.com' }); + + doc.textWithLink( + "Left aligned Link", + doc.internal.pageSize.getWidth() / 2, + 10, + { align: "left", url: "https://www.google.com" } + ); + doc.textWithLink( + "Center aligned Link", + doc.internal.pageSize.getWidth() / 2, + 30, + { align: "center", url: "https://www.google.com" } + ); + doc.textWithLink( + "Justify aligned Link", + doc.internal.pageSize.getWidth() / 2, + 50, + { align: "justify", url: "https://www.google.com" } + ); + doc.textWithLink( + "Right aligned Link", + doc.internal.pageSize.getWidth() / 2, + 70, + { align: "right", url: "https://www.google.com" } + ); comparePdf(doc.output(), "textLinkWithAlignOptions.pdf", "annotations"); });