fix Bugzilla Bug 81311 nsFontCache cannot be shared between multiple toolkits

by Roland.Mainz@informatik.med.uni-giessen.de r=dbaron sr=blizzard
This commit is contained in:
timeless%mac.com 2001-08-09 08:08:39 +00:00
Родитель 14f8f478f9
Коммит caa4e5ecea
9 изменённых файлов: 192 добавлений и 222 удалений

Просмотреть файл

@ -17,7 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All * Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
*/ */
#ifndef nsDeviceContext_h___ #ifndef nsDeviceContext_h___
@ -29,11 +30,33 @@
#include "nsCOMPtr.h" #include "nsCOMPtr.h"
#include "nsIAtom.h" #include "nsIAtom.h"
#include "nsIStringBundle.h" #include "nsIStringBundle.h"
#include "nsVoidArray.h"
class nsIImageRequest; class nsIImageRequest;
class nsHashtable; 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 class NS_GFX DeviceContextImpl : public nsIDeviceContext
{ {
@ -83,6 +106,8 @@ public:
NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName, NS_IMETHOD GetLocalFontName(const nsString& aFaceName, nsString& aLocalName,
PRBool& aAliased); PRBool& aAliased);
NS_IMETHOD CreateFontCache();
NS_IMETHOD FlushFontCache(void); NS_IMETHOD FlushFontCache(void);
NS_IMETHOD GetDepth(PRUint32& aDepth); NS_IMETHOD GetDepth(PRUint32& aDepth);
@ -98,7 +123,6 @@ protected:
virtual ~DeviceContextImpl(); virtual ~DeviceContextImpl();
void CommonInit(void); void CommonInit(void);
nsresult CreateFontCache();
void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma); void SetGammaTable(PRUint8 * aTable, float aCurrentGamma, float aNewGamma);
nsresult CreateIconILGroupContext(); nsresult CreateIconILGroupContext();
virtual nsresult CreateFontAliasTable(); virtual nsresult CreateFontAliasTable();

Просмотреть файл

