mirror of
https://gitee.com/openharmony/arkui_ace_engine
synced 2024-11-23 23:21:05 +00:00
!38189 【RichEditor】适配文本引擎空段落无法返回实际行高问题
Merge pull request !38189 from xuyue/paragraphHeight
This commit is contained in:
commit
d150501861
@ -67,7 +67,7 @@ void RichEditorLayoutAlgorithm::AppendNewLineSpan()
|
||||
if (StringUtils::ToWstring(lastSpan->content).back() == L'\n') {
|
||||
std::list<RefPtr<SpanItem>> newGroup;
|
||||
auto tailNewLineSpan = AceType::MakeRefPtr<SpanItem>();
|
||||
tailNewLineSpan->content = " \n";
|
||||
tailNewLineSpan->content = "\n";
|
||||
tailNewLineSpan->SetNeedRemoveNewLine(true);
|
||||
CopySpanStyle(lastSpan, tailNewLineSpan);
|
||||
newGroup.push_back(tailNewLineSpan);
|
||||
@ -285,4 +285,30 @@ void RichEditorLayoutAlgorithm::GetSpanParagraphStyle(
|
||||
{
|
||||
MultipleParagraphLayoutAlgorithm::GetSpanParagraphStyle(lineStyle, pStyle);
|
||||
}
|
||||
|
||||
void RichEditorLayoutAlgorithm::HandleEmptyParagraph(RefPtr<Paragraph> paragraph,
|
||||
const std::list<RefPtr<SpanItem>>& spanGroup)
|
||||
{
|
||||
CHECK_NULL_VOID(paragraph && spanGroup.size() == 1);
|
||||
auto spanItem = spanGroup.front();
|
||||
CHECK_NULL_VOID(spanItem);
|
||||
auto content = spanItem->GetSpanContent(spanItem->GetSpanContent());
|
||||
CHECK_NULL_VOID(content.empty());
|
||||
auto textStyle = spanItem->GetTextStyle();
|
||||
CHECK_NULL_VOID(textStyle);
|
||||
paragraph->PushStyle(textStyle.value());
|
||||
}
|
||||
|
||||
RefPtr<SpanItem> RichEditorLayoutAlgorithm::GetParagraphStyleSpanItem(const std::list<RefPtr<SpanItem>>& spanGroup)
|
||||
{
|
||||
auto it = spanGroup.begin();
|
||||
while (it != spanGroup.end()) {
|
||||
if (!AceType::DynamicCast<PlaceholderSpanItem>(*it)) {
|
||||
return *it;
|
||||
}
|
||||
++it;
|
||||
}
|
||||
return *spanGroup.begin();
|
||||
}
|
||||
|
||||
} // namespace OHOS::Ace::NG
|
||||
|
@ -44,6 +44,8 @@ public:
|
||||
|
||||
protected:
|
||||
void GetSpanParagraphStyle(const std::unique_ptr<TextLineStyle>& lineStyle, ParagraphStyle& pStyle) override;
|
||||
void HandleEmptyParagraph(RefPtr<Paragraph> paragraph, const std::list<RefPtr<SpanItem>>& spanGroup) override;
|
||||
RefPtr<SpanItem> GetParagraphStyleSpanItem(const std::list<RefPtr<SpanItem>>& spanGroup) override;
|
||||
|
||||
private:
|
||||
OffsetF GetContentOffset(LayoutWrapper* layoutWrapper) override;
|
||||
|
@ -432,10 +432,11 @@ bool MultipleParagraphLayoutAlgorithm::UpdateParagraphBySpan(LayoutWrapper* layo
|
||||
auto maxLines = static_cast<int32_t>(paraStyle.maxLines);
|
||||
for (auto && group : spans_) {
|
||||
ParagraphStyle spanParagraphStyle = paraStyle;
|
||||
if (group.front()) {
|
||||
GetSpanParagraphStyle(group.front()->textLineStyle, spanParagraphStyle);
|
||||
if (group.front()->fontStyle->HasFontSize()) {
|
||||
auto fontSize = group.front()->fontStyle->GetFontSizeValue();
|
||||
RefPtr<SpanItem> paraStyleSpanItem = GetParagraphStyleSpanItem(group);
|
||||
if (paraStyleSpanItem) {
|
||||
GetSpanParagraphStyle(paraStyleSpanItem->textLineStyle, spanParagraphStyle);
|
||||
if (paraStyleSpanItem->fontStyle->HasFontSize()) {
|
||||
auto fontSize = paraStyleSpanItem->fontStyle->GetFontSizeValue();
|
||||
spanParagraphStyle.fontSize =
|
||||
fontSize.ConvertToPxDistribute(textStyle.GetMinFontScale(), textStyle.GetMaxFontScale());
|
||||
}
|
||||
@ -492,6 +493,7 @@ bool MultipleParagraphLayoutAlgorithm::UpdateParagraphBySpan(LayoutWrapper* layo
|
||||
preParagraphsPlaceholderCount_ += currentParagraphPlaceholderCount_;
|
||||
currentParagraphPlaceholderCount_ = 0;
|
||||
shadowOffset_ += GetShadowOffset(group);
|
||||
HandleEmptyParagraph(paragraph, group);
|
||||
paragraph->Build();
|
||||
ApplyIndent(spanParagraphStyle, paragraph, maxWidth, textStyle);
|
||||
UpdateSymbolSpanEffect(frameNode, paragraph, group);
|
||||
|
@ -57,6 +57,13 @@ protected:
|
||||
const TextStyle& textStyle, const std::string& content, LayoutWrapper* layoutWrapper) const;
|
||||
virtual bool CreateParagraph(
|
||||
const TextStyle& textStyle, std::string content, LayoutWrapper* layoutWrapper, double maxWidth = 0.0) = 0;
|
||||
virtual void HandleEmptyParagraph(RefPtr<Paragraph> paragraph, const std::list<RefPtr<SpanItem>>& spanGroup) {}
|
||||
virtual RefPtr<SpanItem> GetParagraphStyleSpanItem(const std::list<RefPtr<SpanItem>>& spanGroup)
|
||||
{
|
||||
CHECK_NULL_RETURN(!spanGroup.empty(), nullptr);
|
||||
return spanGroup.front();
|
||||
}
|
||||
|
||||
void ApplyIndent(ParagraphStyle& paragraphStyle, const RefPtr<Paragraph>& paragraph, double width,
|
||||
const TextStyle& textStyle);
|
||||
void ConstructTextStyles(
|
||||
|
Loading…
Reference in New Issue
Block a user