fix: copy highlight element #193

pr675
Hufe921 3 years ago
parent e4ea580263
commit 88ebfd2f74

@ -1178,6 +1178,17 @@ export class Draw {
leftTop: [x, y]
}
} = positionList[curRow.startIndex + j]
const preElement = curRow.elementList[j - 1]
// 元素高亮记录
if (element.highlight) {
// 高亮元素相连需立即绘制,并记录下一元素坐标
if (preElement && preElement.highlight && preElement.highlight !== element.highlight) {
this.highlight.render(ctx)
}
this.highlight.recordFillInfo(ctx, x, y, metrics.width, curRow.height, element.highlight)
} else if (preElement?.highlight) {
this.highlight.render(ctx)
}
// 元素绘制
if (element.type === ElementType.IMAGE) {
this._drawRichText(ctx)
@ -1228,7 +1239,6 @@ export class Draw {
} else {
this.textParticle.record(ctx, element, x, y + offsetY)
}
const preElement = curRow.elementList[j - 1]
// 下划线记录
if (element.underline) {
this.underline.recordFillInfo(ctx, x, y + curRow.height, metrics.width, 0, element.color)
@ -1241,16 +1251,6 @@ export class Draw {
} else if (preElement?.strikeout) {
this.strikeout.render(ctx)
}
// 元素高亮记录
if (element.highlight) {
// 高亮元素相连需立即绘制,并记录下一元素坐标
if (preElement && preElement.highlight && preElement.highlight !== element.highlight) {
this.highlight.render(ctx)
}
this.highlight.recordFillInfo(ctx, x, y, metrics.width, curRow.height, element.highlight)
} else if (preElement?.highlight) {
this.highlight.render(ctx)
}
// 选区记录
const { zone: currentZone, startIndex, endIndex } = this.range.getRange()
if (currentZone === zone && startIndex !== endIndex && startIndex <= index && index <= endIndex) {

@ -204,10 +204,13 @@ export function writeElementList(elementList: IElement[], options: DeepRequired<
export function convertTextNodeToElement(textNode: Element | Node): IElement | null {
if (!textNode || textNode.nodeType !== 3) return null
const parentNode = <HTMLElement>textNode.parentNode
const rowFlex = getElementRowFlex(parentNode)
const anchorNode = parentNode.nodeName === 'FONT'
? <HTMLElement>parentNode.parentNode
: parentNode
const rowFlex = getElementRowFlex(anchorNode)
const value = textNode.textContent
const style = window.getComputedStyle(parentNode)
if (!value || parentNode.nodeName === 'STYLE') return null
const style = window.getComputedStyle(anchorNode)
if (!value || anchorNode.nodeName === 'STYLE') return null
const element: IElement = {
value,
color: style.color,
@ -216,9 +219,9 @@ export function convertTextNodeToElement(textNode: Element | Node): IElement | n
size: Math.floor(parseFloat(style.fontSize))
}
// 元素类型-默认文本
if (parentNode.nodeName === 'SUB') {
if (anchorNode.nodeName === 'SUB' || style.verticalAlign === 'sub') {
element.type = ElementType.SUBSCRIPT
} else if (parentNode.nodeName === 'SUP') {
} else if (anchorNode.nodeName === 'SUP' || style.verticalAlign === 'super') {
element.type = ElementType.SUPERSCRIPT
}
// 行对齐

Loading…
Cancel
Save