зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1007013 - remove gfxFT2FontGroup. r=mkato
This commit is contained in:
Родитель
e05955b899
Коммит
d1be6ba0f3
|
@ -39,365 +39,6 @@
|
|||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
|
||||
// rounding and truncation functions for a Freetype floating point number
|
||||
// (FT26Dot6) stored in a 32bit integer with high 26 bits for the integer
|
||||
// part and low 6 bits for the fractional part.
|
||||
#define MOZ_FT_ROUND(x) (((x) + 32) & ~63) // 63 = 2^6 - 1
|
||||
#define MOZ_FT_TRUNC(x) ((x) >> 6)
|
||||
#define CONVERT_DESIGN_UNITS_TO_PIXELS(v, s) \
|
||||
MOZ_FT_TRUNC(MOZ_FT_ROUND(FT_MulFix((v) , (s))))
|
||||
|
||||
#ifndef ANDROID // not needed on Android, we use the generic gfxFontGroup
|
||||
/**
|
||||
* gfxFT2FontGroup
|
||||
*/
|
||||
|
||||
static PRLogModuleInfo *
|
||||
GetFontLog()
|
||||
{
|
||||
static PRLogModuleInfo *sLog;
|
||||
if (!sLog)
|
||||
sLog = PR_NewLogModule("ft2fonts");
|
||||
return sLog;
|
||||
}
|
||||
|
||||
bool
|
||||
gfxFT2FontGroup::FontCallback(const nsAString& fontName,
|
||||
const nsACString& genericName,
|
||||
bool aUseFontSet,
|
||||
void *closure)
|
||||
{
|
||||
nsTArray<nsString> *sa = static_cast<nsTArray<nsString>*>(closure);
|
||||
|
||||
if (!fontName.IsEmpty() && !sa->Contains(fontName)) {
|
||||
sa->AppendElement(fontName);
|
||||
#ifdef DEBUG_pavlov
|
||||
printf(" - %s\n", NS_ConvertUTF16toUTF8(fontName).get());
|
||||
#endif
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
gfxFT2FontGroup::gfxFT2FontGroup(const nsAString& families,
|
||||
const gfxFontStyle *aStyle,
|
||||
gfxUserFontSet *aUserFontSet)
|
||||
: gfxFontGroup(families, aStyle, aUserFontSet)
|
||||
{
|
||||
#ifdef DEBUG_pavlov
|
||||
printf("Looking for %s\n", NS_ConvertUTF16toUTF8(families).get());
|
||||
#endif
|
||||
nsTArray<nsString> familyArray;
|
||||
ForEachFont(FontCallback, &familyArray);
|
||||
|
||||
if (familyArray.Length() == 0) {
|
||||
nsAutoString prefFamilies;
|
||||
gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language, prefFamilies, nullptr);
|
||||
if (!prefFamilies.IsEmpty()) {
|
||||
ForEachFont(prefFamilies, aStyle->language, FontCallback, &familyArray);
|
||||
}
|
||||
}
|
||||
if (familyArray.Length() == 0) {
|
||||
#if defined(MOZ_WIDGET_QT) /* FIXME DFB */
|
||||
printf("failde to find a font. sadface\n");
|
||||
// We want to get rid of this entirely at some point, but first we need real lists of fonts.
|
||||
QFont defaultFont;
|
||||
QFontInfo fi (defaultFont);
|
||||
familyArray.AppendElement(nsDependentString(static_cast<const char16_t *>(fi.family().utf16())));
|
||||
#elif defined(MOZ_WIDGET_GTK)
|
||||
FcResult result;
|
||||
FcChar8 *family = nullptr;
|
||||
FcPattern* pat = FcPatternCreate();
|
||||
FcPattern *match = FcFontMatch(nullptr, pat, &result);
|
||||
if (match)
|
||||
FcPatternGetString(match, FC_FAMILY, 0, &family);
|
||||
if (family)
|
||||
familyArray.AppendElement(NS_ConvertUTF8toUTF16((char*)family));
|
||||
#elif defined(XP_WIN)
|
||||
HGDIOBJ hGDI = ::GetStockObject(SYSTEM_FONT);
|
||||
LOGFONTW logFont;
|
||||
if (hGDI && ::GetObjectW(hGDI, sizeof(logFont), &logFont))
|
||||
familyArray.AppendElement(nsDependentString(logFont.lfFaceName));
|
||||
#elif defined(ANDROID)
|
||||
familyArray.AppendElement(NS_LITERAL_STRING("Droid Sans"));
|
||||
familyArray.AppendElement(NS_LITERAL_STRING("Roboto"));
|
||||
#else
|
||||
#error "Platform not supported"
|
||||
#endif
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < familyArray.Length(); i++) {
|
||||
nsRefPtr<gfxFT2Font> font = gfxFT2Font::GetOrMakeFont(familyArray[i], &mStyle);
|
||||
if (font) {
|
||||
mFonts.AppendElement(font);
|
||||
}
|
||||
}
|
||||
NS_ASSERTION(mFonts.Length() > 0, "We need at least one font in a fontgroup");
|
||||
}
|
||||
|
||||
gfxFT2FontGroup::~gfxFT2FontGroup()
|
||||
{
|
||||
}
|
||||
|
||||
gfxFontGroup *
|
||||
gfxFT2FontGroup::Copy(const gfxFontStyle *aStyle)
|
||||
{
|
||||
return new gfxFT2FontGroup(mFamilies, aStyle, nullptr);
|
||||
}
|
||||
|
||||
// Helper function to return the leading UTF-8 character in a char pointer
|
||||
// as 32bit number. Also sets the length of the current character (i.e. the
|
||||
// offset to the next one) in the second argument
|
||||
uint32_t getUTF8CharAndNext(const uint8_t *aString, uint8_t *aLength)
|
||||
{
|
||||
*aLength = 1;
|
||||
if (aString[0] < 0x80) { // normal 7bit ASCII char
|
||||
return aString[0];
|
||||
}
|
||||
if ((aString[0] >> 5) == 6) { // two leading ones -> two bytes
|
||||
*aLength = 2;
|
||||
return ((aString[0] & 0x1F) << 6) + (aString[1] & 0x3F);
|
||||
}
|
||||
if ((aString[0] >> 4) == 14) { // three leading ones -> three bytes
|
||||
*aLength = 3;
|
||||
return ((aString[0] & 0x0F) << 12) + ((aString[1] & 0x3F) << 6) +
|
||||
(aString[2] & 0x3F);
|
||||
}
|
||||
if ((aString[0] >> 4) == 15) { // four leading ones -> four bytes
|
||||
*aLength = 4;
|
||||
return ((aString[0] & 0x07) << 18) + ((aString[1] & 0x3F) << 12) +
|
||||
((aString[2] & 0x3F) << 6) + (aString[3] & 0x3F);
|
||||
}
|
||||
return aString[0];
|
||||
}
|
||||
|
||||
|
||||
static bool
|
||||
AddFontNameToArray(const nsAString& aName,
|
||||
const nsACString& aGenericName,
|
||||
bool aUseFontSet,
|
||||
void *aClosure)
|
||||
{
|
||||
if (!aName.IsEmpty()) {
|
||||
nsTArray<nsString> *list = static_cast<nsTArray<nsString> *>(aClosure);
|
||||
|
||||
if (list->IndexOf(aName) == list->NoIndex)
|
||||
list->AppendElement(aName);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
gfxFT2FontGroup::FamilyListToArrayList(const nsString& aFamilies,
|
||||
nsIAtom *aLangGroup,
|
||||
nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList)
|
||||
{
|
||||
nsAutoTArray<nsString, 15> fonts;
|
||||
ForEachFont(aFamilies, aLangGroup, AddFontNameToArray, &fonts);
|
||||
|
||||
uint32_t len = fonts.Length();
|
||||
for (uint32_t i = 0; i < len; ++i) {
|
||||
const nsString& str = fonts[i];
|
||||
nsRefPtr<gfxFontEntry> fe = (gfxToolkitPlatform::GetPlatform()->FindFontEntry(str, mStyle));
|
||||
aFontEntryList->AppendElement(fe);
|
||||
}
|
||||
}
|
||||
|
||||
void gfxFT2FontGroup::GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
|
||||
{
|
||||
NS_ASSERTION(aLangGroup, "aLangGroup is null");
|
||||
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
||||
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
||||
nsAutoCString key;
|
||||
aLangGroup->ToUTF8String(key);
|
||||
key.Append("-");
|
||||
key.AppendInt(GetStyle()->style);
|
||||
key.Append("-");
|
||||
key.AppendInt(GetStyle()->weight);
|
||||
if (!platform->GetPrefFontEntries(key, &fonts)) {
|
||||
nsString fontString;
|
||||
platform->GetPrefFonts(aLangGroup, fontString);
|
||||
if (fontString.IsEmpty())
|
||||
return;
|
||||
|
||||
FamilyListToArrayList(fontString, aLangGroup, &fonts);
|
||||
|
||||
platform->SetPrefFontEntries(key, fonts);
|
||||
}
|
||||
aFontEntryList.AppendElements(fonts);
|
||||
}
|
||||
|
||||
static int32_t GetCJKLangGroupIndex(const char *aLangGroup) {
|
||||
int32_t i;
|
||||
for (i = 0; i < COUNT_OF_CJK_LANG_GROUP; i++) {
|
||||
if (!PL_strcasecmp(aLangGroup, sCJKLangGroup[i]))
|
||||
return i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// this function assigns to the array passed in.
|
||||
void gfxFT2FontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList) {
|
||||
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
||||
|
||||
nsAutoCString key("x-internal-cjk-");
|
||||
key.AppendInt(mStyle.style);
|
||||
key.Append("-");
|
||||
key.AppendInt(mStyle.weight);
|
||||
|
||||
if (!platform->GetPrefFontEntries(key, &aFontEntryList)) {
|
||||
NS_ENSURE_TRUE_VOID(Preferences::GetRootBranch());
|
||||
// Add the CJK pref fonts from accept languages, the order should be same order
|
||||
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
|
||||
if (!list.IsEmpty()) {
|
||||
const char kComma = ',';
|
||||
const char *p, *p_end;
|
||||
list.BeginReading(p);
|
||||
list.EndReading(p_end);
|
||||
while (p < p_end) {
|
||||
while (nsCRT::IsAsciiSpace(*p)) {
|
||||
if (++p == p_end)
|
||||
break;
|
||||
}
|
||||
if (p == p_end)
|
||||
break;
|
||||
const char *start = p;
|
||||
while (++p != p_end && *p != kComma)
|
||||
/* nothing */ ;
|
||||
nsAutoCString lang(Substring(start, p));
|
||||
lang.CompressWhitespace(false, true);
|
||||
int32_t index = GetCJKLangGroupIndex(lang.get());
|
||||
if (index >= 0) {
|
||||
nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
|
||||
GetPrefFonts(atom, aFontEntryList);
|
||||
}
|
||||
p++;
|
||||
}
|
||||
}
|
||||
|
||||
// Add the system locale
|
||||
#ifdef XP_WIN
|
||||
switch (::GetACP()) {
|
||||
case 932: GetPrefFonts(nsGkAtoms::Japanese, aFontEntryList); break;
|
||||
case 936: GetPrefFonts(nsGkAtoms::zh_cn, aFontEntryList); break;
|
||||
case 949: GetPrefFonts(nsGkAtoms::ko, aFontEntryList); break;
|
||||
// XXX Don't we need to append nsGkAtoms::zh_hk if the codepage is 950?
|
||||
case 950: GetPrefFonts(nsGkAtoms::zh_tw, aFontEntryList); break;
|
||||
}
|
||||
#else
|
||||
const char *ctype = setlocale(LC_CTYPE, nullptr);
|
||||
if (ctype) {
|
||||
if (!PL_strncasecmp(ctype, "ja", 2)) {
|
||||
GetPrefFonts(nsGkAtoms::Japanese, aFontEntryList);
|
||||
} else if (!PL_strncasecmp(ctype, "zh_cn", 5)) {
|
||||
GetPrefFonts(nsGkAtoms::zh_cn, aFontEntryList);
|
||||
} else if (!PL_strncasecmp(ctype, "zh_hk", 5)) {
|
||||
GetPrefFonts(nsGkAtoms::zh_hk, aFontEntryList);
|
||||
} else if (!PL_strncasecmp(ctype, "zh_tw", 5)) {
|
||||
GetPrefFonts(nsGkAtoms::zh_tw, aFontEntryList);
|
||||
} else if (!PL_strncasecmp(ctype, "ko", 2)) {
|
||||
GetPrefFonts(nsGkAtoms::ko, aFontEntryList);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// last resort...
|
||||
GetPrefFonts(nsGkAtoms::Japanese, aFontEntryList);
|
||||
GetPrefFonts(nsGkAtoms::ko, aFontEntryList);
|
||||
GetPrefFonts(nsGkAtoms::zh_cn, aFontEntryList);
|
||||
GetPrefFonts(nsGkAtoms::zh_hk, aFontEntryList);
|
||||
GetPrefFonts(nsGkAtoms::zh_tw, aFontEntryList);
|
||||
|
||||
platform->SetPrefFontEntries(key, aFontEntryList);
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<gfxFT2Font>
|
||||
gfxFT2FontGroup::WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList, uint32_t aCh)
|
||||
{
|
||||
for (uint32_t i = 0; i < aFontEntryList.Length(); i++) {
|
||||
gfxFontEntry *fe = aFontEntryList[i].get();
|
||||
if (fe->HasCharacter(aCh)) {
|
||||
nsRefPtr<gfxFT2Font> font =
|
||||
gfxFT2Font::GetOrMakeFont(static_cast<FontEntry*>(fe), &mStyle);
|
||||
return font.forget();
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<gfxFont>
|
||||
gfxFT2FontGroup::WhichPrefFontSupportsChar(uint32_t aCh)
|
||||
{
|
||||
if (aCh > 0xFFFF)
|
||||
return nullptr;
|
||||
|
||||
nsRefPtr<gfxFT2Font> selectedFont;
|
||||
|
||||
// check out the style's language
|
||||
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
||||
GetPrefFonts(mStyle.language, fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
||||
|
||||
// otherwise search prefs
|
||||
if (!selectedFont) {
|
||||
uint32_t unicodeRange = FindCharUnicodeRange(aCh);
|
||||
|
||||
/* special case CJK */
|
||||
if (unicodeRange == kRangeSetCJK) {
|
||||
if (PR_LOG_TEST(GetFontLog(), PR_LOG_DEBUG)) {
|
||||
PR_LOG(GetFontLog(), PR_LOG_DEBUG, (" - Trying to find fonts for: CJK"));
|
||||
}
|
||||
|
||||
nsAutoTArray<nsRefPtr<gfxFontEntry>, 15> fonts;
|
||||
GetCJKPrefFonts(fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
||||
} else {
|
||||
nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
|
||||
if (langGroup) {
|
||||
PR_LOG(GetFontLog(), PR_LOG_DEBUG, (" - Trying to find fonts for: %s", nsAtomCString(langGroup).get()));
|
||||
|
||||
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
||||
GetPrefFonts(langGroup, fonts);
|
||||
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedFont) {
|
||||
nsRefPtr<gfxFont> f = static_cast<gfxFont*>(selectedFont.get());
|
||||
return f.forget();
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
already_AddRefed<gfxFont>
|
||||
gfxFT2FontGroup::WhichSystemFontSupportsChar(uint32_t aCh, int32_t aRunScript)
|
||||
{
|
||||
#if defined(XP_WIN) || defined(ANDROID)
|
||||
FontEntry *fe = static_cast<FontEntry*>
|
||||
(gfxPlatformFontList::PlatformFontList()->
|
||||
SystemFindFontForChar(aCh, aRunScript, &mStyle));
|
||||
if (fe) {
|
||||
nsRefPtr<gfxFT2Font> f = gfxFT2Font::GetOrMakeFont(fe, &mStyle);
|
||||
nsRefPtr<gfxFont> font = f.get();
|
||||
return font.forget();
|
||||
}
|
||||
#else
|
||||
nsRefPtr<gfxFont> selectedFont;
|
||||
nsRefPtr<gfxFont> refFont = GetFontAt(0);
|
||||
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
||||
selectedFont = platform->FindFontForChar(aCh, refFont);
|
||||
if (selectedFont)
|
||||
return selectedFont.forget();
|
||||
#endif
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
#endif // !ANDROID
|
||||
|
||||
/**
|
||||
* gfxFT2Font
|
||||
*/
|
||||
|
|
Загрузка…
Ссылка в новой задаче