Skip to content

Implement getLineWidth function #3324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/jspdf.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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