зеркало из https://github.com/mozilla/pjs.git
r=pedemont, sr=blizzard, a=rjesup@wgate.com OS/2 only - Don't scale fonts based on DPI value in prefs just use it to update the values in nsDevice Context the magic will happen
This commit is contained in:
Родитель
cd08ec22af
Коммит
2e6967b628
|
@ -35,6 +35,7 @@
|
|||
#include "nsHashTable.h" // For CreateFontAliasTable()
|
||||
|
||||
#include "nsGfxDefs.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
// Size of the color cube
|
||||
#define COLOR_CUBE_SIZE 216
|
||||
|
@ -43,6 +44,7 @@
|
|||
static PRBool gIsWarp4 = NOT_SETUP;
|
||||
|
||||
PRUint32 nsDeviceContextOS2::sNumberOfScreens = 0;
|
||||
nscoord nsDeviceContextOS2::mDpi = 120;
|
||||
|
||||
nsDeviceContextOS2 :: nsDeviceContextOS2()
|
||||
: DeviceContextImpl()
|
||||
|
@ -81,8 +83,14 @@ nsDeviceContextOS2::~nsDeviceContextOS2()
|
|||
{
|
||||
GFX (::GpiDestroyPS (mPrintPS), FALSE);
|
||||
::DevCloseDC(mPrintDC);
|
||||
} else {
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIPref> prefs = do_GetService(NS_PREF_CONTRACTID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
prefs->UnregisterCallback("browser.display.screen_resolution",
|
||||
prefChanged, (void *)this);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mSpec);
|
||||
}
|
||||
|
||||
|
@ -92,6 +100,35 @@ nsresult nsDeviceContextOS2::Init( nsNativeWidget aWidget)
|
|||
|
||||
CommonInit(::WinOpenWindowDC((HWND)aWidget));
|
||||
|
||||
static int initialized = 0;
|
||||
PRInt32 prefVal = -1;
|
||||
if (!initialized) {
|
||||
initialized = 1;
|
||||
|
||||
// Set prefVal the value of the preference
|
||||
// "browser.display.screen_resolution"
|
||||
// or -1 if we can't get it.
|
||||
// If it's negative, we pretend it's not set.
|
||||
// If it's 0, it means force use of the operating system's logical
|
||||
// resolution.
|
||||
// If it's positive, we use it as the logical resolution
|
||||
nsresult res;
|
||||
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &res));
|
||||
if (NS_SUCCEEDED(res) && prefs) {
|
||||
res = prefs->GetIntPref("browser.display.screen_resolution", &prefVal);
|
||||
if (NS_FAILED(res)) {
|
||||
prefVal = -1;
|
||||
}
|
||||
prefs->RegisterCallback("browser.display.screen_resolution", prefChanged,
|
||||
(void *)this);
|
||||
}
|
||||
|
||||
SetDPI(prefVal);
|
||||
} else {
|
||||
SetDPI(mDpi); // to setup p2t and t2p
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -119,6 +156,8 @@ nsresult nsDeviceContextOS2::Init( nsNativeDeviceContext aContext,
|
|||
|
||||
CommonInit( mPrintDC);
|
||||
|
||||
SetDPI(0);
|
||||
|
||||
GetTwipsToDevUnits( newscale);
|
||||
|
||||
// On OS/2, origscale can be different based on the video resolution.
|
||||
|
@ -158,10 +197,6 @@ void nsDeviceContextOS2 :: CommonInit(HDC aDC)
|
|||
|
||||
GFX (::DevQueryCaps(aDC, CAPS_FAMILY, CAPS_DEVICE_POLYSET_POINTS, alArray), FALSE);
|
||||
|
||||
mTwipsToPixels = ((float)alArray [CAPS_VERTICAL_FONT_RES]) / (float)NSIntPointsToTwips(72);
|
||||
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
|
||||
mDepth = alArray[CAPS_COLOR_BITCOUNT];
|
||||
#ifdef COLOR_256
|
||||
mPaletteInfo.isPaletteDevice = !!(alArray[CAPS_ADDITIONAL_GRAPHICS] & CAPS_PALETTE_MANAGER);
|
||||
|
@ -565,6 +600,55 @@ NS_IMETHODIMP nsDeviceContextOS2::GetDepth(PRUint32& aDepth)
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDeviceContextOS2::SetDPI(PRInt32 aPrefDPI)
|
||||
{
|
||||
// Set OSVal to what the operating system thinks the logical resolution is.
|
||||
long OSVal;
|
||||
HPS ps = ::WinGetScreenPS(HWND_DESKTOP);
|
||||
HDC hdc = GFX (::GpiQueryDevice (ps), HDC_ERROR);
|
||||
GFX (::DevQueryCaps(hdc, CAPS_HORIZONTAL_FONT_RES, 1, &OSVal), FALSE);
|
||||
::WinReleasePS(ps);
|
||||
|
||||
if ((aPrefDPI == 0) || (mPrintDC)) {
|
||||
// If the pref is 0 or we are printing force use of OS value
|
||||
mDpi = OSVal;
|
||||
} else if (aPrefDPI > 0) {
|
||||
// If there's a valid pref value for the logical resolution,
|
||||
// use it.
|
||||
mDpi = aPrefDPI;
|
||||
} else {
|
||||
// if we couldn't get the pref or it's negative then use 120
|
||||
mDpi = 120;
|
||||
}
|
||||
|
||||
int pt2t = 72;
|
||||
|
||||
// make p2t a nice round number - this prevents rounding problems
|
||||
mPixelsToTwips = float(NSToIntRound(float(NSIntPointsToTwips(pt2t)) / float(mDpi)));
|
||||
mTwipsToPixels = 1.0f / mPixelsToTwips;
|
||||
|
||||
// XXX need to reflow all documents
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
int prefChanged(const char *aPref, void *aClosure)
|
||||
{
|
||||
nsDeviceContextOS2 *context = (nsDeviceContextOS2*)aClosure;
|
||||
nsresult rv;
|
||||
|
||||
if (nsCRT::strcmp(aPref, "browser.display.screen_resolution")==0) {
|
||||
PRInt32 dpi;
|
||||
nsCOMPtr<nsIPref> prefs(do_GetService(NS_PREF_CONTRACTID, &rv));
|
||||
rv = prefs->GetIntPref(aPref, &dpi);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
context->SetDPI(dpi);
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef COLOR_256
|
||||
NS_IMETHODIMP nsDeviceContextOS2::GetILColorSpace(IL_ColorSpace*& aColorSpace)
|
||||
{
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
|
||||
|
||||
#ifdef COLOR_256
|
||||
NS_IMETHOD GetILColorSpace(IL_ColorSpace*& aColorSpace);
|
||||
|
||||
|
@ -97,6 +98,7 @@ public:
|
|||
|
||||
// Static Helper Methods
|
||||
static char* GetACPString(const nsString& aStr);
|
||||
nsresult SetDPI(PRInt32 aPrefDPI);
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextOS2();
|
||||
|
@ -123,6 +125,7 @@ protected:
|
|||
|
||||
nsCOMPtr<nsIScreenManager> mScreenManager;
|
||||
static PRUint32 sNumberOfScreens;
|
||||
static nscoord mDpi;
|
||||
|
||||
public:
|
||||
HDC mPrintDC;
|
||||
|
@ -141,4 +144,6 @@ public:
|
|||
nsresult nsDeviceContextOS2::CreateFontAliasTable();
|
||||
};
|
||||
|
||||
static int PR_CALLBACK prefChanged(const char *aPref, void *aClosure);
|
||||
|
||||
#endif /* nsDeviceContextOS2_h___ */
|
||||
|
|
|
@ -68,7 +68,6 @@ static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
|
|||
nsVoidArray *nsFontMetricsOS2::gGlobalFonts = nsnull;
|
||||
PRBool nsFontMetricsOS2::gSubstituteVectorFonts = PR_TRUE;
|
||||
PLHashTable *nsFontMetricsOS2::gFamilyNames = nsnull;
|
||||
nscoord nsFontMetricsOS2::gDPI = 0;
|
||||
long nsFontMetricsOS2::gSystemRes = 0;
|
||||
int nsFontMetricsOS2::gCachedIndex = 0;
|
||||
nsICollation *nsFontMetricsOS2::gCollation = nsnull;
|
||||
|
@ -249,31 +248,12 @@ nsFontOS2::DrawString( HPS aPS, nsDrawingSurfaceOS2* aSurface,
|
|||
/**********************************************************
|
||||
nsFontMetricsOS2
|
||||
**********************************************************/
|
||||
int PR_CALLBACK
|
||||
prefChanged(const char *aPref, void *aClosure)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if( PL_strcmp(aPref, "browser.display.screen_resolution") == 0 )
|
||||
{
|
||||
PRInt32 dpi;
|
||||
rv = gPref->GetIntPref( aPref, &dpi );
|
||||
if( NS_SUCCEEDED(rv) && dpi != 0)
|
||||
nsFontMetricsOS2::gDPI = dpi;
|
||||
else
|
||||
nsFontMetricsOS2::gDPI = nsFontMetricsOS2::gSystemRes;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
FreeGlobals(void)
|
||||
{
|
||||
gInitialized = 0;
|
||||
|
||||
gPref->UnregisterCallback( "browser.display.screen_resolution", prefChanged, NULL );
|
||||
|
||||
#ifdef WINCODE
|
||||
NS_IF_RELEASE(gCharsetManager);
|
||||
#endif
|
||||
|
@ -423,25 +403,6 @@ InitGlobals(void)
|
|||
}
|
||||
}
|
||||
|
||||
// Set prefVal the value of the pref "browser.display.screen_resolution"
|
||||
// When a new profile is created, the pref is set to 0. This tells the code
|
||||
// to default to font resolution of the screen (96 or 120)
|
||||
nsresult res;
|
||||
PRInt32 prefVal = -1;
|
||||
|
||||
res = gPref->GetIntPref( "browser.display.screen_resolution", &prefVal );
|
||||
if (NS_FAILED(res))
|
||||
prefVal = 0;
|
||||
|
||||
gPref->RegisterCallback( "browser.display.screen_resolution", prefChanged, NULL );
|
||||
|
||||
if (prefVal == 0)
|
||||
{
|
||||
prefVal = nsFontMetricsOS2::gSystemRes;
|
||||
}
|
||||
|
||||
nsFontMetricsOS2::gDPI = prefVal;
|
||||
|
||||
//register an observer to take care of cleanup
|
||||
gFontCleanupObserver = new nsFontCleanupObserver();
|
||||
NS_ASSERTION(gFontCleanupObserver, "failed to create observer");
|
||||
|
@ -568,7 +529,7 @@ nsFontMetricsOS2::SetFontHandle( HPS aPS, nsFontOS2* aFont )
|
|||
// points size is less than the minimum or more than the maximum point
|
||||
// size available for Tms Rmn and Helv.
|
||||
if( gSubstituteVectorFonts &&
|
||||
(points > 18 || points < 8 || (gDPI != 96 && gDPI != 120)) &&
|
||||
(points > 18 || points < 8) &&
|
||||
GetVectorSubstitute( aPS, fattrs->szFacename, alias ))
|
||||
{
|
||||
PL_strcpy( fattrs->szFacename, alias );
|
||||
|
@ -650,11 +611,9 @@ nsFontMetricsOS2::SetFontHandle( HPS aPS, nsFontOS2* aFont )
|
|||
float app2dev, fHeight;
|
||||
mDeviceContext->GetAppUnitsToDevUnits( app2dev );
|
||||
|
||||
if( !mDeviceContext->mPrintDC ) /* if not printing */
|
||||
if( fattrs->fsFontUse == 0 ) /* if image font */
|
||||
fHeight = points * gDPI / 72;
|
||||
else
|
||||
fHeight = mFont.size * app2dev * gDPI / nsFontMetricsOS2::gSystemRes;
|
||||
/* if image font and not printing */
|
||||
if ((fattrs->fsFontUse == 0) && (!mDeviceContext->mPrintDC))
|
||||
fHeight = NSIntPointsToTwips(points) * app2dev;
|
||||
else
|
||||
fHeight = mFont.size * app2dev;
|
||||
|
||||
|
|
|
@ -198,7 +198,6 @@ class nsFontMetricsOS2 : public nsIFontMetrics
|
|||
|
||||
static nsVoidArray* gGlobalFonts;
|
||||
static PLHashTable* gFamilyNames;
|
||||
static nscoord gDPI;
|
||||
static long gSystemRes;
|
||||
static nsICollation* gCollation;
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче