mirror of
https://github.com/idrawjs/idraw
synced 2026-05-24 10:08:34 +00:00
feat: add textShadow to element-text
This commit is contained in:
parent
059d5f59c0
commit
5a8d6a0719
4 changed files with 27 additions and 5 deletions
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
Loading…
Reference in a new issue