diff --git a/gfx/src/mac/nsFontMetricsMac.cpp b/gfx/src/mac/nsFontMetricsMac.cpp index 23414d336a6..c24c57eeadb 100644 --- a/gfx/src/mac/nsFontMetricsMac.cpp +++ b/gfx/src/mac/nsFontMetricsMac.cpp @@ -50,6 +50,7 @@ NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aC mFont = new nsFont(aFont); mContext = aCX; + RealizeFont(); if (mFont != nsnull) nsFontMetricsMac::SetFont(*mFont, mContext); @@ -70,6 +71,73 @@ NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aC return NS_OK; } + +static void MapGenericFamilyToFont(const nsString& aGenericFamily, nsString& aFontFace) +{ + // the CSS generic names (conversions from the old Mac Mozilla code for now) + + if (aGenericFamily.EqualsIgnoreCase("serif")) + { + aFontFace = "Times"; + } + else if (aGenericFamily.EqualsIgnoreCase("sans-serif")) + { + aFontFace="Helvetica"; + } + else if (aGenericFamily.EqualsIgnoreCase("cursive")) + { + aFontFace="Zapf Chancery"; + } + else if (aGenericFamily.EqualsIgnoreCase("fantasy")) + { + aFontFace ="New Century Schlbk"; + } + else if (aGenericFamily.EqualsIgnoreCase("monospace")) + { + aFontFace = "Courier"; + } +} + +struct FontEnumData { + FontEnumData(nsIDeviceContext* aDC, nsString& aFaceName) + : mContext(aDC), mFaceName(aFaceName) + {} + nsIDeviceContext* mContext; + nsString& mFaceName; +}; + +static PRBool FontEnumCallback(const nsString& aFamily, PRBool aGeneric, void *aData) +{ + FontEnumData* data = (FontEnumData*)aData; + if (aGeneric) + { + nsAutoString realFace; + MapGenericFamilyToFont(aFamily, realFace); + data->mFaceName=realFace; + return PR_FALSE; // stop + } + else + { + nsAutoString realFace; + PRBool aliased; + data->mContext->GetLocalFontName(aFamily, realFace, aliased); + if (aliased || (NS_OK == data->mContext->CheckFontExistence(realFace))) + { + data->mFaceName=realFace; + return PR_FALSE; // stop + } + } + return PR_TRUE; +} + +void nsFontMetricsMac::RealizeFont() +{ + nsString faceName; + FontEnumData data(mContext, mFont->name); + mFont->EnumerateFamilies(FontEnumCallback, &data); +} + + NS_IMETHODIMP nsFontMetricsMac :: Destroy() { diff --git a/gfx/src/mac/nsFontMetricsMac.h b/gfx/src/mac/nsFontMetricsMac.h index b2a9a8dcd85..07938da1907 100644 --- a/gfx/src/mac/nsFontMetricsMac.h +++ b/gfx/src/mac/nsFontMetricsMac.h @@ -58,7 +58,8 @@ public: NS_IMETHOD GetFontHandle(nsFontHandle& aHandle); static void SetFont(const nsFont& aFont, nsIDeviceContext* aContext); - +protected: + void RealizeFont(); protected: short mFontNum; nscoord mHeight;