Huw Davies : gdi32: Add support for checking the font's gasp flags.
Alexandre Julliard
julliard at winehq.org
Fri Dec 2 10:58:29 CST 2011
Module: wine
Branch: master
Commit: 4ce3af3fad1dfacfe39a441054586707f848038f
URL: http://source.winehq.org/git/wine.git/?a=commit;h=4ce3af3fad1dfacfe39a441054586707f848038f
Author: Huw Davies <huw at codeweavers.com>
Date: Fri Dec 2 14:11:51 2011 +0000
gdi32: Add support for checking the font's gasp flags.
---
dlls/gdi32/font.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 74 insertions(+), 1 deletions(-)
diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c
index 5b7d500..a785283 100644
--- a/dlls/gdi32/font.c
+++ b/dlls/gdi32/font.c
@@ -32,11 +32,18 @@
#include "windef.h"
#include "winbase.h"
#include "winnls.h"
+#include "winternl.h"
#include "gdi_private.h"
#include "wine/exception.h"
#include "wine/unicode.h"
#include "wine/debug.h"
+#ifdef WORDS_BIGENDIAN
+#define get_be_word(x) (x)
+#else
+#define get_be_word(x) RtlUshortByteSwap(x)
+#endif
+
WINE_DEFAULT_DEBUG_CHANNEL(font);
/* Device -> World size conversion */
@@ -258,10 +265,73 @@ static void FONT_NewTextMetricExWToA(const NEWTEXTMETRICEXW *ptmW, NEWTEXTMETRIC
memcpy(&ptmA->ntmFontSig, &ptmW->ntmFontSig, sizeof(FONTSIGNATURE));
}
+static DWORD get_font_ppem( HDC hdc )
+{
+ TEXTMETRICW tm;
+ DWORD ppem;
+ DC *dc = get_dc_ptr( hdc );
+
+ if (!dc) return GDI_ERROR;
+
+ GetTextMetricsW( hdc, &tm );
+ ppem = abs( INTERNAL_YWSTODS( dc, tm.tmAscent + tm.tmDescent - tm.tmInternalLeading ) );
+ release_dc_ptr( dc );
+ return ppem;
+}
+
+#define GASP_GRIDFIT 0x01
+#define GASP_DOGRAY 0x02
+
+static BOOL get_gasp_flags( HDC hdc, WORD *flags )
+{
+ DWORD size, gasp_tag = 0x70736167;
+ WORD buf[16]; /* Enough for seven ranges before we need to alloc */
+ WORD *alloced = NULL, *ptr = buf;
+ WORD num_recs, version;
+ DWORD ppem = get_font_ppem( hdc );
+ BOOL ret = FALSE;
+
+ *flags = 0;
+ if (ppem == GDI_ERROR) return FALSE;
+
+ size = GetFontData( hdc, gasp_tag, 0, NULL, 0 );
+ if (size == GDI_ERROR) return FALSE;
+ if (size < 4 * sizeof(WORD)) return FALSE;
+ if (size > sizeof(buf))
+ {
+ ptr = alloced = HeapAlloc( GetProcessHeap(), 0, size );
+ if (!ptr) return FALSE;
+ }
+
+ GetFontData( hdc, gasp_tag, 0, ptr, size );
+
+ version = get_be_word( *ptr++ );
+ num_recs = get_be_word( *ptr++ );
+
+ if (version > 1 || size < (num_recs * 2 + 2) * sizeof(WORD))
+ {
+ FIXME( "Unsupported gasp table: ver %d size %d recs %d\n", version, size, num_recs );
+ goto done;
+ }
+
+ while (num_recs--)
+ {
+ *flags = get_be_word( *(ptr + 1) );
+ if (ppem <= get_be_word( *ptr )) break;
+ ptr += 2;
+ }
+ TRACE( "got flags %04x for ppem %d\n", *flags, ppem );
+ ret = TRUE;
+
+done:
+ HeapFree( GetProcessHeap(), 0, alloced );
+ return ret;
+}
UINT get_font_aa_flags( HDC hdc )
{
LOGFONTW lf;
+ WORD gasp_flags;
if (GetObjectType( hdc ) == OBJ_MEMDC)
{
@@ -274,7 +344,10 @@ UINT get_font_aa_flags( HDC hdc )
GetObjectW( GetCurrentObject( hdc, OBJ_FONT ), sizeof(lf), &lf );
if (lf.lfQuality == NONANTIALIASED_QUALITY) return GGO_BITMAP;
- /* FIXME, check gasp and user prefs */
+ if (get_gasp_flags( hdc, &gasp_flags ) && !(gasp_flags & GASP_DOGRAY))
+ return GGO_BITMAP;
+
+ /* FIXME, check user prefs */
return GGO_GRAY4_BITMAP;
}
More information about the wine-cvs
mailing list