Commit 22a5beca by 李伟康

修复BUG

1 parent f66b741f
...@@ -55,8 +55,10 @@ class Draw { ...@@ -55,8 +55,10 @@ class Draw {
toRpx (val) { toRpx (val) {
return this[_pixelRatio_] * val return this[_pixelRatio_] * val
} }
getTextWidth (text, fontSize = 12) { getTextWidth (text, fontSize) {
return this[_ctx_].measureText(text).width * fontSize / 12 let font = this[_ctx_].font.split('px')[1]
if (fontSize) this[_ctx_].font = `400 ${fontSize}px${font}`
return this[_ctx_].measureText(text).width
} }
drawFill (x, y, width, height, color) { drawFill (x, y, width, height, color) {
this[_ctx_].beginPath() this[_ctx_].beginPath()
...@@ -84,7 +86,7 @@ class Draw { ...@@ -84,7 +86,7 @@ class Draw {
x, x,
y, y,
} = textParams } = textParams
let text_width = this.getTextWidth(text, 12), let text_width = this.getTextWidth(text),
font = this[_ctx_].font.split('px')[1] font = this[_ctx_].font.split('px')[1]
textAlign = textAlign || 'left' textAlign = textAlign || 'left'
textBaseline = textBaseline || 'normal' textBaseline = textBaseline || 'normal'
......
...@@ -66,7 +66,8 @@ export default { ...@@ -66,7 +66,8 @@ export default {
labelEndX = 88 labelEndX = 88
const draw = new Draw(this, { const draw = new Draw(this, {
width: canvasWidth, width: canvasWidth,
height: canvasHeight height: canvasHeight,
// pixelRatio: 1
}) })
let valueList = [ let valueList = [
userName, userName,
...@@ -95,11 +96,9 @@ export default { ...@@ -95,11 +96,9 @@ export default {
} }
labelList.push('支付定金') labelList.push('支付定金')
valueList.push(`${payPrice}元`) valueList.push(`${payPrice}元`)
console.log(carText , draw.getTextWidth(carText, fontSize) + valueX , valueEndX)
labelList.map((e, index) => { labelList.map((e, index) => {
if (e == '商品名称:' && draw.getTextWidth(carText, fontSize) + valueX > valueEndX - valueX) spacing = 24 if (e == '商品名称:' && draw.getTextWidth(carText, fontSize) > valueEndX - valueX) spacing = 24
if (e == formDescribeSecond && draw.getTextWidth(formContentFirst, fontSize) + valueX > valueEndX - valueX) spacing = 48 if ((e == formDescribeSecond && draw.getTextWidth(formContentFirst, fontSize) > valueEndX - valueX) || e === formDescribeSecond && (draw.getTextWidth(formDescribeFirst, fontSize) > labelEndX - labelX)) spacing = 48
if (e === formDescribeSecond && (draw.getTextWidth(formDescribeFirst, fontSize) + labelX > labelEndX - labelX)) spacing = 48
if (index == labelList.length - 1) textYList.push(452) if (index == labelList.length - 1) textYList.push(452)
else textYList.push(index * 32 + 109 + spacing) else textYList.push(index * 32 + 109 + spacing)
}) })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!