Skip to content
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

#1363 Add notes to pdf export #1625

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
41 changes: 30 additions & 11 deletions src/js/exporters/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const app = require('electron').remote.app
find the longest string of dialogue and text
how much vertical space I need for it?
make thumb fit in that space

*/


Expand Down Expand Up @@ -59,7 +59,7 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
// this is the grid box size
let boxSize = [(documentSize[docwidthIdx]-margin[0]-margin[2]-(spacing * (boxesDim[0]-1)))/boxesDim[0],
(documentSize[docheightIdx]-margin[1]-margin[3]-headerHeight-(spacing * (boxesDim[1])))/boxesDim[1] ]

// get the longest string in the boards
// find how tall it is
let longest = 0
Expand All @@ -69,6 +69,7 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
let val = 0
if( boardData.boards[i].dialogue ) { val += boardData.boards[i].dialogue.length }
if( boardData.boards[i].action ) { val += boardData.boards[i].action.length }
if( boardData.boards[i].notes ) { val += boardData.boards[i].notes.length }

if (val > longest) {
longest = val
Expand All @@ -84,11 +85,16 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
doc.font('bold')
textHeight += doc.heightOfString(boardData.boards[index].dialogue, {width: boxSize[0], align: 'center'});
}
if( boardData.boards[index].action ) {
if( boardData.boards[index].action ) {
doc.font('italic')
textHeight += doc.heightOfString(boardData.boards[index].action, {width: boxSize[0], align: 'left'});
}
textHeight += (boardData.boards[currentBoard].action) ? 17 : 10;
if( boardData.boards[index].notes ) {
textHeight += doc.heightOfString(boardData.boards[index].notes, {width: boxSize[0], align: 'right'});
}
textHeight = 10;
textHeight += boardData.boards[currentBoard].action ? 7 : 0;
textHeight += boardData.boards[currentBoard].notes ? 7 : 0;
}

// calculate imgSize
Expand Down Expand Up @@ -138,7 +144,7 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
doc.font('thin')
doc.fontSize(5)
doc.text('DRAFT: ' + moment().format('LL').toUpperCase(), margin[0], margin[1]+13+5+2+2, {align: 'left'})

doc.fontSize(7)
doc.text('Page: ' + (i+1) + ' / ' + pages, documentSize[docwidthIdx]-margin[2]-50, margin[1], {width: 50, align: 'right'})

Expand Down Expand Up @@ -179,7 +185,7 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
doc.fontSize(4)
doc.text(util.msToTime(boardData.boards[currentBoard].time), x+offset+imgSize[0]-40, y-6, {width: 40, align: 'right'})

let textOffset = ( boardData.boards[currentBoard].action || boardData.boards[currentBoard].dialogue ) ? 5 : 0
let textOffset = ( boardData.boards[currentBoard].action || boardData.boards[currentBoard].dialogue || boardData.boards[currentBoard].notes ) ? 5 : 0
let imgAligned = false

doc.fontSize(7)
Expand All @@ -196,15 +202,15 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa

if (shrinkedImg) {
let metaHeight = doc.heightOfString(boardData.boards[currentBoard].dialogue, {width: imgSize[0], align: 'center'})
if( boardData.boards[currentBoard].action ) {
if( boardData.boards[currentBoard].action ) {

if (stringContainsForeign(boardData.boards[currentBoard].action)) {
doc.font('fallback')
} else {
doc.font('italic')
}
metaHeight += doc.heightOfString(boardData.boards[currentBoard].action, {width: imgSize[0], align: 'left'})

if (stringContainsForeign(boardData.boards[currentBoard].dialogue)) {
doc.font('fallback')
} else {
Expand All @@ -215,13 +221,16 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
imgAligned = textHeight >= metaHeight
}


doc.text(boardData.boards[currentBoard].dialogue, x+(imgAligned ? offset : 0),y+imgSize[1]+textOffset, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'center'})
textOffset += doc.heightOfString(boardData.boards[currentBoard].dialogue, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'center'})

if( boardData.boards[currentBoard].action) {
textOffset += 7
}
if( boardData.boards[currentBoard].notes) {
textOffset += 7
}
}

if (boardData.boards[currentBoard].action) {
Expand All @@ -238,6 +247,16 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
doc.text(boardData.boards[currentBoard].action, x+(imgAligned ? offset : 0),y+imgSize[1]+textOffset, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'left'})
textOffset += doc.heightOfString(boardData.boards[currentBoard].action, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'left'})
}
if (boardData.boards[currentBoard].notes) {
doc.font('fallback')

if (shrinkedImg && !boardData.boards[currentBoard].dialogue) {
imgAligned = (textHeight > (doc.heightOfString(boardData.boards[currentBoard].notes, {width: imgSize[0], align: 'left'}) + 5))
}

doc.text(boardData.boards[currentBoard].notes, x+(imgAligned ? offset : 0),y+imgSize[1]+textOffset, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'left'})
textOffset += doc.heightOfString(boardData.boards[currentBoard].notes, {width: imgAligned ? imgSize[0] : boxSize[0], align: 'left'})
}
currentBoard++
}
}
Expand Down Expand Up @@ -270,8 +289,8 @@ const generatePDF = (paperSize, layout='landscape', rows, cols, spacing, boardDa
height: margin[3] - 12
}
let src = { width: watermarkDimensions[0], height: watermarkDimensions[1] }
let [x, y, w, h] = util.fitToDst(dst, src)
let [x, y, w, h] = util.fitToDst(dst, src)

doc.image(
watermarkImagePath,
doc.page.width - w - margin[2],
Expand Down