fix: web text maxLines

This commit is contained in:
钱泽虹 2023-09-12 19:08:12 +08:00 committed by osborn
parent 87a485e5a2
commit afb3de1fbc
3 changed files with 10 additions and 4 deletions

View File

@ -7301,7 +7301,7 @@ var doric_web = (function (exports, axios, sandbox) {
if (this.maxLines > 0) { if (this.maxLines > 0) {
const computedStyle = window.getComputedStyle(this.view); const computedStyle = window.getComputedStyle(this.view);
const currentContentHeight = this.view.clientHeight - pixelString2Number(computedStyle.paddingTop) - pixelString2Number(computedStyle.paddingBottom); const currentContentHeight = this.view.clientHeight - pixelString2Number(computedStyle.paddingTop) - pixelString2Number(computedStyle.paddingBottom);
let maxHeight = parseFloat(computedStyle.getPropertyValue('font-size')) * this.lineHeight() * this.maxLines; let maxHeight = Math.ceil(parseFloat(computedStyle.getPropertyValue('font-size')) * this.lineHeight() * this.maxLines);
if (currentContentHeight > 0) { if (currentContentHeight > 0) {
maxHeight = Math.min(maxHeight, Math.ceil(currentContentHeight)); maxHeight = Math.min(maxHeight, Math.ceil(currentContentHeight));
} }
@ -7318,6 +7318,8 @@ var doric_web = (function (exports, axios, sandbox) {
tempEle.style.font = style.font; tempEle.style.font = style.font;
tempEle.textContent = this.textElement.innerText; tempEle.textContent = this.textElement.innerText;
tempEle.style.whiteSpace = 'normal'; tempEle.style.whiteSpace = 'normal';
this.view.style.overflow = 'hidden';
tempEle.style.lineHeight = `${this.lineHeight()}em`;
tempEle.style.width = this.view.style.width; tempEle.style.width = this.view.style.width;
document.body.appendChild(tempEle); document.body.appendChild(tempEle);
const height = tempEle.offsetHeight; const height = tempEle.offsetHeight;
@ -7331,6 +7333,7 @@ var doric_web = (function (exports, axios, sandbox) {
tempEle.style.font = style.font; tempEle.style.font = style.font;
tempEle.style.whiteSpace = 'normal'; tempEle.style.whiteSpace = 'normal';
this.view.style.overflow = 'hidden'; this.view.style.overflow = 'hidden';
tempEle.style.lineHeight = `${this.lineHeight()}em`;
tempEle.style.width = this.view.style.width; tempEle.style.width = this.view.style.width;
document.body.appendChild(tempEle); document.body.appendChild(tempEle);
while (start <= end) { while (start <= end) {

File diff suppressed because one or more lines are too long

View File

@ -102,7 +102,7 @@ export class DoricTextNode extends DoricViewNode {
if (this.maxLines > 0) { if (this.maxLines > 0) {
const computedStyle = window.getComputedStyle(this.view) const computedStyle = window.getComputedStyle(this.view)
const currentContentHeight = this.view.clientHeight - pixelString2Number(computedStyle.paddingTop) - pixelString2Number(computedStyle.paddingBottom) const currentContentHeight = this.view.clientHeight - pixelString2Number(computedStyle.paddingTop) - pixelString2Number(computedStyle.paddingBottom)
let maxHeight = parseFloat(computedStyle.getPropertyValue('font-size')) * this.lineHeight() * this.maxLines let maxHeight = Math.ceil(parseFloat(computedStyle.getPropertyValue('font-size')) * this.lineHeight() * this.maxLines)
if (currentContentHeight > 0) { if (currentContentHeight > 0) {
maxHeight = Math.min(maxHeight, Math.ceil(currentContentHeight)) maxHeight = Math.min(maxHeight, Math.ceil(currentContentHeight))
} }
@ -115,12 +115,14 @@ export class DoricTextNode extends DoricViewNode {
lineHeight() { lineHeight() {
return 1.3 return 1.3
} }
computedHeight(style:CSSStyleDeclaration) { computedHeight(style:CSSStyleDeclaration) {
const tempEle = document.createElement('div') const tempEle = document.createElement('div')
tempEle.style.font = style.font tempEle.style.font = style.font
tempEle.textContent = this.textElement.innerText tempEle.textContent = this.textElement.innerText
tempEle.style.whiteSpace = 'normal' tempEle.style.whiteSpace = 'normal'
this.view.style.overflow = 'hidden'
tempEle.style.lineHeight = `${this.lineHeight()}em`
tempEle.style.width = this.view.style.width tempEle.style.width = this.view.style.width
document.body.appendChild(tempEle) document.body.appendChild(tempEle)
@ -137,6 +139,7 @@ export class DoricTextNode extends DoricViewNode {
tempEle.style.font = style.font tempEle.style.font = style.font
tempEle.style.whiteSpace = 'normal' tempEle.style.whiteSpace = 'normal'
this.view.style.overflow = 'hidden' this.view.style.overflow = 'hidden'
tempEle.style.lineHeight = `${this.lineHeight()}em`
tempEle.style.width = this.view.style.width tempEle.style.width = this.view.style.width
document.body.appendChild(tempEle); document.body.appendChild(tempEle);