Bug 449283: DPI on n810 is incorrect, r=roc

This commit is contained in:
Mark Finkle 2009-09-22 08:45:56 -04:00
parent 7e04774dbf
commit 290393eadd
14 changed files with 136 additions and 114 deletions

View file

@ -221,7 +221,7 @@ nsSystemFontsGTK2::GetSystemFontInfo(GtkWidget *aWidget, nsString *aFontName,
if (!MOZ_pango_font_description_get_size_is_absolute(desc)) { if (!MOZ_pango_font_description_get_size_is_absolute(desc)) {
// |size| is in pango-points, so convert to pixels. // |size| is in pango-points, so convert to pixels.
size *= gfxPlatformGtk::DPI() / POINTS_PER_INCH_FLOAT; size *= float(gfxPlatform::GetDPI()) / POINTS_PER_INCH_FLOAT;
} }
// |size| is now pixels // |size| is now pixels

View file

@ -79,7 +79,7 @@ nsSystemFontsQt::GetSystemFontInfo(const char *aClassName, nsString *aFontName,
aFontStyle->weight = qFont.weight(); aFontStyle->weight = qFont.weight();
// FIXME: Set aFontStyle->stretch correctly! // FIXME: Set aFontStyle->stretch correctly!
aFontStyle->stretch = NS_FONT_STRETCH_NORMAL; aFontStyle->stretch = NS_FONT_STRETCH_NORMAL;
aFontStyle->size = qFont.pointSizeF() * float(gfxQtPlatform::DPI()) / 72.0f; aFontStyle->size = qFont.pointSizeF() * float(gfxPlatform::GetDPI()) / 72.0f;
return NS_OK; return NS_OK;
} }

View file

@ -51,6 +51,7 @@
#include "nsThebesDeviceContext.h" #include "nsThebesDeviceContext.h"
#include "nsThebesRenderingContext.h" #include "nsThebesRenderingContext.h"
#include "gfxUserFontSet.h" #include "gfxUserFontSet.h"
#include "gfxPlatform.h"
#include "nsIWidget.h" #include "nsIWidget.h"
#include "nsIView.h" #include "nsIView.h"
@ -656,11 +657,30 @@ nsThebesDeviceContext::SetDPI()
} }
// PostScript, PDF and Mac (when printing) all use 72 dpi // PostScript, PDF and Mac (when printing) all use 72 dpi
if (mPrintingSurface && // Use a printing DC to determine the other dpi values
(mPrintingSurface->GetType() == gfxASurface::SurfaceTypePDF || if (mPrintingSurface) {
mPrintingSurface->GetType() == gfxASurface::SurfaceTypePS || switch (mPrintingSurface->GetType()) {
mPrintingSurface->GetType() == gfxASurface::SurfaceTypeQuartz)) { case gfxASurface::SurfaceTypePDF:
dpi = 72; case gfxASurface::SurfaceTypePS:
case gfxASurface::SurfaceTypeQuartz:
dpi = 72;
break;
#ifdef XP_WIN
case gfxASurface::SurfaceTypeWin32:
case gfxASurface::SurfaceTypeWin32Printing:
PRInt32 OSVal = GetDeviceCaps(GetPrintHDC(), LOGPIXELSY);
dpi = 144;
mPrintingScale = float(OSVal) / dpi;
break;
#endif
#ifdef XP_OS2
case gfxASurface::SurfaceTypeOS2:
LONG lDPI;
if (DevQueryCaps(GetPrintHDC(), CAPS_VERTICAL_FONT_RES, 1, &lDPI))
dpi = lDPI;
break;
#endif
}
dotsArePixels = PR_FALSE; dotsArePixels = PR_FALSE;
} else { } else {
nsresult rv; nsresult rv;
@ -676,67 +696,7 @@ nsThebesDeviceContext::SetDPI()
} }
} }
#if defined(MOZ_ENABLE_GTK2) dpi = gfxPlatform::GetDPI();
GdkScreen *screen = gdk_screen_get_default();
gtk_settings_get_for_screen(screen); // Make sure init is run so we have a resolution
PRInt32 OSVal = PRInt32(round(gdk_screen_get_resolution(screen)));
if (prefDPI == 0) // Force the use of the OS dpi
dpi = OSVal;
else // Otherwise, the minimum dpi is 96dpi
dpi = PR_MAX(OSVal, 96);
#elif defined(XP_WIN)
// XXX we should really look at the widget if !dc but it is currently always null
HDC dc = GetPrintHDC();
if (dc) {
PRInt32 OSVal = GetDeviceCaps(dc, LOGPIXELSY);
dpi = 144;
mPrintingScale = float(OSVal)/dpi;
dotsArePixels = PR_FALSE;
} else {
dc = GetDC((HWND)nsnull);
PRInt32 OSVal = GetDeviceCaps(dc, LOGPIXELSY);
ReleaseDC((HWND)nsnull, dc);
if (OSVal != 0)
dpi = OSVal;
}
#elif defined(XP_OS2)
// get a printer DC if available, otherwise create a new (memory) DC
HDC dc = GetPrintHDC();
PRBool doCloseDC = PR_FALSE;
if (dc <= 0) { // test for NULLHANDLE/DEV_ERROR or HDC_ERROR
// create DC compatible with the screen
dc = DevOpenDC((HAB)1, OD_MEMORY,"*",0L, NULL, NULLHANDLE);
doCloseDC = PR_TRUE;
}
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))
dpi = lDPI;
if (doCloseDC)
DevCloseDC(dc);
}
if (dpi < 0) // something didn't work before, fall back to hardcoded DPI value
dpi = 96;
#elif defined(XP_MACOSX)
// we probably want to actually get a real DPI here?
dpi = 96;
#elif defined(MOZ_WIDGET_QT)
// TODO: get real DPI here with Qt methods
dpi = 96;
#else
#error undefined platform dpi
#endif
if (prefDPI > 0 && !mPrintingSurface) if (prefDPI > 0 && !mPrintingSurface)
dpi = prefDPI; dpi = prefDPI;
} }

View file

@ -87,6 +87,8 @@ public:
} }
protected: protected:
void InitDisplayCaps();
static gfxFontconfigUtils *sFontconfigUtils; static gfxFontconfigUtils *sFontconfigUtils;
private: private:

View file

@ -303,10 +303,27 @@ public:
*/ */
static qcms_transform* GetCMSRGBATransform(); 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;
}
protected: protected:
gfxPlatform() { } gfxPlatform() { }
virtual ~gfxPlatform(); virtual ~gfxPlatform();
/**
* Initialize any needed display metrics (such as DPI)
*/
virtual void InitDisplayCaps();
static PRInt32 sDPI;
private: private:
virtual qcms_profile* GetPlatformCMSOutputProfile(); virtual qcms_profile* GetPlatformCMSOutputProfile();

View file

@ -121,14 +121,6 @@ public:
void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& aFontEntryList); void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& aFontEntryList);
#endif #endif
static double DPI() {
if (sDPI < 0.0) {
InitDPI();
}
NS_ASSERTION(sDPI > 0.0, "Something is wrong");
return sDPI;
}
#ifndef MOZ_PANGO #ifndef MOZ_PANGO
FT_Library GetFTLibrary(); FT_Library GetFTLibrary();
#endif #endif
@ -138,9 +130,8 @@ public:
GdkDrawable *GetGdkDrawable(gfxASurface *target); GdkDrawable *GetGdkDrawable(gfxASurface *target);
protected: protected:
static void InitDPI(); void InitDisplayCaps();
static double sDPI;
static gfxFontconfigUtils *sFontconfigUtils; static gfxFontconfigUtils *sFontconfigUtils;
private: private:

View file

@ -83,20 +83,11 @@ public:
PRBool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> > *aFontEntryList); PRBool GetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> > *aFontEntryList);
void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& aFontEntryList); void SetPrefFontEntries(const nsCString& aLangGroup, nsTArray<nsRefPtr<FontEntry> >& aFontEntryList);
static PRInt32 DPI() {
if (sDPI == -1) {
InitDPI();
}
NS_ASSERTION(sDPI > 0, "Something is wrong");
return sDPI;
}
FT_Library GetFTLibrary(); FT_Library GetFTLibrary();
protected: protected:
static void InitDPI(); void InitDisplayCaps();
static PRInt32 sDPI;
static gfxFontconfigUtils *sFontconfigUtils; static gfxFontconfigUtils *sFontconfigUtils;
private: private:

