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 удалений

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

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
*/
#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();

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

@ -18,6 +18,8 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
*
* 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();

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

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/
#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<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;
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;
}

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

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/
#ifndef nsDeviceContextPS_h___
@ -73,13 +74,11 @@ public:
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 CreateFontCache();
NS_IMETHOD SetSpec(nsIDeviceContextSpec *aSpec);
@ -90,7 +89,6 @@ protected:
PRUint32 mDepth;
nsIDeviceContextSpec *mSpec;
nsIDeviceContext *mParentDeviceContext;
nsVoidArray mFontMetrics; // we are not using the normal font cache, this is special for PostScript.
nsPostScriptObj *mPSObj;
public:

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

@ -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;
}

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

@ -19,6 +19,7 @@
*
* Contributor(s):
* David Smith <david@igelaus.com.au>
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/
#ifndef nsDeviceContextXlib_h__
@ -64,9 +65,11 @@ public:
NS_IMETHOD BeginPage(void);
NS_IMETHOD EndPage(void);
Display * GetDisplay() { return mDisplay; }
Screen * GetScreen() { return mScreen; }
Visual * GetVisual() { return mVisual; }
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; }
@ -91,4 +94,5 @@ private:
PRInt32 mHeight;
};
#endif
#endif /* !nsDeviceContextXlib_h__ */

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

@ -20,7 +20,6 @@
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
* Bradley Baetz <bbaetz@cs.mcgill.ca>
*
*/
#include <strings.h>
@ -55,8 +54,6 @@ nsDeviceContextXp :: nsDeviceContextXp()
mPrintContext = nsnull;
mSpec = nsnull;
mParentDeviceContext = nsnull;
NS_NewISupportsArray(getter_AddRefs(mFontMetrics));
}
/** ---------------------------------------------------
@ -332,7 +329,7 @@ NS_IMETHODIMP nsDeviceContextXp::EndDocument(void)
// 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 */
FlushFontCache();
nsRenderingContextXlib::Shutdown();
nsFontMetricsXlib::FreeGlobals();
@ -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<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
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;
}

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

@ -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<nsIDeviceContextSpec> mSpec;
nsCOMPtr<nsISupportsArray> mFontMetrics; // we are not using the normal font cache
nsIDeviceContext *mParentDeviceContext;
};

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

@ -18,6 +18,7 @@
* Rights Reserved.
*
* Contributor(s):
* Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
*/
#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;
};