diff options
-rw-r--r-- | demos/InputMethod/main.cpp | 2 | ||||
-rw-r--r-- | src/platform/graphics/cairo/PangoTextLayout.cpp | 11 |
2 files changed, 10 insertions, 3 deletions
diff --git a/demos/InputMethod/main.cpp b/demos/InputMethod/main.cpp index 6c0fba3c..ce7f0c21 100644 --- a/demos/InputMethod/main.cpp +++ b/demos/InputMethod/main.cpp @@ -119,7 +119,7 @@ int main() { static_cast<int>(committed_text.size()); auto cursor_rect = text_layout->TextSinglePoint(cursor_pos, false); input_method_context->SetCandidateWindowPosition( - {cursor_rect.left, cursor_rect.GetBottom()}); + {cursor_rect.left, y + cursor_rect.GetBottom()}); window->RequestRepaint(); }; diff --git a/src/platform/graphics/cairo/PangoTextLayout.cpp b/src/platform/graphics/cairo/PangoTextLayout.cpp index d69ee273..8dfd59d5 100644 --- a/src/platform/graphics/cairo/PangoTextLayout.cpp +++ b/src/platform/graphics/cairo/PangoTextLayout.cpp @@ -162,16 +162,23 @@ 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; + int line_index, x_pos, y_pos = 0; pango_layout_index_to_line_x(pango_layout_, utf8_index, trailing, &line_index, &x_pos); + for (int i = 0; i < line_index; i++) { + auto line = pango_layout_get_line(pango_layout_, line_index); + PangoRectangle rectangle; + pango_layout_line_get_extents(line, nullptr, &rectangle); + y_pos += rectangle.height; + } + auto line = pango_layout_get_line(pango_layout_, line_index); PangoRectangle rectangle; pango_layout_line_get_extents(line, nullptr, &rectangle); return ConvertFromPango( - Rect(rectangle.x + x_pos, rectangle.y, 0, rectangle.height)); + Rect(rectangle.x + x_pos, y_pos, 0, rectangle.height)); } TextHitTestResult PangoTextLayout::HitTest(const Point& point) { |