Skip to content

Commit

Permalink
Implement getLineWidth function (#3324)
Browse files Browse the repository at this point in the history
Co-authored-by: Lukas Hollaender <lukas.hollaender@yworks.com>
  • Loading branch information
richardtorres314 and HackbrettXXX committed Dec 10, 2021
1 parent 8094918 commit e2d687c
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 8 deletions.
15 changes: 15 additions & 0 deletions src/jspdf.js
Expand Up @@ -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.
*
Expand All @@ -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;
});
Expand Down Expand Up @@ -5943,6 +5957,7 @@ function jsPDF(options) {
getTextColor: getTextColor,
getLineHeight: getLineHeight,
getLineHeightFactor: getLineHeightFactor,
getLineWidth: getLineWidth,
write: write,
getHorizontalCoordinate: getHorizontalCoordinate,
getVerticalCoordinate: getVerticalCoordinate,
Expand Down
Binary file modified test/reference/autoPaging10Pages.pdf
Binary file not shown.
Binary file modified test/reference/html-font-faces.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break-slice.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break-text.pdf
Binary file not shown.
Binary file modified test/reference/html-margin-page-break.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions test/specs/context2d.pageoverlap.spec.js
Expand Up @@ -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",
Expand Down
6 changes: 2 additions & 4 deletions test/specs/jspdf.unit.spec.js
Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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 });
Expand Down
3 changes: 1 addition & 2 deletions types/index.d.ts
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit e2d687c

Please sign in to comment.