blob: 03b1b1cba29a07e511435eb36c8216675e951b61 (
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
53
54
55
56
57
58
59
60
|
#pragma once
#include "Resource.hpp"
#include "Font.hpp"
#include "cru/common/Base.hpp"
#include "cru/platform/graphics/TextLayout.hpp"
#include <memory>
namespace cru::platform::graphics::osx::quartz {
class OsxCTTextLayout : public OsxQuartzResource, public virtual ITextLayout {
public:
OsxCTTextLayout(IGraphicsFactory* graphics_factory,
std::shared_ptr<OsxCTFont> font, const String& str);
CRU_DELETE_COPY(OsxCTTextLayout)
CRU_DELETE_MOVE(OsxCTTextLayout)
~OsxCTTextLayout() override;
public:
String GetText() override { return text_; }
void SetText(String new_text) override;
std::shared_ptr<IFont> GetFont() override { return font_; }
void SetFont(std::shared_ptr<IFont> font) override;
void SetMaxWidth(float max_width) override;
void SetMaxHeight(float max_height) override;
Rect GetTextBounds(bool includingTrailingSpace = false) override;
std::vector<Rect> TextRangeRect(const TextRange& text_range) override;
Point TextSinglePoint(Index position, bool trailing) override;
TextHitTestResult HitTest(const Point& point) override;
CTFrameRef GetCTFrameRef() const { return ct_frame_; }
CTFrameRef CreateFrameWithColor(const Color& color);
private:
void ReleaseResource();
void RecreateFrame();
private:
float max_width_;
float max_height_;
std::shared_ptr<OsxCTFont> font_;
String text_;
CFMutableAttributedStringRef cf_attributed_text_;
CTFramesetterRef ct_framesetter_ = nullptr;
float suggest_height_;
CTFrameRef ct_frame_ = nullptr;
int line_count_;
std::vector<CGPoint> line_origins_;
std::vector<CTLineRef> lines_;
};
} // namespace cru::platform::graphics::osx::quartz
|