fix(shared): Import logo from the correct place
This commit is contained in:
parent
4ea391ba91
commit
7c4565b52a
1 changed files with 154 additions and 154 deletions
|
@ -1,11 +1,11 @@
|
|||
import PDFDocument from 'pdfkit/js/pdfkit.standalone'
|
||||
import SVGtoPDF from 'svg-to-pdfkit'
|
||||
import {logo} from '@freesewing/plugin-logo'
|
||||
import { path as logoPath } from '../icons/freesewing.js'
|
||||
|
||||
/** an svg of the logo to put on the cover page */
|
||||
const logoSvg = `<svg viewBox="-22 -36 46 50">
|
||||
<style> path {fill: none; stroke: #555555; stroke-width: 0.5} </style>
|
||||
${logo}
|
||||
<path d=${logoPath} />
|
||||
</svg>`
|
||||
|
||||
/**
|
||||
|
@ -50,7 +50,7 @@ export default class PdfMaker {
|
|||
|
||||
constructor({ svg, settings, pages, strings }) {
|
||||
this.settings = settings
|
||||
this.pagesWithContent = pages.withContent;
|
||||
this.pagesWithContent = pages.withContent
|
||||
this.svg = svg
|
||||
this.strings = strings
|
||||
|
||||
|
@ -69,27 +69,26 @@ export default class PdfMaker {
|
|||
this.svgHeight = this.rows * pages.height * mmToPoints
|
||||
}
|
||||
|
||||
|
||||
/** create the pdf document */
|
||||
initPdf() {
|
||||
// instantiate with the correct size and orientation
|
||||
this.pdf = new PDFDocument({
|
||||
size: this.settings.size.toUpperCase(),
|
||||
layout: this.settings.orientation
|
||||
layout: this.settings.orientation,
|
||||
})
|
||||
|
||||
// PdfKit wants to flush the buffer on each new page.
|
||||
// We can't save directly from inside a worker, so we have to manage the buffers ourselves so we can return a blob
|
||||
this.buffers = [];
|
||||
this.buffers = []
|
||||
|
||||
// use a listener to add new data to our buffer storage
|
||||
this.pdf.on('data', this.buffers.push.bind(this.buffers));
|
||||
this.pdf.on('data', this.buffers.push.bind(this.buffers))
|
||||
}
|
||||
|
||||
/** make the pdf */
|
||||
async makePdf() {
|
||||
await this.generateCoverPage()
|
||||
await this.generatePages();
|
||||
await this.generatePages()
|
||||
}
|
||||
|
||||
/** convert the pdf to a blob */
|
||||
|
@ -98,10 +97,12 @@ export default class PdfMaker {
|
|||
// have to do it this way so that the document flushes everything to buffers
|
||||
this.pdf.on('end', () => {
|
||||
// convert buffers to a blob
|
||||
resolve(new Blob(this.buffers, {
|
||||
type: 'application/pdf'
|
||||
}))
|
||||
});
|
||||
resolve(
|
||||
new Blob(this.buffers, {
|
||||
type: 'application/pdf',
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
// end the stream
|
||||
this.pdf.end()
|
||||
|
@ -110,7 +111,6 @@ export default class PdfMaker {
|
|||
|
||||
/** generate the cover page for the pdf */
|
||||
async generateCoverPage() {
|
||||
|
||||
// don't make one if it's not requested
|
||||
if (!this.settings.coverPage) {
|
||||
return
|
||||
|
@ -129,8 +129,8 @@ export default class PdfMaker {
|
|||
height: coverHeight,
|
||||
assumePt: false,
|
||||
// use aspect ratio to center it
|
||||
preserveAspectRatio: 'xMidYMid meet'
|
||||
});
|
||||
preserveAspectRatio: 'xMidYMid meet',
|
||||
})
|
||||
this.pageCount++
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,6 @@ export default class PdfMaker {
|
|||
this.pdf.text(this.strings.tagline, lineStart, lineLevel)
|
||||
lineLevel += 12 + 20
|
||||
|
||||
|
||||
this.pdf.fontSize(48)
|
||||
this.pdf.text(this.strings.design, lineStart, lineLevel)
|
||||
lineLevel += 48
|
||||
|
@ -154,11 +153,12 @@ export default class PdfMaker {
|
|||
await SVGtoPDF(this.pdf, logoSvg, this.pdf.page.width - lineStart - 100, lineStart, {
|
||||
width: 100,
|
||||
height: lineLevel - lineStart - 8,
|
||||
preserveAspectRatio: 'xMaxYMin meet'
|
||||
preserveAspectRatio: 'xMaxYMin meet',
|
||||
})
|
||||
|
||||
this.pdf.lineWidth(1)
|
||||
this.pdf.moveTo(lineStart, lineLevel - 8)
|
||||
this.pdf
|
||||
.moveTo(lineStart, lineLevel - 8)
|
||||
.lineTo(this.pdf.page.width - lineStart, lineLevel - 8)
|
||||
.stroke()
|
||||
|
||||
|
@ -184,7 +184,7 @@ export default class PdfMaker {
|
|||
for (var h = 0; h < this.rows; h++) {
|
||||
for (var w = 0; w < this.columns; w++) {
|
||||
// skip empty pages
|
||||
if (!this.pagesWithContent[h][w]) continue;
|
||||
if (!this.pagesWithContent[h][w]) continue
|
||||
|
||||
// position it
|
||||
let x = -w * this.pageWidth + startMargin
|
||||
|
@ -198,7 +198,7 @@ export default class PdfMaker {
|
|||
|
||||
// add the pdf to the page, offset by the page distances
|
||||
await SVGtoPDF(this.pdf, this.svg, x, y, options)
|
||||
this.pageCount++;
|
||||
this.pageCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue