Bug 537890. Part 3: Remove gfxPlatform::GetDPI(). r=vlad
--- a/gfx/src/thebes/nsSystemFontsAndroid.cpp
+++ b/gfx/src/thebes/nsSystemFontsAndroid.cpp
@@ -60,17 +60,17 @@ nsresult
nsSystemFontsAndroid::GetSystemFontInfo(const char *aClassName, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
aFontStyle->style = FONT_STYLE_NORMAL;
aFontStyle->systemFont = PR_TRUE;
*aFontName = NS_LITERAL_STRING("Droid Sans");
aFontStyle->weight = 400;
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
- aFontStyle->size = 9.0 * float(gfxPlatform::GetDPI()) / 72.0f;
+ aFontStyle->size = 9.0 * 96.0f / 72.0f;
return NS_OK;
}
nsresult
nsSystemFontsAndroid::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const
{
--- a/gfx/src/thebes/nsSystemFontsGTK2.cpp
+++ b/gfx/src/thebes/nsSystemFontsGTK2.cpp
@@ -216,17 +216,17 @@ nsSystemFontsGTK2::GetSystemFontInfo(Gtk
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
float size = float(pango_font_description_get_size(desc)) / PANGO_SCALE;
// |size| is now either pixels or pango-points (not Mozilla-points!)
if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
// |size| is in pango-points, so convert to pixels.
- size *= float(gfxPlatform::GetDPI()) / POINTS_PER_INCH_FLOAT;
+ size *= float(gfxPlatformGtk::GetDPI()) / POINTS_PER_INCH_FLOAT;
}
// |size| is now pixels
aFontStyle->size = size;
pango_font_description_free(desc);
--- a/gfx/src/thebes/nsSystemFontsQt.cpp
+++ b/gfx/src/thebes/nsSystemFontsQt.cpp
@@ -79,19 +79,17 @@ nsSystemFontsQt::GetSystemFontInfo(const
*aFontName = quote + family + quote;
aFontStyle->weight = qFont.weight();
// FIXME: Set aFontStyle->stretch correctly!
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
// use pixel size directly if it is set, otherwise compute from point size
if (qFont.pixelSize() != -1) {
aFontStyle->size = qFont.pixelSize();
} else {
- aFontStyle->size = qFont.pointSizeF()
- * float(gfxPlatform::GetDPI())
- / 72.0f;
+ aFontStyle->size = qFont.pointSizeF() * 96.0f / 72.0f;
}
return NS_OK;
}
nsresult
nsSystemFontsQt::GetSystemFont(nsSystemFontID anID, nsString *aFontName,
gfxFontStyle *aFontStyle) const
--- a/gfx/thebes/gfxOS2Platform.cpp
+++ b/gfx/thebes/gfxOS2Platform.cpp
@@ -216,27 +216,8 @@ gfxOS2Platform::FindFontForChar(PRUint32
}
}
}
// no match found, so add to the set of non-matching codepoints
mCodepointsWithNoFonts.set(aCh);
return nsnull;
}
-
-void
-gfxOS2Platform::InitDisplayCaps()
-{
- // create DC compatible with the screen
- HDC dc = DevOpenDC((HAB)1, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
- if (dc > 0) {
- // we do have a DC and we can query the DPI setting from it
- LONG lDPI;
- if (DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &lDPI))
- gfxPlatform::sDPI = lDPI;
- DevCloseDC(dc);
- }
-
- if (gfxPlatform::sDPI <= 0) {
- // Fall back to something sane
- gfxPlatform::sDPI = 96;
- }
-}
--- a/gfx/thebes/gfxOS2Platform.h
+++ b/gfx/thebes/gfxOS2Platform.h
@@ -82,18 +82,16 @@ public:
already_AddRefed<gfxOS2Font> FindFontForChar(PRUint32 aCh, gfxOS2Font *aFont);
// return true if it's already known that we don't have a font for this char
PRBool noFontWithChar(PRUint32 aCh) {
return mCodepointsWithNoFonts.test(aCh);
}
protected:
- void InitDisplayCaps();
-
static gfxFontconfigUtils *sFontconfigUtils;
private:
// when font lookup fails for a character, cache it to skip future searches
gfxSparseBitSet mCodepointsWithNoFonts;
};
#endif /* GFX_OS2_PLATFORM_H */
--- a/gfx/thebes/gfxPangoFonts.cpp
+++ b/gfx/thebes/gfxPangoFonts.cpp
@@ -707,28 +707,40 @@ gfx_pango_fc_font_get_coverage(PangoFont
self->mCoverage =
pango_coverage_ref(downloadedFontEntry->GetPangoCoverage());
}
}
return pango_coverage_ref(self->mCoverage);
}
+static PRInt32
+GetDPI()
+{
+#if defined(MOZ_WIDGET_GTK2)
+ return gfxPlatformGtk::GetDPI();
+#elif defined(MOZ_WIDGET_QT)
+ return gfxQtPlatform::GetDPI();
+#else
+ return 96;
+#endif
+}
+
static PangoFontDescription *
gfx_pango_fc_font_describe(PangoFont *font)
{
gfxPangoFcFont *self = GFX_PANGO_FC_FONT(font);
PangoFcFont *fcFont = &self->parent_instance;
PangoFontDescription *result =
pango_font_description_copy(fcFont->description);
gfxFcFont *gfxFont = gfxPangoFcFont::GfxFont(self);
if (gfxFont) {
double pixelsize = gfxFont->GetStyle()->size;
- double dpi = gfxPlatform::GetDPI();
+ double dpi = GetDPI();
gint size = moz_pango_units_from_double(pixelsize * dpi / 72.0);
pango_font_description_set_size(result, size);
}
return result;
}
static PangoFontDescription *
gfx_pango_fc_font_describe_absolute(PangoFont *font)
@@ -1715,18 +1727,17 @@ gfx_pango_font_map_load_fontset(PangoFon
return gfxPangoFontset::NewFontset(fontGroup, language);
}
static double
gfx_pango_font_map_get_resolution(PangoFcFontMap *fcfontmap,
PangoContext *context)
{
// This merely enables the FC_SIZE field of the pattern to be accurate.
- // We use gfxPlatform::GetDPI() much of the time...
- return gfxPlatform::GetDPI();
+ return GetDPI();
}
#ifdef MOZ_WIDGET_GTK2
static void ApplyGdkScreenFontOptions(FcPattern *aPattern);
#endif
// Apply user settings and defaults to pattern in preparation for matching.
static void
--- a/gfx/thebes/gfxPlatform.cpp
+++ b/gfx/thebes/gfxPlatform.cpp
@@ -81,18 +81,16 @@
#include "nsCRT.h"
#include "GLContext.h"
#include "GLContextProvider.h"
#include "mozilla/FunctionTimer.h"
gfxPlatform *gPlatform = nsnull;
-PRInt32 gfxPlatform::sDPI = -1;
-
// These two may point to the same profile
static qcms_profile *gCMSOutputProfile = nsnull;
static qcms_profile *gCMSsRGBProfile = nsnull;
static qcms_transform *gCMSRGBTransform = nsnull;
static qcms_transform *gCMSInverseRGBTransform = nsnull;
static qcms_transform *gCMSRGBATransform = nsnull;
@@ -1058,23 +1056,16 @@ static void MigratePrefs()
rv = prefs->GetBoolPref(CMPrefNameOld, &CMWasEnabled);
if (NS_SUCCEEDED(rv) && (CMWasEnabled == PR_TRUE))
prefs->SetIntPref(CMPrefName, eCMSMode_All);
prefs->ClearUserPref(CMPrefNameOld);
}
}
-void
-gfxPlatform::InitDisplayCaps()
-{
- // Fall back to something sane
- gfxPlatform::sDPI = 96;
-}
-
// default SetupClusterBoundaries, based on Unicode properties;
// platform subclasses may override if they wish
static nsIUGenCategory* gGenCategory = nsnull;
static nsIUGenCategory*
GetGenCategory()
{
if (!gGenCategory) {
--- a/gfx/thebes/gfxPlatform.h
+++ b/gfx/thebes/gfxPlatform.h
@@ -332,44 +332,27 @@ public:
*/
static qcms_transform* GetCMSInverseRGBTransform();
/**
* Return sRGBA -> output device transform.
*/
static qcms_transform* GetCMSRGBATransform();
- /**
- * Return display DPI
- */
- static PRInt32 GetDPI() {
- if (sDPI < 0) {
- gfxPlatform::GetPlatform()->InitDisplayCaps();
- }
- NS_ASSERTION(sDPI > 0, "Something is wrong");
- return sDPI;
- }
-
virtual void FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref);
protected:
gfxPlatform();
virtual ~gfxPlatform();
static PRBool GetBoolPref(const char *aPref, PRBool aDefault);
void AppendCJKPrefLangs(eFontPrefLang aPrefLangs[], PRUint32 &aLen,
eFontPrefLang aCharLang, eFontPrefLang aPageLang);
- /**
- * Initialize any needed display metrics (such as DPI)
- */
- virtual void InitDisplayCaps();
- static PRInt32 sDPI;
-
PRBool mAllowDownloadableFonts;
// whether to use the HarfBuzz layout engine
PRInt8 mUseHarfBuzzLevel;
private:
virtual qcms_profile* GetPlatformCMSOutputProfile();
--- a/gfx/thebes/gfxPlatformGtk.cpp
+++ b/gfx/thebes/gfxPlatformGtk.cpp
@@ -470,27 +470,32 @@ gfxPlatformGtk::CreateFontGroup(const ns
const gfxFontStyle *aStyle,
gfxUserFontSet * /*aUserFontSet*/)
{
return new gfxFT2FontGroup(aFamilies, aStyle);
}
#endif
-void
-gfxPlatformGtk::InitDisplayCaps()
+static PRInt32 sDPI = 0;
+
+PRInt32
+gfxPlatformGtk::GetDPI()
{
- // Make sure init is run so we have a resolution
- GdkScreen *screen = gdk_screen_get_default();
- gtk_settings_get_for_screen(screen);
- gfxPlatform::sDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
- if (gfxPlatform::sDPI <= 0) {
- // Fall back to something sane
- gfxPlatform::sDPI = 96;
+ if (!sDPI) {
+ // Make sure init is run so we have a resolution
+ GdkScreen *screen = gdk_screen_get_default();
+ gtk_settings_get_for_screen(screen);
+ sDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
+ if (sDPI <= 0) {
+ // Fall back to something sane
+ sDPI = 96;
+ }
}
+ return sDPI;
}
qcms_profile *
gfxPlatformGtk::GetPlatformCMSOutputProfile()
{
#ifdef MOZ_X11
const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
--- a/gfx/thebes/gfxPlatformGtk.h
+++ b/gfx/thebes/gfxPlatformGtk.h
@@ -117,18 +117,18 @@ public:
#ifndef MOZ_PANGO
FT_Library GetFTLibrary();
#endif
static void SetGdkDrawable(gfxASurface *target,
GdkDrawable *drawable);
static GdkDrawable *GetGdkDrawable(gfxASurface *target);
+ static PRInt32 GetDPI();
+
protected:
- void InitDisplayCaps();
-
static gfxFontconfigUtils *sFontconfigUtils;
private:
virtual qcms_profile *GetPlatformCMSOutputProfile();
};
#endif /* GFX_PLATFORM_GTK_H */
--- a/gfx/thebes/gfxQtPlatform.cpp
+++ b/gfx/thebes/gfxQtPlatform.cpp
@@ -565,19 +565,18 @@ gfxQtPlatform::GetPrefFontEntries(const
return mPrefFonts.Get(aKey, array);
}
void
gfxQtPlatform::SetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<gfxFontEntry> >& array)
{
mPrefFonts.Put(aKey, array);
}
+
#endif
-void
-gfxQtPlatform::InitDisplayCaps()
+PRInt32
+gfxQtPlatform::GetDPI()
{
QDesktopWidget* rootWindow = qApp->desktop();
- sDPI = rootWindow->logicalDpiY(); // y-axis DPI for fonts
- if (sDPI <= 0)
- sDPI = 96; // something more sensible
+ PRInt32 dpi = rootWindow->logicalDpiY(); // y-axis DPI for fonts
+ return dpi <= 0 ? 96 : dpi;
}
-
--- a/gfx/thebes/gfxQtPlatform.h
+++ b/gfx/thebes/gfxQtPlatform.h
@@ -126,19 +126,20 @@ public:
#ifndef MOZ_PANGO
FT_Library GetFTLibrary();
#endif
RenderMode GetRenderMode() { return mRenderMode; }
void SetRenderMode(RenderMode rmode) { mRenderMode = rmode; }
+ static PRInt32 GetDPI();
+
protected:
static gfxFontconfigUtils *sFontconfigUtils;
- void InitDisplayCaps();
private:
virtual qcms_profile *GetPlatformCMSOutputProfile();
// TODO: unify this with mPrefFonts (NB: holds families, not fonts) in gfxPlatformFontList
nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<gfxFontEntry> > > mPrefFonts;
RenderMode mRenderMode;
--- a/gfx/thebes/gfxWindowsPlatform.cpp
+++ b/gfx/thebes/gfxWindowsPlatform.cpp
@@ -623,26 +623,16 @@ gfxWindowsPlatform::WindowsOSVersion()
} else {
winVersion = PRInt32(vinfo.dwMajorVersion << 16) + vinfo.dwMinorVersion;
}
}
return winVersion;
}
void
-gfxWindowsPlatform::InitDisplayCaps()
-{
- HDC dc = GetDC((HWND)nsnull);
-
- gfxPlatform::sDPI = GetDeviceCaps(dc, LOGPIXELSY);
-
- ReleaseDC((HWND)nsnull, dc);
-}
-
-void
gfxWindowsPlatform::FontsPrefsChanged(nsIPrefBranch *aPrefBranch, const char *aPref)
{
PRBool clearTextFontCaches = PR_TRUE;
gfxPlatform::FontsPrefsChanged(aPrefBranch, aPref);
if (!aPref) {
mUseClearTypeForDownloadableFonts = UNINITIALIZED_VALUE;
--- a/gfx/thebes/gfxWindowsPlatform.h
+++ b/gfx/thebes/gfxWindowsPlatform.h
@@ -221,18 +221,16 @@ public:
cairo_device_t *GetD2DDevice() { return mD2DDevice; }
#endif
#ifdef MOZ_FT2_FONTS
FT_Library GetFTLibrary();
#endif
protected:
- void InitDisplayCaps();
-
RenderMode mRenderMode;
PRBool mUseClearTypeForDownloadableFonts;
PRBool mUseClearTypeAlways;
private:
void Init();
--- a/widget/src/os2/nsWindow.cpp
+++ b/widget/src/os2/nsWindow.cpp
@@ -563,16 +563,38 @@ nsIWidget* nsWindow::GetParent()
if (mFrame || mIsDestroying || mOnDestroyCalled ||
!mParent || mParent->mIsDestroying) {
return 0;
}
return mParent;
}
+static PRInt32 sDPI = 0;
+
+float nsWindow::GetDPI()
+{
+ if (!sDPI) {
+ // create DC compatible with the screen
+ HDC dc = DevOpenDC((HAB)1, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
+ if (dc > 0) {
+ // we do have a DC and we can query the DPI setting from it
+ LONG lDPI;
+ if (DevQueryCaps(dc, CAPS_VERTICAL_FONT_RES, 1, &lDPI))
+ sDPI = lDPI;
+ DevCloseDC(dc);
+ }
+ if (sDPI <= 0) {
+ // Fall back to something sane
+ sDPI = 96;
+ }
+ }
+ return sDPI;
+}
+
//-----------------------------------------------------------------------------
NS_METHOD nsWindow::Enable(PRBool aState)
{
HWND hMain = GetMainWindow();
if (hMain) {
WinEnableWindow(hMain, aState);
}
--- a/widget/src/os2/nsWindow.h
+++ b/widget/src/os2/nsWindow.h
@@ -166,16 +166,17 @@ public:
const nsIntRect& aRect,
EVENT_CALLBACK aHandleEventFunction,
nsIDeviceContext* aContext,
nsIAppShell* aAppShell = nsnull,
nsIToolkit* aToolkit = nsnull,
nsWidgetInitData* aInitData = nsnull);
NS_IMETHOD Destroy();
virtual nsIWidget* GetParent();
+ virtual float GetDPI();
NS_IMETHOD Enable(PRBool aState);
NS_IMETHOD IsEnabled(PRBool* aState);
NS_IMETHOD Show(PRBool aState);
NS_IMETHOD IsVisible(PRBool& aState);
NS_IMETHOD SetFocus(PRBool aRaise);
NS_IMETHOD Invalidate(const nsIntRect& aRect,
PRBool aIsSynchronous);
NS_IMETHOD Update();