diff --git a/src/core/helpers/hidpi.js b/src/core/helpers/hidpi.js index 1bc15a84a23f5b07bbfe700348194e9212614b82..ca8e0084be33a35f288a6fbe9e748deb583afd32 100644 --- a/src/core/helpers/hidpi.js +++ b/src/core/helpers/hidpi.js @@ -106,7 +106,8 @@ if (pixelRatio !== 1) { args[1] *= pixelRatio args[2] *= pixelRatio - var font = this.font + // Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值 + var font = this.__font__ || this.font this.font = font.replace( /(\d+\.?\d*)(px|em|rem|pt)/g, function (w, m, u) { @@ -130,7 +131,8 @@ if (pixelRatio !== 1) { args[1] *= pixelRatio // x args[2] *= pixelRatio // y - var font = this.font + // Safari 重新设置部分属性会导致其他值恢复默认,需获取原始值 + var font = this.__font__ || this.font this.font = font.replace( /(\d+\.?\d*)(px|em|rem|pt)/g, function (w, m, u) { diff --git a/src/core/view/components/canvas/index.vue b/src/core/view/components/canvas/index.vue index 0652211f5b8dc55cd49f53f0b3307cec94ca8214..7ebca5eb4c5666837df16fd6cce36489d8a4fa25 100644 --- a/src/core/view/components/canvas/index.vue +++ b/src/core/view/components/canvas/index.vue @@ -212,24 +212,21 @@ export default { data.forEach(function (color_, method_) { c2d[_[method_]] = _[method_] === 'shadowColor' ? resolveColor(color_) : color_ }) - } else { - if (method1 === 'fontSize') { - c2d.font = c2d.font.replace(/\d+\.?\d*px/, data[0] + 'px') - } else { - if (method1 === 'lineDash') { - c2d.setLineDash(data[0]) - c2d.lineDashOffset = data[1] || 0 - } else { - if (method1 === 'textBaseline') { - if (data[0] === 'normal') { - data[0] = 'alphabetic' - } - c2d[method1] = data[0] - } else { - c2d[method1] = data[0] - } - } + } else if (method1 === 'fontSize') { + const font = c2d.__font__ || c2d.font + c2d.__font__ = c2d.font = font.replace(/\d+\.?\d*px/, data[0] + 'px') + } else if (method1 === 'lineDash') { + c2d.setLineDash(data[0]) + c2d.lineDashOffset = data[1] || 0 + } else if (method1 === 'textBaseline') { + if (data[0] === 'normal') { + data[0] = 'alphabetic' } + c2d[method1] = data[0] + } else if (method1 === 'font') { + c2d.__font__ = c2d.font = data[0] + } else { + c2d[method1] = data[0] } } else if (method === 'fillPath' || method === 'strokePath') { method = method.replace(/Path/, '')