2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2012-05-21 15:12:37 +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/. */
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
#ifndef gfxMacPlatformFontList_H_
|
|
|
|
#define gfxMacPlatformFontList_H_
|
|
|
|
|
2013-10-16 08:53:52 +04:00
|
|
|
#include <CoreFoundation/CoreFoundation.h>
|
|
|
|
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2009-08-16 17:52:12 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
|
|
|
|
#include "gfxPlatformFontList.h"
|
|
|
|
#include "gfxPlatform.h"
|
2011-06-24 21:55:27 +04:00
|
|
|
#include "gfxPlatformMac.h"
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
#include "nsTArray.h"
|
2015-10-08 09:04:08 +03:00
|
|
|
#include "mozilla/LookAndFeel.h"
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
#include "mozilla/gfx/UnscaledFontMac.h"
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
class gfxMacPlatformFontList;
|
|
|
|
|
|
|
|
// a single member of a font family (i.e. a single face, such as Times Italic)
|
2020-03-10 18:00:56 +03:00
|
|
|
class MacOSFontEntry final : public gfxFontEntry {
|
2009-08-16 17:52:12 +04:00
|
|
|
public:
|
|
|
|
friend class gfxMacPlatformFontList;
|
2018-05-15 16:59:26 +03:00
|
|
|
friend class gfxMacFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
MacOSFontEntry(const nsACString& aPostscriptName, WeightRange aWeight,
|
2016-07-04 22:13:34 +03:00
|
|
|
bool aIsStandardFace = false, double aSizeHint = 0.0);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-11-19 14:22:10 +04:00
|
|
|
// for use with data fonts
|
2018-09-12 22:34:57 +03:00
|
|
|
MacOSFontEntry(const nsACString& aPostscriptName, CGFontRef aFontRef,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeight, StretchRange aStretch,
|
2014-09-08 11:23:20 +04:00
|
|
|
SlantStyleRange aStyle, bool aIsDataUserFont, bool aIsLocal);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-05-30 13:28:44 +03:00
|
|
|
virtual ~MacOSFontEntry() { ::CGFontRelease(mFontRef); }
|
2011-06-24 21:55:27 +04:00
|
|
|
|
2017-08-01 13:25:35 +03:00
|
|
|
gfxFontEntry* Clone() const override;
|
|
|
|
|
2020-04-08 20:35:30 +03:00
|
|
|
// Return a non-owning reference to our CGFont; caller must not release it.
|
|
|
|
// This will cause the fontEntry to create & retain a CGFont for the life
|
|
|
|
// of the entry.
|
|
|
|
// Note that in the case of a broken font, this could return null.
|
2017-01-18 23:38:04 +03:00
|
|
|
CGFontRef GetFontRef();
|
2011-06-24 21:55:27 +04:00
|
|
|
|
2020-04-08 20:35:30 +03:00
|
|
|
// Return a new reference to our CGFont. Caller is responsible to release
|
|
|
|
// this reference.
|
|
|
|
// (If the entry has a cached CGFont, this just bumps its refcount and
|
|
|
|
// returns it; if not, the instance returned will be owned solely by the
|
|
|
|
// caller.)
|
|
|
|
// Note that in the case of a broken font, this could return null.
|
|
|
|
CGFontRef CreateOrCopyFontRef();
|
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
// override gfxFontEntry table access function to bypass table cache,
|
|
|
|
// use CGFontRef API to get direct access to system font data
|
2017-01-18 23:38:04 +03:00
|
|
|
hb_blob_t* GetFontTable(uint32_t aTag) override;
|
2012-11-19 14:22:10 +04:00
|
|
|
|
2017-01-18 23:38:04 +03:00
|
|
|
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
nsresult ReadCMAP(FontInfoData* aFontInfoData = nullptr) override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool RequiresAATLayout() const { return mRequiresAAT; }
|
2010-07-22 13:25:21 +04:00
|
|
|
|
2018-01-26 18:47:19 +03:00
|
|
|
bool HasVariations() override;
|
2018-01-26 18:47:20 +03:00
|
|
|
void GetVariationAxes(
|
|
|
|
nsTArray<gfxFontVariationAxis>& aVariationAxes) override;
|
2018-01-29 16:24:11 +03:00
|
|
|
void GetVariationInstances(
|
|
|
|
nsTArray<gfxFontVariationInstance>& aInstances) override;
|
2018-01-26 18:47:20 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCFF();
|
2010-10-07 11:59:16 +04:00
|
|
|
|
2017-10-12 00:12:43 +03:00
|
|
|
bool SupportsOpenTypeFeature(Script aScript, uint32_t aFeatureTag) override;
|
2017-10-12 00:12:42 +03:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
protected:
|
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;
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2017-01-18 23:38:04 +03:00
|
|
|
bool HasFontTable(uint32_t aTableTag) override;
|
2011-06-24 21:55:27 +04:00
|
|
|
|
2013-05-16 20:29:20 +04:00
|
|
|
static void DestroyBlobFunc(void* aUserData);
|
|
|
|
|
2011-06-24 21:55:27 +04:00
|
|
|
CGFontRef
|
|
|
|
mFontRef; // owning reference to the CGFont, released on destruction
|
|
|
|
|
2016-07-04 22:13:34 +03:00
|
|
|
double mSizeHint;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFontRefInitialized;
|
|
|
|
bool mRequiresAAT;
|
|
|
|
bool mIsCFF;
|
|
|
|
bool mIsCFFInitialized;
|
2017-04-03 17:45:52 +03:00
|
|
|
bool mHasVariations;
|
|
|
|
bool mHasVariationsInitialized;
|
2017-10-12 00:12:43 +03:00
|
|
|
bool mHasAATSmallCaps;
|
|
|
|
bool mHasAATSmallCapsInitialized;
|
2018-05-15 16:59:26 +03:00
|
|
|
|
|
|
|
// To work around Core Text's mishandling of the default value for 'opsz',
|
|
|
|
// we need to record whether the font has an a optical size axis, what its
|
|
|
|
// range and default values are, and a usable close-to-default alternative.
|
|
|
|
// (See bug 1457417 for details.)
|
|
|
|
// These fields are used by gfxMacFont, but stored in the font entry so
|
|
|
|
// that only a single font instance needs to inspect the available
|
|
|
|
// variations.
|
|
|
|
bool mCheckedForOpszAxis;
|
|
|
|
bool mHasOpszAxis;
|
|
|
|
gfxFontVariationAxis mOpszAxis;
|
|
|
|
float mAdjustedDefaultOpsz;
|
|
|
|
|
2015-09-07 10:01:59 +03:00
|
|
|
nsTHashtable<nsUint32HashKey> mAvailableTables;
|
2017-04-07 00:41:02 +03:00
|
|
|
|
2017-10-18 21:22:09 +03:00
|
|
|
mozilla::ThreadSafeWeakPtr<mozilla::gfx::UnscaledFontMac> mUnscaledFont;
|
2009-08-16 17:52:12 +04:00
|
|
|
};
|
|
|
|
|
2020-03-10 18:00:56 +03:00
|
|
|
class gfxMacPlatformFontList final : public gfxPlatformFontList {
|
2020-03-09 15:27:45 +03:00
|
|
|
using FontFamilyListEntry = mozilla::dom::SystemFontListEntry;
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
public:
|
|
|
|
static gfxMacPlatformFontList* PlatformFontList() {
|
2009-10-07 18:13:40 +04:00
|
|
|
return static_cast<gfxMacPlatformFontList*>(sPlatformFontList);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
gfxFontFamily* CreateFontFamily(const nsACString& aName,
|
|
|
|
FontVisibility aVisibility) const override;
|
2017-08-01 13:25:35 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontEntry* LookupLocalFont(const nsACString& aFontName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry,
|
|
|
|
SlantStyleRange aStyleForEntry) override;
|
2015-10-19 05:16:43 +03:00
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontEntry* MakePlatformFont(const nsACString& aFontName,
|
2018-04-25 09:18:23 +03:00
|
|
|
WeightRange aWeightForEntry,
|
|
|
|
StretchRange aStretchForEntry,
|
|
|
|
SlantStyleRange aStyleForEntry,
|
2015-10-08 09:04:08 +03:00
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength) override;
|
|
|
|
|
2019-04-27 18:37:58 +03:00
|
|
|
bool FindAndAddFamilies(mozilla::StyleGenericFontFamily aGeneric,
|
|
|
|
const nsACString& 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-10-08 09:04:08 +03:00
|
|
|
|
|
|
|
// lookup the system font for a particular system font type and set
|
|
|
|
// the name and style characteristics
|
|
|
|
void LookupSystemFont(mozilla::LookAndFeel::FontID aSystemFontID,
|
2019-02-08 16:22:11 +03:00
|
|
|
nsACString& aSystemFontName, gfxFontStyle& aFontStyle);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2016-11-15 16:58:29 +03:00
|
|
|
// Values for the entryType field in FontFamilyListEntry records passed
|
|
|
|
// from chrome to content process.
|
|
|
|
enum FontFamilyEntryType {
|
|
|
|
kStandardFontFamily = 0, // a standard installed font family
|
2020-04-02 15:36:24 +03:00
|
|
|
kTextSizeSystemFontFamily = 1, // name of 'system' font at text sizes
|
|
|
|
kDisplaySizeSystemFontFamily = 2 // 'system' font at display sizes
|
2016-11-15 16:58:29 +03:00
|
|
|
};
|
2020-03-09 15:27:45 +03:00
|
|
|
void ReadSystemFontList(nsTArray<FontFamilyListEntry>* aList);
|
2016-11-15 16:58:29 +03:00
|
|
|
|
2016-08-23 03:06:07 +03:00
|
|
|
protected:
|
2019-04-01 17:33:34 +03:00
|
|
|
FontFamily GetDefaultFontForPlatform(const gfxFontStyle* aStyle) override;
|
2016-08-23 03:06:07 +03:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
private:
|
|
|
|
friend class gfxPlatformMac;
|
|
|
|
|
|
|
|
gfxMacPlatformFontList();
|
2012-03-09 06:05:47 +04:00
|
|
|
virtual ~gfxMacPlatformFontList();
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
// initialize font lists
|
2017-01-18 23:38:04 +03:00
|
|
|
nsresult InitFontListForPlatform() override;
|
2019-04-27 18:38:26 +03:00
|
|
|
void InitSharedFontListForPlatform() override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
// special case font faces treated as font families (set via prefs)
|
|
|
|
void InitSingleFaceList();
|
2019-06-26 21:58:48 +03:00
|
|
|
void InitAliasesForSingleFaceList();
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
// initialize system fonts
|
2016-07-04 22:13:34 +03:00
|
|
|
void InitSystemFontNames();
|
2015-10-08 09:04:08 +03:00
|
|
|
|
|
|
|
// helper function to lookup in both hidden system fonts and normal fonts
|
2018-09-12 22:34:57 +03:00
|
|
|
gfxFontFamily* FindSystemFontFamily(const nsACString& aFamily);
|
2015-10-08 09:04:08 +03:00
|
|
|
|
2020-04-02 04:38:21 +03:00
|
|
|
FontVisibility GetVisibilityForFamily(const nsACString& aName) const;
|
|
|
|
|
2017-01-18 23:38:04 +03:00
|
|
|
static void RegisteredFontsChangedNotificationCallback(
|
|
|
|
CFNotificationCenterRef center, void* observer, CFStringRef name,
|
|
|
|
const void* object, CFDictionaryRef userInfo);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2017-07-13 11:40:33 +03:00
|
|
|
// attempt to use platform-specific fallback for the given character
|
|
|
|
// return null if no usable result found
|
2019-04-01 17:33:34 +03:00
|
|
|
gfxFontEntry* PlatformGlobalFontFallback(const uint32_t aCh,
|
|
|
|
Script aRunScript,
|
|
|
|
const gfxFontStyle* aMatchStyle,
|
2020-05-08 00:10:46 +03:00
|
|
|
FontFamily& aMatchedFamily) override;
|
2012-03-09 06:05:47 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
bool UsesSystemFallback() override { return true; }
|
2012-03-09 06:05:47 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
already_AddRefed<FontInfoData> CreateFontInfoData() override;
|
2014-01-29 11:39:01 +04:00
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
// Add the specified family to mFontFamilies.
|
2015-09-03 20:44:43 +03:00
|
|
|
// Ideally we'd use NSString* instead of CFStringRef here, but this header
|
|
|
|
// file is included in .cpp files, so we can't use objective C classes here.
|
|
|
|
// But CFStringRef and NSString* are the same thing anyway (they're
|
|
|
|
// toll-free bridged).
|
|
|
|
void AddFamily(CFStringRef aFamily);
|
|
|
|
|
2020-04-02 15:36:24 +03:00
|
|
|
void AddFamily(const nsACString& aFamilyName, FontVisibility aVisibility);
|
2016-11-15 16:58:29 +03:00
|
|
|
|
2017-08-24 11:33:38 +03:00
|
|
|
void ActivateFontsFromDir(nsIFile* aDir);
|
|
|
|
|
2019-04-27 18:38:26 +03:00
|
|
|
gfxFontEntry* CreateFontEntry(
|
|
|
|
mozilla::fontlist::Face* aFace,
|
|
|
|
const mozilla::fontlist::Family* aFamily) override;
|
|
|
|
|
|
|
|
void GetFacesInitDataForFamily(
|
|
|
|
const mozilla::fontlist::Family* aFamily,
|
|
|
|
nsTArray<mozilla::fontlist::Face::InitData>& aFaces) const override;
|
|
|
|
|
|
|
|
void ReadFaceNamesForFamily(mozilla::fontlist::Family* aFamily,
|
|
|
|
bool aNeedFullnamePostscriptNames) override;
|
|
|
|
|
2014-05-29 16:00:55 +04:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
void ActivateBundledFonts();
|
|
|
|
#endif
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
enum { kATSGenerationInitial = -1 };
|
2012-03-09 06:05:47 +04:00
|
|
|
|
|
|
|
// default font for use with system-wide font fallback
|
|
|
|
CTFontRef mDefaultFont;
|
2015-10-08 09:04:08 +03:00
|
|
|
|
|
|
|
// font families that -apple-system maps to
|
|
|
|
// Pre-10.11 this was always a single font family, such as Lucida Grande
|
|
|
|
// or Helvetica Neue. For OSX 10.11, Apple uses pair of families
|
|
|
|
// for the UI, one for text sizes and another for display sizes
|
|
|
|
bool mUseSizeSensitiveSystemFont;
|
2018-09-12 22:34:57 +03:00
|
|
|
nsCString mSystemTextFontFamilyName;
|
|
|
|
nsCString mSystemDisplayFontFamilyName; // only used on OSX 10.11
|
2009-08-16 17:52:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* gfxMacPlatformFontList_H_ */
|