Skip to content

Commit

Permalink
Fix: stroke rendering on Graphics when width is set to 0 (#10496)
Browse files Browse the repository at this point in the history
* couple of tweaks to not render stroke if stoke width is 0

* Update tests/visual/scenes/text/text-stroke.scene.ts

Co-authored-by: Matt Karl <matt@mattkarl.com>

* lint

* fix test

---------

Co-authored-by: Matt Karl <matt@mattkarl.com>
  • Loading branch information
GoodBoyDigital and bigtimebuddy committed Apr 30, 2024
1 parent caab673 commit 75bcada
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/scene/text/TextStyle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ function convertV7Tov8Style(style: TextStyleOptions)
};
}

if (oldStyle.strokeThickness)
if (oldStyle.strokeThickness !== undefined)
{
// #if _DEBUG
deprecation(v8_0_0, 'strokeThickness is now a part of stroke');
Expand Down
2 changes: 1 addition & 1 deletion src/scene/text/canvas/CanvasTextSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ export class CanvasTextSystem implements System
linePositionX += (maxLineWidth - lineWidths[i]) / 2;
}

if (style._stroke)
if (style._stroke?.width)
{
this._drawLetterSpacing(
lines[i],
Expand Down
41 changes: 41 additions & 0 deletions tests/visual/scenes/text/text-stroke.scene.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { Graphics } from '../../../../src/scene/graphics/shared/Graphics';
import { Text } from '../../../../src/scene/text/Text';
import { TextStyle } from '../../../../src/scene/text/TextStyle';

import type { Container } from '../../../../src/scene/container/Container';
import type { TestScene } from '../../types';

export const scene: TestScene = {
it: 'should render text stroke if it has a width greater than one',
pixelMatch: 10,
create: async (scene: Container) =>
{
const style = new TextStyle({
fontFamily: 'Arial',
fontWeight: 'bold',
fontStyle: 'normal',
fontSize: 36,
fill: 0xFFFFFF,
stroke: {
color: 0x000000,
width: 0,
},
align: 'center',
wordWrap: true,
wordWrapWidth: 200,
breakWords: true,
});

const text = new Text({
text: 'PixiJS is very cool indeed',
style
});

const whiteBox = new Graphics().rect(0, 0, 128, 128).fill(0xFFFFFF);

scene.addChild(whiteBox);
scene.addChild(text);

// This SHOULD result in a totally white texture :)
},
};
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 75bcada

Please sign in to comment.