mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-24 19:37:15 +00:00
Check in updated version of nsGfxFactory that manages the ImageManager
class. This was crashing us. PHOTON ONLY Also added un-finished nsFontEnumerator class to nsFontMetricsPh
This commit is contained in:
parent
990f93bd5d
commit
0427220fc1
@ -20,11 +20,20 @@
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "xp_core.h"
|
||||
#include "nsQuickSort.h"
|
||||
#include "nsFontMetricsPh.h"
|
||||
#include "nsPhGfxLog.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
static int gGotAllFontNames = 0;
|
||||
|
||||
// XXX many of these statics need to be freed at shutdown time
|
||||
static PLHashTable* gFamilies = nsnull;
|
||||
|
||||
static PLHashTable* gFamilyNames = nsnull;
|
||||
|
||||
static NS_DEFINE_IID(kIFontMetricsIID, NS_IFONT_METRICS_IID);
|
||||
|
||||
nsFontMetricsPh :: nsFontMetricsPh()
|
||||
@ -350,3 +359,156 @@ nsFontMetricsPh::GetFontHandle(nsFontHandle &aHandle)
|
||||
aHandle = (nsFontHandle) &mFontHandle;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// The Font Enumerator
|
||||
|
||||
nsFontEnumeratorPh::nsFontEnumeratorPh()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::nsFontEnumeratorPh this=<%p>\n", this));
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFontEnumeratorPh,
|
||||
NS_GET_IID(nsIFontEnumerator));
|
||||
|
||||
static int gInitializedFontEnumerator = 0;
|
||||
|
||||
static int
|
||||
InitializeFontEnumerator(void)
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::InitializeFontEnumerator\n"));
|
||||
|
||||
gInitializedFontEnumerator = 1;
|
||||
|
||||
if (!gGotAllFontNames) {
|
||||
gGotAllFontNames = 1;
|
||||
//GetFontNames("-*-*-*-*-*-*-*-*-*-*-*-*-*-*");
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
typedef struct EnumerateFamilyInfo
|
||||
{
|
||||
PRUnichar** mArray;
|
||||
int mIndex;
|
||||
} EnumerateFamilyInfo;
|
||||
|
||||
static PRIntn
|
||||
EnumerateFamily(PLHashEntry* he, PRIntn i, void* arg)
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::EnumerateFamily\n"));
|
||||
|
||||
EnumerateFamilyInfo* info = (EnumerateFamilyInfo*) arg;
|
||||
PRUnichar** array = info->mArray;
|
||||
int j = info->mIndex;
|
||||
PRUnichar* str = ((nsString*) he->key)->ToNewUnicode();
|
||||
if (!str) {
|
||||
for (j = j - 1; j >= 0; j--) {
|
||||
nsAllocator::Free(array[j]);
|
||||
}
|
||||
info->mIndex = 0;
|
||||
return HT_ENUMERATE_STOP;
|
||||
}
|
||||
array[j] = str;
|
||||
info->mIndex++;
|
||||
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
static int
|
||||
CompareFontNames(const void* aArg1, const void* aArg2, void* aClosure)
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::CompareFontNames\n"));
|
||||
|
||||
const PRUnichar* str1 = *((const PRUnichar**) aArg1);
|
||||
const PRUnichar* str2 = *((const PRUnichar**) aArg2);
|
||||
|
||||
// XXX add nsICollation stuff
|
||||
|
||||
return nsCRT::strcmp(str1, str2);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontEnumeratorPh::EnumerateAllFonts(PRUint32* aCount, PRUnichar*** aResult)
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::EnumerateAllFonts this=<%p>\n", this));
|
||||
|
||||
if (aCount) {
|
||||
*aCount = 0;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aResult) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if (!gInitializedFontEnumerator) {
|
||||
if (!InitializeFontEnumerator()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
PRUnichar** array = (PRUnichar**)
|
||||
nsAllocator::Alloc(gFamilies->nentries * sizeof(PRUnichar*));
|
||||
if (!array) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
EnumerateFamilyInfo info = { array, 0 };
|
||||
PL_HashTableEnumerateEntries(gFamilies, EnumerateFamily, &info);
|
||||
if (!info.mIndex) {
|
||||
nsAllocator::Free(array);
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_QuickSort(array, gFamilies->nentries, sizeof(PRUnichar*),
|
||||
CompareFontNames, nsnull);
|
||||
|
||||
*aCount = gFamilies->nentries;
|
||||
*aResult = array;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFontEnumeratorPh::EnumerateFonts(const char* aLangGroup,
|
||||
const char* aGeneric, PRUint32* aCount, PRUnichar*** aResult)
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG, ("nsFontEnumeratorPh::EnumerateFonts this=<%p>\n", this));
|
||||
|
||||
if ((!aLangGroup) || (!aGeneric)) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aCount) {
|
||||
*aCount = 0;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aResult) {
|
||||
*aResult = nsnull;
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
if ((!strcmp(aLangGroup, "x-unicode")) ||
|
||||
(!strcmp(aLangGroup, "x-user-def"))) {
|
||||
return EnumerateAllFonts(aCount, aResult);
|
||||
}
|
||||
|
||||
if (!gInitializedFontEnumerator) {
|
||||
if (!InitializeFontEnumerator()) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
}
|
||||
|
||||
// XXX still need to implement aLangGroup and aGeneric
|
||||
return EnumerateAllFonts(aCount, aResult);
|
||||
}
|
@ -26,12 +26,14 @@
|
||||
#include <Pt.h>
|
||||
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIFontEnumerator.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsRenderingContextPh.h"
|
||||
#include "nsDeviceContextPh.h"
|
||||
|
||||
class nsFontMetricsPh : public nsIFontMetrics
|
||||
@ -86,4 +88,12 @@ protected:
|
||||
nsCOMPtr<nsIAtom> mLangGroup;
|
||||
};
|
||||
|
||||
class nsFontEnumeratorPh : public nsIFontEnumerator
|
||||
{
|
||||
public:
|
||||
nsFontEnumeratorPh();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIFONTENUMERATOR
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -29,17 +29,21 @@
|
||||
#include "nsImagePh.h"
|
||||
#include "nsDeviceContextPh.h"
|
||||
#include "nsRegionPh.h"
|
||||
#include "nsScriptableRegion.h"
|
||||
#include "nsBlender.h"
|
||||
#include "nsDeviceContextSpecPh.h"
|
||||
#include "nsDeviceContextSpecFactoryP.h"
|
||||
|
||||
#include "nsIImageManager.h"
|
||||
#include "nsPhGfxLog.h"
|
||||
|
||||
static NS_DEFINE_IID(kCFontMetrics, NS_FONT_METRICS_CID);
|
||||
static NS_DEFINE_IID(kCFontEnumerator, NS_FONT_ENUMERATOR_CID);
|
||||
static NS_DEFINE_IID(kCRenderingContext, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCImage, NS_IMAGE_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContext, NS_DEVICE_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCRegion, NS_REGION_CID);
|
||||
static NS_DEFINE_IID(kCScriptableRegion, NS_SCRIPTABLE_REGION_CID);
|
||||
|
||||
static NS_DEFINE_IID(kCBlender, NS_BLENDER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
@ -47,38 +51,28 @@ static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
static NS_DEFINE_IID(kCDeviceContextSpec, NS_DEVICE_CONTEXT_SPEC_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContextSpecFactory, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
|
||||
static NS_DEFINE_IID(kImageManagerImpl, NS_IMAGEMANAGER_CID);
|
||||
|
||||
|
||||
//static NS_DEFINE_IID(kCDrawingSurface, NS_DRAWING_SURFACE_CID);
|
||||
//static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
//static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
class nsGfxFactoryPh : public nsIFactory
|
||||
{
|
||||
public:
|
||||
// nsISupports methods
|
||||
NS_IMETHOD QueryInterface(const nsIID &aIID,
|
||||
void **aResult);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
// nsISupports methods
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
NS_DECL_NSIFACTORY
|
||||
|
||||
nsGfxFactoryPh(const nsCID &aClass);
|
||||
~nsGfxFactoryPh();
|
||||
|
||||
private:
|
||||
nsrefcnt mRefCnt;
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
nsGfxFactoryPh::nsGfxFactoryPh(const nsCID &aClass)
|
||||
{
|
||||
mRefCnt = 0;
|
||||
NS_INIT_ISUPPORTS();
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
@ -118,6 +112,8 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
@ -125,7 +121,8 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
|
||||
PRBool already_addreffed = PR_FALSE;
|
||||
|
||||
if (mClassID.Equals(kCFontMetrics))
|
||||
{
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for nsFontMetricsPh.\n"));
|
||||
@ -149,6 +146,15 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
|
||||
NS_NEWXPCOM(region, nsRegionPh);
|
||||
inst = (nsISupports *)region;
|
||||
}
|
||||
else if (mClassID.Equals(kCScriptableRegion)) {
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for kCScriptableRegion nsRegionPh.\n"));
|
||||
nsCOMPtr<nsIRegion> rgn;
|
||||
NS_NEWXPCOM(rgn, nsRegionPh);
|
||||
if (rgn != nsnull) {
|
||||
nsCOMPtr<nsIScriptableRegion> scriptableRgn = new nsScriptableRegion(rgn);
|
||||
inst = scriptableRgn;
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kCBlender)) {
|
||||
inst = (nsISupports *)new nsBlender;
|
||||
}
|
||||
@ -164,6 +170,22 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
|
||||
NS_NEWXPCOM(dcs, nsDeviceContextSpecFactoryPh);
|
||||
inst = (nsISupports *)dcs;
|
||||
}
|
||||
else if (mClassID.Equals(kImageManagerImpl)) {
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for ImageManagerImpl.\n"));
|
||||
nsCOMPtr<nsIImageManager> iManager;
|
||||
res = NS_NewImageManager(getter_AddRefs(iManager));
|
||||
already_addreffed = PR_TRUE;
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
res = iManager->QueryInterface(NS_GET_IID(nsISupports), (void**)&inst);
|
||||
}
|
||||
}
|
||||
else if (mClassID.Equals(kCFontEnumerator)) {
|
||||
PR_LOG(PhGfxLog, PR_LOG_DEBUG,("nsGfxFactoryPh::CreateInstance asking for FontEnumerator.\n"));
|
||||
nsFontEnumeratorPh* fe;
|
||||
NS_NEWXPCOM(fe, nsFontEnumeratorPh);
|
||||
inst = (nsISupports *)fe;
|
||||
}
|
||||
|
||||
if (inst == NULL)
|
||||
{
|
||||
@ -171,17 +193,12 @@ nsresult nsGfxFactoryPh::CreateInstance(nsISupports *aOuter,
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (res != NS_OK) {
|
||||
// We didn't get the right interface, so clean up
|
||||
PR_LOG(PhGfxLog, PR_LOG_ERROR,("nsGfxFactoryPh::CreateInstance Did not get the right interface, Failed.\n"));
|
||||
delete inst;
|
||||
}
|
||||
// else {
|
||||
// inst->Release();
|
||||
// }
|
||||
if (already_addreffed == PR_FALSE)
|
||||
NS_ADDREF(inst);
|
||||
|
||||
res = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user