View file

@ -163,6 +163,8 @@ private:
#endif #endif
protected: protected:
void InitDisplayCaps();
RenderMode mRenderMode; RenderMode mRenderMode;
private: private:

View file

@ -219,3 +219,22 @@ gfxOS2Platform::FindFontForChar(PRUint32 aCh, gfxOS2Font *aFont)
mCodepointsWithNoFonts.set(aCh); mCodepointsWithNoFonts.set(aCh);
return nsnull; 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;
}
}

View file

@ -787,7 +787,7 @@ gfx_pango_fc_font_describe(PangoFont *font)
gfxFcFont *gfxFont = gfxPangoFcFont::GfxFont(self); gfxFcFont *gfxFont = gfxPangoFcFont::GfxFont(self);
if (gfxFont) { if (gfxFont) {
double pixelsize = gfxFont->GetStyle()->size; double pixelsize = gfxFont->GetStyle()->size;
double dpi = gfxPlatformGtk::DPI(); double dpi = gfxPlatform::GetDPI();
gint size = moz_pango_units_from_double(pixelsize * dpi / 72.0); gint size = moz_pango_units_from_double(pixelsize * dpi / 72.0);
pango_font_description_set_size(result, size); pango_font_description_set_size(result, size);
} }
@ -1784,8 +1784,8 @@ gfx_pango_font_map_get_resolution(PangoFcFontMap *fcfontmap,
PangoContext *context) PangoContext *context)
{ {
// This merely enables the FC_SIZE field of the pattern to be accurate. // This merely enables the FC_SIZE field of the pattern to be accurate.
// We use gfxPlatformGtk::DPI() much of the time... // We use gfxPlatform::GetDPI() much of the time...
return gfxPlatformGtk::DPI(); return gfxPlatform::GetDPI();
} }
#ifdef MOZ_WIDGET_GTK2 #ifdef MOZ_WIDGET_GTK2

View file

@ -73,6 +73,8 @@
gfxPlatform *gPlatform = nsnull; gfxPlatform *gPlatform = nsnull;
PRInt32 gfxPlatform::sDPI = -1;
// These two may point to the same profile // These two may point to the same profile
static qcms_profile *gCMSOutputProfile = nsnull; static qcms_profile *gCMSOutputProfile = nsnull;
static qcms_profile *gCMSsRGBProfile = nsnull; static qcms_profile *gCMSsRGBProfile = nsnull;
@ -764,3 +766,10 @@ static void MigratePrefs()
} }
} }
void
gfxPlatform::InitDisplayCaps()
{
// Fall back to something sane
gfxPlatform::sDPI = 96;
}

View file

