From 1d988db2db5a2ff3dd53e98205ac3dc1561e73b7 Mon Sep 17 00:00:00 2001 From: Ian MacArthur Date: Tue, 12 Apr 2011 16:18:42 +0000 Subject: Under win32, text_extents() is not handling surrogate pairs either, at least on XP. The problem seems to be in GetGlyphIndicesW() which is returning invalid indices for the surrogate pairs. This causes subsequent measurements of the glyphs to fail, of course. This patch does not fix the problem, it only makes sure it fails cleanly, causing a fallback to the default fl_measure like behaviour. This is not nice, nor what I want, but at least it is consistent for now... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8582 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 --- src/fl_font_win32.cxx | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/fl_font_win32.cxx b/src/fl_font_win32.cxx index fae064034..097037367 100644 --- a/src/fl_font_win32.cxx +++ b/src/fl_font_win32.cxx @@ -291,6 +291,7 @@ void Fl_GDI_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy int minx = 0, miny = -999999; unsigned len = 0, idx = 0; HWND hWnd = 0; + HDC gc = fl_gc; // local copy of current gc - make a copy in case we change it... // Have we loaded the GetGlyphIndicesW function yet? if (have_loaded_GetGlyphIndices == 0) { @@ -301,12 +302,12 @@ void Fl_GDI_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy // The following code makes a best effort attempt to obtain a valid fl_gc. // See description in fl_width() above for an explanation. - if (!fl_gc) { // We have no valid gc, try and obtain one - // Use our first fltk window, or fallback to using the screen via GetDC(NULL) - hWnd = Fl::first_window() ? fl_xid(Fl::first_window()) : NULL; - fl_gc = GetDC(hWnd); + if (!gc) { // We have no valid gc, try and obtain one + // Use our first fltk window, or fallback to using the screen via GetDC(NULL) + hWnd = Fl::first_window() ? fl_xid(Fl::first_window()) : NULL; + gc = GetDC(hWnd); } - if (!fl_gc)goto exit_error; // no valid gc, attempt to use fallback measure + if (!gc) goto exit_error; // no valid gc, attempt to use fallback measure // now convert the string to WCHAR and measure it len = fl_utf8toUtf16(c, n, ext_buff, wc_len); @@ -318,18 +319,17 @@ void Fl_GDI_Graphics_Driver::text_extents(const char *c, int n, int &dx, int &dy gi = new WORD[wc_len]; len = fl_utf8toUtf16(c, n, ext_buff, wc_len); } - SelectObject(fl_gc, fl_fontsize->fid); + SelectObject(gc, fl_fontsize->fid); - if (fl_GetGlyphIndices(fl_gc, (WCHAR*)ext_buff, len, gi, 0) == GDI_ERROR) { - // some error occured here - just return fl_measure values? + if (fl_GetGlyphIndices(gc, (WCHAR*)ext_buff, len, gi, GGI_MARK_NONEXISTING_GLYPHS) == GDI_ERROR) { + // some error occured here - just return fl_measure values goto exit_error; } - // now we have the glyph array we measure each glyph in turn... for(idx = 0; idx < len; idx++){ - if (GetGlyphOutlineW (fl_gc, gi[idx], GGO_METRICS | GGO_GLYPH_INDEX, + if (GetGlyphOutlineW (gc, gi[idx], GGO_METRICS | GGO_GLYPH_INDEX, &metrics, 0, NULL, &matrix) == GDI_ERROR) { - goto exit_error; + goto exit_error; } maxw += metrics.gmCellIncX; if(idx == 0) minx = metrics.gmptGlyphOrigin.x; -- cgit v1.2.3