!16150 支持计算文字及文字阴影绘制区域

Merge pull request !16150 from liumingxiang/text_paint_region
This commit is contained in:
openharmony_ci 2024-10-30 02:57:32 +00:00 committed by Gitee
commit e063e5fd76
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
6 changed files with 29 additions and 0 deletions

View File

@ -462,6 +462,18 @@ void Typography::UpdateColor(size_t from, size_t to, const Drawing::Color& color
}
paragraph_->UpdateColor(from, to, color);
}
Drawing::RectI Typography::GeneratePaintRegion(double x, double y) const
{
std::unique_lock<std::shared_mutex> writeLock(mutex_);
if (!paragraph_) {
double left = std::floor(x);
double top = std::floor(y);
return Drawing::RectI(left, top, left, top);
}
return paragraph_->GeneratePaintRegion(x, y);
}
} // namespace AdapterTxt
} // namespace Rosen
} // namespace OHOS

View File

@ -76,6 +76,7 @@ public:
std::unique_ptr<OHOS::Rosen::Typography> CloneSelf() override;
void UpdateColor(size_t from, size_t to, const Drawing::Color& color) override;
void* GetParagraph() override { return reinterpret_cast<void*>(paragraph_.get()); }
Drawing::RectI GeneratePaintRegion(double x, double y) const override;
private:
std::unique_ptr<SPText::Paragraph> paragraph_ = nullptr;
std::vector<TextStyle> lineMetricsStyles_;

View File

@ -163,6 +163,7 @@ public:
virtual void UpdateColor(size_t from, size_t to, const Drawing::Color& color) = 0;
virtual double GetLongestLineWithIndent() const = 0;
virtual void* GetParagraph() = 0;
virtual Drawing::RectI GeneratePaintRegion(double x, double y) const = 0;
};
} // namespace Rosen
} // namespace OHOS

View File

@ -416,6 +416,19 @@ void ParagraphImpl::RecordDifferentPthreadCall(const char* caller) const
threadId_ = currenetThreadId;
}
}
Drawing::RectI ParagraphImpl::GeneratePaintRegion(double x, double y)
{
RecordDifferentPthreadCall("GeneratePaintRegion");
if (!paragraph_) {
double left = std::floor(x);
double top = std::floor(y);
return Drawing::RectI(left, top, left, top);
}
SkIRect skIRect = paragraph_->generatePaintRegion(SkDoubleToScalar(x), SkDoubleToScalar(y));
return Drawing::RectI(skIRect.left(), skIRect.top(), skIRect.right(), skIRect.bottom());
}
} // namespace SPText
} // namespace Rosen
} // namespace OHOS

View File

@ -120,6 +120,7 @@ public:
std::unique_ptr<Paragraph> CloneSelf() override;
TextStyle SkStyleToTextStyle(const skia::textlayout::TextStyle& skStyle) override;
void UpdateColor(size_t from, size_t to, const RSColor& color) override;
Drawing::RectI GeneratePaintRegion(double x, double y) override;
private:
void RecordDifferentPthreadCall(const char* caller) const;

View File

@ -197,6 +197,7 @@ public:
virtual TextStyle SkStyleToTextStyle(const skia::textlayout::TextStyle& skStyle) = 0;
virtual void UpdateColor(size_t from, size_t to, const RSColor& color) = 0;
virtual Range<size_t> GetEllipsisTextRange() = 0;
virtual OHOS::Rosen::Drawing::RectI GeneratePaintRegion(double x, double y) = 0;
};
} // namespace SPText
} // namespace Rosen