Skip to content

Commit

Permalink
fix: skip filling on text
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoiver committed May 23, 2024
1 parent edf26f6 commit 8afcc49
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __tests__/demos/2d/transform-text.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Circle, Text, runtime } from '../../../packages/g';
import { Circle, Text } from '../../../packages/g';

export async function transformText(context) {
const { canvas } = context;
Expand Down
19 changes: 14 additions & 5 deletions packages/g-plugin-canvas-renderer/src/shapes/styles/Default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,14 @@ export function applyFill(
plugin: CanvasRendererPlugin,
runtime: GlobalRuntime,
imagePool: ImagePool,
skipFill = false,
) {
if (Array.isArray(fill)) {
fill.forEach((gradient) => {
context.fillStyle = getColor(gradient, object, context, imagePool);

fillRule ? context.fill(fillRule) : context.fill();
if (!skipFill) {
fillRule ? context.fill(fillRule) : context.fill();
}
});
} else {
if (isPattern(fill)) {
Expand All @@ -297,7 +299,9 @@ export function applyFill(
imagePool,
);
}
fillRule ? context.fill(fillRule) : context.fill();
if (!skipFill) {
fillRule ? context.fill(fillRule) : context.fill();
}
}
}

Expand All @@ -309,11 +313,14 @@ export function applyStroke(
plugin: CanvasRendererPlugin,
runtime: GlobalRuntime,
imagePool: ImagePool,
skipStroke = false,
) {
if (Array.isArray(stroke)) {
stroke.forEach((gradient) => {
context.strokeStyle = getColor(gradient, object, context, imagePool);
context.stroke();
if (!skipStroke) {
context.stroke();
}
});
} else {
if (isPattern(stroke)) {
Expand All @@ -327,6 +334,8 @@ export function applyStroke(
imagePool,
);
}
context.stroke();
if (!skipStroke) {
context.stroke();
}
}
}
2 changes: 2 additions & 0 deletions packages/g-plugin-canvas-renderer/src/shapes/styles/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ export class TextRenderer implements StyleRenderer {
plugin,
runtime,
this.imagePool,
true,
);

let currentGlobalAlpha: number;
Expand Down Expand Up @@ -319,6 +320,7 @@ export class TextRenderer implements StyleRenderer {
plugin,
runtime,
this.imagePool,
true,
);

let currentGlobalAlpha: number;
Expand Down

0 comments on commit 8afcc49

Please sign in to comment.