implement Mac GFX w/ langGroup. From now we will use the correct CJK font depend on the document charset. Howerver, it have not listen to the pref yet. r=erik. a=chofmann

This commit is contained in:
ftang%netscape.com 1999-12-09 22:44:34 +00:00
Родитель 2fdf046684
Коммит bfb3fff3c2
6 изменённых файлов: 42 добавлений и 33 удалений

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

@ -29,6 +29,7 @@
struct nsFont;
class nsString;
class nsIDeviceContext;
class nsIAtom;
// IID for the nsIFontMetrics interface
#define NS_IFONT_METRICS_IID \
@ -52,7 +53,7 @@ class nsIFontMetrics : public nsISupports
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IFONT_METRICS_IID)
#ifdef XP_PC
#if defined( XP_PC ) || defined( XP_MAC )
/**
* Initialize the font metrics. Call this after creating the font metrics.
* Font metrics you get from the font cache do NOT need to be initialized
@ -144,7 +145,7 @@ public:
*/
NS_IMETHOD GetFont(const nsFont *&aFont) = 0;
#ifdef XP_PC
#if defined( XP_PC ) || defined( XP_MAC )
/**
* Returns the language group associated with these metrics
*/

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

@ -52,11 +52,12 @@ nsFontMetricsMac :: ~nsFontMetricsMac()
NS_IMPL_ISUPPORTS(nsFontMetricsMac, kIFontMetricsIID);
NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIDeviceContext* aCX)
NS_IMETHODIMP nsFontMetricsMac :: Init(const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aCX)
{
NS_ASSERTION(!(nsnull == aCX), "attempt to init fontmetrics with null device context");
mFont = new nsFont(aFont);
mLangGroup = aLangGroup;
mContext = aCX;
RealizeFont();
@ -125,9 +126,11 @@ nsUnicodeFontMappingMac* nsFontMetricsMac :: GetUnicodeFontMapping()
// the lang attribute from the tag level to here.
// XXX hard code to some value till peterl pass them down.
nsAutoString lang("");
nsAutoString documentCharset("ISO-8859-1");
nsAutoString langGroup("ja");
if(mLangGroup)
mLangGroup->ToString(langGroup);
if(! mFontMapping)
mFontMapping = nsUnicodeFontMappingMac::GetCachedInstance(mFont, mContext,documentCharset, lang);
mFontMapping = nsUnicodeFontMappingMac::GetCachedInstance(mFont, mContext,langGroup, lang);
return mFontMapping;
}
@ -300,6 +303,18 @@ NS_IMETHODIMP nsFontMetricsMac :: GetFont(const nsFont *&aFont)
aFont = mFont;
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsMac::GetLangGroup(nsIAtom** aLangGroup)
{
if (!aLangGroup) {
return NS_ERROR_NULL_POINTER;
}
*aLangGroup = mLangGroup;
NS_IF_ADDREF(*aLangGroup);
return NS_OK;
}
NS_IMETHODIMP nsFontMetricsMac :: GetWidths(const nscoord *&aWidths)
{

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

@ -31,6 +31,8 @@
#include "nsUnitConversion.h"
#include "nsIDeviceContext.h"
#include "nsCRT.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
class nsUnicodeFontMappingMac;
class nsFontMetricsMac : public nsIFontMetrics
@ -43,7 +45,7 @@ public:
NS_DECL_ISUPPORTS
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext* aContext);
NS_IMETHOD Init(const nsFont& aFont, nsIAtom* aLangGroup, nsIDeviceContext* aContext);
NS_IMETHOD Destroy();
NS_IMETHOD GetXHeight(nscoord& aResult);
@ -58,6 +60,7 @@ public:
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
NS_IMETHOD GetWidths(const nscoord *&aWidths);
NS_IMETHOD GetFont(const nsFont *&aFont);
NS_IMETHOD GetLangGroup(nsIAtom** aLangGroup);
NS_IMETHOD GetFontHandle(nsFontHandle& aHandle);
virtual nsresult GetSpaceWidth(nscoord &aSpaceWidth);
// fill a native TextStyle record with the font, size and style (not color)
@ -80,7 +83,7 @@ protected:
nscoord mMaxDescent;
nscoord mMaxAdvance;
nscoord mSpaceWidth;
nsCOMPtr<nsIAtom> mLangGroup;
nsFont *mFont;
nsIDeviceContext *mContext;
};

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

