MCPcopy Create free account
hub / github.com/DiscordMessenger/dm / MdMeasureString

Function MdMeasureString

src/windows/TextInterface_Win32.cpp:65–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

63}
64
65Point MdMeasureString(DrawingContext* context, const String& word, int styleFlags, bool& outWasWordWrapped, int maxWidth)
66{
67 outWasWordWrapped = false;
68 RECT rect;
69 HDC hdc = context->m_hdc;
70 HFONT font = MdDetermineFont(styleFlags);
71 HGDIOBJ old = SelectObject(hdc, font);
72
73 if (styleFlags & WORD_CEMOJI)
74 {
75 // Is an emoji. Therefore, render it as a square and go off.
76 int height = MdLineHeight(context, styleFlags);
77 rect.left = rect.top = 0;
78 rect.right = rect.bottom = height;
79 }
80 else
81 {
82 if (maxWidth > 0) {
83 rect.left = rect.top = 0;
84 rect.right = maxWidth;
85 rect.bottom = 10000000;
86 DrawText(hdc, word.GetWrapped(), -1, &rect, DT_CALCRECT | DT_WORDBREAK | DT_NOPREFIX | DT_EDITCONTROL);
87 }
88 else {
89 DrawText(hdc, word.GetWrapped(), -1, &rect, DT_CALCRECT | DT_NOPREFIX);
90 }
91
92 if (styleFlags & (WORD_MLCODE | WORD_NOFORMAT)) {
93 SIZE sz;
94 GetTextExtentPoint(hdc, word.GetWrapped(), (int) word.GetSize(), &sz);
95
96 outWasWordWrapped = sz.cx > rect.right - rect.left;
97
98 if (styleFlags & WORD_MLCODE) {
99 rect.right += 8;
100 rect.bottom += 8;
101 }
102 }
103 }
104
105 if ((styleFlags & (WORD_ITALIC | WORD_SMALLER)) && word.GetSize() != 0)
106 {
107 // subtract the overhang (C spacing) of the last character.
108 TCHAR chr = word.GetWrapped()[word.GetSize() - 1];
109 rect.right -= MdGetOverhang(hdc, chr);
110 }
111
112 SelectObject(hdc, old);
113
114 return { rect.right - rect.left, rect.bottom - rect.top };
115}
116int GetProfilePictureSize();
117int MdLineHeight(DrawingContext* context, int styleFlags)
118{

Callers 1

LayoutMethod · 0.85

Calls 5

MdDetermineFontFunction · 0.85
MdLineHeightFunction · 0.85
MdGetOverhangFunction · 0.85
GetWrappedMethod · 0.80
GetSizeMethod · 0.80

Tested by

no test coverage detected