Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1195)

Unified Diff: Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp

Issue 17080004: Move windows specific isFixedPitch to FontPlatformData (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
diff --git a/Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp b/Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
index 587131614469dabfa01fa28806b70c9f865c5dcd..77da4a5c2af25a15fcbe9ad8fed8a6b9d9ef62cb 100644
--- a/Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
+++ b/Source/core/platform/graphics/chromium/FontPlatformDataChromiumWin.cpp
@@ -203,6 +203,36 @@ FontPlatformData::~FontPlatformData()
m_scriptFontProperties = 0;
}
+bool FontPlatformData::isFixedPitch() const
+{
+#if ENABLE(GDI_FONTS_ON_WINDOWS)
+ // TEXTMETRICS have this. Set m_treatAsFixedPitch based off that.
+ HWndDC dc(0);
+ HGDIOBJ oldFont = SelectObject(dc, hfont());
+
+ // Yes, this looks backwards, but the fixed pitch bit is actually set if the font
+ // is *not* fixed pitch. Unbelievable but true.
+ TEXTMETRIC textMetric = { 0 };
+ if (!GetTextMetrics(dc, &textMetric)) {
+ if (ensureFontLoaded(hfont())) {
+ // Retry GetTextMetrics.
+ // FIXME: Handle gracefully the error if this call also fails.
+ // See http://crbug.com/6401.
+ if (!GetTextMetrics(dc, &textMetric))
+ LOG_ERROR("Unable to get the text metrics after second attempt");
+ }
+ }
+
+ bool treatAsFixedPitch = !(textMetric.tmPitchAndFamily & TMPF_FIXED_PITCH);
+
+ SelectObject(dc, oldFont);
+
+ return treatAsFixedPitch;
+#else
+ return typeface()->isFixedPitch();
+#endif
+}
+
FontPlatformData::RefCountedHFONT::~RefCountedHFONT()
{
if (m_hfont != reinterpret_cast<HFONT>(-1)) {

Powered by Google App Engine
This is Rietveld 408576698