aboutsummaryrefslogtreecommitdiff
path: root/include/cru/platform/graphics/cairo/PangoTextLayout.h
blob: 7e2bb2a960a20b4d16bd51d79a6fc8440491ad57 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#pragma once
#include "../TextLayout.h"
#include "CairoResource.h"
#include "PangoFont.h"

#include <pango/pango.h>

namespace cru::platform::graphics::cairo {
class PangoTextLayout : public CairoResource, public virtual ITextLayout {
 public:
  PangoTextLayout(CairoGraphicsFactory* factory, std::shared_ptr<IFont> font);

  ~PangoTextLayout() override;

 public:
  String GetText() override;
  void SetText(String new_text) override;

  std::shared_ptr<IFont> GetFont() override;
  void SetFont(std::shared_ptr<IFont> font) override;

  void SetMaxWidth(float max_width) override;
  void SetMaxHeight(float max_height) override;

  bool IsEditMode() override;
  void SetEditMode(bool enable) override;

  Index GetLineIndexFromCharIndex(Index char_index) override;
  Index GetLineCount() override;
  float GetLineHeight(Index line_index) override;

  Rect GetTextBounds(bool includingTrailingSpace = false) override;
  std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
  // Width is always 0, height is line height.
  Rect TextSinglePoint(Index position, bool trailing) override;
  TextHitTestResult HitTest(const Point& point) override;

 private:
  Index FromUtf8IndexToUtf16Index(Index index);
  Index FromUtf16IndexToUtf8Index(Index index);

 private:
  String text_;
  std::string utf8_text_;

  bool edit_mode_ = false;

  std::shared_ptr<PangoFont> font_;

  PangoLayout* pango_layout_;
};
}  // namespace cru::platform::graphics::cairo