diff --git a/m133/modules/skparagraph/src/ParagraphImpl.h b/m133/modules/skparagraph/src/ParagraphImpl.h index e3d5e8fae555eef1dc23399c5c451e15ad448693..87cd496de48836e251448470d45778b4120f33be 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 d9f58e15746f9deaf07a4313e8ece0b293c6e694..2f02de7bc63a98445edef7797113d77622dbea50 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 4458ea8362011ae352cdabd49591f3e2aabf3c65..594f4a7196c205505b5ad85da2f94add0b38fc46 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 3f765fe2352d8ce87749f5bedd92e3cc99b92f3f..3f81dd36d452b5eb9bfb456fcff25f8b4756023c 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 3a28ffd4c52076124c47355584ff2d954a20dcf7..5922586f10e40ee411bbf8ef7843c9e2b7249d90 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 d57b66a9c0ce7dbc564faebce4551fc6f3331eaf..90496d07fbc6d19e6a0ac1f1384222466f44fe2e 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;