diff --git a/modules/skparagraph/include/Paragraph.h b/modules/skparagraph/include/Paragraph.h index 420bdeb2cf3eaa16bad1327fd200bc13d68aa65c..4c44a07b838c82afbc31ba0c2960c64d3225c2b1 100644 --- a/modules/skparagraph/include/Paragraph.h +++ b/modules/skparagraph/include/Paragraph.h @@ -76,6 +76,8 @@ public: virtual void setState(InternalState state) = 0; virtual InternalState getState() const = 0; + + virtual std::string GetDumpInfo() const = 0; #endif virtual void layout(SkScalar width) = 0; diff --git a/modules/skparagraph/src/ParagraphImpl.cpp b/modules/skparagraph/src/ParagraphImpl.cpp index 0c3cd812aafe382de8f33e0f47d8937998e73879..1d7002ef53db005e7f7de2c7360acfd6a4285e39 100644 --- a/modules/skparagraph/src/ParagraphImpl.cpp +++ b/modules/skparagraph/src/ParagraphImpl.cpp @@ -28,6 +28,7 @@ #include #ifdef OHOS_SUPPORT +#include #include "log.h" #include "modules/skparagraph/src/TextLineBaseImpl.h" #include "TextParameter.h" @@ -646,17 +647,26 @@ void ParagraphImpl::layout(SkScalar rawWidth) { } void ParagraphImpl::paint(SkCanvas* canvas, SkScalar x, SkScalar y) { +#ifdef OHOS_SUPPORT + fState = kDrawn; +#endif CanvasParagraphPainter painter(canvas); paint(&painter, x, y); } void ParagraphImpl::paint(ParagraphPainter* painter, SkScalar x, SkScalar y) { +#ifdef OHOS_SUPPORT + fState = kDrawn; +#endif for (auto& line : fLines) { line.paint(painter, x, y); } } void ParagraphImpl::paint(ParagraphPainter* painter, RSPath* path, SkScalar hOffset, SkScalar vOffset) { +#ifdef OHOS_SUPPORT + fState = kDrawn; +#endif auto& style = fTextStyles[0].fStyle; float align = 0.0f; switch (paragraphStyle().getTextAlign()) { @@ -2426,5 +2436,61 @@ std::unique_ptr ParagraphImpl::CloneSelf() return paragraph; } +#ifdef OHOS_SUPPORT +std::string_view ParagraphImpl::GetState() const +{ + static std::unordered_map state = { + {kUnknown, "Unknow"}, + {kIndexed, "Indexed"}, + {kShaped, "Shaped"}, + {kLineBroken, "LineBroken"}, + {kFormatted, "Formatted"}, + {kDrawn, "Drawn"}, + }; + return state[fState]; +} + +std::string ParagraphImpl::GetDumpInfo() const +{ + std::ostringstream paragraphInfo; + paragraphInfo << "Paragraph dump:"; + paragraphInfo << "Text sz:" << fText.size() << ",State:" << GetState() << ","; + uint32_t glyphSize = 0; + uint32_t runIndex = 0; + for (auto& run : fRuns) { + paragraphInfo << "Run" << runIndex << " glyph sz:" << run.size() + << ",rng[" << run.textRange().start << "-" << run.textRange().end << "),"; + runIndex++; + glyphSize += run.size(); + } + uint32_t blockIndex = 0; + for (auto& block : fTextStyles) { + paragraphInfo << "Blk" << blockIndex + << " rng[" << block.fRange.start << "-"<< block.fRange.end << ")" + << ",sz:" << block.fStyle.getFontSize() + << ",clr:" << std::hex << block.fStyle.getColor() << std::dec + << ",ht:" << block.fStyle.getHeight() + << ",wt:" << block.fStyle.getFontStyle().GetWeight() + << ",wd:" << block.fStyle.getFontStyle().GetWidth() + << ",slt:" << block.fStyle.getFontStyle().GetSlant() << ","; + blockIndex++; + } + paragraphInfo << "Paragraph glyph sz:" << glyphSize << ","; + uint32_t lineIndex = 0; + for (auto& line : fLines) { + if (lineIndex > 0) { + paragraphInfo << ","; + } + auto runs = line.getLineAllRuns(); + auto runSize = runs.size(); + if (runSize !=0 ) { + paragraphInfo << "L" << lineIndex << " run rng:" << runs[0] << "-" << runs[runSize - 1]; + } + lineIndex++; + } + return paragraphInfo.str(); +} +#endif + } // namespace textlayout } // namespace skia diff --git a/modules/skparagraph/src/ParagraphImpl.h b/modules/skparagraph/src/ParagraphImpl.h index fe00f7ad2abd0cad4aa0e73ba308e5753c477314..c2c33705b9223037072dd4566076c850cbaf7706 100644 --- a/modules/skparagraph/src/ParagraphImpl.h +++ b/modules/skparagraph/src/ParagraphImpl.h @@ -136,6 +136,7 @@ public: #ifdef OHOS_SUPPORT TextRange getEllipsisTextRange() override; + std::string GetDumpInfo() const override; #endif TextLine& addLine(SkVector offset, SkVector advance, @@ -407,6 +408,7 @@ private: TextBox getEmptyTextRect(RectHeightStyle rectHeightStyle) const; size_t prefixByteCountUntilChar(size_t index); void copyProperties(const ParagraphImpl& source); + std::string_view GetState() const; #endif // Input