| | |
| | | * @param {Object} configs 配置信息 |
| | | * @param {Boolean} selectId 编辑元素 |
| | | */ |
| | | static sketch (configs, selectId) { |
| | | static sketch (configs, selectId, debug = false) { |
| | | if (!configs.height || !configs.width) return |
| | | |
| | | if (configs.height / configs.width > 10 || configs.width / configs.height > 10) return |
| | |
| | | }) |
| | | |
| | | return new Promise(resolve => { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | }) |
| | | } else { |
| | | return new Promise(resolve => { |
| | |
| | | * @param {Object} context 画布对象 |
| | | * @param {Object} elements 图片文字信息 |
| | | */ |
| | | static sketchothers (context, elements, selectId, ratio, resolve) { |
| | | static sketchothers (context, elements, selectId, debug, ratio, resolve) { |
| | | let element = elements.splice(0, 1)[0] // 逐个绘制图片文字 |
| | | let textLineSpace = 5 // 绘制时行间距,防止文字重叠 |
| | | context.save() |
| | |
| | | context.translate(-_cx, -_cy) // 恢复原点 |
| | | } |
| | | |
| | | if (selectId === element.uuid) { // 选中元素,设置外部阴影 |
| | | if (debug || selectId === element.uuid) { // 选中元素,设置外部阴影 |
| | | context.shadowBlur = 5 |
| | | context.shadowColor = '#1890ff' |
| | | context.fillStyle = 'white' |
| | |
| | | context.fillRect(element.left, element.top, element.width, element.height) |
| | | } |
| | | |
| | | if (selectId === element.uuid && element.width > 3 * ratio && element.height > 3 * ratio) { // 选中元素,设置外部阴影 |
| | | if ((debug || selectId === element.uuid) && element.width > 3 * ratio && element.height > 3 * ratio) { // 选中元素,设置外部阴影 |
| | | context.strokeStyle = '#1890ff' |
| | | context.beginPath() |
| | | context.moveTo(element.left + element.width - 7, element.top + element.height - 2) |
| | |
| | | if (!element.width || !element.height) { |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |
| | |
| | | image.onerror = () => { |
| | | context.restore() // 重置画布 |
| | | if (elements.length > 0) { |
| | | this.sketchothers(context, elements, selectId, ratio, resolve) |
| | | this.sketchothers(context, elements, selectId, debug, ratio, resolve) |
| | | } else { |
| | | this.cachesketch(context, resolve) |
| | | } |