2015-05-13 08:11:25 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* 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/. */
|
|
|
|
|
|
|
|
#ifndef GFXFCPLATFORMFONTLIST_H_
|
|
|
|
#define GFXFCPLATFORMFONTLIST_H_
|
|
|
|
|
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxFontEntry.h"
|
|
|
|
#include "gfxFT2FontBase.h"
|
|
|
|
#include "gfxPlatformFontList.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
#include "mozilla/mozalloc.h"
|
2017-08-07 23:20:37 +03:00
|
|
|
#include "nsAutoRef.h"
|
2016-04-15 22:45:37 +03:00
|
|
|
#include "nsClassHashtable.h"
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
#include <fontconfig/fontconfig.h>
|
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include FT_TRUETYPE_TABLES_H
|
2018-01-29 16:24:11 +03:00
|
|
|
#include FT_MULTIPLE_MASTERS_H
|
2015-05-13 08:11:25 +03:00
|
|
|
#include <cairo.h>
|
|
|
|
#include <cairo-ft.h>
|
|
|
|
|
2018-06-09 15:44:00 +03:00
|
|
|
#if defined(MOZ_CONTENT_SANDBOX) && defined (XP_LINUX)
|
2017-11-09 19:54:30 +03:00
|
|
|
#include "mozilla/SandboxBroker.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class SystemFontListEntry;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
template <>
|
2017-08-07 23:20:37 +03:00
|
|
|
class nsAutoRefTraits<FcPattern> : public nsPointerRefTraits<FcPattern>
|
2015-05-13 08:11:25 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-08-07 23:20:37 +03:00
|
|
|
static void Release(FcPattern *ptr) { FcPatternDestroy(ptr); }
|
|
|
|
static void AddRef(FcPattern *ptr) { FcPatternReference(ptr); }
|
2015-05-13 08:11:25 +03:00
|
|
|
};
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
template <>
|
|
|
|
class nsAutoRefTraits<FcConfig> : public nsPointerRefTraits<FcConfig>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static void Release(FcConfig *ptr) { FcConfigDestroy(ptr); }
|
|
|
|
static void AddRef(FcConfig *ptr) { FcConfigReference(ptr); }
|
|
|
|
};
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// Helper classes used for clearning out user font data when cairo font
|
|
|
|
// face is destroyed. Since multiple faces may use the same data, be
|
|
|
|
// careful to assure that the data is only cleared out when all uses
|
|
|
|
// expire. The font entry object contains a refptr to FTUserFontData and
|
|
|
|
// each cairo font created from that font entry contains a
|
|
|
|
// FTUserFontDataRef with a refptr to that same FTUserFontData object.
|
|
|
|
|
|
|
|
class FTUserFontData {
|
|
|
|
public:
|
2017-05-18 04:56:24 +03:00
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(FTUserFontData)
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
explicit FTUserFontData(FT_Face aFace, const uint8_t* aData)
|
|
|
|
: mFace(aFace), mFontData(aData)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint8_t *FontData() const { return mFontData; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
~FTUserFontData()
|
|
|
|
{
|
2017-05-18 04:56:24 +03:00
|
|
|
mozilla::gfx::Factory::ReleaseFTFace(mFace);
|
2015-05-13 08:11:25 +03:00
|
|
|
if (mFontData) {
|
2017-10-12 05:08:44 +03:00
|
|
|
free((void*)mFontData);
|
2015-05-13 08:11:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FT_Face mFace;
|
|
|
|
const uint8_t *mFontData;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The names for the font entry and font classes should really
|
|
|
|
// the common 'Fc' abbreviation but the gfxPangoFontGroup code already
|
|
|
|
// defines versions of these, so use the verbose name for now.
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
class gfxFontconfigFontEntry : public gfxFontEntry {
|
2015-05-13 08:11:25 +03:00
|
|
|
public:
|
|
|
|
// used for system fonts with explicit patterns
|
2015-05-13 08:11:26 +03:00
|
|
|
explicit gfxFontconfigFontEntry(const nsAString& aFaceName,
|
2016-06-15 16:35:05 +03:00
|
|
|
FcPattern* aFontPattern,
|
|
|
|
bool aIgnoreFcCharmap);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// used for data fonts where the fontentry takes ownership
|
|
|
|
// of the font data and the FT_Face
|
2015-05-13 08:11:26 +03:00
|
|
|
explicit gfxFontconfigFontEntry(const nsAString& aFaceName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight,
|
|
|
|
StretchRange aStretch,
|
|
|
|
SlantStyleRange aStyle,
|
2015-05-13 08:11:25 +03:00
|
|
|
const uint8_t *aData,
|
2017-12-10 17:01:32 +03:00
|
|
|
uint32_t aLength,
|
2015-05-13 08:11:25 +03:00
|
|
|
FT_Face aFace);
|
|
|
|
|
|
|
|
// used for @font-face local system fonts with explicit patterns
|
2015-05-13 08:11:26 +03:00
|
|
|
explicit gfxFontconfigFontEntry(const nsAString& 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);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
gfxFontEntry* Clone() const override;
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
FcPattern* GetPattern() { return mFontPattern; }
|
|
|
|
|
|
|
|
nsresult ReadCMAP(FontInfoData *aFontInfoData = nullptr) override;
|
|
|
|
bool TestCharacterMap(uint32_t aCh) override;
|
|
|
|
|
2017-12-07 16:22:49 +03:00
|
|
|
FT_Face GetFTFace();
|
|
|
|
|
2018-08-02 00:39:05 +03:00
|
|
|
FT_MM_Var* GetMMVar() override;
|
2018-01-29 16:24:11 +03:00
|
|
|
|
2018-01-18 22:27:41 +03:00
|
|
|
bool HasVariations() override;
|
|
|
|
void GetVariationAxes(nsTArray<gfxFontVariationAxis>& aAxes) override;
|
2018-01-29 16:24:11 +03:00
|
|
|
void GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances) override;
|
2018-01-18 22:27:41 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
hb_blob_t* GetFontTable(uint32_t aTableTag) override;
|
|
|
|
|
|
|
|
void ForgetHBFace() override;
|
|
|
|
void ReleaseGrFace(gr_face* aFace) override;
|
|
|
|
|
2017-03-29 20:47:46 +03:00
|
|
|
double GetAspect();
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
protected:
|
2015-05-13 08:11:26 +03:00
|
|
|
virtual ~gfxFontconfigFontEntry();
|
2015-05-13 08:11:25 +03:00
|
|
|
|
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 *CreateFontInstance(const gfxFontStyle *aFontStyle) override;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// helper method for creating cairo font from pattern
|
|
|
|
cairo_scaled_font_t*
|
|
|
|
CreateScaledFont(FcPattern* aRenderPattern,
|
2017-01-13 01:37:07 +03:00
|
|
|
gfxFloat aAdjustedSize,
|
2018-06-01 20:08:57 +03:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
FT_Face aFTFace);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// override to pull data from FTFace
|
|
|
|
virtual nsresult
|
|
|
|
CopyFontTable(uint32_t aTableTag,
|
2016-02-02 18:36:30 +03:00
|
|
|
nsTArray<uint8_t>& aBuffer) override;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// if HB or GR faces are gone, close down the FT_Face
|
|
|
|
void MaybeReleaseFTFace();
|
|
|
|
|
|
|
|
// pattern for a single face of a family
|
|
|
|
nsCountedRef<FcPattern> mFontPattern;
|
|
|
|
|
|
|
|
// user font data, when needed
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<FTUserFontData> mUserFontData;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
// FTFace - initialized when needed
|
|
|
|
FT_Face mFTFace;
|
|
|
|
bool mFTFaceInitialized;
|
2016-06-15 16:35:05 +03:00
|
|
|
|
|
|
|
// Whether TestCharacterMap should check the actual cmap rather than asking
|
|
|
|
// fontconfig about character coverage.
|
|
|
|
// We do this for app-bundled (rather than system) fonts, as they may
|
|
|
|
// include color glyphs that fontconfig would overlook, and for fonts
|
|
|
|
// loaded via @font-face.
|
|
|
|
bool mIgnoreFcCharmap;
|
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
// Whether the face supports variations. For system-installed fonts, we
|
|
|
|
// query fontconfig for this (so they will only work if fontconfig is
|
|
|
|
// recent enough to include support); for downloaded user-fonts we query
|
|
|
|
// the FreeType face.
|
|
|
|
bool mHasVariations;
|
|
|
|
bool mHasVariationsInitialized;
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
double mAspect;
|
|
|
|
|
|
|
|
// data font
|
|
|
|
const uint8_t* mFontData;
|
2017-12-10 17:01:32 +03:00
|
|
|
uint32_t mLength;
|
2017-04-07 00:41:02 +03:00
|
|
|
|
|
|
|
class UnscaledFontCache
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
already_AddRefed<mozilla::gfx::UnscaledFontFontconfig>
|
|
|
|
Lookup(const char* aFile, uint32_t aIndex);
|
|
|
|
|
|
|
|
void Add(const RefPtr<mozilla::gfx::UnscaledFontFontconfig>& aUnscaledFont) {
|
|
|
|
mUnscaledFonts[kNumEntries-1] = aUnscaledFont;
|
|
|
|
MoveToFront(kNumEntries-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void MoveToFront(size_t aIndex);
|
|
|
|
|
|
|
|
static const size_t kNumEntries = 3;
|
2017-10-18 21:22:09 +03:00
|
|
|
mozilla::ThreadSafeWeakPtr<mozilla::gfx::UnscaledFontFontconfig> mUnscaledFonts[kNumEntries];
|
2017-04-07 00:41:02 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
UnscaledFontCache mUnscaledFontCache;
|
2018-01-29 16:24:11 +03:00
|
|
|
|
|
|
|
// Because of FreeType bug 52955, we keep the FT_MM_Var struct when it is
|
|
|
|
// first loaded, rather than releasing it and re-fetching it as needed.
|
|
|
|
FT_MM_Var* mMMVar = nullptr;
|
|
|
|
bool mMMVarInitialized = false;
|
2015-05-13 08:11:25 +03:00
|
|
|
};
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
class gfxFontconfigFontFamily : public gfxFontFamily {
|
2015-05-13 08:11:25 +03:00
|
|
|
public:
|
2015-05-13 08:11:26 +03:00
|
|
|
explicit gfxFontconfigFontFamily(const nsAString& aName) :
|
2016-06-15 16:35:05 +03:00
|
|
|
gfxFontFamily(aName),
|
2017-03-29 20:47:46 +03:00
|
|
|
mContainsAppFonts(false),
|
2017-05-05 22:46:10 +03:00
|
|
|
mHasNonScalableFaces(false),
|
|
|
|
mForceScalable(false)
|
2016-06-15 16:35:05 +03:00
|
|
|
{ }
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
template<typename Func>
|
|
|
|
void AddFacesToFontList(Func aAddPatternFunc);
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
void FindStyleVariations(FontInfoData *aFontInfoData = nullptr) override;
|
|
|
|
|
|
|
|
// Families are constructed initially with just references to patterns.
|
|
|
|
// When necessary, these are enumerated within FindStyleVariations.
|
|
|
|
void AddFontPattern(FcPattern* aFontPattern);
|
|
|
|
|
2016-06-15 16:35:05 +03:00
|
|
|
void SetFamilyContainsAppFonts(bool aContainsAppFonts)
|
|
|
|
{
|
|
|
|
mContainsAppFonts = aContainsAppFonts;
|
|
|
|
}
|
|
|
|
|
2017-03-29 20:47:46 +03:00
|
|
|
void
|
|
|
|
FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
|
|
|
|
nsTArray<gfxFontEntry*>& aFontEntryList,
|
2017-08-07 19:27:33 +03:00
|
|
|
bool aIgnoreSizeTolerance) override;
|
2017-03-29 20:47:46 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
bool FilterForFontList(nsAtom* aLangGroup,
|
2018-02-06 09:46:57 +03:00
|
|
|
const nsACString& aGeneric) const final {
|
2017-09-11 21:24:01 +03:00
|
|
|
return SupportsLangGroup(aLangGroup);
|
|
|
|
}
|
2017-09-11 21:22:15 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
protected:
|
2017-04-08 01:49:44 +03:00
|
|
|
virtual ~gfxFontconfigFontFamily();
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-09-11 21:24:01 +03:00
|
|
|
// helper for FilterForFontList
|
2017-10-03 01:05:19 +03:00
|
|
|
bool SupportsLangGroup(nsAtom *aLangGroup) const;
|
2017-09-11 21:24:01 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
nsTArray<nsCountedRef<FcPattern> > mFontPatterns;
|
2016-06-15 16:35:05 +03:00
|
|
|
|
|
|
|
bool mContainsAppFonts;
|
2017-03-29 20:47:46 +03:00
|
|
|
bool mHasNonScalableFaces;
|
2017-05-05 22:46:10 +03:00
|
|
|
bool mForceScalable;
|
2015-05-13 08:11:25 +03:00
|
|
|
};
|
|
|
|
|
2017-08-07 23:20:37 +03:00
|
|
|
class gfxFontconfigFont : public gfxFT2FontBase {
|
2015-05-13 08:11:25 +03:00
|
|
|
public:
|
2017-04-07 00:41:02 +03:00
|
|
|
gfxFontconfigFont(const RefPtr<mozilla::gfx::UnscaledFontFontconfig> &aUnscaledFont,
|
|
|
|
cairo_scaled_font_t *aScaledFont,
|
2016-07-20 22:07:11 +03:00
|
|
|
FcPattern *aPattern,
|
2017-01-13 01:37:07 +03:00
|
|
|
gfxFloat aAdjustedSize,
|
2015-05-13 08:11:25 +03:00
|
|
|
gfxFontEntry *aFontEntry,
|
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
|
|
|
const gfxFontStyle *aFontStyle);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-08-07 23:20:37 +03:00
|
|
|
virtual FontType GetType() const override { return FONT_TYPE_FONTCONFIG; }
|
|
|
|
virtual FcPattern *GetPattern() const { return mPattern; }
|
|
|
|
|
2017-08-07 23:20:44 +03:00
|
|
|
virtual already_AddRefed<mozilla::gfx::ScaledFont>
|
|
|
|
GetScaledFont(DrawTarget *aTarget) override;
|
|
|
|
|
2017-08-07 23:20:37 +03:00
|
|
|
private:
|
2015-05-13 08:11:26 +03:00
|
|
|
virtual ~gfxFontconfigFont();
|
2017-08-07 23:20:37 +03:00
|
|
|
|
|
|
|
nsCountedRef<FcPattern> mPattern;
|
2015-05-13 08:11:25 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class gfxFcPlatformFontList : public gfxPlatformFontList {
|
|
|
|
public:
|
2015-05-13 08:11:26 +03:00
|
|
|
gfxFcPlatformFontList();
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-11-17 05:39:58 +03:00
|
|
|
static gfxFcPlatformFontList* PlatformFontList() {
|
|
|
|
return static_cast<gfxFcPlatformFontList*>(sPlatformFontList);
|
|
|
|
}
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
// initialize font lists
|
2016-08-23 03:06:07 +03:00
|
|
|
virtual nsresult InitFontListForPlatform() override;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2017-10-03 01:05:19 +03:00
|
|
|
void GetFontList(nsAtom *aLangGroup,
|
2015-05-13 08:11:25 +03:00
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts) override;
|
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
void ReadSystemFontList(
|
|
|
|
InfallibleTArray<mozilla::dom::SystemFontListEntry>* retValue);
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
gfxFontEntry*
|
2018-04-13 22:34:37 +03:00
|
|
|
LookupLocalFont(const nsAString& aFontName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry,
|
|
|
|
SlantStyleRange aStyleForEntry) override;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
gfxFontEntry*
|
2018-04-13 22:34:37 +03:00
|
|
|
MakePlatformFont(const nsAString& aFontName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry,
|
|
|
|
SlantStyleRange aStyleForEntry,
|
2015-05-13 08:11:25 +03:00
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength) override;
|
|
|
|
|
2016-04-12 09:06:22 +03:00
|
|
|
bool FindAndAddFamilies(const nsAString& aFamily,
|
2018-05-25 16:07:57 +03:00
|
|
|
nsTArray<FamilyAndGeneric>* aOutput,
|
2017-08-01 13:25:35 +03:00
|
|
|
FindFamiliesFlags aFlags,
|
2016-04-12 09:06:22 +03:00
|
|
|
gfxFontStyle* aStyle = nullptr,
|
|
|
|
gfxFloat aDevToCssSize = 1.0) override;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
|
|
|
bool GetStandardFamilyName(const nsAString& aFontName,
|
|
|
|
nsAString& aFamilyName) override;
|
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
FcConfig* GetLastConfig() const { return mLastConfig; }
|
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
// override to use fontconfig lookup for generics
|
|
|
|
void AddGenericFonts(mozilla::FontFamilyType aGenericType,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aLanguage,
|
2018-05-25 16:07:57 +03:00
|
|
|
nsTArray<FamilyAndGeneric>& aFamilyList) override;
|
2015-11-16 02:48:40 +03:00
|
|
|
|
|
|
|
void ClearLangGroupPrefFonts() override;
|
|
|
|
|
2015-11-20 07:35:15 +03:00
|
|
|
// clear out cached generic-lang ==> family-list mappings
|
|
|
|
void ClearGenericMappings() {
|
|
|
|
mGenericMappings.Clear();
|
|
|
|
}
|
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
// map lang group ==> lang string
|
2018-05-28 12:09:28 +03:00
|
|
|
// When aForFontEnumerationThread is true, this method will avoid using
|
|
|
|
// LanguageService::LookupLanguage, because it is not safe for off-main-
|
|
|
|
// thread use (except by stylo traversal, which does the necessary locking)
|
|
|
|
void GetSampleLangForGroup(nsAtom* aLanguage, nsACString& aLangStr,
|
|
|
|
bool aForFontEnumerationThread = false);
|
2018-05-25 23:18:54 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
static FT_Library GetFTLibrary();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~gfxFcPlatformFontList();
|
|
|
|
|
2017-11-09 19:54:30 +03:00
|
|
|
#ifdef MOZ_CONTENT_SANDBOX
|
|
|
|
typedef mozilla::SandboxBroker::Policy SandboxPolicy;
|
|
|
|
#else
|
|
|
|
// Dummy type just so we can still have a SandboxPolicy* parameter.
|
|
|
|
struct SandboxPolicy {};
|
|
|
|
#endif
|
|
|
|
|
2016-06-15 16:35:05 +03:00
|
|
|
// Add all the font families found in a font set.
|
|
|
|
// aAppFonts indicates whether this is the system or application fontset.
|
2017-11-09 19:54:30 +03:00
|
|
|
void AddFontSetFamilies(FcFontSet* aFontSet, const SandboxPolicy* aPolicy,
|
|
|
|
bool aAppFonts);
|
2017-11-02 23:29:33 +03:00
|
|
|
|
2017-11-02 23:29:33 +03:00
|
|
|
// Helper for above, to add a single font pattern.
|
|
|
|
void AddPatternToFontList(FcPattern* aFont, FcChar8*& aLastFamilyName,
|
|
|
|
nsAString& aFamilyName,
|
|
|
|
RefPtr<gfxFontconfigFontFamily>& aFontFamily,
|
|
|
|
bool aAppFonts);
|
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
// figure out which families fontconfig maps a generic to
|
2015-05-13 08:11:25 +03:00
|
|
|
// (aGeneric assumed already lowercase)
|
2015-11-16 02:48:40 +03:00
|
|
|
PrefFontList* FindGenericFamilies(const nsAString& aGeneric,
|
2017-10-03 01:05:19 +03:00
|
|
|
nsAtom* aLanguage);
|
2015-11-16 02:48:40 +03:00
|
|
|
|
|
|
|
// are all pref font settings set to use fontconfig generics?
|
|
|
|
bool PrefFontListsUseOnlyGenerics();
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
static void CheckFontUpdates(nsITimer *aTimer, void *aThis);
|
|
|
|
|
2016-08-23 03:06:07 +03:00
|
|
|
virtual gfxFontFamily*
|
|
|
|
GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
|
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
gfxFontFamily* CreateFontFamily(const nsAString& aName) const override;
|
|
|
|
|
2018-05-25 23:18:54 +03:00
|
|
|
// helper method for finding an appropriate lang string
|
|
|
|
bool TryLangForGroup(const nsACString& aOSLang, nsAtom* aLangGroup,
|
2018-05-28 12:09:28 +03:00
|
|
|
nsACString& aLang, bool aForFontEnumerationThread);
|
2018-05-25 23:18:54 +03:00
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
void ActivateBundledFonts();
|
|
|
|
nsCString mBundledFontsPath;
|
|
|
|
bool mBundledFontsInitialized;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// to avoid enumerating all fonts, maintain a mapping of local font
|
|
|
|
// names to family
|
2015-05-27 10:19:19 +03:00
|
|
|
nsBaseHashtable<nsStringHashKey,
|
|
|
|
nsCountedRef<FcPattern>,
|
|
|
|
FcPattern*> mLocalNames;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
// caching generic/lang ==> font family list
|
2016-04-15 22:45:37 +03:00
|
|
|
nsClassHashtable<nsCStringHashKey,
|
|
|
|
PrefFontList> mGenericMappings;
|
2015-05-13 08:11:25 +03:00
|
|
|
|
2016-04-09 13:09:08 +03:00
|
|
|
// Caching family lookups as found by FindAndAddFamilies after resolving
|
|
|
|
// substitutions. The gfxFontFamily objects cached here are owned by the
|
|
|
|
// gfxFcPlatformFontList via its mFamilies table; note that if the main
|
|
|
|
// font list is rebuilt (e.g. due to a fontconfig configuration change),
|
|
|
|
// these pointers will be invalidated. InitFontList() flushes the cache
|
|
|
|
// in this case.
|
|
|
|
nsDataHashtable<nsCStringHashKey,
|
2018-05-25 16:07:57 +03:00
|
|
|
nsTArray<FamilyAndGeneric>> mFcSubstituteCache;
|
2015-06-10 09:23:45 +03:00
|
|
|
|
2015-05-13 08:11:26 +03:00
|
|
|
nsCOMPtr<nsITimer> mCheckFontUpdatesTimer;
|
|
|
|
nsCountedRef<FcConfig> mLastConfig;
|
|
|
|
|
2015-11-16 02:48:40 +03:00
|
|
|
// By default, font prefs under Linux are set to simply lookup
|
|
|
|
// via fontconfig the appropriate font for serif/sans-serif/monospace.
|
|
|
|
// Rather than check each time a font pref is used, check them all at startup
|
|
|
|
// and set a boolean to flag the case that non-default user font prefs exist
|
|
|
|
// Note: langGroup == x-math is handled separately
|
|
|
|
bool mAlwaysUseFontconfigGenerics;
|
|
|
|
|
2015-05-13 08:11:25 +03:00
|
|
|
static FT_Library sCairoFTLibrary;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GFXPLATFORMFONTLIST_H_ */
|