Skip to content

Commit

Permalink
CONFIG put all startY into the settings as a config object
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreKelling committed Feb 16, 2024
1 parent b398c17 commit 0d7e8b5
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion dist/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jspdf-product-label",
"version": "1.1.2",
"version": "1.1.3",
"main": "src/app.js",
"author": "André Kelling",
"description": "Dymo Label PDF printing.",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jspdf-template-labelprint",
"version": "1.1.2",
"version": "1.1.3",
"main": "src/app.js",
"author": "André Kelling",
"description": "Dymo Label PDF template",
Expand Down
4 changes: 1 addition & 3 deletions src/print/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,14 @@ export default (printDataArr) => {

settings(doc);

let startY = 18;

const pageWidth = doc.internal.pageSize.width;

// <><>><><>><>><><><><><>>><><<><><><><>
// COMPONENTS
// <><>><><>><>><><><><><>>><><<><><><><>

printDataArr.forEach((printData, index) => {
titles(doc, printData, startY, pageWidth);
titles(doc, printData, pageWidth);

bulletPoints(doc, printData.bulletPoints, pageWidth);

Expand Down
2 changes: 1 addition & 1 deletion src/print/partials/bullet-points.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (doc, bulletPoints, pageWidth) => {
}

const startX = 2;
let startY = 37;
let startY = doc.vars.startY.bulletPoints;
const lineSpacing = doc.vars.lineSpacing - 1.6;

doc.setFontSize(doc.vars.fontSizes.NormalFontSize);
Expand Down
2 changes: 1 addition & 1 deletion src/print/partials/logo.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (doc, logo) => {
return;
}

const startY = 1;
const startY = doc.vars.startY.logo;;
const pageWidth = doc.internal.pageSize.width;
const pageWidthInPx = Math.round((pageWidth - 4) * mmDpiFactor); // minus 4mm, 2mm spacing for each side
const maxHeightLogo = 18; // in mm from first startY for the productName
Expand Down
2 changes: 1 addition & 1 deletion src/print/partials/product-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (doc, productCode, pageWidth) => {
return;
}
const pageCenterX = pageWidth / 2;
let startY = 55;
let startY = doc.vars.startY.productCode;

doc.setFontSize(doc.vars.fontSizes.SmallFontSize);

Expand Down
2 changes: 1 addition & 1 deletion src/print/partials/product-id.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default (doc, productId, pageWidth) => {
return;
}
const pageCenterX = pageWidth / 2;
let startY = 86;
let startY = doc.vars.startY.productId;

doc.setFontSize(doc.vars.fontSizes.IdFontSize);

Expand Down
2 changes: 1 addition & 1 deletion src/print/partials/qr-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default (doc, qrCode, pageWidth) => {
if (!qrCode) {
return;
}
const startY = 57;
const startY = doc.vars.startY.qrCode;
const qrCodeDimension = 63;
const maxWidthInPx = qrCodeDimension;
const maxHeightInPx = qrCodeDimension;
Expand Down
9 changes: 9 additions & 0 deletions src/print/partials/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ export default (doc) => {
// SETTINGS
// <><>><><>><>><><><><><>>><><<><><><><>

doc.vars.startY = {
logo: 1,
titles:14,
bulletPoints:37,
productCode:55,
qrCode:57,
productId:86
};

doc.vars.fontSizes = {
TitleFontSize:14,
SubTitleFontSize:12,
Expand Down
4 changes: 2 additions & 2 deletions src/print/partials/titles.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import JsPDF from 'jspdf';
*
* @param {JsPDF} doc
* @param {PrintData} printData
* @param {number} startY
* @param {number} pageWidth
*/
export default (doc, printData, startY, pageWidth) => {
export default (doc, printData, pageWidth) => {
const pageCenterX = pageWidth / 2;
let startY = doc.vars.startY.titles;

doc.setFontSize(doc.vars.fontSizes.TitleFontSize);
const productName = printData.productName;
Expand Down

0 comments on commit 0d7e8b5

Please sign in to comment.