2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2015-05-13 08:11:25 +03: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/. */
|
|
|
|
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
#include "gfxFcPlatformFontList.h"
|
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxFontConstants.h"
|
|
|
|
#include "gfxFT2Utils.h"
|
|
|
|
#include "gfxPlatform.h"
|
|
|
|
#include "mozilla/ArrayUtils.h"
|
2017-11-02 23:29:33 +03:00
|
|
|
#include "mozilla/dom/ContentChild.h"
|
|
|
|
#include "mozilla/dom/ContentParent.h"
|
2015-11-16 02:48:40 +03:00
|
|
|
#include "mozilla/Preferences.h"
|
2016-08-17 01:41:12 +03:00
|
|
|
#include "mozilla/Sprintf.h"
|
2021-01-18 23:04:36 +03:00
|
|
|
#include "mozilla/StaticPrefs_gfx.h"
|
2021-03-08 19:23:39 +03:00
|
|
|
#include "mozilla/Telemetry.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsUnicodeProperties.h"
|
2015-05-13 08:11:26 +03:00
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2015-11-16 02:48:40 +03:00
|
|
|
#include "nsCharSeparatedTokenizer.h"
|
2017-11-02 23:29:33 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2019-04-27 18:38:28 +03:00
|
|
|
#include "SharedFontList-impl.h"
|
2020-04-03 02:12:56 +03:00
|
|
|
#include "StandardFonts-linux.inc"
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-09-02 21:12:32 +03:00
|
|
|
#include "mozilla/gfx/HelpersCairo.h"
|
|
|
|
|
2019-10-02 00:56:30 +03:00
|
|
|
#include <cairo-ft.h>
|
2015-05-13 08:11:25 +03:00
|
|
|
#include <fontconfig/fcfreetype.h>
|
2018-01-18 22:27:41 +03:00
|
|
|
#include <dlfcn.h>
|
2017-11-02 23:29:33 +03:00
|
|
|
#include <unistd.h>
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
# include <gdk/gdk.h>
|
2021-05-01 23:00:31 +03:00
|
|
|
# include <gtk/gtk.h>
|
2015-11-20 07:35:15 +03:00
|
|
|
# include "gfxPlatformGtk.h"
|
2021-03-11 17:32:53 +03:00
|
|
|
# include "mozilla/WidgetUtilsGtk.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
#endif
|
|
|
|
|
2016-07-20 21:18:21 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
# include "mozilla/X11Util.h"
|
|
|
|
#endif
|
|
|
|
|
2019-03-19 01:31:59 +03:00
|
|
|
#if defined(MOZ_SANDBOX) && defined(XP_LINUX)
|
2017-11-09 19:54:30 +03:00
|
|
|
# include "mozilla/SandboxBrokerPolicyFactory.h"
|
|
|
|
# include "mozilla/SandboxSettings.h"
|
|
|
|
#endif
|
|
|
|
|
2018-01-18 22:27:41 +03:00
|
|
|
#include FT_MULTIPLE_MASTERS_H
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
using namespace mozilla;
|
2017-04-07 00:41:02 +03:00
|
|
|
using namespace mozilla::gfx;
|
2015-05-13 08:11:25 +03:00
|
|
|
using namespace mozilla::unicode;
|
|
|
|
|
|
|
|
#ifndef FC_POSTSCRIPT_NAME
|
|
|
|
# define FC_POSTSCRIPT_NAME "postscriptname" /* String */
|
|
|
|
#endif
|
2018-04-25 09:18:23 +03:00
|
|
|
#ifndef FC_VARIABLE
|
|
|
|
# define FC_VARIABLE "variable" /* Bool */
|
|
|
|
#endif
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
#define PRINTING_FC_PROPERTY "gfx.printing"
|
|
|
|
|
2015-05-21 23:22:04 +03:00
|
|
|
#define LOG_FONTLIST(args) \
|
|
|
|
MOZ_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), LogLevel::Debug, args)
|
2015-06-04 01:22:28 +03:00
|
|
|
#define LOG_FONTLIST_ENABLED() \
|
2015-05-13 08:11:25 +03:00
|
|
|
MOZ_LOG_TEST(gfxPlatform::GetLog(eGfxLog_fontlist), LogLevel::Debug)
|
2015-06-04 01:22:28 +03:00
|
|
|
#define LOG_CMAPDATA_ENABLED() \
|
2015-05-13 08:11:25 +03:00
|
|
|
MOZ_LOG_TEST(gfxPlatform::GetLog(eGfxLog_cmapdata), LogLevel::Debug)
|
|
|
|
|
|
|
|
static const FcChar8* ToFcChar8Ptr(const char* aStr) {
|
|
|
|
return reinterpret_cast<const FcChar8*>(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const char* ToCharPtr(const FcChar8* aStr) {
|
|
|
|
return reinterpret_cast<const char*>(aStr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// canonical name ==> first en name or first name if no en name
|
|
|
|
// This is the required logic for fullname lookups as per CSS3 Fonts spec.
|
|
|
|
static uint32_t FindCanonicalNameIndex(FcPattern* aFont,
|
|
|
|
const char* aLangField) {
|
|
|
|
uint32_t n = 0, en = 0;
|
|
|
|
FcChar8* lang;
|
|
|
|
while (FcPatternGetString(aFont, aLangField, n, &lang) == FcResultMatch) {
|
|
|
|
// look for 'en' or variants, en-US, en-JP etc.
|
|
|
|
uint32_t len = strlen(ToCharPtr(lang));
|
|
|
|
bool enPrefix = (strncmp(ToCharPtr(lang), "en", 2) == 0);
|
|
|
|
if (enPrefix && (len == 2 || (len > 2 && aLangField[2] == '-'))) {
|
|
|
|
en = n;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
return en;
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
static void GetFaceNames(FcPattern* aFont, const nsACString& aFamilyName,
|
|
|
|
nsACString& aPostscriptName, nsACString& aFullname) {
|
2015-05-13 08:11:25 +03:00
|
|
|
// get the Postscript name
|
|
|
|
FcChar8* psname;
|
|
|
|
if (FcPatternGetString(aFont, FC_POSTSCRIPT_NAME, 0, &psname) ==
|
|
|
|
FcResultMatch) {
|
2018-09-12 22:34:57 +03:00
|
|
|
aPostscriptName = ToCharPtr(psname);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// get the canonical fullname (i.e. en name or first name)
|
|
|
|
uint32_t en = FindCanonicalNameIndex(aFont, FC_FULLNAMELANG);
|
|
|
|
FcChar8* fullname;
|
|
|
|
if (FcPatternGetString(aFont, FC_FULLNAME, en, &fullname) == FcResultMatch) {
|
2018-09-12 22:34:57 +03:00
|
|
|
aFullname = ToCharPtr(fullname);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// if have fullname, done
|
|
|
|
if (!aFullname.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// otherwise, set the fullname to family + style name [en] and use that
|
2018-09-12 22:34:57 +03:00
|
|
|
aFullname = aFamilyName;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// figure out the en style name
|
|
|
|
en = FindCanonicalNameIndex(aFont, FC_STYLELANG);
|
2018-09-12 22:34:57 +03:00
|
|
|
nsAutoCString style;
|
2015-05-13 08:11:25 +03:00
|
|
|
FcChar8* stylename = nullptr;
|
|
|
|
FcPatternGetString(aFont, FC_STYLE, en, &stylename);
|
|
|
|
if (stylename) {
|
2018-09-12 22:34:57 +03:00
|
|
|
style = ToCharPtr(stylename);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!style.IsEmpty() && !style.EqualsLiteral("Regular")) {
|
|
|
|
aFullname.Append(' ');
|
|
|
|
aFullname.Append(style);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static FontWeight MapFcWeight(int aFcWeight) {
|
2017-02-09 15:39:27 +03:00
|
|
|
if (aFcWeight <= (FC_WEIGHT_THIN + FC_WEIGHT_EXTRALIGHT) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(100);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_EXTRALIGHT + FC_WEIGHT_LIGHT) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(200);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_LIGHT + FC_WEIGHT_BOOK) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(300);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_REGULAR + FC_WEIGHT_MEDIUM) / 2) {
|
|
|
|
// This includes FC_WEIGHT_BOOK
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(400);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_MEDIUM + FC_WEIGHT_DEMIBOLD) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(500);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_DEMIBOLD + FC_WEIGHT_BOLD) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(600);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_BOLD + FC_WEIGHT_EXTRABOLD) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(700);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= (FC_WEIGHT_EXTRABOLD + FC_WEIGHT_BLACK) / 2) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(800);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
if (aFcWeight <= FC_WEIGHT_BLACK) {
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(900);
|
2017-02-09 15:39:27 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// including FC_WEIGHT_EXTRABLACK
|
2018-04-13 22:34:37 +03:00
|
|
|
return FontWeight(901);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2018-04-23 17:52:20 +03:00
|
|
|
// TODO(emilio, jfkthame): I think this can now be more fine-grained.
|
2015-05-13 08:11:25 +03:00
|
|
|
static FontStretch MapFcWidth(int aFcWidth) {
|
|
|
|
if (aFcWidth <= (FC_WIDTH_ULTRACONDENSED + FC_WIDTH_EXTRACONDENSED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::UltraCondensed();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_EXTRACONDENSED + FC_WIDTH_CONDENSED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::ExtraCondensed();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_CONDENSED + FC_WIDTH_SEMICONDENSED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::Condensed();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_SEMICONDENSED + FC_WIDTH_NORMAL) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::SemiCondensed();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_NORMAL + FC_WIDTH_SEMIEXPANDED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::Normal();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_SEMIEXPANDED + FC_WIDTH_EXPANDED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::SemiExpanded();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_EXPANDED + FC_WIDTH_EXTRAEXPANDED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::Expanded();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
if (aFcWidth <= (FC_WIDTH_EXTRAEXPANDED + FC_WIDTH_ULTRAEXPANDED) / 2) {
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::ExtraExpanded();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2018-04-23 17:52:20 +03:00
|
|
|
return FontStretch::UltraExpanded();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
static void GetFontProperties(FcPattern* aFontPattern, WeightRange* aWeight,
|
|
|
|
StretchRange* aStretch,
|
2021-06-06 23:30:14 +03:00
|
|
|
SlantStyleRange* aSlantStyle,
|
|
|
|
uint16_t* aSize = nullptr) {
|
2017-08-01 13:25:35 +03:00
|
|
|
// weight
|
|
|
|
int weight;
|
|
|
|
if (FcPatternGetInteger(aFontPattern, FC_WEIGHT, 0, &weight) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
weight = FC_WEIGHT_REGULAR;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
*aWeight = WeightRange(MapFcWeight(weight));
|
2017-08-01 13:25:35 +03:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
// width
|
2015-05-13 08:11:25 +03:00
|
|
|
int width;
|
2018-01-06 13:58:23 +03:00
|
|
|
if (FcPatternGetInteger(aFontPattern, FC_WIDTH, 0, &width) != FcResultMatch) {
|
2015-05-13 08:11:25 +03:00
|
|
|
width = FC_WIDTH_NORMAL;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
*aStretch = StretchRange(MapFcWidth(width));
|
|
|
|
|
|
|
|
// italic
|
|
|
|
int slant;
|
|
|
|
if (FcPatternGetInteger(aFontPattern, FC_SLANT, 0, &slant) != FcResultMatch) {
|
|
|
|
slant = FC_SLANT_ROMAN;
|
|
|
|
}
|
|
|
|
if (slant == FC_SLANT_OBLIQUE) {
|
|
|
|
*aSlantStyle = SlantStyleRange(FontSlantStyle::Oblique());
|
|
|
|
} else if (slant > 0) {
|
|
|
|
*aSlantStyle = SlantStyleRange(FontSlantStyle::Italic());
|
|
|
|
}
|
2021-06-06 23:30:14 +03:00
|
|
|
|
|
|
|
if (aSize) {
|
|
|
|
// pixel size, or zero if scalable
|
|
|
|
FcBool scalable;
|
|
|
|
if (FcPatternGetBool(aFontPattern, FC_SCALABLE, 0, &scalable) ==
|
|
|
|
FcResultMatch &&
|
|
|
|
scalable) {
|
|
|
|
*aSize = 0;
|
|
|
|
} else {
|
|
|
|
double size;
|
|
|
|
if (FcPatternGetDouble(aFontPattern, FC_PIXEL_SIZE, 0, &size) ==
|
|
|
|
FcResultMatch) {
|
|
|
|
*aSize = uint16_t(NS_round(size));
|
|
|
|
} else {
|
|
|
|
*aSize = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsACString& aFaceName,
|
|
|
|
FcPattern* aFontPattern,
|
|
|
|
bool aIgnoreFcCharmap)
|
2019-10-02 00:56:30 +03:00
|
|
|
: gfxFT2FontEntryBase(aFaceName),
|
2019-04-27 18:38:28 +03:00
|
|
|
mFontPattern(aFontPattern),
|
|
|
|
mFTFaceInitialized(false),
|
|
|
|
mIgnoreFcCharmap(aIgnoreFcCharmap),
|
2021-06-14 15:32:37 +03:00
|
|
|
mHasVariationsInitialized(false) {
|
2019-04-27 18:38:28 +03:00
|
|
|
GetFontProperties(aFontPattern, &mWeightRange, &mStretchRange, &mStyleRange);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-01-06 13:58:23 +03:00
|
|
|
gfxFontEntry* gfxFontconfigFontEntry::Clone() const {
|
|
|
|
MOZ_ASSERT(!IsUserFont(), "we can only clone installed fonts!");
|
2017-08-01 13:25:35 +03:00
|
|
|
return new gfxFontconfigFontEntry(Name(), mFontPattern, mIgnoreFcCharmap);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
static already_AddRefed<FcPattern> CreatePatternForFace(FT_Face aFace) {
|
2018-01-06 13:58:23 +03:00
|
|
|
// Use fontconfig to fill out the pattern from the FTFace.
|
|
|
|
// The "file" argument cannot be nullptr (in fontconfig-2.6.0 at
|
|
|
|
// least). The dummy file passed here is removed below.
|
|
|
|
//
|
|
|
|
// When fontconfig scans the system fonts, FcConfigGetBlanks(nullptr)
|
|
|
|
// is passed as the "blanks" argument, which provides that unexpectedly
|
|
|
|
// blank glyphs are elided. Here, however, we pass nullptr for
|
|
|
|
// "blanks", effectively assuming that, if the font has a blank glyph,
|
|
|
|
// then the author intends any associated character to be rendered
|
|
|
|
// blank.
|
2020-09-17 02:11:13 +03:00
|
|
|
RefPtr<FcPattern> pattern =
|
|
|
|
dont_AddRef(FcFreeTypeQueryFace(aFace, ToFcChar8Ptr(""), 0, nullptr));
|
2018-01-06 13:58:23 +03:00
|
|
|
// given that we have a FT_Face, not really sure this is possible...
|
|
|
|
if (!pattern) {
|
2020-09-17 02:11:13 +03:00
|
|
|
pattern = dont_AddRef(FcPatternCreate());
|
2018-01-06 13:58:23 +03:00
|
|
|
}
|
|
|
|
FcPatternDel(pattern, FC_FILE);
|
|
|
|
FcPatternDel(pattern, FC_INDEX);
|
|
|
|
|
|
|
|
// Make a new pattern and store the face in it so that cairo uses
|
|
|
|
// that when creating a cairo font face.
|
|
|
|
FcPatternAddFTFace(pattern, FC_FT_FACE, aFace);
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
return pattern.forget();
|
2018-01-06 13:58:23 +03:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
static already_AddRefed<SharedFTFace> CreateFaceForPattern(
|
|
|
|
FcPattern* aPattern) {
|
2018-01-06 13:58:23 +03:00
|
|
|
FcChar8* filename;
|
|
|
|
if (FcPatternGetString(aPattern, FC_FILE, 0, &filename) != FcResultMatch) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
int index;
|
|
|
|
if (FcPatternGetInteger(aPattern, FC_INDEX, 0, &index) != FcResultMatch) {
|
|
|
|
index = 0; // default to 0 if not found in pattern
|
|
|
|
}
|
2019-09-16 20:07:59 +03:00
|
|
|
return Factory::NewSharedFTFace(nullptr, ToCharPtr(filename), index);
|
2018-01-06 13:58:23 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsACString& aFaceName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight,
|
|
|
|
StretchRange aStretch,
|
|
|
|
SlantStyleRange aStyle,
|
2019-09-16 20:07:59 +03:00
|
|
|
RefPtr<SharedFTFace>&& aFace)
|
2019-10-02 00:56:30 +03:00
|
|
|
: gfxFT2FontEntryBase(aFaceName),
|
2019-09-16 20:07:59 +03:00
|
|
|
mFTFace(std::move(aFace)),
|
2015-05-13 08:11:25 +03:00
|
|
|
mFTFaceInitialized(true),
|
2016-06-15 16:35:05 +03:00
|
|
|
mIgnoreFcCharmap(true),
|
2021-06-14 15:32:37 +03:00
|
|
|
mHasVariationsInitialized(false) {
|
2018-04-25 09:18:23 +03:00
|
|
|
mWeightRange = aWeight;
|
|
|
|
mStyleRange = aStyle;
|
|
|
|
mStretchRange = aStretch;
|
2015-05-13 08:11:25 +03:00
|
|
|
mIsDataUserFont = true;
|
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
mFontPattern = CreatePatternForFace(mFTFace->GetFace());
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontconfigFontEntry::gfxFontconfigFontEntry(const nsACString& aFaceName,
|
2015-05-13 08:11:25 +03:00
|
|
|
FcPattern* aFontPattern,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight,
|
|
|
|
StretchRange aStretch,
|
|
|
|
SlantStyleRange aStyle)
|
2019-10-02 00:56:30 +03:00
|
|
|
: gfxFT2FontEntryBase(aFaceName),
|
2015-05-13 08:11:25 +03:00
|
|
|
mFontPattern(aFontPattern),
|
|
|
|
mFTFaceInitialized(false),
|
2021-06-14 15:32:37 +03:00
|
|
|
mHasVariationsInitialized(false) {
|
2018-04-25 09:18:23 +03:00
|
|
|
mWeightRange = aWeight;
|
|
|
|
mStyleRange = aStyle;
|
|
|
|
mStretchRange = aStretch;
|
2015-05-13 08:11:25 +03:00
|
|
|
mIsLocalUserFont = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-15 16:35:05 +03:00
|
|
|
// The proper setting of mIgnoreFcCharmap is tricky for fonts loaded
|
|
|
|
// via src:local()...
|
|
|
|
// If the local font happens to come from the application fontset,
|
|
|
|
// we want to set it to true so that color/svg fonts will work even
|
|
|
|
// if the default glyphs are blank; but if the local font is a non-
|
|
|
|
// sfnt face (e.g. legacy type 1) then we need to set it to false
|
|
|
|
// because our cmap-reading code will fail and we depend on FT+Fc to
|
|
|
|
// determine the coverage.
|
|
|
|
// We set the flag here, but may flip it the first time TestCharacterMap
|
|
|
|
// is called, at which point we'll look to see whether a 'cmap' is
|
|
|
|
// actually present in the font.
|
|
|
|
mIgnoreFcCharmap = true;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2018-01-29 16:24:11 +03:00
|
|
|
typedef FT_Error (*GetVarFunc)(FT_Face, FT_MM_Var**);
|
|
|
|
typedef FT_Error (*DoneVarFunc)(FT_Library, FT_MM_Var*);
|
|
|
|
static GetVarFunc sGetVar;
|
|
|
|
static DoneVarFunc sDoneVar;
|
|
|
|
static bool sInitializedVarFuncs = false;
|
|
|
|
|
|
|
|
static void InitializeVarFuncs() {
|
|
|
|
if (sInitializedVarFuncs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sInitializedVarFuncs = true;
|
2018-02-01 18:28:09 +03:00
|
|
|
#if MOZ_TREE_FREETYPE
|
|
|
|
sGetVar = &FT_Get_MM_Var;
|
|
|
|
sDoneVar = &FT_Done_MM_Var;
|
|
|
|
#else
|
2018-01-29 16:24:11 +03:00
|
|
|
sGetVar = (GetVarFunc)dlsym(RTLD_DEFAULT, "FT_Get_MM_Var");
|
|
|
|
sDoneVar = (DoneVarFunc)dlsym(RTLD_DEFAULT, "FT_Done_MM_Var");
|
2018-02-01 18:28:09 +03:00
|
|
|
#endif
|
2018-01-29 16:24:11 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
gfxFontconfigFontEntry::~gfxFontconfigFontEntry() {
|
2018-01-29 16:24:11 +03:00
|
|
|
if (mMMVar) {
|
|
|
|
// Prior to freetype 2.9, there was no specific function to free the
|
|
|
|
// FT_MM_Var record, and the docs just said to use free().
|
|
|
|
// InitializeVarFuncs must have been called in order for mMMVar to be
|
|
|
|
// non-null here, so we don't need to do it again.
|
|
|
|
if (sDoneVar) {
|
|
|
|
MOZ_ASSERT(mFTFace, "How did mMMVar get set without a face?");
|
2019-09-16 20:07:59 +03:00
|
|
|
(*sDoneVar)(mFTFace->GetFace()->glyph->library, mMMVar);
|
2018-01-29 16:24:11 +03:00
|
|
|
} else {
|
|
|
|
free(mMMVar);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
nsresult gfxFontconfigFontEntry::ReadCMAP(FontInfoData* aFontInfoData) {
|
2015-05-13 08:11:25 +03:00
|
|
|
// attempt this once, if errors occur leave a blank cmap
|
|
|
|
if (mCharacterMap) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxCharacterMap> charmap;
|
2015-05-13 08:11:25 +03:00
|
|
|
nsresult rv;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
if (aFontInfoData &&
|
|
|
|
(charmap = GetCMAPFromFontInfo(aFontInfoData, mUVSOffset))) {
|
|
|
|
rv = NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2015-05-13 08:11:25 +03:00
|
|
|
uint32_t kCMAP = TRUETYPE_TAG('c', 'm', 'a', 'p');
|
|
|
|
charmap = new gfxCharacterMap();
|
|
|
|
AutoTable cmapTable(this, kCMAP);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
if (cmapTable) {
|
|
|
|
uint32_t cmapLen;
|
|
|
|
const uint8_t* cmapData = reinterpret_cast<const uint8_t*>(
|
2017-07-05 22:18:51 +03:00
|
|
|
hb_blob_get_data(cmapTable, &cmapLen));
|
2015-05-13 08:11:25 +03:00
|
|
|
rv = gfxFontUtils::ReadCMAP(cmapData, cmapLen, *charmap, mUVSOffset);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
mHasCmapTable = NS_SUCCEEDED(rv);
|
|
|
|
if (mHasCmapTable) {
|
|
|
|
gfxPlatformFontList* pfl = gfxPlatformFontList::PlatformFontList();
|
2019-04-27 18:38:28 +03:00
|
|
|
fontlist::FontList* sharedFontList = pfl->SharedFontList();
|
|
|
|
if (!IsUserFont() && mShmemFace) {
|
|
|
|
mShmemFace->SetCharacterMap(sharedFontList, charmap); // async
|
|
|
|
if (!TrySetShmemCharacterMap()) {
|
|
|
|
// Temporarily retain charmap, until the shared version is
|
|
|
|
// ready for use.
|
|
|
|
mCharacterMap = charmap;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mCharacterMap = pfl->FindCharMap(charmap);
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
} else {
|
|
|
|
// if error occurred, initialize to null cmap
|
|
|
|
mCharacterMap = new gfxCharacterMap();
|
|
|
|
}
|
|
|
|
|
2017-07-26 23:03:57 +03:00
|
|
|
LOG_FONTLIST(("(fontlist-cmap) name: %s, size: %zu hash: %8.8x%s\n",
|
2015-05-13 08:11:25 +03:00
|
|
|
mName.get(), charmap->SizeOfIncludingThis(moz_malloc_size_of),
|
|
|
|
charmap->mHash, mCharacterMap == charmap ? " new" : ""));
|
|
|
|
if (LOG_CMAPDATA_ENABLED()) {
|
|
|
|
char prefix[256];
|
2016-08-17 01:41:12 +03:00
|
|
|
SprintfLiteral(prefix, "(cmapdata) name: %.220s", mName.get());
|
2015-05-13 08:11:25 +03:00
|
|
|
charmap->Dump(prefix, eGfxLog_cmapdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool HasChar(FcPattern* aFont, FcChar32 aCh) {
|
|
|
|
FcCharSet* charset = nullptr;
|
2015-05-13 08:11:26 +03:00
|
|
|
FcPatternGetCharSet(aFont, FC_CHARSET, 0, &charset);
|
2015-05-13 08:11:25 +03:00
|
|
|
return charset && FcCharSetHasChar(charset, aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
bool gfxFontconfigFontEntry::TestCharacterMap(uint32_t aCh) {
|
2015-05-13 08:11:25 +03:00
|
|
|
// For user fonts, or for fonts bundled with the app (which might include
|
|
|
|
// color/svg glyphs where the default glyphs may be blank, and thus confuse
|
|
|
|
// fontconfig/freetype's char map checking), we instead check the cmap
|
|
|
|
// directly for character coverage.
|
|
|
|
if (mIgnoreFcCharmap) {
|
2016-06-15 16:35:05 +03:00
|
|
|
// If it does not actually have a cmap, switch our strategy to use
|
2015-05-13 08:11:25 +03:00
|
|
|
// fontconfig's charmap after all (except for data fonts, which must
|
2016-08-19 15:57:05 +03:00
|
|
|
// always have a cmap to have passed OTS validation).
|
|
|
|
if (!mIsDataUserFont && !HasFontTable(TRUETYPE_TAG('c', 'm', 'a', 'p'))) {
|
|
|
|
mIgnoreFcCharmap = false;
|
2016-06-15 16:35:05 +03:00
|
|
|
// ...and continue with HasChar() below.
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2016-08-19 15:57:05 +03:00
|
|
|
return gfxFontEntry::TestCharacterMap(aCh);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-06-15 16:35:05 +03:00
|
|
|
// otherwise (for system fonts), use the charmap in the pattern
|
|
|
|
return HasChar(mFontPattern, aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-10-30 14:56:27 +03:00
|
|
|
bool gfxFontconfigFontEntry::HasFontTable(uint32_t aTableTag) {
|
|
|
|
if (FTUserFontData* ufd = GetUserFontData()) {
|
|
|
|
return !!gfxFontUtils::FindTableDirEntry(ufd->FontData(), aTableTag);
|
|
|
|
}
|
2020-10-30 18:06:01 +03:00
|
|
|
return gfxFT2FontEntryBase::FaceHasTable(GetFTFace(), aTableTag);
|
2020-10-30 14:56:27 +03:00
|
|
|
}
|
|
|
|
|
2017-12-07 16:22:49 +03:00
|
|
|
hb_blob_t* gfxFontconfigFontEntry::GetFontTable(uint32_t aTableTag) {
|
2015-05-13 08:11:25 +03:00
|
|
|
// for data fonts, read directly from the font data
|
2019-09-16 20:07:59 +03:00
|
|
|
if (FTUserFontData* ufd = GetUserFontData()) {
|
|
|
|
return gfxFontUtils::GetTableFromFontData(ufd->FontData(), aTableTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
return gfxFontEntry::GetFontTable(aTableTag);
|
|
|
|
}
|
|
|
|
|
2021-06-14 15:32:37 +03:00
|
|
|
double gfxFontconfigFontEntry::GetAspect(uint8_t aSizeAdjustBasis) {
|
|
|
|
using FontSizeAdjust = gfxFont::FontSizeAdjust;
|
2021-07-07 14:58:40 +03:00
|
|
|
if (FontSizeAdjust::Tag(aSizeAdjustBasis) == FontSizeAdjust::Tag::ExHeight ||
|
|
|
|
FontSizeAdjust::Tag(aSizeAdjustBasis) == FontSizeAdjust::Tag::CapHeight) {
|
2021-06-14 15:32:37 +03:00
|
|
|
// try to compute aspect from OS/2 metrics if available
|
|
|
|
AutoTable os2Table(this, TRUETYPE_TAG('O', 'S', '/', '2'));
|
|
|
|
if (os2Table) {
|
|
|
|
uint16_t upem = UnitsPerEm();
|
|
|
|
if (upem != kInvalidUPEM) {
|
|
|
|
uint32_t len;
|
|
|
|
const auto* os2 =
|
|
|
|
reinterpret_cast<const OS2Table*>(hb_blob_get_data(os2Table, &len));
|
|
|
|
if (uint16_t(os2->version) >= 2) {
|
|
|
|
// XXX(jfkthame) Other implementations don't have the check for
|
|
|
|
// values <= 0.1em; should we drop that here? Just require it to be
|
|
|
|
// a positive number?
|
|
|
|
if (FontSizeAdjust::Tag(aSizeAdjustBasis) ==
|
2021-07-07 14:58:40 +03:00
|
|
|
FontSizeAdjust::Tag::ExHeight) {
|
2021-06-14 15:32:37 +03:00
|
|
|
if (len >= offsetof(OS2Table, sxHeight) + sizeof(int16_t) &&
|
|
|
|
int16_t(os2->sxHeight) > 0.1 * upem) {
|
|
|
|
return double(int16_t(os2->sxHeight)) / upem;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (FontSizeAdjust::Tag(aSizeAdjustBasis) ==
|
2021-07-07 14:58:40 +03:00
|
|
|
FontSizeAdjust::Tag::CapHeight) {
|
2021-06-14 15:32:37 +03:00
|
|
|
if (len >= offsetof(OS2Table, sCapHeight) + sizeof(int16_t) &&
|
|
|
|
int16_t(os2->sCapHeight) > 0.1 * upem) {
|
|
|
|
return double(int16_t(os2->sCapHeight)) / upem;
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-05 22:18:51 +03:00
|
|
|
|
2021-06-14 15:32:37 +03:00
|
|
|
// create a font to calculate the requested aspect
|
2017-07-05 22:18:51 +03:00
|
|
|
gfxFontStyle s;
|
2021-06-14 15:32:37 +03:00
|
|
|
s.size = 256.0; // pick large size to reduce hinting artifacts
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
RefPtr<gfxFont> font = FindOrMakeFont(&s);
|
2017-07-05 22:18:51 +03:00
|
|
|
if (font) {
|
2019-04-01 17:32:19 +03:00
|
|
|
const gfxFont::Metrics& metrics =
|
|
|
|
font->GetMetrics(nsFontMetrics::eHorizontal);
|
2021-06-14 15:32:37 +03:00
|
|
|
if (metrics.emHeight == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
switch (FontSizeAdjust::Tag(aSizeAdjustBasis)) {
|
2021-07-07 14:58:40 +03:00
|
|
|
case FontSizeAdjust::Tag::ExHeight:
|
2021-06-14 15:32:37 +03:00
|
|
|
return metrics.xHeight / metrics.emHeight;
|
2021-07-07 14:58:40 +03:00
|
|
|
case FontSizeAdjust::Tag::CapHeight:
|
2021-06-14 15:32:37 +03:00
|
|
|
return metrics.capHeight / metrics.emHeight;
|
2021-07-07 14:58:40 +03:00
|
|
|
case FontSizeAdjust::Tag::ChWidth:
|
2021-06-14 15:32:37 +03:00
|
|
|
return metrics.zeroWidth > 0 ? metrics.zeroWidth / metrics.emHeight
|
|
|
|
: 0.5;
|
2021-07-07 14:58:40 +03:00
|
|
|
case FontSizeAdjust::Tag::IcWidth:
|
|
|
|
case FontSizeAdjust::Tag::IcHeight: {
|
|
|
|
bool vertical = FontSizeAdjust::Tag(aSizeAdjustBasis) ==
|
|
|
|
FontSizeAdjust::Tag::IcHeight;
|
|
|
|
gfxFloat advance = font->GetCharAdvance(0x6C34, vertical);
|
2021-06-14 15:32:37 +03:00
|
|
|
return advance > 0 ? advance / metrics.emHeight : 1.0;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
2017-07-05 22:18:51 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-07-05 22:18:51 +03:00
|
|
|
|
2021-06-14 15:32:37 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("failed to compute size-adjust aspect");
|
|
|
|
return 0.5;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2019-10-02 00:56:30 +03:00
|
|
|
static void PrepareFontOptions(FcPattern* aPattern, int* aOutLoadFlags,
|
2019-09-16 20:07:59 +03:00
|
|
|
unsigned int* aOutSynthFlags) {
|
|
|
|
int loadFlags = FT_LOAD_DEFAULT;
|
|
|
|
unsigned int synthFlags = 0;
|
|
|
|
|
2015-05-20 18:44:09 +03:00
|
|
|
// xxx - taken from the gfxFontconfigFonts code, needs to be reviewed
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
FcBool printing;
|
|
|
|
if (FcPatternGetBool(aPattern, PRINTING_FC_PROPERTY, 0, &printing) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
printing = FcFalse;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Font options are set explicitly here to improve cairo's caching
|
2019-09-16 20:15:10 +03:00
|
|
|
// behavior and to record the relevant parts of the pattern so that
|
|
|
|
// the pattern can be released.
|
2015-05-13 08:11:25 +03:00
|
|
|
//
|
|
|
|
// Most font_options have already been set as defaults on the FcPattern
|
|
|
|
// with cairo_ft_font_options_substitute(), then user and system
|
|
|
|
// fontconfig configurations were applied. The resulting font_options
|
|
|
|
// have been recorded on the face during
|
|
|
|
// cairo_ft_font_face_create_for_pattern().
|
|
|
|
//
|
|
|
|
// None of the settings here cause this scaled_font to behave any
|
|
|
|
// differently from how it would behave if it were created from the same
|
|
|
|
// face with default font_options.
|
|
|
|
//
|
|
|
|
// We set options explicitly so that the same scaled_font will be found in
|
|
|
|
// the cairo_scaled_font_map when cairo loads glyphs from a context with
|
|
|
|
// the same font_face, font_matrix, ctm, and surface font_options.
|
|
|
|
//
|
|
|
|
// Unfortunately, _cairo_scaled_font_keys_equal doesn't know about the
|
|
|
|
// font_options on the cairo_ft_font_face, and doesn't consider default
|
|
|
|
// option values to not match any explicit values.
|
|
|
|
//
|
|
|
|
// Even after cairo_set_scaled_font is used to set font_options for the
|
|
|
|
// cairo context, when cairo looks for a scaled_font for the context, it
|
|
|
|
// will look for a font with some option values from the target surface if
|
|
|
|
// any values are left default on the context font_options. If this
|
|
|
|
// scaled_font is created with default font_options, cairo will not find
|
|
|
|
// it.
|
|
|
|
//
|
|
|
|
// The one option not recorded in the pattern is hint_metrics, which will
|
|
|
|
// affect glyph metrics. The default behaves as CAIRO_HINT_METRICS_ON.
|
|
|
|
// We should be considering the font_options of the surface on which this
|
|
|
|
// font will be used, but currently we don't have different gfxFonts for
|
|
|
|
// different surface font_options, so we'll create a font suitable for the
|
|
|
|
// Screen. Image and xlib surfaces default to CAIRO_HINT_METRICS_ON.
|
|
|
|
|
|
|
|
// The remaining options have been recorded on the pattern and the face.
|
|
|
|
// _cairo_ft_options_merge has some logic to decide which options from the
|
|
|
|
// scaled_font or from the cairo_ft_font_face take priority in the way the
|
|
|
|
// font behaves.
|
|
|
|
//
|
|
|
|
// In the majority of cases, _cairo_ft_options_merge uses the options from
|
|
|
|
// the cairo_ft_font_face, so sometimes it is not so important which
|
|
|
|
// values are set here so long as they are not defaults, but we'll set
|
|
|
|
// them to the exact values that we expect from the font, to be consistent
|
|
|
|
// and to protect against changes in cairo.
|
|
|
|
//
|
|
|
|
// In some cases, _cairo_ft_options_merge uses some options from the
|
|
|
|
// scaled_font's font_options rather than options on the
|
|
|
|
// cairo_ft_font_face (from fontconfig).
|
|
|
|
// https://bugs.freedesktop.org/show_bug.cgi?id=11838
|
|
|
|
//
|
|
|
|
// Surface font options were set on the pattern in
|
|
|
|
// cairo_ft_font_options_substitute. If fontconfig has changed the
|
|
|
|
// hint_style then that is what the user (or distribution) wants, so we
|
|
|
|
// use the setting from the FcPattern.
|
|
|
|
//
|
|
|
|
// Fallback values here mirror treatment of defaults in cairo-ft-font.c.
|
|
|
|
FcBool hinting = FcFalse;
|
|
|
|
if (FcPatternGetBool(aPattern, FC_HINTING, 0, &hinting) != FcResultMatch) {
|
|
|
|
hinting = FcTrue;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:15:10 +03:00
|
|
|
int fc_hintstyle = FC_HINT_NONE;
|
|
|
|
if ((!printing || hinting) &&
|
|
|
|
FcPatternGetInteger(aPattern, FC_HINT_STYLE, 0, &fc_hintstyle) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
fc_hintstyle = FC_HINT_FULL;
|
|
|
|
}
|
|
|
|
switch (fc_hintstyle) {
|
|
|
|
case FC_HINT_NONE:
|
2019-10-02 00:56:30 +03:00
|
|
|
loadFlags = FT_LOAD_NO_HINTING;
|
2019-09-16 20:15:10 +03:00
|
|
|
break;
|
|
|
|
case FC_HINT_SLIGHT:
|
2019-10-02 00:56:30 +03:00
|
|
|
loadFlags = FT_LOAD_TARGET_LIGHT;
|
2015-05-13 08:11:25 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool fc_antialias;
|
|
|
|
if (FcPatternGetBool(aPattern, FC_ANTIALIAS, 0, &fc_antialias) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
fc_antialias = FcTrue;
|
|
|
|
}
|
|
|
|
if (!fc_antialias) {
|
2019-09-16 20:15:10 +03:00
|
|
|
if (fc_hintstyle != FC_HINT_NONE) {
|
2019-10-02 00:56:30 +03:00
|
|
|
loadFlags = FT_LOAD_TARGET_MONO;
|
2019-09-16 20:15:10 +03:00
|
|
|
}
|
2019-10-02 00:56:30 +03:00
|
|
|
loadFlags |= FT_LOAD_MONOCHROME;
|
|
|
|
} else if (fc_hintstyle == FC_HINT_FULL) {
|
|
|
|
int fc_rgba;
|
|
|
|
if (FcPatternGetInteger(aPattern, FC_RGBA, 0, &fc_rgba) != FcResultMatch) {
|
|
|
|
fc_rgba = FC_RGBA_UNKNOWN;
|
|
|
|
}
|
|
|
|
switch (fc_rgba) {
|
|
|
|
case FC_RGBA_RGB:
|
|
|
|
case FC_RGBA_BGR:
|
|
|
|
loadFlags = FT_LOAD_TARGET_LCD;
|
|
|
|
break;
|
|
|
|
case FC_RGBA_VRGB:
|
|
|
|
case FC_RGBA_VBGR:
|
|
|
|
loadFlags = FT_LOAD_TARGET_LCD_V;
|
|
|
|
break;
|
2019-09-16 20:15:10 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
FcBool bitmap;
|
|
|
|
if (FcPatternGetBool(aPattern, FC_EMBEDDED_BITMAP, 0, &bitmap) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
bitmap = FcFalse;
|
|
|
|
}
|
2019-10-02 00:56:30 +03:00
|
|
|
if (fc_antialias && (fc_hintstyle == FC_HINT_NONE || !bitmap)) {
|
2019-09-16 20:07:59 +03:00
|
|
|
loadFlags |= FT_LOAD_NO_BITMAP;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool autohint;
|
|
|
|
if (FcPatternGetBool(aPattern, FC_AUTOHINT, 0, &autohint) == FcResultMatch &&
|
|
|
|
autohint) {
|
|
|
|
loadFlags |= FT_LOAD_FORCE_AUTOHINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
FcBool embolden;
|
|
|
|
if (FcPatternGetBool(aPattern, FC_EMBOLDEN, 0, &embolden) == FcResultMatch &&
|
|
|
|
embolden) {
|
|
|
|
synthFlags |= CAIRO_FT_SYNTHESIZE_BOLD;
|
|
|
|
}
|
2018-06-01 20:08:57 +03:00
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
*aOutLoadFlags = loadFlags;
|
|
|
|
*aOutSynthFlags = synthFlags;
|
2018-06-01 20:08:57 +03:00
|
|
|
}
|
|
|
|
|
2016-07-20 21:18:21 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
static bool GetXftInt(Display* aDisplay, const char* aName, int* aResult) {
|
|
|
|
if (!aDisplay) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
char* value = XGetDefault(aDisplay, "Xft", aName);
|
|
|
|
if (!value) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-20 21:18:21 +03:00
|
|
|
if (FcNameConstant(const_cast<FcChar8*>(ToFcChar8Ptr(value)), aResult)) {
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-20 21:18:21 +03:00
|
|
|
char* end;
|
|
|
|
*aResult = strtol(value, &end, 0);
|
|
|
|
if (end != value) {
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-07-20 21:18:21 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
static void PreparePattern(FcPattern* aPattern, bool aIsPrinterFont) {
|
2015-05-19 08:30:55 +03:00
|
|
|
FcConfigSubstitute(nullptr, aPattern, FcMatchPattern);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// This gets cairo_font_options_t for the Screen. We should have
|
|
|
|
// different font options for printing (no hinting) but we are not told
|
|
|
|
// what we are measuring for.
|
|
|
|
//
|
|
|
|
// If cairo adds support for lcd_filter, gdk will not provide the default
|
|
|
|
// setting for that option. We could get the default setting by creating
|
|
|
|
// an xlib surface once, recording its font_options, and then merging the
|
|
|
|
// gdk options.
|
|
|
|
//
|
|
|
|
// Using an xlib surface would also be an option to get Screen font
|
|
|
|
// options for non-GTK X11 toolkits, but less efficient than using GDK to
|
|
|
|
// pick up dynamic changes.
|
|
|
|
if (aIsPrinterFont) {
|
|
|
|
cairo_font_options_t* options = cairo_font_options_create();
|
|
|
|
cairo_font_options_set_hint_style(options, CAIRO_HINT_STYLE_NONE);
|
|
|
|
cairo_font_options_set_antialias(options, CAIRO_ANTIALIAS_GRAY);
|
|
|
|
cairo_ft_font_options_substitute(options, aPattern);
|
|
|
|
cairo_font_options_destroy(options);
|
|
|
|
FcPatternAddBool(aPattern, PRINTING_FC_PROPERTY, FcTrue);
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
2021-05-01 23:00:31 +03:00
|
|
|
} else {
|
|
|
|
gfxFcPlatformFontList::PlatformFontList()->SubstituteSystemFontOptions(
|
|
|
|
aPattern);
|
|
|
|
#endif // MOZ_WIDGET_GTK
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FcDefaultSubstitute(aPattern);
|
|
|
|
}
|
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
void gfxFontconfigFontEntry::UnscaledFontCache::MoveToFront(size_t aIndex) {
|
|
|
|
if (aIndex > 0) {
|
2017-10-18 21:22:09 +03:00
|
|
|
ThreadSafeWeakPtr<UnscaledFontFontconfig> front =
|
2018-05-30 22:15:35 +03:00
|
|
|
std::move(mUnscaledFonts[aIndex]);
|
2017-04-07 00:41:02 +03:00
|
|
|
for (size_t i = aIndex; i > 0; i--) {
|
2018-05-30 22:15:35 +03:00
|
|
|
mUnscaledFonts[i] = std::move(mUnscaledFonts[i - 1]);
|
2017-04-07 00:41:02 +03:00
|
|
|
}
|
2018-05-30 22:15:35 +03:00
|
|
|
mUnscaledFonts[0] = std::move(front);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-04-07 00:41:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<UnscaledFontFontconfig>
|
2019-09-16 20:07:59 +03:00
|
|
|
gfxFontconfigFontEntry::UnscaledFontCache::Lookup(const std::string& aFile,
|
2017-04-07 00:41:02 +03:00
|
|
|
uint32_t aIndex) {
|
|
|
|
for (size_t i = 0; i < kNumEntries; i++) {
|
2017-10-18 21:22:09 +03:00
|
|
|
RefPtr<UnscaledFontFontconfig> entry(mUnscaledFonts[i]);
|
2019-09-16 20:07:59 +03:00
|
|
|
if (entry && entry->GetFile() == aFile && entry->GetIndex() == aIndex) {
|
2017-04-07 00:41:02 +03:00
|
|
|
MoveToFront(i);
|
2017-10-18 21:22:09 +03:00
|
|
|
return entry.forget();
|
2017-04-07 00:41:02 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-04-07 00:41:02 +03:00
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-29 20:47:46 +03:00
|
|
|
static inline gfxFloat SizeForStyle(gfxFontconfigFontEntry* aEntry,
|
|
|
|
const gfxFontStyle& aStyle) {
|
2021-06-14 15:32:37 +03:00
|
|
|
return StyleFontSizeAdjust::Tag(aStyle.sizeAdjustBasis) !=
|
|
|
|
StyleFontSizeAdjust::Tag::None
|
|
|
|
? aStyle.GetAdjustedSize(aEntry->GetAspect(aStyle.sizeAdjustBasis))
|
|
|
|
: aStyle.size * aEntry->mSizeAdjust;
|
2017-03-29 20:47:46 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-29 20:47:46 +03:00
|
|
|
static double ChooseFontSize(gfxFontconfigFontEntry* aEntry,
|
|
|
|
const gfxFontStyle& aStyle) {
|
|
|
|
double requestedSize = SizeForStyle(aEntry, aStyle);
|
|
|
|
double bestDist = -1.0;
|
|
|
|
double bestSize = requestedSize;
|
|
|
|
double size;
|
|
|
|
int v = 0;
|
|
|
|
while (FcPatternGetDouble(aEntry->GetPattern(), FC_PIXEL_SIZE, v, &size) ==
|
|
|
|
FcResultMatch) {
|
|
|
|
++v;
|
|
|
|
double dist = fabs(size - requestedSize);
|
|
|
|
if (bestDist < 0.0 || dist < bestDist) {
|
|
|
|
bestDist = dist;
|
|
|
|
bestSize = size;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-05 22:46:10 +03:00
|
|
|
// If the font has bitmaps but wants to be scaled, then let it scale.
|
|
|
|
if (bestSize >= 0.0) {
|
|
|
|
FcBool scalable;
|
|
|
|
if (FcPatternGetBool(aEntry->GetPattern(), FC_SCALABLE, 0, &scalable) ==
|
|
|
|
FcResultMatch &&
|
|
|
|
scalable) {
|
|
|
|
return requestedSize;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
return bestSize;
|
|
|
|
}
|
|
|
|
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
gfxFont* gfxFontconfigFontEntry::CreateFontInstance(
|
|
|
|
const gfxFontStyle* aFontStyle) {
|
2020-09-17 02:11:13 +03:00
|
|
|
RefPtr<FcPattern> pattern = dont_AddRef(FcPatternCreate());
|
2016-08-17 19:01:01 +03:00
|
|
|
if (!pattern) {
|
|
|
|
NS_WARNING("Failed to create Fontconfig pattern for font instance");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
|
|
|
|
double size = ChooseFontSize(this, *aFontStyle);
|
2018-01-06 13:58:23 +03:00
|
|
|
FcPatternAddDouble(pattern, FC_PIXEL_SIZE, size);
|
2017-12-10 17:01:32 +03:00
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
RefPtr<SharedFTFace> face = GetFTFace();
|
|
|
|
if (!face) {
|
|
|
|
NS_WARNING("Failed to get FreeType face for pattern");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-10-02 00:56:30 +03:00
|
|
|
if (HasVariations()) {
|
2019-09-16 20:07:59 +03:00
|
|
|
// For variation fonts, we create a new FT_Face here so that
|
|
|
|
// variation coordinates from the style can be applied without
|
|
|
|
// affecting other font instances created from the same entry
|
|
|
|
// (font resource).
|
2019-10-02 00:56:30 +03:00
|
|
|
// For user fonts: create a new FT_Face from the font data, and then make
|
|
|
|
// a pattern from that.
|
|
|
|
// For system fonts: create a new FT_Face and store it in a copy of the
|
|
|
|
// original mFontPattern.
|
|
|
|
RefPtr<SharedFTFace> varFace = face->GetData()
|
|
|
|
? face->GetData()->CloneFace()
|
|
|
|
: CreateFaceForPattern(mFontPattern);
|
|
|
|
if (varFace) {
|
|
|
|
AutoTArray<gfxFontVariation, 8> settings;
|
|
|
|
GetVariationsForStyle(settings, *aFontStyle);
|
|
|
|
gfxFT2FontBase::SetupVarCoords(GetMMVar(), settings, varFace->GetFace());
|
|
|
|
face = std::move(varFace);
|
2016-08-17 19:01:01 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2018-06-01 20:08:57 +03:00
|
|
|
PreparePattern(pattern, aFontStyle->printerFont);
|
2020-09-17 02:11:13 +03:00
|
|
|
RefPtr<FcPattern> renderPattern =
|
|
|
|
dont_AddRef(FcFontRenderPrepare(nullptr, pattern, mFontPattern));
|
2017-04-07 00:41:02 +03:00
|
|
|
if (!renderPattern) {
|
|
|
|
NS_WARNING("Failed to prepare Fontconfig pattern for font instance");
|
2018-01-29 16:24:11 +03:00
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-04-07 00:41:02 +03:00
|
|
|
|
2019-10-02 00:56:30 +03:00
|
|
|
if (aFontStyle->NeedsSyntheticBold(this)) {
|
|
|
|
FcPatternAddBool(renderPattern, FC_EMBOLDEN, FcTrue);
|
|
|
|
}
|
|
|
|
|
|
|
|
// will synthetic oblique be applied using a transform?
|
|
|
|
if (IsUpright() && aFontStyle->style != FontSlantStyle::Normal() &&
|
|
|
|
aFontStyle->allowSyntheticStyle) {
|
|
|
|
// disable embedded bitmaps (mimics behavior in 90-synthetic.conf)
|
|
|
|
FcPatternDel(renderPattern, FC_EMBEDDED_BITMAP);
|
|
|
|
FcPatternAddBool(renderPattern, FC_EMBEDDED_BITMAP, FcFalse);
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:15:10 +03:00
|
|
|
int loadFlags;
|
|
|
|
unsigned int synthFlags;
|
2019-10-02 00:56:30 +03:00
|
|
|
PrepareFontOptions(renderPattern, &loadFlags, &synthFlags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
std::string file;
|
2017-04-07 00:41:02 +03:00
|
|
|
int index = 0;
|
2019-09-16 20:07:59 +03:00
|
|
|
if (!face->GetData()) {
|
|
|
|
const FcChar8* fcFile;
|
2017-12-10 17:01:32 +03:00
|
|
|
if (FcPatternGetString(renderPattern, FC_FILE, 0,
|
2019-09-16 20:07:59 +03:00
|
|
|
const_cast<FcChar8**>(&fcFile)) != FcResultMatch ||
|
2017-04-07 00:41:02 +03:00
|
|
|
FcPatternGetInteger(renderPattern, FC_INDEX, 0, &index) !=
|
|
|
|
FcResultMatch) {
|
|
|
|
NS_WARNING("No file in Fontconfig pattern for font instance");
|
|
|
|
return nullptr;
|
|
|
|
}
|
2019-09-16 20:07:59 +03:00
|
|
|
file = ToCharPtr(fcFile);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-04-07 00:41:02 +03:00
|
|
|
|
|
|
|
RefPtr<UnscaledFontFontconfig> unscaledFont =
|
2019-09-16 20:07:59 +03:00
|
|
|
mUnscaledFontCache.Lookup(file, index);
|
2017-08-07 23:20:44 +03:00
|
|
|
if (!unscaledFont) {
|
2019-09-16 20:07:59 +03:00
|
|
|
unscaledFont = mFTFace->GetData() ? new UnscaledFontFontconfig(mFTFace)
|
|
|
|
: new UnscaledFontFontconfig(
|
|
|
|
std::move(file), index, mFTFace);
|
2015-05-13 08:11:25 +03:00
|
|
|
mUnscaledFontCache.Add(unscaledFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2019-09-16 20:15:10 +03:00
|
|
|
gfxFont* newFont = new gfxFontconfigFont(
|
2019-10-02 00:56:30 +03:00
|
|
|
unscaledFont, std::move(face), renderPattern, size, this, aFontStyle,
|
|
|
|
loadFlags, (synthFlags & CAIRO_FT_SYNTHESIZE_BOLD) != 0);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-12-07 16:22:49 +03:00
|
|
|
return newFont;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
const RefPtr<SharedFTFace>& gfxFontconfigFontEntry::GetFTFace() {
|
2018-04-25 09:18:23 +03:00
|
|
|
if (!mFTFaceInitialized) {
|
|
|
|
mFTFaceInitialized = true;
|
2018-04-25 16:03:44 +03:00
|
|
|
mFTFace = CreateFaceForPattern(mFontPattern);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-25 16:03:44 +03:00
|
|
|
return mFTFace;
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:07:59 +03:00
|
|
|
FTUserFontData* gfxFontconfigFontEntry::GetUserFontData() {
|
|
|
|
if (mFTFace && mFTFace->GetData()) {
|
|
|
|
return static_cast<FTUserFontData*>(mFTFace->GetData());
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
bool gfxFontconfigFontEntry::HasVariations() {
|
|
|
|
if (mHasVariationsInitialized) {
|
|
|
|
return mHasVariations;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-04-25 09:18:23 +03:00
|
|
|
mHasVariationsInitialized = true;
|
|
|
|
mHasVariations = false;
|
|
|
|
|
2018-04-25 16:03:44 +03:00
|
|
|
if (!gfxPlatform::GetPlatform()->HasVariationFontSupport()) {
|
2018-04-25 09:18:23 +03:00
|
|
|
return mHasVariations;
|
2018-01-18 22:27:41 +03:00
|
|
|
}
|
|
|
|
|
2018-01-29 16:24:11 +03:00
|
|
|
// For installed fonts, query the fontconfig pattern rather than paying
|
|
|
|
// the cost of loading a FT_Face that we otherwise might never need.
|
|
|
|
if (!IsUserFont() || IsLocalUserFont()) {
|
2018-04-25 09:18:23 +03:00
|
|
|
FcBool variable;
|
2018-01-29 16:24:11 +03:00
|
|
|
if ((FcPatternGetBool(mFontPattern, FC_VARIABLE, 0, &variable) ==
|
|
|
|
FcResultMatch) &&
|
|
|
|
variable) {
|
|
|
|
mHasVariations = true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2019-09-16 20:07:59 +03:00
|
|
|
if (GetFTFace()) {
|
|
|
|
mHasVariations =
|
|
|
|
mFTFace->GetFace()->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS;
|
2018-01-18 22:27:41 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
return mHasVariations;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-01-29 16:24:11 +03:00
|
|
|
FT_MM_Var* gfxFontconfigFontEntry::GetMMVar() {
|
2015-05-13 08:11:25 +03:00
|
|
|
if (mMMVarInitialized) {
|
2018-01-29 16:24:11 +03:00
|
|
|
return mMMVar;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
mMMVarInitialized = true;
|
2018-01-29 16:24:11 +03:00
|
|
|
InitializeVarFuncs();
|
|
|
|
if (!sGetVar) {
|
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-09-16 20:07:59 +03:00
|
|
|
if (!GetFTFace()) {
|
2018-01-29 16:24:11 +03:00
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-09-16 20:07:59 +03:00
|
|
|
if (FT_Err_Ok != (*sGetVar)(mFTFace->GetFace(), &mMMVar)) {
|
2018-01-29 16:24:11 +03:00
|
|
|
mMMVar = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-01-29 16:24:11 +03:00
|
|
|
return mMMVar;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFontconfigFontEntry::GetVariationAxes(
|
|
|
|
nsTArray<gfxFontVariationAxis>& aAxes) {
|
2018-04-26 19:08:18 +03:00
|
|
|
if (!HasVariations()) {
|
2018-01-18 22:27:41 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-26 19:08:18 +03:00
|
|
|
gfxFT2Utils::GetVariationAxes(GetMMVar(), aAxes);
|
2018-01-29 16:24:11 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFontconfigFontEntry::GetVariationInstances(
|
|
|
|
nsTArray<gfxFontVariationInstance>& aInstances) {
|
2018-04-26 19:08:18 +03:00
|
|
|
if (!HasVariations()) {
|
2018-01-29 16:24:11 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-04-26 19:08:18 +03:00
|
|
|
gfxFT2Utils::GetVariationInstances(this, GetMMVar(), aInstances);
|
2018-01-18 22:27:41 +03:00
|
|
|
}
|
|
|
|
|
2017-12-07 16:22:49 +03:00
|
|
|
nsresult gfxFontconfigFontEntry::CopyFontTable(uint32_t aTableTag,
|
|
|
|
nsTArray<uint8_t>& aBuffer) {
|
|
|
|
NS_ASSERTION(!mIsDataUserFont,
|
|
|
|
"data fonts should be reading tables directly from memory");
|
2020-10-30 18:06:01 +03:00
|
|
|
return gfxFT2FontEntryBase::CopyFaceTable(GetFTFace(), aTableTag, aBuffer);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
void gfxFontconfigFontFamily::FindStyleVariations(FontInfoData* aFontInfoData) {
|
2015-05-13 08:11:25 +03:00
|
|
|
if (mHasStyles) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add font entries for each of the faces
|
2018-09-12 22:34:57 +03:00
|
|
|
uint32_t numFonts = mFontPatterns.Length();
|
|
|
|
NS_ASSERTION(numFonts, "font family containing no faces!!");
|
|
|
|
uint32_t numRegularFaces = 0;
|
|
|
|
for (uint32_t i = 0; i < numFonts; i++) {
|
|
|
|
FcPattern* face = mFontPatterns[i];
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
// figure out the psname/fullname and choose which to use as the facename
|
2016-06-15 16:35:05 +03:00
|
|
|
nsAutoCString psname, fullname;
|
|
|
|
GetFaceNames(face, mName, psname, fullname);
|
|
|
|
const nsAutoCString& faceName = !psname.IsEmpty() ? psname : fullname;
|
2018-04-25 16:03:44 +03:00
|
|
|
|
|
|
|
gfxFontconfigFontEntry* fontEntry =
|
|
|
|
new gfxFontconfigFontEntry(faceName, face, mContainsAppFonts);
|
2018-04-25 09:18:23 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
if (gfxPlatform::GetPlatform()->HasVariationFontSupport()) {
|
|
|
|
fontEntry->SetupVariationRanges();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
AddFontEntry(fontEntry);
|
2015-11-11 15:13:33 +03:00
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
if (fontEntry->IsNormalStyle()) {
|
|
|
|
numRegularFaces++;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2015-11-11 15:13:33 +03:00
|
|
|
|
|
|
|
if (LOG_FONTLIST_ENABLED()) {
|
|
|
|
nsAutoCString weightString;
|
2015-05-13 08:11:25 +03:00
|
|
|
fontEntry->Weight().ToString(weightString);
|
|
|
|
nsAutoCString stretchString;
|
|
|
|
fontEntry->Stretch().ToString(stretchString);
|
|
|
|
nsAutoCString styleString;
|
2015-05-13 08:11:26 +03:00
|
|
|
fontEntry->SlantStyle().ToString(styleString);
|
|
|
|
LOG_FONTLIST(
|
2015-05-13 08:11:25 +03:00
|
|
|
("(fontlist) added (%s) to family (%s)"
|
|
|
|
" with style: %s weight: %s stretch: %s"
|
|
|
|
" psname: %s fullname: %s",
|
2017-05-05 22:46:10 +03:00
|
|
|
fontEntry->Name().get(), Name().get(), styleString.get(),
|
|
|
|
weightString.get(), stretchString.get(), psname.get(),
|
|
|
|
fullname.get()));
|
2017-03-29 20:47:46 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
|
2015-11-11 15:13:33 +03:00
|
|
|
// somewhat arbitrary, but define a family with two or more regular
|
|
|
|
// faces as a family for which intra-family fallback should be used
|
|
|
|
if (numRegularFaces > 1) {
|
|
|
|
mCheckForFallbackFaces = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
mFaceNamesInitialized = true;
|
|
|
|
mFontPatterns.Clear();
|
|
|
|
SetHasStyles(true);
|
2020-07-06 17:00:58 +03:00
|
|
|
|
|
|
|
CheckForSimpleFamily();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:42:44 +03:00
|
|
|
void gfxFontconfigFontFamily::AddFontPattern(FcPattern* aFontPattern,
|
|
|
|
bool aSingleName) {
|
2015-05-13 08:11:25 +03:00
|
|
|
NS_ASSERTION(
|
|
|
|
!mHasStyles,
|
|
|
|
"font patterns must not be added to already enumerated families");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-04 03:45:39 +03:00
|
|
|
FcBool outline;
|
|
|
|
if (FcPatternGetBool(aFontPattern, FC_OUTLINE, 0, &outline) !=
|
|
|
|
FcResultMatch ||
|
|
|
|
!outline) {
|
2017-03-29 20:47:46 +03:00
|
|
|
mHasNonScalableFaces = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 22:46:10 +03:00
|
|
|
FcBool scalable;
|
|
|
|
if (FcPatternGetBool(aFontPattern, FC_SCALABLE, 0, &scalable) ==
|
2017-05-04 03:45:39 +03:00
|
|
|
FcResultMatch &&
|
2017-05-05 22:46:10 +03:00
|
|
|
scalable) {
|
|
|
|
mForceScalable = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-09 17:50:44 +03:00
|
|
|
if (aSingleName) {
|
2021-04-20 13:42:44 +03:00
|
|
|
mFontPatterns.InsertElementAt(mUniqueNameFaceCount++, aFontPattern);
|
2021-04-09 17:50:44 +03:00
|
|
|
} else {
|
|
|
|
mFontPatterns.AppendElement(aFontPattern);
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-29 20:47:46 +03:00
|
|
|
static const double kRejectDistance = 10000.0;
|
|
|
|
|
|
|
|
// Calculate a distance score representing the size disparity between the
|
|
|
|
// requested style's size and the font entry's size.
|
2017-05-05 22:46:10 +03:00
|
|
|
static double SizeDistance(gfxFontconfigFontEntry* aEntry,
|
|
|
|
const gfxFontStyle& aStyle, bool aForceScalable) {
|
2017-03-29 20:47:46 +03:00
|
|
|
double requestedSize = SizeForStyle(aEntry, aStyle);
|
|
|
|
double bestDist = -1.0;
|
|
|
|
double size;
|
|
|
|
int v = 0;
|
|
|
|
while (FcPatternGetDouble(aEntry->GetPattern(), FC_PIXEL_SIZE, v, &size) ==
|
|
|
|
FcResultMatch) {
|
|
|
|
++v;
|
|
|
|
double dist = fabs(size - requestedSize);
|
|
|
|
if (bestDist < 0.0 || dist < bestDist) {
|
|
|
|
bestDist = dist;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
if (bestDist < 0.0) {
|
|
|
|
// No size means scalable
|
|
|
|
return -1.0;
|
2017-05-05 22:46:10 +03:00
|
|
|
} else if (aForceScalable || 5.0 * bestDist < requestedSize) {
|
2017-03-29 20:47:46 +03:00
|
|
|
// fontconfig prefers a matching family or lang to pixelsize of bitmap
|
|
|
|
// fonts. CSS suggests a tolerance of 20% on pixelsize.
|
|
|
|
return bestDist;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-29 20:47:46 +03:00
|
|
|
// Reject any non-scalable fonts that are not within tolerance.
|
|
|
|
return kRejectDistance;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFontconfigFontFamily::FindAllFontsForStyle(
|
|
|
|
const gfxFontStyle& aFontStyle, nsTArray<gfxFontEntry*>& aFontEntryList,
|
|
|
|
bool aIgnoreSizeTolerance) {
|
|
|
|
gfxFontFamily::FindAllFontsForStyle(aFontStyle, aFontEntryList,
|
2017-08-07 19:27:33 +03:00
|
|
|
aIgnoreSizeTolerance);
|
2017-03-29 20:47:46 +03:00
|
|
|
|
|
|
|
if (!mHasNonScalableFaces) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Iterate over the the available fonts while compacting any groups
|
|
|
|
// of unscalable fonts with matching styles into a single entry
|
|
|
|
// corresponding to the closest available size. If the closest
|
2017-08-07 19:27:33 +03:00
|
|
|
// available size is rejected for being outside tolerance, then the
|
2017-03-29 20:47:46 +03:00
|
|
|
// entire group will be skipped.
|
|
|
|
size_t skipped = 0;
|
|
|
|
gfxFontconfigFontEntry* bestEntry = nullptr;
|
|
|
|
double bestDist = -1.0;
|
2017-08-07 19:27:33 +03:00
|
|
|
for (size_t i = 0; i < aFontEntryList.Length(); i++) {
|
2017-03-29 20:47:46 +03:00
|
|
|
gfxFontconfigFontEntry* entry =
|
|
|
|
static_cast<gfxFontconfigFontEntry*>(aFontEntryList[i]);
|
2018-04-25 09:18:23 +03:00
|
|
|
double dist =
|
|
|
|
SizeDistance(entry, aFontStyle, mForceScalable || aIgnoreSizeTolerance);
|
2017-03-29 20:47:46 +03:00
|
|
|
// If the entry is scalable or has a style that does not match
|
|
|
|
// the group of unscalable fonts, then start a new group.
|
|
|
|
if (dist < 0.0 || !bestEntry || bestEntry->Stretch() != entry->Stretch() ||
|
|
|
|
bestEntry->Weight() != entry->Weight() ||
|
|
|
|
bestEntry->SlantStyle() != entry->SlantStyle()) {
|
|
|
|
// If the best entry in this group is still outside the tolerance,
|
|
|
|
// then skip the entire group.
|
|
|
|
if (bestDist >= kRejectDistance) {
|
|
|
|
skipped++;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
// Remove any compacted entries from the previous group.
|
|
|
|
if (skipped) {
|
|
|
|
i -= skipped;
|
|
|
|
aFontEntryList.RemoveElementsAt(i, skipped);
|
|
|
|
skipped = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
// Mark the start of the new group.
|
|
|
|
bestEntry = entry;
|
|
|
|
bestDist = dist;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-03-29 20:47:46 +03:00
|
|
|
// If this entry more closely matches the requested size than the
|
|
|
|
// current best in the group, then take this entry instead.
|
|
|
|
if (dist < bestDist) {
|
|
|
|
aFontEntryList[i - 1 - skipped] = entry;
|
|
|
|
bestEntry = entry;
|
|
|
|
bestDist = dist;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
skipped++;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
// If the best entry in this group is still outside the tolerance,
|
|
|
|
// then skip the entire group.
|
|
|
|
if (bestDist >= kRejectDistance) {
|
|
|
|
skipped++;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-03-29 20:47:46 +03:00
|
|
|
// Remove any compacted entries from the current group.
|
|
|
|
if (skipped) {
|
|
|
|
aFontEntryList.TruncateLength(aFontEntryList.Length() - skipped);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-11 21:22:15 +03:00
|
|
|
static bool PatternHasLang(const FcPattern* aPattern, const FcChar8* aLang) {
|
|
|
|
FcLangSet* langset;
|
|
|
|
|
|
|
|
if (FcPatternGetLangSet(aPattern, FC_LANG, 0, &langset) != FcResultMatch) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-09-11 21:22:15 +03:00
|
|
|
if (FcLangSetHasLang(langset, aLang) != FcLangDifferentLang) {
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-09-11 21:22:15 +03:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool gfxFontconfigFontFamily::SupportsLangGroup(nsAtom* aLangGroup) const {
|
2017-09-11 21:22:15 +03:00
|
|
|
if (!aLangGroup || aLangGroup == nsGkAtoms::Unicode) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString fcLang;
|
|
|
|
gfxFcPlatformFontList* pfl = gfxFcPlatformFontList::PlatformFontList();
|
|
|
|
pfl->GetSampleLangForGroup(aLangGroup, fcLang);
|
|
|
|
if (fcLang.IsEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Before FindStyleVariations has been called, mFontPatterns will contain
|
|
|
|
// the font patterns. Afterward, it'll be empty, but mAvailableFonts
|
|
|
|
// will contain the font entries, each of which holds a reference to its
|
|
|
|
// pattern. We only check the first pattern in each list, because support
|
|
|
|
// for langs is considered to be consistent across all faces in a family.
|
|
|
|
FcPattern* fontPattern;
|
|
|
|
if (mFontPatterns.Length()) {
|
|
|
|
fontPattern = mFontPatterns[0];
|
|
|
|
} else if (mAvailableFonts.Length()) {
|
|
|
|
fontPattern = static_cast<gfxFontconfigFontEntry*>(mAvailableFonts[0].get())
|
|
|
|
->GetPattern();
|
|
|
|
} else {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// is lang included in the underlying pattern?
|
|
|
|
return PatternHasLang(fontPattern, ToFcChar8Ptr(fcLang.get()));
|
|
|
|
}
|
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
/* virtual */
|
|
|
|
gfxFontconfigFontFamily::~gfxFontconfigFontFamily() {
|
|
|
|
// Should not be dropped by stylo
|
2017-11-02 23:29:33 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename Func>
|
2017-04-07 00:41:02 +03:00
|
|
|
void gfxFontconfigFontFamily::AddFacesToFontList(Func aAddPatternFunc) {
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
if (HasStyles()) {
|
|
|
|
for (auto& fe : mAvailableFonts) {
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!fe) {
|
2015-05-13 08:11:26 +03:00
|
|
|
continue;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
2017-08-07 23:20:44 +03:00
|
|
|
auto fce = static_cast<gfxFontconfigFontEntry*>(fe.get());
|
2018-06-15 02:42:56 +03:00
|
|
|
aAddPatternFunc(fce->GetPattern(), mContainsAppFonts);
|
2017-08-07 23:20:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-11-02 23:29:33 +03:00
|
|
|
for (auto& pat : mFontPatterns) {
|
|
|
|
aAddPatternFunc(pat, mContainsAppFonts);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontconfigFont::gfxFontconfigFont(
|
2017-04-07 00:41:02 +03:00
|
|
|
const RefPtr<UnscaledFontFontconfig>& aUnscaledFont,
|
2019-10-02 00:56:30 +03:00
|
|
|
RefPtr<SharedFTFace>&& aFTFace, FcPattern* aPattern, gfxFloat aAdjustedSize,
|
|
|
|
gfxFontEntry* aFontEntry, const gfxFontStyle* aFontStyle, int aLoadFlags,
|
|
|
|
bool aEmbolden)
|
|
|
|
: gfxFT2FontBase(aUnscaledFont, std::move(aFTFace), aFontEntry, aFontStyle,
|
|
|
|
aLoadFlags, aEmbolden),
|
2017-08-07 23:20:37 +03:00
|
|
|
mPattern(aPattern) {
|
2019-09-16 20:15:10 +03:00
|
|
|
mAdjustedSize = aAdjustedSize;
|
|
|
|
InitMetrics();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2020-03-04 18:39:20 +03:00
|
|
|
gfxFontconfigFont::~gfxFontconfigFont() = default;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
already_AddRefed<ScaledFont> gfxFontconfigFont::GetScaledFont(
|
2017-08-07 23:20:44 +03:00
|
|
|
mozilla::gfx::DrawTarget* aTarget) {
|
|
|
|
if (!mAzureScaledFont) {
|
2019-09-16 20:07:59 +03:00
|
|
|
mAzureScaledFont = Factory::CreateScaledFontForFontconfigFont(
|
2019-10-02 00:56:30 +03:00
|
|
|
GetUnscaledFont(), GetAdjustedSize(), mFTFace, GetPattern());
|
2018-07-04 17:56:40 +03:00
|
|
|
InitializeScaledFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-08-07 23:20:44 +03:00
|
|
|
|
|
|
|
RefPtr<ScaledFont> scaledFont(mAzureScaledFont);
|
|
|
|
return scaledFont.forget();
|
|
|
|
}
|
|
|
|
|
2019-09-16 20:15:10 +03:00
|
|
|
bool gfxFontconfigFont::ShouldHintMetrics() const {
|
|
|
|
return !GetStyle()->printerFont;
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
gfxFcPlatformFontList::gfxFcPlatformFontList()
|
2015-06-10 09:23:45 +03:00
|
|
|
: mLocalNames(64),
|
|
|
|
mGenericMappings(32),
|
|
|
|
mFcSubstituteCache(64),
|
|
|
|
mLastConfig(nullptr),
|
2015-11-16 02:48:40 +03:00
|
|
|
mAlwaysUseFontconfigGenerics(true) {
|
2021-08-06 17:06:53 +03:00
|
|
|
CheckFamilyList(kBaseFonts_Ubuntu_20_04);
|
|
|
|
CheckFamilyList(kLangFonts_Ubuntu_20_04);
|
|
|
|
CheckFamilyList(kBaseFonts_Fedora_32);
|
2019-09-22 19:21:06 +03:00
|
|
|
mLastConfig = FcConfigGetCurrent();
|
2017-11-02 23:29:33 +03:00
|
|
|
if (XRE_IsParentProcess()) {
|
|
|
|
// if the rescan interval is set, start the timer
|
|
|
|
int rescanInterval = FcConfigGetRescanInterval(nullptr);
|
|
|
|
if (rescanInterval) {
|
|
|
|
NS_NewTimerWithFuncCallback(
|
|
|
|
getter_AddRefs(mCheckFontUpdatesTimer), CheckFontUpdates, this,
|
|
|
|
(rescanInterval + 1) * 1000, nsITimer::TYPE_REPEATING_SLACK,
|
|
|
|
"gfxFcPlatformFontList::gfxFcPlatformFontList");
|
|
|
|
if (!mCheckFontUpdatesTimer) {
|
|
|
|
NS_WARNING("Failure to create font updates timer");
|
2015-05-13 08:11:26 +03:00
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:26 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
mBundledFontsInitialized = false;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
gfxFcPlatformFontList::~gfxFcPlatformFontList() {
|
2015-05-13 08:11:26 +03:00
|
|
|
if (mCheckFontUpdatesTimer) {
|
|
|
|
mCheckFontUpdatesTimer->Cancel();
|
|
|
|
mCheckFontUpdatesTimer = nullptr;
|
|
|
|
}
|
2021-05-01 23:00:31 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
ClearSystemFontOptions();
|
|
|
|
#endif
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2017-11-09 19:54:30 +03:00
|
|
|
void gfxFcPlatformFontList::AddFontSetFamilies(FcFontSet* aFontSet,
|
|
|
|
const SandboxPolicy* aPolicy,
|
|
|
|
bool aAppFonts) {
|
2015-05-13 08:11:25 +03:00
|
|
|
// This iterates over the fonts in a font set and adds in gfxFontFamily
|
2017-11-02 23:29:33 +03:00
|
|
|
// objects for each family. Individual gfxFontEntry objects for each face
|
|
|
|
// are not created here; the patterns are just stored in the family. When
|
|
|
|
// a family is actually used, it will be populated with gfxFontEntry
|
|
|
|
// records and the patterns moved to those.
|
2015-05-18 06:33:46 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!aFontSet) {
|
2017-11-02 23:29:33 +03:00
|
|
|
NS_WARNING("AddFontSetFamilies called with a null font set.");
|
|
|
|
return;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FcChar8* lastFamilyName = (FcChar8*)"";
|
2018-08-22 12:27:00 +03:00
|
|
|
RefPtr<gfxFontconfigFontFamily> fontFamily;
|
|
|
|
nsAutoCString familyName;
|
|
|
|
for (int f = 0; f < aFontSet->nfont; f++) {
|
2017-11-09 19:54:30 +03:00
|
|
|
FcPattern* pattern = aFontSet->fonts[f];
|
2017-11-02 23:29:33 +03:00
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
// Skip any fonts that aren't readable for us (e.g. due to restrictive
|
|
|
|
// file ownership/permissions).
|
|
|
|
FcChar8* path;
|
|
|
|
if (FcPatternGetString(pattern, FC_FILE, 0, &path) != FcResultMatch) {
|
|
|
|
continue;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
if (access(reinterpret_cast<const char*>(path), F_OK | R_OK) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
|
2019-03-19 01:31:59 +03:00
|
|
|
#if defined(MOZ_SANDBOX) && defined(XP_LINUX)
|
2017-11-02 23:29:33 +03:00
|
|
|
// Skip any fonts that will be blocked by the content-process sandbox
|
|
|
|
// policy.
|
|
|
|
if (aPolicy && !(aPolicy->Lookup(reinterpret_cast<const char*>(path)) &
|
|
|
|
SandboxBroker::Perms::MAY_READ)) {
|
|
|
|
continue;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
2017-11-02 23:29:33 +03:00
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
AddPatternToFontList(pattern, lastFamilyName, familyName, fontFamily,
|
|
|
|
aAppFonts);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFcPlatformFontList::AddPatternToFontList(
|
|
|
|
FcPattern* aFont, FcChar8*& aLastFamilyName, nsACString& aFamilyName,
|
|
|
|
RefPtr<gfxFontconfigFontFamily>& aFontFamily, bool aAppFonts) {
|
|
|
|
// get canonical name
|
|
|
|
uint32_t cIndex = FindCanonicalNameIndex(aFont, FC_FAMILYLANG);
|
|
|
|
FcChar8* canonical = nullptr;
|
|
|
|
FcPatternGetString(aFont, FC_FAMILY, cIndex, &canonical);
|
|
|
|
if (!canonical) {
|
|
|
|
return;
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
|
|
|
|
// same as the last one? no need to add a new family, skip
|
|
|
|
if (FcStrCmp(canonical, aLastFamilyName) != 0) {
|
|
|
|
aLastFamilyName = canonical;
|
|
|
|
|
|
|
|
// add new family if one doesn't already exist
|
|
|
|
aFamilyName.Truncate();
|
|
|
|
aFamilyName = ToCharPtr(canonical);
|
2018-09-12 22:34:57 +03:00
|
|
|
nsAutoCString keyName(aFamilyName);
|
2017-11-02 23:29:33 +03:00
|
|
|
ToLowerCase(keyName);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-03-01 12:59:29 +03:00
|
|
|
aFontFamily = static_cast<gfxFontconfigFontFamily*>(
|
|
|
|
mFontFamilies
|
|
|
|
.LookupOrInsertWith(keyName,
|
|
|
|
[&] {
|
|
|
|
FontVisibility visibility =
|
|
|
|
aAppFonts
|
|
|
|
? FontVisibility::Base
|
|
|
|
: GetVisibilityForFamily(keyName);
|
|
|
|
return MakeRefPtr<gfxFontconfigFontFamily>(
|
|
|
|
aFamilyName, visibility);
|
|
|
|
})
|
|
|
|
.get());
|
2017-11-02 23:29:33 +03:00
|
|
|
// Record if the family contains fonts from the app font set
|
|
|
|
// (in which case we won't rely on fontconfig's charmap, due to
|
|
|
|
// bug 1276594).
|
|
|
|
if (aAppFonts) {
|
|
|
|
aFontFamily->SetFamilyContainsAppFonts(true);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2021-04-09 17:50:44 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-04-09 17:50:44 +03:00
|
|
|
// Add pointers to other localized family names. Most fonts
|
|
|
|
// only have a single name, so the first call to GetString
|
|
|
|
// will usually not match
|
|
|
|
FcChar8* otherName;
|
|
|
|
int n = (cIndex == 0 ? 1 : 0);
|
2021-04-20 13:42:44 +03:00
|
|
|
while (FcPatternGetString(aFont, FC_FAMILY, n, &otherName) == FcResultMatch) {
|
2021-04-09 17:50:44 +03:00
|
|
|
nsAutoCString otherFamilyName(ToCharPtr(otherName));
|
|
|
|
AddOtherFamilyName(aFontFamily, otherFamilyName);
|
|
|
|
n++;
|
|
|
|
if (n == int(cIndex)) {
|
|
|
|
n++; // skip over canonical name
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2021-04-09 17:50:44 +03:00
|
|
|
const bool singleName = n == 1;
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
MOZ_ASSERT(aFontFamily, "font must belong to a font family");
|
2021-04-09 17:50:44 +03:00
|
|
|
aFontFamily->AddFontPattern(aFont, singleName);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// map the psname, fullname ==> font family for local font lookups
|
2018-09-12 22:34:57 +03:00
|
|
|
nsAutoCString psname, fullname;
|
2015-05-13 08:11:25 +03:00
|
|
|
GetFaceNames(aFont, aFamilyName, psname, fullname);
|
2017-11-02 23:29:33 +03:00
|
|
|
if (!psname.IsEmpty()) {
|
|
|
|
ToLowerCase(psname);
|
2021-03-09 14:39:36 +03:00
|
|
|
mLocalNames.InsertOrUpdate(psname, RefPtr{aFont});
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
if (!fullname.IsEmpty()) {
|
|
|
|
ToLowerCase(fullname);
|
2021-04-09 17:50:44 +03:00
|
|
|
mLocalNames.WithEntryHandle(fullname, [&](auto&& entry) {
|
|
|
|
if (entry && !singleName) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
entry.InsertOrUpdate(RefPtr{aFont});
|
|
|
|
});
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2016-08-23 03:06:07 +03:00
|
|
|
nsresult gfxFcPlatformFontList::InitFontListForPlatform() {
|
2017-11-02 23:29:33 +03:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
2021-01-18 23:04:36 +03:00
|
|
|
if (StaticPrefs::gfx_bundled_fonts_activate_AtStartup() != 0) {
|
|
|
|
ActivateBundledFonts();
|
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
#endif
|
2015-05-13 08:11:26 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
mLocalNames.Clear();
|
2017-11-02 23:29:33 +03:00
|
|
|
mFcSubstituteCache.Clear();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
ClearSystemFontOptions();
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
mAlwaysUseFontconfigGenerics = PrefFontListsUseOnlyGenerics();
|
|
|
|
mOtherFamilyNamesInitialized = true;
|
|
|
|
|
2019-09-22 19:21:06 +03:00
|
|
|
mLastConfig = FcConfigGetCurrent();
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
// Content process: use the font list passed from the chrome process,
|
|
|
|
// because we can't rely on fontconfig in the presence of sandboxing;
|
|
|
|
// it may report fonts that we can't actually access.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
FcChar8* lastFamilyName = (FcChar8*)"";
|
|
|
|
RefPtr<gfxFontconfigFontFamily> fontFamily;
|
|
|
|
nsAutoCString familyName;
|
|
|
|
|
|
|
|
// Get font list that was passed during XPCOM startup
|
|
|
|
// or in an UpdateFontList message.
|
|
|
|
auto& fontList = dom::ContentChild::GetSingleton()->SystemFontList();
|
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
UpdateSystemFontOptionsFromIpc(fontList.options());
|
|
|
|
#endif
|
|
|
|
|
2017-11-13 00:35:25 +03:00
|
|
|
// For fontconfig versions between 2.10.94 and 2.11.1 inclusive,
|
2017-11-02 23:29:33 +03:00
|
|
|
// we need to escape any leading space in the charset element,
|
2017-11-13 00:35:25 +03:00
|
|
|
// otherwise FcNameParse will fail. :(
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2017-11-13 00:35:25 +03:00
|
|
|
// The bug was introduced on 2013-05-24 by
|
|
|
|
// https://cgit.freedesktop.org/fontconfig/commit/?id=cd9b1033a68816a7acfbba1718ba0aa5888f6ec7
|
|
|
|
// "Bug 64906 - FcNameParse() should ignore leading whitespace in
|
|
|
|
// parameters"
|
|
|
|
// because ignoring a leading space in the encoded value of charset
|
|
|
|
// causes erroneous decoding of the whole element.
|
2017-11-02 23:29:33 +03:00
|
|
|
// This first shipped in version 2.10.94, and was eventually fixed as
|
|
|
|
// a side-effect of switching to the "human-readable" representation of
|
2017-11-13 00:35:25 +03:00
|
|
|
// charsets on 2014-07-03 in
|
|
|
|
// https://cgit.freedesktop.org/fontconfig/commit/?id=e708e97c351d3bc9f7030ef22ac2f007d5114730
|
|
|
|
// "Change charset parse/unparse format to be human readable"
|
|
|
|
// (with a followup fix next day) which means a leading space is no
|
|
|
|
// longer significant. This fix landed after 2.11.1 had been shipped,
|
|
|
|
// so the first version tag without the bug is 2.11.91.
|
|
|
|
int fcVersion = FcGetVersion();
|
|
|
|
bool fcCharsetParseBug = fcVersion >= 21094 && fcVersion <= 21101;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
for (FontPatternListEntry& fpe : fontList.entries()) {
|
2017-11-13 00:35:25 +03:00
|
|
|
nsCString& patternStr = fpe.pattern();
|
|
|
|
if (fcCharsetParseBug) {
|
|
|
|
int32_t index = patternStr.Find(":charset= ");
|
|
|
|
if (index != kNotFound) {
|
|
|
|
// insert backslash after the =, before the space
|
|
|
|
patternStr.Insert('\\', index + 9);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
FcPattern* pattern = FcNameParse((const FcChar8*)patternStr.get());
|
|
|
|
AddPatternToFontList(pattern, lastFamilyName, familyName, fontFamily,
|
|
|
|
fpe.appFontFamily());
|
|
|
|
FcPatternDestroy(pattern);
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
LOG_FONTLIST(
|
2017-11-02 23:29:33 +03:00
|
|
|
("got font list from chrome process: "
|
|
|
|
"%u faces in %u families",
|
2021-05-01 23:00:31 +03:00
|
|
|
(unsigned)fontList.entries().Length(), mFontFamilies.Count()));
|
2017-11-09 19:54:30 +03:00
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
fontList.entries().Clear();
|
2017-11-10 19:05:33 +03:00
|
|
|
return NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
UpdateSystemFontOptions();
|
|
|
|
|
2017-11-09 19:54:30 +03:00
|
|
|
UniquePtr<SandboxPolicy> policy;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-03-19 01:31:59 +03:00
|
|
|
#if defined(MOZ_SANDBOX) && defined(XP_LINUX)
|
2017-11-22 14:10:20 +03:00
|
|
|
// If read sandboxing is enabled, create a temporary SandboxPolicy to
|
|
|
|
// check font paths; use a fake PID to avoid picking up any PID-specific
|
|
|
|
// rules by accident.
|
2017-11-09 19:54:30 +03:00
|
|
|
SandboxBrokerPolicyFactory policyFactory;
|
2017-11-22 14:10:20 +03:00
|
|
|
if (GetEffectiveContentSandboxLevel() > 2 &&
|
2017-11-09 19:54:30 +03:00
|
|
|
!PR_GetEnv("MOZ_DISABLE_CONTENT_SANDBOX")) {
|
|
|
|
policy = policyFactory.GetContentPolicy(-1, false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// iterate over available fonts
|
|
|
|
FcFontSet* systemFonts = FcConfigGetFonts(nullptr, FcSetSystem);
|
2017-11-09 19:54:30 +03:00
|
|
|
AddFontSetFamilies(systemFonts, policy.get(), /* aAppFonts = */ false);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
2021-01-18 23:04:36 +03:00
|
|
|
if (StaticPrefs::gfx_bundled_fonts_activate_AtStartup() != 0) {
|
|
|
|
FcFontSet* appFonts = FcConfigGetFonts(nullptr, FcSetApplication);
|
|
|
|
AddFontSetFamilies(appFonts, policy.get(), /* aAppFonts = */ true);
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
#endif
|
|
|
|
|
2017-11-10 19:05:33 +03:00
|
|
|
return NS_OK;
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
void gfxFcPlatformFontList::ReadSystemFontList(dom::SystemFontList* retValue) {
|
2017-11-02 23:29:33 +03:00
|
|
|
// Fontconfig versions below 2.9 drop the FC_FILE element in FcNameUnparse
|
|
|
|
// (see https://bugs.freedesktop.org/show_bug.cgi?id=26718), so when using
|
|
|
|
// an older version, we manually append it to the unparsed pattern.
|
2021-05-01 23:00:31 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
SystemFontOptionsToIpc(retValue->options());
|
|
|
|
#endif
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
if (FcGetVersion() < 20900) {
|
2021-03-12 19:14:58 +03:00
|
|
|
for (const auto& entry : mFontFamilies) {
|
|
|
|
auto* family = static_cast<gfxFontconfigFontFamily*>(entry.GetWeak());
|
2017-11-02 23:29:33 +03:00
|
|
|
family->AddFacesToFontList([&](FcPattern* aPat, bool aAppFonts) {
|
|
|
|
char* s = (char*)FcNameUnparse(aPat);
|
2019-04-27 18:38:28 +03:00
|
|
|
nsDependentCString patternStr(s);
|
2019-07-16 16:52:19 +03:00
|
|
|
char* file = nullptr;
|
2017-11-02 23:29:33 +03:00
|
|
|
if (FcResultMatch ==
|
2019-07-16 16:52:19 +03:00
|
|
|
FcPatternGetString(aPat, FC_FILE, 0, (FcChar8**)&file)) {
|
2017-11-02 23:29:33 +03:00
|
|
|
patternStr.Append(":file=");
|
2019-07-16 16:52:19 +03:00
|
|
|
patternStr.Append(file);
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
2021-05-01 23:00:31 +03:00
|
|
|
retValue->entries().AppendElement(
|
|
|
|
FontPatternListEntry(patternStr, aAppFonts));
|
2019-04-27 18:38:28 +03:00
|
|
|
free(s);
|
2018-11-30 13:46:48 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-12 19:14:58 +03:00
|
|
|
for (const auto& entry : mFontFamilies) {
|
|
|
|
auto* family = static_cast<gfxFontconfigFontFamily*>(entry.GetWeak());
|
2017-11-02 23:29:33 +03:00
|
|
|
family->AddFacesToFontList([&](FcPattern* aPat, bool aAppFonts) {
|
|
|
|
char* s = (char*)FcNameUnparse(aPat);
|
|
|
|
nsDependentCString patternStr(s);
|
2021-05-01 23:00:31 +03:00
|
|
|
retValue->entries().AppendElement(
|
|
|
|
FontPatternListEntry(patternStr, aAppFonts));
|
2018-11-30 13:46:48 +03:00
|
|
|
free(s);
|
|
|
|
});
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-11-02 23:29:33 +03:00
|
|
|
}
|
|
|
|
|
2021-04-20 13:42:44 +03:00
|
|
|
// Per family array of faces.
|
|
|
|
class FacesData {
|
|
|
|
using FaceInitArray = AutoTArray<fontlist::Face::InitData, 8>;
|
|
|
|
|
|
|
|
FaceInitArray mFaces;
|
|
|
|
|
|
|
|
// Number of faces that have a single name. Faces that have multiple names are
|
|
|
|
// sorted last.
|
|
|
|
uint32_t mUniqueNameFaceCount = 0;
|
|
|
|
|
|
|
|
public:
|
|
|
|
void Add(fontlist::Face::InitData&& aData, bool aSingleName) {
|
|
|
|
if (aSingleName) {
|
|
|
|
mFaces.InsertElementAt(mUniqueNameFaceCount++, std::move(aData));
|
|
|
|
} else {
|
|
|
|
mFaces.AppendElement(std::move(aData));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const FaceInitArray& Get() const { return mFaces; }
|
|
|
|
};
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
void gfxFcPlatformFontList::InitSharedFontListForPlatform() {
|
|
|
|
mLocalNames.Clear();
|
|
|
|
mFcSubstituteCache.Clear();
|
|
|
|
|
|
|
|
mAlwaysUseFontconfigGenerics = PrefFontListsUseOnlyGenerics();
|
|
|
|
mOtherFamilyNamesInitialized = true;
|
|
|
|
|
2019-09-22 19:21:06 +03:00
|
|
|
mLastConfig = FcConfigGetCurrent();
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
if (!XRE_IsParentProcess()) {
|
2021-05-01 23:00:31 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
auto& fontList = dom::ContentChild::GetSingleton()->SystemFontList();
|
|
|
|
UpdateSystemFontOptionsFromIpc(fontList.options());
|
|
|
|
#endif
|
2019-04-27 18:38:28 +03:00
|
|
|
// Content processes will access the shared-memory data created by the
|
|
|
|
// parent, so they do not need to query fontconfig for the available
|
|
|
|
// fonts themselves.
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
UpdateSystemFontOptions();
|
|
|
|
#endif
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
2021-01-18 23:04:36 +03:00
|
|
|
if (StaticPrefs::gfx_bundled_fonts_activate_AtStartup() != 0) {
|
2021-03-08 19:23:39 +03:00
|
|
|
TimeStamp start = TimeStamp::Now();
|
2021-01-18 23:04:36 +03:00
|
|
|
ActivateBundledFonts();
|
2021-03-08 19:23:39 +03:00
|
|
|
TimeStamp end = TimeStamp::Now();
|
|
|
|
Telemetry::Accumulate(Telemetry::FONTLIST_BUNDLEDFONTS_ACTIVATE,
|
|
|
|
(end - start).ToMilliseconds());
|
2021-01-18 23:04:36 +03:00
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
UniquePtr<SandboxPolicy> policy;
|
|
|
|
|
|
|
|
#if defined(MOZ_CONTENT_SANDBOX) && defined(XP_LINUX)
|
|
|
|
// If read sandboxing is enabled, create a temporary SandboxPolicy to
|
|
|
|
// check font paths; use a fake PID to avoid picking up any PID-specific
|
|
|
|
// rules by accident.
|
|
|
|
SandboxBrokerPolicyFactory policyFactory;
|
|
|
|
if (GetEffectiveContentSandboxLevel() > 2 &&
|
|
|
|
!PR_GetEnv("MOZ_DISABLE_CONTENT_SANDBOX")) {
|
|
|
|
policy = policyFactory.GetContentPolicy(-1, false);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsTArray<fontlist::Family::InitData> families;
|
|
|
|
|
2021-04-20 13:42:44 +03:00
|
|
|
nsClassHashtable<nsCStringHashKey, FacesData> faces;
|
2019-04-27 18:38:28 +03:00
|
|
|
|
2020-09-09 22:56:50 +03:00
|
|
|
// Do we need to work around the fontconfig FcNameParse/FcNameUnparse bug
|
|
|
|
// (present in versions between 2.10.94 and 2.11.1 inclusive)? See comment
|
|
|
|
// in InitFontListForPlatform for details.
|
|
|
|
int fcVersion = FcGetVersion();
|
|
|
|
bool fcCharsetParseBug = fcVersion >= 21094 && fcVersion <= 21101;
|
|
|
|
|
|
|
|
auto addPattern = [this, fcCharsetParseBug, &families, &faces](
|
2019-04-27 18:38:28 +03:00
|
|
|
FcPattern* aPattern, FcChar8*& aLastFamilyName,
|
|
|
|
nsCString& aFamilyName, bool aAppFont) -> void {
|
|
|
|
// get canonical name
|
|
|
|
uint32_t cIndex = FindCanonicalNameIndex(aPattern, FC_FAMILYLANG);
|
|
|
|
FcChar8* canonical = nullptr;
|
|
|
|
FcPatternGetString(aPattern, FC_FAMILY, cIndex, &canonical);
|
|
|
|
if (!canonical) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-07-15 21:38:51 +03:00
|
|
|
nsAutoCString keyName;
|
|
|
|
keyName = ToCharPtr(canonical);
|
|
|
|
ToLowerCase(keyName);
|
2021-04-20 13:42:44 +03:00
|
|
|
|
|
|
|
aLastFamilyName = canonical;
|
|
|
|
aFamilyName = ToCharPtr(canonical);
|
2019-04-27 18:38:28 +03:00
|
|
|
|
2020-07-15 21:38:51 +03:00
|
|
|
// Same canonical family name as the last one? Definitely no need to add a
|
|
|
|
// new family record.
|
2021-04-20 13:42:44 +03:00
|
|
|
auto* faceList =
|
|
|
|
faces
|
|
|
|
.LookupOrInsertWith(
|
|
|
|
keyName,
|
|
|
|
[&] {
|
|
|
|
FontVisibility visibility =
|
|
|
|
aAppFont ? FontVisibility::Base
|
|
|
|
: GetVisibilityForFamily(keyName);
|
|
|
|
families.AppendElement(fontlist::Family::InitData(
|
|
|
|
keyName, aFamilyName, fontlist::Family::kNoIndex,
|
|
|
|
visibility,
|
|
|
|
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
|
|
|
return MakeUnique<FacesData>();
|
|
|
|
})
|
|
|
|
.get();
|
2019-04-27 18:38:28 +03:00
|
|
|
|
|
|
|
char* s = (char*)FcNameUnparse(aPattern);
|
|
|
|
nsAutoCString descriptor(s);
|
|
|
|
free(s);
|
|
|
|
|
2020-09-09 22:56:50 +03:00
|
|
|
if (fcCharsetParseBug) {
|
|
|
|
// Escape any leading space in charset to work around FcNameParse bug.
|
|
|
|
int32_t index = descriptor.Find(":charset= ");
|
|
|
|
if (index != kNotFound) {
|
|
|
|
// insert backslash after the =, before the space
|
|
|
|
descriptor.Insert('\\', index + 9);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
WeightRange weight(FontWeight::Normal());
|
|
|
|
StretchRange stretch(FontStretch::Normal());
|
|
|
|
SlantStyleRange style(FontSlantStyle::Normal());
|
2021-06-06 23:30:14 +03:00
|
|
|
uint16_t size;
|
|
|
|
GetFontProperties(aPattern, &weight, &stretch, &style, &size);
|
2019-04-27 18:38:28 +03:00
|
|
|
|
2021-06-06 23:30:14 +03:00
|
|
|
auto initData = fontlist::Face::InitData{descriptor, 0, size, false,
|
|
|
|
weight, stretch, style};
|
2020-07-15 21:38:51 +03:00
|
|
|
|
|
|
|
// Add entries for any other localized family names. (Most fonts only have
|
|
|
|
// a single family name, so the first call to GetString will usually fail).
|
|
|
|
FcChar8* otherName;
|
|
|
|
int n = (cIndex == 0 ? 1 : 0);
|
|
|
|
while (FcPatternGetString(aPattern, FC_FAMILY, n, &otherName) ==
|
|
|
|
FcResultMatch) {
|
|
|
|
nsAutoCString otherFamilyName(ToCharPtr(otherName));
|
|
|
|
keyName = otherFamilyName;
|
|
|
|
ToLowerCase(keyName);
|
|
|
|
|
2021-02-22 15:07:46 +03:00
|
|
|
faces
|
2021-02-26 12:11:45 +03:00
|
|
|
.LookupOrInsertWith(
|
|
|
|
keyName,
|
|
|
|
[&] {
|
|
|
|
FontVisibility visibility =
|
|
|
|
aAppFont ? FontVisibility::Base
|
|
|
|
: GetVisibilityForFamily(keyName);
|
|
|
|
families.AppendElement(fontlist::Family::InitData(
|
|
|
|
keyName, otherFamilyName, fontlist::Family::kNoIndex,
|
|
|
|
visibility,
|
|
|
|
/*bundled*/ aAppFont, /*badUnderline*/ false));
|
|
|
|
|
2021-04-20 13:42:44 +03:00
|
|
|
return MakeUnique<FacesData>();
|
2021-02-26 12:11:45 +03:00
|
|
|
})
|
2021-04-20 13:42:44 +03:00
|
|
|
.get()
|
|
|
|
->Add(fontlist::Face::InitData(initData), /* singleName = */ false);
|
2020-07-15 21:38:51 +03:00
|
|
|
|
|
|
|
n++;
|
|
|
|
if (n == int(cIndex)) {
|
|
|
|
n++; // skip over canonical name
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 17:50:44 +03:00
|
|
|
|
|
|
|
const bool singleName = n == 1;
|
2021-04-20 13:42:44 +03:00
|
|
|
faceList->Add(std::move(initData), singleName);
|
2021-04-09 17:50:44 +03:00
|
|
|
|
|
|
|
// map the psname, fullname ==> font family for local font lookups
|
|
|
|
nsAutoCString psname, fullname;
|
|
|
|
GetFaceNames(aPattern, aFamilyName, psname, fullname);
|
|
|
|
if (!psname.IsEmpty()) {
|
|
|
|
ToLowerCase(psname);
|
|
|
|
mLocalNameTable.InsertOrUpdate(
|
|
|
|
psname, fontlist::LocalFaceRec::InitData(keyName, descriptor));
|
|
|
|
}
|
|
|
|
if (!fullname.IsEmpty()) {
|
|
|
|
ToLowerCase(fullname);
|
|
|
|
if (fullname != psname) {
|
|
|
|
mLocalNameTable.WithEntryHandle(fullname, [&](auto&& entry) {
|
|
|
|
if (entry && !singleName) {
|
|
|
|
// We only override an existing entry if this is the only way to
|
|
|
|
// name this family. This prevents dubious aliases from clobbering
|
|
|
|
// the local name table.
|
|
|
|
return;
|
|
|
|
}
|
2021-04-20 13:42:44 +03:00
|
|
|
entry.InsertOrUpdate(
|
|
|
|
fontlist::LocalFaceRec::InitData(keyName, descriptor));
|
2021-04-09 17:50:44 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
auto addFontSetFamilies = [&addPattern](FcFontSet* aFontSet,
|
|
|
|
SandboxPolicy* aPolicy,
|
|
|
|
bool aAppFonts) -> void {
|
|
|
|
FcChar8* lastFamilyName = (FcChar8*)"";
|
|
|
|
RefPtr<gfxFontconfigFontFamily> fontFamily;
|
|
|
|
nsAutoCString familyName;
|
|
|
|
for (int f = 0; f < aFontSet->nfont; f++) {
|
|
|
|
FcPattern* pattern = aFontSet->fonts[f];
|
|
|
|
|
|
|
|
// Skip any fonts that aren't readable for us (e.g. due to restrictive
|
|
|
|
// file ownership/permissions).
|
|
|
|
FcChar8* path;
|
|
|
|
if (FcPatternGetString(pattern, FC_FILE, 0, &path) != FcResultMatch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (access(reinterpret_cast<const char*>(path), F_OK | R_OK) != 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(MOZ_CONTENT_SANDBOX) && defined(XP_LINUX)
|
|
|
|
// Skip any fonts that will be blocked by the content-process sandbox
|
|
|
|
// policy.
|
|
|
|
if (aPolicy && !(aPolicy->Lookup(reinterpret_cast<const char*>(path)) &
|
|
|
|
SandboxBroker::Perms::MAY_READ)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-10 19:13:39 +03:00
|
|
|
// If this is a TrueType or OpenType font, discard the FC_CHARSET object
|
|
|
|
// (which may be very large), because we'll read the 'cmap' directly.
|
|
|
|
// This substantially reduces the pressure on shared memory (bug 1664151)
|
|
|
|
// due to the large font descriptors (serialized patterns).
|
|
|
|
FcChar8* fontFormat;
|
|
|
|
if (FcPatternGetString(pattern, FC_FONTFORMAT, 0, &fontFormat) ==
|
|
|
|
FcResultMatch &&
|
|
|
|
(!FcStrCmp(fontFormat, (const FcChar8*)"TrueType") ||
|
|
|
|
!FcStrCmp(fontFormat, (const FcChar8*)"CFF"))) {
|
|
|
|
FcPattern* clone = FcPatternDuplicate(pattern);
|
|
|
|
FcPatternDel(clone, FC_CHARSET);
|
|
|
|
addPattern(clone, lastFamilyName, familyName, aAppFonts);
|
|
|
|
FcPatternDestroy(clone);
|
|
|
|
} else {
|
|
|
|
addPattern(pattern, lastFamilyName, familyName, aAppFonts);
|
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// iterate over available fonts
|
|
|
|
FcFontSet* systemFonts = FcConfigGetFonts(nullptr, FcSetSystem);
|
|
|
|
addFontSetFamilies(systemFonts, policy.get(), /* aAppFonts = */ false);
|
|
|
|
|
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
2021-01-18 23:04:36 +03:00
|
|
|
if (StaticPrefs::gfx_bundled_fonts_activate_AtStartup() != 0) {
|
|
|
|
FcFontSet* appFonts = FcConfigGetFonts(nullptr, FcSetApplication);
|
|
|
|
addFontSetFamilies(appFonts, policy.get(), /* aAppFonts = */ true);
|
|
|
|
}
|
2019-04-27 18:38:28 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
mozilla::fontlist::FontList* list = SharedFontList();
|
|
|
|
list->SetFamilyNames(families);
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < families.Length(); i++) {
|
2021-04-20 13:42:44 +03:00
|
|
|
list->Families()[i].AddFaces(list, faces.Get(families[i].mKey)->Get());
|
2019-04-27 18:38:28 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-03 02:12:56 +03:00
|
|
|
gfxFcPlatformFontList::DistroID gfxFcPlatformFontList::GetDistroID() const {
|
|
|
|
// Helper called to initialize sResult the first time this is used.
|
|
|
|
auto getDistroID = []() {
|
|
|
|
DistroID result = DistroID::Unknown;
|
|
|
|
FILE* fp = fopen("/etc/os-release", "r");
|
|
|
|
if (fp) {
|
|
|
|
char buf[512];
|
|
|
|
while (fgets(buf, sizeof(buf), fp)) {
|
|
|
|
if (strncmp(buf, "ID=", 3) == 0) {
|
|
|
|
if (strncmp(buf + 3, "ubuntu", 6) == 0) {
|
|
|
|
result = DistroID::Ubuntu;
|
|
|
|
} else if (strncmp(buf + 3, "fedora", 6) == 0) {
|
|
|
|
result = DistroID::Fedora;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
static DistroID sResult = getDistroID();
|
|
|
|
return sResult;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontVisibility gfxFcPlatformFontList::GetVisibilityForFamily(
|
|
|
|
const nsACString& aName) const {
|
|
|
|
switch (GetDistroID()) {
|
|
|
|
case DistroID::Ubuntu:
|
2021-08-06 17:06:53 +03:00
|
|
|
if (FamilyInList(aName, kBaseFonts_Ubuntu_20_04)) {
|
2020-04-03 02:12:56 +03:00
|
|
|
return FontVisibility::Base;
|
|
|
|
}
|
2021-08-06 17:06:53 +03:00
|
|
|
if (FamilyInList(aName, kLangFonts_Ubuntu_20_04)) {
|
2020-04-03 02:12:56 +03:00
|
|
|
return FontVisibility::LangPack;
|
|
|
|
}
|
|
|
|
return FontVisibility::User;
|
|
|
|
case DistroID::Fedora:
|
2021-08-06 17:06:53 +03:00
|
|
|
if (FamilyInList(aName, kBaseFonts_Fedora_32)) {
|
2020-04-03 02:12:56 +03:00
|
|
|
return FontVisibility::Base;
|
|
|
|
}
|
|
|
|
return FontVisibility::User;
|
|
|
|
default:
|
|
|
|
// We don't know how to categorize fonts on this system
|
|
|
|
return FontVisibility::Unknown;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
gfxFontEntry* gfxFcPlatformFontList::CreateFontEntry(
|
|
|
|
fontlist::Face* aFace, const fontlist::Family* aFamily) {
|
2020-07-06 17:29:23 +03:00
|
|
|
nsAutoCString desc(aFace->mDescriptor.AsString(SharedFontList()));
|
2019-04-27 18:38:28 +03:00
|
|
|
FcPattern* pattern = FcNameParse((const FcChar8*)desc.get());
|
2020-07-06 17:29:23 +03:00
|
|
|
auto* fe = new gfxFontconfigFontEntry(desc, pattern, true);
|
2019-04-27 18:38:28 +03:00
|
|
|
FcPatternDestroy(pattern);
|
2020-07-06 17:29:23 +03:00
|
|
|
fe->InitializeFrom(aFace, aFamily);
|
2019-04-27 18:38:28 +03:00
|
|
|
return fe;
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// For displaying the fontlist in UI, use explicit call to FcFontList. Using
|
|
|
|
// FcFontList results in the list containing the localized names as dictated
|
|
|
|
// by system defaults.
|
2017-10-03 01:05:19 +03:00
|
|
|
static void GetSystemFontList(nsTArray<nsString>& aListOfFonts,
|
|
|
|
nsAtom* aLangGroup) {
|
2015-05-13 08:11:25 +03:00
|
|
|
aListOfFonts.Clear();
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
RefPtr<FcPattern> pat = dont_AddRef(FcPatternCreate());
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!pat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
UniquePtr<FcObjectSet> os(FcObjectSetBuild(FC_FAMILY, nullptr));
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!os) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the lang to the pattern
|
|
|
|
nsAutoCString fcLang;
|
|
|
|
gfxFcPlatformFontList* pfl = gfxFcPlatformFontList::PlatformFontList();
|
|
|
|
pfl->GetSampleLangForGroup(aLangGroup, fcLang,
|
2018-05-28 12:09:28 +03:00
|
|
|
/*aForFontEnumerationThread*/ true);
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!fcLang.IsEmpty()) {
|
|
|
|
FcPatternAddString(pat, FC_LANG, ToFcChar8Ptr(fcLang.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
UniquePtr<FcFontSet> fs(FcFontList(nullptr, pat, os.get()));
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!fs) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < fs->nfont; i++) {
|
|
|
|
char* family;
|
|
|
|
|
|
|
|
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8**)&family) !=
|
2017-11-02 23:29:33 +03:00
|
|
|
FcResultMatch) {
|
2015-05-13 08:11:25 +03:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
// Remove duplicates...
|
2015-05-13 08:11:25 +03:00
|
|
|
nsAutoString strFamily;
|
|
|
|
AppendUTF8toUTF16(MakeStringSpan(family), strFamily);
|
|
|
|
if (aListOfFonts.Contains(strFamily)) {
|
2015-11-16 02:48:40 +03:00
|
|
|
continue;
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
aListOfFonts.AppendElement(strFamily);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
aListOfFonts.Sort();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
void gfxFcPlatformFontList::GetFontList(nsAtom* aLangGroup,
|
2015-05-27 10:19:19 +03:00
|
|
|
const nsACString& aGenericFamily,
|
2015-05-13 08:11:25 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts) {
|
2015-05-27 10:19:19 +03:00
|
|
|
// Get the list of font family names using fontconfig
|
2015-05-13 08:11:25 +03:00
|
|
|
GetSystemFontList(aListOfFonts, aLangGroup);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// Under Linux, the generics "serif", "sans-serif" and "monospace"
|
|
|
|
// are included in the pref fontlist. These map to whatever fontconfig
|
|
|
|
// decides they should be for a given language, rather than one of the
|
|
|
|
// fonts listed in the prefs font lists (e.g. font.name.*, font.name-list.*)
|
2015-05-27 10:19:19 +03:00
|
|
|
bool serif = false, sansSerif = false, monospace = false;
|
2015-05-13 08:11:25 +03:00
|
|
|
if (aGenericFamily.IsEmpty())
|
|
|
|
serif = sansSerif = monospace = true;
|
|
|
|
else if (aGenericFamily.LowerCaseEqualsLiteral("serif"))
|
|
|
|
serif = true;
|
|
|
|
else if (aGenericFamily.LowerCaseEqualsLiteral("sans-serif"))
|
|
|
|
sansSerif = true;
|
2015-05-27 10:19:19 +03:00
|
|
|
else if (aGenericFamily.LowerCaseEqualsLiteral("monospace"))
|
2015-05-13 08:11:25 +03:00
|
|
|
monospace = true;
|
|
|
|
else if (aGenericFamily.LowerCaseEqualsLiteral("cursive") ||
|
|
|
|
aGenericFamily.LowerCaseEqualsLiteral("fantasy"))
|
|
|
|
serif = sansSerif = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
else
|
2018-06-18 08:43:11 +03:00
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected CSS generic font family");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-05-27 10:19:19 +03:00
|
|
|
// The first in the list becomes the default in
|
|
|
|
// FontBuilder.readFontSelection() if the preference-selected font is not
|
2015-05-13 08:11:25 +03:00
|
|
|
// available, so put system configured defaults first.
|
2015-05-27 10:19:19 +03:00
|
|
|
if (monospace) aListOfFonts.InsertElementAt(0, u"monospace"_ns);
|
|
|
|
if (sansSerif) aListOfFonts.InsertElementAt(0, u"sans-serif"_ns);
|
|
|
|
if (serif) aListOfFonts.InsertElementAt(0, u"serif"_ns);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-04-01 17:33:34 +03:00
|
|
|
FontFamily gfxFcPlatformFontList::GetDefaultFontForPlatform(
|
2020-11-13 16:15:39 +03:00
|
|
|
const gfxFontStyle* aStyle, nsAtom* aLanguage) {
|
2015-06-02 11:20:15 +03:00
|
|
|
// Get the default font by using a fake name to retrieve the first
|
|
|
|
// scalable font that fontconfig suggests for the given language.
|
2020-11-13 16:15:39 +03:00
|
|
|
PrefFontList* prefFonts = FindGenericFamilies(
|
|
|
|
"-moz-default"_ns, aLanguage ? aLanguage : nsGkAtoms::x_western);
|
2015-11-16 02:48:40 +03:00
|
|
|
NS_ASSERTION(prefFonts, "null list of generic fonts");
|
|
|
|
if (prefFonts && !prefFonts->IsEmpty()) {
|
2015-05-27 10:19:19 +03:00
|
|
|
return (*prefFonts)[0];
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2019-04-01 17:33:34 +03:00
|
|
|
return FontFamily();
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontEntry* gfxFcPlatformFontList::LookupLocalFont(
|
2018-04-25 09:18:23 +03:00
|
|
|
const nsACString& aFontName, WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry, SlantStyleRange aStyleForEntry) {
|
2017-05-18 04:56:24 +03:00
|
|
|
nsAutoCString keyName(aFontName);
|
|
|
|
ToLowerCase(keyName);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2019-04-27 18:38:28 +03:00
|
|
|
if (SharedFontList()) {
|
|
|
|
return LookupInSharedFaceNameList(aFontName, aWeightForEntry,
|
|
|
|
aStretchForEntry, aStyleForEntry);
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
// if name is not in the global list, done
|
2021-03-09 14:39:36 +03:00
|
|
|
const auto fontPattern = mLocalNames.Lookup(keyName);
|
2017-10-03 01:05:19 +03:00
|
|
|
if (!fontPattern) {
|
|
|
|
return nullptr;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2021-03-09 14:39:36 +03:00
|
|
|
return new gfxFontconfigFontEntry(aFontName, *fontPattern, aWeightForEntry,
|
2018-09-18 11:34:21 +03:00
|
|
|
aStretchForEntry, aStyleForEntry);
|
2015-11-16 02:48:40 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
gfxFontEntry* gfxFcPlatformFontList::MakePlatformFont(
|
|
|
|
const nsACString& aFontName, WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry, SlantStyleRange aStyleForEntry,
|
|
|
|
const uint8_t* aFontData, uint32_t aLength) {
|
2019-09-16 20:07:59 +03:00
|
|
|
RefPtr<FTUserFontData> ufd = new FTUserFontData(aFontData, aLength);
|
|
|
|
RefPtr<SharedFTFace> face = ufd->CloneFace();
|
2017-05-18 04:56:24 +03:00
|
|
|
if (!face) {
|
2018-09-12 22:34:57 +03:00
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-04-09 13:09:08 +03:00
|
|
|
return new gfxFontconfigFontEntry(aFontName, aWeightForEntry,
|
2019-09-16 20:07:59 +03:00
|
|
|
aStretchForEntry, aStyleForEntry,
|
|
|
|
std::move(face));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-06-20 10:44:21 +03:00
|
|
|
bool gfxFcPlatformFontList::FindAndAddFamilies(
|
2019-04-27 18:37:58 +03:00
|
|
|
StyleGenericFontFamily aGeneric, const nsACString& aFamily,
|
|
|
|
nsTArray<FamilyAndGeneric>* aOutput, FindFamiliesFlags aFlags,
|
2020-11-13 16:15:39 +03:00
|
|
|
gfxFontStyle* aStyle, nsAtom* aLanguage, gfxFloat aDevToCssSize) {
|
2015-05-13 08:11:25 +03:00
|
|
|
nsAutoCString familyName(aFamily);
|
|
|
|
ToLowerCase(familyName);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-11 00:42:26 +03:00
|
|
|
if (!(aFlags & FindFamiliesFlags::eQuotedFamilyName)) {
|
|
|
|
// deprecated generic names are explicitly converted to standard generics
|
|
|
|
bool isDeprecatedGeneric = false;
|
|
|
|
if (familyName.EqualsLiteral("sans") ||
|
|
|
|
familyName.EqualsLiteral("sans serif")) {
|
|
|
|
familyName.AssignLiteral("sans-serif");
|
|
|
|
isDeprecatedGeneric = true;
|
|
|
|
} else if (familyName.EqualsLiteral("mono")) {
|
|
|
|
familyName.AssignLiteral("monospace");
|
|
|
|
isDeprecatedGeneric = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// fontconfig generics? use fontconfig to determine the family for lang
|
|
|
|
if (isDeprecatedGeneric ||
|
2021-06-18 22:35:50 +03:00
|
|
|
mozilla::StyleSingleFontFamily::Parse(familyName).IsGeneric()) {
|
2020-11-13 16:15:39 +03:00
|
|
|
PrefFontList* prefFonts = FindGenericFamilies(familyName, aLanguage);
|
2019-04-11 00:42:26 +03:00
|
|
|
if (prefFonts && !prefFonts->IsEmpty()) {
|
|
|
|
aOutput->AppendElements(*prefFonts);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2016-04-09 13:09:08 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// fontconfig allows conditional substitutions in such a way that it's
|
|
|
|
// difficult to distinguish an explicit substitution from other suggested
|
|
|
|
// choices. To sniff out explicit substitutions, compare the substitutions
|
|
|
|
// for "font, -moz-sentinel" to "-moz-sentinel" to sniff out the
|
|
|
|
// substitutions
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2015-05-13 08:11:25 +03:00
|
|
|
// Example:
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2015-05-13 08:11:25 +03:00
|
|
|
// serif ==> DejaVu Serif, ...
|
|
|
|
// Helvetica, serif ==> Helvetica, TeX Gyre Heros, Nimbus Sans L, DejaVu
|
2018-11-30 13:46:48 +03:00
|
|
|
// Serif
|
|
|
|
//
|
2015-05-13 08:11:25 +03:00
|
|
|
// In this case fontconfig is including Tex Gyre Heros and
|
|
|
|
// Nimbus Sans L as alternatives for Helvetica.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-06-10 09:23:45 +03:00
|
|
|
// Because the FcConfigSubstitute call is quite expensive, we cache the
|
2016-04-09 13:09:08 +03:00
|
|
|
// actual font families found via this process. So check the cache first:
|
2021-03-02 16:32:01 +03:00
|
|
|
if (auto cachedFamilies = mFcSubstituteCache.Lookup(familyName)) {
|
|
|
|
if (cachedFamilies->IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
aOutput->AppendElements(*cachedFamilies);
|
|
|
|
return true;
|
|
|
|
}
|
2021-03-02 15:38:21 +03:00
|
|
|
|
2021-03-02 16:32:01 +03:00
|
|
|
// It wasn't in the cache, so we need to ask fontconfig...
|
|
|
|
const FcChar8* kSentinelName = ToFcChar8Ptr("-moz-sentinel");
|
|
|
|
FcChar8* sentinelFirstFamily = nullptr;
|
|
|
|
RefPtr<FcPattern> sentinelSubst = dont_AddRef(FcPatternCreate());
|
|
|
|
FcPatternAddString(sentinelSubst, FC_FAMILY, kSentinelName);
|
|
|
|
FcConfigSubstitute(nullptr, sentinelSubst, FcMatchPattern);
|
|
|
|
FcPatternGetString(sentinelSubst, FC_FAMILY, 0, &sentinelFirstFamily);
|
|
|
|
|
|
|
|
// substitutions for font, -moz-sentinel pattern
|
|
|
|
RefPtr<FcPattern> fontWithSentinel = dont_AddRef(FcPatternCreate());
|
|
|
|
FcPatternAddString(fontWithSentinel, FC_FAMILY,
|
|
|
|
ToFcChar8Ptr(familyName.get()));
|
|
|
|
FcPatternAddString(fontWithSentinel, FC_FAMILY, kSentinelName);
|
|
|
|
FcConfigSubstitute(nullptr, fontWithSentinel, FcMatchPattern);
|
|
|
|
|
|
|
|
// Add all font family matches until reaching the sentinel.
|
|
|
|
AutoTArray<FamilyAndGeneric, 10> cachedFamilies;
|
|
|
|
FcChar8* substName = nullptr;
|
|
|
|
for (int i = 0; FcPatternGetString(fontWithSentinel, FC_FAMILY, i,
|
|
|
|
&substName) == FcResultMatch;
|
|
|
|
i++) {
|
|
|
|
if (sentinelFirstFamily && FcStrCmp(substName, sentinelFirstFamily) == 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::FindAndAddFamilies(
|
|
|
|
aGeneric, nsDependentCString(ToCharPtr(substName)), &cachedFamilies,
|
|
|
|
aFlags, aStyle, aLanguage);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache the resulting list, so we don't have to do this again.
|
|
|
|
const auto& insertedCachedFamilies =
|
|
|
|
mFcSubstituteCache.InsertOrUpdate(familyName, std::move(cachedFamilies));
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2021-03-02 16:32:01 +03:00
|
|
|
if (insertedCachedFamilies.IsEmpty()) {
|
2016-04-12 09:06:22 +03:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2021-03-02 16:32:01 +03:00
|
|
|
aOutput->AppendElements(insertedCachedFamilies);
|
2015-05-13 08:11:25 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-11-16 02:48:36 +03:00
|
|
|
bool gfxFcPlatformFontList::GetStandardFamilyName(const nsCString& aFontName,
|
|
|
|
nsACString& aFamilyName) {
|
|
|
|
aFamilyName.Truncate();
|
|
|
|
|
|
|
|
// The fontconfig list of fonts includes generic family names in the
|
2018-09-12 22:34:57 +03:00
|
|
|
// font list. For these, just use the generic name.
|
2015-05-13 08:11:25 +03:00
|
|
|
if (aFontName.EqualsLiteral("serif") ||
|
|
|
|
aFontName.EqualsLiteral("sans-serif") ||
|
2018-09-12 22:34:57 +03:00
|
|
|
aFontName.EqualsLiteral("monospace")) {
|
|
|
|
aFamilyName.Assign(aFontName);
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:36 +03:00
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
RefPtr<FcPattern> pat = dont_AddRef(FcPatternCreate());
|
2015-11-16 02:48:36 +03:00
|
|
|
if (!pat) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
UniquePtr<FcObjectSet> os(FcObjectSetBuild(FC_FAMILY, nullptr));
|
2015-11-16 02:48:36 +03:00
|
|
|
if (!os) {
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:36 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// add the family name to the pattern
|
2015-11-16 02:48:36 +03:00
|
|
|
FcPatternAddString(pat, FC_FAMILY, ToFcChar8Ptr(aFontName.get()));
|
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
UniquePtr<FcFontSet> givenFS(FcFontList(nullptr, pat, os.get()));
|
2015-11-16 02:48:36 +03:00
|
|
|
if (!givenFS) {
|
|
|
|
return true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:36 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
// See if there is a font face with first family equal to the given family
|
2015-11-16 02:48:36 +03:00
|
|
|
// (needs to be in sync with names coming from GetFontList())
|
|
|
|
nsTArray<nsCString> candidates;
|
|
|
|
for (int i = 0; i < givenFS->nfont; i++) {
|
|
|
|
char* firstFamily;
|
|
|
|
|
|
|
|
if (FcPatternGetString(givenFS->fonts[i], FC_FAMILY, 0,
|
|
|
|
(FcChar8**)&firstFamily) != FcResultMatch) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCString first(firstFamily);
|
|
|
|
if (!candidates.Contains(first)) {
|
|
|
|
candidates.AppendElement(first);
|
|
|
|
|
|
|
|
if (aFontName.Equals(first)) {
|
2018-09-12 22:34:57 +03:00
|
|
|
aFamilyName.Assign(aFontName);
|
2015-11-16 02:48:36 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:36 +03:00
|
|
|
|
|
|
|
// Because fontconfig conflates different family name types, need to
|
|
|
|
// double check that the candidate name is not simply a different
|
2015-11-16 02:48:40 +03:00
|
|
|
// name type. For example, if a font with nameID=16 "Minion Pro" and
|
|
|
|
// nameID=21 "Minion Pro Caption" exists, calling FcFontList with
|
2018-05-25 16:07:57 +03:00
|
|
|
// family="Minion Pro" will return a set of patterns some of which
|
|
|
|
// will have a first family of "Minion Pro Caption". Ignore these
|
2015-11-16 02:48:40 +03:00
|
|
|
// patterns and use the first candidate that maps to a font set with
|
|
|
|
// the same number of faces and an identical set of patterns.
|
|
|
|
for (uint32_t j = 0; j < candidates.Length(); ++j) {
|
2015-11-16 02:48:36 +03:00
|
|
|
FcPatternDel(pat, FC_FAMILY);
|
2015-05-13 08:11:25 +03:00
|
|
|
FcPatternAddString(pat, FC_FAMILY, (FcChar8*)candidates[j].get());
|
2015-11-16 02:48:40 +03:00
|
|
|
|
2020-09-17 02:11:13 +03:00
|
|
|
UniquePtr<FcFontSet> candidateFS(FcFontList(nullptr, pat, os.get()));
|
2015-11-16 02:48:40 +03:00
|
|
|
if (!candidateFS) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (candidateFS->nfont != givenFS->nfont) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool equal = true;
|
|
|
|
for (int i = 0; i < givenFS->nfont; ++i) {
|
|
|
|
if (!FcPatternEqual(candidateFS->fonts[i], givenFS->fonts[i])) {
|
|
|
|
equal = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (equal) {
|
|
|
|
aFamilyName = candidates[j];
|
2016-04-12 09:06:22 +03:00
|
|
|
return true;
|
2015-11-16 02:48:40 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:40 +03:00
|
|
|
|
|
|
|
// didn't find localized name, leave family name blank
|
2018-05-25 16:07:57 +03:00
|
|
|
return true;
|
2015-11-16 02:48:40 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFcPlatformFontList::AddGenericFonts(
|
2019-04-27 18:37:58 +03:00
|
|
|
StyleGenericFontFamily aGenericType, nsAtom* aLanguage,
|
2018-04-17 23:45:29 +03:00
|
|
|
nsTArray<FamilyAndGeneric>& aFamilyList) {
|
|
|
|
bool usePrefFontList = false;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2018-09-18 11:34:21 +03:00
|
|
|
const char* generic = GetGenericName(aGenericType);
|
|
|
|
NS_ASSERTION(generic, "weird generic font type");
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!generic) {
|
|
|
|
return;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
// By default, most font prefs on Linux map to "use fontconfig"
|
|
|
|
// keywords. So only need to explicitly lookup font pref if
|
2018-09-18 11:34:21 +03:00
|
|
|
// non-default settings exist
|
|
|
|
nsAutoCString genericToLookup(generic);
|
2015-11-16 02:48:40 +03:00
|
|
|
if ((!mAlwaysUseFontconfigGenerics && aLanguage) ||
|
|
|
|
aLanguage == nsGkAtoms::x_math) {
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* langGroup = GetLangGroup(aLanguage);
|
2017-07-31 07:23:50 +03:00
|
|
|
nsAutoString fontlistValue;
|
|
|
|
Preferences::GetString(NamePref(generic, langGroup).get(), fontlistValue);
|
|
|
|
nsresult rv;
|
2015-11-16 02:48:40 +03:00
|
|
|
if (fontlistValue.IsEmpty()) {
|
2017-03-29 17:21:47 +03:00
|
|
|
// The font name list may have two or more family names as comma
|
|
|
|
// separated list. In such case, not matching with generic font
|
|
|
|
// name is fine because if the list prefers specific font, we
|
|
|
|
// should try to use the pref with complicated path.
|
2015-11-16 02:48:40 +03:00
|
|
|
rv = Preferences::GetString(NameListPref(generic, langGroup).get(),
|
2017-07-31 07:23:50 +03:00
|
|
|
fontlistValue);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-07-31 07:23:50 +03:00
|
|
|
rv = NS_OK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:40 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
if (!fontlistValue.EqualsLiteral("serif") &&
|
|
|
|
!fontlistValue.EqualsLiteral("sans-serif") &&
|
|
|
|
!fontlistValue.EqualsLiteral("monospace")) {
|
|
|
|
usePrefFontList = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2015-11-16 02:48:40 +03:00
|
|
|
// serif, sans-serif or monospace was specified
|
2018-09-18 11:34:21 +03:00
|
|
|
genericToLookup.Truncate();
|
2015-11-16 02:48:40 +03:00
|
|
|
AppendUTF16toUTF8(fontlistValue, genericToLookup);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-16 02:48:40 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// when pref fonts exist, use standard pref font lookup
|
2015-11-16 02:48:40 +03:00
|
|
|
if (usePrefFontList) {
|
|
|
|
return gfxPlatformFontList::AddGenericFonts(aGenericType, aLanguage,
|
|
|
|
aFamilyList);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
PrefFontList* prefFonts = FindGenericFamilies(genericToLookup, aLanguage);
|
|
|
|
NS_ASSERTION(prefFonts, "null generic font list");
|
|
|
|
aFamilyList.SetCapacity(aFamilyList.Length() + prefFonts->Length());
|
2018-09-18 11:34:21 +03:00
|
|
|
for (auto& f : *prefFonts) {
|
2019-04-01 17:33:34 +03:00
|
|
|
aFamilyList.AppendElement(FamilyAndGeneric(f, aGenericType));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-05-27 10:19:27 +03:00
|
|
|
void gfxFcPlatformFontList::ClearLangGroupPrefFonts() {
|
|
|
|
ClearGenericMappings();
|
|
|
|
gfxPlatformFontList::ClearLangGroupPrefFonts();
|
|
|
|
mAlwaysUseFontconfigGenerics = PrefFontListsUseOnlyGenerics();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-27 10:19:27 +03:00
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
gfxPlatformFontList::PrefFontList* gfxFcPlatformFontList::FindGenericFamilies(
|
|
|
|
const nsCString& aGeneric, nsAtom* aLanguage) {
|
|
|
|
// set up name
|
|
|
|
nsAutoCString fcLang;
|
|
|
|
GetSampleLangForGroup(aLanguage, fcLang);
|
|
|
|
ToLowerCase(fcLang);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-18 11:34:21 +03:00
|
|
|
nsAutoCString genericLang(aGeneric);
|
2015-11-20 07:35:15 +03:00
|
|
|
if (fcLang.Length() > 0) {
|
|
|
|
genericLang.Append('-');
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
genericLang.Append(fcLang);
|
2015-11-20 07:35:15 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// try to get the family from the cache
|
2021-02-15 18:12:17 +03:00
|
|
|
return mGenericMappings.WithEntryHandle(
|
|
|
|
genericLang, [&](auto&& entry) -> PrefFontList* {
|
|
|
|
if (!entry) {
|
|
|
|
// if not found, ask fontconfig to pick the appropriate font
|
|
|
|
RefPtr<FcPattern> genericPattern = dont_AddRef(FcPatternCreate());
|
|
|
|
FcPatternAddString(genericPattern, FC_FAMILY,
|
|
|
|
ToFcChar8Ptr(aGeneric.get()));
|
|
|
|
|
|
|
|
// -- prefer scalable fonts
|
|
|
|
FcPatternAddBool(genericPattern, FC_SCALABLE, FcTrue);
|
|
|
|
|
|
|
|
// -- add the lang to the pattern
|
|
|
|
if (!fcLang.IsEmpty()) {
|
|
|
|
FcPatternAddString(genericPattern, FC_LANG,
|
|
|
|
ToFcChar8Ptr(fcLang.get()));
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
// -- perform substitutions
|
|
|
|
FcConfigSubstitute(nullptr, genericPattern, FcMatchPattern);
|
|
|
|
FcDefaultSubstitute(genericPattern);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
// -- sort to get the closest matches
|
|
|
|
FcResult result;
|
|
|
|
UniquePtr<FcFontSet> faces(
|
|
|
|
FcFontSort(nullptr, genericPattern, FcFalse, nullptr, &result));
|
2021-02-15 17:43:23 +03:00
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
if (!faces) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
// -- select the fonts to be used for the generic
|
|
|
|
auto prefFonts = MakeUnique<PrefFontList>(); // can be empty but in
|
|
|
|
// practice won't happen
|
|
|
|
uint32_t limit =
|
|
|
|
gfxPlatformGtk::GetPlatform()->MaxGenericSubstitions();
|
|
|
|
bool foundFontWithLang = false;
|
|
|
|
for (int i = 0; i < faces->nfont; i++) {
|
|
|
|
FcPattern* font = faces->fonts[i];
|
|
|
|
FcChar8* mappedGeneric = nullptr;
|
|
|
|
|
|
|
|
FcPatternGetString(font, FC_FAMILY, 0, &mappedGeneric);
|
|
|
|
if (mappedGeneric) {
|
|
|
|
nsAutoCString mappedGenericName(ToCharPtr(mappedGeneric));
|
|
|
|
AutoTArray<FamilyAndGeneric, 1> genericFamilies;
|
|
|
|
if (gfxPlatformFontList::FindAndAddFamilies(
|
|
|
|
StyleGenericFontFamily::None, mappedGenericName,
|
|
|
|
&genericFamilies, FindFamiliesFlags(0))) {
|
|
|
|
MOZ_ASSERT(genericFamilies.Length() == 1,
|
|
|
|
"expected a single family");
|
|
|
|
if (!prefFonts->Contains(genericFamilies[0].mFamily)) {
|
|
|
|
prefFonts->AppendElement(genericFamilies[0].mFamily);
|
|
|
|
bool foundLang =
|
|
|
|
!fcLang.IsEmpty() &&
|
|
|
|
PatternHasLang(font, ToFcChar8Ptr(fcLang.get()));
|
|
|
|
foundFontWithLang = foundFontWithLang || foundLang;
|
|
|
|
// check to see if the list is full
|
|
|
|
if (prefFonts->Length() >= limit) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-15 17:43:23 +03:00
|
|
|
}
|
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
// if no font in the list matches the lang, trim all but the first one
|
|
|
|
if (!prefFonts->IsEmpty() && !foundFontWithLang) {
|
|
|
|
prefFonts->TruncateLength(1);
|
|
|
|
}
|
2021-02-15 17:43:23 +03:00
|
|
|
|
2021-02-15 18:12:17 +03:00
|
|
|
entry.Insert(std::move(prefFonts));
|
|
|
|
}
|
2021-03-01 12:59:29 +03:00
|
|
|
return entry->get();
|
2021-02-15 18:12:17 +03:00
|
|
|
});
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
bool gfxFcPlatformFontList::PrefFontListsUseOnlyGenerics() {
|
2017-04-12 13:32:19 +03:00
|
|
|
static const char kFontNamePrefix[] = "font.name.";
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
bool prefFontsUseOnlyGenerics = true;
|
2019-06-07 04:01:12 +03:00
|
|
|
nsTArray<nsCString> names;
|
|
|
|
nsresult rv =
|
|
|
|
Preferences::GetRootBranch()->GetChildList(kFontNamePrefix, names);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
for (auto& name : names) {
|
2015-11-16 02:48:40 +03:00
|
|
|
// Check whether all font.name prefs map to generic keywords
|
2015-11-16 02:48:36 +03:00
|
|
|
// and that the pref name and keyword match.
|
2015-11-16 02:48:40 +03:00
|
|
|
// Ex: font.name.serif.ar ==> "serif" (ok)
|
|
|
|
// Ex: font.name.serif.ar ==> "monospace" (return false)
|
|
|
|
// Ex: font.name.serif.ar ==> "DejaVu Serif" (return false)
|
2017-03-29 17:21:47 +03:00
|
|
|
// Ex: font.name.serif.ar ==> "" and
|
|
|
|
// font.name-list.serif.ar ==> "serif" (ok)
|
|
|
|
// Ex: font.name.serif.ar ==> "" and
|
|
|
|
// font.name-list.serif.ar ==> "Something, serif"
|
2015-11-16 02:48:40 +03:00
|
|
|
// (return false)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-06-07 04:01:12 +03:00
|
|
|
nsDependentCSubstring prefName =
|
|
|
|
Substring(name, ArrayLength(kFontNamePrefix) - 1);
|
2015-11-16 02:48:40 +03:00
|
|
|
nsCCharSeparatedTokenizer tokenizer(prefName, '.');
|
|
|
|
const nsDependentCSubstring& generic = tokenizer.nextToken();
|
|
|
|
const nsDependentCSubstring& langGroup = tokenizer.nextToken();
|
2017-07-31 07:28:48 +03:00
|
|
|
nsAutoCString fontPrefValue;
|
2019-06-07 04:01:12 +03:00
|
|
|
Preferences::GetCString(name.get(), fontPrefValue);
|
2017-03-29 17:21:47 +03:00
|
|
|
if (fontPrefValue.IsEmpty()) {
|
|
|
|
// The font name list may have two or more family names as comma
|
|
|
|
// separated list. In such case, not matching with generic font
|
|
|
|
// name is fine because if the list prefers specific font, this
|
|
|
|
// should return false.
|
2017-07-31 07:28:48 +03:00
|
|
|
Preferences::GetCString(NameListPref(generic, langGroup).get(),
|
|
|
|
fontPrefValue);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
if (!langGroup.EqualsLiteral("x-math") &&
|
|
|
|
!generic.Equals(fontPrefValue)) {
|
|
|
|
prefFontsUseOnlyGenerics = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-11-16 02:48:40 +03:00
|
|
|
return prefFontsUseOnlyGenerics;
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2019-02-26 01:07:19 +03:00
|
|
|
/* static */
|
|
|
|
void gfxFcPlatformFontList::CheckFontUpdates(nsITimer* aTimer, void* aThis) {
|
2017-11-02 23:29:33 +03:00
|
|
|
// A content process is not supposed to check this directly;
|
|
|
|
// it will be notified by the parent when the font list changes.
|
|
|
|
MOZ_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
// check for font updates
|
|
|
|
FcInitBringUptoDate();
|
|
|
|
|
|
|
|
// update fontlist if current config changed
|
|
|
|
gfxFcPlatformFontList* pfl = static_cast<gfxFcPlatformFontList*>(aThis);
|
|
|
|
FcConfig* current = FcConfigGetCurrent();
|
|
|
|
if (current != pfl->GetLastConfig()) {
|
|
|
|
pfl->UpdateFontList();
|
|
|
|
pfl->ForceGlobalReflow();
|
2017-11-02 23:29:33 +03:00
|
|
|
|
2020-12-31 03:33:48 +03:00
|
|
|
mozilla::dom::ContentParent::NotifyUpdatedFonts(true);
|
2015-05-13 08:11:26 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontFamily* gfxFcPlatformFontList::CreateFontFamily(
|
2020-04-02 15:36:24 +03:00
|
|
|
const nsACString& aName, FontVisibility aVisibility) const {
|
|
|
|
return new gfxFontconfigFontFamily(aName, aVisibility);
|
2017-08-01 13:25:35 +03:00
|
|
|
}
|
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
// mapping of moz lang groups ==> default lang
|
|
|
|
struct MozLangGroupData {
|
|
|
|
nsAtom* const& mozLangGroup;
|
|
|
|
const char* defaultLang;
|
|
|
|
};
|
|
|
|
|
|
|
|
const MozLangGroupData MozLangGroups[] = {
|
|
|
|
{nsGkAtoms::x_western, "en"}, {nsGkAtoms::x_cyrillic, "ru"},
|
|
|
|
{nsGkAtoms::x_devanagari, "hi"}, {nsGkAtoms::x_tamil, "ta"},
|
|
|
|
{nsGkAtoms::x_armn, "hy"}, {nsGkAtoms::x_beng, "bn"},
|
|
|
|
{nsGkAtoms::x_cans, "iu"}, {nsGkAtoms::x_ethi, "am"},
|
|
|
|
{nsGkAtoms::x_geor, "ka"}, {nsGkAtoms::x_gujr, "gu"},
|
|
|
|
{nsGkAtoms::x_guru, "pa"}, {nsGkAtoms::x_khmr, "km"},
|
|
|
|
{nsGkAtoms::x_knda, "kn"}, {nsGkAtoms::x_mlym, "ml"},
|
|
|
|
{nsGkAtoms::x_orya, "or"}, {nsGkAtoms::x_sinh, "si"},
|
|
|
|
{nsGkAtoms::x_tamil, "ta"}, {nsGkAtoms::x_telu, "te"},
|
|
|
|
{nsGkAtoms::x_tibt, "bo"}, {nsGkAtoms::Unicode, 0}};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
bool gfxFcPlatformFontList::TryLangForGroup(const nsACString& aOSLang,
|
|
|
|
nsAtom* aLangGroup,
|
|
|
|
nsACString& aFcLang,
|
|
|
|
bool aForFontEnumerationThread) {
|
|
|
|
// Truncate at '.' or '@' from aOSLang, and convert '_' to '-'.
|
|
|
|
// aOSLang is in the form "language[_territory][.codeset][@modifier]".
|
|
|
|
// fontconfig takes languages in the form "language-territory".
|
|
|
|
// nsLanguageAtomService takes languages in the form language-subtag,
|
|
|
|
// where subtag may be a territory. fontconfig and nsLanguageAtomService
|
|
|
|
// handle case-conversion for us.
|
|
|
|
const char *pos, *end;
|
|
|
|
aOSLang.BeginReading(pos);
|
|
|
|
aOSLang.EndReading(end);
|
|
|
|
aFcLang.Truncate();
|
|
|
|
while (pos < end) {
|
|
|
|
switch (*pos) {
|
|
|
|
case '.':
|
|
|
|
case '@':
|
|
|
|
end = pos;
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2018-05-25 23:18:54 +03:00
|
|
|
case '_':
|
|
|
|
aFcLang.Append('-');
|
2018-11-30 13:46:48 +03:00
|
|
|
break;
|
2018-05-25 23:18:54 +03:00
|
|
|
default:
|
|
|
|
aFcLang.Append(*pos);
|
|
|
|
}
|
|
|
|
++pos;
|
|
|
|
}
|
|
|
|
|
2018-05-28 12:09:28 +03:00
|
|
|
if (!aForFontEnumerationThread) {
|
2018-05-25 23:18:54 +03:00
|
|
|
nsAtom* atom = mLangService->LookupLanguage(aFcLang);
|
|
|
|
return atom == aLangGroup;
|
|
|
|
}
|
|
|
|
|
2018-05-28 12:09:28 +03:00
|
|
|
// If we were called by the font enumeration thread, we can't use
|
|
|
|
// mLangService->LookupLanguage because it is not thread-safe.
|
|
|
|
// Use GetUncachedLanguageGroup to avoid unsafe access to the lang-group
|
|
|
|
// mapping cache hashtable.
|
|
|
|
nsAutoCString lowered(aFcLang);
|
|
|
|
ToLowerCase(lowered);
|
|
|
|
RefPtr<nsAtom> lang = NS_Atomize(lowered);
|
|
|
|
RefPtr<nsAtom> group = mLangService->GetUncachedLanguageGroup(lang);
|
|
|
|
return group.get() == aLangGroup;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
void gfxFcPlatformFontList::GetSampleLangForGroup(
|
2018-05-28 12:09:28 +03:00
|
|
|
nsAtom* aLanguage, nsACString& aLangStr, bool aForFontEnumerationThread) {
|
2018-05-25 23:18:54 +03:00
|
|
|
aLangStr.Truncate();
|
|
|
|
if (!aLanguage) {
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
2018-05-28 12:09:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// set up lang string
|
|
|
|
const MozLangGroupData* mozLangGroup = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-28 12:09:28 +03:00
|
|
|
// -- look it up in the list of moz lang groups
|
|
|
|
for (unsigned int i = 0; i < ArrayLength(MozLangGroups); ++i) {
|
|
|
|
if (aLanguage == MozLangGroups[i].mozLangGroup) {
|
2018-05-25 23:18:54 +03:00
|
|
|
mozLangGroup = &MozLangGroups[i];
|
2018-05-28 12:09:28 +03:00
|
|
|
break;
|
2018-05-25 23:18:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-25 23:18:54 +03:00
|
|
|
|
|
|
|
// -- not a mozilla lang group? Just return the BCP47 string
|
|
|
|
// representation of the lang group
|
|
|
|
if (!mozLangGroup) {
|
|
|
|
// Not a special mozilla language group.
|
|
|
|
// Use aLanguage as a language code.
|
|
|
|
aLanguage->ToUTF8String(aLangStr);
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
2018-05-25 23:18:54 +03:00
|
|
|
|
|
|
|
// -- check the environment for the user's preferred language that
|
|
|
|
// corresponds to this mozilla lang group.
|
|
|
|
const char* languages = getenv("LANGUAGE");
|
|
|
|
if (languages) {
|
|
|
|
const char separator = ':';
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
for (const char* pos = languages; true; ++pos) {
|
|
|
|
if (*pos == '\0' || *pos == separator) {
|
2018-05-28 12:09:25 +03:00
|
|
|
if (languages < pos &&
|
2018-05-25 23:18:54 +03:00
|
|
|
TryLangForGroup(Substring(languages, pos), aLanguage, aLangStr,
|
|
|
|
aForFontEnumerationThread)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-28 12:09:25 +03:00
|
|
|
if (*pos == '\0') {
|
|
|
|
break;
|
2018-05-25 23:18:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
languages = pos + 1;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-28 12:09:25 +03:00
|
|
|
const char* ctype = setlocale(LC_CTYPE, nullptr);
|
2018-05-28 12:09:28 +03:00
|
|
|
if (ctype && TryLangForGroup(nsDependentCString(ctype), aLanguage, aLangStr,
|
|
|
|
aForFontEnumerationThread)) {
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
if (mozLangGroup->defaultLang) {
|
|
|
|
aLangStr.Assign(mozLangGroup->defaultLang);
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2018-05-25 23:18:54 +03:00
|
|
|
aLangStr.Truncate();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-05-25 23:18:54 +03:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
void gfxFcPlatformFontList::ActivateBundledFonts() {
|
|
|
|
if (!mBundledFontsInitialized) {
|
|
|
|
mBundledFontsInitialized = true;
|
|
|
|
nsCOMPtr<nsIFile> localDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(localDir));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(localDir->Append(u"fonts"_ns))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool isDir;
|
|
|
|
if (NS_FAILED(localDir->IsDirectory(&isDir)) || !isDir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(localDir->GetNativePath(mBundledFontsPath))) {
|
2018-11-30 13:46:48 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
if (!mBundledFontsPath.IsEmpty()) {
|
|
|
|
FcConfigAppFontAddDir(nullptr, ToFcChar8Ptr(mBundledFontsPath.get()));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef MOZ_WIDGET_GTK
|
|
|
|
/***************************************************************************
|
|
|
|
*
|
2021-05-01 23:00:31 +03:00
|
|
|
* These functions must be last in the file because it uses the system cairo
|
2021-07-30 02:38:30 +03:00
|
|
|
* library. Above this point the cairo library used is the tree cairo.
|
2015-05-13 08:11:25 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Tree cairo symbols have different names. Disable their activation through
|
|
|
|
// preprocessor macros.
|
2021-07-30 02:38:30 +03:00
|
|
|
# undef cairo_ft_font_options_substitute
|
|
|
|
|
|
|
|
# undef cairo_font_options_create
|
|
|
|
# undef cairo_font_options_destroy
|
|
|
|
# undef cairo_font_options_copy
|
|
|
|
# undef cairo_font_options_equal
|
|
|
|
|
|
|
|
# undef cairo_font_options_get_antialias
|
|
|
|
# undef cairo_font_options_set_antialias
|
|
|
|
# undef cairo_font_options_get_hint_style
|
|
|
|
# undef cairo_font_options_set_hint_style
|
|
|
|
# undef cairo_font_options_get_lcd_filter
|
|
|
|
# undef cairo_font_options_set_lcd_filter
|
|
|
|
# undef cairo_font_options_get_subpixel_order
|
|
|
|
# undef cairo_font_options_set_subpixel_order
|
2021-05-01 23:00:31 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// The system cairo functions are not declared because the include paths cause
|
|
|
|
// the gdk headers to pick up the tree cairo.h.
|
|
|
|
extern "C" {
|
|
|
|
NS_VISIBILITY_DEFAULT void cairo_ft_font_options_substitute(
|
|
|
|
const cairo_font_options_t* options, FcPattern* pattern);
|
2021-05-01 23:00:31 +03:00
|
|
|
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_font_options_t* cairo_font_options_copy(
|
|
|
|
const cairo_font_options_t*);
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_font_options_t* cairo_font_options_create();
|
|
|
|
NS_VISIBILITY_DEFAULT void cairo_font_options_destroy(cairo_font_options_t*);
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_bool_t cairo_font_options_equal(
|
|
|
|
const cairo_font_options_t*, const cairo_font_options_t*);
|
|
|
|
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_antialias_t
|
|
|
|
cairo_font_options_get_antialias(const cairo_font_options_t*);
|
|
|
|
NS_VISIBILITY_DEFAULT void cairo_font_options_set_antialias(
|
|
|
|
cairo_font_options_t*, cairo_antialias_t);
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_hint_style_t
|
|
|
|
cairo_font_options_get_hint_style(const cairo_font_options_t*);
|
|
|
|
NS_VISIBILITY_DEFAULT void cairo_font_options_set_hint_style(
|
|
|
|
cairo_font_options_t*, cairo_hint_style_t);
|
|
|
|
NS_VISIBILITY_DEFAULT cairo_subpixel_order_t
|
|
|
|
cairo_font_options_get_subpixel_order(const cairo_font_options_t*);
|
|
|
|
NS_VISIBILITY_DEFAULT void cairo_font_options_set_subpixel_order(
|
|
|
|
cairo_font_options_t*, cairo_subpixel_order_t);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
void gfxFcPlatformFontList::ClearSystemFontOptions() {
|
|
|
|
if (mSystemFontOptions) {
|
|
|
|
cairo_font_options_destroy(mSystemFontOptions);
|
|
|
|
mSystemFontOptions = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool gfxFcPlatformFontList::UpdateSystemFontOptions() {
|
|
|
|
MOZ_RELEASE_ASSERT(XRE_IsParentProcess());
|
|
|
|
|
|
|
|
if (gfxPlatform::IsHeadless()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
# ifdef MOZ_X11
|
|
|
|
{
|
|
|
|
// This one shouldn't change during the X session.
|
|
|
|
int lcdfilter;
|
|
|
|
GdkDisplay* dpy = gdk_display_get_default();
|
|
|
|
if (mozilla::widget::GdkIsX11Display(dpy) &&
|
|
|
|
GetXftInt(GDK_DISPLAY_XDISPLAY(dpy), "lcdfilter", &lcdfilter)) {
|
|
|
|
mFreetypeLcdSetting = lcdfilter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# endif // MOZ_X11
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
const cairo_font_options_t* options =
|
|
|
|
gdk_screen_get_font_options(gdk_screen_get_default());
|
2021-05-01 23:00:31 +03:00
|
|
|
if (!options) {
|
|
|
|
bool changed = !!mSystemFontOptions;
|
|
|
|
ClearSystemFontOptions();
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
|
|
|
cairo_font_options_t* newOptions = cairo_font_options_copy(options);
|
|
|
|
|
|
|
|
if (mSystemFontOptions &&
|
|
|
|
cairo_font_options_equal(mSystemFontOptions, options)) {
|
|
|
|
cairo_font_options_destroy(newOptions);
|
|
|
|
return false;
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2021-05-01 23:00:31 +03:00
|
|
|
ClearSystemFontOptions();
|
|
|
|
mSystemFontOptions = newOptions;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFcPlatformFontList::SystemFontOptionsToIpc(
|
|
|
|
dom::SystemFontOptions& aOptions) {
|
|
|
|
aOptions.antialias() =
|
|
|
|
mSystemFontOptions ? cairo_font_options_get_antialias(mSystemFontOptions)
|
|
|
|
: CAIRO_ANTIALIAS_DEFAULT;
|
|
|
|
aOptions.subpixelOrder() =
|
|
|
|
mSystemFontOptions
|
|
|
|
? cairo_font_options_get_subpixel_order(mSystemFontOptions)
|
|
|
|
: CAIRO_SUBPIXEL_ORDER_DEFAULT;
|
|
|
|
aOptions.hintStyle() =
|
|
|
|
mSystemFontOptions ? cairo_font_options_get_hint_style(mSystemFontOptions)
|
|
|
|
: CAIRO_HINT_STYLE_DEFAULT;
|
|
|
|
aOptions.lcdFilter() = mFreetypeLcdSetting;
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFcPlatformFontList::UpdateSystemFontOptionsFromIpc(
|
|
|
|
const dom::SystemFontOptions& aOptions) {
|
|
|
|
ClearSystemFontOptions();
|
|
|
|
mSystemFontOptions = cairo_font_options_create();
|
|
|
|
cairo_font_options_set_antialias(mSystemFontOptions,
|
|
|
|
cairo_antialias_t(aOptions.antialias()));
|
|
|
|
cairo_font_options_set_hint_style(mSystemFontOptions,
|
|
|
|
cairo_hint_style_t(aOptions.hintStyle()));
|
|
|
|
cairo_font_options_set_subpixel_order(
|
|
|
|
mSystemFontOptions, cairo_subpixel_order_t(aOptions.subpixelOrder()));
|
|
|
|
mFreetypeLcdSetting = aOptions.lcdFilter();
|
|
|
|
}
|
|
|
|
|
|
|
|
void gfxFcPlatformFontList::SubstituteSystemFontOptions(FcPattern* aPattern) {
|
|
|
|
if (mSystemFontOptions) {
|
|
|
|
cairo_ft_font_options_substitute(mSystemFontOptions, aPattern);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mFreetypeLcdSetting != -1) {
|
|
|
|
FcValue value;
|
|
|
|
if (FcPatternGet(aPattern, FC_LCD_FILTER, 0, &value) == FcResultNoMatch) {
|
|
|
|
FcPatternAddInteger(aPattern, FC_LCD_FILTER, mFreetypeLcdSetting);
|
|
|
|
}
|
|
|
|
}
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
|
2016-03-16 07:54:15 +03:00
|
|
|
#endif // MOZ_WIDGET_GTK
|