aboutsummaryrefslogtreecommitdiff
path: root/src/platform/graphics/cairo/PangoTextLayout.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/platform/graphics/cairo/PangoTextLayout.cpp')
-rw-r--r--src/platform/graphics/cairo/PangoTextLayout.cpp56
1 files changed, 15 insertions, 41 deletions
diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp
index 746056e2..f8ed20c7 100644
--- a/src/platform/graphics/cairo/PangoTextLayout.cpp
+++ b/src/platform/graphics/cairo/PangoTextLayout.cpp
@@ -1,5 +1,4 @@
#include "cru/platform/graphics/cairo/PangoTextLayout.h"
-#include "cru/base/StringUtil.h"
#include "cru/platform/Check.h"
#include "cru/platform/GraphicsBase.h"
#include "cru/platform/graphics/Base.h"
@@ -24,7 +23,7 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
std::shared_ptr<IFont> font)
: CairoResource(factory) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_ = pango_cairo_create_layout(factory->GetDefaultCairo());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
@@ -32,19 +31,18 @@ PangoTextLayout::PangoTextLayout(CairoGraphicsFactory* factory,
PangoTextLayout::~PangoTextLayout() { g_object_unref(pango_layout_); }
-String PangoTextLayout::GetText() { return text_; }
+std::string PangoTextLayout::GetText() { return text_; }
-void PangoTextLayout::SetText(String new_text) {
+void PangoTextLayout::SetText(std::string new_text) {
text_ = std::move(new_text);
- utf8_text_ = text_.ToUtf8();
- pango_layout_set_text(pango_layout_, utf8_text_.c_str(), utf8_text_.size());
+ pango_layout_set_text(pango_layout_, text_.c_str(), text_.size());
}
std::shared_ptr<IFont> PangoTextLayout::GetFont() { return font_; }
void PangoTextLayout::SetFont(std::shared_ptr<IFont> font) {
Expects(font);
- font_ = CheckPlatform<PangoFont>(font, GetPlatformIdUtf8());
+ font_ = CheckPlatform<PangoFont>(font, GetPlatformId());
pango_layout_set_font_description(pango_layout_,
font_->GetPangoFontDescription());
}
@@ -63,9 +61,8 @@ void PangoTextLayout::SetEditMode(bool enable) { edit_mode_ = enable; }
Index PangoTextLayout::GetLineIndexFromCharIndex(Index char_index) {
int line;
- pango_layout_index_to_line_x(pango_layout_,
- FromUtf16IndexToUtf8Index(char_index), false,
- &line, nullptr);
+ pango_layout_index_to_line_x(pango_layout_, char_index, false, &line,
+ nullptr);
return line;
}
@@ -80,27 +77,6 @@ float PangoTextLayout::GetLineHeight(Index line_index) {
return static_cast<float>(height) / PANGO_SCALE;
}
-Index PangoTextLayout::FromUtf8IndexToUtf16Index(Index index) {
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
- int cp_count = 0;
- while ((!iter.IsPastEnd()) && iter.GetPosition() < index) {
- ++iter;
- cp_count++;
- }
- return text_.IndexFromCodePointToCodeUnit(cp_count);
-}
-
-Index PangoTextLayout::FromUtf16IndexToUtf8Index(Index index) {
- Index cp_index = text_.IndexFromCodeUnitToCodePoint(index);
- Utf8CodePointIterator iter(utf8_text_.data(), utf8_text_.size());
-
- for (Index i = 0; i < cp_index; ++i) {
- ++iter;
- }
-
- return iter.GetPosition();
-}
-
Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
PangoRectangle rectangle;
pango_layout_get_extents(pango_layout_, nullptr, &rectangle);
@@ -110,17 +86,17 @@ Rect PangoTextLayout::GetTextBounds(bool includingTrailingSpace) {
std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
auto tr = text_range.Normalize();
- auto utf8_start_index = FromUtf16IndexToUtf8Index(tr.GetStart());
- auto utf8_end_index = FromUtf16IndexToUtf8Index(tr.GetEnd());
+ auto start_index = tr.GetStart();
+ auto end_index = tr.GetEnd();
PangoRectangle rectangle;
int start_line_index, end_line_index, start_x_pos, end_x_pos;
- pango_layout_index_to_line_x(pango_layout_, utf8_start_index, false,
+ pango_layout_index_to_line_x(pango_layout_, start_index, false,
&start_line_index, &start_x_pos);
- pango_layout_index_to_line_x(pango_layout_, utf8_end_index, false,
- &end_line_index, &end_x_pos);
+ pango_layout_index_to_line_x(pango_layout_, end_index, false, &end_line_index,
+ &end_x_pos);
- pango_layout_index_to_pos(pango_layout_, utf8_start_index, &rectangle);
+ pango_layout_index_to_pos(pango_layout_, start_index, &rectangle);
auto top = rectangle.y;
if (start_line_index == end_line_index) {
@@ -161,9 +137,8 @@ std::vector<Rect> PangoTextLayout::TextRangeRect(const TextRange& text_range) {
}
Rect PangoTextLayout::TextSinglePoint(Index position, bool trailing) {
- auto utf8_index = FromUtf16IndexToUtf8Index(position);
int line_index, x_pos, y_pos = 0;
- pango_layout_index_to_line_x(pango_layout_, utf8_index, trailing, &line_index,
+ pango_layout_index_to_line_x(pango_layout_, position, trailing, &line_index,
&x_pos);
for (int i = 0; i < line_index; i++) {
@@ -186,8 +161,7 @@ TextHitTestResult PangoTextLayout::HitTest(const Point& point) {
auto inside_text =
pango_layout_xy_to_index(pango_layout_, point.x * PANGO_SCALE,
point.y * PANGO_SCALE, &index, &trailing);
- return TextHitTestResult{FromUtf8IndexToUtf16Index(index), trailing != 0,
- inside_text != 0};
+ return TextHitTestResult{index, trailing != 0, inside_text != 0};
}
} // namespace cru::platform::graphics::cairo