I'm trying to use DrawTextW with the DT_CALCRECT flag to find the width and height of a Unicode string. Everything works correctly if the string contains only 'latin' characters (MS byte = 0) but as soon as I include one or more Arabic or Cyrillic characters DrawTextW is returning a width of *zero* for the entire string (the height is correct, however). The font selected into the DC definitely has the required characters; I've tried both Arial and Tahoma. For example if the string is 0x0028 0x002A 0x0029 DrawTextW returns a height of 58 and a width of 62. If I change the string to 0x0028 0x062A 0x0029 (the second character being Arabic Teh) DrawTextW returns a height of 58 but a width of zero. If I remove the DT_CALCRECT flag the correct characters are drawn, proving that the selected font has them. Any idea why this is happening (with Windows XP SP2, if it matters) ? Richard. http://www.rtrussell.co.uk/ To reply by email change 'news' to my forename.
[XPPro SP2] Your example gives me rect of 22 width and 16 height. Cyrillic letters also works fine. Double-check your invocations... hath wrote: news:e117d366-b11a-4e60-9b15-014cca888552@q26g2000prq.googlegroups.com... > I'm trying to use DrawTextW with the DT_CALCRECT flag to find the > width and height of a Unicode string. Everything works correctly if > the string contains only 'latin' characters (MS byte = 0) but as soon > as I include one or more Arabic or Cyrillic characters DrawTextW is > returning a width of *zero* for the entire string (the height is > correct, however). The font selected into the DC definitely has the > required characters; I've tried both Arial and Tahoma. > > For example if the string is 0x0028 0x002A 0x0029 DrawTextW returns a > height of 58 and a width of 62. If I change the string to 0x0028 > 0x062A 0x0029 (the second character being Arabic Teh) DrawTextW > returns a height of 58 but a width of zero. > > If I remove the DT_CALCRECT flag the correct characters are drawn, > proving that the selected font has them. > > Any idea why this is happening (with Windows XP SP2, if it matters) ? > > Richard. > http://www.rtrussell.co.uk/ > To reply by email change 'news' to my forename.
On Sep 4, 8:24 pm, "st" <s...@sandy.localdomain> wrote: > [XPPro SP2] Your example gives me rect of 22 width and 16 height. > Cyrillic letters also works fine. Double-check your invocations... It's hard to understand what I could be doing wrong, given that I am simply changing one character in a Unicode (wide) string and making no other changes at all. The language I am using - BBC BASIC - also isolates me from some of the possible errors I might make in a lower- level language like C. It does mean I am making the DrawTextW call from a thread without a message pump, but I'm not aware of that being an issue, especially not one that could affect only certain Unicode characters. Richard. http://www.rtrussell.co.uk/ To reply by email change 'news' to my forename.
Also note that DrawTextW returns only string *height*. Function adjusts width and height rectangle which you passed in it _by reference_. Also check your compiler documentation about formatting wide strings (if you specify it as literal) and data type if you use WCHAR array. hath written: news:e791e04f-9f80-4ef2-a168-f501f7d7d22b@a18g2000pra.googlegroups.com... On Sep 4, 8:24 pm, "st" <s...@sandy.localdomain> wrote: > [XPPro SP2] Your example gives me rect of 22 width and 16 height. > Cyrillic letters also works fine. Double-check your invocations... It's hard to understand what I could be doing wrong, given that I am simply changing one character in a Unicode (wide) string and making no other changes at all. The language I am using - BBC BASIC - also isolates me from some of the possible errors I might make in a lower- level language like C. It does mean I am making the DrawTextW call from a thread without a message pump, but I'm not aware of that being an issue, especially not one that could affect only certain Unicode characters. Richard. http://www.rtrussell.co.uk/ To reply by email change 'news' to my forename.
On Sep 5, 7:00 am, "st" <s...@sandy.localdomain> wrote: > Also note that DrawTextW returns only string *height*. > Function adjusts width and height rectangle which you passed > in it _by reference_. Of course. How else do you think I am getting the (correct) width value when the second character is 0x002A? In both cases (working, with the second character 0x002A, and non- working, with the second character 0x062A) the height is returned *both* in the appropriate field of the rectangle *and* as the value returned from the function. > Also check your compiler documentation about formatting wide strings > (if you specify it as literal) and data type if you use WCHAR array. I am explicitly loading the 16-bit values, since BBC BASIC doesn't support that data type natively. Remember, it is all working as expected with the 'latin' characters (they are still 16-bit Unicode) so such issues would have broken that case as well. Whatever the problem is, it isn't that I'm doing something 'stupid' as you seem to suggest. Richard. http://www.rtrussell.co.uk/ To reply by email change 'news' to my forename.