diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-18 21:25:44 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-18 21:25:44 +0800 |
| commit | df2dadbd0f0ace6e02281c84218537ec2ce5c47f (patch) | |
| tree | 56a360c16c4ba46658572305d3a444fb30d32272 /src/platform/graphics/direct2d | |
| parent | 3648f669cb42cdd9d232d60c8b9715dfbbe5b31a (diff) | |
| download | cru-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/direct2d')
| -rw-r--r-- | src/platform/graphics/direct2d/Font.cpp | 2 | ||||
| -rw-r--r-- | src/platform/graphics/direct2d/TextLayout.cpp | 26 |
2 files changed, 10 insertions, 18 deletions
diff --git a/src/platform/graphics/direct2d/Font.cpp b/src/platform/graphics/direct2d/Font.cpp index 18a4a2c7..4e0a5e49 100644 --- a/src/platform/graphics/direct2d/Font.cpp +++ b/src/platform/graphics/direct2d/Font.cpp @@ -17,7 +17,7 @@ DWriteFont::DWriteFont(DirectGraphicsFactory* factory, std::string font_family, ::GetLastError(), "Failed to get locale when create dwrite font."); CheckHResult(factory->GetDWriteFactory()->CreateTextFormat( - string::ToUtf16(font_family_).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, + string::ToUtf16WString(font_family_).c_str(), nullptr, DWRITE_FONT_WEIGHT_NORMAL, DWRITE_FONT_STYLE_NORMAL, DWRITE_FONT_STRETCH_NORMAL, font_size, buffer.data(), &text_format_)); diff --git a/src/platform/graphics/direct2d/TextLayout.cpp b/src/platform/graphics/direct2d/TextLayout.cpp index 3fc91616..18784ccb 100644 --- a/src/platform/graphics/direct2d/TextLayout.cpp +++ b/src/platform/graphics/direct2d/TextLayout.cpp @@ -13,7 +13,7 @@ DWriteTextLayout::DWriteTextLayout(DirectGraphicsFactory* factory, Expects(font); font_ = CheckPlatform<DWriteFont>(font, GetPlatformId()); - utf16_text_ = string::ToUtf16(text_); + utf16_text_ = string::ToUtf16WString(text_); CheckHResult(factory->GetDWriteFactory()->CreateTextLayout( utf16_text_.c_str(), static_cast<UINT32>(utf16_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); @@ -25,7 +25,7 @@ std::string DWriteTextLayout::GetText() { return text_; } void DWriteTextLayout::SetText(std::string new_text) { text_ = std::move(new_text); - utf16_text_ = string::ToUtf16(text_); + utf16_text_ = string::ToUtf16WString(text_); CheckHResult(GetDirectFactory()->GetDWriteFactory()->CreateTextLayout( utf16_text_.c_str(), static_cast<UINT32>(utf16_text_.size()), font_->GetComInterface(), max_width_, max_height_, &text_layout_)); @@ -108,15 +108,11 @@ std::vector<Rect> DWriteTextLayout::TextRangeRect( const auto text_range = Range::FromTwoSides( string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - text_range_arg.GetStart())), + utf16_text_, string::Utf8IndexCodeUnitToCodePoint( + text_, text_range_arg.GetStart())), string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - text_range_arg.GetEnd()))) + utf16_text_, string::Utf8IndexCodeUnitToCodePoint( + text_, text_range_arg.GetEnd()))) .Normalize(); DWRITE_TEXT_METRICS text_metrics; @@ -147,9 +143,7 @@ std::vector<Rect> DWriteTextLayout::TextRangeRect( Rect DWriteTextLayout::TextSinglePoint(Index position, bool trailing) { position = string::Utf16IndexCodePointToCodeUnit( - reinterpret_cast<const char16_t*>(utf16_text_.data()), utf16_text_.size(), - string::Utf8IndexCodeUnitToCodePoint(text_.data(), text_.size(), - position)); + utf16_text_, string::Utf8IndexCodeUnitToCodePoint(text_, position)); DWRITE_HIT_TEST_METRICS metrics; FLOAT left; FLOAT top; @@ -169,10 +163,8 @@ TextHitTestResult DWriteTextLayout::HitTest(const Point& point) { TextHitTestResult result; result.position = string::Utf8IndexCodePointToCodeUnit( - text_.data(), text_.size(), - string::Utf16IndexCodeUnitToCodePoint( - reinterpret_cast<const char16_t*>(utf16_text_.data()), - utf16_text_.size(), metrics.textPosition)); + text_, + string::Utf16IndexCodeUnitToCodePoint(utf16_text_, metrics.textPosition)); result.trailing = trailing != 0; if (result.trailing) { |