@ -245,34 +245,24 @@ void nsUnicodeFontMappingMac::InitByLANG(const nsString& aLANG)
}
}
//--------------------------------------------------------------------------
void nsUnicodeFontMappingMac::InitByDocumentCharset(const nsString& aDocumentCharset)
void nsUnicodeFontMappingMac::InitByLangGroup(const nsString& aLangGroup)
{
// do not countinue if there are no difference to look at the document Charset
if( ScriptMapInitComplete() )
return;
if(gUtil->ScriptEnabled(smRoman) && aDocumentCharset.EqualsIgnoreCase("ISO-8859-1"))
if(gUtil->ScriptEnabled(smRoman) && aLangGroup.EqualsIgnoreCase("x-western"))
{
FillVarBlockToScript(smRoman, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smSimpChinese) &&
(aDocumentCharset.EqualsIgnoreCase("GB2312") ||
aDocumentCharset.EqualsIgnoreCase("ISO-2022-CN") ||
aDocumentCharset.EqualsIgnoreCase("ZH") ))
} else if(gUtil->ScriptEnabled(smSimpChinese) && aLangGroup.EqualsIgnoreCase("zh-CN"))
{
FillVarBlockToScript(smSimpChinese, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smKorean) &&
( aDocumentCharset.EqualsIgnoreCase("EUC-KR") ||
aDocumentCharset.EqualsIgnoreCase("ISO-2022-KR") ))
} else if(gUtil->ScriptEnabled(smKorean) && aLangGroup.EqualsIgnoreCase("ko"))
{
FillVarBlockToScript(smKorean, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smTradChinese) &&
( aDocumentCharset.EqualsIgnoreCase("Big5") ||
aDocumentCharset.EqualsIgnoreCase("x-euc-tw") ))
} else if(gUtil->ScriptEnabled(smTradChinese) && aLangGroup.EqualsIgnoreCase("zh-TW"))
{
FillVarBlockToScript(smTradChinese, mPrivBlockToScript);
} else if(gUtil->ScriptEnabled(smJapanese) &&
( aDocumentCharset.EqualsIgnoreCase("Shift_JIS") ||
aDocumentCharset.EqualsIgnoreCase("EUC-JP") ||
aDocumentCharset.EqualsIgnoreCase("ISO-2022-JP") ))
} else if(gUtil->ScriptEnabled(smJapanese) && aLangGroup.EqualsIgnoreCase("ja"))
{
FillVarBlockToScript(smJapanese, mPrivBlockToScript);
}
@ -298,7 +288,7 @@ void nsUnicodeFontMappingMac::InitDefaultScriptFonts()
nsUnicodeFontMappingMac::nsUnicodeFontMappingMac(
nsFont* aFont, nsIDeviceContext *aDeviceContext,
const nsString& aDocumentCharset, const nsString& aLANG)
const nsString& aLangGroup, const nsString& aLANG)
{
PRInt32 i;
for(i = kUnicodeBlockFixedScriptMax ; i < kUnicodeBlockSize; i++)
@ -308,13 +298,13 @@ nsUnicodeFontMappingMac::nsUnicodeFontMappingMac(
InitByFontFamily(aFont, aDeviceContext);
InitByLANG(aLANG);
InitByDocumentCharset(aDocumentCharset);
InitByLangGroup(aLangGroup);
InitDefaultScriptFonts();
}
//--------------------------------------------------------------------------
nsUnicodeFontMappingMac* nsUnicodeFontMappingMac::GetCachedInstance(
nsFont* aFont, nsIDeviceContext *aDeviceContext, const nsString& aDocumentCharset, const nsString& aLANG)
nsFont* aFont, nsIDeviceContext *aDeviceContext, const nsString& aLangGroup, const nsString& aLANG)
{
if(! gUtil)
gUtil = nsUnicodeMappingUtil::GetSingleton();
@ -324,11 +314,11 @@ nsUnicodeFontMappingMac* nsUnicodeFontMappingMac::GetCachedInstance(
nsUnicodeFontMappingMac* obj = nsnull;
nsAutoString key = aFont->name;
key.Append(":");
key.Append(aDocumentCharset);
key.Append(aLangGroup);
key.Append(":");
key.Append(aLANG);
if(! gCache->Get ( key, &obj )){
obj = new nsUnicodeFontMappingMac(aFont, aDeviceContext, aDocumentCharset, aLANG);
obj = new nsUnicodeFontMappingMac(aFont, aDeviceContext, aLangGroup, aLANG);
if( obj )
gCache->Set ( key, obj);
}

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

@ -33,7 +33,7 @@ class nsUnicodeFontMappingCache;
class nsUnicodeFontMappingMac {
public:
nsUnicodeFontMappingMac(nsFont* aFont, nsIDeviceContext *aDeviceContext,
const nsString& aDocumentCharset, const nsString& aLANG);
const nsString& aLangGroup, const nsString& aLANG);
short GetFontID(PRUnichar aChar);
inline const short *GetScriptFallbackFonts() {
return mScriptFallbackFontIDs;
@ -41,14 +41,14 @@ public:
PRBool Equals(const nsUnicodeFontMappingMac& anther);
static nsUnicodeFontMappingMac* GetCachedInstance(nsFont* aFont, nsIDeviceContext *aDeviceContext,
const nsString& aDocumentCharset, const nsString& aLANG);
const nsString& aLangGroup, const nsString& aLANG);
protected:
PRBool ScriptMapInitComplete();
void InitByFontFamily(nsFont* aFont, nsIDeviceContext *aDeviceContext);
void InitByLANG(const nsString& aLANG);
void InitByDocumentCharset(const nsString& aDocumentCharset);
void InitByLangGroup(const nsString& aLangGroup);
void InitDefaultScriptFonts();
void processOneLangRegion(const char* aLanguage, const char* aRegion );
nsUnicodeBlock GetBlock(PRUnichar aChar);

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

@ -741,7 +741,7 @@ nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
const nsFont* font;
aMetrics->GetFont(font);
#ifdef XP_PC
#if defined( XP_PC ) || defined(XP_MAC)
nsCOMPtr<nsIAtom> langGroup;
aMetrics->GetLangGroup(getter_AddRefs(langGroup));
if (aFont.Equals(*font) && (aLangGroup == langGroup))
@ -766,7 +766,7 @@ nsresult nsFontCache :: GetMetricsFor(const nsFont& aFont, nsIAtom* aLangGroup,
return rv;
}
#ifdef XP_PC
#if defined( XP_PC ) || defined(XP_MAC)
rv = fm->Init(aFont, aLangGroup, mContext);
#else
rv = fm->Init(aFont, mContext);