2019-08-03 15:03:33 +02:00
|
|
|
import markers from './lib/markers'
|
2022-01-25 09:28:07 +01:00
|
|
|
import pkg from '../package.json'
|
2018-07-21 16:37:18 +02:00
|
|
|
|
2018-07-23 17:44:52 +00:00
|
|
|
export default {
|
2022-01-25 09:28:07 +01:00
|
|
|
name: pkg.name,
|
|
|
|
version: pkg.version,
|
2018-07-21 15:34:46 +02:00
|
|
|
hooks: {
|
2021-11-21 17:27:03 +01:00
|
|
|
preRender: (svg) => {
|
2019-08-03 15:03:33 +02:00
|
|
|
if (svg.attributes.get('freesewing:plugin-cutonfold') === false) {
|
2022-01-25 09:28:07 +01:00
|
|
|
svg.attributes.set('freesewing:plugin-cutonfold', pkg.version)
|
2019-08-03 15:03:33 +02:00
|
|
|
svg.defs += markers
|
2018-12-08 17:49:21 +01:00
|
|
|
}
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
2018-07-24 09:10:09 +00:00
|
|
|
},
|
|
|
|
macros: {
|
2021-01-31 09:22:15 +01:00
|
|
|
cutonfold: function (so) {
|
2019-07-16 16:20:16 +02:00
|
|
|
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-07-16 16:20:16 +02:00
|
|
|
}
|
2021-11-21 17:27:03 +01:00
|
|
|
const points = this.points
|
2019-02-13 14:18:23 +01:00
|
|
|
so = {
|
2019-09-29 16:58:21 +02:00
|
|
|
offset: 15,
|
2019-02-13 14:49:25 +01:00
|
|
|
margin: 5,
|
2019-08-03 15:03:33 +02:00
|
|
|
prefix: '',
|
2021-04-24 10:16:31 +02:00
|
|
|
...so,
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|
2019-08-03 15:25:29 +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]
|
2022-01-24 09:25:36 +01:00
|
|
|
.shiftTowards(so.from, so.offset * this.context.settings.scale)
|
2019-08-03 15:03:33 +02:00
|
|
|
.rotate(-90, points['cutonfoldFrom' + so.prefix])
|
2019-08-03 15:25:29 +02:00
|
|
|
points['cutonfoldVia2' + so.prefix] = points['cutonfoldTo' + so.prefix]
|
2022-01-24 09:25:36 +01:00
|
|
|
.shiftTowards(so.to, so.offset * this.context.settings.scale)
|
2019-08-03 15:03:33 +02:00
|
|
|
.rotate(90, points['cutonfoldTo' + so.prefix])
|
2021-11-21 17:27:03 +01:00
|
|
|
const text = so.grainline ? 'cutOnFoldAndGrainline' : 'cutOnFold'
|
2019-08-03 15:03:33 +02:00
|
|
|
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')
|
2021-04-24 10:16:31 +02:00
|
|
|
},
|
|
|
|
},
|
2019-08-03 15:03:33 +02:00
|
|
|
}
|