aboutsummaryrefslogtreecommitdiff
path: root/src/platform/graphics/quartz/TextLayout.cpp
diff options
context:
space:
mode:
authorYuqian Yang <crupest@crupest.life>2025-11-18 21:25:44 +0800
committerYuqian Yang <crupest@crupest.life>2025-11-18 21:25:44 +0800
commitdf2dadbd0f0ace6e02281c84218537ec2ce5c47f (patch)
tree56a360c16c4ba46658572305d3a444fb30d32272 /src/platform/graphics/quartz/TextLayout.cpp
parent3648f669cb42cdd9d232d60c8b9715dfbbe5b31a (diff)
downloadcru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.tar.gz
cru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.tar.bz2
cru-df2dadbd0f0ace6e02281c84218537ec2ce5c47f.zip
Add overload of string_view for string utils. clean up codes.
Diffstat (limited to 'src/platform/graphics/quartz/TextLayout.cpp')
-rw-r--r--src/platform/graphics/quartz/TextLayout.cpp28
1 files changed, 11 insertions, 17 deletions
diff --git a/src/platform/graphics/quartz/TextLayout.cpp b/src/platform/graphics/quartz/TextLayout.cpp
index 4793a19c..80cb8a3f 100644
--- a/src/platform/graphics/quartz/TextLayout.cpp
+++ b/src/platform/graphics/quartz/TextLayout.cpp
@@ -238,28 +238,25 @@ TextHitTestResult OsxCTTextLayout::HitTest(const Point& point) {
bool inside_text;
if (pp.x < bounds.origin.x) {
- po = cru::string::Utf8IndexCodePointToCodeUnit(
- actual_text_.data(), actual_text_.size(), range.location);
+ po = cru::string::Utf8IndexCodePointToCodeUnit(actual_text_,
+ range.location);
inside_text = false;
} else if (pp.x > bounds.origin.x + bounds.size.width) {
po = cru::string::Utf8IndexCodePointToCodeUnit(
- actual_text_.data(), actual_text_.size(),
- range.location + range.length);
+ actual_text_, range.location + range.length);
inside_text = false;
} else {
int position = CTLineGetStringIndexForPosition(
line,
CGPointMake(pp.x - line_origins_[i].x, pp.y - line_origins_[i].y));
- po = cru::string::Utf8IndexCodePointToCodeUnit(
- actual_text_.data(), actual_text_.size(), position);
+ po = cru::string::Utf8IndexCodePointToCodeUnit(actual_text_, position);
inside_text = true;
}
if (po != 0 &&
po == cru::string::Utf8IndexCodePointToCodeUnit(
- actual_text_.data(), actual_text_.size(),
- range.location + range.length) &&
+ actual_text_, range.location + range.length) &&
actual_text_[po - 1] == u'\n') {
--po;
}
@@ -405,13 +402,11 @@ CGRect OsxCTTextLayout::DoGetTextBoundsIncludingEmptyLines(
std::vector<CGRect> OsxCTTextLayout::DoTextRangeRect(
const TextRange& text_range) {
- const auto r =
- Range::FromTwoSides(
- cru::string::Utf8IndexCodeUnitToCodePoint(
- actual_text_.data(), actual_text_.size(), text_range.position),
- cru::string::Utf8IndexCodeUnitToCodePoint(
- actual_text_.data(), actual_text_.size(), text_range.GetEnd()))
- .Normalize();
+ const auto r = Range::FromTwoSides(cru::string::Utf8IndexCodeUnitToCodePoint(
+ actual_text_, text_range.position),
+ cru::string::Utf8IndexCodeUnitToCodePoint(
+ actual_text_, text_range.GetEnd()))
+ .Normalize();
std::vector<CGRect> results;
@@ -443,8 +438,7 @@ CGRect OsxCTTextLayout::DoTextSinglePoint(Index position, bool trailing) {
if (actual_text_.empty()) return CGRectMake(0, 0, 0, font_->GetFontSize());
- position = cru::string::Utf8IndexCodeUnitToCodePoint(
- actual_text_.data(), actual_text_.size(), position);
+ position = cru::string::Utf8IndexCodeUnitToCodePoint(actual_text_, position);
for (int i = 0; i < line_count_; i++) {
auto line = lines_[i];