@ -91,7 +91,13 @@
#include FT_FREETYPE_H #include FT_FREETYPE_H
#endif #endif
double gfxPlatformGtk::sDPI = -1.0; #ifdef MOZ_PLATFORM_HILDON
#include "nsCOMPtr.h"
#include "nsILocalFile.h"
#include "nsILineInputStream.h"
#include "nsNetUtil.h"
#endif
gfxFontconfigUtils *gfxPlatformGtk::sFontconfigUtils = nsnull; gfxFontconfigUtils *gfxPlatformGtk::sFontconfigUtils = nsnull;
#ifndef MOZ_PANGO #ifndef MOZ_PANGO
@ -128,8 +134,6 @@ gfxPlatformGtk::gfxPlatformGtk()
gCodepointsWithNoFonts = new gfxSparseBitSet(); gCodepointsWithNoFonts = new gfxSparseBitSet();
UpdateFontList(); UpdateFontList();
#endif #endif
InitDPI();
} }
gfxPlatformGtk::~gfxPlatformGtk() gfxPlatformGtk::~gfxPlatformGtk()
@ -523,16 +527,46 @@ gfxPlatformGtk::CreateFontGroup(const nsAString &aFamilies,
#endif #endif
/* static */
void void
gfxPlatformGtk::InitDPI() gfxPlatformGtk::InitDisplayCaps()
{ {
sDPI = gdk_screen_get_resolution(gdk_screen_get_default()); #if defined(MOZ_PLATFORM_HILDON)
// Check the cached value
if (gfxPlatform::sDPI == -1) {
nsresult rv;
nsCOMPtr<nsILocalFile> file;
rv = NS_NewLocalFile(NS_LITERAL_STRING("/proc/component_version"),
PR_TRUE, getter_AddRefs(file));
if (NS_SUCCEEDED(rv)) {
nsCOMPtr<nsIInputStream> fileStream;
NS_NewLocalFileInputStream(getter_AddRefs(fileStream), file);
nsCOMPtr<nsILineInputStream> lineStream = do_QueryInterface(fileStream);
// Extract the product code from the component_version file
nsCAutoString buffer;
PRBool isMore = PR_TRUE;
if (NS_SUCCEEDED(lineStream->ReadLine(buffer, &isMore))) {
if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-51"))) {
gfxPlatform::sDPI = 265; // It's an N900
}
else if (StringEndsWith(buffer, NS_LITERAL_CSTRING("RX-48"))) {
gfxPlatform::sDPI = 225; // It's an N810
}
}
}
}
#else
GdkScreen *screen = gdk_screen_get_default();
gtk_settings_get_for_screen(screen); // Make sure init is run so we have a resolution
gfxPlatform::sDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
#endif
if (sDPI <= 0.0) { if (gfxPlatform::sDPI <= 0.0) {
// Fall back to something sane // Fall back to something sane
sDPI = 96.0; gfxPlatform::sDPI = 96.0;
} else {
// Minimum DPI is 96
gfxPlatform::sDPI = PR_MAX(sDPI, 96);
} }
} }

View file

@ -64,7 +64,6 @@
#include <ft2build.h> #include <ft2build.h>
#include FT_FREETYPE_H #include FT_FREETYPE_H
PRInt32 gfxQtPlatform::sDPI = -1;
gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull; gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nsnull;
static cairo_user_data_key_t cairo_qt_pixmap_key; static cairo_user_data_key_t cairo_qt_pixmap_key;
static void do_qt_pixmap_unref (void *data) static void do_qt_pixmap_unref (void *data)
@ -98,8 +97,6 @@ gfxQtPlatform::gfxQtPlatform()
gPrefFonts->Init(100); gPrefFonts->Init(100);
gCodepointsWithNoFonts = new gfxSparseBitSet(); gCodepointsWithNoFonts = new gfxSparseBitSet();
UpdateFontList(); UpdateFontList();
InitDPI();
} }
gfxQtPlatform::~gfxQtPlatform() gfxQtPlatform::~gfxQtPlatform()
@ -354,23 +351,12 @@ gfxQtPlatform::CreateFontGroup(const nsAString &aFamilies,
return new gfxFT2FontGroup(aFamilies, aStyle); return new gfxFT2FontGroup(aFamilies, aStyle);
} }
/* static */
void
gfxQtPlatform::InitDPI()
{
if (sDPI <= 0) {
// Fall back to something sane
sDPI = 96;
}
}
qcms_profile* qcms_profile*
gfxQtPlatform::GetPlatformCMSOutputProfile() gfxQtPlatform::GetPlatformCMSOutputProfile()
{ {
return nsnull; return nsnull;
} }
FT_Library FT_Library
gfxQtPlatform::GetFTLibrary() gfxQtPlatform::GetFTLibrary()
{ {

View file

@ -981,3 +981,14 @@ gfxWindowsPlatform::GetFTLibrary()
return gPlatformFTLibrary; return gPlatformFTLibrary;
} }
#endif #endif
void
gfxWindowsPlatform::InitDisplayCaps()
{
HDC dc = GetDC((HWND)nsnull);
gfxPlatform::sDPI = GetDeviceCaps(dc, LOGPIXELSY);
ReleaseDC((HWND)nsnull, dc);
}