mirror of
https://github.com/konvajs/konva.git
synced 2025-10-15 12:34:52 +08:00
more textpath rendering fixes
This commit is contained in:
@@ -712,29 +712,84 @@ suite('TextPath', function () {
|
||||
|
||||
test('check bad calculations', function () {
|
||||
var stage = addStage();
|
||||
stage.draggable(true);
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var textpath = new Konva.TextPath({
|
||||
x: 100,
|
||||
y: 150,
|
||||
fill: '#333',
|
||||
fontSize: 16,
|
||||
scaleX: 0.8,
|
||||
scaleY: 0.8,
|
||||
text:
|
||||
'__________________________________________________________________________________________________________________________________________________________________________________________________________________',
|
||||
data:
|
||||
'M 109.98618090452261 138.6656132223618 C 135.94577638190955 48.80547503140701 149.91187876884422 79.79800957914573 151.40954773869348 117.23973382537689 S 123.00811620603017 419.616741991206 122.84170854271358 460.0538041771357 S 134.33883542713568 469.8304329459799 149.98115577889448 464.33898005653265 S 245.4620163316583 411.5856081972362 257.1105527638191 412.91686950376885 S 239.31850251256282 474.434854428392 249.96859296482413 475.76611573492465 S 338.21036306532665 425.67526648869347 348.5276381909548 424.3440051821608 S 337.3640408291457 461.1772344535176 338.5288944723618 464.33898005653265 S 346.8778454773869 466.79295744346734 358.52638190954775 451.4834524183417',
|
||||
});
|
||||
layer.add(textpath);
|
||||
var path = new Konva.Path({
|
||||
stroke: 'red',
|
||||
scaleX: 0.8,
|
||||
scaleY: 0.8,
|
||||
data:
|
||||
'M 109.98618090452261 138.6656132223618 C 135.94577638190955 48.80547503140701 149.91187876884422 79.79800957914573 151.40954773869348 117.23973382537689 S 123.00811620603017 419.616741991206 122.84170854271358 460.0538041771357 S 134.33883542713568 469.8304329459799 149.98115577889448 464.33898005653265 S 245.4620163316583 411.5856081972362 257.1105527638191 412.91686950376885 S 239.31850251256282 474.434854428392 249.96859296482413 475.76611573492465 S 338.21036306532665 425.67526648869347 348.5276381909548 424.3440051821608 S 337.3640408291457 461.1772344535176 338.5288944723618 464.33898005653265 S 346.8778454773869 466.79295744346734 358.52638190954775 451.4834524183417',
|
||||
});
|
||||
layer.add(path);
|
||||
layer.draw();
|
||||
|
||||
var rect = textpath.getClientRect();
|
||||
|
||||
assert.equal(rect.height, 412.4370496991363, 'check height');
|
||||
assert.equal(rect.height, 332.3365704376247, 'check height');
|
||||
|
||||
textpath.text('');
|
||||
rect = textpath.getClientRect();
|
||||
assert.equal(rect.height, 0, 'check height');
|
||||
});
|
||||
|
||||
test('check bad calculations 2', function () {
|
||||
var stage = addStage();
|
||||
|
||||
var layer = new Konva.Layer();
|
||||
stage.add(layer);
|
||||
|
||||
var textpath = new Konva.TextPath({
|
||||
x: 0,
|
||||
y: 0,
|
||||
fill: '#333',
|
||||
fontSize: 10,
|
||||
// strokeWidth: 100,
|
||||
stroke: 'black',
|
||||
scaleX: 0.4,
|
||||
scaleY: 0.4,
|
||||
text:
|
||||
'....................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................',
|
||||
data:
|
||||
'M 117.12814070351759 108.66938206658291 C 79.18719346733668 277.73956799623113 75.85761180904522 379.96743797110554 82.84673366834171 395.7761659861809 S 148.83130025125627 280.47708118718595 177.12060301507537 244.36661824748745 S 326.1725898241206 61.02036887562815 325.67336683417085 85.815110709799 S 174.998726758794 435.7304316896985 172.8354271356784 457.1970202575377 S 273.65633103015074 310.01551271984926 307.1042713567839 270.07767352386935 S 466.09929459798997 92.08432302135678 459.9422110552764 114.3829499057789 S 266.23512060301505 435.5226006595478 254.2537688442211 461.4821961369347 S 328.1430565326633 368.1639210113065 357.09798994974875 337.2120956344221 S 486.31961118090453 207.61623570979899 502.79396984924625 195.8012916143216 S 511.48859170854274 200.85065719221106 498.50879396984925 235.79626648869348 S 379.73086055276383 489.4401119660804 391.37939698492465 495.76360317211055 S 573.2022663316583 313.03941849874377 598.4962311557789 290.0751609610553 S 608.3285672110553 288.6610529208543 608.4949748743719 298.64551271984925 S 604.9168530150754 352.64801334799 599.9246231155779 375.778678548995 S 540.6820665829146 508.5077162374372 565.643216080402 497.19199513190955 S 690.3761155778894 408.77881799623117 814.1834170854271 278.6480252826633',
|
||||
});
|
||||
var path = new Konva.Path({
|
||||
x: 0,
|
||||
y: 0,
|
||||
stroke: 'red',
|
||||
scaleX: 0.4,
|
||||
scaleY: 0.4,
|
||||
data:
|
||||
'M 117.12814070351759 108.66938206658291 C 79.18719346733668 277.73956799623113 75.85761180904522 379.96743797110554 82.84673366834171 395.7761659861809 S 148.83130025125627 280.47708118718595 177.12060301507537 244.36661824748745 S 326.1725898241206 61.02036887562815 325.67336683417085 85.815110709799 S 174.998726758794 435.7304316896985 172.8354271356784 457.1970202575377 S 273.65633103015074 310.01551271984926 307.1042713567839 270.07767352386935 S 466.09929459798997 92.08432302135678 459.9422110552764 114.3829499057789 S 266.23512060301505 435.5226006595478 254.2537688442211 461.4821961369347 S 328.1430565326633 368.1639210113065 357.09798994974875 337.2120956344221 S 486.31961118090453 207.61623570979899 502.79396984924625 195.8012916143216 S 511.48859170854274 200.85065719221106 498.50879396984925 235.79626648869348 S 379.73086055276383 489.4401119660804 391.37939698492465 495.76360317211055 S 573.2022663316583 313.03941849874377 598.4962311557789 290.0751609610553 S 608.3285672110553 288.6610529208543 608.4949748743719 298.64551271984925 S 604.9168530150754 352.64801334799 599.9246231155779 375.778678548995 S 540.6820665829146 508.5077162374372 565.643216080402 497.19199513190955 S 690.3761155778894 408.77881799623117 814.1834170854271 278.6480252826633',
|
||||
});
|
||||
layer.add(path);
|
||||
// emulate different size function:
|
||||
// I found the app with custom font
|
||||
// we calculations were not correct
|
||||
// so I just coppied text size from that app
|
||||
textpath._getTextSize = () => {
|
||||
return { height: 10, width: 5.9399871826171875 };
|
||||
};
|
||||
layer.add(textpath);
|
||||
|
||||
layer.draw();
|
||||
|
||||
var rect = textpath.getClientRect();
|
||||
assert.equal(rect.width, 298.50744485064837);
|
||||
assert.equal(rect.height, 170.74755779649587);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user