[pango/pango1-dwrite] Implement is_hinted for PangoWin32Font
- From: Chun-wei Fan <fanchunwei src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango1-dwrite] Implement is_hinted for PangoWin32Font
- Date: Tue, 12 Jul 2022 08:24:07 +0000 (UTC)
commit f7e6cb0179e6553be5a4b998084a2b10c027f520
Author: Chun-wei Fan <fanchunwei src gnome org>
Date: Mon Jul 11 19:09:01 2022 +0800
Implement is_hinted for PangoWin32Font
This is the GDI+ implementation for querying whether a given font supports
hinting, which will be meant for Windows 7 and 8, since the DirectWrite
counterpart is only available for Windows 8.1 or later, which will be in
a later patch.
Link to gdiplus.lib as we are using the flat C APIs from there, which sadly we
had to add into our own private headers since we can't just include the GDI+
headers from our plain-C sources.
pango/meson.build | 1 +
pango/pangocairo-win32font.c | 2 +-
pango/pangowin32-fontmap.c | 1 +
pango/pangowin32-private.h | 6 ++++
pango/pangowin32.c | 70 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 79 insertions(+), 1 deletion(-)
---
diff --git a/pango/meson.build b/pango/meson.build
index cc301f0b7..efcc0c936 100644
--- a/pango/meson.build
+++ b/pango/meson.build
@@ -430,6 +430,7 @@ if host_system == 'windows'
pangowin32_deps = pango_deps + [
libpango_dep,
cc.find_library('gdi32'),
+ cc.find_library('gdiplus'),
]
if enable_dwrite_support
pangowin32_deps += cc.find_library('dwrite')
diff --git a/pango/pangocairo-win32font.c b/pango/pangocairo-win32font.c
index 9f4f5c140..e79c4e9f6 100644
--- a/pango/pangocairo-win32font.c
+++ b/pango/pangocairo-win32font.c
@@ -267,7 +267,7 @@ _pango_cairo_win32_font_new (PangoCairoWin32FontMap *cwfontmap,
&face->logfontw,
win32font->size,
&win32font->logfontw);
-
+ win32font->is_hinted = pango_win32_font_check_is_hinted (win32font);
cairo_matrix_init_identity (&font_matrix);
cairo_matrix_scale (&font_matrix, size, size);
diff --git a/pango/pangowin32-fontmap.c b/pango/pangowin32-fontmap.c
index 88ab343c3..cfe7f366d 100644
--- a/pango/pangowin32-fontmap.c
+++ b/pango/pangowin32-fontmap.c
@@ -1151,6 +1151,7 @@ pango_win32_font_neww (PangoFontMap *fontmap,
result->size = size;
_pango_win32_make_matching_logfontw (fontmap, lfp, size, &result->logfontw);
+ result->is_hinted = pango_win32_font_check_is_hinted (result);
return result;
}
diff --git a/pango/pangowin32-private.h b/pango/pangowin32-private.h
index 9bbc3b22c..d23f74423 100644
--- a/pango/pangowin32-private.h
+++ b/pango/pangowin32-private.h
@@ -215,6 +215,9 @@ struct _PangoWin32Font
*/
gboolean in_cache;
GHashTable *glyph_info;
+
+ /* whether the font supports hinting */
+ gboolean is_hinted;
};
struct _PangoWin32FontClass
@@ -365,6 +368,9 @@ void pango_win32_insert_font (PangoWin32FontMap
gpointer dwrite_font,
gboolean is_synthetic);
+_PANGO_EXTERN
+gboolean pango_win32_font_check_is_hinted (PangoWin32Font *font);
+
void pango_win32_dwrite_font_map_init (PangoWin32FontMap *map);
void pango_win32_dwrite_font_map_populate (PangoWin32FontMap *map);
diff --git a/pango/pangowin32.c b/pango/pangowin32.c
index eed92dde7..003bd1015 100644
--- a/pango/pangowin32.c
+++ b/pango/pangowin32.c
@@ -56,6 +56,7 @@ static gboolean pango_win32_font_real_select_font (PangoFont *font,
HDC hdc);
static void pango_win32_font_real_done_font (PangoFont *font);
static double pango_win32_font_real_get_metrics_factor (PangoFont *font);
+static gboolean pango_win32_font_is_hinted (PangoFont *font);
static void pango_win32_get_item_properties (PangoItem *item,
PangoUnderline *uline,
@@ -187,6 +188,7 @@ _pango_win32_font_class_init (PangoWin32FontClass *class)
{
GObjectClass *object_class = G_OBJECT_CLASS (class);
PangoFontClass *font_class = PANGO_FONT_CLASS (class);
+ PangoFontClassPrivate *pclass;
object_class->finalize = pango_win32_font_finalize;
object_class->dispose = pango_win32_font_dispose;
@@ -203,6 +205,9 @@ _pango_win32_font_class_init (PangoWin32FontClass *class)
class->done_font = pango_win32_font_real_done_font;
class->get_metrics_factor = pango_win32_font_real_get_metrics_factor;
+ pclass = g_type_class_get_private ((GTypeClass *) class, PANGO_TYPE_FONT);
+ pclass->is_hinted = pango_win32_font_is_hinted;
+
_pango_win32_get_display_dc ();
}
@@ -647,6 +652,71 @@ pango_win32_font_real_get_metrics_factor (PangoFont *font)
return PANGO_SCALE;
}
+gboolean
+pango_win32_font_check_is_hinted (PangoWin32Font *font)
+{
+ LOGFONTW lfw;
+ HDC hdc;
+ HFONT hfont, oldhfont;
+ GpGraphics *gpgraphics = NULL;
+ TextRenderingHint mode;
+ gboolean is_hinted = FALSE;
+ GpStatus status;
+ GdiplusStartupInput input;
+ ULONG_PTR gdiplusToken = 0;
+
+ lfw = font->logfontw;
+ memset (&input, 0, sizeof (input));
+ input.GdiplusVersion = 1;
+
+ if ((hfont = CreateFontIndirectW (&lfw)) == NULL)
+ return FALSE;
+
+ hdc = _pango_win32_get_display_dc ();
+
+ if ((oldhfont = SelectObject (hdc, hfont)) == NULL)
+ {
+ DeleteObject (hfont);
+ return FALSE;
+ }
+
+ if (GdiplusStartup (&gdiplusToken, &input, NULL) != Ok)
+ return FALSE;
+
+ if (GdipCreateFromHDC (hdc, &gpgraphics) == Ok &&
+ GdipGetTextRenderingHint (gpgraphics, &mode) == Ok)
+ {
+ if (mode == TextRenderingHintSingleBitPerPixelGridFit ||
+ mode == TextRenderingHintAntiAliasGridFit ||
+ mode == TextRenderingHintClearTypeGridFit)
+ is_hinted = TRUE;
+ else if (mode == TextRenderingHintSystemDefault)
+ {
+ BOOL sys_is_hinted = FALSE;
+
+ if (SystemParametersInfoW (SPI_GETFONTSMOOTHING, 0, &sys_is_hinted, 0))
+ is_hinted = sys_is_hinted;
+ }
+ else
+ is_hinted = FALSE;
+ }
+
+ GdipDeleteGraphics (gpgraphics);
+ GdiplusShutdown (gdiplusToken);
+ SelectObject (hdc, oldhfont);
+ DeleteObject (hfont);
+
+ return is_hinted;
+}
+
+static gboolean
+pango_win32_font_is_hinted (PangoFont *font)
+{
+ g_return_val_if_fail (PANGO_WIN32_IS_FONT (font), FALSE);
+
+ return PANGO_WIN32_FONT (font)->is_hinted;
+}
+
/**
* pango_win32_font_logfont:
* @font: a `PangoFont` which must be from the Win32 backend
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]