From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Tom Seddon Newsgroups: gmane.emacs.bugs Subject: bug#6364: [PATCH] Use GetCharABCWidthsFloatW if GetGlyphOutlineW fails. Date: Tue, 26 Nov 2013 21:50:02 +0000 Message-ID: References: <8CCD3BEBEE756DD-DB8-DFB9@web-mmc-m08.sysops.aol.com> <713BA87B-E38A-4777-B054-E136A7C96EF9@tomseddon.plus.com> <83pppn9hjm.fsf@gnu.org> <3E4E896E-71DC-402F-A572-E65A4AB621FA@tomseddon.plus.com> <83k3fuap9u.fsf@gnu.org> <83ioveanyq.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Mac OS X Mail 7.0 \(1822\)) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1385502676 31476 80.91.229.3 (26 Nov 2013 21:51:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 26 Nov 2013 21:51:16 +0000 (UTC) Cc: 6364@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Nov 26 22:51:20 2013 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VlQXO-0005KS-KJ for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Nov 2013 22:51:18 +0100 Original-Received: from localhost ([::1]:32899 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlQXO-0002eC-9w for geb-bug-gnu-emacs@m.gmane.org; Tue, 26 Nov 2013 16:51:18 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:40689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlQXF-0002Zk-Fh for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2013 16:51:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VlQX9-0004zU-Dq for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2013 16:51:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:60713) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VlQX9-0004zQ-Au for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2013 16:51:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1VlQX8-0001pc-PG for bug-gnu-emacs@gnu.org; Tue, 26 Nov 2013 16:51:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Tom Seddon Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 26 Nov 2013 21:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6364 X-GNU-PR-Package: emacs,w32 X-GNU-PR-Keywords: patch Original-Received: via spool by 6364-submit@debbugs.gnu.org id=B6364.13855026146968 (code B ref 6364); Tue, 26 Nov 2013 21:51:02 +0000 Original-Received: (at 6364) by debbugs.gnu.org; 26 Nov 2013 21:50:14 +0000 Original-Received: from localhost ([127.0.0.1]:46499 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VlQWL-0001oJ-QB for submit@debbugs.gnu.org; Tue, 26 Nov 2013 16:50:14 -0500 Original-Received: from caiajhbdccah.dreamhost.com ([208.97.132.207]:49940 helo=homiemail-a97.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1VlQWH-0001o7-9y for 6364@debbugs.gnu.org; Tue, 26 Nov 2013 16:50:10 -0500 Original-Received: from homiemail-a97.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a97.g.dreamhost.com (Postfix) with ESMTP id DFA17286078; Tue, 26 Nov 2013 13:50:07 -0800 (PST) Original-Received: from [192.168.1.101] (tomseddon.plus.com [212.159.116.120]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: tom@ouro.ltd.uk) by homiemail-a97.g.dreamhost.com (Postfix) with ESMTPSA id 038D9286058; Tue, 26 Nov 2013 13:50:05 -0800 (PST) In-Reply-To: <83ioveanyq.fsf@gnu.org> X-Mailer: Apple Mail (2.1822) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:81018 Archived-At: On 26 Nov 2013, at 20:48, Eli Zaretskii wrote: > OK. So what other function(s) can be used for this purpose? >=20 > If there are no good alternatives, I guess we will go with > GetCharABCWidthsFloatW anyway, since the situation cannot become worse > than it is already. I've changed it to GetCharWidth32, which is in the list on that MSDN = page - see patch below. I've checked this against all bitmap fonts on my = system and it produces the same results (and emacs looks to behave the = same, including in terms of performance). This function only works for bitmap fonts, but hopefully if = GetGlyphOutlineW ever fails, the reason is that the font is a bitmap = one! (And if not, and GetCharWidth32 fails too, there's the same = fallback as before in the form of GetTextExtentPoint32.) > Btw, I used your recipe, but didn't see any significant slowdown with > fixed.fon (also, the file bigline.txt is missing, I just used the > 16384 thingy instead. Agh, my mistake - I should have included start-slow.el, not = start-bigline.el. Sorry. start-slow.el looks like this: (set-face-attribute 'default nil :font "fixed") (switch-to-buffer (find-file "usb.ids")) (goto-char (point-max)) Maybe that will show up the problem? But it sounds rather like your = computer just doesn't suffer from this issue, for whatever reason... Thanks, --Tom P.S. my two PCs are as follows, and unpatched emacs performs poorly on = both of them when using bitmap fonts: - 3.4GHz Core i7 desktop, 16GB RAM, GeForce 560Ti, Windows 7 - 2.53GHz Core 2 Duo laptop, 8GB RAM, GeForce 9400M, Windows 7 (this is = a Macbook Pro - the performance is also bad running in a VM) So this could be something to do with NVidia display drivers on Windows = 7, I suppose? Though I'd expect the VM to have its own drivers, = suggesting that it might not actually be the graphics card vendor... ----------------------------------- =46rom 09fe3b0c0eb07c5ada87aee0864fa1d9478fdcf1 Mon Sep 17 00:00:00 2001 From: Tom Seddon Date: Mon, 25 Nov 2013 22:19:47 +0000 Subject: [PATCH] Use GetCharWidth32W if GetGlyphOutlineW fails. The previous fallback - which will still be used if GetCharWidth32W fails - was to call GetTextExtentPoint32W. This can be rather slow, mainly due to having to create a DC for it each time - but not to say that using the cache isn't cheaper than GetTextExtentPoint32W anyway. --- src/w32font.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/w32font.c b/src/w32font.c index 5c5a15c..08316ec 100644 --- a/src/w32font.c +++ b/src/w32font.c @@ -149,6 +149,7 @@ static BOOL g_b_init_get_outline_metrics_w; static BOOL g_b_init_get_text_metrics_w; static BOOL g_b_init_get_glyph_outline_w; static BOOL g_b_init_get_glyph_outline_w; +static BOOL g_b_init_get_char_width_32_w; =20 typedef UINT (WINAPI * GetOutlineTextMetricsW_Proc) ( HDC hdc, @@ -165,6 +166,11 @@ typedef DWORD (WINAPI * GetGlyphOutlineW_Proc) ( DWORD cbBuffer, LPVOID lpvBuffer, const MAT2 *lpmat2); +typedef BOOL (WINAPI * GetCharWidth32W_Proc) ( + HDC hdc, + UINT uFirstChar, + UINT uLastChar, + LPINT lpBuffer); =20 /* Several "wide" functions we use to support the font backends are unavailable on Windows 9X, unless UNICOWS.DLL is installed (their @@ -274,6 +280,23 @@ get_glyph_outline_w (HDC hdc, UINT uChar, UINT = uFormat, LPGLYPHMETRICS lpgm, lpvBuffer, lpmat2); } =20 +static DWORD WINAPI get_char_width_32_w (HDC hdc, UINT uFirstChar, + UINT uLastChar, LPINT lpBuffer) +{ + static GetCharWidth32W_Proc s_pfn_Get_Char_Width_32W =3D NULL; + HMODULE hm_unicows =3D NULL; + if (g_b_init_get_char_width_32_w =3D=3D 0) + { + g_b_init_get_char_width_32_w =3D 1; + hm_unicows =3D w32_load_unicows_or_gdi32 (); + if (hm_unicows) + s_pfn_Get_Char_Width_32W =3D (GetCharWidth32W_Proc) + GetProcAddress (hm_unicows, "GetCharWidth32W"); + } + eassert (s_pfn_Get_Char_Width_32W !=3D NULL); + return s_pfn_Get_Char_Width_32W (hdc, uFirstChar, uLastChar, = lpBuffer); +} + static int memq_no_quit (Lisp_Object elt, Lisp_Object list) { @@ -2438,6 +2461,7 @@ compute_metrics (HDC dc, struct w32font_info = *w32_font, unsigned int code, GLYPHMETRICS gm; MAT2 transform; unsigned int options =3D GGO_METRICS; + INT width; =20 if (w32_font->glyph_idx) options |=3D GGO_GLYPH_INDEX; @@ -2454,6 +2478,13 @@ compute_metrics (HDC dc, struct w32font_info = *w32_font, unsigned int code, metrics->width =3D gm.gmCellIncX; metrics->status =3D W32METRIC_SUCCESS; } + else if (get_char_width_32_w (dc, code, code, &width) !=3D 0) + { + metrics->lbearing =3D 0; + metrics->rbearing =3D width; + metrics->width =3D width; + metrics->status =3D W32METRIC_SUCCESS; + } else metrics->status =3D W32METRIC_FAIL; } --=20 1.8.1.msysgit.1