feat: text element width #277
This commit is contained in:
@@ -1593,6 +1593,10 @@ export class Draw {
|
|||||||
this.blockParticle.render(pageNo, element, x, y)
|
this.blockParticle.render(pageNo, element, x, y)
|
||||||
} else {
|
} else {
|
||||||
this.textParticle.record(ctx, element, x, y + offsetY)
|
this.textParticle.record(ctx, element, x, y + offsetY)
|
||||||
|
// 如果设置字宽需单独绘制
|
||||||
|
if (element.width) {
|
||||||
|
this._drawRichText(ctx)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// 下划线记录
|
// 下划线记录
|
||||||
if (element.underline || element.control?.underline) {
|
if (element.underline || element.control?.underline) {
|
||||||
|
|||||||
@@ -67,6 +67,20 @@ export class TextParticle {
|
|||||||
ctx: CanvasRenderingContext2D,
|
ctx: CanvasRenderingContext2D,
|
||||||
element: IElement
|
element: IElement
|
||||||
): TextMetrics {
|
): TextMetrics {
|
||||||
|
// 优先使用自定义字宽设置
|
||||||
|
if (element.width) {
|
||||||
|
const textMetrics = ctx.measureText(element.value)
|
||||||
|
// TextMetrics是类无法解构
|
||||||
|
return {
|
||||||
|
width: element.width,
|
||||||
|
actualBoundingBoxAscent: textMetrics.actualBoundingBoxAscent,
|
||||||
|
actualBoundingBoxDescent: textMetrics.actualBoundingBoxDescent,
|
||||||
|
actualBoundingBoxLeft: textMetrics.actualBoundingBoxLeft,
|
||||||
|
actualBoundingBoxRight: textMetrics.actualBoundingBoxRight,
|
||||||
|
fontBoundingBoxAscent: textMetrics.fontBoundingBoxAscent,
|
||||||
|
fontBoundingBoxDescent: textMetrics.fontBoundingBoxDescent
|
||||||
|
}
|
||||||
|
}
|
||||||
const id = `${element.value}${ctx.font}`
|
const id = `${element.value}${ctx.font}`
|
||||||
const cacheTextMetrics = this.cacheMeasureText.get(id)
|
const cacheTextMetrics = this.cacheMeasureText.get(id)
|
||||||
if (cacheTextMetrics) {
|
if (cacheTextMetrics) {
|
||||||
|
|||||||
Reference in New Issue
Block a user