| 198 | } |
| 199 | |
| 200 | int drawText(std::string_view text, SIZE& tSize, Device::TextAlign eAlign, const FontDefinition& textDefinition) |
| 201 | { |
| 202 | int nRet = 0; |
| 203 | wchar_t* pwszBuffer = nullptr; |
| 204 | wchar_t* fixedText = nullptr; |
| 205 | do |
| 206 | { |
| 207 | AX_BREAK_IF(text.empty()); |
| 208 | |
| 209 | DWORD dwFmt = DT_WORDBREAK; |
| 210 | if (!textDefinition._enableWrap) |
| 211 | { |
| 212 | dwFmt |= DT_SINGLELINE; |
| 213 | } |
| 214 | DWORD dwHoriFlag = (int)eAlign & 0x0f; |
| 215 | DWORD dwVertFlag = ((int)eAlign & 0xf0) >> 4; |
| 216 | |
| 217 | switch (dwHoriFlag) |
| 218 | { |
| 219 | case 1: // left |
| 220 | dwFmt |= DT_LEFT; |
| 221 | break; |
| 222 | case 2: // right |
| 223 | dwFmt |= DT_RIGHT; |
| 224 | break; |
| 225 | case 3: // center |
| 226 | dwFmt |= DT_CENTER; |
| 227 | break; |
| 228 | } |
| 229 | |
| 230 | int nLen = static_cast<int>(text.length()); |
| 231 | // utf-8 to utf-16 |
| 232 | int nBufLen = nLen + 1; |
| 233 | pwszBuffer = new wchar_t[nBufLen]; |
| 234 | AX_BREAK_IF(!pwszBuffer); |
| 235 | |
| 236 | memset(pwszBuffer, 0, sizeof(wchar_t) * nBufLen); |
| 237 | nLen = MultiByteToWideChar(CP_UTF8, 0, text.data(), nLen, pwszBuffer, nBufLen); |
| 238 | |
| 239 | if (strchr(text.data(), '&')) |
| 240 | { |
| 241 | fixedText = new wchar_t[nLen * 2 + 1]; |
| 242 | int fixedIndex = 0; |
| 243 | for (int index = 0; index < nLen; ++index) |
| 244 | { |
| 245 | if (pwszBuffer[index] == '&') |
| 246 | { |
| 247 | fixedText[fixedIndex] = '&'; |
| 248 | fixedText[fixedIndex + 1] = '&'; |
| 249 | fixedIndex += 2; |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | fixedText[fixedIndex] = pwszBuffer[index]; |
| 254 | fixedIndex += 1; |
| 255 | } |
| 256 | } |
| 257 | fixedText[fixedIndex] = '\0'; |