@@ -4131,7 +4131,7 @@ win_check_glyphs(wchar *wcs, uint num, cattrflags attr)
41314131 ReleaseDC (wnd , dc );
41324132}
41334133
4134- #define dont_debug_win_char_width
4134+ #define dont_debug_win_char_width 2
41354135
41364136#ifdef debug_win_char_width
41374137int
@@ -4214,30 +4214,36 @@ win_char_width(xchar c, cattrflags attr)
42144214#endif
42154215
42164216 int ibuf = 0 ;
4217- bool ok = GetCharWidth32W (dc , c , c , & ibuf );
4217+
4218+ #ifdef use_getcharwidth
4219+ #warning avoid buggy GetCharWidth*
4220+ if (c < 0x10000 ) {
4221+ bool ok = GetCharWidth32W (dc , c , c , & ibuf );
42184222#ifdef debug_win_char_width
4219- printf (" getcharw %04X %dpx/cell %dpx\n" , c , ibuf , cell_width );
4223+ printf (" getcharwidth32 %04X %dpx( /cell %dpx) \n" , c , ibuf , cell_width );
42204224#endif
4221- if (!ok ) {
4222- ReleaseDC (wnd , dc );
4223- return 0 ;
4224- }
4225+ if (!ok ) {
4226+ ReleaseDC (wnd , dc );
4227+ return 0 ;
4228+ }
42254229
4226- // report char as wide if its width is more than 1½ cells;
4227- // this is unreliable if font fallback is involved (#615)
4228- ibuf += cell_width / 2 - 1 ;
4229- ibuf /= cell_width ;
4230- if (ibuf > 1 ) {
4230+ // report char as wide if its width is more than 1½ cells;
4231+ // this is unreliable if font fallback is involved (#615)
4232+ ibuf += cell_width / 2 - 1 ;
4233+ ibuf /= cell_width ;
4234+ if (ibuf > 1 ) {
42314235#ifdef debug_win_char_width
4232- printf (" enquired %04X %dpx/cell %dpx\n" , c , ibuf , cell_width );
4236+ printf (" enquired %04X %dpx/cell %dpx\n" , c , ibuf , cell_width );
42334237#endif
4234- ReleaseDC (wnd , dc );
4235- //printf(" win_char_width %04X -> %d\n", c, ibuf);
4236- return ibuf ;
4238+ ReleaseDC (wnd , dc );
4239+ //printf(" win_char_width %04X -> %d\n", c, ibuf);
4240+ return ibuf ;
4241+ }
42374242 }
4243+ #endif
42384244
42394245#ifdef measure_width
4240- int act_char_width (wchar wc )
4246+ int act_char_width (xchar wc )
42414247 {
42424248 HDC wid_dc = CreateCompatibleDC (dc );
42434249 HBITMAP wid_bm = CreateCompatibleBitmap (dc , cell_width * 2 , cell_height );
@@ -4249,10 +4255,20 @@ win_char_width(xchar c, cattrflags attr)
42494255 SetBkMode (wid_dc , OPAQUE );
42504256 int dx = 0 ;
42514257 use_uniscribe = cfg .font_render == FR_UNISCRIBE ;
4252- text_out_start (wid_dc , & wc , 1 , & dx );
4253- text_out (wid_dc , 0 , 0 , ETO_OPAQUE , null , & wc , 1 , & dx );
4258+ wchar wc2 [2 ];
4259+ if (wc < 0x10000 ) {
4260+ * wc2 = wc ;
4261+ text_out_start (wid_dc , wc2 , 1 , & dx );
4262+ text_out (wid_dc , 0 , 0 , ETO_OPAQUE , null , wc2 , 1 , & dx );
4263+ }
4264+ else {
4265+ wc2 [0 ] = high_surrogate (wc );
4266+ wc2 [1 ] = low_surrogate (wc );
4267+ text_out_start (wid_dc , wc2 , 2 , & dx );
4268+ text_out (wid_dc , 0 , 0 , ETO_OPAQUE , null , wc2 , 2 , & dx );
4269+ }
42544270 text_out_end ();
4255- # ifdef debug_win_char_width
4271+ # if defined( debug_win_char_width ) && debug_win_char_width > 1
42564272 for (int y = 0 ; y < cell_height ; y ++ ) {
42574273 printf (" %2d|" , y );
42584274 for (int x = 0 ; x < cell_width * 2 ; x ++ ) {
@@ -4294,23 +4310,28 @@ win_char_width(xchar c, cattrflags attr)
42944310 // although FONT_WIDE is actually activated
42954311 }
42964312
4297- if ((c >= 0x3000 && c <= 0x303F )
4298- || ( c >= 0x2460 && c <= 0x24FF ) // Enclosed Alphanumerics
4299- || (c >= 0x2600 && c <= 0x27BF ) // Miscellaneous Symbols, Dingbats
4313+ if ((c >= 0x3000 && c <= 0x303F ) // CJK Symbols and Punctuation
4314+
4315+ || (c >= 0x2460 && c <= 0x24FF ) // Enclosed Alphanumerics, to cover:
43004316 //|| (c >= 0x249C && c <= 0x24E9) // parenthesized/circled letters
4301- || (c >= 0x3248 && c <= 0x324F ) // Enclosed CJK Letters and Months
4317+
4318+ //|| (c >= 0x2600 && c <= 0x27BF) // Miscellaneous Symbols, Dingbats
4319+ || c == 0x26AC
4320+
4321+ || (c >= 0x3248 && c <= 0x324F ) // circled CJK Numbers
43024322 || (c >= 0x1F100 && c <= 0x1F1FF ) // Enclosed Alphanumeric Supplement
4303- #ifdef check_more_mostly_covered_below
4304- || ( c >= 0x2100 && c <= 0x23FF ) // Letterlike, Number Forms, Arrows, Math Operators, Misc Technical
4305- || (c >= 0x25A0 && c <= 0x25FF ) // Geometric Shapes
4306- || (c >= 0x2B00 && c <= 0x2BFF ) // Miscellaneous Symbols and Arrows
4307- #endif
4323+
4324+ || c == 0x2139 // Letterlike: Information Source
4325+ || (c >= 0x2180 && c <= 0x2182 ) // Number Forms: combined Roman Numerals
4326+ || (c >= 0x2187 && c <= 0x2188 ) // Number Forms: combined Roman Numerals
4327+
43084328 || (c >= 0xE000 && c < 0xF900 ) // Private Use Area
4329+
43094330 || (// check all non-letters with some exceptions
43104331 bidi_class (c ) != L // indicates not a letter
4311- &&
4332+ && // do not check these non-letters:
43124333 !( (c >= 0x2500 && c <= 0x2588 ) // Box Drawing, Block Elements
4313- || (c >= 0x2592 && c <= 0x2594 ) // Block Elements
4334+ || (c >= 0x2591 && c <= 0x2594 ) // Block Elements
43144335 || (c >= 0x2160 && c <= 0x2179 ) // Roman Numerals
43154336 //|| wcschr (W("‐‑‘’‚‛“”„‟‹›"), c) // #712 workaround; now caching
43164337 )
0 commit comments