diff options
author | crupest <crupest@outlook.com> | 2021-11-16 21:09:37 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-11-16 21:09:37 +0800 |
commit | f61cd0575f9f8b7be154073304795c22b0ec26ab (patch) | |
tree | ce5ee227a278ee104cd3121612b12f114abd5c89 /src | |
parent | 835ec1f25454cd14c5eda45b5bcb614c894fc948 (diff) | |
download | cru-f61cd0575f9f8b7be154073304795c22b0ec26ab.tar.gz cru-f61cd0575f9f8b7be154073304795c22b0ec26ab.tar.bz2 cru-f61cd0575f9f8b7be154073304795c22b0ec26ab.zip |
...
Diffstat (limited to 'src')
-rw-r--r-- | src/osx/graphics/quartz/TextLayout.cpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/osx/graphics/quartz/TextLayout.cpp b/src/osx/graphics/quartz/TextLayout.cpp index e47c0109..a5607854 100644 --- a/src/osx/graphics/quartz/TextLayout.cpp +++ b/src/osx/graphics/quartz/TextLayout.cpp @@ -142,12 +142,13 @@ Rect OsxCTTextLayout::TextSinglePoint(Index position, bool trailing) { if (position < head_empty_line_count_) { return {0, position * font_->GetFontSize(), 0, font_->GetFontSize()}; } else if (position > text_.size() - tail_empty_line_count_) { - return {0, - static_cast<float>(DoGetTextBounds().size.height) + - (head_empty_line_count_ + position - - (text_.size() - tail_empty_line_count_) - 1) * - font_->GetFontSize(), - 0, font_->GetFontSize()}; + return { + 0, + static_cast<float>(text_bounds_without_trailing_space_.size.height) + + (head_empty_line_count_ + position - + (text_.size() - tail_empty_line_count_) - 1) * + font_->GetFontSize(), + 0, font_->GetFontSize()}; } else { auto result = DoTextSinglePoint(position - head_empty_line_count_, trailing); @@ -168,7 +169,7 @@ TextHitTestResult OsxCTTextLayout::HitTest(const Point& point) { } } - auto text_bounds = DoGetTextBounds(); + auto text_bounds = text_bounds_without_trailing_space_; auto text_height = static_cast<float>(text_bounds.size.height); auto th = text_height + head_empty_line_count_ * font_->GetFontSize(); @@ -278,6 +279,8 @@ void OsxCTTextLayout::RecreateFrame() { } auto bounds = DoGetTextBounds(false); + text_bounds_without_trailing_space_ = bounds; + text_bounds_with_trailing_space_ = DoGetTextBounds(true); transform_ = Matrix::Translation(-bounds.origin.x, -bounds.origin.y) * @@ -347,7 +350,8 @@ CGRect OsxCTTextLayout::DoGetTextBounds(bool includingTrailingSpace) { CGRect OsxCTTextLayout::DoGetTextBoundsIncludingEmptyLines( bool includingTrailingSpace) { - auto result = DoGetTextBounds(includingTrailingSpace); + auto result = includingTrailingSpace ? text_bounds_with_trailing_space_ + : text_bounds_without_trailing_space_; result.size.height += head_empty_line_count_ * font_->GetFontSize(); result.size.height += tail_empty_line_count_ * font_->GetFontSize(); |