2009-08-16 17:52:12 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
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>
|
|
|
|
|
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
|
|
|
|
|
|
|
class gfxMacPlatformFontList;
|
|
|
|
|
|
|
|
// a single member of a font family (i.e. a single face, such as Times Italic)
|
|
|
|
class MacOSFontEntry : public gfxFontEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
friend class gfxMacPlatformFontList;
|
|
|
|
|
2012-11-19 14:22:10 +04:00
|
|
|
MacOSFontEntry(const nsAString& aPostscriptName, int32_t aWeight,
|
2013-01-04 18:01:44 +04:00
|
|
|
bool aIsStandardFace = false);
|
2012-11-19 14:22:10 +04:00
|
|
|
|
|
|
|
// for use with data fonts
|
|
|
|
MacOSFontEntry(const nsAString& aPostscriptName, CGFontRef aFontRef,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint16_t aWeight, uint16_t aStretch, uint8_t aStyle,
|
2014-09-08 11:23:20 +04:00
|
|
|
bool aIsDataUserFont, bool aIsLocal);
|
2012-11-19 14:22:10 +04:00
|
|
|
|
2011-06-24 21:55:27 +04:00
|
|
|
virtual ~MacOSFontEntry() {
|
|
|
|
::CGFontRelease(mFontRef);
|
|
|
|
}
|
|
|
|
|
2012-11-19 14:22:10 +04:00
|
|
|
virtual CGFontRef GetFontRef();
|
2011-06-24 21:55:27 +04:00
|
|
|
|
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
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual hb_blob_t *GetFontTable(uint32_t aTag) override;
|
2012-11-19 14:22:10 +04:00
|
|
|
|
2013-10-15 06:19:47 +04:00
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
2015-03-21 19:28:04 +03:00
|
|
|
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
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsCFF();
|
2010-10-07 11:59:16 +04:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
protected:
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual gfxFont* CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold) override;
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual 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
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mFontRefInitialized;
|
|
|
|
bool mRequiresAAT;
|
|
|
|
bool mIsCFF;
|
|
|
|
bool mIsCFFInitialized;
|
2015-09-07 10:01:59 +03:00
|
|
|
nsTHashtable<nsUint32HashKey> mAvailableTables;
|
2009-08-16 17:52:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class gfxMacPlatformFontList : public gfxPlatformFontList {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t AppleWeightToCSSWeight(int32_t aAppleWeight);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
gfxFontFamily* GetDefaultFont(const gfxFontStyle* aStyle) override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
bool GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName) override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
gfxFontEntry* LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle) override;
|
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
gfxFontEntry* MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2015-10-08 09:04:08 +03:00
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength) override;
|
|
|
|
|
|
|
|
gfxFontFamily* FindFamily(const nsAString& aFamily,
|
2015-11-20 16:01:12 +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,
|
|
|
|
nsAString& aSystemFontName,
|
|
|
|
gfxFontStyle &aFontStyle,
|
|
|
|
float aDevPixPerCSSPixel);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2016-01-15 10:33:51 +03:00
|
|
|
virtual void
|
|
|
|
AppendLinkedSystemFamilies(nsIAtom* aLanguage,
|
|
|
|
nsTArray<gfxFontFamily*>& aFamilyList) override;
|
|
|
|
|
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
|
2015-10-08 09:04:08 +03:00
|
|
|
nsresult InitFontList() override;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
// special case font faces treated as font families (set via prefs)
|
|
|
|
void InitSingleFaceList();
|
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
// initialize system fonts
|
|
|
|
void InitSystemFonts();
|
|
|
|
|
2016-01-15 10:33:51 +03:00
|
|
|
// helper function for looking up font cascades
|
|
|
|
void LookupFontCascadeForLang(const nsACString& aLang,
|
|
|
|
nsTArray<gfxFontFamily*>& aCascadeList);
|
|
|
|
|
2015-10-08 09:04:08 +03:00
|
|
|
// helper function to lookup in both hidden system fonts and normal fonts
|
|
|
|
gfxFontFamily* FindSystemFontFamily(const nsAString& aFamily);
|
|
|
|
|
2013-10-16 08:53:52 +04:00
|
|
|
static void RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center,
|
|
|
|
void *observer,
|
|
|
|
CFStringRef name,
|
|
|
|
const void *object,
|
|
|
|
CFDictionaryRef userInfo);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2012-03-09 06:05:47 +04:00
|
|
|
// search fonts system-wide for a given character, null otherwise
|
2015-10-08 09:04:08 +03:00
|
|
|
gfxFontEntry* GlobalFontFallback(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
|
|
|
const gfxFontStyle* aMatchStyle,
|
|
|
|
uint32_t& aCmapCount,
|
|
|
|
gfxFontFamily** 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
|
|
|
|
2015-09-03 20:44:43 +03:00
|
|
|
// Add the specified family to mSystemFontFamilies or mFontFamilies.
|
|
|
|
// 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);
|
|
|
|
|
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
|
|
|
|
|
|
|
// hidden system fonts used within UI elements, there may be a whole set
|
|
|
|
// for different locales (e.g. .Helvetica Neue UI, .SF NS Text)
|
|
|
|
FontFamilyTable mSystemFontFamilies;
|
|
|
|
|
|
|
|
// 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;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontFamily> mSystemTextFontFamily;
|
|
|
|
RefPtr<gfxFontFamily> mSystemDisplayFontFamily; // only used on OSX 10.11
|
2016-01-15 10:33:51 +03:00
|
|
|
|
|
|
|
// system font cascade - under OSX, the system font is effectively
|
|
|
|
// not a single family but a fontlist with the Latin font at the end
|
|
|
|
// of the list (e.g. Lucida Grande, Helevetica Neue, San Francisco)
|
|
|
|
|
|
|
|
// most languages use a common default set of choices matching lang=en
|
|
|
|
PrefFontList mDefaultCascadeFamilies;
|
|
|
|
|
|
|
|
// for languages where the fontlist doesn't match the default list
|
|
|
|
// (e.g. zh-TW will prioritize the traditional Chinese font over the
|
|
|
|
// Japanese font)
|
|
|
|
nsBaseHashtable<nsCStringHashKey,
|
|
|
|
nsAutoPtr<PrefFontList>,
|
|
|
|
PrefFontList*> mNonDefaultCascadeFamilies;
|
2009-08-16 17:52:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* gfxMacPlatformFontList_H_ */
|