Design guide
Hi there and welcome to this guide that explains how FreeSewing designs work.
it's about what goes on under the hood each time a sewing pattern is generated by FreeSewing.
This illustration is a good starting point to gain a better understanding of the structure of a FreeSewing design:
- Preview
- Code
- X-Ray
({ PointpointsPathpathsoptionspart }) => {
// Draws a w*h boxreturns a Path object
const box = (nameoriginwidthheightclasses='fabric') => {
let base = height
if (width < height) base = width
let t = base
points[name + 'TopLeft'] = new Point(origin.xorigin.y)
points[name + 'BottomLeft'] = new Point(origin.xorigin.y + height)
points[name + 'BottomRight'] = new Point(
origin.x + width,
origin.y + height
)
points[name + 'TopRight'] = new Point(origin.x + widthorigin.y)
points[name + 'Mid'] = points[name + 'TopLeft'].shiftFractionTowards(
points[name + 'BottomRight'],
0.5
)
points[name + 'Mid'].y += 3
return new Path()
.move(points[name + 'TopLeft'])
.line(points[name + 'BottomLeft'])
.line(points[name + 'BottomRight'])
.line(points[name + 'TopRight'])
.line(points[name + 'TopLeft'])
.close()
.addClass(classes)
}
// Draws and arrow from to and places text
const arrow = (nametext = '') => {
let from = points[name + 'From']
let to = points[name + 'To']
from = from.shiftTowards(to2)
to = to.shiftTowards(from2)
const base = from.dist(to)
const r = 3
points[name + 'Tip1'] = to.shiftTowards(from3.5).rotate(rfrom)
points[name + 'Tip2'] = to.shiftTowards(from3.5).rotate(r * -1from)
const path = new Path()
.move(from)
.line(to)
.move(points[name + 'Tip1'])
.line(to)
.line(points[name + 'Tip2'])
.addClass('lining stroke-lg')
if (options.focus === name) path.addClass('note')
return text
? path.addText(' ' + textoptions.focus === name ? 'fill-note center' : 'center')
: path
}
// Draws a box and handled text placement
const drawBox = (namexywidthheighttext=trueclassestextClasses='') => {
points[name + 'Origin'] = new Point(xy)
paths[name] = box(namepoints[name + 'Origin']widthheightclasses)
if (text === 'b') {
paths[name+'_label'] = new Path()
.move(points[name+'BottomLeft'])
.line(points[name+'BottomRight'])
.addClass('hidden')
.addText(name'center ' + textClasses)
.attr('data-text-dy'-1)
}
else if (text === 't') {
paths[name+'_label'] = new Path()
.move(points[name+'TopLeft'])
.line(points[name+'TopRight'])
.addClass('hidden')
.addText(name'center ' + textClasses)
.attr('data-text-dy'11)
}
else if (text === 'r') {
paths[name+'_label'] = new Path()
.move(points[name+'BottomRight'])
.line(points[name+'TopRight'])
.addClass('hidden')
.addText(name'center ' + textClasses)
.attr('data-text-dx'-5)
}
else if (text) points[name + 'Mid'].addText(name'center')
}
// Settings
drawBox('Settings Set 0'-140-185020'Settings 0''fabric fill-bg')
drawBox('Settings Set 1'-14065020'Settings 0''fabric fill-bg')
const sname = 'Settings'
drawBox(sname-145-246165'b''fabric''text-lg bold')
points.arrowDraftFrom = new Point(-84,15)
points.arrowDraftTo = new Point(-4515)
paths.arrowDraft = arrow('arrowDraft''draft()')
// Stacks
drawBox('Stack 0'-30-3350169'b''mark fill-mark''fill-mark')
paths['Stack 0'].attr('fill-opacity'0.2)
drawBox('Stack 1'23-3350169'b''mark fill-mark''fill-mark')
paths['Stack 1'].attr('fill-opacity'0.2)
drawBox('Stack 2'76-3350169'b''mark fill-mark''fill-mark')
paths['Stack 2'].attr('fill-opacity'0.2)
// Sets
drawBox('Set 0'-33-3017476'r''contrast fill-contrast''fill-contrast')
paths['Set 0'].attr('fill-opacity'0.2)
drawBox('Set 1'-335017476'r''contrast fill-contrast''fill-contrast')
paths['Set 1'].attr('fill-opacity'0.2)
// Parts set 0
drawBox('Part A (set 0)'-27-274470'b''note fill-bg')
drawBox('points'-24-243812true'note')
drawBox('paths'-24-93812true'note')
drawBox('snippets'-2463812true'note')
drawBox('Part B (set 0)'26-274470'b''note fill-bg')
drawBox(' points '29-243812true'note')
drawBox(' paths '29-93812true'note')
drawBox(' snippets '2963812true'note')
drawBox('Part C (set 0)'79-274470'b''note fill-bg')
drawBox(' points '82-243812true'note')
drawBox(' paths '82-93812true'note')
drawBox(' snippets '8263812true'note')
drawBox('setStore 0'-242114412true'lining fill-lining dashed''fill-various')
paths['setStore 0'].attr('fill-opacity'0.2)
// Parts set 1
drawBox('Part A (set 1)'-27534470'b''note fill-bg')
drawBox(' points'-24563812true'note')
drawBox(' paths'-24713812true'note')
drawBox(' snippets'-24863812true'note')
drawBox('Part B (set 1)'26534470'b''note fill-bg')
drawBox(' points '29563812true'note')
drawBox(' paths '29713812true'note')
drawBox(' snippets '29863812true'note')
drawBox('Part C (set 1)'79534470'b''note fill-bg')
drawBox(' points '82563812true'note')
drawBox(' paths '82713812true'note')
drawBox(' snippets '82863812true'note')
drawBox('setStore 1'-2410114712true'lining fill-lining dashed''fill-various')
paths['setStore 1'].attr('fill-opacity'0.2)
// Design
drawBox('Pattern Store'-30-5215515true'lining fill-lining')
paths['Pattern Store'].attr('fill-opacity'0.2)
drawBox('Design'-43-59195216'b''fabric stroke-lg''text-lg bold')
// Render
points.arrowSvgFrom = new Point(154,15)
points.arrowSvgTo = new Point(225-15)
paths.arrowSvg = arrow('arrowSvg''render()')
points.arrowReactFrom = new Point(154,15)
points.arrowReactTo = new Point(22545)
paths.arrowReact = arrow('arrowReact''getRenderProps()')
drawBox('Render stage'190-52105175'b''interfacing lashed''text-lg bold')
// Render logos
points.svg = new Point(225-15).addText('SVG''text-lg bold')
points. = new Point(22545).addText("React\nSvelte\nVue\nJS\n..."'text-lg')
// Prevent clipping
paths.unclip = new Path().move(new Point(260-80))
return part
}
A schematic overview of what goes on inside a FreeSewing design
If it looks like a lot don't despair. I included all the info on the graphical overviewbut most of it you can safely ignore and consider under the hood unless you want to do some really advanced things with FreeSewing.
If we look at our image through squinted eyeswe can identify three areas:
- The Settings on the left
- The Render stage on the right
- The Pattern in the center
The left and right parts are all about how to integrate FreeSewing in your frontend. In other wordshow you'll plug it into your websiteor online storeor a mobile application.
We'll briefly cover those areas in this page. But a deep-dive into those topics is outside the scope of this guide.
The settings
On the leftwe have the settings box. It represents the settings that are provided by the user.
Most of the settings are the same for all designs generated with FreeSewing as they are provided by the core library.
Noteworthy exceptions are the measurements
and options keys as they are defined by the pattern design.
In other wordsdifferent patterns will required different measurements and provide different options.
But all patterns will allow users to set the units (for example).
Settings are provided by passing them to the Pattern constructor
Multiset support
Since version 3 of FreeSewingyou can pass multiple sets of settings to Pattern.draft().
We call this multset support.
In 99% of the casesyou will only have a single set of settingsand you can mostly forget about this feature. It is typically used to compare different drafts or to draft for different sets of measurements (for example).
Rendering your pattern
By rendering the patternwe mean to generate the output to show to the user.
This can be done in two different ways:
Render to SVG
The core library ships with a renderer that will render your pattern to SVG.
To use itcall Pattern.render() which will return an SVG string.
BYOR (bring your own renderer)
If you'd like more fine-grained control over the outputyou can use your own renderer.
To do socall Pattern.getRenderProps()
which will return all the data you need to render your pattern in the way you prefer.
This is what we use on these documentation pages to render with React
The pattern
Last but not leastwe've arrived at the central item: the pattern itself. The pattern is a container that holds all your partsalong with a (pattern-wide) store.
In realityyour pattern is a that takes the user's settings as input and will return an instantiated pattern.
That pattern instance will have a draft() method which will do the actual work of
drafting the pattern. Once draftedthe pattern can be rendered.
While the pattern does a lot of heavy lifting behind the sceneswe can content ourselves by understanding its different building blocks: