From af68c5da46a4c4e950a84d53c446074edc6576fc Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 23 Aug 2023 13:44:17 -0300 Subject: [PATCH 01/14] Define PDF widths constants --- src/components/Settings/Export/Export.constants.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Settings/Export/Export.constants.js b/src/components/Settings/Export/Export.constants.js index 81fd2d841..6e588f2db 100644 --- a/src/components/Settings/Export/Export.constants.js +++ b/src/components/Settings/Export/Export.constants.js @@ -32,6 +32,10 @@ export const NOT_FOUND_IMAGE = export const EMPTY_IMAGE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg=='; +export const PICSEEPAL_GRID_WIDTH = 553; +export const PDF_GRID_WIDTH = 800; +export const PDF_BORDER_WIDTH = 2; + export const EXPORT_CONFIG_BY_TYPE = { cboard: { filename: 'board.json', From 4f3640865b0cff28d9e7611ca3aa06f5c0ebc71c Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 23 Aug 2023 13:49:17 -0300 Subject: [PATCH 02/14] Set cell width on generated PDF --- .../Settings/Export/Export.helpers.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 9b6689dcc..f7858a401 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -14,7 +14,10 @@ import { CBOARD_ZIP_OPTIONS, NOT_FOUND_IMAGE, EMPTY_IMAGE, - PDF_GRID_BORDER + PDF_GRID_BORDER, + PICSEEPAL_GRID_WIDTH, + PDF_GRID_WIDTH, + PDF_BORDER_WIDTH } from './Export.constants'; import { LABEL_POSITION_ABOVE, @@ -360,10 +363,10 @@ async function toDataURL(url, styles = {}, outputFormat = 'image/jpeg') { pdfMake.tableLayouts = { pdfGridLayout: { hLineWidth: function(i, node) { - return 2; + return PDF_BORDER_WIDTH; }, vLineWidth: function(i) { - return 2; + return PDF_BORDER_WIDTH; }, hLineColor: function(i) { return '#ffffff'; @@ -380,14 +383,25 @@ pdfMake.tableLayouts = { } }; +function getCellWidths(columns, picsee = false) { + const GRID_WIDTH = picsee ? PICSEEPAL_GRID_WIDTH : PDF_GRID_WIDTH; + const cellWidht = Math.floor( + (GRID_WIDTH - PDF_BORDER_WIDTH * columns) / columns + ); + const cellWidths = new Array(columns).fill(cellWidht); + return cellWidths; +} + async function generatePDFBoard(board, intl, breakPage = true, picsee = false) { const header = board.name || ''; const columns = board.isFixed && board.grid ? board.grid.columns : CBOARD_COLUMNS; const rows = board.isFixed && board.grid ? board.grid.rows : CBOARD_ROWS; + const cellWidths = getCellWidths(columns, picsee); + const table = { table: { - widths: '*', + widths: cellWidths, body: [{}] }, layout: 'pdfGridLayout' From 5f4ae41fb63415cb3febb3d5ee5e36f029791e74 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 23 Aug 2023 13:54:53 -0300 Subject: [PATCH 03/14] Add page break on nonfixed board --- src/components/Settings/Export/Export.helpers.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index f7858a401..6ecc37fbc 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -521,6 +521,18 @@ async function generateNonFixedBoard( // Wait for previous tile await prev; currentRow = i >= (currentRow + 1) * columns ? currentRow + 1 : currentRow; + + // Add a page break when we reach the maximum number of rows on the + // current page. + let pageBreak = false; + if ( + (currentRow + 1) % rows === 1 && + currentRow + 1 > rows && + currentRow !== 0 + ) { + pageBreak = true; + } + return await addTileToGrid( tile, intl, @@ -528,7 +540,7 @@ async function generateNonFixedBoard( rows, columns, currentRow, - false, + pageBreak, picsee ); }, Promise.resolve()); From 0f11e56c74d4e2d509aca78df85056e55458f4dd Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 23 Aug 2023 14:12:26 -0300 Subject: [PATCH 04/14] Absolute position on PicseePal background --- src/components/Settings/Export/Export.helpers.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 6ecc37fbc..e4074347d 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -934,16 +934,17 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { return { stack: [ { + absolutePosition: { x: 0, y: 3 }, text: [ { text: '\nPicseePal compatible PDF', fontSize: 18, - alignment: 'center', - bold: true + alignment: 'center' } ] }, { + absolutePosition: { x: 0, y: 48 }, canvas: [ { // rectangle showing PicseePal viewable area @@ -969,6 +970,10 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { ] }, { + absolutePosition: { + x: 0, + y: 500 + }, text: [ { text: `\nPlease print on A4 / US Letter paper at 100% scale. @@ -982,7 +987,7 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { }; }; - docDefinition.pageMargins = [144, 93, 144, 130]; + docDefinition.pageMargins = [144, 103, 144, 130]; } const lastBoardIndex = boards.length - 1; From 64d3834808659f3d603d2047960b89d1a214cd2a Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Wed, 23 Aug 2023 16:00:56 -0300 Subject: [PATCH 05/14] Fix vertical margins --- src/components/Settings/Export/Export.helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index e4074347d..2ff77370c 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -987,7 +987,7 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { }; }; - docDefinition.pageMargins = [144, 103, 144, 130]; + docDefinition.pageMargins = [144, 100, 144, 120]; } const lastBoardIndex = boards.length - 1; From 5485a6267eb749abb7199ed492c8914cec5a4119 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 13:01:56 -0300 Subject: [PATCH 06/14] Center title on PDF --- src/components/Settings/Export/Export.helpers.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 2ff77370c..28003938e 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -393,7 +393,12 @@ function getCellWidths(columns, picsee = false) { } async function generatePDFBoard(board, intl, breakPage = true, picsee = false) { - const header = board.name || ''; + const header = { + absolutePosition: { x: 0, y: 5 }, + text: board.name || '', + alignment: 'center', + fontSize: 8 + }; const columns = board.isFixed && board.grid ? board.grid.columns : CBOARD_COLUMNS; const rows = board.isFixed && board.grid ? board.grid.rows : CBOARD_ROWS; From 9015c1c42b00cec2361c454dd616abced716844a Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 13:03:07 -0300 Subject: [PATCH 07/14] Fix pageBreak on boardReduce --- src/components/Settings/Export/Export.helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 28003938e..d21a9d75d 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -998,7 +998,7 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { const lastBoardIndex = boards.length - 1; const content = await boards.reduce(async (prev, board, i) => { const prevContent = await prev; - const breakPage = i !== lastBoardIndex; + const breakPage = i !== 0; const boardPDFData = await generatePDFBoard(board, intl, breakPage, picsee); return prevContent.concat(boardPDFData); }, Promise.resolve([])); From 53354c8352513d0282a5434675be716d7e68f18c Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 13:03:52 -0300 Subject: [PATCH 08/14] Add Picseepal and Pdf images widths constants --- .../Settings/Export/Export.constants.js | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/src/components/Settings/Export/Export.constants.js b/src/components/Settings/Export/Export.constants.js index 6e588f2db..c4eea12ba 100644 --- a/src/components/Settings/Export/Export.constants.js +++ b/src/components/Settings/Export/Export.constants.js @@ -69,3 +69,65 @@ export const PDF_GRID_BORDER = { labelData: [true, false, true, true] } }; + +export const PICSEEPAL_IMAGES_WIDTH = { + column: { + 1: 130, + 2: 130, + 3: 80, + 4: 84, + 5: 75, + 6: 60, + 7: 55, + 8: 55, + 9: 45, + 10: 45, + 11: 40, + 12: 37 + }, + row: { + 1: 130, + 2: 130, + 3: 86, + 4: 59, + 5: 45, + 6: 33, + 7: 29, + 8: 23, + 9: 17, + 10: 14, + 11: 11, + 12: 9 + } +}; + +export const PDF_IMAGES_WIDTH = { + column: { + 1: 130, + 2: 130, + 3: 80, + 4: 84, + 5: 75, + 6: 60, + 7: 55, + 8: 55, + 9: 45, + 10: 45, + 11: 40, + 12: 37 + }, + row: { + 1: 130, + 2: 130, + 3: 130, + 4: 100, + 5: 80, + 6: 60, + 7: 50, + 8: 40, + 9: 35, + 10: 30, + 11: 20, + 12: 20 + } +}; From 7d7f0ed3a3b5f8bf108b3e9321dbbe3c7570143f Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 13:06:39 -0300 Subject: [PATCH 09/14] Refactor images width definition --- .../Settings/Export/Export.helpers.js | 64 ++++--------------- 1 file changed, 11 insertions(+), 53 deletions(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index d21a9d75d..2f97108dd 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -17,7 +17,9 @@ import { PDF_GRID_BORDER, PICSEEPAL_GRID_WIDTH, PDF_GRID_WIDTH, - PDF_BORDER_WIDTH + PDF_BORDER_WIDTH, + PICSEEPAL_IMAGES_WIDTH, + PDF_IMAGES_WIDTH } from './Export.constants'; import { LABEL_POSITION_ABOVE, @@ -622,59 +624,16 @@ const addTileToGrid = async ( border: PDF_GRID_BORDER[labelPosition].labelData }; - if (picsee) { - // This scales down images to fit inside PicseePal - // dimensions depending on number of columns - var colImgWidths = { - 1: 130, - 2: 130, - 3: 80, - 4: 84, - 5: 75, - 6: 60, - 7: 55, - 8: 55, - 9: 45, - 10: 45, - 11: 40, - 12: 37 - // max num of columns is 12 - }; - var rowImgWidths = { - 1: 130, - 2: 130, - 3: 86, - 4: 59, - 5: 45, - 6: 33, - 7: 32, - 8: 26, - 9: 21, - 10: 17, - 11: 14, - 12: 11 - // max num of rows is 12 - }; + const IMG_WIDTH = picsee ? PICSEEPAL_IMAGES_WIDTH : PDF_IMAGES_WIDTH; - imageData.width = Math.min(colImgWidths[columns], rowImgWidths[rows]); + imageData.width = Math.min(IMG_WIDTH.column[columns], IMG_WIDTH.row[rows]); - if (imageData.width <= 37) { - labelData.fontSize = 7; - } else if (imageData.width <= 40) { - labelData.fontSize = 8; - } else if (imageData.width <= 45) { - labelData.fontSize = 9; - } - } else { - // if not picseepal PDF, then retain old method for computing image widths - if (11 === columns || columns === 12 || rows >= 6) { - imageData.width = '59'; - labelData.fontSize = 9; - } else if (9 === columns || columns === 10 || rows === 5) { - imageData.width = '70'; - } else if (7 === columns || columns === 8) { - imageData.width = '90'; - } + if (imageData.width <= 37) { + labelData.fontSize = 7; + } else if (imageData.width <= 40) { + labelData.fontSize = 8; + } else if (imageData.width <= 45) { + labelData.fontSize = 9; } let value1, @@ -995,7 +954,6 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { docDefinition.pageMargins = [144, 100, 144, 120]; } - const lastBoardIndex = boards.length - 1; const content = await boards.reduce(async (prev, board, i) => { const prevContent = await prev; const breakPage = i !== 0; From 8ac4afb515b035b966669111431506b4bbec3ba6 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 13:07:37 -0300 Subject: [PATCH 10/14] Fix pageBreak depending on Picsee variable --- src/components/Settings/Export/Export.helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 2f97108dd..c6dca1e14 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -415,7 +415,7 @@ async function generatePDFBoard(board, intl, breakPage = true, picsee = false) { }; if (breakPage) { - table.pageBreak = 'before'; + picsee ? (table.pageBreak = 'before') : (header.pageBreak = 'before'); } if (!board.tiles || !board.tiles.length) { From 808edd5d5414959416d846ad8cd480df75998a82 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 15:04:54 -0300 Subject: [PATCH 11/14] Fix exported PDF filename --- src/components/Settings/Export/Export.helpers.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index c6dca1e14..30114df9b 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -967,7 +967,7 @@ export async function pdfExportAdapter(boards = [], intl, picsee = false) { if (pdfObj) { let prefix = getDatetimePrefix(); if (content.length === 2) { - prefix = prefix + content[0] + ' '; + prefix = prefix + content[0].text + ' '; } else { prefix = prefix + 'boardsset '; } From 72c4b2e5e1cd12df85cfbfe1c56354ebaea56ecf Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 17:21:48 -0300 Subject: [PATCH 12/14] Fix PDF export grid dimensions --- src/components/Settings/Export/Export.constants.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/components/Settings/Export/Export.constants.js b/src/components/Settings/Export/Export.constants.js index c4eea12ba..6c19a3a68 100644 --- a/src/components/Settings/Export/Export.constants.js +++ b/src/components/Settings/Export/Export.constants.js @@ -111,10 +111,10 @@ export const PDF_IMAGES_WIDTH = { 6: 60, 7: 55, 8: 55, - 9: 45, + 9: 48, 10: 45, - 11: 40, - 12: 37 + 11: 45, + 12: 45 }, row: { 1: 130, @@ -127,7 +127,7 @@ export const PDF_IMAGES_WIDTH = { 8: 40, 9: 35, 10: 30, - 11: 20, - 12: 20 + 11: 30, + 12: 25 } }; From e509f2e949bfa2b05c88c048a4ea1ce214a2a248 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 18:58:29 -0300 Subject: [PATCH 13/14] Fix images width --- .../Settings/Export/Export.constants.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/components/Settings/Export/Export.constants.js b/src/components/Settings/Export/Export.constants.js index 6c19a3a68..59c068b94 100644 --- a/src/components/Settings/Export/Export.constants.js +++ b/src/components/Settings/Export/Export.constants.js @@ -105,16 +105,16 @@ export const PDF_IMAGES_WIDTH = { column: { 1: 130, 2: 130, - 3: 80, - 4: 84, - 5: 75, - 6: 60, - 7: 55, - 8: 55, - 9: 48, - 10: 45, - 11: 45, - 12: 45 + 3: 130, + 4: 100, + 5: 100, + 6: 100, + 7: 100, + 8: 90, + 9: 80, + 10: 70, + 11: 70, + 12: 60 }, row: { 1: 130, From 052270d1c64ca850c123afc8eb400e241dfdca85 Mon Sep 17 00:00:00 2001 From: Rodri Sanchez Date: Mon, 28 Aug 2023 19:02:53 -0300 Subject: [PATCH 14/14] Small fix --- src/components/Settings/Export/Export.helpers.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/components/Settings/Export/Export.helpers.js b/src/components/Settings/Export/Export.helpers.js index 30114df9b..4fe54f055 100644 --- a/src/components/Settings/Export/Export.helpers.js +++ b/src/components/Settings/Export/Export.helpers.js @@ -387,9 +387,7 @@ pdfMake.tableLayouts = { function getCellWidths(columns, picsee = false) { const GRID_WIDTH = picsee ? PICSEEPAL_GRID_WIDTH : PDF_GRID_WIDTH; - const cellWidht = Math.floor( - (GRID_WIDTH - PDF_BORDER_WIDTH * columns) / columns - ); + const cellWidht = (GRID_WIDTH - PDF_BORDER_WIDTH * columns) / columns; const cellWidths = new Array(columns).fill(cellWidht); return cellWidths; }