feat: add textShadow to element-text

This commit is contained in:
chenshenhai 2021-10-10 23:32:13 +08:00
parent 059d5f59c0
commit 5a8d6a0719
4 changed files with 27 additions and 5 deletions

View file

@ -37,7 +37,12 @@ const data = {
color: "#999999",
borderRadius: 60,
borderWidth: 4,
borderColor: "#03a9f4"
borderColor: "#03a9f4",
textShadowColor: '#000000',
textShadowOffsetX: 2,
textShadowOffsetY: 2,
textShadowBlur: 0.5,
},
},
{

View file

@ -15,6 +15,10 @@ export function clearContext(ctx: TypeContext) {
ctx.setStrokeStyle('#000000');
ctx.setLineDash([]);
ctx.setGlobalAlpha(1);
ctx.setShadowColor('#00000000');
ctx.setShadowOffsetX(0)
ctx.setShadowOffsetY(0);
ctx.setShadowBlur(0);
}
export function drawBgColor(ctx: TypeContext, color: string) {

View file

@ -74,6 +74,18 @@ export function drawText(
if (lines.length * fontHeight < elem.h) {
_y += ((elem.h - lines.length * fontHeight) / 2);
}
if (desc.textShadowColor !== undefined) {
ctx.setShadowColor(desc.textShadowColor);
}
if (desc.textShadowOffsetX !== undefined) {
ctx.setShadowOffsetX(desc.textShadowOffsetX);
}
if (desc.textShadowOffsetY !== undefined) {
ctx.setShadowOffsetY(desc.textShadowOffsetY);
}
if (desc.textShadowBlur !== undefined) {
ctx.setShadowBlur(desc.textShadowBlur);
}
lines.forEach((line, i) => {
let _x = elem.x;
if (desc.textAlign === 'center') {
@ -83,6 +95,7 @@ export function drawText(
}
ctx.fillText(line.text, _x, _y + fontHeight * i);
});
clearContext(ctx);
}
// draw text stroke

View file

@ -66,10 +66,10 @@ type TypeElemDescText = {
bgColor?: string;
strokeColor?: string;
strokeWidth?: number;
shadowColor?: string;
shadowOffsetX?: number;
shadowOffsetY?: number;
shadowOffsetBlur?: number;
textShadowColor?: string;
textShadowOffsetX?: number;
textShadowOffsetY?: number;
textShadowBlur?: number;
} & TypeElemBoxDesc
type TypeElemDescCircle = {