1
0
Fork 0
freesewing/packages/plugin-cutonfold/src/index.js

54 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-08-03 15:03:33 +02:00
import markers from './lib/markers'
import { version, name } from '../package.json'
2018-07-23 17:44:52 +00:00
export default {
name: name,
version: version,
2018-07-21 15:34:46 +02:00
hooks: {
preRender: function(svg) {
2019-08-03 15:03:33 +02:00
if (svg.attributes.get('freesewing:plugin-cutonfold') === false) {
svg.attributes.set('freesewing:plugin-cutonfold', version)
svg.defs += markers
}
2018-07-21 15:34:46 +02:00
}
},
macros: {
2018-08-05 13:04:23 +02:00
cutonfold: function(so) {
if (so === false) {
2019-08-03 15:03:33 +02:00
delete this.points.cutonfoldFrom
delete this.points.cutonfoldTo
delete this.points.cutonfoldVia1
delete this.points.cutonfoldVia2
delete this.paths.cutonfold
return true
}
2019-08-03 15:03:33 +02:00
let points = this.points
so = {
2019-09-29 16:58:21 +02:00
offset: 15,
margin: 5,
2019-08-03 15:03:33 +02:00
prefix: '',
...so
2019-08-03 15:03:33 +02:00
}
points['cutonfoldFrom' + so.prefix] = so.from.shiftFractionTowards(so.to, so.margin / 100)
points['cutonfoldTo' + so.prefix] = so.to.shiftFractionTowards(so.from, so.margin / 100)
points['cutonfoldVia1' + so.prefix] = points['cutonfoldFrom' + so.prefix]
.shiftTowards(so.from, so.offset)
2019-08-03 15:03:33 +02:00
.rotate(-90, points['cutonfoldFrom' + so.prefix])
points['cutonfoldVia2' + so.prefix] = points['cutonfoldTo' + so.prefix]
.shiftTowards(so.to, so.offset)
2019-08-03 15:03:33 +02:00
.rotate(90, points['cutonfoldTo' + so.prefix])
let text = so.grainline ? 'cutOnFoldAndGrainline' : 'cutOnFold'
this.paths['cutonfold' + so.prefix] = new this.Path()
.move(points['cutonfoldFrom' + so.prefix])
.line(points['cutonfoldVia1' + so.prefix])
.line(points['cutonfoldVia2' + so.prefix])
.line(points['cutonfoldTo' + so.prefix])
.attr('class', 'note')
.attr('marker-start', 'url(#cutonfoldFrom)')
.attr('marker-end', 'url(#cutonfoldTo)')
.attr('data-text', text)
.attr('data-text-class', 'center fill-note')
2018-07-21 15:34:46 +02:00
}
}
2019-08-03 15:03:33 +02:00
}