Skip to content

Commit 65b9933

Browse files
committed
tweak.
1 parent 84d0e50 commit 65b9933

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

src/graphic/Style.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11

2+
import fixShadow from './helper/fixShadow';
3+
24
var STYLE_COMMON_PROPS = [
35
['shadowBlur', 0], ['shadowOffsetX', 0], ['shadowOffsetY', 0], ['shadowColor', '#000'],
46
['lineCap', 'butt'], ['lineJoin', 'miter'], ['miterLimit', 10]
@@ -350,27 +352,14 @@ Style.prototype = {
350352
var prevStyle = prevEl && prevEl.style;
351353
var firstDraw = !prevStyle;
352354

353-
// Fix shadow size and offset with dpr
354-
var fixShadow = function (propName, value) {
355-
if ([
356-
'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
357-
'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
358-
'textBoxShadowBlur', 'textBoxShadowOffsetX',
359-
'textBoxShadowOffsetY'
360-
].indexOf(propName) >= 0) {
361-
return value *= ctx.dpr;
362-
}
363-
return value;
364-
};
365-
366355
for (var i = 0; i < STYLE_COMMON_PROPS.length; i++) {
367356
var prop = STYLE_COMMON_PROPS[i];
368357
var styleName = prop[0];
369358

370359
if (firstDraw || style[styleName] !== prevStyle[styleName]) {
371360
// FIXME Invalid property value will cause style leak from previous element.
372361
ctx[styleName] =
373-
fixShadow(styleName, style[styleName] || prop[1]);
362+
fixShadow(ctx, styleName, style[styleName] || prop[1]);
374363
}
375364
}
376365

src/graphic/helper/fixShadow.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
var SHADOW_PROPS = {
3+
'shadowBlur': 1,
4+
'shadowOffsetX': 1,
5+
'shadowOffsetY': 1,
6+
'textShadowBlur': 1,
7+
'textShadowOffsetX': 1,
8+
'textShadowOffsetY': 1,
9+
'textBoxShadowBlur': 1,
10+
'textBoxShadowOffsetX': 1,
11+
'textBoxShadowOffsetY': 1
12+
};
13+
14+
export default function (ctx, propName, value) {
15+
if (SHADOW_PROPS.hasOwnProperty(propName)) {
16+
return value *= ctx.dpr;
17+
}
18+
return value;
19+
}

src/graphic/helper/text.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
import * as textContain from '../../contain/text';
1111
import * as roundRectHelper from './roundRect';
1212
import * as imageHelper from './image';
13+
import fixShadow from './fixShadow';
1314

1415
// TODO: Have not support 'start', 'end' yet.
1516
var VALID_TEXT_ALIGN = {left: 1, right: 1, center: 1};
@@ -418,16 +419,7 @@ function setCtx(ctx, prop, value) {
418419
// if (ctx.__currentValues[prop] !== value) {
419420
// ctx[prop] = ctx.__currentValues[prop] = value;
420421

421-
// Fix shadow size and offset with dpr
422-
if ([
423-
'shadowBlur', 'shadowOffsetX', 'shadowOffsetY',
424-
'textShadowBlur', 'textShadowOffsetX', 'textShadowOffsetY',
425-
'textBoxShadowBlur', 'textBoxShadowOffsetX', 'textBoxShadowOffsetY'
426-
].indexOf(prop) >= 0) {
427-
value *= ctx.dpr;
428-
}
429-
430-
ctx[prop] = value;
422+
ctx[prop] = fixShadow(ctx, prop, value);
431423
// }
432424
return ctx[prop];
433425
}

0 commit comments

Comments
 (0)