mirror of
https://github.com/konvajs/konva.git
synced 2025-06-28 15:23:44 +08:00
build fixes, text underline fixes
This commit is contained in:
parent
08b3fb159e
commit
33d64e194c
@ -162,7 +162,7 @@ gulp.task('api', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
gulp.task('watch', 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']));
|
||||||
|
4
konva.js
4
konva.js
@ -12466,14 +12466,14 @@
|
|||||||
if (shouldUnderline) {
|
if (shouldUnderline) {
|
||||||
context.save();
|
context.save();
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
context.moveTo(0, Math.round(lineHeightPx / 2));
|
context.moveTo(0, Math.round(fontSize / 2));
|
||||||
spacesNumber = text.split(' ').length - 1;
|
spacesNumber = text.split(' ').length - 1;
|
||||||
oneWord = spacesNumber === 0;
|
oneWord = spacesNumber === 0;
|
||||||
lineWidth =
|
lineWidth =
|
||||||
align === JUSTIFY && lastLine && !oneWord
|
align === JUSTIFY && lastLine && !oneWord
|
||||||
? totalWidth - padding * 2
|
? totalWidth - padding * 2
|
||||||
: width;
|
: 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
|
// I have no idea what is real ratio
|
||||||
// just /15 looks good enough
|
// just /15 looks good enough
|
||||||
context.lineWidth = fontSize / 15;
|
context.lineWidth = fontSize / 15;
|
||||||
|
2
konva.min.js
vendored
2
konva.min.js
vendored
File diff suppressed because one or more lines are too long
@ -180,14 +180,14 @@ export class Text extends Shape {
|
|||||||
context.save();
|
context.save();
|
||||||
context.beginPath();
|
context.beginPath();
|
||||||
|
|
||||||
context.moveTo(0, Math.round(lineHeightPx / 2));
|
context.moveTo(0, Math.round(fontSize / 2));
|
||||||
spacesNumber = text.split(' ').length - 1;
|
spacesNumber = text.split(' ').length - 1;
|
||||||
oneWord = spacesNumber === 0;
|
oneWord = spacesNumber === 0;
|
||||||
lineWidth =
|
lineWidth =
|
||||||
align === JUSTIFY && lastLine && !oneWord
|
align === JUSTIFY && lastLine && !oneWord
|
||||||
? totalWidth - padding * 2
|
? totalWidth - padding * 2
|
||||||
: width;
|
: 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
|
// I have no idea what is real ratio
|
||||||
// just /15 looks good enough
|
// just /15 looks good enough
|
||||||
|
@ -24,4 +24,26 @@ suite('Filter', function() {
|
|||||||
cloneAndCompareLayer(layer, 50);
|
cloneAndCompareLayer(layer, 50);
|
||||||
Konva.pixelRatio = 1;
|
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();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -540,6 +540,37 @@ suite('Text', function() {
|
|||||||
assert.equal(layer.getContext().getTrace(), trace);
|
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() {
|
test('text multi line with strike', function() {
|
||||||
var stage = addStage();
|
var stage = addStage();
|
||||||
var layer = new Konva.Layer();
|
var layer = new Konva.Layer();
|
||||||
|
Loading…
Reference in New Issue
Block a user