From 6fbb1bf1cb816d52606980ea2bdf25bb9e8d8378 Mon Sep 17 00:00:00 2001 From: Richard Torres Date: Sun, 5 Dec 2021 02:55:19 -0500 Subject: [PATCH 1/3] feat: exposing linewidth in jspdf, updating types and unit tests --- src/jspdf.js | 15 +++++++++++++++ test/reference/autoPaging10Pages.pdf | Bin 5841 -> 5841 bytes test/specs/context2d.pageoverlap.spec.js | 4 ++-- test/specs/jspdf.unit.spec.js | 6 ++---- types/index.d.ts | 3 +-- 5 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/jspdf.js b/src/jspdf.js index a887774db..66ff8ec26 100644 --- a/src/jspdf.js +++ b/src/jspdf.js @@ -4935,6 +4935,19 @@ function jsPDF(options) { }; var lineWidth = options.lineWidth || 0.200025; // 2mm + /** + * Gets the line width, default: 0.200025. + * + * @function + * @instance + * @returns {number} lineWidth + * @memberof jsPDF# + * @name getLineWidth + */ + var getLineWidth = (API.__private__.getLineWidth = API.getLineWidth = function() { + return lineWidth; + }); + /** * Sets line width for upcoming lines. * @@ -4948,6 +4961,7 @@ function jsPDF(options) { var setLineWidth = (API.__private__.setLineWidth = API.setLineWidth = function( width ) { + lineWidth = width; out(hpf(scale(width)) + " w"); return this; }); @@ -5943,6 +5957,7 @@ function jsPDF(options) { getTextColor: getTextColor, getLineHeight: getLineHeight, getLineHeightFactor: getLineHeightFactor, + getLineWidth: getLineWidth, write: write, getHorizontalCoordinate: getHorizontalCoordinate, getVerticalCoordinate: getVerticalCoordinate, diff --git a/test/reference/autoPaging10Pages.pdf b/test/reference/autoPaging10Pages.pdf index e4b983a1655a316384709a7905463b7c57414520..432b1f549403e1161ae7212e8b2a3233bbb2ffff 100644 GIT binary patch delta 255 zcmcbpdr^0T6cdY)o`vz`Kvv7i;Y|H7j@4upW+cu>WX?VoxXdY-dX33**_9{za+FPe zz%~&sxOp!7c1AF7a|EY8r>2pfiJpNbm%ejRYGO%dex6HWNveW|iJ{G9xF^D>q$#dD2C;M`gO@6>O z5h}EKF8g*yAbWERr#7difgTWQa_Ku4r6!hS=I6O2mZU0ZxL6rlT9_Le85%%Os v4MK;R^ogG(kNn%k+MNw)Rmx-l;374v>tG^on1^q-$ diff --git a/test/specs/context2d.pageoverlap.spec.js b/test/specs/context2d.pageoverlap.spec.js index c01f6b6a3..3328d0351 100644 --- a/test/specs/context2d.pageoverlap.spec.js +++ b/test/specs/context2d.pageoverlap.spec.js @@ -27,14 +27,14 @@ describe("Module: Context2D autoPaging", () => { "0 J", "1. w", "0 j", - "0.2 w", + "1. w", "1. 0. 0. RG", "0. 0. 0. rg", "1. 0. 0. RG", "0 J", "1. w", "0 j", - "0.2 w", + "1. w", "1. 0. 0. RG", "0. 0. 0. rg", "1. 0. 0. RG", diff --git a/test/specs/jspdf.unit.spec.js b/test/specs/jspdf.unit.spec.js index b24dc2064..651cf8eff 100644 --- a/test/specs/jspdf.unit.spec.js +++ b/test/specs/jspdf.unit.spec.js @@ -894,11 +894,9 @@ describe("Core: Unit Tests", () => { it("jsPDF private function getLineWidth", () => { const doc = jsPDF({ floatPrecision: 2 }); - var writeArray = []; - doc.__private__.setCustomOutputDestination(writeArray); doc.__private__.setLineWidth(595.28); - expect(writeArray).toEqual(["1687.41 w"]); + expect(doc.__private__.getLineWidth()).toEqual(595.28); }); it("jsPDF private function setLineDash", () => { @@ -2536,7 +2534,7 @@ This is a test too.`, doc2.text('Some text', 10, 10, { lineHeightFactor: 1.5, baseline: 'middle' }); expect(writeArray1).toEqual(writeArray2); -}); + }); it("jsPDF private function setLineCap", () => { var doc = jsPDF({ floatPrecision: 2 }); diff --git a/types/index.d.ts b/types/index.d.ts index fd45e9e1f..8a9553073 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -789,6 +789,7 @@ declare module "jspdf" { getFormObject(key: any): any; getLineHeight(): number; getLineHeightFactor(): number; + getLineWidth(): number; getNumberOfPages(): number; getPageInfo(pageNumberOneBased: number): PageInfo; getR2L(): boolean; @@ -810,9 +811,7 @@ declare module "jspdf" { style?: string | null, closed?: boolean ): jsPDF; - clip(): jsPDF; clipEvenOdd(): jsPDF; - discardPath(): jsPDF; close(): jsPDF; stroke(): jsPDF; fill(pattern?: PatternData): jsPDF; From 34c43a2e143d7344485af4e1072eda0fc727948a Mon Sep 17 00:00:00 2001 From: Richard Torres Date: Tue, 7 Dec 2021 21:48:30 -0500 Subject: [PATCH 2/3] updating reference pdf --- test/reference/html-margin-page-break.pdf | Bin 4848 -> 4847 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/test/reference/html-margin-page-break.pdf b/test/reference/html-margin-page-break.pdf index b33794de7ec37b731653f68574951c40694d62a5..21cd55b9891b9efb57e5aab44d4f3c3df07c9598 100644 GIT binary patch delta 486 zcmaixyG{a85QYmwa|%Hd`faup=XP!hS!Fkzmcm*S3hdNmrLf}xEVrca6-;~rpN3K% zfdxqjOu?@T8Dd}p2i<=^+6OEg7c-skmf`eJbKGwHmU3mQoC+wETw5F&v`OGJDF zwpn$*`Zj}YWv`jpHNaj%v+R8?!ir}3=B{e y0@axqSeQ=^60(nj1R-wHPQeDZBt*teAr=ygiA5z9MX70ACWe-VT&k+B{%!!I?PO{I From bdb8a6370f32fe25ec5e70e35721e3e174d8809f Mon Sep 17 00:00:00 2001 From: Lukas Hollaender Date: Fri, 10 Dec 2021 10:51:56 +0100 Subject: [PATCH 3/3] update references --- test/reference/html-font-faces.pdf | Bin 105746 -> 105746 bytes .../html-margin-page-break-slice.pdf | Bin 24791 -> 24788 bytes .../reference/html-margin-page-break-text.pdf | Bin 24398 -> 24395 bytes 3 files changed, 0 insertions(+), 0 deletions(-) diff --git a/test/reference/html-font-faces.pdf b/test/reference/html-font-faces.pdf index e4824e1e7bf2f830e4d999971fce5bbb40ae97e1..8734ae10aa70af0fb1435507e7d70f3f53090906 100644 GIT binary patch delta 23 fcmbQVi*3>_whf0=Sd8>6jGK?CY(J*L=u-gza32WW delta 23 fcmbQVi*3>_whf0=SPb+`&6|&@Y(J*L=u-gza103C diff --git a/test/reference/html-margin-page-break-slice.pdf b/test/reference/html-margin-page-break-slice.pdf index c63b2b1407bd290bef7972b4b8e2703cb6639b18..bddee5693bff2bbcd58eb62de43e62e51b5bc1b3 100644 GIT binary patch delta 457 zcmcb9knzev#toa)_zb!1?6`_cic%AExeWC-A5;?%<}*SOn|x3$d$YIIWFbBiOz{Zc zBLboZ3I-sckf*=}W*8Zp8JJHtjO!LPN0Tu$F*i4#d@)YA-UwaB(#+HtP0Yy9!USEN zk)frT1-d#T14~N`F(YFP^Nftm4I%3I5RNr6u{51r7%yCJf?H*i?6`_cic%AExeWA-HXl$E5au^V6`XuPEqk-4)np-lQ!Emp zzDEQ^jTH<)Kp{_o3(PPwHZwGstQXf^Z-FLbXku=TA!cc6VuG&D(#+HpP0Yy9!UR*y z(%cYTospq|5k#yW;UpuVqc9X2o1Ht7-ANds1B?*FfcL( zB6NkuhNcD>Vn*f|1{#|fLVbeph_R_5hNF!w%rNb+G_jm)mN1>&m`hdF)!z*Or^aiS diff --git a/test/reference/html-margin-page-break-text.pdf b/test/reference/html-margin-page-break-text.pdf index bc1cf41454ca2e0f26faddf457ceb1daed4aca1d..0ed26c68a8fc95f71b1ae0159a6cffa5bb011013 100644 GIT binary patch delta 501 zcmX@NkMZM~Kf5MGUOg z$U8w$%*=D)ma)E7^8^+%`~yZ z5HmGLH_yn>+`tT?t{&keLkklF49%A27U*I|h6d=4F)}hTHpEb8Y=+@LBNIzh2i6-H z7#W!vVT6y7xv2?;ffg1R1{xa}LVbeph_Rs|hNF#5u*89>sqy3uanm?V&AC)nUH#nv Dk-%zE delta 447 zcmX@TkMZ0-#tqr3{N`MCc3j0JMX8CoTn2hZlcg-OH$PF;5aKsQmDnt0F-M5s2vrcQ zTHiZCkjdO&^28WnM)S!_W4am5CL6{I+nOmDfPg}t0vDKJXklq-f-YuhXkdyaW@Kn$ zYBaeKXo3ZXjJbg&hM0wkF@~6>h2i9jvBLEjW*Zq9qq_kpWQOimBO_A-BXm=Z%!~~% z#LP|2F~lq^pyqkOJ#S=eV2I&#V?!fDbj`*l<`|Y3o0^(UUK=-!!_0t7Rn^ts4FE$G BVwC^@