From 63ef3f269bbefc998f6bb3151681568d628db0dd Mon Sep 17 00:00:00 2001 From: "timeless%mac.com" Date: Thu, 9 Aug 2001 08:08:39 +0000 Subject: [PATCH] fix Bugzilla Bug 81311 nsFontCache cannot be shared between multiple toolkits by Roland.Mainz@informatik.med.uni-giessen.de r=dbaron sr=blizzard git-svn-id: svn://10.0.0.236/trunk@100649 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/public/nsDeviceContext.h | 32 ++++- mozilla/gfx/src/nsDeviceContext.cpp | 62 ++++----- mozilla/gfx/src/ps/nsDeviceContextPS.cpp | 95 ++++---------- mozilla/gfx/src/ps/nsDeviceContextPS.h | 38 +++--- mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp | 32 +++++ mozilla/gfx/src/xlib/nsDeviceContextXlib.h | 18 ++- mozilla/gfx/src/xprint/nsDeviceContextXP.cpp | 123 +++++++----------- mozilla/gfx/src/xprint/nsDeviceContextXP.h | 7 +- .../gfx/src/xprint/nsIDeviceContextXPrint.h | 7 +- 9 files changed, 192 insertions(+), 222 deletions(-) diff --git a/mozilla/gfx/public/nsDeviceContext.h b/mozilla/gfx/public/nsDeviceContext.h index 5eb68a2d0c1..2463566eba7 100644 --- a/mozilla/gfx/public/nsDeviceContext.h +++ b/mozilla/gfx/public/nsDeviceContext.h @@ -17,7 +17,8 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Roland Mainz */ #ifndef nsDeviceContext_h___ @@ -29,11 +30,33 @@ #include "nsCOMPtr.h" #include "nsIAtom.h" #include "nsIStringBundle.h" - +#include "nsVoidArray.h" class nsIImageRequest; class nsHashtable; -class nsFontCache; + +class nsFontCache +{ +public: + nsFontCache(); + ~nsFontCache(); + + nsresult Init(nsIDeviceContext* aContext); + nsresult GetDeviceContext(nsIDeviceContext *&aContext) const; + nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, + nsIFontMetrics *&aMetrics); + nsresult Flush(); + /* printer device context classes may create their own + * subclasses of nsFontCache (and override this method) and override + * DeviceContextImpl::CreateFontCache (see bug 81311). + */ + NS_IMETHOD CreateFontMetricsInstance(nsIFontMetrics** fm); + +protected: + nsVoidArray mFontMetrics; + nsIDeviceContext *mContext; // we do not addref this since + // ownership is implied. MMP. +}; class NS_GFX DeviceContextImpl : public nsIDeviceContext { @@ -83,6 +106,8 @@ public: NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName, PRBool& aAliased); + NS_IMETHOD CreateFontCache(); + NS_IMETHOD FlushFontCache(void); NS_IMETHOD GetDepth(PRUint32& aDepth); @@ -98,7 +123,6 @@ protected: virtual ~DeviceContextImpl(); void CommonInit(void); - nsresult CreateFontCache(); void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma); nsresult CreateIconILGroupContext(); virtual nsresult CreateFontAliasTable(); diff --git a/mozilla/gfx/src/nsDeviceContext.cpp b/mozilla/gfx/src/nsDeviceContext.cpp index 8e5abb12d0f..39155d4d75a 100644 --- a/mozilla/gfx/src/nsDeviceContext.cpp +++ b/mozilla/gfx/src/nsDeviceContext.cpp @@ -18,6 +18,8 @@ * Rights Reserved. * * Contributor(s): + * Roland Mainz + * * This Original Code has been modified by IBM Corporation. Modifications made by IBM * described herein are Copyright (c) International Business Machines Corporation, 2000. * Modifications to Mozilla code or documentation identified per MPL Section 3.3 @@ -34,7 +36,6 @@ #include "nsImageRequest.h" #include "nsIImageGroup.h" #include "il_util.h" -#include "nsVoidArray.h" #include "nsIFontMetrics.h" #include "nsHashtable.h" #include "nsILanguageAtomService.h" @@ -54,25 +55,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); // done I10N -class nsFontCache -{ -public: - nsFontCache(); - ~nsFontCache(); - - nsresult Init(nsIDeviceContext* aContext); - nsresult GetDeviceContext(nsIDeviceContext *&aContext) const; - nsresult GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, - nsIFontMetrics *&aMetrics); - nsresult Flush(); - -protected: - nsVoidArray mFontMetrics; - nsIDeviceContext *mContext; //we do not addref this since - //ownership is implied. MMP. -}; - - NS_IMPL_ISUPPORTS1(DeviceContextImpl, nsIDeviceContext) DeviceContextImpl :: DeviceContextImpl() @@ -242,7 +224,7 @@ NS_IMETHODIMP DeviceContextImpl :: InitRenderingContext(nsIRenderingContext *aCo return aContext->Init(this, aWin); } -nsresult DeviceContextImpl::CreateFontCache() +NS_IMETHODIMP DeviceContextImpl::CreateFontCache() { mFontCache = new nsFontCache(); if (nsnull == mFontCache) { @@ -306,9 +288,7 @@ NS_IMETHODIMP DeviceContextImpl :: SetZoom(float aZoom) { if (mZoom != aZoom) { mZoom = aZoom; - if (mFontCache) { - mFontCache->Flush(); - } + FlushFontCache(); } return NS_OK; } @@ -323,9 +303,7 @@ NS_IMETHODIMP DeviceContextImpl :: SetTextZoom(float aTextZoom) { if (mTextZoom != aTextZoom) { mTextZoom = aTextZoom; - if (mFontCache) { - mFontCache->Flush(); - } + FlushFontCache(); } return NS_OK; } @@ -761,7 +739,8 @@ nsFontCache :: ~nsFontCache() Flush(); } -nsresult nsFontCache :: Init(nsIDeviceContext* aContext) +NS_IMETHODIMP +nsFontCache :: Init(nsIDeviceContext* aContext) { NS_PRECONDITION(nsnull != aContext, "null ptr"); // Note: we don't hold a reference to the device context, because it @@ -770,14 +749,16 @@ nsresult nsFontCache :: Init(nsIDeviceContext* aContext) return NS_OK; } -nsresult nsFontCache :: GetDeviceContext(nsIDeviceContext *&aContext) const +NS_IMETHODIMP +nsFontCache :: GetDeviceContext(nsIDeviceContext *&aContext) const { NS_IF_ADDREF(mContext); aContext = mContext; return NS_OK; } -nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, +NS_IMETHODIMP +nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics *&aMetrics) { // First check our cache @@ -808,19 +789,17 @@ nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, // It's not in the cache. Get font metrics and then cache them. - static NS_DEFINE_CID(kFontMetricsCID, NS_FONT_METRICS_CID); + nsIFontMetrics *fm = nsnull; + nsresult rv = CreateFontMetricsInstance(&fm); - nsIFontMetrics* fm; - nsresult rv = nsComponentManager::CreateInstance(kFontMetricsCID, nsnull, - NS_GET_IID(nsIFontMetrics), (void **)&fm); - if (NS_OK != rv) { + if (NS_FAILED(rv)) { aMetrics = nsnull; return rv; } rv = fm->Init(aFont, aLangGroup, mContext); - if (NS_OK != rv) { + if (NS_FAILED(rv)) { aMetrics = nsnull; return rv; } @@ -832,6 +811,17 @@ nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, return NS_OK; } +/* PostScript and Xprint module may override this method to create + * nsIFontMetrics objects with their own classes + */ +NS_IMETHODIMP +nsFontCache::CreateFontMetricsInstance(nsIFontMetrics** fm) +{ + static NS_DEFINE_CID(kFontMetricsCID, NS_FONT_METRICS_CID); + return CallCreateInstance(kFontMetricsCID, fm); +} + + nsresult nsFontCache :: Flush() { PRInt32 i, n = mFontMetrics.Count(); diff --git a/mozilla/gfx/src/ps/nsDeviceContextPS.cpp b/mozilla/gfx/src/ps/nsDeviceContextPS.cpp index f590e2577db..48d36757654 100644 --- a/mozilla/gfx/src/ps/nsDeviceContextPS.cpp +++ b/mozilla/gfx/src/ps/nsDeviceContextPS.cpp @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Roland Mainz */ #include "nsDeviceContextPS.h" @@ -36,7 +37,6 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID); */ nsDeviceContextPS :: nsDeviceContextPS() { - NS_INIT_REFCNT(); mSpec = nsnull; mParentDeviceContext = nsnull; @@ -48,19 +48,8 @@ nsDeviceContextPS :: nsDeviceContextPS() */ nsDeviceContextPS :: ~nsDeviceContextPS() { -PRInt32 i, n; - - // get rid of the fonts in our mFontMetrics cache - n= mFontMetrics.Count(); - for (i = 0; i < n; i++){ - nsIFontMetrics* fm = (nsIFontMetrics*) mFontMetrics.ElementAt(i); - fm->Destroy(); - NS_RELEASE(fm); - } - mFontMetrics.Clear(); NS_IF_RELEASE(mSpec); NS_IF_RELEASE(mParentDeviceContext); - } NS_IMETHODIMP @@ -359,64 +348,34 @@ NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixe return NS_OK; } -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - * @update 12/21/98 dwc - */ -NS_IMETHODIMP nsDeviceContextPS::GetMetricsFor(const nsFont& aFont, nsIFontMetrics *&aMetrics) +class nsFontCachePS : public nsFontCache { - GetLocaleLangGroup(); - return GetMetricsFor(aFont, mLocaleLangGroup, aMetrics); -} +public: + /* override DeviceContextImpl::CreateFontCache() */ + NS_IMETHODIMP CreateFontMetricsInstance(nsIFontMetrics** aResult); +}; -NS_IMETHODIMP nsDeviceContextPS::GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics *&aMetrics) + +NS_IMETHODIMP nsFontCachePS::CreateFontMetricsInstance(nsIFontMetrics** aResult) { -PRInt32 n,cnt; -nsresult rv; - - // First check our cache - n = mFontMetrics.Count(); - - for (cnt = 0; cnt < n; cnt++) - { - aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt); - - const nsFont* font; - aMetrics->GetFont(font); - nsCOMPtr langGroup; - aMetrics->GetLangGroup(getter_AddRefs(langGroup)); - if (aFont.Equals(*font) && (aLangGroup == langGroup.get())) - { - NS_ADDREF(aMetrics); - return NS_OK; - } - } - - // It's not in the cache. Get font metrics and then cache them. - nsIFontMetrics* fm = new nsFontMetricsPS(); - if (nsnull == fm) { - aMetrics = nsnull; - return NS_ERROR_FAILURE; - } - - rv = fm->Init(aFont, aLangGroup, this); - - if (NS_OK != rv) { - aMetrics = nsnull; - return rv; - } - - mFontMetrics.AppendElement(fm); - NS_ADDREF(fm); // this is for the cache - - - for (cnt = 0; cnt < n; cnt++){ - aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt); - const nsFont *font; - aMetrics->GetFont(font); - } - - NS_ADDREF(fm); // this is for the routine that needs this font - aMetrics = fm; + NS_PRECONDITION(aResult, "null out param"); + nsIFontMetrics *fm = new nsFontMetricsPS(); + if (!fm) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(fm); + *aResult = fm; return NS_OK; } + +/* override DeviceContextImpl::CreateFontCache() */ +NS_IMETHODIMP nsDeviceContextPS::CreateFontCache() +{ + mFontCache = new nsFontCachePS(); + if (nsnull == mFontCache) { + return NS_ERROR_OUT_OF_MEMORY; + } + mFontCache->Init(this); + return NS_OK; +} + + diff --git a/mozilla/gfx/src/ps/nsDeviceContextPS.h b/mozilla/gfx/src/ps/nsDeviceContextPS.h index 926495e10cf..134249b3d3a 100644 --- a/mozilla/gfx/src/ps/nsDeviceContextPS.h +++ b/mozilla/gfx/src/ps/nsDeviceContextPS.h @@ -18,6 +18,7 @@ * Rights Reserved. * * Contributor(s): + * Roland Mainz */ #ifndef nsDeviceContextPS_h___ @@ -40,7 +41,7 @@ class nsDeviceContextPS : public DeviceContextImpl, public: nsDeviceContextPS(); - NS_DECL_ISUPPORTS_INHERITED + NS_DECL_ISUPPORTS_INHERITED /** * This method does nothing since a postscript devicecontext will never be created @@ -58,39 +59,36 @@ public: NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const; - void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; } + void SetDrawingSurface(nsDrawingSurface aSurface) { mSurface = aSurface; } NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface); - NS_IMETHOD CheckFontExistence(const nsString& aFontName); + NS_IMETHOD CheckFontExistence(const nsString& aFontName); NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace); - NS_IMETHOD GetDepth(PRUint32& aDepth); - NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel); + NS_IMETHOD GetDepth(PRUint32& aDepth); + NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel); - NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight); - NS_IMETHOD GetClientRect(nsRect &aRect); - NS_IMETHOD GetRect(nsRect &aRect); + NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight); + NS_IMETHOD GetClientRect(nsRect &aRect); + NS_IMETHOD GetRect(nsRect &aRect); - NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext); + NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,nsIDeviceContext *&aContext); NS_IMETHOD GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const; - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics*& aMetrics); - NS_IMETHOD BeginDocument(PRUnichar * aTitle); - NS_IMETHOD EndDocument(void); - NS_IMETHOD BeginPage(void); - NS_IMETHOD EndPage(void); - + NS_IMETHOD BeginDocument(PRUnichar * aTitle); + NS_IMETHOD EndDocument(void); + NS_IMETHOD BeginPage(void); + NS_IMETHOD EndPage(void); + NS_IMETHOD CreateFontCache(); NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec); protected: - virtual ~nsDeviceContextPS(); + virtual ~nsDeviceContextPS(); - nsDrawingSurface mSurface; - PRUint32 mDepth; + nsDrawingSurface mSurface; + PRUint32 mDepth; nsIDeviceContextSpec *mSpec; nsIDeviceContext *mParentDeviceContext; - nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript. nsPostScriptObj *mPSObj; public: diff --git a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp b/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp index 45e7b7084d8..ae0730c66b7 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp +++ b/mozilla/gfx/src/xlib/nsDeviceContextXlib.cpp @@ -509,3 +509,35 @@ NS_IMETHODIMP nsDeviceContextXlib::EndPage(void) PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n")); return NS_OK; } + +class nsFontCacheXlib : public nsFontCache +{ +public: + /* override DeviceContextImpl::CreateFontCache() */ + NS_IMETHODIMP CreateFontMetricsInstance(nsIFontMetrics** aResult); +}; + + +NS_IMETHODIMP nsFontCacheXlib::CreateFontMetricsInstance(nsIFontMetrics** aResult) +{ + NS_PRECONDITION(aResult, "null out param"); + nsIFontMetrics *fm = new nsFontMetricsXlib(); + if (!fm) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(fm); + *aResult = fm; + return NS_OK; +} + +/* override DeviceContextImpl::CreateFontCache() */ +NS_IMETHODIMP nsDeviceContextXlib::CreateFontCache() +{ + mFontCache = new nsFontCacheXlib(); + if (nsnull == mFontCache) { + return NS_ERROR_OUT_OF_MEMORY; + } + mFontCache->Init(this); + return NS_OK; +} + + diff --git a/mozilla/gfx/src/xlib/nsDeviceContextXlib.h b/mozilla/gfx/src/xlib/nsDeviceContextXlib.h index e772c49b23a..6b1a36760cf 100644 --- a/mozilla/gfx/src/xlib/nsDeviceContextXlib.h +++ b/mozilla/gfx/src/xlib/nsDeviceContextXlib.h @@ -18,7 +18,8 @@ * Rights Reserved. * * Contributor(s): - * David Smith + * David Smith + * Roland Mainz */ #ifndef nsDeviceContextXlib_h__ @@ -64,11 +65,13 @@ public: NS_IMETHOD BeginPage(void); NS_IMETHOD EndPage(void); - Display * GetDisplay() { return mDisplay; } - Screen * GetScreen() { return mScreen; } - Visual * GetVisual() { return mVisual; } - int GetDepth() { return mDepth; } - NS_IMETHOD GetDepth( PRUint32 &depth ) { depth=(PRUint32)mDepth;return NS_OK; } + NS_IMETHOD CreateFontCache(); + + Display *GetDisplay() { return mDisplay; } + Screen *GetScreen() { return mScreen; } + Visual *GetVisual() { return mVisual; } + int GetDepth() { return mDepth; } + NS_IMETHOD GetDepth( PRUint32 &depth ) { depth=(PRUint32)mDepth;return NS_OK; } protected: @@ -91,4 +94,5 @@ private: PRInt32 mHeight; }; -#endif +#endif /* !nsDeviceContextXlib_h__ */ + diff --git a/mozilla/gfx/src/xprint/nsDeviceContextXP.cpp b/mozilla/gfx/src/xprint/nsDeviceContextXP.cpp index 7f43da8fc63..4c03db4f3e6 100644 --- a/mozilla/gfx/src/xprint/nsDeviceContextXP.cpp +++ b/mozilla/gfx/src/xprint/nsDeviceContextXP.cpp @@ -18,9 +18,8 @@ * Rights Reserved. * * Contributor(s): - * Roland Mainz - * Bradley Baetz - * + * Roland Mainz + * Bradley Baetz */ #include @@ -55,8 +54,6 @@ nsDeviceContextXp :: nsDeviceContextXp() mPrintContext = nsnull; mSpec = nsnull; mParentDeviceContext = nsnull; - - NS_NewISupportsArray(getter_AddRefs(mFontMetrics)); } /** --------------------------------------------------- @@ -325,19 +322,19 @@ NS_IMETHODIMP nsDeviceContextXp::EndDocument(void) PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::EndDocument()\n")); nsresult rv = NS_OK; if (mPrintContext != nsnull) { - rv = mPrintContext->EndDocument(); - - // gisburn: mPrintContext cannot be reused between to print - // tasks as the destination print server may be a different one - // or the printer used on the same print server has other - // properties (build-in fonts for example ) than the printer - // previously used - mFontMetrics = nsnull; /* nsCOMPtr will release/free all objects */ - nsRenderingContextXlib::Shutdown(); - nsFontMetricsXlib::FreeGlobals(); - - delete mPrintContext; - mPrintContext = nsnull; + rv = mPrintContext->EndDocument(); + + // gisburn: mPrintContext cannot be reused between to print + // tasks as the destination print server may be a different one + // or the printer used on the same print server has other + // properties (build-in fonts for example ) than the printer + // previously used + FlushFontCache(); + nsRenderingContextXlib::Shutdown(); + nsFontMetricsXlib::FreeGlobals(); + + delete mPrintContext; + mPrintContext = nsnull; } return rv; @@ -402,68 +399,40 @@ NS_IMETHODIMP nsDeviceContextXp::GetDepth(PRUint32& aDepth) return NS_OK; } -/** --------------------------------------------------- - * See documentation in nsIDeviceContext.h - */ -NS_IMETHODIMP nsDeviceContextXp::GetMetricsFor(const nsFont& aFont, - nsIAtom* aLangGroup, nsIFontMetrics *&aMetrics) -{ - return GetMetricsFor(aFont, aMetrics); -} - -NS_IMETHODIMP nsDeviceContextXp::GetMetricsFor(const nsFont& aFont, - nsIFontMetrics *&aMetrics) -{ - PRUint32 n, cnt; - nsresult rv; - - // First check our cache - rv = mFontMetrics->Count(&n); - if (NS_FAILED(rv)) - return rv; - - nsCOMPtr m; - - for (cnt = 0; cnt < n; cnt++) { - if (NS_SUCCEEDED(mFontMetrics->QueryElementAt(cnt, - NS_GET_IID(nsIFontMetrics), - getter_AddRefs(m)))) { - const nsFont* font; - m->GetFont(font); - if (aFont.Equals(*font)) { - aMetrics = m; - NS_ADDREF(aMetrics); - return NS_OK; - } - } - } - - // It's not in the cache. Get font metrics and then cache them. - nsCOMPtr fm = new nsFontMetricsXlib(); - if (!fm) { - aMetrics = nsnull; - return NS_ERROR_FAILURE; - } - - // XXX need to pass real lang group - rv = fm->Init(aFont, nsnull, this); - - if (NS_FAILED(rv)) { - aMetrics = nsnull; - return rv; - } - - mFontMetrics->AppendElement(fm); - - aMetrics = fm; - NS_ADDREF(aMetrics); - return NS_OK; -} - NS_IMETHODIMP nsDeviceContextXp::GetPrintContext(nsXPrintContext*& aContext) { aContext = mPrintContext; - //NS_ADDREF(aContext); return NS_OK; } +class nsFontCacheXp : public nsFontCache +{ +public: + /* override DeviceContextImpl::CreateFontCache() */ + NS_IMETHODIMP CreateFontMetricsInstance(nsIFontMetrics** aResult); +}; + + +NS_IMETHODIMP nsFontCacheXp::CreateFontMetricsInstance(nsIFontMetrics** aResult) +{ + NS_PRECONDITION(aResult, "null out param"); + nsIFontMetrics *fm = new nsFontMetricsXlib(); + if (!fm) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(fm); + *aResult = fm; + return NS_OK; +} + +/* override DeviceContextImpl::CreateFontCache() */ +NS_IMETHODIMP nsDeviceContextXp::CreateFontCache() +{ + mFontCache = new nsFontCacheXp(); + if (nsnull == mFontCache) { + return NS_ERROR_OUT_OF_MEMORY; + } + mFontCache->Init(this); + return NS_OK; +} + + diff --git a/mozilla/gfx/src/xprint/nsDeviceContextXP.h b/mozilla/gfx/src/xprint/nsDeviceContextXP.h index cc074330a7b..944783a86f3 100644 --- a/mozilla/gfx/src/xprint/nsDeviceContextXP.h +++ b/mozilla/gfx/src/xprint/nsDeviceContextXP.h @@ -18,7 +18,7 @@ * Rights Reserved. * * Contributor(s): - * Roland Mainz + * Roland Mainz */ #ifndef nsDeviceContextXp_h___ @@ -82,9 +82,7 @@ public: Display *GetDisplay(); NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext); - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, - nsIFontMetrics*& aMetrics); + NS_IMETHOD CreateFontCache(); protected: virtual ~nsDeviceContextXp(); @@ -93,7 +91,6 @@ protected: Display *mDisplay; Screen *mScreen; nsCOMPtr mSpec; - nsCOMPtr mFontMetrics; // we are not using the normal font cache nsIDeviceContext *mParentDeviceContext; }; diff --git a/mozilla/gfx/src/xprint/nsIDeviceContextXPrint.h b/mozilla/gfx/src/xprint/nsIDeviceContextXPrint.h index daf70572dd2..e7726f10cfc 100644 --- a/mozilla/gfx/src/xprint/nsIDeviceContextXPrint.h +++ b/mozilla/gfx/src/xprint/nsIDeviceContextXPrint.h @@ -17,7 +17,8 @@ * Copyright (C) 1998 Netscape Communications Corporation. All * Rights Reserved. * - * Contributor(s): + * Contributor(s): + * Roland Mainz */ #include "nsISupports.h" @@ -44,10 +45,6 @@ public: nsIDeviceContext *aPrinterContext) = 0; NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext) = 0; - - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics) = 0; - NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, - nsIFontMetrics*& aMetrics) = 0; };