From 44b91fb795986d07cdb2741161277ab91cfa5349 Mon Sep 17 00:00:00 2001 From: FTL1ght Date: Thu, 11 Sep 2025 19:54:05 +0800 Subject: [PATCH] Fix the issue of ellipsis not being drawn Signed-off-by: FTL1ght Change-Id: I44388bbf9cb9bc58f51d675ca64290fd06cd691b --- m133/modules/skparagraph/src/ParagraphImpl.h | 6 +++ m133/modules/skparagraph/src/TextLine.cpp | 46 ++++++++++++-------- m133/modules/skparagraph/src/TextLine.h | 2 + modules/skparagraph/src/ParagraphImpl.h | 6 +++ modules/skparagraph/src/TextLine.cpp | 46 ++++++++++++-------- modules/skparagraph/src/TextLine.h | 2 + 6 files changed, 72 insertions(+), 36 deletions(-) diff --git a/m133/modules/skparagraph/src/ParagraphImpl.h b/m133/modules/skparagraph/src/ParagraphImpl.h index e3d5e8fae5..87cd496de4 100644 --- a/m133/modules/skparagraph/src/ParagraphImpl.h +++ b/m133/modules/skparagraph/src/ParagraphImpl.h @@ -357,6 +357,10 @@ public: bool IsPlaceholderAlignedFollowParagraph(size_t placeholderIndex); bool setPlaceholderAlignment(size_t placeholderIndex, PlaceholderAlignment alignment); Block& getBlockByRun(const Run& run); + int getEllipsisRunIndexOffset() const { return fEllipsisRunIndexOffset; } + void setEllipsisRunIndexOffset(int offset) { fEllipsisRunIndexOffset = offset; } + bool IsEllipsisReplaceFitCluster() const { return fIsEllipsisReplaceFitCluster; } + void setIsEllipsisReplaceFitCluster(bool state) { fIsEllipsisReplaceFitCluster = state; } #endif private: friend class ParagraphBuilder; @@ -465,6 +469,8 @@ private: // just for building cluster table, record the last built unicode autospacing flag; Cluster::AutoSpacingFlag fLastAutoSpacingFlag; bool fSkipTextBlobDrawing{false}; + int fEllipsisRunIndexOffset{0}; + bool fIsEllipsisReplaceFitCluster{false}; #endif }; } // namespace textlayout diff --git a/m133/modules/skparagraph/src/TextLine.cpp b/m133/modules/skparagraph/src/TextLine.cpp index d9f58e1574..2f02de7bc6 100644 --- a/m133/modules/skparagraph/src/TextLine.cpp +++ b/m133/modules/skparagraph/src/TextLine.cpp @@ -1217,7 +1217,11 @@ void TextLine::createTailEllipsis(SkScalar maxWidth, const SkString& ellipsis, b // Update the ellipsis attributes and line attributes. TailEllipsisUpdateEllipsis(cluster, ellipsisRun, ellipsis, width); TailEllipsisUpdateLine(cluster, width, clusterIndex, wordBreakType); - + // Update the ellipsis info for the paragraph that has been split runs. + if (fEllipsis && fOwner->getParagraphStyle().getVerticalAlignment() != TextVerticalAlign::BASELINE) { + fOwner->setEllipsisRunIndexOffset(cluster.runIndex() - fEllipsisIndex); + fOwner->setIsEllipsisReplaceFitCluster(cluster.textRange().start == fEllipsis->textRange().start); + } break; } @@ -3443,8 +3447,24 @@ void TextLine::applyVerticalShift() { } } -void TextLine::refresh() { - // Refresh line runs order +void TextLine::refreshLineEllipsis() { + if (!ellipsis()) { + return; + } + + TextIndex replaceTextIndex = fOwner->IsEllipsisReplaceFitCluster() ? + ellipsis()->textRange().start : ellipsis()->textRange().start - 1; + ClusterIndex clusterIndex = fOwner->clusterIndex(replaceTextIndex); + size_t runIndex = fOwner->cluster(clusterIndex).runIndex() + fOwner->getEllipsisRunIndexOffset(); + ellipsis()->fIndex = runIndex; + setEllipsisRunIndex(runIndex); +} + +void TextLine::refreshLineRuns() { + if (fRunsInVisualOrder.empty()) { + return; + } + auto& start = fOwner->cluster(clustersWithSpaces().start); auto& end = fOwner->cluster(clustersWithSpaces().end - 1); size_t numRuns = end.runIndex() - start.runIndex() + 1; @@ -3477,22 +3497,12 @@ void TextLine::refresh() { } } setLineAllRuns(runsInVisualOrder); +} - if (ellipsis()) { - ClusterIndex clusterIndex = 0; - if (fOwner->getParagraphStyle().getEllipsisMod() == EllipsisModal::HEAD) { - clusterIndex = clusters().start; - } else { - TextIndex textIndex = ellipsis()->textRange().start == 0 ? 0 : ellipsis()->textRange().start - 1; - if (textIndex > 0) { - textIndex--; - } - clusterIndex = fOwner->clusterIndex(textIndex); - } - size_t runIndex = fOwner->cluster(clusterIndex).runIndex(); - ellipsis()->fIndex = runIndex; - setEllipsisRunIndex(runIndex); - } +void TextLine::refresh() { + refreshLineEllipsis(); + // Refresh line runs order + refreshLineRuns(); } RSRect TextLine::getImageBounds() const diff --git a/m133/modules/skparagraph/src/TextLine.h b/m133/modules/skparagraph/src/TextLine.h index 4458ea8362..594f4a7196 100644 --- a/m133/modules/skparagraph/src/TextLine.h +++ b/m133/modules/skparagraph/src/TextLine.h @@ -362,6 +362,8 @@ private: void computeNextPaintGlyphRange(ClipContext& context, const TextRange& lastGlyphRange, StyleType styleType) const; SkRect computeShadowRect(SkScalar x, SkScalar y, const TextStyle& style, const ClipContext& context) const; SkRect getAllShadowsRect(SkScalar x, SkScalar y) const; + void refreshLineRuns(); + void refreshLineEllipsis(); #endif ParagraphImpl* fOwner; diff --git a/modules/skparagraph/src/ParagraphImpl.h b/modules/skparagraph/src/ParagraphImpl.h index 3f765fe235..3f81dd36d4 100644 --- a/modules/skparagraph/src/ParagraphImpl.h +++ b/modules/skparagraph/src/ParagraphImpl.h @@ -345,6 +345,10 @@ public: bool IsPlaceholderAlignedFollowParagraph(size_t placeholderIndex); bool setPlaceholderAlignment(size_t placeholderIndex, PlaceholderAlignment alignment); Block& getBlockByRun(const Run& run); + int getEllipsisRunIndexOffset() const { return fEllipsisRunIndexOffset; } + void setEllipsisRunIndexOffset(int offset) { fEllipsisRunIndexOffset = offset; } + bool IsEllipsisReplaceFitCluster() const { return fIsEllipsisReplaceFitCluster; } + void setIsEllipsisReplaceFitCluster(bool state) { fIsEllipsisReplaceFitCluster = state; } #endif #ifndef USE_SKIA_TXT bool GetLineFontMetrics(const size_t lineNumber, size_t& charNumber, @@ -474,6 +478,8 @@ private: // just for building cluster table, record the last built unicode autospacing flag; Cluster::AutoSpacingFlag fLastAutoSpacingFlag; bool fSkipTextBlobDrawing{false}; + int fEllipsisRunIndexOffset{0}; + bool fIsEllipsisReplaceFitCluster{false}; #endif }; } // namespace textlayout diff --git a/modules/skparagraph/src/TextLine.cpp b/modules/skparagraph/src/TextLine.cpp index 3a28ffd4c5..5922586f10 100644 --- a/modules/skparagraph/src/TextLine.cpp +++ b/modules/skparagraph/src/TextLine.cpp @@ -1163,7 +1163,11 @@ void TextLine::createTailEllipsis(SkScalar maxWidth, const SkString& ellipsis, b // Update the ellipsis attributes and line attributes. TailEllipsisUpdateEllipsis(cluster, ellipsisRun, ellipsis, width); TailEllipsisUpdateLine(cluster, width, clusterIndex, wordBreakType); - + // Update the ellipsis info for the paragraph that has been split runs. + if (fEllipsis && fOwner->getParagraphStyle().getVerticalAlignment() != TextVerticalAlign::BASELINE) { + fOwner->setEllipsisRunIndexOffset(cluster.runIndex() - fEllipsisIndex); + fOwner->setIsEllipsisReplaceFitCluster(cluster.textRange().start == fEllipsis->textRange().start); + } break; } @@ -3122,8 +3126,24 @@ void TextLine::applyVerticalShift() { } } -void TextLine::refresh() { - // Refresh line runs order +void TextLine::refreshLineEllipsis() { + if (!ellipsis()) { + return; + } + + TextIndex replaceTextIndex = fOwner->IsEllipsisReplaceFitCluster() ? + ellipsis()->textRange().start : ellipsis()->textRange().start - 1; + ClusterIndex clusterIndex = fOwner->clusterIndex(replaceTextIndex); + size_t runIndex = fOwner->cluster(clusterIndex).runIndex() + fOwner->getEllipsisRunIndexOffset(); + ellipsis()->fIndex = runIndex; + setEllipsisRunIndex(runIndex); +} + +void TextLine::refreshLineRuns() { + if (fRunsInVisualOrder.empty()) { + return; + } + auto& start = fOwner->cluster(clustersWithSpaces().start); auto& end = fOwner->cluster(clustersWithSpaces().end - 1); size_t numRuns = end.runIndex() - start.runIndex() + 1; @@ -3156,22 +3176,12 @@ void TextLine::refresh() { } } setLineAllRuns(runsInVisualOrder); +} - if (ellipsis()) { - ClusterIndex clusterIndex = 0; - if (fOwner->getParagraphStyle().getEllipsisMod() == EllipsisModal::HEAD) { - clusterIndex = clusters().start; - } else { - TextIndex textIndex = ellipsis()->textRange().start == 0 ? 0 : ellipsis()->textRange().start - 1; - if (textIndex > 0) { - textIndex--; - } - clusterIndex = fOwner->clusterIndex(textIndex); - } - size_t runIndex = fOwner->cluster(clusterIndex).runIndex(); - ellipsis()->fIndex = runIndex; - setEllipsisRunIndex(runIndex); - } +void TextLine::refresh() { + refreshLineEllipsis(); + // Refresh line runs order + refreshLineRuns(); } RSRect TextLine::getImageBounds() const diff --git a/modules/skparagraph/src/TextLine.h b/modules/skparagraph/src/TextLine.h index d57b66a9c0..90496d07fb 100644 --- a/modules/skparagraph/src/TextLine.h +++ b/modules/skparagraph/src/TextLine.h @@ -352,6 +352,8 @@ private: void computeNextPaintGlyphRange(ClipContext& context, const TextRange& lastGlyphRange, StyleType styleType) const; SkRect computeShadowRect(SkScalar x, SkScalar y, const TextStyle& style, const ClipContext& context) const; SkRect getAllShadowsRect(SkScalar x, SkScalar y) const; + void refreshLineRuns(); + void refreshLineEllipsis(); #endif ParagraphImpl* fOwner; -- Gitee