| 63 | } |
| 64 | |
| 65 | Point 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 | } |
| 116 | int GetProfilePictureSize(); |
| 117 | int MdLineHeight(DrawingContext* context, int styleFlags) |
| 118 | { |
no test coverage detected