2008-08-06 13:48:55 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2012-06-27 17:15:32 -07:00
|
|
|
#if defined(MOZ_WIDGET_GTK)
|
2008-08-06 13:48:55 -07:00
|
|
|
#include "gfxPlatformGtk.h"
|
2008-08-28 04:05:53 -07:00
|
|
|
#define gfxToolkitPlatform gfxPlatformGtk
|
|
|
|
#elif defined(MOZ_WIDGET_QT)
|
|
|
|
#include <qfontinfo.h>
|
2010-03-04 13:51:42 -08:00
|
|
|
#include "gfxQtPlatform.h"
|
2008-08-28 04:05:53 -07:00
|
|
|
#define gfxToolkitPlatform gfxQtPlatform
|
2009-01-22 22:24:29 -08:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
#include "gfxWindowsPlatform.h"
|
|
|
|
#define gfxToolkitPlatform gfxWindowsPlatform
|
2010-05-11 10:27:36 -07:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
#include "gfxAndroidPlatform.h"
|
|
|
|
#define gfxToolkitPlatform gfxAndroidPlatform
|
2008-08-28 04:05:53 -07:00
|
|
|
#endif
|
2010-05-11 10:27:36 -07:00
|
|
|
|
2008-08-06 13:48:55 -07:00
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "gfxFT2Fonts.h"
|
2009-10-30 16:13:41 -07:00
|
|
|
#include "gfxFT2FontBase.h"
|
|
|
|
#include "gfxFT2Utils.h"
|
2011-09-23 04:15:36 -07:00
|
|
|
#include "gfxFT2FontList.h"
|
2008-08-06 13:48:55 -07:00
|
|
|
#include <locale.h>
|
2010-12-09 03:58:16 -08:00
|
|
|
#include "gfxHarfBuzzShaper.h"
|
2011-12-09 14:32:29 -08:00
|
|
|
#include "gfxGraphiteShaper.h"
|
2012-03-29 14:08:43 -07:00
|
|
|
#include "nsGkAtoms.h"
|
2009-01-18 12:14:14 -08:00
|
|
|
#include "nsTArray.h"
|
2009-09-09 08:35:08 -07:00
|
|
|
#include "nsUnicodeRange.h"
|
|
|
|
#include "nsCRT.h"
|
2012-02-08 14:52:57 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2009-09-09 08:35:08 -07:00
|
|
|
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prinit.h"
|
2011-06-11 19:30:16 -07:00
|
|
|
|
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
// 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))))
|
|
|
|
|
2011-09-23 04:15:36 -07:00
|
|
|
#ifndef ANDROID // not needed on Android, we use the generic gfxFontGroup
|
2008-08-06 13:48:55 -07:00
|
|
|
/**
|
|
|
|
* gfxFT2FontGroup
|
|
|
|
*/
|
|
|
|
|
2013-01-21 13:54:42 -08:00
|
|
|
static PRLogModuleInfo *
|
|
|
|
GetFontLog()
|
|
|
|
{
|
|
|
|
static PRLogModuleInfo *sLog;
|
|
|
|
if (!sLog)
|
|
|
|
sLog = PR_NewLogModule("ft2fonts");
|
|
|
|
return sLog;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2008-08-06 13:48:55 -07:00
|
|
|
gfxFT2FontGroup::FontCallback(const nsAString& fontName,
|
2011-07-13 01:40:32 -07:00
|
|
|
const nsACString& genericName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aUseFontSet,
|
2011-07-13 01:40:32 -07:00
|
|
|
void *closure)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString> *sa = static_cast<nsTArray<nsString>*>(closure);
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-01-18 12:14:14 -08:00
|
|
|
if (!fontName.IsEmpty() && !sa->Contains(fontName)) {
|
|
|
|
sa->AppendElement(fontName);
|
2008-08-06 13:48:55 -07:00
|
|
|
#ifdef DEBUG_pavlov
|
|
|
|
printf(" - %s\n", NS_ConvertUTF16toUTF8(fontName).get());
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFT2FontGroup::gfxFT2FontGroup(const nsAString& families,
|
2010-07-15 23:03:45 -07:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
|
|
|
: gfxFontGroup(families, aStyle, aUserFontSet)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
|
|
|
#ifdef DEBUG_pavlov
|
|
|
|
printf("Looking for %s\n", NS_ConvertUTF16toUTF8(families).get());
|
|
|
|
#endif
|
2009-01-18 12:14:14 -08:00
|
|
|
nsTArray<nsString> familyArray;
|
2008-08-06 13:48:55 -07:00
|
|
|
ForEachFont(FontCallback, &familyArray);
|
|
|
|
|
2009-01-18 12:14:14 -08:00
|
|
|
if (familyArray.Length() == 0) {
|
2008-08-06 13:48:55 -07:00
|
|
|
nsAutoString prefFamilies;
|
2012-07-30 07:20:58 -07:00
|
|
|
gfxToolkitPlatform::GetPlatform()->GetPrefFonts(aStyle->language, prefFamilies, nullptr);
|
2008-08-06 13:48:55 -07:00
|
|
|
if (!prefFamilies.IsEmpty()) {
|
2010-02-24 09:57:44 -08:00
|
|
|
ForEachFont(prefFamilies, aStyle->language, FontCallback, &familyArray);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
2009-01-18 12:14:14 -08:00
|
|
|
if (familyArray.Length() == 0) {
|
2009-01-22 22:24:29 -08:00
|
|
|
#if defined(MOZ_WIDGET_QT) /* FIXME DFB */
|
2008-08-06 13:48:55 -07:00
|
|
|
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);
|
2009-01-18 12:14:14 -08:00
|
|
|
familyArray.AppendElement(nsDependentString(static_cast<const PRUnichar *>(fi.family().utf16())));
|
2012-06-27 17:15:32 -07:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2009-01-22 22:24:29 -08:00
|
|
|
FcResult result;
|
2012-07-30 07:20:58 -07:00
|
|
|
FcChar8 *family = nullptr;
|
2009-01-22 22:24:29 -08:00
|
|
|
FcPattern* pat = FcPatternCreate();
|
2012-07-30 07:20:58 -07:00
|
|
|
FcPattern *match = FcFontMatch(nullptr, pat, &result);
|
2009-01-22 22:24:29 -08:00
|
|
|
if (match)
|
|
|
|
FcPatternGetString(match, FC_FAMILY, 0, &family);
|
|
|
|
if (family)
|
2009-01-22 23:59:24 -08:00
|
|
|
familyArray.AppendElement(NS_ConvertUTF8toUTF16((char*)family));
|
2009-01-22 22:24:29 -08:00
|
|
|
#elif defined(XP_WIN)
|
|
|
|
HGDIOBJ hGDI = ::GetStockObject(SYSTEM_FONT);
|
|
|
|
LOGFONTW logFont;
|
2009-09-10 13:52:40 -07:00
|
|
|
if (hGDI && ::GetObjectW(hGDI, sizeof(logFont), &logFont))
|
2009-01-22 22:24:29 -08:00
|
|
|
familyArray.AppendElement(nsDependentString(logFont.lfFaceName));
|
2010-05-11 10:27:36 -07:00
|
|
|
#elif defined(ANDROID)
|
|
|
|
familyArray.AppendElement(NS_LITERAL_STRING("Droid Sans"));
|
2012-03-17 02:39:09 -07:00
|
|
|
familyArray.AppendElement(NS_LITERAL_STRING("Roboto"));
|
2009-01-22 22:24:29 -08:00
|
|
|
#else
|
|
|
|
#error "Platform not supported"
|
2008-08-06 13:48:55 -07:00
|
|
|
#endif
|
2009-01-22 22:24:29 -08:00
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < familyArray.Length(); i++) {
|
2009-01-22 22:24:29 -08:00
|
|
|
nsRefPtr<gfxFT2Font> font = gfxFT2Font::GetOrMakeFont(familyArray[i], &mStyle);
|
2008-08-06 13:48:55 -07:00
|
|
|
if (font) {
|
|
|
|
mFonts.AppendElement(font);
|
|
|
|
}
|
|
|
|
}
|
2009-01-22 22:24:29 -08:00
|
|
|
NS_ASSERTION(mFonts.Length() > 0, "We need at least one font in a fontgroup");
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFT2FontGroup::~gfxFT2FontGroup()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontGroup *
|
|
|
|
gfxFT2FontGroup::Copy(const gfxFontStyle *aStyle)
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return new gfxFT2FontGroup(mFamilies, aStyle, nullptr);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t getUTF8CharAndNext(const uint8_t *aString, uint8_t *aLength)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
|
|
|
*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];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2009-09-09 08:35:08 -07:00
|
|
|
AddFontNameToArray(const nsAString& aName,
|
|
|
|
const nsACString& aGenericName,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aUseFontSet,
|
2009-09-09 08:35:08 -07:00
|
|
|
void *aClosure)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2009-09-09 08:35:08 -07:00
|
|
|
if (!aName.IsEmpty()) {
|
|
|
|
nsTArray<nsString> *list = static_cast<nsTArray<nsString> *>(aClosure);
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
if (list->IndexOf(aName) == list->NoIndex)
|
|
|
|
list->AppendElement(aName);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
void
|
|
|
|
gfxFT2FontGroup::FamilyListToArrayList(const nsString& aFamilies,
|
2010-02-24 09:57:57 -08:00
|
|
|
nsIAtom *aLangGroup,
|
2009-10-07 07:13:40 -07:00
|
|
|
nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2009-09-09 08:35:08 -07:00
|
|
|
nsAutoTArray<nsString, 15> fonts;
|
|
|
|
ForEachFont(aFamilies, aLangGroup, AddFontNameToArray, &fonts);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = fonts.Length();
|
|
|
|
for (uint32_t i = 0; i < len; ++i) {
|
2009-09-09 08:35:08 -07:00
|
|
|
const nsString& str = fonts[i];
|
2009-10-07 07:13:40 -07:00
|
|
|
nsRefPtr<gfxFontEntry> fe = (gfxToolkitPlatform::GetPlatform()->FindFontEntry(str, mStyle));
|
2009-09-09 08:35:08 -07:00
|
|
|
aFontEntryList->AppendElement(fe);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
void gfxFT2FontGroup::GetPrefFonts(nsIAtom *aLangGroup, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
|
|
|
|
{
|
2009-09-09 08:35:08 -07:00
|
|
|
NS_ASSERTION(aLangGroup, "aLangGroup is null");
|
|
|
|
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
2009-10-07 07:13:40 -07:00
|
|
|
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString key;
|
2010-02-24 09:57:57 -08:00
|
|
|
aLangGroup->ToUTF8String(key);
|
2009-09-09 08:35:08 -07:00
|
|
|
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;
|
|
|
|
|
2010-02-24 09:57:57 -08:00
|
|
|
FamilyListToArrayList(fontString, aLangGroup, &fonts);
|
2009-09-09 08:35:08 -07:00
|
|
|
|
|
|
|
platform->SetPrefFontEntries(key, fonts);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-09 08:35:08 -07:00
|
|
|
aFontEntryList.AppendElements(fonts);
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t GetCJKLangGroupIndex(const char *aLangGroup) {
|
|
|
|
int32_t i;
|
2009-09-09 08:35:08 -07:00
|
|
|
for (i = 0; i < COUNT_OF_CJK_LANG_GROUP; i++) {
|
|
|
|
if (!PL_strcasecmp(aLangGroup, sCJKLangGroup[i]))
|
|
|
|
return i;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-09 08:35:08 -07:00
|
|
|
return -1;
|
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
// this function assigns to the array passed in.
|
2009-10-07 07:13:40 -07:00
|
|
|
void gfxFT2FontGroup::GetCJKPrefFonts(nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList) {
|
2009-09-09 08:35:08 -07:00
|
|
|
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString key("x-internal-cjk-");
|
2009-09-09 08:35:08 -07:00
|
|
|
key.AppendInt(mStyle.style);
|
|
|
|
key.Append("-");
|
|
|
|
key.AppendInt(mStyle.weight);
|
|
|
|
|
|
|
|
if (!platform->GetPrefFontEntries(key, &aFontEntryList)) {
|
2012-09-14 03:00:31 -07:00
|
|
|
NS_ENSURE_TRUE_VOID(Preferences::GetRootBranch());
|
2009-09-09 08:35:08 -07:00
|
|
|
// Add the CJK pref fonts from accept languages, the order should be same order
|
2011-06-11 19:30:16 -07:00
|
|
|
nsAdoptingCString list = Preferences::GetLocalizedCString("intl.accept_languages");
|
2009-09-09 08:35:08 -07:00
|
|
|
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;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-09 08:35:08 -07:00
|
|
|
if (p == p_end)
|
|
|
|
break;
|
|
|
|
const char *start = p;
|
|
|
|
while (++p != p_end && *p != kComma)
|
|
|
|
/* nothing */ ;
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString lang(Substring(start, p));
|
2011-10-17 07:59:28 -07:00
|
|
|
lang.CompressWhitespace(false, true);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = GetCJKLangGroupIndex(lang.get());
|
2010-02-24 09:57:57 -08:00
|
|
|
if (index >= 0) {
|
|
|
|
nsCOMPtr<nsIAtom> atom = do_GetAtom(sCJKLangGroup[index]);
|
|
|
|
GetPrefFonts(atom, aFontEntryList);
|
|
|
|
}
|
2009-09-09 08:35:08 -07:00
|
|
|
p++;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
// Add the system locale
|
|
|
|
#ifdef XP_WIN
|
|
|
|
switch (::GetACP()) {
|
2012-03-29 14:08:43 -07:00
|
|
|
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;
|
2009-09-09 08:35:08 -07:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
const char *ctype = setlocale(LC_CTYPE, NULL);
|
|
|
|
if (ctype) {
|
|
|
|
if (!PL_strncasecmp(ctype, "ja", 2)) {
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::Japanese, aFontEntryList);
|
2009-09-09 08:35:08 -07:00
|
|
|
} else if (!PL_strncasecmp(ctype, "zh_cn", 5)) {
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::zh_cn, aFontEntryList);
|
2009-09-09 08:35:08 -07:00
|
|
|
} else if (!PL_strncasecmp(ctype, "zh_hk", 5)) {
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::zh_hk, aFontEntryList);
|
2009-09-09 08:35:08 -07:00
|
|
|
} else if (!PL_strncasecmp(ctype, "zh_tw", 5)) {
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::zh_tw, aFontEntryList);
|
2009-09-09 08:35:08 -07:00
|
|
|
} else if (!PL_strncasecmp(ctype, "ko", 2)) {
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::ko, aFontEntryList);
|
2009-09-09 08:35:08 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// last resort...
|
2012-03-29 14:08:43 -07:00
|
|
|
GetPrefFonts(nsGkAtoms::Japanese, aFontEntryList);
|
|
|
|
GetPrefFonts(nsGkAtoms::ko, aFontEntryList);
|
|
|
|
GetPrefFonts(nsGkAtoms::zh_cn, aFontEntryList);
|
|
|
|
GetPrefFonts(nsGkAtoms::zh_hk, aFontEntryList);
|
|
|
|
GetPrefFonts(nsGkAtoms::zh_tw, aFontEntryList);
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
platform->SetPrefFontEntries(key, aFontEntryList);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
2009-09-09 08:35:08 -07:00
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
already_AddRefed<gfxFT2Font>
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFT2FontGroup::WhichFontSupportsChar(const nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList, uint32_t aCh)
|
2009-09-09 08:35:08 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < aFontEntryList.Length(); i++) {
|
2009-10-07 07:13:40 -07:00
|
|
|
gfxFontEntry *fe = aFontEntryList[i].get();
|
2009-09-09 08:35:08 -07:00
|
|
|
if (fe->HasCharacter(aCh)) {
|
|
|
|
nsRefPtr<gfxFT2Font> font =
|
2009-10-07 07:13:40 -07:00
|
|
|
gfxFT2Font::GetOrMakeFont(static_cast<FontEntry*>(fe), &mStyle);
|
2009-09-09 08:35:08 -07:00
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
}
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
already_AddRefed<gfxFont>
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFT2FontGroup::WhichPrefFontSupportsChar(uint32_t aCh)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2009-09-09 08:35:08 -07:00
|
|
|
if (aCh > 0xFFFF)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
nsRefPtr<gfxFT2Font> selectedFont;
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2010-02-24 09:57:44 -08:00
|
|
|
// check out the style's language
|
2009-10-07 07:13:40 -07:00
|
|
|
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
2010-02-24 09:57:57 -08:00
|
|
|
GetPrefFonts(mStyle.language, fonts);
|
2009-09-09 08:35:08 -07:00
|
|
|
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
// otherwise search prefs
|
|
|
|
if (!selectedFont) {
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t unicodeRange = FindCharUnicodeRange(aCh);
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
/* special case CJK */
|
|
|
|
if (unicodeRange == kRangeSetCJK) {
|
2012-10-29 16:32:10 -07:00
|
|
|
if (PR_LOG_TEST(GetFontLog(), PR_LOG_DEBUG)) {
|
|
|
|
PR_LOG(GetFontLog(), PR_LOG_DEBUG, (" - Trying to find fonts for: CJK"));
|
2009-09-10 13:52:40 -07:00
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-10-07 07:13:40 -07:00
|
|
|
nsAutoTArray<nsRefPtr<gfxFontEntry>, 15> fonts;
|
2009-09-09 08:35:08 -07:00
|
|
|
GetCJKPrefFonts(fonts);
|
|
|
|
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
2008-08-06 13:48:55 -07:00
|
|
|
} else {
|
2010-02-24 09:57:57 -08:00
|
|
|
nsIAtom *langGroup = LangGroupFromUnicodeRange(unicodeRange);
|
2009-09-09 08:35:08 -07:00
|
|
|
if (langGroup) {
|
2012-10-29 16:32:10 -07:00
|
|
|
PR_LOG(GetFontLog(), PR_LOG_DEBUG, (" - Trying to find fonts for: %s", nsAtomCString(langGroup).get()));
|
2010-03-10 12:47:45 -08:00
|
|
|
|
2009-10-07 07:13:40 -07:00
|
|
|
nsAutoTArray<nsRefPtr<gfxFontEntry>, 5> fonts;
|
2009-09-09 08:35:08 -07:00
|
|
|
GetPrefFonts(langGroup, fonts);
|
|
|
|
selectedFont = WhichFontSupportsChar(fonts, aCh);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-09 08:35:08 -07:00
|
|
|
if (selectedFont) {
|
|
|
|
nsRefPtr<gfxFont> f = static_cast<gfxFont*>(selectedFont.get());
|
|
|
|
return f.forget();
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-09-09 08:35:08 -07:00
|
|
|
}
|
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
already_AddRefed<gfxFont>
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFT2FontGroup::WhichSystemFontSupportsChar(uint32_t aCh, int32_t aRunScript)
|
2009-09-09 08:35:08 -07:00
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
#if defined(XP_WIN) || defined(ANDROID)
|
2009-10-07 07:13:40 -07:00
|
|
|
FontEntry *fe = static_cast<FontEntry*>
|
2012-03-08 18:05:24 -08:00
|
|
|
(gfxPlatformFontList::PlatformFontList()->
|
|
|
|
SystemFindFontForChar(aCh, aRunScript, &mStyle));
|
2009-10-07 07:13:40 -07:00
|
|
|
if (fe) {
|
|
|
|
nsRefPtr<gfxFT2Font> f = gfxFT2Font::GetOrMakeFont(fe, &mStyle);
|
|
|
|
nsRefPtr<gfxFont> font = f.get();
|
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
#else
|
2009-09-09 08:35:08 -07:00
|
|
|
nsRefPtr<gfxFont> selectedFont;
|
2010-07-15 23:03:45 -07:00
|
|
|
nsRefPtr<gfxFont> refFont = GetFontAt(0);
|
2009-09-09 08:35:08 -07:00
|
|
|
gfxToolkitPlatform *platform = gfxToolkitPlatform::GetPlatform();
|
|
|
|
selectedFont = platform->FindFontForChar(aCh, refFont);
|
|
|
|
if (selectedFont)
|
|
|
|
return selectedFont.forget();
|
2009-10-07 07:13:40 -07:00
|
|
|
#endif
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
2011-09-23 04:15:36 -07:00
|
|
|
#endif // !ANDROID
|
|
|
|
|
2010-12-09 03:57:23 -08:00
|
|
|
/**
|
|
|
|
* gfxFT2Font
|
|
|
|
*/
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxFT2Font::ShapeText(gfxContext *aContext,
|
|
|
|
const PRUnichar *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
|
|
|
gfxShapedText *aShapedText,
|
|
|
|
bool aPreferPlatformShaping)
|
2010-12-09 03:57:23 -08:00
|
|
|
{
|
2011-09-28 23:19:26 -07:00
|
|
|
bool ok = false;
|
2010-12-09 03:58:16 -08:00
|
|
|
|
2011-12-09 14:32:29 -08:00
|
|
|
if (FontCanSupportGraphite()) {
|
|
|
|
if (gfxPlatform::GetPlatform()->UseGraphiteShaping()) {
|
|
|
|
if (!mGraphiteShaper) {
|
|
|
|
mGraphiteShaper = new gfxGraphiteShaper(this);
|
|
|
|
}
|
2013-01-04 10:35:37 -08:00
|
|
|
ok = mGraphiteShaper->ShapeText(aContext, aText,
|
|
|
|
aOffset, aLength,
|
|
|
|
aScript, aShapedText);
|
2011-12-09 14:32:29 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
if (!ok && gfxPlatform::GetPlatform()->UseHarfBuzzForScript(aScript)) {
|
2011-02-17 16:04:34 -08:00
|
|
|
if (!mHarfBuzzShaper) {
|
2011-02-16 15:46:00 -08:00
|
|
|
gfxFT2LockedFace face(this);
|
|
|
|
mFUnitsConvFactor = face.XScale();
|
|
|
|
|
|
|
|
mHarfBuzzShaper = new gfxHarfBuzzShaper(this);
|
|
|
|
}
|
2013-01-04 10:35:37 -08:00
|
|
|
ok = mHarfBuzzShaper->ShapeText(aContext, aText,
|
|
|
|
aOffset, aLength,
|
|
|
|
aScript, aShapedText);
|
2010-12-09 03:58:16 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!ok) {
|
2013-01-04 10:35:37 -08:00
|
|
|
AddRange(aText, aOffset, aLength, aShapedText);
|
2010-12-09 03:58:16 -08:00
|
|
|
}
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
PostShapingFixup(aContext, aText, aOffset, aLength, aShapedText);
|
2011-09-02 13:18:10 -07:00
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxFT2Font::AddRange(const PRUnichar *aText, uint32_t aOffset,
|
|
|
|
uint32_t aLength, gfxShapedText *aShapedText)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2013-01-04 10:35:37 -08:00
|
|
|
const uint32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
|
2008-08-06 13:48:55 -07:00
|
|
|
// we'll pass this in/figure it out dynamically, but at this point there can be only one face.
|
2010-12-09 03:57:23 -08:00
|
|
|
gfxFT2LockedFace faceLock(this);
|
2009-10-30 16:13:41 -07:00
|
|
|
FT_Face face = faceLock.get();
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph *charGlyphs =
|
|
|
|
aShapedText->GetCharacterGlyphs();
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
const gfxFT2Font::CachedGlyphData *cgd = nullptr, *cgdNext = nullptr;
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2010-12-09 03:57:23 -08:00
|
|
|
FT_UInt spaceGlyph = GetSpaceGlyph();
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
for (uint32_t i = 0; i < aLength; i++, aOffset++) {
|
|
|
|
PRUnichar ch = aText[i];
|
2008-08-06 13:48:55 -07:00
|
|
|
|
|
|
|
if (ch == 0) {
|
|
|
|
// treat this null byte as a missing glyph, don't create a glyph for it
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->SetMissingGlyph(aOffset, 0, this);
|
2008-08-06 13:48:55 -07:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2010-12-09 03:57:23 -08:00
|
|
|
NS_ASSERTION(!gfxFontGroup::IsInvalidChar(ch), "Invalid char detected");
|
2009-09-10 13:52:40 -07:00
|
|
|
|
|
|
|
if (cgdNext) {
|
|
|
|
cgd = cgdNext;
|
2012-07-30 07:20:58 -07:00
|
|
|
cgdNext = nullptr;
|
2009-09-10 13:52:40 -07:00
|
|
|
} else {
|
2010-12-09 03:57:23 -08:00
|
|
|
cgd = GetGlyphDataForChar(ch);
|
2009-09-10 13:52:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_UInt gid = cgd->glyphIndex;
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t advance = 0;
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
if (gid == 0) {
|
2008-08-06 13:48:55 -07:00
|
|
|
advance = -1; // trigger the missing glyphs case below
|
|
|
|
} else {
|
|
|
|
// find next character and its glyph -- in case they exist
|
|
|
|
// and exist in the current font face -- to compute kerning
|
2011-12-06 04:39:19 -08:00
|
|
|
PRUnichar chNext = 0;
|
2008-08-06 13:48:55 -07:00
|
|
|
FT_UInt gidNext = 0;
|
|
|
|
FT_Pos lsbDeltaNext = 0;
|
|
|
|
|
2013-01-04 10:35:37 -08:00
|
|
|
if (FT_HAS_KERNING(face) && i + 1 < aLength) {
|
|
|
|
chNext = aText[i + 1];
|
2008-08-06 13:48:55 -07:00
|
|
|
if (chNext != 0) {
|
2010-12-09 03:57:23 -08:00
|
|
|
cgdNext = GetGlyphDataForChar(chNext);
|
2009-09-10 13:52:40 -07:00
|
|
|
gidNext = cgdNext->glyphIndex;
|
|
|
|
if (gidNext && gidNext != spaceGlyph)
|
|
|
|
lsbDeltaNext = cgdNext->lsbDelta;
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
advance = cgd->xAdvance;
|
2008-08-06 13:48:55 -07:00
|
|
|
|
|
|
|
// now add kerning to the current glyph's advance
|
|
|
|
if (chNext && gidNext) {
|
|
|
|
FT_Vector kerning; kerning.x = 0;
|
|
|
|
FT_Get_Kerning(face, gid, gidNext, FT_KERNING_DEFAULT, &kerning);
|
|
|
|
advance += kerning.x;
|
2009-09-10 13:52:40 -07:00
|
|
|
if (cgd->rsbDelta - lsbDeltaNext >= 32) {
|
2008-08-06 13:48:55 -07:00
|
|
|
advance -= 64;
|
2009-09-10 13:52:40 -07:00
|
|
|
} else if (cgd->rsbDelta - lsbDeltaNext < -32) {
|
2008-08-06 13:48:55 -07:00
|
|
|
advance += 64;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-09 12:18:17 -08:00
|
|
|
// convert 26.6 fixed point to app units
|
|
|
|
// round rather than truncate to nearest pixel
|
|
|
|
// because these advances are often scaled
|
|
|
|
advance = ((advance * appUnitsPerDevUnit + 32) >> 6);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (advance >= 0 &&
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph::IsSimpleAdvance(advance) &&
|
|
|
|
gfxShapedText::CompressedGlyph::IsSimpleGlyphID(gid)) {
|
|
|
|
charGlyphs[aOffset].SetSimpleGlyph(advance, gid);
|
2008-08-06 13:48:55 -07:00
|
|
|
} else if (gid == 0) {
|
|
|
|
// gid = 0 only happens when the glyph is missing from the font
|
2013-01-04 10:35:37 -08:00
|
|
|
aShapedText->SetMissingGlyph(aOffset, ch, this);
|
2008-08-06 13:48:55 -07:00
|
|
|
} else {
|
|
|
|
gfxTextRun::DetailedGlyph details;
|
|
|
|
details.mGlyphID = gid;
|
2013-01-04 10:35:37 -08:00
|
|
|
NS_ASSERTION(details.mGlyphID == gid,
|
|
|
|
"Seriously weird glyph ID detected!");
|
2008-08-06 13:48:55 -07:00
|
|
|
details.mAdvance = advance;
|
|
|
|
details.mXOffset = 0;
|
|
|
|
details.mYOffset = 0;
|
2013-01-04 10:35:37 -08:00
|
|
|
gfxShapedText::CompressedGlyph g;
|
|
|
|
g.SetComplex(charGlyphs[aOffset].IsClusterStart(), true, 1);
|
|
|
|
aShapedText->SetGlyphs(aOffset, g, &details);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
}
|
2009-09-10 13:52:40 -07:00
|
|
|
}
|
2008-08-06 13:48:55 -07:00
|
|
|
|
2009-10-30 16:13:41 -07:00
|
|
|
gfxFT2Font::gfxFT2Font(cairo_scaled_font_t *aCairoFont,
|
2011-09-23 04:16:13 -07:00
|
|
|
FT2FontEntry *aFontEntry,
|
2011-07-26 07:04:55 -07:00
|
|
|
const gfxFontStyle *aFontStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNeedsBold)
|
2009-10-30 16:13:41 -07:00
|
|
|
: gfxFT2FontBase(aCairoFont, aFontEntry, aFontStyle)
|
2008-08-06 13:48:55 -07:00
|
|
|
{
|
2008-08-28 04:05:53 -07:00
|
|
|
NS_ASSERTION(mFontEntry, "Unable to find font entry for font. Something is whack.");
|
2011-09-02 13:18:25 -07:00
|
|
|
mApplySyntheticBold = aNeedsBold;
|
2009-09-10 13:52:40 -07:00
|
|
|
mCharGlyphCache.Init(64);
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFT2Font::~gfxFT2Font()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_font_face_t *
|
|
|
|
gfxFT2Font::CairoFontFace()
|
|
|
|
{
|
2008-08-28 04:05:53 -07:00
|
|
|
return GetFontEntry()->CairoFontFace();
|
2008-08-06 13:48:55 -07:00
|
|
|
}
|
|
|
|
|
2009-01-22 22:24:29 -08:00
|
|
|
/**
|
|
|
|
* Look up the font in the gfxFont cache. If we don't find it, create one.
|
|
|
|
* In either case, add a ref, append it to the aFonts array, and return it ---
|
|
|
|
* except for OOM in which case we do nothing and return null.
|
|
|
|
*/
|
|
|
|
already_AddRefed<gfxFT2Font>
|
2011-09-23 04:15:36 -07:00
|
|
|
gfxFT2Font::GetOrMakeFont(const nsAString& aName, const gfxFontStyle *aStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNeedsBold)
|
2009-01-22 22:24:29 -08:00
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
#ifdef ANDROID
|
2011-09-23 04:16:13 -07:00
|
|
|
FT2FontEntry *fe = static_cast<FT2FontEntry*>
|
2011-09-23 04:15:36 -07:00
|
|
|
(gfxPlatformFontList::PlatformFontList()->
|
|
|
|
FindFontForFamily(aName, aStyle, aNeedsBold));
|
|
|
|
#else
|
2011-09-23 04:16:13 -07:00
|
|
|
FT2FontEntry *fe = static_cast<FT2FontEntry*>
|
2009-10-07 07:13:40 -07:00
|
|
|
(gfxToolkitPlatform::GetPlatform()->FindFontEntry(aName, *aStyle));
|
2011-09-23 04:15:36 -07:00
|
|
|
#endif
|
2009-04-22 22:29:47 -07:00
|
|
|
if (!fe) {
|
2009-09-10 13:52:40 -07:00
|
|
|
NS_WARNING("Failed to find font entry for font!");
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-04-22 22:29:47 -07:00
|
|
|
}
|
2009-01-22 22:24:29 -08:00
|
|
|
|
2011-07-26 07:04:55 -07:00
|
|
|
nsRefPtr<gfxFT2Font> font = GetOrMakeFont(fe, aStyle, aNeedsBold);
|
2009-09-09 08:35:08 -07:00
|
|
|
return font.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxFT2Font>
|
2011-09-23 04:16:13 -07:00
|
|
|
gfxFT2Font::GetOrMakeFont(FT2FontEntry *aFontEntry, const gfxFontStyle *aStyle,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNeedsBold)
|
2009-09-09 08:35:08 -07:00
|
|
|
{
|
2011-09-23 02:34:42 -07:00
|
|
|
nsRefPtr<gfxFont> font = gfxFontCache::GetCache()->Lookup(aFontEntry, aStyle);
|
2009-04-22 22:29:47 -07:00
|
|
|
if (!font) {
|
2011-09-23 04:16:13 -07:00
|
|
|
cairo_scaled_font_t *scaledFont = aFontEntry->CreateScaledFont(aStyle);
|
2011-07-26 07:04:55 -07:00
|
|
|
font = new gfxFT2Font(scaledFont, aFontEntry, aStyle, aNeedsBold);
|
2009-10-30 16:13:41 -07:00
|
|
|
cairo_scaled_font_destroy(scaledFont);
|
2009-01-22 22:24:29 -08:00
|
|
|
if (!font)
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2009-01-22 22:24:29 -08:00
|
|
|
gfxFontCache::GetCache()->AddNew(font);
|
|
|
|
}
|
2013-04-28 04:52:10 -07:00
|
|
|
return font.forget().downcast<gfxFT2Font>();
|
2009-01-22 22:24:29 -08:00
|
|
|
}
|
|
|
|
|
2009-09-10 13:52:40 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
gfxFT2Font::FillGlyphDataForChar(uint32_t ch, CachedGlyphData *gd)
|
2009-09-10 13:52:40 -07:00
|
|
|
{
|
2009-10-30 16:13:41 -07:00
|
|
|
gfxFT2LockedFace faceLock(this);
|
|
|
|
FT_Face face = faceLock.get();
|
2009-09-10 13:52:40 -07:00
|
|
|
|
2012-05-21 14:09:54 -07:00
|
|
|
if (!face->charmap || face->charmap->encoding != FT_ENCODING_UNICODE) {
|
|
|
|
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
|
|
|
|
}
|
2009-09-10 13:52:40 -07:00
|
|
|
FT_UInt gid = FT_Get_Char_Index(face, ch);
|
|
|
|
|
|
|
|
if (gid == 0) {
|
|
|
|
// this font doesn't support this char!
|
|
|
|
NS_ASSERTION(gid != 0, "We don't have a glyph, but font indicated that it supported this char in tables?");
|
|
|
|
gd->glyphIndex = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-08 14:52:57 -08:00
|
|
|
FT_Int32 flags = gfxPlatform::GetPlatform()->FontHintingEnabled() ?
|
|
|
|
FT_LOAD_DEFAULT :
|
|
|
|
(FT_LOAD_NO_AUTOHINT | FT_LOAD_NO_HINTING);
|
|
|
|
FT_Error err = FT_Load_Glyph(face, gid, flags);
|
2009-09-10 13:52:40 -07:00
|
|
|
|
|
|
|
if (err) {
|
|
|
|
// hmm, this is weird, we failed to load a glyph that we had?
|
|
|
|
NS_WARNING("Failed to load glyph that we got from Get_Char_index");
|
|
|
|
|
|
|
|
gd->glyphIndex = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gd->glyphIndex = gid;
|
|
|
|
gd->lsbDelta = face->glyph->lsb_delta;
|
|
|
|
gd->rsbDelta = face->glyph->rsb_delta;
|
|
|
|
gd->xAdvance = face->glyph->advance.x;
|
|
|
|
}
|
2012-03-23 05:14:16 -07:00
|
|
|
|
|
|
|
void
|
|
|
|
gfxFT2Font::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const
|
|
|
|
{
|
|
|
|
gfxFont::SizeOfExcludingThis(aMallocSizeOf, aSizes);
|
|
|
|
aSizes->mFontInstances +=
|
2012-07-30 07:20:58 -07:00
|
|
|
mCharGlyphCache.SizeOfExcludingThis(nullptr, aMallocSizeOf);
|
2012-03-23 05:14:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxFT2Font::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const
|
|
|
|
{
|
|
|
|
aSizes->mFontInstances += aMallocSizeOf(this);
|
|
|
|
SizeOfExcludingThis(aMallocSizeOf, aSizes);
|
|
|
|
}
|