Skip to content

Commit e2d687c

Browse files
Implement getLineWidth function (#3324)
Co-authored-by: Lukas Hollaender <[email protected]>
1 parent 8094918 commit e2d687c

9 files changed

+20
-8
lines changed

src/jspdf.js

+15
Original file line numberDiff line numberDiff line change
@@ -4935,6 +4935,19 @@ function jsPDF(options) {
49354935
};
49364936

49374937
var lineWidth = options.lineWidth || 0.200025; // 2mm
4938+
/**
4939+
* Gets the line width, default: 0.200025.
4940+
*
4941+
* @function
4942+
* @instance
4943+
* @returns {number} lineWidth
4944+
* @memberof jsPDF#
4945+
* @name getLineWidth
4946+
*/
4947+
var getLineWidth = (API.__private__.getLineWidth = API.getLineWidth = function() {
4948+
return lineWidth;
4949+
});
4950+
49384951
/**
49394952
* Sets line width for upcoming lines.
49404953
*
@@ -4948,6 +4961,7 @@ function jsPDF(options) {
49484961
var setLineWidth = (API.__private__.setLineWidth = API.setLineWidth = function(
49494962
width
49504963
) {
4964+
lineWidth = width;
49514965
out(hpf(scale(width)) + " w");
49524966
return this;
49534967
});
@@ -5943,6 +5957,7 @@ function jsPDF(options) {
59435957
getTextColor: getTextColor,
59445958
getLineHeight: getLineHeight,
59455959
getLineHeightFactor: getLineHeightFactor,
5960+
getLineWidth: getLineWidth,
59465961
write: write,
59475962
getHorizontalCoordinate: getHorizontalCoordinate,
59485963
getVerticalCoordinate: getVerticalCoordinate,

test/reference/autoPaging10Pages.pdf

0 Bytes
Binary file not shown.

test/reference/html-font-faces.pdf

0 Bytes
Binary file not shown.
-3 Bytes
Binary file not shown.
-3 Bytes
Binary file not shown.
-1 Bytes
Binary file not shown.

test/specs/context2d.pageoverlap.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ describe("Module: Context2D autoPaging", () => {
2727
"0 J",
2828
"1. w",
2929
"0 j",
30-
"0.2 w",
30+
"1. w",
3131
"1. 0. 0. RG",
3232
"0. 0. 0. rg",
3333
"1. 0. 0. RG",
3434
"0 J",
3535
"1. w",
3636
"0 j",
37-
"0.2 w",
37+
"1. w",
3838
"1. 0. 0. RG",
3939
"0. 0. 0. rg",
4040
"1. 0. 0. RG",

test/specs/jspdf.unit.spec.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -894,11 +894,9 @@ describe("Core: Unit Tests", () => {
894894

895895
it("jsPDF private function getLineWidth", () => {
896896
const doc = jsPDF({ floatPrecision: 2 });
897-
var writeArray = [];
898-
doc.__private__.setCustomOutputDestination(writeArray);
899897
doc.__private__.setLineWidth(595.28);
900898

901-
expect(writeArray).toEqual(["1687.41 w"]);
899+
expect(doc.__private__.getLineWidth()).toEqual(595.28);
902900
});
903901

904902
it("jsPDF private function setLineDash", () => {
@@ -2536,7 +2534,7 @@ This is a test too.`,
25362534
doc2.text('Some text', 10, 10, { lineHeightFactor: 1.5, baseline: 'middle' });
25372535

25382536
expect(writeArray1).toEqual(writeArray2);
2539-
});
2537+
});
25402538

25412539
it("jsPDF private function setLineCap", () => {
25422540
var doc = jsPDF({ floatPrecision: 2 });

types/index.d.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,7 @@ declare module "jspdf" {
789789
getFormObject(key: any): any;
790790
getLineHeight(): number;
791791
getLineHeightFactor(): number;
792+
getLineWidth(): number;
792793
getNumberOfPages(): number;
793794
getPageInfo(pageNumberOneBased: number): PageInfo;
794795
getR2L(): boolean;
@@ -810,9 +811,7 @@ declare module "jspdf" {
810811
style?: string | null,
811812
closed?: boolean
812813
): jsPDF;
813-
clip(): jsPDF;
814814
clipEvenOdd(): jsPDF;
815-
discardPath(): jsPDF;
816815
close(): jsPDF;
817816
stroke(): jsPDF;
818817
fill(pattern?: PatternData): jsPDF;

0 commit comments

Comments
 (0)