build fixes, text underline fixes

This commit is contained in:
Anton Lavrenov 2019-02-06 12:46:21 -05:00
parent 08b3fb159e
commit 33d64e194c
6 changed files with 60 additions and 7 deletions

View File

@ -162,7 +162,7 @@ gulp.task('api', function() {
});
gulp.task('watch', function() {
gulp.watch(['src/**/*.js'], ['dev-build']);
gulp.watch(['src/**/*.js'], gulp.series(['dev-build']));
});
gulp.task('default', gulp.series(['dev-build', 'watch', 'server']));
gulp.task('default', gulp.parallel(['dev-build', 'watch', 'server']));

View File

@ -12466,14 +12466,14 @@
if (shouldUnderline) {
context.save();
context.beginPath();
context.moveTo(0, Math.round(lineHeightPx / 2));
context.moveTo(0, Math.round(fontSize / 2));
spacesNumber = text.split(' ').length - 1;
oneWord = spacesNumber === 0;
lineWidth =
align === JUSTIFY && lastLine && !oneWord
? totalWidth - padding * 2
: width;
context.lineTo(Math.round(lineWidth), Math.round(lineHeightPx / 2));
context.lineTo(Math.round(lineWidth), Math.round(fontSize / 2));
// I have no idea what is real ratio
// just /15 looks good enough
context.lineWidth = fontSize / 15;

2
konva.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -180,14 +180,14 @@ export class Text extends Shape {
context.save();
context.beginPath();
context.moveTo(0, Math.round(lineHeightPx / 2));
context.moveTo(0, Math.round(fontSize / 2));
spacesNumber = text.split(' ').length - 1;
oneWord = spacesNumber === 0;
lineWidth =
align === JUSTIFY && lastLine && !oneWord
? totalWidth - padding * 2
: width;
context.lineTo(Math.round(lineWidth), Math.round(lineHeightPx / 2));
context.lineTo(Math.round(lineWidth), Math.round(fontSize / 2));
// I have no idea what is real ratio
// just /15 looks good enough

View File

@ -24,4 +24,26 @@ suite('Filter', function() {
cloneAndCompareLayer(layer, 50);
Konva.pixelRatio = 1;
});
test.skip('try to serialize node with filter', function() {
var stage = addStage();
var layer = new Konva.Layer();
var circle = new Konva.Circle({
x: stage.width() / 2,
y: stage.height() / 2,
fill: 'red',
stroke: 'green',
radius: 15
});
layer.add(circle);
stage.add(layer);
circle.cache();
circle.filters([Konva.Filters.Blur]);
circle.blurRadius(0);
layer.draw();
var json = circle.toJSON();
});
});

View File

@ -540,6 +540,37 @@ suite('Text', function() {
assert.equal(layer.getContext().getTrace(), trace);
});
// ======================================================
test('text with underline and large line height', function() {
var stage = addStage();
var layer = new Konva.Layer();
var text = new Konva.Text({
fontFamily: 'Arial',
text: 'text',
fontSize: 80,
lineHeight: 2,
textDecoration: 'underline'
});
layer.add(text);
stage.add(layer);
var canvas = createCanvas();
var context = canvas.getContext('2d');
context.translate(0, 80);
context.lineWidth = 2;
context.font = '80px Arial';
context.textBaseline = 'middle';
context.fillText('text', 0, 0);
context.beginPath();
context.moveTo(0, 40);
context.lineTo(text.width(), 40);
context.lineWidth = 80 / 15;
context.stroke();
compareLayerAndCanvas(layer, canvas, 50);
});
test('text multi line with strike', function() {
var stage = addStage();
var layer = new Konva.Layer();