automatically lower signature font size if text doesn't fit
This commit is contained in:
committed by
Pete Matsyburka
parent
f1d6bbdc67
commit
e55c8f251d
@@ -251,13 +251,28 @@ export default {
|
|||||||
const context = canvas.getContext('2d')
|
const context = canvas.getContext('2d')
|
||||||
|
|
||||||
const fontFamily = 'Arial'
|
const fontFamily = 'Arial'
|
||||||
const fontSize = '44px'
|
const initialFontSize = 50
|
||||||
const fontStyle = 'italic'
|
const fontStyle = 'italic'
|
||||||
const fontWeight = ''
|
const fontWeight = ''
|
||||||
|
|
||||||
context.font = fontStyle + ' ' + fontWeight + ' ' + fontSize + ' ' + fontFamily
|
const setFontSize = (size) => {
|
||||||
context.textAlign = 'center'
|
context.font = `${fontStyle} ${fontWeight} ${size}px ${fontFamily}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const adjustFontSizeToFit = (text, maxWidth, initialSize) => {
|
||||||
|
let size = initialSize
|
||||||
|
|
||||||
|
setFontSize(size)
|
||||||
|
|
||||||
|
while (context.measureText(text).width > maxWidth && size > 1) {
|
||||||
|
size -= 1
|
||||||
|
setFontSize(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustFontSizeToFit(e.target.value, canvas.width / scale, initialFontSize)
|
||||||
|
|
||||||
|
context.textAlign = 'center'
|
||||||
context.clearRect(0, 0, canvas.width / scale, canvas.height / scale)
|
context.clearRect(0, 0, canvas.width / scale, canvas.height / scale)
|
||||||
context.fillText(e.target.value, canvas.width / 2 / scale, canvas.height / 2 / scale + 11)
|
context.fillText(e.target.value, canvas.width / 2 / scale, canvas.height / 2 / scale + 11)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -455,13 +455,28 @@ export default {
|
|||||||
const context = canvas.getContext('2d')
|
const context = canvas.getContext('2d')
|
||||||
|
|
||||||
const fontFamily = 'Dancing Script'
|
const fontFamily = 'Dancing Script'
|
||||||
const fontSize = '38px'
|
const initialFontSize = 44
|
||||||
const fontStyle = 'italic'
|
const fontStyle = 'italic'
|
||||||
const fontWeight = ''
|
const fontWeight = ''
|
||||||
|
|
||||||
context.font = fontStyle + ' ' + fontWeight + ' ' + fontSize + ' ' + fontFamily
|
const setFontSize = (size) => {
|
||||||
context.textAlign = 'center'
|
context.font = `${fontStyle} ${fontWeight} ${size}px ${fontFamily}`
|
||||||
|
}
|
||||||
|
|
||||||
|
const adjustFontSizeToFit = (text, maxWidth, initialSize) => {
|
||||||
|
let size = initialSize
|
||||||
|
|
||||||
|
setFontSize(size)
|
||||||
|
|
||||||
|
while (context.measureText(text).width > maxWidth && size > 1) {
|
||||||
|
size -= 1
|
||||||
|
setFontSize(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
adjustFontSizeToFit(e.target.value, canvas.width / scale, initialFontSize)
|
||||||
|
|
||||||
|
context.textAlign = 'center'
|
||||||
context.clearRect(0, 0, canvas.width / scale, canvas.height / scale)
|
context.clearRect(0, 0, canvas.width / scale, canvas.height / scale)
|
||||||
context.fillText(e.target.value, canvas.width / 2 / scale, canvas.height / 2 / scale + 11)
|
context.fillText(e.target.value, canvas.width / 2 / scale, canvas.height / 2 / scale + 11)
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user