| 531 | | if (useWfuncs) |
|---|
| 532 | | return GetTextExtentPoint32W(dc, toUTF16z(str), len, s); |
|---|
| 533 | | else |
|---|
| 534 | | return GetTextExtentPoint32A(dc, toMBSz(str), len, s); |
|---|
| | 542 | if (useWfuncs) { |
|---|
| | 543 | wchar[] wstr = toUTF16(str); |
|---|
| | 544 | return GetTextExtentPoint32W(dc, wstr, wstr.length, s); |
|---|
| | 545 | } else { |
|---|
| | 546 | size_t al; |
|---|
| | 547 | char* ansi = toMBSzl(str, al); |
|---|
| | 548 | return GetTextExtentPoint32A(dc, ansi, al, s); |
|---|
| | 549 | } |
|---|
| | 560 | |
|---|
| | 561 | /****************************************** |
|---|
| | 562 | * Converts the UTF-8 string s into a null-terminated string in a Windows |
|---|
| | 563 | * 8-bit character set. |
|---|
| | 564 | * |
|---|
| | 565 | * Params: |
|---|
| | 566 | * s = UTF-8 string to convert. |
|---|
| | 567 | * reslen = the number of bytes in the resulting buffer |
|---|
| | 568 | * (not including the null terminator) will be place here. |
|---|
| | 569 | * codePage = is the number of the target codepage, or |
|---|
| | 570 | * 0 - ANSI, |
|---|
| | 571 | * 1 - OEM, |
|---|
| | 572 | * 2 - Mac |
|---|
| | 573 | * |
|---|
| | 574 | * Authors: |
|---|
| | 575 | * yaneurao, Walter Bright, Stewart Gordon |
|---|
| | 576 | */ |
|---|
| | 577 | private import std.windows.syserror; |
|---|
| | 578 | char* toMBSzl(char[] s, out size_t reslen, uint codePage = 0) |
|---|
| | 579 | { |
|---|
| | 580 | // Only need to do this if any chars have the high bit set |
|---|
| | 581 | foreach (char c; s) |
|---|
| | 582 | { |
|---|
| | 583 | if (c >= 0x80) |
|---|
| | 584 | { |
|---|
| | 585 | char[] result; |
|---|
| | 586 | int readLen; |
|---|
| | 587 | wchar* ws = std.utf.toUTF16z(s); |
|---|
| | 588 | result.length = WideCharToMultiByte(codePage, 0, ws, -1, null, 0, |
|---|
| | 589 | null, null); |
|---|
| | 590 | |
|---|
| | 591 | if (result.length) |
|---|
| | 592 | { |
|---|
| | 593 | readLen = WideCharToMultiByte(codePage, 0, ws, -1, result.ptr, |
|---|
| | 594 | result.length, null, null); |
|---|
| | 595 | } |
|---|
| | 596 | |
|---|
| | 597 | if (!readLen || readLen != result.length) |
|---|
| | 598 | { |
|---|
| | 599 | throw new Exception("Couldn't convert string: " ~ |
|---|
| | 600 | sysErrorString(GetLastError())); |
|---|
| | 601 | } |
|---|
| | 602 | |
|---|
| | 603 | reslen = result.length ? result.length-1 : 0; |
|---|
| | 604 | return result; |
|---|
| | 605 | } |
|---|
| | 606 | } |
|---|
| | 607 | reslen = s.length; |
|---|
| | 608 | return std.string.toStringz(s); |
|---|
| | 609 | } |
|---|