1
0
Fork 0
freesewing/packages/rendertest/src/text.js

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2021-01-31 09:22:15 +01:00
export default function (part) {
2021-12-24 13:28:34 +01:00
const { Point, Path, points, paths, store } = part.shorthand()
2019-05-07 12:50:49 +02:00
2019-08-03 15:03:33 +02:00
let y = store.get('y')
2021-12-24 13:28:34 +01:00
const w = store.get('w')
// Text sizes
y += 15
points.textsize = new Point(0,y)
.attr('data-text', 'Text sizes')
.attr('data-text-class', 'text-lg bold')
const sizes = {
'text-xs': 3,
'text-sm': 5,
'text': 8,
'text-lg': 10,
'text-xl': 14,
'text-2xl': 22,
'text-3xl': 28,
'text-4xl': 42,
}
for (const [size, shift] of Object.entries(sizes)) {
y += shift
points['t' + size] = new Point(0, y)
.attr('data-text', size)
.attr('data-text-class', `text ${size}`)
}
// Text alignment
y += 15
points.textalign = new Point(0,y)
.attr('data-text', 'Text alignment')
.attr('data-text-class', 'text-lg bold')
2019-08-03 15:03:33 +02:00
y += 10
points.tl = new Point(0, y)
points.tr = new Point(w, y)
2021-01-31 09:22:15 +01:00
paths.text = new Path().move(points.tl).line(points.tr).attr('data-text', 'text')
2021-12-24 13:28:34 +01:00
// Align center
2019-08-03 15:03:33 +02:00
points.tlc = new Point(0, y)
points.trc = new Point(w, y)
2019-05-07 12:50:49 +02:00
paths.textc = new Path()
.move(points.tlc)
.line(points.trc)
2019-08-03 15:03:33 +02:00
.attr('data-text', 'text.center')
.attr('data-text-class', 'center')
2021-12-24 13:28:34 +01:00
// Align right
2019-08-03 15:03:33 +02:00
points.tlr = new Point(0, y)
points.trr = new Point(w, y)
2019-05-07 12:50:49 +02:00
paths.textr = new Path()
.move(points.tlr)
.line(points.trr)
2019-08-03 15:03:33 +02:00
.attr('data-text', 'text.right')
.attr('data-text-class', 'right')
2021-12-24 13:28:34 +01:00
// Text style
y += 20
points.textstyle = new Point(0,y)
.attr('data-text', 'Text style')
.attr('data-text-class', 'text-lg bold')
y += 10
points.titalic = new Point(0, y)
.attr('data-text', '.italic')
.attr('data-text-class', 'italic')
y += 10
points.tbold = new Point(0, y)
.attr('data-text', '.bold')
.attr('data-text-class', 'bold')
2019-08-03 15:03:33 +02:00
store.set('y', y)
2019-05-07 12:50:49 +02:00
2019-08-03 15:03:33 +02:00
return part
2019-05-07 12:50:49 +02:00
}