fixClipWithShadow.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. var env = require("../../core/env");
  2. // Fix weird bug in some version of IE11 (like 11.0.9600.178**),
  3. // where exception "unexpected call to method or property access"
  4. // might be thrown when calling ctx.fill or ctx.stroke after a path
  5. // whose area size is zero is drawn and ctx.clip() is called and
  6. // shadowBlur is set. See #4572, #3112, #5777.
  7. // (e.g.,
  8. // ctx.moveTo(10, 10);
  9. // ctx.lineTo(20, 10);
  10. // ctx.closePath();
  11. // ctx.clip();
  12. // ctx.shadowBlur = 10;
  13. // ...
  14. // ctx.fill();
  15. // )
  16. var shadowTemp = [['shadowBlur', 0], ['shadowColor', '#000'], ['shadowOffsetX', 0], ['shadowOffsetY', 0]];
  17. function _default(orignalBrush) {
  18. // version string can be: '11.0'
  19. return env.browser.ie && env.browser.version >= 11 ? function () {
  20. var clipPaths = this.__clipPaths;
  21. var style = this.style;
  22. var modified;
  23. if (clipPaths) {
  24. for (var i = 0; i < clipPaths.length; i++) {
  25. var clipPath = clipPaths[i];
  26. var shape = clipPath && clipPath.shape;
  27. var type = clipPath && clipPath.type;
  28. if (shape && (type === 'sector' && shape.startAngle === shape.endAngle || type === 'rect' && (!shape.width || !shape.height))) {
  29. for (var j = 0; j < shadowTemp.length; j++) {
  30. // It is save to put shadowTemp static, because shadowTemp
  31. // will be all modified each item brush called.
  32. shadowTemp[j][2] = style[shadowTemp[j][0]];
  33. style[shadowTemp[j][0]] = shadowTemp[j][1];
  34. }
  35. modified = true;
  36. break;
  37. }
  38. }
  39. }
  40. orignalBrush.apply(this, arguments);
  41. if (modified) {
  42. for (var j = 0; j < shadowTemp.length; j++) {
  43. style[shadowTemp[j][0]] = shadowTemp[j][2];
  44. }
  45. }
  46. } : orignalBrush;
  47. }
  48. module.exports = _default;