forked from UnigramDev/Unigram
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTextFormat.cpp
More file actions
51 lines (42 loc) · 1.38 KB
/
Copy pathTextFormat.cpp
File metadata and controls
51 lines (42 loc) · 1.38 KB
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
#include "pch.h"
#include "TextFormat.h"
#if __has_include("TextFormat.g.cpp")
#include "TextFormat.g.cpp"
#endif
#include "Helpers\COMHelper.h"
namespace winrt::Telegram::Native::implementation
{
TextFormat::TextFormat(winrt::com_ptr<IDWriteTextLayout> textLayout, uint32_t textLength, double fontSize, double maxWidth)
: m_textLayout(textLayout)
, m_textLength(textLength)
, m_fontSize(fontSize)
, m_maxWidth(maxWidth)
{
}
float2 TextFormat::ContentEnd(double fontSize, double width)
{
float2 offset;
ContentEndImpl(fontSize, width, offset);
return offset;
}
HRESULT TextFormat::ContentEndImpl(double fontSize, double width, float2& offset)
{
HRESULT result;
if (m_fontSize != fontSize)
{
ReturnIfFailed(result, m_textLayout->SetFontSize(fontSize, { 0, m_textLength }));
m_fontSize = fontSize;
}
if (m_maxWidth != width)
{
ReturnIfFailed(result, m_textLayout->SetMaxWidth(width));
m_maxWidth = width;
}
FLOAT x;
FLOAT y;
DWRITE_HIT_TEST_METRICS metrics;
ReturnIfFailed(result, m_textLayout->HitTestTextPosition(m_textLength - 1, false, &x, &y, &metrics));
offset = float2(metrics.left + metrics.width, metrics.top + metrics.height);
return result;
}
}