documenting
This commit is contained in:
parent
ffdebf2e8e
commit
e9cad60778
3 changed files with 47 additions and 1 deletions
|
@ -81,6 +81,7 @@ function setCutOnFold(store, p1, p2) {
|
||||||
return store
|
return store
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Get a list of fabrics used by the pattern for the given settings */
|
||||||
function getCutFabrics(store, settings) {
|
function getCutFabrics(store, settings) {
|
||||||
const cutlist = store.get('cutlist')
|
const cutlist = store.get('cutlist')
|
||||||
const list = settings.only ? [].concat(settings.only) : Object.keys(cutlist)
|
const list = settings.only ? [].concat(settings.only) : Object.keys(cutlist)
|
||||||
|
|
|
@ -24,6 +24,15 @@ export const defaultPdfSettings = {
|
||||||
cutlist: true,
|
cutlist: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instantiate a pattern that uses plugins theme, i18n, and cutlist
|
||||||
|
* @param {Design} design the design to construct the pattern from
|
||||||
|
* @param {Object} gist the gist
|
||||||
|
* @param {Object} overwrite settings to overwrite gist settings with
|
||||||
|
* @param {string} format the export format this pattern will be prepared for
|
||||||
|
* @param {function} t the i18n function
|
||||||
|
* @return {Pattern} a pattern
|
||||||
|
*/
|
||||||
const themedPattern = (design, gist, overwrite, format, t) => {
|
const themedPattern = (design, gist, overwrite, format, t) => {
|
||||||
const pattern = new design({ ...gist, ...overwrite })
|
const pattern = new design({ ...gist, ...overwrite })
|
||||||
|
|
||||||
|
@ -34,7 +43,18 @@ const themedPattern = (design, gist, overwrite, format, t) => {
|
||||||
|
|
||||||
return pattern
|
return pattern
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate svgs of all cutting layouts for the pattern
|
||||||
|
* @param {Pattern} pattern the pattern to generate cutting layouts for
|
||||||
|
* @param {Design} design the design constructor for the pattern
|
||||||
|
* @param {Object} gist the gist
|
||||||
|
* @param {string} format the export format this pattern will be prepared for
|
||||||
|
* @param {function} t the i18n function
|
||||||
|
* @return {Object} a dictionary of svgs and related translation strings, keyed by fabric
|
||||||
|
*/
|
||||||
const generateCutLayouts = (pattern, design, gist, format, t) => {
|
const generateCutLayouts = (pattern, design, gist, format, t) => {
|
||||||
|
// get the fabrics from the already drafted base pattern
|
||||||
const fabrics = pattern.setStores[pattern.activeSet].cutlist.getCutFabrics(
|
const fabrics = pattern.setStores[pattern.activeSet].cutlist.getCutFabrics(
|
||||||
pattern.settings[0]
|
pattern.settings[0]
|
||||||
) || ['fabric']
|
) || ['fabric']
|
||||||
|
@ -42,15 +62,22 @@ const generateCutLayouts = (pattern, design, gist, format, t) => {
|
||||||
|
|
||||||
const isImperial = gist.units === 'imperial'
|
const isImperial = gist.units === 'imperial'
|
||||||
const cutLayouts = {}
|
const cutLayouts = {}
|
||||||
|
// each fabric
|
||||||
fabrics.forEach((f) => {
|
fabrics.forEach((f) => {
|
||||||
|
// get the settings and layout for that fabric
|
||||||
const fabricSettings = fabricSettingsOrDefault(gist, f)
|
const fabricSettings = fabricSettingsOrDefault(gist, f)
|
||||||
const fabricLayout = get(gist, ['layouts', 'cuttingLayout', f], true)
|
const fabricLayout = get(gist, ['layouts', 'cuttingLayout', f], true)
|
||||||
|
|
||||||
|
// make a new pattern
|
||||||
const fabricPattern = themedPattern(design, gist, { layout: fabricLayout }, format, t)
|
const fabricPattern = themedPattern(design, gist, { layout: fabricLayout }, format, t)
|
||||||
|
// add cut layout plugin and fabric plugin
|
||||||
.use(cutLayoutPlugin(f, fabricSettings.grainDirection))
|
.use(cutLayoutPlugin(f, fabricSettings.grainDirection))
|
||||||
.use(fabricPlugin({ ...fabricSettings, printStyle: true, setPatternSize: 'width' }))
|
.use(fabricPlugin({ ...fabricSettings, printStyle: true, setPatternSize: 'width' }))
|
||||||
|
|
||||||
|
// draft and render
|
||||||
fabricPattern.draft()
|
fabricPattern.draft()
|
||||||
const svg = fabricPattern.render()
|
const svg = fabricPattern.render()
|
||||||
|
// include translations
|
||||||
cutLayouts[f] = {
|
cutLayouts[f] = {
|
||||||
svg,
|
svg,
|
||||||
title: t('plugin:' + f),
|
title: t('plugin:' + f),
|
||||||
|
|
|
@ -29,6 +29,8 @@ export class PdfMaker {
|
||||||
buffers
|
buffers
|
||||||
/** translated strings to add to the cover page */
|
/** translated strings to add to the cover page */
|
||||||
strings
|
strings
|
||||||
|
/** cutting layout svgs and strings */
|
||||||
|
cutLayouts
|
||||||
|
|
||||||
/** the usable width (excluding margin) of the pdf page, in points */
|
/** the usable width (excluding margin) of the pdf page, in points */
|
||||||
pageWidth
|
pageWidth
|
||||||
|
@ -124,6 +126,7 @@ export class PdfMaker {
|
||||||
await this.generateSvgPage(this.svg)
|
await this.generateSvgPage(this.svg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** generate a page that has an svg centered in it below any text */
|
||||||
async generateSvgPage(svg) {
|
async generateSvgPage(svg) {
|
||||||
//abitrary margin for visual space
|
//abitrary margin for visual space
|
||||||
let coverMargin = 85
|
let coverMargin = 85
|
||||||
|
@ -138,8 +141,12 @@ export class PdfMaker {
|
||||||
// use aspect ratio to center it
|
// use aspect ratio to center it
|
||||||
preserveAspectRatio: 'xMidYMid meet',
|
preserveAspectRatio: 'xMidYMid meet',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// increment page count
|
||||||
this.pageCount++
|
this.pageCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** generate the title for the cover page */
|
||||||
async generateCoverPageTitle() {
|
async generateCoverPageTitle() {
|
||||||
this.addText('FreeSewing', 28)
|
this.addText('FreeSewing', 28)
|
||||||
.addText(this.strings.tagline, 12, 20)
|
.addText(this.strings.tagline, 12, 20)
|
||||||
|
@ -162,6 +169,7 @@ export class PdfMaker {
|
||||||
this.addText(this.strings.url, 10)
|
this.addText(this.strings.url, 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** generate the title for a cutting layout page */
|
||||||
async generateCutLayoutTitle(fabricTitle, fabricDimensions) {
|
async generateCutLayoutTitle(fabricTitle, fabricDimensions) {
|
||||||
this.addText(this.strings.cuttingLayout, 12, 2).addText(fabricTitle, 28)
|
this.addText(this.strings.cuttingLayout, 12, 2).addText(fabricTitle, 28)
|
||||||
|
|
||||||
|
@ -175,6 +183,7 @@ export class PdfMaker {
|
||||||
this.addText(fabricDimensions, 16)
|
this.addText(fabricDimensions, 16)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** generate all cutting layout pages */
|
||||||
async generateCutLayoutPages() {
|
async generateCutLayoutPages() {
|
||||||
if (!this.settings.cutlist || !this.cutLayouts) return
|
if (!this.settings.cutlist || !this.cutLayouts) return
|
||||||
|
|
||||||
|
@ -216,15 +225,24 @@ export class PdfMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Reset to a clean page */
|
||||||
nextPage() {
|
nextPage() {
|
||||||
// if no pages have been made, we can use the current
|
// set the line level back to the top
|
||||||
this.lineLevel = lineStart
|
this.lineLevel = lineStart
|
||||||
|
|
||||||
|
// if no pages have been made, we can use the current
|
||||||
if (this.pageCount === 0) return
|
if (this.pageCount === 0) return
|
||||||
|
|
||||||
// otherwise make a new page
|
// otherwise make a new page
|
||||||
this.pdf.addPage()
|
this.pdf.addPage()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add Text to the page at the current line level
|
||||||
|
* @param {String} text the text to add
|
||||||
|
* @param {Number} fontSize the size for the text
|
||||||
|
* @param {Number} marginBottom additional margin to add below the text
|
||||||
|
*/
|
||||||
addText(text, fontSize, marginBottom = 0) {
|
addText(text, fontSize, marginBottom = 0) {
|
||||||
this.pdf.fontSize(fontSize)
|
this.pdf.fontSize(fontSize)
|
||||||
this.pdf.text(text, 50, this.lineLevel)
|
this.pdf.text(text, 50, this.lineLevel)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue