2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2014-09-16 13:58:12 +04: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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_FONTENTRY_H
|
|
|
|
#define GFX_FONTENTRY_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "nsString.h"
|
2015-10-19 05:16:43 +03:00
|
|
|
#include "gfxFontConstants.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxFontFeatures.h"
|
|
|
|
#include "gfxFontUtils.h"
|
2018-01-26 18:47:19 +03:00
|
|
|
#include "gfxFontVariations.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "mozilla/HashFunctions.h"
|
|
|
|
#include "mozilla/MemoryReporting.h"
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "nsUnicodeScriptCodes.h"
|
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "harfbuzz/hb.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2015-10-20 19:12:41 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2017-04-07 00:41:02 +03:00
|
|
|
#include "mozilla/WeakPtr.h"
|
2019-12-19 19:05:35 +03:00
|
|
|
#include "ThebesRLBoxTypes.h"
|
2018-05-15 16:59:25 +03:00
|
|
|
#include <math.h>
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
typedef struct gr_face gr_face;
|
2018-08-02 00:39:05 +03:00
|
|
|
typedef struct FT_MM_Var_ FT_MM_Var;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
# include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct gfxFontStyle;
|
|
|
|
class gfxContext;
|
|
|
|
class gfxFont;
|
|
|
|
class gfxFontFamily;
|
|
|
|
class gfxUserFontData;
|
|
|
|
class gfxSVGGlyphs;
|
|
|
|
class FontInfoData;
|
|
|
|
struct FontListSizes;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-07-22 16:56:09 +03:00
|
|
|
namespace mozilla {
|
|
|
|
class SVGContextPaint;
|
2019-04-01 17:33:34 +03:00
|
|
|
namespace fontlist {
|
|
|
|
struct Family;
|
|
|
|
struct Face;
|
|
|
|
} // namespace fontlist
|
|
|
|
} // namespace mozilla
|
2016-07-22 16:56:09 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
#define NO_FONT_LANGUAGE_OVERRIDE 0
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class gfxCharacterMap : public gfxSparseBitSet {
|
|
|
|
public:
|
|
|
|
nsrefcnt AddRef() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
|
2014-09-16 13:58:12 +04:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "gfxCharacterMap", sizeof(*this));
|
|
|
|
return mRefCnt;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
nsrefcnt Release() {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(0 != mRefCnt, "dup release");
|
2014-09-16 13:58:12 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "gfxCharacterMap");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
NotifyReleased();
|
|
|
|
// |this| has been deleted.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
gfxCharacterMap() : mHash(0), mBuildOnTheFly(false), mShared(false) {}
|
|
|
|
|
2014-12-11 01:48:11 +03:00
|
|
|
explicit gfxCharacterMap(const gfxSparseBitSet& aOther)
|
2014-11-06 07:42:50 +03:00
|
|
|
: gfxSparseBitSet(aOther),
|
|
|
|
mHash(0),
|
|
|
|
mBuildOnTheFly(false),
|
|
|
|
mShared(false) {}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void CalcHash() { mHash = GetChecksum(); }
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return gfxSparseBitSet::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// hash of the cmap bitvector
|
|
|
|
uint32_t mHash;
|
|
|
|
|
|
|
|
// if cmap is built on the fly it's never shared
|
|
|
|
bool mBuildOnTheFly;
|
|
|
|
|
|
|
|
// cmap is shared globally
|
|
|
|
bool mShared;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void NotifyReleased();
|
|
|
|
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfxCharacterMap(const gfxCharacterMap&);
|
|
|
|
gfxCharacterMap& operator=(const gfxCharacterMap&);
|
|
|
|
};
|
|
|
|
|
2018-01-30 12:57:39 +03:00
|
|
|
// Info on an individual font feature, for reporting available features
|
|
|
|
// to DevTools via the GetFeatureInfo method.
|
|
|
|
struct gfxFontFeatureInfo {
|
|
|
|
uint32_t mTag;
|
|
|
|
uint32_t mScript;
|
|
|
|
uint32_t mLangSys;
|
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class gfxFontEntry {
|
|
|
|
public:
|
2015-12-16 00:56:40 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2016-04-21 20:58:59 +03:00
|
|
|
typedef mozilla::unicode::Script Script;
|
2018-04-23 17:52:20 +03:00
|
|
|
typedef mozilla::FontWeight FontWeight;
|
|
|
|
typedef mozilla::FontSlantStyle FontSlantStyle;
|
|
|
|
typedef mozilla::FontStretch FontStretch;
|
2018-04-25 09:18:23 +03:00
|
|
|
typedef mozilla::WeightRange WeightRange;
|
2018-04-25 09:18:23 +03:00
|
|
|
typedef mozilla::SlantStyleRange SlantStyleRange;
|
|
|
|
typedef mozilla::StretchRange StretchRange;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-08 01:49:44 +03:00
|
|
|
// Used by stylo
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontEntry)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
explicit gfxFontEntry(const nsACString& aName, bool aIsStandardFace = false);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
// Create a new entry that refers to the same font as this, but without
|
|
|
|
// additional state that may have been set up (such as family name).
|
|
|
|
// (This is only to be used for system fonts in the platform font list,
|
|
|
|
// not user fonts.)
|
|
|
|
virtual gfxFontEntry* Clone() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// unique name for the face, *not* the family; not necessarily the
|
|
|
|
// "real" or user-friendly name, may be an internal identifier
|
2018-09-12 22:34:57 +03:00
|
|
|
const nsCString& Name() const { return mName; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// family name
|
2018-09-12 22:34:57 +03:00
|
|
|
const nsCString& FamilyName() const { return mFamilyName; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// The following two methods may be relatively expensive, as they
|
|
|
|
// will (usually, except on Linux) load and parse the 'name' table;
|
|
|
|
// they are intended only for the font-inspection API, not for
|
|
|
|
// perf-critical layout/drawing work.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// The "real" name of the face, if available from the font resource;
|
|
|
|
// returns Name() if nothing better is available.
|
2018-09-12 22:34:57 +03:00
|
|
|
virtual nsCString RealFaceName();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange Weight() const { return mWeightRange; }
|
2018-04-25 09:18:23 +03:00
|
|
|
StretchRange Stretch() const { return mStretchRange; }
|
|
|
|
SlantStyleRange SlantStyle() const { return mStyleRange; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool IsUserFont() const { return mIsDataUserFont || mIsLocalUserFont; }
|
|
|
|
bool IsLocalUserFont() const { return mIsLocalUserFont; }
|
|
|
|
bool IsFixedPitch() const { return mFixedPitch; }
|
2018-04-25 09:18:23 +03:00
|
|
|
bool IsItalic() const { return SlantStyle().Min().IsItalic(); }
|
|
|
|
bool IsOblique() const { return SlantStyle().Min().IsOblique(); }
|
|
|
|
bool IsUpright() const { return SlantStyle().Min().IsNormal(); }
|
2018-05-09 15:49:24 +03:00
|
|
|
inline bool SupportsItalic();
|
2018-05-04 12:19:55 +03:00
|
|
|
inline bool SupportsBold(); // defined below, because of RangeFlags use
|
2014-09-16 13:58:12 +04:00
|
|
|
bool IgnoreGDEF() const { return mIgnoreGDEF; }
|
|
|
|
bool IgnoreGSUB() const { return mIgnoreGSUB; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
// Return whether the face corresponds to "normal" CSS style properties:
|
|
|
|
// font-style: normal;
|
|
|
|
// font-weight: normal;
|
|
|
|
// font-stretch: normal;
|
2014-09-16 13:58:12 +04:00
|
|
|
// If this is false, we might want to fall back to a different face and
|
2017-10-28 15:21:38 +03:00
|
|
|
// possibly apply synthetic styling.
|
|
|
|
bool IsNormalStyle() const {
|
|
|
|
return IsUpright() && Weight().Min() <= FontWeight::Normal() &&
|
2018-04-25 09:18:23 +03:00
|
|
|
Weight().Max() >= FontWeight::Normal() &&
|
2018-04-25 09:18:23 +03:00
|
|
|
Stretch().Min() <= FontStretch::Normal() &&
|
|
|
|
Stretch().Max() >= FontStretch::Normal();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
// whether a feature is supported by the font (limited to a small set
|
|
|
|
// of features for which some form of fallback needs to be implemented)
|
|
|
|
virtual bool SupportsOpenTypeFeature(Script aScript, uint32_t aFeatureTag);
|
|
|
|
bool SupportsGraphiteFeature(uint32_t aFeatureTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
// returns a set containing all input glyph ids for a given feature
|
|
|
|
const hb_set_t* InputsForOpenTypeFeature(Script aScript,
|
2017-10-12 00:12:42 +03:00
|
|
|
uint32_t aFeatureTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
virtual bool HasFontTable(uint32_t aTableTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 09:18:23 +03:00
|
|
|
inline bool HasGraphiteTables() {
|
|
|
|
if (!mCheckedForGraphiteTables) {
|
|
|
|
CheckForGraphiteTables();
|
|
|
|
mCheckedForGraphiteTables = true;
|
2017-10-28 15:21:38 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return mHasGraphiteTables;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-10-28 15:21:38 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
inline bool HasCmapTable() {
|
2019-04-27 18:37:58 +03:00
|
|
|
if (!mCharacterMap && !mShmemCharacterMap) {
|
2014-09-16 13:58:12 +04:00
|
|
|
ReadCMAP();
|
2019-04-27 18:37:58 +03:00
|
|
|
NS_ASSERTION(mCharacterMap || mShmemCharacterMap,
|
|
|
|
"failed to initialize character map");
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
return mHasCmapTable;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
inline bool HasCharacter(uint32_t ch) {
|
2019-04-27 18:37:58 +03:00
|
|
|
if (mShmemCharacterMap) {
|
|
|
|
return mShmemCharacterMap->test(ch);
|
|
|
|
}
|
2019-04-29 17:39:05 +03:00
|
|
|
if (mCharacterMap) {
|
|
|
|
if (mShmemFace && TrySetShmemCharacterMap()) {
|
|
|
|
// Forget our temporary local copy, now we can use the shared cmap
|
|
|
|
mCharacterMap = nullptr;
|
|
|
|
return mShmemCharacterMap->test(ch);
|
|
|
|
}
|
|
|
|
if (mCharacterMap->test(ch)) {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
return TestCharacterMap(ch);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual bool SkipDuringSystemFallback() { return false; }
|
|
|
|
nsresult InitializeUVSMap();
|
|
|
|
uint16_t GetUVSGlyph(uint32_t aCh, uint32_t aVS);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// All concrete gfxFontEntry subclasses (except gfxUserFontEntry) need
|
|
|
|
// to override this, otherwise the font will never be used as it will
|
|
|
|
// be considered to support no characters.
|
|
|
|
// ReadCMAP() must *always* set the mCharacterMap pointer to a valid
|
|
|
|
// gfxCharacterMap, even if empty, as other code assumes this pointer
|
|
|
|
// can be safely dereferenced.
|
|
|
|
virtual nsresult ReadCMAP(FontInfoData* aFontInfoData = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool TryGetSVGData(gfxFont* aFont);
|
|
|
|
bool HasSVGGlyph(uint32_t aGlyphId);
|
2015-12-16 00:56:40 +03:00
|
|
|
bool GetSVGGlyphExtents(DrawTarget* aDrawTarget, uint32_t aGlyphId,
|
2017-11-23 22:40:33 +03:00
|
|
|
gfxFloat aSize, gfxRect* aResult);
|
2017-05-18 23:03:41 +03:00
|
|
|
void RenderSVGGlyph(gfxContext* aContext, uint32_t aGlyphId,
|
2016-07-22 16:56:09 +03:00
|
|
|
mozilla::SVGContextPaint* aContextPaint);
|
2014-09-16 13:58:12 +04:00
|
|
|
// Call this when glyph geometry or rendering has changed
|
|
|
|
// (e.g. animated SVG glyphs)
|
|
|
|
void NotifyGlyphsChanged();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool TryGetColorGlyphs();
|
|
|
|
bool GetColorLayersInfo(uint32_t aGlyphId,
|
2020-03-09 17:16:17 +03:00
|
|
|
const mozilla::gfx::DeviceColor& aDefaultColor,
|
2014-09-16 13:58:12 +04:00
|
|
|
nsTArray<uint16_t>& layerGlyphs,
|
2020-03-09 17:16:17 +03:00
|
|
|
nsTArray<mozilla::gfx::DeviceColor>& layerColors);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Access to raw font table data (needed for Harfbuzz):
|
|
|
|
// returns a pointer to data owned by the fontEntry or the OS,
|
|
|
|
// which will remain valid until the blob is destroyed.
|
|
|
|
// The data MUST be treated as read-only; we may be getting a
|
|
|
|
// reference to a shared system font cache.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// The default implementation uses CopyFontTable to get the data
|
|
|
|
// into a byte array, and maintains a cache of loaded tables.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Subclasses should override this if they can provide more efficient
|
|
|
|
// access than copying table data into our own buffers.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get blob that encapsulates a specific font table, or nullptr if
|
|
|
|
// the table doesn't exist in the font.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Caller is responsible to call hb_blob_destroy() on the returned blob
|
|
|
|
// (if non-nullptr) when no longer required. For transient access to a
|
|
|
|
// table, use of AutoTable (below) is generally preferred.
|
|
|
|
virtual hb_blob_t* GetFontTable(uint32_t aTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Stack-based utility to return a specified table, automatically releasing
|
|
|
|
// the blob when the AutoTable goes out of scope.
|
|
|
|
class AutoTable {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
AutoTable(gfxFontEntry* aFontEntry, uint32_t aTag) {
|
|
|
|
mBlob = aFontEntry->GetFontTable(aTag);
|
|
|
|
}
|
2019-02-18 20:16:22 +03:00
|
|
|
~AutoTable() { hb_blob_destroy(mBlob); }
|
2014-09-16 13:58:12 +04:00
|
|
|
operator hb_blob_t*() const { return mBlob; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
private:
|
|
|
|
hb_blob_t* mBlob;
|
|
|
|
// not implemented:
|
|
|
|
AutoTable(const AutoTable&) = delete;
|
|
|
|
AutoTable& operator=(const AutoTable&) = delete;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Return a font instance for a particular style. This may be a newly-
|
|
|
|
// created instance, or a font already in the global cache.
|
|
|
|
// We can't return a UniquePtr here, because we may be returning a shared
|
|
|
|
// cached instance; but we also don't return already_AddRefed, because
|
|
|
|
// the caller may only need to use the font temporarily and doesn't need
|
|
|
|
// a strong reference.
|
|
|
|
gfxFont* FindOrMakeFont(const gfxFontStyle* aStyle,
|
|
|
|
gfxCharacterMap* aUnicodeRangeMap = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get an existing font table cache entry in aBlob if it has been
|
|
|
|
// registered, or return false if not. Callers must call
|
|
|
|
// hb_blob_destroy on aBlob if true is returned.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Note that some gfxFont implementations may not call this at all,
|
2015-12-16 00:56:40 +03:00
|
|
|
// if it is more efficient to get the table from the OS at that level.
|
|
|
|
bool GetExistingFontTable(uint32_t aTag, hb_blob_t** aBlob);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Elements of aTable are transferred (not copied) to and returned in a
|
|
|
|
// new hb_blob_t which is registered on the gfxFontEntry, but the initial
|
|
|
|
// reference is owned by the caller. Removing the last reference
|
|
|
|
// unregisters the table from the font entry.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Pass nullptr for aBuffer to indicate that the table is not present and
|
|
|
|
// nullptr will be returned. Also returns nullptr on OOM.
|
|
|
|
hb_blob_t* ShareFontTableAndGetBlob(uint32_t aTag, nsTArray<uint8_t>* aTable);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the font's unitsPerEm from the 'head' table, in the case of an
|
|
|
|
// sfnt resource. Will return kInvalidUPEM for non-sfnt fonts,
|
|
|
|
// if present on the platform.
|
|
|
|
uint16_t UnitsPerEm();
|
2018-11-30 13:46:48 +03:00
|
|
|
enum {
|
2014-09-16 13:58:12 +04:00
|
|
|
kMinUPEM = 16, // Limits on valid unitsPerEm range, from the
|
|
|
|
kMaxUPEM = 16384, // OpenType spec
|
|
|
|
kInvalidUPEM = uint16_t(-1)
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Shaper face accessors:
|
|
|
|
// NOTE that harfbuzz and graphite handle ownership/lifetime of the face
|
|
|
|
// object in completely different ways.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get HarfBuzz face corresponding to this font file.
|
|
|
|
// Caller must release with hb_face_destroy() when finished with it,
|
|
|
|
// and the font entry will be notified via ForgetHBFace.
|
|
|
|
hb_face_t* GetHBFace();
|
2019-11-12 00:39:45 +03:00
|
|
|
void ForgetHBFace();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-12-19 19:05:35 +03:00
|
|
|
// Get the sandbox instance that graphite is running in.
|
|
|
|
rlbox_sandbox_gr* GetGrSandbox();
|
|
|
|
|
|
|
|
// Register and get the callback handle for the glyph advance firefox callback
|
|
|
|
// Since the sandbox instance is shared with multiple test shapers, callback
|
|
|
|
// registration must be handled centrally to ensure multiple instances don't
|
|
|
|
// register the same callback.
|
|
|
|
sandbox_callback_gr<float (*)(const void*, uint16_t)>*
|
|
|
|
GetGrSandboxAdvanceCallbackHandle();
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get Graphite face corresponding to this font file.
|
|
|
|
// Caller must call gfxFontEntry::ReleaseGrFace when finished with it.
|
2019-12-19 19:05:35 +03:00
|
|
|
// Graphite is run in a sandbox
|
|
|
|
tainted_opaque_gr<gr_face*> GetGrFace();
|
|
|
|
void ReleaseGrFace(tainted_opaque_gr<gr_face*> aFace);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Does the font have graphite contextuals that involve the space glyph
|
2015-08-03 11:04:59 +03:00
|
|
|
// (and therefore we should bypass the word cache)?
|
2019-12-19 19:05:47 +03:00
|
|
|
// Since this function inspects data from libGraphite stored in sandbox memory
|
|
|
|
// it can only return a "hint" to the correct return value. This is because
|
|
|
|
// a compromised libGraphite could change the sandbox memory maliciously at
|
|
|
|
// any moment. The caller must ensure the calling code performs safe actions
|
|
|
|
// independent of the value returned, to unwrap this return.
|
|
|
|
tainted_boolean_hint HasGraphiteSpaceContextuals();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Release any SVG-glyphs document this font may have loaded.
|
|
|
|
void DisconnectSVG();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Called to notify that aFont is being destroyed. Needed when we're tracking
|
|
|
|
// the fonts belonging to this font entry.
|
|
|
|
void NotifyFontDestroyed(gfxFont* aFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
// For memory reporting of the platform font list.
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2017-06-30 01:37:52 +03:00
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
// Used for reporting on individual font entries in the user font cache,
|
|
|
|
// which are not present in the platform font list.
|
|
|
|
size_t ComputedSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
// Used when checking for complex script support, to mask off cmap ranges
|
|
|
|
struct ScriptRange {
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t rangeStart;
|
|
|
|
uint32_t rangeEnd;
|
2018-12-08 16:44:55 +03:00
|
|
|
uint32_t numTags; // number of entries in the tags[] array
|
|
|
|
hb_tag_t tags[3]; // up to three OpenType script tags to check
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2018-12-08 16:44:55 +03:00
|
|
|
bool SupportsScriptInGSUB(const hb_tag_t* aScriptTags, uint32_t aNumTags);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Font-variation query methods.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Font backends that don't support variations should provide empty
|
|
|
|
* implementations.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2018-04-26 19:08:18 +03:00
|
|
|
virtual bool HasVariations() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual void GetVariationAxes(
|
|
|
|
nsTArray<gfxFontVariationAxis>& aVariationAxes) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual void GetVariationInstances(
|
|
|
|
nsTArray<gfxFontVariationInstance>& aInstances) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool HasBoldVariableWeight();
|
2018-05-09 15:49:24 +03:00
|
|
|
bool HasItalicVariation();
|
2014-09-16 13:58:12 +04:00
|
|
|
void CheckForVariationAxes();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Set up the entry's weight/stretch/style ranges according to axes found
|
|
|
|
// by GetVariationAxes (for installed fonts; do NOT call this for user
|
|
|
|
// fonts, where the ranges are provided by @font-face descriptors).
|
|
|
|
void SetupVariationRanges();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get variation axis settings that should be used to implement a particular
|
|
|
|
// font style using this resource.
|
|
|
|
void GetVariationsForStyle(nsTArray<gfxFontVariation>& aResult,
|
2018-04-25 09:18:23 +03:00
|
|
|
const gfxFontStyle& aStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the font's list of features (if any) for DevTools support.
|
2016-02-02 18:36:30 +03:00
|
|
|
void GetFeatureInfo(nsTArray<gfxFontFeatureInfo>& aFeatureInfo);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// This is only called on platforms where we use FreeType.
|
|
|
|
virtual FT_MM_Var* GetMMVar() { return nullptr; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-30 13:28:44 +03:00
|
|
|
// Return true if the font has a 'trak' table (and we can successfully
|
|
|
|
// interpret it), otherwise false. This will load and cache the table
|
|
|
|
// the first time it is called.
|
|
|
|
bool HasTrackingTable();
|
|
|
|
|
|
|
|
// Return the tracking (in font units) to be applied for the given size.
|
|
|
|
// (This is a floating-point number because of possible interpolation.)
|
|
|
|
float TrackingForCSSPx(float aSize) const;
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mName;
|
2014-09-16 13:58:12 +04:00
|
|
|
nsCString mFamilyName;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
RefPtr<gfxCharacterMap> mCharacterMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-27 18:37:58 +03:00
|
|
|
mozilla::fontlist::Face* mShmemFace = nullptr;
|
|
|
|
const SharedBitSet* mShmemCharacterMap = nullptr;
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
mozilla::UniquePtr<uint8_t[]> mUVSData;
|
|
|
|
mozilla::UniquePtr<gfxUserFontData> mUserFontData;
|
2015-08-03 11:04:59 +03:00
|
|
|
mozilla::UniquePtr<gfxSVGGlyphs> mSVGGlyphs;
|
2014-09-16 13:58:12 +04:00
|
|
|
// list of gfxFonts that are using SVG glyphs
|
2018-04-25 20:54:03 +03:00
|
|
|
nsTArray<gfxFont*> mFontsUsingSVGGlyphs;
|
2014-09-16 13:58:12 +04:00
|
|
|
nsTArray<gfxFontFeature> mFeatureSettings;
|
2018-04-25 20:54:03 +03:00
|
|
|
nsTArray<gfxFontVariation> mVariationSettings;
|
2014-09-16 13:58:12 +04:00
|
|
|
mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, bool>> mSupportedFeatures;
|
|
|
|
mozilla::UniquePtr<nsDataHashtable<nsUint32HashKey, hb_set_t*>>
|
|
|
|
mFeatureInputs;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Color Layer font support
|
2018-04-25 20:54:03 +03:00
|
|
|
hb_blob_t* mCOLR = nullptr;
|
|
|
|
hb_blob_t* mCPAL = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// bitvector of substitution space features per script, one each
|
|
|
|
// for default and non-default features
|
2018-04-25 20:54:03 +03:00
|
|
|
uint32_t mDefaultSubSpaceFeatures[(int(Script::NUM_SCRIPT_CODES) + 31) / 32];
|
2018-11-30 13:46:48 +03:00
|
|
|
uint32_t
|
2014-09-16 13:58:12 +04:00
|
|
|
mNonDefaultSubSpaceFeatures[(int(Script::NUM_SCRIPT_CODES) + 31) / 32];
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
uint32_t mUVSOffset = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
uint32_t mLanguageOverride = NO_FONT_LANGUAGE_OVERRIDE;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
WeightRange mWeightRange = WeightRange(FontWeight(500));
|
|
|
|
StretchRange mStretchRange = StretchRange(FontStretch::Normal());
|
2014-09-16 13:58:12 +04:00
|
|
|
SlantStyleRange mStyleRange = SlantStyleRange(FontSlantStyle::Normal());
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// For user fonts (only), we need to record whether or not weight/stretch/
|
|
|
|
// slant variations should be clamped to the range specified in the entry
|
2016-05-03 14:14:34 +03:00
|
|
|
// properties. When the @font-face rule omitted one or more of these
|
|
|
|
// descriptors, it is treated as the initial value for font-matching (and
|
|
|
|
// so that is what we record in the font entry), but when rendering the
|
|
|
|
// range is NOT clamped.
|
2014-09-16 13:58:12 +04:00
|
|
|
enum class RangeFlags : uint8_t {
|
|
|
|
eNoFlags = 0,
|
2018-04-26 17:32:36 +03:00
|
|
|
eAutoWeight = (1 << 0),
|
2014-09-16 13:58:12 +04:00
|
|
|
eAutoStretch = (1 << 1),
|
2018-05-04 12:19:55 +03:00
|
|
|
eAutoSlantStyle = (1 << 2),
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Flag to record whether the face has a variable "wght" axis
|
|
|
|
// that supports "bold" values, used to disable the application
|
|
|
|
// of synthetic-bold effects.
|
|
|
|
eBoldVariableWeight = (1 << 3),
|
|
|
|
// Whether the face has an 'ital' axis.
|
|
|
|
eItalicVariation = (1 << 4),
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Flags to record if the face uses a non-CSS-compatible scale
|
|
|
|
// for weight and/or stretch, in which case we won't map the
|
|
|
|
// properties to the variation axes (though they can still be
|
2018-04-26 19:08:18 +03:00
|
|
|
// explicitly set using font-variation-settings).
|
|
|
|
eNonCSSWeight = (1 << 5),
|
|
|
|
eNonCSSStretch = (1 << 6)
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2018-04-26 19:08:18 +03:00
|
|
|
RangeFlags mRangeFlags = RangeFlags::eNoFlags;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-26 19:08:18 +03:00
|
|
|
// NOTE that there are currently exactly 24 one-bit flags defined here,
|
2018-04-25 09:18:23 +03:00
|
|
|
// so together with the 8-bit RangeFlags above, this packs neatly to a
|
|
|
|
// 32-bit boundary. Worth considering if further flags are wanted.
|
|
|
|
bool mFixedPitch : 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mIsBadUnderlineFont : 1;
|
2018-04-25 09:18:23 +03:00
|
|
|
bool mIsUserFontContainer : 1; // userfont entry
|
|
|
|
bool mIsDataUserFont : 1; // platform font entry (data)
|
|
|
|
bool mIsLocalUserFont : 1; // platform font entry (local)
|
|
|
|
bool mStandardFace : 1;
|
|
|
|
bool mIgnoreGDEF : 1;
|
|
|
|
bool mIgnoreGSUB : 1;
|
|
|
|
bool mSVGInitialized : 1;
|
|
|
|
bool mHasSpaceFeaturesInitialized : 1;
|
2018-01-30 12:57:39 +03:00
|
|
|
bool mHasSpaceFeatures : 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mHasSpaceFeaturesKerning : 1;
|
|
|
|
bool mHasSpaceFeaturesNonKerning : 1;
|
2018-01-30 12:57:39 +03:00
|
|
|
bool mSkipDefaultFeatureSpaceCheck : 1;
|
|
|
|
bool mGraphiteSpaceContextualsInitialized : 1;
|
2015-08-03 11:04:59 +03:00
|
|
|
bool mHasGraphiteSpaceContextuals : 1;
|
2018-01-30 12:57:39 +03:00
|
|
|
bool mSpaceGlyphIsInvisible : 1;
|
2014-11-18 13:23:45 +03:00
|
|
|
bool mSpaceGlyphIsInvisibleInitialized : 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mHasGraphiteTables : 1;
|
2018-01-30 12:57:39 +03:00
|
|
|
bool mCheckedForGraphiteTables : 1;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mHasCmapTable : 1;
|
|
|
|
bool mGrFaceInitialized : 1;
|
|
|
|
bool mCheckedForColorGlyph : 1;
|
2018-05-09 15:49:24 +03:00
|
|
|
bool mCheckedForVariationAxes : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
protected:
|
2018-01-30 12:57:39 +03:00
|
|
|
friend class gfxPlatformFontList;
|
|
|
|
friend class gfxMacPlatformFontList;
|
2016-05-03 14:14:34 +03:00
|
|
|
friend class gfxUserFcFontEntry;
|
2014-09-16 13:58:12 +04:00
|
|
|
friend class gfxFontFamily;
|
2018-01-30 12:57:39 +03:00
|
|
|
friend class gfxSingleFaceMacFontFamily;
|
2016-05-03 14:14:34 +03:00
|
|
|
friend class gfxUserFontEntry;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-30 12:57:39 +03:00
|
|
|
gfxFontEntry();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-08-02 00:39:05 +03:00
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
|
|
|
virtual ~gfxFontEntry();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
virtual gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
virtual void CheckForGraphiteTables();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
// Copy a font table into aBuffer.
|
|
|
|
// The caller will be responsible for ownership of the data.
|
|
|
|
virtual nsresult CopyFontTable(uint32_t aTableTag,
|
|
|
|
nsTArray<uint8_t>& aBuffer) {
|
|
|
|
MOZ_ASSERT_UNREACHABLE(
|
|
|
|
"forgot to override either GetFontTable or "
|
2018-06-18 08:43:11 +03:00
|
|
|
"CopyFontTable?");
|
2018-04-25 20:54:03 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2019-05-30 13:28:44 +03:00
|
|
|
// Helper for HasTrackingTable; check/parse the table and cache pointers
|
|
|
|
// to the subtables we need. Returns false on failure, in which case the
|
|
|
|
// table is unusable.
|
|
|
|
bool ParseTrakTable();
|
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
// lookup the cmap in cached font data
|
|
|
|
virtual already_AddRefed<gfxCharacterMap> GetCMAPFromFontInfo(
|
|
|
|
FontInfoData* aFontInfoData, uint32_t& aUVSOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-26 17:32:36 +03:00
|
|
|
// helper for HasCharacter(), which is what client code should call
|
|
|
|
virtual bool TestCharacterMap(uint32_t aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-04-29 17:39:05 +03:00
|
|
|
// Try to set mShmemCharacterMap, based on the char map in mShmemFace;
|
|
|
|
// return true if successful, false if it remains null (maybe the parent
|
|
|
|
// hasn't handled our SetCharacterMap message yet).
|
|
|
|
bool TrySetShmemCharacterMap();
|
|
|
|
|
2018-04-26 17:32:36 +03:00
|
|
|
// Shaper-specific face objects, shared by all instantiations of the same
|
|
|
|
// physical font, regardless of size.
|
|
|
|
// Usually, only one of these will actually be created for any given font
|
|
|
|
// entry, depending on the font tables that are present.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-26 17:32:36 +03:00
|
|
|
// hb_face_t is refcounted internally, so each shaper that's using it will
|
|
|
|
// bump the ref count when it acquires the face, and "destroy" (release) it
|
|
|
|
// in its destructor. The font entry has only this non-owning reference to
|
|
|
|
// the face; when the face is deleted, it will tell the font entry to forget
|
|
|
|
// it, so that a new face will be created next time it is needed.
|
|
|
|
hb_face_t* mHBFace = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
static hb_blob_t* HBGetTable(hb_face_t* face, uint32_t aTag, void* aUserData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
// Callback that the hb_face will use to tell us when it is being deleted.
|
2014-09-16 13:58:12 +04:00
|
|
|
static void HBFaceDeletedCallback(void* aUserData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-12-19 19:05:35 +03:00
|
|
|
// All libGraphite functionality is sandboxed in an rlbox sandbox. This
|
|
|
|
// contains data for the sandbox instance.
|
|
|
|
struct GrSandboxData;
|
|
|
|
GrSandboxData* mSandboxData = nullptr;
|
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
// gr_face is -not- refcounted, so it will be owned directly by the font
|
2014-09-16 13:58:12 +04:00
|
|
|
// entry, and we'll keep a count of how many references we've handed out;
|
|
|
|
// each shaper is responsible to call ReleaseGrFace on its entry when
|
|
|
|
// finished with it, so that we know when it can be deleted.
|
2019-12-19 19:05:35 +03:00
|
|
|
tainted_opaque_gr<gr_face*> mGrFace;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-30 13:28:44 +03:00
|
|
|
// For AAT font, a strong reference to the 'trak' table (if present).
|
2019-06-09 18:34:20 +03:00
|
|
|
hb_blob_t* const kTrakTableUninitialized = (hb_blob_t*)(intptr_t(-1));
|
2019-05-30 13:28:44 +03:00
|
|
|
hb_blob_t* mTrakTable = kTrakTableUninitialized;
|
|
|
|
bool TrakTableInitialized() const {
|
|
|
|
return mTrakTable != kTrakTableUninitialized;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cached pointers to tables within 'trak', initialized by ParseTrakTable.
|
|
|
|
const mozilla::AutoSwap_PRInt16* mTrakValues;
|
|
|
|
const mozilla::AutoSwap_PRInt32* mTrakSizeTable;
|
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
// number of current users of this entry's mGrFace
|
2018-04-25 20:54:03 +03:00
|
|
|
nsrefcnt mGrFaceRefCnt = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-12-19 19:05:35 +03:00
|
|
|
static tainted_opaque_gr<const void*> GrGetTable(
|
|
|
|
rlbox_sandbox_gr& sandbox, tainted_opaque_gr<const void*> aAppFaceHandle,
|
|
|
|
tainted_opaque_gr<unsigned int> aName, tainted_opaque_gr<size_t*> aLen);
|
|
|
|
static void GrReleaseTable(rlbox_sandbox_gr& sandbox,
|
|
|
|
tainted_opaque_gr<const void*> aAppFaceHandle,
|
|
|
|
tainted_opaque_gr<const void*> aTableBuffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
// For memory reporting: size of user-font data belonging to this entry.
|
2018-05-04 19:36:01 +03:00
|
|
|
// We record this in the font entry because the actual data block may be
|
|
|
|
// handed over to platform APIs, so that it would become difficult (and
|
|
|
|
// platform-specific) to measure it directly at report-gathering time.
|
|
|
|
uint32_t mComputedSizeOfUserFont = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-04 19:36:01 +03:00
|
|
|
// Font's unitsPerEm from the 'head' table, if available (will be set to
|
|
|
|
// kInvalidUPEM for non-sfnt font formats)
|
2018-04-26 17:32:36 +03:00
|
|
|
uint16_t mUnitsPerEm = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-30 13:28:44 +03:00
|
|
|
uint16_t mNumTrakSizes;
|
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* Font table hashtable, to support GetFontTable for harfbuzz.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2018-05-04 12:19:55 +03:00
|
|
|
* The harfbuzz shaper (and potentially other clients) needs access to raw
|
|
|
|
* font table data. This needs to be cached so that it can be used
|
|
|
|
* repeatedly (each time we construct a text run; in some cases, for
|
|
|
|
* each character/glyph within the run) without re-fetching large tables
|
2014-09-16 13:58:12 +04:00
|
|
|
* every time.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Because we may instantiate many gfxFonts for the same physical font
|
|
|
|
* file (at different sizes), we should ensure that they can share a
|
|
|
|
* single cached copy of the font tables. To do this, we implement table
|
|
|
|
* access and sharing on the fontEntry rather than the font itself.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* The default implementation uses GetFontTable() to read font table
|
|
|
|
* data into byte arrays, and wraps them in blobs which are registered in
|
|
|
|
* a hashtable. The hashtable can then return pre-existing blobs to
|
|
|
|
* harfbuzz.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Harfbuzz will "destroy" the blobs when it is finished with them. When
|
|
|
|
* the last blob reference is removed, the FontTableBlobData user data
|
|
|
|
* will remove the blob from the hashtable if still registered.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class FontTableBlobData;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* FontTableHashEntry manages the entries of hb_blob_t's containing font
|
|
|
|
* table data.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* This is used to share font tables across fonts with the same
|
|
|
|
* font entry (but different sizes) for use by HarfBuzz. The hashtable
|
|
|
|
* does not own a strong reference to the blob, but keeps a weak pointer,
|
|
|
|
* managed by FontTableBlobData. Similarly FontTableBlobData keeps only a
|
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
|
|
|
* weak pointer to the hashtable, managed by FontTableHashEntry.
|
|
|
|
*/
|
2018-11-30 13:46:48 +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
|
|
|
class FontTableHashEntry : public nsUint32HashKey {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
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
|
|
|
// Declarations for nsTHashtable
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
typedef nsUint32HashKey KeyClass;
|
|
|
|
typedef KeyClass::KeyType KeyType;
|
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
|
|
|
typedef KeyClass::KeyTypePointer KeyTypePointer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
explicit FontTableHashEntry(KeyTypePointer aTag)
|
|
|
|
: KeyClass(aTag), mSharedBlobData(nullptr), mBlob(nullptr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// NOTE: This assumes the new entry belongs to the same hashtable as
|
|
|
|
// the old, because the mHashtable pointer in mSharedBlobData (if
|
|
|
|
// present) will not be updated.
|
2018-06-18 08:43:11 +03:00
|
|
|
FontTableHashEntry(FontTableHashEntry&& toMove)
|
|
|
|
: KeyClass(std::move(toMove)),
|
|
|
|
mSharedBlobData(std::move(toMove.mSharedBlobData)),
|
2018-05-30 22:15:35 +03:00
|
|
|
mBlob(std::move(toMove.mBlob)) {
|
2018-06-18 08:43:11 +03:00
|
|
|
toMove.mSharedBlobData = nullptr;
|
2014-09-16 13:58:12 +04:00
|
|
|
toMove.mBlob = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
~FontTableHashEntry() { Clear(); }
|
|
|
|
|
|
|
|
// FontTable/Blob API
|
|
|
|
|
|
|
|
// Transfer (not copy) elements of aTable to a new hb_blob_t and
|
|
|
|
// return ownership to the caller. A weak reference to the blob is
|
|
|
|
// recorded in the hashtable entry so that others may use the same
|
|
|
|
// table.
|
2016-02-02 18:36:30 +03:00
|
|
|
hb_blob_t* ShareTableAndGetBlob(
|
|
|
|
nsTArray<uint8_t>&& aTable,
|
2014-09-16 13:58:12 +04:00
|
|
|
nsTHashtable<FontTableHashEntry>* aHashtable);
|
|
|
|
|
|
|
|
// Return a strong reference to the blob.
|
|
|
|
// Callers must hb_blob_destroy the returned blob.
|
|
|
|
hb_blob_t* GetBlob() const;
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void DeleteFontTableBlobData(void* aBlobData);
|
|
|
|
// not implemented
|
|
|
|
FontTableHashEntry& operator=(FontTableHashEntry& toCopy);
|
|
|
|
|
|
|
|
FontTableBlobData* mSharedBlobData;
|
|
|
|
hb_blob_t* mBlob;
|
|
|
|
};
|
|
|
|
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<nsTHashtable<FontTableHashEntry>> mFontTableCache;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
gfxFontEntry(const gfxFontEntry&);
|
|
|
|
gfxFontEntry& operator=(const gfxFontEntry&);
|
|
|
|
};
|
|
|
|
|
2018-04-26 17:32:36 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxFontEntry::RangeFlags)
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2018-05-09 15:49:24 +03:00
|
|
|
inline bool gfxFontEntry::SupportsItalic() {
|
|
|
|
return SlantStyle().Max().IsItalic() ||
|
|
|
|
((mRangeFlags & RangeFlags::eAutoSlantStyle) ==
|
|
|
|
RangeFlags::eAutoSlantStyle &&
|
|
|
|
HasItalicVariation());
|
|
|
|
}
|
|
|
|
|
2018-05-04 12:19:55 +03:00
|
|
|
inline bool gfxFontEntry::SupportsBold() {
|
|
|
|
// bold == weights 600 and above
|
|
|
|
// We return true if the face has a max weight descriptor >= 600,
|
|
|
|
// OR if it's a user font with auto-weight (no descriptor) and has
|
|
|
|
// a weight axis that supports values >= 600
|
|
|
|
return Weight().Max().IsBold() ||
|
|
|
|
((mRangeFlags & RangeFlags::eAutoWeight) == RangeFlags::eAutoWeight &&
|
|
|
|
HasBoldVariableWeight());
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// used when iterating over all fonts looking for a match for a given character
|
|
|
|
struct GlobalFontMatch {
|
|
|
|
GlobalFontMatch(const uint32_t aCharacter, const gfxFontStyle& aStyle)
|
2019-04-27 18:37:29 +03:00
|
|
|
: mStyle(aStyle), mCh(aCharacter) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-15 16:59:25 +03:00
|
|
|
RefPtr<gfxFontEntry> mBestMatch; // current best match
|
|
|
|
RefPtr<gfxFontFamily> mMatchedFamily; // the family it belongs to
|
2019-04-27 18:37:29 +03:00
|
|
|
mozilla::fontlist::Family* mMatchedSharedFamily = nullptr;
|
|
|
|
const gfxFontStyle& mStyle; // style to match
|
|
|
|
const uint32_t mCh; // codepoint to be matched
|
|
|
|
uint32_t mCount = 0; // number of fonts matched
|
|
|
|
uint32_t mCmapsTested = 0; // number of cmaps tested
|
|
|
|
float mMatchDistance = INFINITY; // metric indicating closest match
|
2014-09-16 13:58:12 +04:00
|
|
|
};
|
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
// Installation status (base system / langpack / user-installed) may determine
|
|
|
|
// whether the font is visible to CSS font-family or src:local() lookups.
|
|
|
|
// (Exactly what these mean and how accurate they are may be vary across
|
|
|
|
// platforms -- e.g. on Linux there is no clear "base" set of fonts.)
|
|
|
|
enum class FontVisibility : uint8_t {
|
|
|
|
Unknown = 0, // No categorization of families available on this system
|
|
|
|
Base = 1, // Standard part of the base OS installation
|
|
|
|
LangPack = 2, // From an optional OS component such as language support
|
|
|
|
User = 3, // User-installed font (or installed by another app, etc)
|
|
|
|
Hidden = 4, // Internal system font, should never exposed to users
|
|
|
|
Count = 5, // Count of values, for IPC serialization
|
|
|
|
};
|
|
|
|
|
|
|
|
namespace IPC {
|
|
|
|
template <>
|
|
|
|
struct ParamTraits<FontVisibility>
|
|
|
|
: public ContiguousEnumSerializer<FontVisibility, FontVisibility::Unknown,
|
|
|
|
FontVisibility::Count> {};
|
|
|
|
} // namespace IPC
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class gfxFontFamily {
|
|
|
|
public:
|
2017-04-08 01:49:44 +03:00
|
|
|
// Used by stylo
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxFontFamily)
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
gfxFontFamily(const nsACString& aName, FontVisibility aVisibility)
|
2014-09-16 13:58:12 +04:00
|
|
|
: mName(aName),
|
2020-04-02 15:36:24 +03:00
|
|
|
mVisibility(aVisibility),
|
2014-09-16 13:58:12 +04:00
|
|
|
mOtherFamilyNamesInitialized(false),
|
|
|
|
mHasOtherFamilyNames(false),
|
|
|
|
mFaceNamesInitialized(false),
|
|
|
|
mHasStyles(false),
|
|
|
|
mIsSimpleFamily(false),
|
|
|
|
mIsBadUnderlineFamily(false),
|
|
|
|
mFamilyCharacterMapInitialized(false),
|
2015-11-11 15:13:33 +03:00
|
|
|
mSkipDefaultFeatureSpaceCheck(false),
|
2017-08-01 13:25:35 +03:00
|
|
|
mCheckForFallbackFaces(false),
|
|
|
|
mCheckedForLegacyFamilyNames(false) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
const nsCString& Name() { return mName; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
virtual void LocalizedName(nsACString& aLocalizedName);
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual bool HasOtherFamilyNames();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=835204:
|
|
|
|
// check the font's 'name' table to see if it has a legacy family name
|
|
|
|
// that would have been used by GDI (e.g. to split extra-bold or light
|
|
|
|
// faces in a large family into separate "styled families" because of
|
|
|
|
// GDI's 4-faces-per-family limitation). If found, the styled family
|
|
|
|
// name will be added to the font list's "other family names" table.
|
|
|
|
bool CheckForLegacyFamilyNames(gfxPlatformFontList* aFontList);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<gfxFontEntry>>& GetFontList() { return mAvailableFonts; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
void AddFontEntry(RefPtr<gfxFontEntry> aFontEntry) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// bug 589682 - set the IgnoreGDEF flag on entries for Italic faces
|
|
|
|
// of Times New Roman, because of buggy table in those fonts
|
|
|
|
if (aFontEntry->IsItalic() && !aFontEntry->IsUserFont() &&
|
|
|
|
Name().EqualsLiteral("Times New Roman")) {
|
|
|
|
aFontEntry->mIgnoreGDEF = true;
|
|
|
|
}
|
|
|
|
if (aFontEntry->mFamilyName.IsEmpty()) {
|
|
|
|
aFontEntry->mFamilyName = Name();
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(aFontEntry->mFamilyName.Equals(Name()));
|
|
|
|
}
|
|
|
|
aFontEntry->mSkipDefaultFeatureSpaceCheck = mSkipDefaultFeatureSpaceCheck;
|
|
|
|
mAvailableFonts.AppendElement(aFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-10 10:49:09 +03:00
|
|
|
// If we're adding a face to a family that has been marked as "simple",
|
|
|
|
// we need to ensure any null entries are removed, as well as clearing
|
|
|
|
// the flag (which may be set again later).
|
|
|
|
if (mIsSimpleFamily) {
|
|
|
|
for (size_t i = mAvailableFonts.Length() - 1; i-- > 0;) {
|
|
|
|
if (!mAvailableFonts[i]) {
|
|
|
|
mAvailableFonts.RemoveElementAt(i);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-09-10 10:49:09 +03:00
|
|
|
mIsSimpleFamily = false;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// note that the styles for this family have been added
|
2017-08-07 19:27:33 +03:00
|
|
|
bool HasStyles() { return mHasStyles; }
|
2014-09-16 13:58:12 +04:00
|
|
|
void SetHasStyles(bool aHasStyles) { mHasStyles = aHasStyles; }
|
|
|
|
|
|
|
|
// choose a specific face to match a style using CSS font matching
|
|
|
|
// rules (weight matching occurs here). may return a face that doesn't
|
|
|
|
// precisely match (e.g. normal face when no italic face exists).
|
|
|
|
gfxFontEntry* FindFontForStyle(const gfxFontStyle& aFontStyle,
|
|
|
|
bool aIgnoreSizeTolerance = false);
|
|
|
|
|
|
|
|
virtual void FindAllFontsForStyle(const gfxFontStyle& aFontStyle,
|
|
|
|
nsTArray<gfxFontEntry*>& aFontEntryList,
|
|
|
|
bool aIgnoreSizeTolerance = false);
|
|
|
|
|
|
|
|
// checks for a matching font within the family
|
|
|
|
// used as part of the font fallback process
|
2018-09-12 22:34:57 +03:00
|
|
|
void FindFontForChar(GlobalFontMatch* aMatchData);
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// checks all fonts for a matching font within the family
|
|
|
|
void SearchAllFontsForChar(GlobalFontMatch* aMatchData);
|
|
|
|
|
|
|
|
// read in other family names, if any, and use functor to add each into cache
|
|
|
|
virtual void ReadOtherFamilyNames(gfxPlatformFontList* aPlatformFontList);
|
|
|
|
|
|
|
|
// set when other family names have been read in
|
|
|
|
void SetOtherFamilyNamesInitialized() { mOtherFamilyNamesInitialized = true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// read in other localized family names, fullnames and Postscript names
|
|
|
|
// for all faces and append to lookup tables
|
|
|
|
virtual void ReadFaceNames(gfxPlatformFontList* aPlatformFontList,
|
|
|
|
bool aNeedFullnamePostscriptNames,
|
|
|
|
FontInfoData* aFontInfoData = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// find faces belonging to this family (platform implementations override
|
|
|
|
// this; should be made pure virtual once all subclasses have been updated)
|
|
|
|
virtual void FindStyleVariations(FontInfoData* aFontInfoData = nullptr) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// search for a specific face using the Postscript name
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontEntry* FindFont(const nsACString& aPostscriptName);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// read in cmaps for all the faces
|
|
|
|
void ReadAllCMAPs(FontInfoData* aFontInfoData = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool TestCharacterMap(uint32_t aCh) {
|
|
|
|
if (!mFamilyCharacterMapInitialized) {
|
|
|
|
ReadAllCMAPs();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return mFamilyCharacterMap.test(aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void ResetCharacterMap() {
|
|
|
|
mFamilyCharacterMap.reset();
|
|
|
|
mFamilyCharacterMapInitialized = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// mark this family as being in the "bad" underline offset blacklist
|
|
|
|
void SetBadUnderlineFamily() {
|
|
|
|
mIsBadUnderlineFamily = true;
|
|
|
|
if (mHasStyles) {
|
|
|
|
SetBadUnderlineFonts();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
bool IsBadUnderlineFamily() const { return mIsBadUnderlineFamily; }
|
2015-11-11 15:13:33 +03:00
|
|
|
bool CheckForFallbackFaces() const { return mCheckForFallbackFaces; }
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// sort available fonts to put preferred (standard) faces towards the end
|
|
|
|
void SortAvailableFonts();
|
|
|
|
|
|
|
|
// check whether the family fits into the simple 4-face model,
|
|
|
|
// so we can use simplified style-matching;
|
|
|
|
// if so set the mIsSimpleFamily flag (defaults to False before we've checked)
|
|
|
|
void CheckForSimpleFamily();
|
|
|
|
|
|
|
|
// For memory reporter
|
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Only used for debugging checks - does a linear search
|
|
|
|
bool ContainsFace(gfxFontEntry* aFontEntry);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void SetSkipSpaceFeatureCheck(bool aSkipCheck) {
|
|
|
|
mSkipDefaultFeatureSpaceCheck = aSkipCheck;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-09-11 21:24:01 +03:00
|
|
|
// Check whether this family is appropriate to include in the Preferences
|
|
|
|
// font list for the given langGroup and CSS generic, if the platform lets
|
|
|
|
// us determine this.
|
|
|
|
// Return true if the family should be included in the list, false to omit.
|
|
|
|
// Default implementation returns true for everything, so no filtering
|
|
|
|
// will occur; individual platforms may override.
|
2017-10-03 01:05:19 +03:00
|
|
|
virtual bool FilterForFontList(nsAtom* aLangGroup,
|
2017-09-11 21:24:01 +03:00
|
|
|
const nsACString& aGeneric) const {
|
2017-09-11 21:22:15 +03:00
|
|
|
return true;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
FontVisibility Visibility() const { return mVisibility; }
|
|
|
|
bool IsHidden() const { return Visibility() == FontVisibility::Hidden; }
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
protected:
|
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2017-04-08 01:49:44 +03:00
|
|
|
virtual ~gfxFontFamily();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool ReadOtherFamilyNamesForFace(gfxPlatformFontList* aPlatformFontList,
|
|
|
|
hb_blob_t* aNameTable,
|
|
|
|
bool useFullName = false);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// set whether this font family is in "bad" underline offset blacklist.
|
|
|
|
void SetBadUnderlineFonts() {
|
|
|
|
uint32_t i, numFonts = mAvailableFonts.Length();
|
|
|
|
for (i = 0; i < numFonts; i++) {
|
|
|
|
if (mAvailableFonts[i]) {
|
|
|
|
mAvailableFonts[i]->mIsBadUnderlineFont = true;
|
|
|
|
}
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mName;
|
2015-10-18 08:24:48 +03:00
|
|
|
nsTArray<RefPtr<gfxFontEntry>> mAvailableFonts;
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxSparseBitSet mFamilyCharacterMap;
|
2020-04-02 15:36:24 +03:00
|
|
|
|
|
|
|
FontVisibility mVisibility;
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mOtherFamilyNamesInitialized : 1;
|
|
|
|
bool mHasOtherFamilyNames : 1;
|
|
|
|
bool mFaceNamesInitialized : 1;
|
|
|
|
bool mHasStyles : 1;
|
|
|
|
bool mIsSimpleFamily : 1;
|
|
|
|
bool mIsBadUnderlineFamily : 1;
|
|
|
|
bool mFamilyCharacterMapInitialized : 1;
|
|
|
|
bool mSkipDefaultFeatureSpaceCheck : 1;
|
2015-11-11 15:13:33 +03:00
|
|
|
bool mCheckForFallbackFaces : 1; // check other faces for character
|
2017-08-01 13:25:35 +03:00
|
|
|
bool mCheckedForLegacyFamilyNames : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
enum {
|
|
|
|
// for "simple" families, the faces are stored in mAvailableFonts
|
|
|
|
// with fixed positions:
|
|
|
|
kRegularFaceIndex = 0,
|
|
|
|
kBoldFaceIndex = 1,
|
|
|
|
kItalicFaceIndex = 2,
|
|
|
|
kBoldItalicFaceIndex = 3,
|
|
|
|
// mask values for selecting face with bold and/or italic attributes
|
|
|
|
kBoldMask = 0x01,
|
|
|
|
kItalicMask = 0x02
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2019-04-01 17:33:34 +03:00
|
|
|
// Wrapper for either a mozilla::fontlist::Family in the shared font list or an
|
|
|
|
// unshared gfxFontFamily that belongs just to the current process. This does
|
|
|
|
// not own a reference, it just wraps a raw pointer and records the type.
|
|
|
|
struct FontFamily {
|
|
|
|
FontFamily() : mUnshared(nullptr), mIsShared(false) {}
|
|
|
|
|
|
|
|
FontFamily(const FontFamily& aOther) = default;
|
|
|
|
|
|
|
|
explicit FontFamily(gfxFontFamily* aFamily)
|
|
|
|
: mUnshared(aFamily), mIsShared(false) {}
|
|
|
|
|
|
|
|
explicit FontFamily(mozilla::fontlist::Family* aFamily)
|
|
|
|
: mShared(aFamily), mIsShared(true) {}
|
|
|
|
|
|
|
|
bool operator==(const FontFamily& aOther) const {
|
|
|
|
return mIsShared == aOther.mIsShared &&
|
|
|
|
(mIsShared ? mShared == aOther.mShared
|
|
|
|
: mUnshared == aOther.mUnshared);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsNull() const { return mIsShared ? !mShared : !mUnshared; }
|
|
|
|
|
|
|
|
union {
|
|
|
|
gfxFontFamily* mUnshared;
|
|
|
|
mozilla::fontlist::Family* mShared;
|
|
|
|
};
|
|
|
|
bool mIsShared;
|
|
|
|
};
|
|
|
|
|
2018-05-25 16:07:57 +03:00
|
|
|
// Struct used in the gfxFontGroup font list to keep track of a font family
|
|
|
|
// together with the CSS generic (if any) that was mapped to it in this
|
|
|
|
// particular case (so it can be reported to the DevTools font inspector).
|
|
|
|
struct FamilyAndGeneric final {
|
|
|
|
FamilyAndGeneric()
|
2020-02-11 04:23:37 +03:00
|
|
|
: mFamily(), mGeneric(mozilla::StyleGenericFontFamily(0)) {}
|
2020-03-04 18:39:20 +03:00
|
|
|
FamilyAndGeneric(const FamilyAndGeneric& aOther) = default;
|
2019-04-02 00:47:59 +03:00
|
|
|
explicit FamilyAndGeneric(gfxFontFamily* aFamily,
|
|
|
|
mozilla::StyleGenericFontFamily aGeneric =
|
2020-02-11 04:23:37 +03:00
|
|
|
mozilla::StyleGenericFontFamily(0))
|
2018-05-25 16:07:57 +03:00
|
|
|
: mFamily(aFamily), mGeneric(aGeneric) {}
|
2019-04-02 00:47:59 +03:00
|
|
|
explicit FamilyAndGeneric(mozilla::fontlist::Family* aFamily,
|
|
|
|
mozilla::StyleGenericFontFamily aGeneric =
|
2020-02-11 04:23:37 +03:00
|
|
|
mozilla::StyleGenericFontFamily(0))
|
2019-04-01 17:33:34 +03:00
|
|
|
: mFamily(aFamily), mGeneric(aGeneric) {}
|
2019-04-02 00:47:59 +03:00
|
|
|
explicit FamilyAndGeneric(const FontFamily& aFamily,
|
|
|
|
mozilla::StyleGenericFontFamily aGeneric =
|
2020-02-11 04:23:37 +03:00
|
|
|
mozilla::StyleGenericFontFamily(0))
|
2019-04-01 17:33:34 +03:00
|
|
|
: mFamily(aFamily), mGeneric(aGeneric) {}
|
|
|
|
|
|
|
|
bool operator==(const FamilyAndGeneric& aOther) const {
|
2019-04-02 00:47:59 +03:00
|
|
|
return mFamily == aOther.mFamily && mGeneric == aOther.mGeneric;
|
2019-04-01 17:33:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FontFamily mFamily;
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily mGeneric;
|
2018-05-25 16:07:57 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
#endif
|