@ -18,6 +18,8 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
*
* This Original Code has been modified by IBM Corporation. Modifications made by IBM * This Original Code has been modified by IBM Corporation. Modifications made by IBM
* described herein are Copyright (c) International Business Machines Corporation, 2000. * described herein are Copyright (c) International Business Machines Corporation, 2000.
* Modifications to Mozilla code or documentation identified per MPL Section 3.3 * Modifications to Mozilla code or documentation identified per MPL Section 3.3
@ -34,7 +36,6 @@
#include "nsImageRequest.h" #include "nsImageRequest.h"
#include "nsIImageGroup.h" #include "nsIImageGroup.h"
#include "il_util.h" #include "il_util.h"
#include "nsVoidArray.h"
#include "nsIFontMetrics.h" #include "nsIFontMetrics.h"
#include "nsHashtable.h" #include "nsHashtable.h"
#include "nsILanguageAtomService.h" #include "nsILanguageAtomService.h"
@ -54,25 +55,6 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID); static NS_DEFINE_CID(kStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
// done I10N // 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) NS_IMPL_ISUPPORTS1(DeviceContextImpl, nsIDeviceContext)
DeviceContextImpl :: DeviceContextImpl() DeviceContextImpl :: DeviceContextImpl()
@ -242,7 +224,7 @@ NS_IMETHODIMP DeviceContextImpl :: InitRenderingContext(nsIRenderingContext *aCo
return aContext->Init(this, aWin); return aContext->Init(this, aWin);
} }
nsresult DeviceContextImpl::CreateFontCache() NS_IMETHODIMP DeviceContextImpl::CreateFontCache()
{ {
mFontCache = new nsFontCache(); mFontCache = new nsFontCache();
if (nsnull == mFontCache) { if (nsnull == mFontCache) {
@ -306,9 +288,7 @@ NS_IMETHODIMP DeviceContextImpl :: SetZoom(float aZoom)
{ {
if (mZoom != aZoom) { if (mZoom != aZoom) {
mZoom = aZoom; mZoom = aZoom;
if (mFontCache) { FlushFontCache();
mFontCache->Flush();
}
} }
return NS_OK; return NS_OK;
} }
@ -323,9 +303,7 @@ NS_IMETHODIMP DeviceContextImpl :: SetTextZoom(float aTextZoom)
{ {
if (mTextZoom != aTextZoom) { if (mTextZoom != aTextZoom) {
mTextZoom = aTextZoom; mTextZoom = aTextZoom;
if (mFontCache) { FlushFontCache();
mFontCache->Flush();
}
} }
return NS_OK; return NS_OK;
} }
@ -761,7 +739,8 @@ nsFontCache :: ~nsFontCache()
Flush(); Flush();
} }
nsresult nsFontCache :: Init(nsIDeviceContext* aContext) NS_IMETHODIMP
nsFontCache :: Init(nsIDeviceContext* aContext)
{ {
NS_PRECONDITION(nsnull != aContext, "null ptr"); NS_PRECONDITION(nsnull != aContext, "null ptr");
// Note: we don't hold a reference to the device context, because it // 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; return NS_OK;
} }
nsresult nsFontCache :: GetDeviceContext(nsIDeviceContext *&aContext) const NS_IMETHODIMP
nsFontCache :: GetDeviceContext(nsIDeviceContext *&aContext) const
{ {
NS_IF_ADDREF(mContext); NS_IF_ADDREF(mContext);
aContext = mContext; aContext = mContext;
return NS_OK; return NS_OK;
} }
nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, NS_IMETHODIMP
nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
nsIFontMetrics *&aMetrics) nsIFontMetrics *&aMetrics)
{ {
// First check our cache // 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. // 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; if (NS_FAILED(rv)) {
nsresult rv = nsComponentManager::CreateInstance(kFontMetricsCID, nsnull,
NS_GET_IID(nsIFontMetrics), (void **)&fm);
if (NS_OK != rv) {
aMetrics = nsnull; aMetrics = nsnull;
return rv; return rv;
} }
rv = fm->Init(aFont, aLangGroup, mContext); rv = fm->Init(aFont, aLangGroup, mContext);
if (NS_OK != rv) { if (NS_FAILED(rv)) {
aMetrics = nsnull; aMetrics = nsnull;
return rv; return rv;
} }
@ -832,6 +811,17 @@ nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
return NS_OK; 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() nsresult nsFontCache :: Flush()
{ {
PRInt32 i, n = mFontMetrics.Count(); PRInt32 i, n = mFontMetrics.Count();

Просмотреть файл

@ -18,6 +18,7 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/ */
#include "nsDeviceContextPS.h" #include "nsDeviceContextPS.h"
@ -36,7 +37,6 @@ static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
*/ */
nsDeviceContextPS :: nsDeviceContextPS() nsDeviceContextPS :: nsDeviceContextPS()
{ {
NS_INIT_REFCNT(); NS_INIT_REFCNT();
mSpec = nsnull; mSpec = nsnull;
mParentDeviceContext = nsnull; mParentDeviceContext = nsnull;
@ -48,19 +48,8 @@ nsDeviceContextPS :: nsDeviceContextPS()
*/ */
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(mSpec);
NS_IF_RELEASE(mParentDeviceContext); NS_IF_RELEASE(mParentDeviceContext);
} }
NS_IMETHODIMP NS_IMETHODIMP
@ -359,64 +348,34 @@ NS_IMETHODIMP nsDeviceContextPS :: ConvertPixel(nscolor aColor, PRUint32 & aPixe
return NS_OK; return NS_OK;
} }
/** --------------------------------------------------- class nsFontCachePS : public nsFontCache
* See documentation in nsIDeviceContext.h
* @update 12/21/98 dwc
*/
NS_IMETHODIMP nsDeviceContextPS::GetMetricsFor(const nsFont& aFont, nsIFontMetrics *&aMetrics)
{ {
GetLocaleLangGroup(); public:
return GetMetricsFor(aFont, mLocaleLangGroup, aMetrics); /* 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; NS_PRECONDITION(aResult, "null out param");
nsresult rv; nsIFontMetrics *fm = new nsFontMetricsPS();
if (!fm)
// First check our cache return NS_ERROR_OUT_OF_MEMORY;
n = mFontMetrics.Count(); NS_ADDREF(fm);
*aResult = fm;
for (cnt = 0; cnt < n; cnt++)
{
aMetrics = (nsIFontMetrics*) mFontMetrics.ElementAt(cnt);
const nsFont* font;
aMetrics->GetFont(font);
nsCOMPtr<nsIAtom> 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;
return NS_OK; 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;
}

Просмотреть файл

@ -18,6 +18,7 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/ */
#ifndef nsDeviceContextPS_h___ #ifndef nsDeviceContextPS_h___
@ -40,7 +41,7 @@ class nsDeviceContextPS : public DeviceContextImpl,
public: public:
nsDeviceContextPS(); nsDeviceContextPS();
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
/** /**
* This method does nothing since a postscript devicecontext will never be created * 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; 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 GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
NS_IMETHOD CheckFontExistence(const nsString& aFontName); NS_IMETHOD CheckFontExistence(const nsString& aFontName);
NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace); NS_IMETHODIMP GetILColorSpace(IL_ColorSpace*& aColorSpace);
NS_IMETHOD GetDepth(PRUint32& aDepth); NS_IMETHOD GetDepth(PRUint32& aDepth);
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel); NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight); NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
NS_IMETHOD GetClientRect(nsRect &aRect); NS_IMETHOD GetClientRect(nsRect &aRect);
NS_IMETHOD GetRect(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 GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const;
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); NS_IMETHOD BeginDocument(PRUnichar * aTitle);
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup, nsIFontMetrics*& aMetrics); NS_IMETHOD EndDocument(void);
NS_IMETHOD BeginDocument(PRUnichar * aTitle); NS_IMETHOD BeginPage(void);
NS_IMETHOD EndDocument(void); NS_IMETHOD EndPage(void);
NS_IMETHOD BeginPage(void); NS_IMETHOD CreateFontCache();
NS_IMETHOD EndPage(void);
NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec); NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec);
protected: protected:
virtual ~nsDeviceContextPS(); virtual ~nsDeviceContextPS();
nsDrawingSurface mSurface; nsDrawingSurface mSurface;
PRUint32 mDepth; PRUint32 mDepth;
nsIDeviceContextSpec *mSpec; nsIDeviceContextSpec *mSpec;
nsIDeviceContext *mParentDeviceContext; nsIDeviceContext *mParentDeviceContext;
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
nsPostScriptObj *mPSObj; nsPostScriptObj *mPSObj;
public: public:

Просмотреть файл

@ -509,3 +509,35 @@ NS_IMETHODIMP nsDeviceContextXlib::EndPage(void)
PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n")); PR_LOG(DeviceContextXlibLM, PR_LOG_DEBUG, ("nsDeviceContextXlib::EndPage()\n"));
return NS_OK; 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;
}

Просмотреть файл

@ -18,7 +18,8 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* David Smith <david@igelaus.com.au> * David Smith <david@igelaus.com.au>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/ */
#ifndef nsDeviceContextXlib_h__ #ifndef nsDeviceContextXlib_h__
@ -64,11 +65,13 @@ public:
NS_IMETHOD BeginPage(void); NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void); NS_IMETHOD EndPage(void);
Display * GetDisplay() { return mDisplay; } NS_IMETHOD CreateFontCache();
Screen * GetScreen() { return mScreen; }
Visual * GetVisual() { return mVisual; } Display *GetDisplay() { return mDisplay; }
int GetDepth() { return mDepth; } Screen *GetScreen() { return mScreen; }
NS_IMETHOD GetDepth( PRUint32 &depth ) { depth=(PRUint32)mDepth;return NS_OK; } Visual *GetVisual() { return mVisual; }
int GetDepth() { return mDepth; }
NS_IMETHOD GetDepth( PRUint32 &depth ) { depth=(PRUint32)mDepth;return NS_OK; }
protected: protected:
@ -91,4 +94,5 @@ private:
PRInt32 mHeight; PRInt32 mHeight;
}; };
#endif #endif /* !nsDeviceContextXlib_h__ */

Просмотреть файл

@ -18,9 +18,8 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de> * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
* Bradley Baetz <bbaetz@cs.mcgill.ca> * Bradley Baetz <bbaetz@cs.mcgill.ca>
*
*/ */
#include <strings.h> #include <strings.h>
@ -55,8 +54,6 @@ nsDeviceContextXp :: nsDeviceContextXp()
mPrintContext = nsnull; mPrintContext = nsnull;
mSpec = nsnull; mSpec = nsnull;
mParentDeviceContext = 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")); PR_LOG(nsDeviceContextXpLM, PR_LOG_DEBUG, ("nsDeviceContextXp::EndDocument()\n"));
nsresult rv = NS_OK; nsresult rv = NS_OK;
if (mPrintContext != nsnull) { if (mPrintContext != nsnull) {
rv = mPrintContext->EndDocument(); rv = mPrintContext->EndDocument();
// gisburn: mPrintContext cannot be reused between to print // gisburn: mPrintContext cannot be reused between to print
// tasks as the destination print server may be a different one // tasks as the destination print server may be a different one
// or the printer used on the same print server has other // or the printer used on the same print server has other
// properties (build-in fonts for example ) than the printer // properties (build-in fonts for example ) than the printer
// previously used // previously used
mFontMetrics = nsnull; /* nsCOMPtr will release/free all objects */ FlushFontCache();
nsRenderingContextXlib::Shutdown(); nsRenderingContextXlib::Shutdown();
nsFontMetricsXlib::FreeGlobals(); nsFontMetricsXlib::FreeGlobals();
delete mPrintContext; delete mPrintContext;
mPrintContext = nsnull; mPrintContext = nsnull;
} }
return rv; return rv;
@ -402,68 +399,40 @@ NS_IMETHODIMP nsDeviceContextXp::GetDepth(PRUint32& aDepth)
return NS_OK; 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<nsIFontMetrics> 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<nsIFontMetrics> 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 NS_IMETHODIMP
nsDeviceContextXp::GetPrintContext(nsXPrintContext*& aContext) { nsDeviceContextXp::GetPrintContext(nsXPrintContext*& aContext) {
aContext = mPrintContext; aContext = mPrintContext;
//NS_ADDREF(aContext);
return NS_OK; 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;
}

Просмотреть файл

@ -18,7 +18,7 @@
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de> * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/ */
#ifndef nsDeviceContextXp_h___ #ifndef nsDeviceContextXp_h___
@ -82,9 +82,7 @@ public:
Display *GetDisplay(); Display *GetDisplay();
NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext); NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext);
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIFontMetrics*& aMetrics); NS_IMETHOD CreateFontCache();
NS_IMETHOD GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
nsIFontMetrics*& aMetrics);
protected: protected:
virtual ~nsDeviceContextXp(); virtual ~nsDeviceContextXp();
@ -93,7 +91,6 @@ protected:
Display *mDisplay; Display *mDisplay;
Screen *mScreen; Screen *mScreen;
nsCOMPtr<nsIDeviceContextSpec> mSpec; nsCOMPtr<nsIDeviceContextSpec> mSpec;
nsCOMPtr<nsISupportsArray> mFontMetrics; // we are not using the normal font cache
nsIDeviceContext *mParentDeviceContext; nsIDeviceContext *mParentDeviceContext;
}; };

Просмотреть файл

@ -17,7 +17,8 @@
* Copyright (C) 1998 Netscape Communications Corporation. All * Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved. * Rights Reserved.
* *
* Contributor(s): * Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/ */
#include "nsISupports.h" #include "nsISupports.h"
@ -44,10 +45,6 @@ public:
nsIDeviceContext *aPrinterContext) = 0; nsIDeviceContext *aPrinterContext) = 0;
NS_IMETHOD GetPrintContext(nsXPrintContext*& aContext) = 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;
}; };