2009-08-16 13:52:12 +00:00
|
|
|
/* -*- Mode: ObjC; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: BSD
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006-2009 Mozilla Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
|
|
|
* John Daggett <jdaggett@mozilla.com>
|
|
|
|
* Jonathan Kew <jfkthame@gmail.com>
|
2009-10-12 23:43:43 +00:00
|
|
|
*
|
2009-08-16 13:52:12 +00:00
|
|
|
* Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
|
|
|
|
* its contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
|
|
|
|
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2011-01-21 16:44:33 +00:00
|
|
|
#ifdef MOZ_LOGGING
|
|
|
|
#define FORCE_PR_LOG /* Allow logging in the release build */
|
|
|
|
#endif
|
|
|
|
#include "prlog.h"
|
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
#import <AppKit/AppKit.h>
|
|
|
|
|
|
|
|
#include "gfxPlatformMac.h"
|
|
|
|
#include "gfxMacPlatformFontList.h"
|
2010-03-10 12:46:41 +00:00
|
|
|
#include "gfxMacFont.h"
|
2009-08-16 13:52:12 +00:00
|
|
|
#include "gfxUserFontSet.h"
|
2012-05-23 13:15:43 +00:00
|
|
|
#include "harfbuzz/hb.h"
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
|
|
|
#include "nsDirectoryServiceDefs.h"
|
2014-05-29 12:00:55 +00:00
|
|
|
#include "nsAppDirectoryServiceDefs.h"
|
2009-08-16 13:52:12 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2012-03-09 02:05:47 +00:00
|
|
|
#include "nsCharTraits.h"
|
2014-03-28 05:40:42 +00:00
|
|
|
#include "nsCocoaFeatures.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "gfxFontConstants.h"
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-12-21 09:48:39 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-07-27 06:42:53 +00:00
|
|
|
#include "mozilla/Telemetry.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2011-07-27 06:42:53 +00:00
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <time.h>
|
|
|
|
|
2011-07-27 06:42:53 +00:00
|
|
|
using namespace mozilla;
|
|
|
|
|
2010-03-09 16:37:56 +00:00
|
|
|
class nsAutoreleasePool {
|
|
|
|
public:
|
|
|
|
nsAutoreleasePool()
|
|
|
|
{
|
|
|
|
mLocalPool = [[NSAutoreleasePool alloc] init];
|
|
|
|
}
|
|
|
|
~nsAutoreleasePool()
|
|
|
|
{
|
|
|
|
[mLocalPool release];
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
NSAutoreleasePool *mLocalPool;
|
|
|
|
};
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// indexes into the NSArray objects that the Cocoa font manager returns
|
|
|
|
// as the available members of a family
|
|
|
|
#define INDEX_FONT_POSTSCRIPT_NAME 0
|
|
|
|
#define INDEX_FONT_FACE_NAME 1
|
|
|
|
#define INDEX_FONT_WEIGHT 2
|
|
|
|
#define INDEX_FONT_TRAITS 3
|
|
|
|
|
|
|
|
static const int kAppleMaxWeight = 14;
|
|
|
|
static const int kAppleExtraLightWeight = 3;
|
|
|
|
static const int kAppleUltraLightWeight = 2;
|
|
|
|
|
|
|
|
static const int gAppleWeightToCSSWeight[] = {
|
|
|
|
0,
|
2009-10-12 23:43:43 +00:00
|
|
|
1, // 1.
|
2009-08-16 13:52:12 +00:00
|
|
|
1, // 2. W1, ultralight
|
|
|
|
2, // 3. W2, extralight
|
|
|
|
3, // 4. W3, light
|
|
|
|
4, // 5. W4, semilight
|
|
|
|
5, // 6. W5, medium
|
|
|
|
6, // 7.
|
|
|
|
6, // 8. W6, semibold
|
|
|
|
7, // 9. W7, bold
|
|
|
|
8, // 10. W8, extrabold
|
|
|
|
8, // 11.
|
|
|
|
9, // 12. W9, ultrabold
|
|
|
|
9, // 13
|
|
|
|
9 // 14
|
|
|
|
};
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
// cache Cocoa's "shared font manager" for performance
|
|
|
|
static NSFontManager *sFontManager;
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
static void GetStringForNSString(const NSString *aSrc, nsAString& aDist)
|
|
|
|
{
|
|
|
|
aDist.SetLength([aSrc length]);
|
2013-10-10 16:59:40 +00:00
|
|
|
[aSrc getCharacters:reinterpret_cast<unichar*>(aDist.BeginWriting())];
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static NSString* GetNSStringForString(const nsAString& aSrc)
|
|
|
|
{
|
2013-10-10 16:59:40 +00:00
|
|
|
return [NSString stringWithCharacters:reinterpret_cast<const unichar*>(aSrc.BeginReading())
|
|
|
|
length:aSrc.Length()];
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
|
2011-01-21 16:44:33 +00:00
|
|
|
#define LOG_FONTLIST(args) PR_LOG(gfxPlatform::GetLog(eGfxLog_fontlist), \
|
|
|
|
PR_LOG_DEBUG, args)
|
|
|
|
#define LOG_FONTLIST_ENABLED() PR_LOG_TEST( \
|
|
|
|
gfxPlatform::GetLog(eGfxLog_fontlist), \
|
|
|
|
PR_LOG_DEBUG)
|
2012-03-09 02:05:14 +00:00
|
|
|
#define LOG_CMAPDATA_ENABLED() PR_LOG_TEST( \
|
|
|
|
gfxPlatform::GetLog(eGfxLog_cmapdata), \
|
|
|
|
PR_LOG_DEBUG)
|
2011-01-21 16:44:33 +00:00
|
|
|
|
|
|
|
#endif // PR_LOGGING
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
#pragma mark-
|
|
|
|
|
2012-05-23 13:15:43 +00:00
|
|
|
// Complex scripts will not render correctly unless appropriate AAT or OT
|
|
|
|
// layout tables are present.
|
|
|
|
// For OpenType, we also check that the GSUB table supports the relevant
|
|
|
|
// script tag, to avoid using things like Arial Unicode MS for Lao (it has
|
|
|
|
// the characters, but lacks OpenType support).
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2012-05-23 13:15:43 +00:00
|
|
|
// TODO: consider whether we should move this to gfxFontEntry and do similar
|
|
|
|
// cmap-masking on other platforms to avoid using fonts that won't shape
|
|
|
|
// properly.
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
nsresult
|
2014-01-29 07:39:01 +00:00
|
|
|
MacOSFontEntry::ReadCMAP(FontInfoData *aFontInfoData)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
|
|
|
// attempt this once, if errors occur leave a blank cmap
|
2012-04-18 23:59:43 +00:00
|
|
|
if (mCharacterMap) {
|
2009-08-16 13:52:12 +00:00
|
|
|
return NS_OK;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
2012-04-18 23:59:43 +00:00
|
|
|
|
2014-01-29 07:39:01 +00:00
|
|
|
nsRefPtr<gfxCharacterMap> charmap;
|
2013-05-21 04:25:47 +00:00
|
|
|
nsresult rv;
|
2014-01-29 07:39:01 +00:00
|
|
|
bool symbolFont;
|
2013-05-21 04:25:47 +00:00
|
|
|
|
2014-01-29 07:39:01 +00:00
|
|
|
if (aFontInfoData && (charmap = GetCMAPFromFontInfo(aFontInfoData,
|
|
|
|
mUVSOffset,
|
|
|
|
symbolFont))) {
|
|
|
|
rv = NS_OK;
|
2013-05-21 04:25:47 +00:00
|
|
|
} else {
|
2014-01-29 07:39:01 +00:00
|
|
|
uint32_t kCMAP = TRUETYPE_TAG('c','m','a','p');
|
|
|
|
charmap = new gfxCharacterMap();
|
|
|
|
AutoTable cmapTable(this, kCMAP);
|
|
|
|
|
|
|
|
if (cmapTable) {
|
|
|
|
bool unicodeFont = false, symbolFont = false; // currently ignored
|
|
|
|
uint32_t cmapLen;
|
|
|
|
const uint8_t* cmapData =
|
|
|
|
reinterpret_cast<const uint8_t*>(hb_blob_get_data(cmapTable,
|
|
|
|
&cmapLen));
|
|
|
|
rv = gfxFontUtils::ReadCMAP(cmapData, cmapLen,
|
|
|
|
*charmap, mUVSOffset,
|
|
|
|
unicodeFont, symbolFont);
|
|
|
|
} else {
|
|
|
|
rv = NS_ERROR_NOT_AVAILABLE;
|
|
|
|
}
|
2013-05-16 16:29:20 +00:00
|
|
|
}
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2013-02-22 16:52:20 +00:00
|
|
|
if (NS_SUCCEEDED(rv) && !HasGraphiteTables()) {
|
2013-01-21 09:24:45 +00:00
|
|
|
// We assume a Graphite font knows what it's doing,
|
|
|
|
// and provides whatever shaping is needed for the
|
|
|
|
// characters it supports, so only check/clear the
|
|
|
|
// complex-script ranges for non-Graphite fonts
|
2013-02-22 16:52:20 +00:00
|
|
|
|
2012-04-18 23:59:43 +00:00
|
|
|
// for layout support, check for the presence of mort/morx and/or
|
|
|
|
// opentype layout tables
|
|
|
|
bool hasAATLayout = HasFontTable(TRUETYPE_TAG('m','o','r','x')) ||
|
2012-05-23 13:15:43 +00:00
|
|
|
HasFontTable(TRUETYPE_TAG('m','o','r','t'));
|
2012-04-18 23:59:43 +00:00
|
|
|
bool hasGSUB = HasFontTable(TRUETYPE_TAG('G','S','U','B'));
|
|
|
|
bool hasGPOS = HasFontTable(TRUETYPE_TAG('G','P','O','S'));
|
|
|
|
if (hasAATLayout && !(hasGSUB || hasGPOS)) {
|
|
|
|
mRequiresAAT = true; // prefer CoreText if font has no OTL tables
|
|
|
|
}
|
2012-05-23 13:15:43 +00:00
|
|
|
|
2014-05-05 18:59:55 +00:00
|
|
|
for (const ScriptRange* sr = gfxPlatformFontList::sComplexScriptRanges;
|
|
|
|
sr->rangeStart; sr++) {
|
2012-04-18 23:59:43 +00:00
|
|
|
// check to see if the cmap includes complex script codepoints
|
2014-05-05 18:59:55 +00:00
|
|
|
if (charmap->TestRange(sr->rangeStart, sr->rangeEnd)) {
|
2012-04-18 23:59:43 +00:00
|
|
|
if (hasAATLayout) {
|
|
|
|
// prefer CoreText for Apple's complex-script fonts,
|
|
|
|
// even if they also have some OpenType tables
|
|
|
|
// (e.g. Geeza Pro Bold on 10.6; see bug 614903)
|
|
|
|
mRequiresAAT = true;
|
2012-05-23 13:15:43 +00:00
|
|
|
// and don't mask off complex-script ranges, we assume
|
|
|
|
// the AAT tables will provide the necessary shaping
|
|
|
|
continue;
|
2012-04-18 23:59:43 +00:00
|
|
|
}
|
2012-05-23 13:15:43 +00:00
|
|
|
|
2012-10-22 07:47:01 +00:00
|
|
|
// We check for GSUB here, as GPOS alone would not be ok.
|
2014-05-05 18:59:55 +00:00
|
|
|
if (hasGSUB && SupportsScriptInGSUB(sr->tags)) {
|
2012-10-22 07:47:01 +00:00
|
|
|
continue;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
2012-05-23 13:15:43 +00:00
|
|
|
|
2014-05-05 18:59:55 +00:00
|
|
|
charmap->ClearRange(sr->rangeStart, sr->rangeEnd);
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-18 23:59:43 +00:00
|
|
|
mHasCmapTable = NS_SUCCEEDED(rv);
|
|
|
|
if (mHasCmapTable) {
|
|
|
|
gfxPlatformFontList *pfl = gfxPlatformFontList::PlatformFontList();
|
|
|
|
mCharacterMap = pfl->FindCharMap(charmap);
|
|
|
|
} else {
|
|
|
|
// if error occurred, initialize to null cmap
|
|
|
|
mCharacterMap = new gfxCharacterMap();
|
|
|
|
}
|
|
|
|
|
2011-01-21 16:44:33 +00:00
|
|
|
#ifdef PR_LOGGING
|
2012-04-18 23:59:43 +00:00
|
|
|
LOG_FONTLIST(("(fontlist-cmap) name: %s, size: %d hash: %8.8x%s\n",
|
2011-01-21 16:44:33 +00:00
|
|
|
NS_ConvertUTF16toUTF8(mName).get(),
|
2012-04-18 23:59:43 +00:00
|
|
|
charmap->SizeOfIncludingThis(moz_malloc_size_of),
|
|
|
|
charmap->mHash, mCharacterMap == charmap ? " new" : ""));
|
2012-03-09 02:05:14 +00:00
|
|
|
if (LOG_CMAPDATA_ENABLED()) {
|
|
|
|
char prefix[256];
|
|
|
|
sprintf(prefix, "(cmapdata) name: %.220s",
|
|
|
|
NS_ConvertUTF16toUTF8(mName).get());
|
2012-04-18 23:59:43 +00:00
|
|
|
charmap->Dump(prefix, eGfxLog_cmapdata);
|
2012-03-09 02:05:14 +00:00
|
|
|
}
|
2011-01-21 16:44:33 +00:00
|
|
|
#endif
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
gfxFont*
|
2011-09-29 06:19:26 +00:00
|
|
|
MacOSFontEntry::CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold)
|
2011-06-24 17:55:27 +00:00
|
|
|
{
|
|
|
|
return new gfxMacFont(this, aFontStyle, aNeedsBold);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2011-06-24 17:55:27 +00:00
|
|
|
MacOSFontEntry::IsCFF()
|
|
|
|
{
|
|
|
|
if (!mIsCFFInitialized) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsCFFInitialized = true;
|
2011-06-24 17:55:27 +00:00
|
|
|
mIsCFF = HasFontTable(TRUETYPE_TAG('C','F','F',' '));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mIsCFF;
|
|
|
|
}
|
|
|
|
|
2012-11-19 10:22:10 +00:00
|
|
|
MacOSFontEntry::MacOSFontEntry(const nsAString& aPostscriptName,
|
|
|
|
int32_t aWeight,
|
|
|
|
bool aIsStandardFace)
|
2013-01-04 14:01:44 +00:00
|
|
|
: gfxFontEntry(aPostscriptName, aIsStandardFace),
|
2012-11-19 10:22:10 +00:00
|
|
|
mFontRef(NULL),
|
|
|
|
mFontRefInitialized(false),
|
|
|
|
mRequiresAAT(false),
|
|
|
|
mIsCFF(false),
|
|
|
|
mIsCFFInitialized(false)
|
2009-10-07 15:26:58 +00:00
|
|
|
{
|
2012-11-19 10:22:10 +00:00
|
|
|
mWeight = aWeight;
|
2009-10-07 15:26:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 10:22:10 +00:00
|
|
|
MacOSFontEntry::MacOSFontEntry(const nsAString& aPostscriptName,
|
|
|
|
CGFontRef aFontRef,
|
|
|
|
uint16_t aWeight, uint16_t aStretch,
|
|
|
|
uint32_t aItalicStyle,
|
|
|
|
bool aIsUserFont, bool aIsLocal)
|
2013-01-04 14:01:44 +00:00
|
|
|
: gfxFontEntry(aPostscriptName, false),
|
2012-11-19 10:22:10 +00:00
|
|
|
mFontRef(NULL),
|
|
|
|
mFontRefInitialized(false),
|
|
|
|
mRequiresAAT(false),
|
|
|
|
mIsCFF(false),
|
|
|
|
mIsCFFInitialized(false)
|
2010-10-07 07:59:16 +00:00
|
|
|
{
|
2011-06-24 17:55:27 +00:00
|
|
|
mFontRef = aFontRef;
|
2011-10-17 14:59:28 +00:00
|
|
|
mFontRefInitialized = true;
|
2011-06-24 17:55:27 +00:00
|
|
|
::CFRetain(mFontRef);
|
|
|
|
|
|
|
|
mWeight = aWeight;
|
|
|
|
mStretch = aStretch;
|
2011-10-17 14:59:28 +00:00
|
|
|
mFixedPitch = false; // xxx - do we need this for downloaded fonts?
|
2012-03-15 09:04:46 +00:00
|
|
|
mItalic = (aItalicStyle & (NS_FONT_STYLE_ITALIC | NS_FONT_STYLE_OBLIQUE)) != 0;
|
2011-06-24 17:55:27 +00:00
|
|
|
mIsUserFont = aIsUserFont;
|
|
|
|
mIsLocalUserFont = aIsLocal;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGFontRef
|
2012-11-19 10:22:10 +00:00
|
|
|
MacOSFontEntry::GetFontRef()
|
2011-06-24 17:55:27 +00:00
|
|
|
{
|
|
|
|
if (!mFontRefInitialized) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mFontRefInitialized = true;
|
2011-06-24 17:55:27 +00:00
|
|
|
NSString *psname = GetNSStringForString(mName);
|
|
|
|
mFontRef = ::CGFontCreateWithFontName(CFStringRef(psname));
|
2010-10-07 07:59:16 +00:00
|
|
|
}
|
2011-06-24 17:55:27 +00:00
|
|
|
return mFontRef;
|
|
|
|
}
|
2010-10-07 07:59:16 +00:00
|
|
|
|
2013-05-16 16:29:20 +00:00
|
|
|
/*static*/ void
|
|
|
|
MacOSFontEntry::DestroyBlobFunc(void* aUserData)
|
2011-06-24 17:55:27 +00:00
|
|
|
{
|
2013-05-16 16:29:20 +00:00
|
|
|
::CFRelease((CFDataRef)aUserData);
|
|
|
|
}
|
2011-06-24 17:55:27 +00:00
|
|
|
|
2013-05-16 16:29:20 +00:00
|
|
|
hb_blob_t *
|
|
|
|
MacOSFontEntry::GetFontTable(uint32_t aTag)
|
|
|
|
{
|
2011-06-24 17:55:27 +00:00
|
|
|
CGFontRef fontRef = GetFontRef();
|
|
|
|
if (!fontRef) {
|
2013-05-16 16:29:20 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:29:20 +00:00
|
|
|
CFDataRef dataRef = ::CGFontCopyTableForTag(fontRef, aTag);
|
|
|
|
if (dataRef) {
|
|
|
|
return hb_blob_create((const char*)::CFDataGetBytePtr(dataRef),
|
|
|
|
::CFDataGetLength(dataRef),
|
|
|
|
HB_MEMORY_MODE_READONLY,
|
|
|
|
(void*)dataRef, DestroyBlobFunc);
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
|
|
|
|
2013-05-16 16:29:20 +00:00
|
|
|
return nullptr;
|
2010-10-07 07:59:16 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-11-19 10:22:10 +00:00
|
|
|
MacOSFontEntry::HasFontTable(uint32_t aTableTag)
|
2011-06-24 17:55:27 +00:00
|
|
|
{
|
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
|
|
|
CGFontRef fontRef = GetFontRef();
|
|
|
|
if (!fontRef) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFDataRef tableData = ::CGFontCopyTableForTag(fontRef, aTableTag);
|
|
|
|
if (!tableData) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
::CFRelease(tableData);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
2009-09-28 10:25:22 +00:00
|
|
|
|
2012-03-27 21:38:39 +00:00
|
|
|
void
|
2013-10-15 02:19:47 +00:00
|
|
|
MacOSFontEntry::AddSizeOfIncludingThis(MallocSizeOf aMallocSizeOf,
|
|
|
|
FontListSizes* aSizes) const
|
2012-03-27 21:38:39 +00:00
|
|
|
{
|
|
|
|
aSizes->mFontListSize += aMallocSizeOf(this);
|
2013-10-15 02:19:47 +00:00
|
|
|
AddSizeOfExcludingThis(aMallocSizeOf, aSizes);
|
2012-03-27 21:38:39 +00:00
|
|
|
}
|
|
|
|
|
2009-09-28 10:25:22 +00:00
|
|
|
/* gfxMacFontFamily */
|
|
|
|
#pragma mark-
|
|
|
|
|
|
|
|
class gfxMacFontFamily : public gfxFontFamily
|
|
|
|
{
|
|
|
|
public:
|
2014-08-08 01:17:30 +00:00
|
|
|
explicit gfxMacFontFamily(nsAString& aName) :
|
2009-09-28 10:25:22 +00:00
|
|
|
gfxFontFamily(aName)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~gfxMacFontFamily() {}
|
|
|
|
|
|
|
|
virtual void LocalizedName(nsAString& aLocalizedName);
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2014-01-29 07:39:01 +00:00
|
|
|
virtual void FindStyleVariations(FontInfoData *aFontInfoData = nullptr);
|
2009-09-28 10:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxMacFontFamily::LocalizedName(nsAString& aLocalizedName)
|
|
|
|
{
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-09-28 10:25:22 +00:00
|
|
|
if (!HasOtherFamilyNames()) {
|
|
|
|
aLocalizedName = mName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *family = GetNSStringForString(mName);
|
2009-10-12 23:43:43 +00:00
|
|
|
NSString *localized = [sFontManager
|
2009-09-28 10:25:22 +00:00
|
|
|
localizedNameForFamily:family
|
|
|
|
face:nil];
|
|
|
|
|
|
|
|
if (localized) {
|
|
|
|
GetStringForNSString(localized, aLocalizedName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// failed to get localized name, just use the canonical one
|
|
|
|
aLocalizedName = mName;
|
|
|
|
}
|
|
|
|
|
2014-03-20 09:46:42 +00:00
|
|
|
// Return the CSS weight value to use for the given face, overriding what
|
|
|
|
// AppKit gives us (used to adjust families with bad weight values, see
|
|
|
|
// bug 931426).
|
|
|
|
// A return value of 0 indicates no override - use the existing weight.
|
|
|
|
static inline int
|
|
|
|
GetWeightOverride(const nsAString& aPSName)
|
|
|
|
{
|
|
|
|
nsAutoCString prefName("font.weight-override.");
|
|
|
|
// The PostScript name is required to be ASCII; if it's not, the font is
|
|
|
|
// broken anyway, so we really don't care that this is lossy.
|
|
|
|
LossyAppendUTF16toASCII(aPSName, prefName);
|
|
|
|
return Preferences::GetInt(prefName.get(), 0);
|
|
|
|
}
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
void
|
2014-01-29 07:39:01 +00:00
|
|
|
gfxMacFontFamily::FindStyleVariations(FontInfoData *aFontInfoData)
|
2009-10-12 23:43:43 +00:00
|
|
|
{
|
|
|
|
if (mHasStyles)
|
|
|
|
return;
|
|
|
|
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
NSString *family = GetNSStringForString(mName);
|
|
|
|
|
|
|
|
// create a font entry for each face
|
|
|
|
NSArray *fontfaces = [sFontManager
|
|
|
|
availableMembersOfFontFamily:family]; // returns an array of [psname, style name, weight, traits] elements, goofy api
|
|
|
|
int faceCount = [fontfaces count];
|
|
|
|
int faceIndex;
|
|
|
|
|
|
|
|
for (faceIndex = 0; faceIndex < faceCount; faceIndex++) {
|
|
|
|
NSArray *face = [fontfaces objectAtIndex:faceIndex];
|
|
|
|
NSString *psname = [face objectAtIndex:INDEX_FONT_POSTSCRIPT_NAME];
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t appKitWeight = [[face objectAtIndex:INDEX_FONT_WEIGHT] unsignedIntValue];
|
|
|
|
uint32_t macTraits = [[face objectAtIndex:INDEX_FONT_TRAITS] unsignedIntValue];
|
2009-10-12 23:43:43 +00:00
|
|
|
NSString *facename = [face objectAtIndex:INDEX_FONT_FACE_NAME];
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isStandardFace = false;
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2013-08-06 21:52:52 +00:00
|
|
|
if (appKitWeight == kAppleExtraLightWeight) {
|
2009-10-12 23:43:43 +00:00
|
|
|
// if the facename contains UltraLight, set the weight to the ultralight weight value
|
|
|
|
NSRange range = [facename rangeOfString:@"ultralight" options:NSCaseInsensitiveSearch];
|
|
|
|
if (range.location != NSNotFound) {
|
|
|
|
appKitWeight = kAppleUltraLightWeight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// make a nsString
|
|
|
|
nsAutoString postscriptFontName;
|
|
|
|
GetStringForNSString(psname, postscriptFontName);
|
|
|
|
|
2014-03-20 09:46:42 +00:00
|
|
|
int32_t cssWeight = GetWeightOverride(postscriptFontName);
|
|
|
|
if (cssWeight) {
|
|
|
|
// scale down and clamp, to get a value from 1..9
|
|
|
|
cssWeight = ((cssWeight + 50) / 100);
|
|
|
|
cssWeight = std::max(1, std::min(cssWeight, 9));
|
|
|
|
} else {
|
|
|
|
cssWeight =
|
|
|
|
gfxMacPlatformFontList::AppleWeightToCSSWeight(appKitWeight);
|
|
|
|
}
|
|
|
|
cssWeight *= 100; // scale up to CSS values
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
if ([facename isEqualToString:@"Regular"] ||
|
|
|
|
[facename isEqualToString:@"Bold"] ||
|
|
|
|
[facename isEqualToString:@"Italic"] ||
|
|
|
|
[facename isEqualToString:@"Oblique"] ||
|
|
|
|
[facename isEqualToString:@"Bold Italic"] ||
|
|
|
|
[facename isEqualToString:@"Bold Oblique"])
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
isStandardFace = true;
|
2009-10-12 23:43:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// create a font entry
|
2012-11-19 10:01:43 +00:00
|
|
|
MacOSFontEntry *fontEntry =
|
2013-01-04 14:01:44 +00:00
|
|
|
new MacOSFontEntry(postscriptFontName, cssWeight, isStandardFace);
|
2011-06-24 17:55:27 +00:00
|
|
|
if (!fontEntry) {
|
|
|
|
break;
|
|
|
|
}
|
2009-10-12 23:43:43 +00:00
|
|
|
|
|
|
|
// set additional properties based on the traits reported by Cocoa
|
|
|
|
if (macTraits & (NSCondensedFontMask | NSNarrowFontMask | NSCompressedFontMask)) {
|
|
|
|
fontEntry->mStretch = NS_FONT_STRETCH_CONDENSED;
|
|
|
|
} else if (macTraits & NSExpandedFontMask) {
|
|
|
|
fontEntry->mStretch = NS_FONT_STRETCH_EXPANDED;
|
|
|
|
}
|
2010-11-16 08:34:38 +00:00
|
|
|
// Cocoa fails to set the Italic traits bit for HelveticaLightItalic,
|
|
|
|
// at least (see bug 611855), so check for style name endings as well
|
|
|
|
if ((macTraits & NSItalicFontMask) ||
|
|
|
|
[facename hasSuffix:@"Italic"] ||
|
|
|
|
[facename hasSuffix:@"Oblique"])
|
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
fontEntry->mItalic = true;
|
2009-10-12 23:43:43 +00:00
|
|
|
}
|
|
|
|
if (macTraits & NSFixedPitchFontMask) {
|
2011-10-17 14:59:28 +00:00
|
|
|
fontEntry->mFixedPitch = true;
|
2009-10-12 23:43:43 +00:00
|
|
|
}
|
|
|
|
|
2009-10-07 14:13:40 +00:00
|
|
|
#ifdef PR_LOGGING
|
2011-01-21 16:44:33 +00:00
|
|
|
if (LOG_FONTLIST_ENABLED()) {
|
|
|
|
LOG_FONTLIST(("(fontlist) added (%s) to family (%s)"
|
2009-10-07 14:13:40 +00:00
|
|
|
" with style: %s weight: %d stretch: %d"
|
|
|
|
" (apple-weight: %d macTraits: %8.8x)",
|
|
|
|
NS_ConvertUTF16toUTF8(fontEntry->Name()).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(Name()).get(),
|
|
|
|
fontEntry->IsItalic() ? "italic" : "normal",
|
|
|
|
cssWeight, fontEntry->Stretch(),
|
|
|
|
appKitWeight, macTraits));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
// insert into font entry array of family
|
|
|
|
AddFontEntry(fontEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
SortAvailableFonts();
|
2011-10-17 14:59:28 +00:00
|
|
|
SetHasStyles(true);
|
2009-10-12 23:43:43 +00:00
|
|
|
|
|
|
|
if (mIsBadUnderlineFamily) {
|
|
|
|
SetBadUnderlineFonts();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-28 10:25:22 +00:00
|
|
|
|
|
|
|
/* gfxSingleFaceMacFontFamily */
|
|
|
|
#pragma mark-
|
|
|
|
|
|
|
|
class gfxSingleFaceMacFontFamily : public gfxFontFamily
|
|
|
|
{
|
|
|
|
public:
|
2014-08-08 01:17:30 +00:00
|
|
|
explicit gfxSingleFaceMacFontFamily(nsAString& aName) :
|
2009-09-28 10:25:22 +00:00
|
|
|
gfxFontFamily(aName)
|
2014-04-03 04:13:11 +00:00
|
|
|
{
|
|
|
|
mFaceNamesInitialized = true; // omit from face name lists
|
|
|
|
}
|
2009-09-28 10:25:22 +00:00
|
|
|
|
|
|
|
virtual ~gfxSingleFaceMacFontFamily() {}
|
|
|
|
|
|
|
|
virtual void LocalizedName(nsAString& aLocalizedName);
|
|
|
|
|
2010-01-29 01:41:25 +00:00
|
|
|
virtual void ReadOtherFamilyNames(gfxPlatformFontList *aPlatformFontList);
|
2009-09-28 10:25:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxSingleFaceMacFontFamily::LocalizedName(nsAString& aLocalizedName)
|
|
|
|
{
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-09-28 10:25:22 +00:00
|
|
|
if (!HasOtherFamilyNames()) {
|
|
|
|
aLocalizedName = mName;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry *fe = mAvailableFonts[0];
|
|
|
|
NSFont *font = [NSFont fontWithName:GetNSStringForString(fe->Name())
|
|
|
|
size:0.0];
|
|
|
|
if (font) {
|
|
|
|
NSString *localized = [font displayName];
|
|
|
|
if (localized) {
|
|
|
|
GetStringForNSString(localized, aLocalizedName);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// failed to get localized name, just use the canonical one
|
|
|
|
aLocalizedName = mName;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-01-29 01:41:25 +00:00
|
|
|
gfxSingleFaceMacFontFamily::ReadOtherFamilyNames(gfxPlatformFontList *aPlatformFontList)
|
2009-09-28 10:25:22 +00:00
|
|
|
{
|
2013-05-16 16:29:20 +00:00
|
|
|
if (mOtherFamilyNamesInitialized) {
|
2009-09-28 10:25:22 +00:00
|
|
|
return;
|
2013-05-16 16:29:20 +00:00
|
|
|
}
|
2009-09-28 10:25:22 +00:00
|
|
|
|
2010-01-29 01:41:25 +00:00
|
|
|
gfxFontEntry *fe = mAvailableFonts[0];
|
2013-05-16 16:29:20 +00:00
|
|
|
if (!fe) {
|
2010-01-29 01:41:25 +00:00
|
|
|
return;
|
2013-05-16 16:29:20 +00:00
|
|
|
}
|
2010-01-29 01:41:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint32_t kNAME = TRUETYPE_TAG('n','a','m','e');
|
2010-01-29 01:41:25 +00:00
|
|
|
|
2013-05-16 16:29:20 +00:00
|
|
|
gfxFontEntry::AutoTable nameTable(fe, kNAME);
|
|
|
|
if (!nameTable) {
|
2010-01-29 01:41:25 +00:00
|
|
|
return;
|
2013-05-16 16:29:20 +00:00
|
|
|
}
|
2010-01-29 01:41:25 +00:00
|
|
|
|
|
|
|
mHasOtherFamilyNames = ReadOtherFamilyNamesForFace(aPlatformFontList,
|
2013-05-16 16:29:20 +00:00
|
|
|
nameTable,
|
2011-10-17 14:59:28 +00:00
|
|
|
true);
|
2013-05-16 16:29:20 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
mOtherFamilyNamesInitialized = true;
|
2009-09-28 10:25:22 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
/* gfxMacPlatformFontList */
|
|
|
|
#pragma mark-
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
gfxMacPlatformFontList::gfxMacPlatformFontList() :
|
2013-10-16 04:53:52 +00:00
|
|
|
gfxPlatformFontList(false),
|
2012-07-30 14:20:58 +00:00
|
|
|
mDefaultFont(nullptr)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
2014-05-29 12:00:55 +00:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
ActivateBundledFonts();
|
|
|
|
#endif
|
|
|
|
|
2013-10-16 04:53:52 +00:00
|
|
|
::CFNotificationCenterAddObserver(::CFNotificationCenterGetLocalCenter(),
|
|
|
|
this,
|
|
|
|
RegisteredFontsChangedNotificationCallback,
|
|
|
|
kCTFontManagerRegisteredFontsChangedNotification,
|
|
|
|
0,
|
|
|
|
CFNotificationSuspensionBehaviorDeliverImmediately);
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
// cache this in a static variable so that MacOSFontFamily objects
|
|
|
|
// don't have to repeatedly look it up
|
|
|
|
sFontManager = [NSFontManager sharedFontManager];
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 02:05:47 +00:00
|
|
|
gfxMacPlatformFontList::~gfxMacPlatformFontList()
|
|
|
|
{
|
|
|
|
if (mDefaultFont) {
|
|
|
|
::CFRelease(mDefaultFont);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-08 11:02:27 +00:00
|
|
|
nsresult
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxMacPlatformFontList::InitFontList()
|
|
|
|
{
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2011-07-27 06:42:53 +00:00
|
|
|
Telemetry::AutoTimer<Telemetry::MAC_INITFONTLIST_TOTAL> timer;
|
|
|
|
|
2010-01-29 01:41:25 +00:00
|
|
|
// reset font lists
|
|
|
|
gfxPlatformFontList::InitFontList();
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// iterate over available families
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2014-01-29 07:39:00 +00:00
|
|
|
CFArrayRef familyNames = CTFontManagerCopyAvailableFontFamilyNames();
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2014-01-29 07:39:00 +00:00
|
|
|
// iterate over families
|
|
|
|
uint32_t i, numFamilies;
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2014-01-29 07:39:00 +00:00
|
|
|
numFamilies = CFArrayGetCount(familyNames);
|
|
|
|
for (i = 0; i < numFamilies; i++) {
|
|
|
|
CFStringRef family = (CFStringRef)CFArrayGetValueAtIndex(familyNames, i);
|
|
|
|
|
|
|
|
// CTFontManager includes weird internal family names and
|
|
|
|
// LastResort, skip over those
|
|
|
|
if (!family ||
|
|
|
|
::CFStringHasPrefix(family, CFSTR(".")) ||
|
|
|
|
CFStringCompare(family, CFSTR("LastResort"),
|
|
|
|
kCFCompareCaseInsensitive) == kCFCompareEqualTo) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoTArray<UniChar, 1024> buffer;
|
|
|
|
CFIndex len = ::CFStringGetLength(family);
|
|
|
|
buffer.SetLength(len+1);
|
|
|
|
::CFStringGetCharacters(family, ::CFRangeMake(0, len),
|
|
|
|
buffer.Elements());
|
|
|
|
buffer[len] = 0;
|
|
|
|
nsAutoString familyName(reinterpret_cast<char16_t*>(buffer.Elements()), len);
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// create a family entry
|
2014-01-29 07:39:00 +00:00
|
|
|
gfxFontFamily *familyEntry = new gfxMacFontFamily(familyName);
|
2009-08-16 13:52:12 +00:00
|
|
|
if (!familyEntry) break;
|
|
|
|
|
|
|
|
// add the family entry to the hash table
|
2014-01-29 07:39:00 +00:00
|
|
|
ToLowerCase(familyName);
|
|
|
|
mFontFamilies.Put(familyName, familyEntry);
|
2010-01-28 06:56:16 +00:00
|
|
|
|
|
|
|
// check the bad underline blacklist
|
2014-01-29 07:39:00 +00:00
|
|
|
if (mBadUnderlineFamilyNames.Contains(familyName))
|
2010-01-28 06:56:16 +00:00
|
|
|
familyEntry->SetBadUnderlineFamily();
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2014-01-29 07:39:00 +00:00
|
|
|
CFRelease(familyNames);
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
InitSingleFaceList();
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
// to avoid full search of font name tables, seed the other names table with localized names from
|
2009-08-16 13:52:12 +00:00
|
|
|
// some of the prefs fonts which are accessed via their localized names. changes in the pref fonts will only cause
|
|
|
|
// a font lookup miss earlier. this is a simple optimization, it's not required for correctness
|
|
|
|
PreloadNamesList();
|
|
|
|
|
|
|
|
// start the delayed cmap loader
|
2013-04-26 07:40:44 +00:00
|
|
|
GetPrefsAndStartLoader();
|
2010-11-08 11:02:27 +00:00
|
|
|
|
2012-12-21 09:48:39 +00:00
|
|
|
return NS_OK;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxMacPlatformFontList::InitSingleFaceList()
|
|
|
|
{
|
|
|
|
nsAutoTArray<nsString, 10> singleFaceFonts;
|
|
|
|
gfxFontUtils::GetPrefsFontList("font.single-face-list", singleFaceFonts);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t numFonts = singleFaceFonts.Length();
|
|
|
|
for (uint32_t i = 0; i < numFonts; i++) {
|
2011-01-21 16:44:33 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-singleface) face name: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(singleFaceFonts[i]).get()));
|
|
|
|
#endif
|
2012-07-30 14:20:58 +00:00
|
|
|
gfxFontEntry *fontEntry = LookupLocalFont(nullptr, singleFaceFonts[i]);
|
2009-08-16 13:52:12 +00:00
|
|
|
if (fontEntry) {
|
|
|
|
nsAutoString familyName, key;
|
2009-09-29 00:38:59 +00:00
|
|
|
familyName = singleFaceFonts[i];
|
2009-08-16 13:52:12 +00:00
|
|
|
GenerateFontListKey(familyName, key);
|
2011-01-21 16:44:33 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-singleface) family name: %s, key: %s\n",
|
|
|
|
NS_ConvertUTF16toUTF8(familyName).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(key).get()));
|
|
|
|
#endif
|
2009-08-16 13:52:12 +00:00
|
|
|
|
|
|
|
// add only if doesn't exist already
|
2012-03-27 21:38:39 +00:00
|
|
|
if (!mFontFamilies.GetWeak(key)) {
|
|
|
|
gfxFontFamily *familyEntry =
|
|
|
|
new gfxSingleFaceMacFontFamily(familyName);
|
2009-08-16 13:52:12 +00:00
|
|
|
familyEntry->AddFontEntry(fontEntry);
|
2011-10-17 14:59:28 +00:00
|
|
|
familyEntry->SetHasStyles(true);
|
2009-08-16 13:52:12 +00:00
|
|
|
mFontFamilies.Put(key, familyEntry);
|
2011-01-21 16:44:33 +00:00
|
|
|
#ifdef PR_LOGGING
|
|
|
|
LOG_FONTLIST(("(fontlist-singleface) added new family\n",
|
|
|
|
NS_ConvertUTF16toUTF8(familyName).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(key).get()));
|
|
|
|
#endif
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxMacPlatformFontList::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
gfxFontFamily *family = FindFamily(aFontName);
|
|
|
|
if (family) {
|
2009-09-28 10:25:22 +00:00
|
|
|
family->LocalizedName(aFamilyName);
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-16 04:53:52 +00:00
|
|
|
gfxMacPlatformFontList::RegisteredFontsChangedNotificationCallback(CFNotificationCenterRef center,
|
|
|
|
void *observer,
|
|
|
|
CFStringRef name,
|
|
|
|
const void *object,
|
|
|
|
CFDictionaryRef userInfo)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
2013-10-16 04:53:52 +00:00
|
|
|
if (!::CFEqual(name, kCTFontManagerRegisteredFontsChangedNotification)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-17 14:17:22 +00:00
|
|
|
gfxMacPlatformFontList* fl = static_cast<gfxMacPlatformFontList*>(observer);
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// xxx - should be carefully pruning the list of fonts, not rebuilding it from scratch
|
2014-04-17 14:17:22 +00:00
|
|
|
fl->UpdateFontList();
|
2012-12-21 09:48:39 +00:00
|
|
|
|
|
|
|
// modify a preference that will trigger reflow everywhere
|
2014-04-17 14:17:22 +00:00
|
|
|
fl->ForceGlobalReflow();
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2012-03-09 02:05:47 +00:00
|
|
|
gfxFontEntry*
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxMacPlatformFontList::GlobalFontFallback(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-09 02:05:47 +00:00
|
|
|
const gfxFontStyle* aMatchStyle,
|
2012-12-19 09:42:25 +00:00
|
|
|
uint32_t& aCmapCount,
|
|
|
|
gfxFontFamily** aMatchedFamily)
|
2012-03-09 02:05:47 +00:00
|
|
|
{
|
|
|
|
bool useCmaps = gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
|
|
|
|
|
|
|
|
if (useCmaps) {
|
|
|
|
return gfxPlatformFontList::GlobalFontFallback(aCh,
|
|
|
|
aRunScript,
|
|
|
|
aMatchStyle,
|
2012-12-19 09:42:25 +00:00
|
|
|
aCmapCount,
|
|
|
|
aMatchedFamily);
|
2012-03-09 02:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CFStringRef str;
|
|
|
|
UniChar ch[2];
|
|
|
|
CFIndex len = 1;
|
|
|
|
|
|
|
|
if (IS_IN_BMP(aCh)) {
|
|
|
|
ch[0] = aCh;
|
|
|
|
str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, ch, 1,
|
|
|
|
kCFAllocatorNull);
|
|
|
|
} else {
|
|
|
|
ch[0] = H_SURROGATE(aCh);
|
|
|
|
ch[1] = L_SURROGATE(aCh);
|
|
|
|
str = ::CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, ch, 2,
|
|
|
|
kCFAllocatorNull);
|
|
|
|
if (!str) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2012-03-09 02:05:47 +00:00
|
|
|
}
|
|
|
|
len = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
// use CoreText to find the fallback family
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gfxFontEntry *fontEntry = nullptr;
|
2012-03-09 02:05:47 +00:00
|
|
|
CTFontRef fallback;
|
|
|
|
bool cantUseFallbackFont = false;
|
|
|
|
|
|
|
|
if (!mDefaultFont) {
|
2013-11-02 19:51:48 +00:00
|
|
|
mDefaultFont = ::CTFontCreateWithName(CFSTR("LucidaGrande"), 12.f,
|
2012-03-09 02:05:47 +00:00
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
fallback = ::CTFontCreateForString(mDefaultFont, str,
|
|
|
|
::CFRangeMake(0, len));
|
|
|
|
|
|
|
|
if (fallback) {
|
|
|
|
CFStringRef familyName = ::CTFontCopyFamilyName(fallback);
|
|
|
|
::CFRelease(fallback);
|
|
|
|
|
|
|
|
if (familyName &&
|
|
|
|
::CFStringCompare(familyName, CFSTR("LastResort"),
|
|
|
|
kCFCompareCaseInsensitive) != kCFCompareEqualTo)
|
|
|
|
{
|
|
|
|
nsAutoTArray<UniChar, 1024> buffer;
|
|
|
|
CFIndex len = ::CFStringGetLength(familyName);
|
|
|
|
buffer.SetLength(len+1);
|
|
|
|
::CFStringGetCharacters(familyName, ::CFRangeMake(0, len),
|
|
|
|
buffer.Elements());
|
|
|
|
buffer[len] = 0;
|
2014-01-04 15:02:17 +00:00
|
|
|
nsDependentString familyName(reinterpret_cast<char16_t*>(buffer.Elements()), len);
|
2012-03-09 02:05:47 +00:00
|
|
|
|
|
|
|
bool needsBold; // ignored in the system fallback case
|
|
|
|
|
2012-12-19 09:42:25 +00:00
|
|
|
gfxFontFamily *family = FindFamily(familyName);
|
|
|
|
if (family) {
|
|
|
|
fontEntry = family->FindFontForStyle(*aMatchStyle, needsBold);
|
|
|
|
if (fontEntry) {
|
|
|
|
if (fontEntry->TestCharacterMap(aCh)) {
|
|
|
|
*aMatchedFamily = family;
|
|
|
|
} else {
|
|
|
|
fontEntry = nullptr;
|
|
|
|
cantUseFallbackFont = true;
|
|
|
|
}
|
|
|
|
}
|
2012-03-09 02:05:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (familyName) {
|
|
|
|
::CFRelease(familyName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cantUseFallbackFont) {
|
|
|
|
Telemetry::Accumulate(Telemetry::BAD_FALLBACK_FONT, cantUseFallbackFont);
|
|
|
|
}
|
|
|
|
|
|
|
|
::CFRelease(str);
|
|
|
|
|
|
|
|
return fontEntry;
|
|
|
|
}
|
|
|
|
|
2012-12-19 09:42:25 +00:00
|
|
|
gfxFontFamily*
|
|
|
|
gfxMacPlatformFontList::GetDefaultFont(const gfxFontStyle* aStyle)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
NSString *defaultFamily = [[NSFont userFontOfSize:aStyle->size] familyName];
|
|
|
|
nsAutoString familyName;
|
|
|
|
|
|
|
|
GetStringForNSString(defaultFamily, familyName);
|
2012-12-19 09:42:25 +00:00
|
|
|
return FindFamily(familyName);
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
|
|
|
gfxMacPlatformFontList::AppleWeightToCSSWeight(int32_t aAppleWeight)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
|
|
|
if (aAppleWeight < 1)
|
|
|
|
aAppleWeight = 1;
|
|
|
|
else if (aAppleWeight > kAppleMaxWeight)
|
|
|
|
aAppleWeight = kAppleMaxWeight;
|
|
|
|
return gAppleWeightToCSSWeight[aAppleWeight];
|
|
|
|
}
|
|
|
|
|
2009-10-12 23:43:43 +00:00
|
|
|
gfxFontEntry*
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxMacPlatformFontList::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
2009-10-07 14:13:40 +00:00
|
|
|
const nsAString& aFontName)
|
2009-08-16 13:52:12 +00:00
|
|
|
{
|
2010-03-09 16:37:56 +00:00
|
|
|
nsAutoreleasePool localPool;
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
NSString *faceName = GetNSStringForString(aFontName);
|
2011-06-24 17:55:27 +00:00
|
|
|
MacOSFontEntry *newFontEntry;
|
|
|
|
|
2012-11-19 10:01:43 +00:00
|
|
|
// lookup face based on postscript or full name
|
|
|
|
CGFontRef fontRef = ::CGFontCreateWithFontName(CFStringRef(faceName));
|
|
|
|
if (!fontRef) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-06-24 17:55:27 +00:00
|
|
|
|
2012-11-19 10:01:43 +00:00
|
|
|
if (aProxyEntry) {
|
|
|
|
uint16_t w = aProxyEntry->mWeight;
|
|
|
|
NS_ASSERTION(w >= 100 && w <= 900, "bogus font weight value!");
|
2011-06-24 17:55:27 +00:00
|
|
|
|
2012-11-19 10:01:43 +00:00
|
|
|
newFontEntry =
|
2012-11-19 10:22:10 +00:00
|
|
|
new MacOSFontEntry(aFontName, fontRef,
|
|
|
|
w, aProxyEntry->mStretch,
|
|
|
|
aProxyEntry->mItalic ?
|
|
|
|
NS_FONT_STYLE_ITALIC : NS_FONT_STYLE_NORMAL,
|
|
|
|
true, true);
|
2012-11-19 10:01:43 +00:00
|
|
|
} else {
|
|
|
|
newFontEntry =
|
2012-11-19 10:22:10 +00:00
|
|
|
new MacOSFontEntry(aFontName, fontRef,
|
|
|
|
400, 0, NS_FONT_STYLE_NORMAL,
|
|
|
|
false, false);
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
2012-11-19 10:01:43 +00:00
|
|
|
::CFRelease(fontRef);
|
2011-06-24 17:55:27 +00:00
|
|
|
|
|
|
|
return newFontEntry;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReleaseData(void *info, const void *data, size_t size)
|
|
|
|
{
|
|
|
|
NS_Free((void*)data);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2012-11-19 10:22:10 +00:00
|
|
|
gfxMacPlatformFontList::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const uint8_t *aFontData,
|
|
|
|
uint32_t aLength)
|
2011-06-24 17:55:27 +00:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aFontData, "MakePlatformFont called with null data");
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t w = aProxyEntry->mWeight;
|
2011-06-24 17:55:27 +00:00
|
|
|
NS_ASSERTION(w >= 100 && w <= 900, "bogus font weight value!");
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
// create the font entry
|
|
|
|
nsAutoString uniqueName;
|
2009-10-12 23:43:43 +00:00
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
nsresult rv = gfxFontUtils::MakeUniqueUserFontName(uniqueName);
|
|
|
|
if (NS_FAILED(rv)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2011-06-24 17:55:27 +00:00
|
|
|
}
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
CGDataProviderRef provider =
|
2012-07-30 14:20:58 +00:00
|
|
|
::CGDataProviderCreateWithData(nullptr, aFontData, aLength,
|
2011-06-24 17:55:27 +00:00
|
|
|
&ReleaseData);
|
|
|
|
CGFontRef fontRef = ::CGFontCreateWithDataProvider(provider);
|
|
|
|
::CGDataProviderRelease(provider);
|
2009-08-16 13:52:12 +00:00
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
if (!fontRef) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 10:22:10 +00:00
|
|
|
nsAutoPtr<MacOSFontEntry>
|
|
|
|
newFontEntry(new MacOSFontEntry(uniqueName, fontRef, w,
|
|
|
|
aProxyEntry->mStretch,
|
|
|
|
aProxyEntry->mItalic ?
|
|
|
|
NS_FONT_STYLE_ITALIC :
|
|
|
|
NS_FONT_STYLE_NORMAL,
|
|
|
|
true, false));
|
2011-12-19 10:36:05 +00:00
|
|
|
::CFRelease(fontRef);
|
2011-06-24 17:55:27 +00:00
|
|
|
|
|
|
|
// if succeeded and font cmap is good, return the new font
|
|
|
|
if (newFontEntry->mIsValid && NS_SUCCEEDED(newFontEntry->ReadCMAP())) {
|
|
|
|
return newFontEntry.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if something is funky about this font, delete immediately
|
2012-12-19 09:42:25 +00:00
|
|
|
|
2011-06-24 17:55:27 +00:00
|
|
|
#if DEBUG
|
2012-12-19 09:42:25 +00:00
|
|
|
NS_WARNING("downloaded font not loaded properly");
|
2011-06-24 17:55:27 +00:00
|
|
|
#endif
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
2014-01-29 07:39:01 +00:00
|
|
|
|
|
|
|
// used to load system-wide font info on off-main thread
|
|
|
|
class MacFontInfo : public FontInfoData {
|
|
|
|
public:
|
|
|
|
MacFontInfo(bool aLoadOtherNames,
|
|
|
|
bool aLoadFaceNames,
|
|
|
|
bool aLoadCmaps) :
|
|
|
|
FontInfoData(aLoadOtherNames, aLoadFaceNames, aLoadCmaps)
|
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~MacFontInfo() {}
|
|
|
|
|
|
|
|
virtual void Load() {
|
|
|
|
nsAutoreleasePool localPool;
|
2014-04-03 04:13:11 +00:00
|
|
|
// bug 975460 - async font loader crashes sometimes under 10.6, disable
|
|
|
|
if (nsCocoaFeatures::OnLionOrLater()) {
|
2014-03-28 05:40:42 +00:00
|
|
|
FontInfoData::Load();
|
|
|
|
}
|
2014-01-29 07:39:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// loads font data for all members of a given family
|
|
|
|
virtual void LoadFontFamilyData(const nsAString& aFamilyName);
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
MacFontInfo::LoadFontFamilyData(const nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
// family name ==> CTFontDescriptor
|
|
|
|
NSString *famName = GetNSStringForString(aFamilyName);
|
|
|
|
CFStringRef family = CFStringRef(famName);
|
|
|
|
|
|
|
|
CFMutableDictionaryRef attr =
|
|
|
|
CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
|
|
|
|
&kCFTypeDictionaryValueCallBacks);
|
|
|
|
CFDictionaryAddValue(attr, kCTFontFamilyNameAttribute, family);
|
|
|
|
CTFontDescriptorRef fd = CTFontDescriptorCreateWithAttributes(attr);
|
|
|
|
CFRelease(attr);
|
|
|
|
CFArrayRef matchingFonts =
|
|
|
|
CTFontDescriptorCreateMatchingFontDescriptors(fd, NULL);
|
|
|
|
CFRelease(fd);
|
|
|
|
if (!matchingFonts) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<nsString> otherFamilyNames;
|
|
|
|
bool hasOtherFamilyNames = true;
|
|
|
|
|
|
|
|
// iterate over faces in the family
|
|
|
|
int f, numFaces = (int) CFArrayGetCount(matchingFonts);
|
|
|
|
for (f = 0; f < numFaces; f++) {
|
|
|
|
mLoadStats.fonts++;
|
|
|
|
|
|
|
|
CTFontDescriptorRef faceDesc =
|
|
|
|
(CTFontDescriptorRef)CFArrayGetValueAtIndex(matchingFonts, f);
|
|
|
|
if (!faceDesc) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CTFontRef fontRef = CTFontCreateWithFontDescriptor(faceDesc,
|
|
|
|
0.0, nullptr);
|
2014-02-25 07:37:26 +00:00
|
|
|
if (!fontRef) {
|
|
|
|
NS_WARNING("failed to create a CTFontRef");
|
|
|
|
continue;
|
|
|
|
}
|
2014-01-29 07:39:01 +00:00
|
|
|
|
|
|
|
if (mLoadCmaps) {
|
|
|
|
// face name
|
|
|
|
CFStringRef faceName = (CFStringRef)
|
|
|
|
CTFontDescriptorCopyAttribute(faceDesc, kCTFontNameAttribute);
|
|
|
|
|
|
|
|
nsAutoTArray<UniChar, 1024> buffer;
|
|
|
|
CFIndex len = CFStringGetLength(faceName);
|
|
|
|
buffer.SetLength(len+1);
|
|
|
|
CFStringGetCharacters(faceName, ::CFRangeMake(0, len),
|
|
|
|
buffer.Elements());
|
|
|
|
buffer[len] = 0;
|
|
|
|
nsAutoString fontName(reinterpret_cast<char16_t*>(buffer.Elements()),
|
|
|
|
len);
|
|
|
|
|
|
|
|
// load the cmap data
|
|
|
|
FontFaceData fontData;
|
2014-04-03 04:13:14 +00:00
|
|
|
CFDataRef cmapTable = CTFontCopyTable(fontRef, kCTFontTableCmap,
|
|
|
|
kCTFontTableOptionNoOptions);
|
|
|
|
|
2014-01-29 07:39:01 +00:00
|
|
|
if (cmapTable) {
|
|
|
|
bool unicodeFont = false, symbolFont = false; // ignored
|
|
|
|
const uint8_t *cmapData =
|
|
|
|
(const uint8_t*)CFDataGetBytePtr(cmapTable);
|
|
|
|
uint32_t cmapLen = CFDataGetLength(cmapTable);
|
|
|
|
nsRefPtr<gfxCharacterMap> charmap = new gfxCharacterMap();
|
|
|
|
uint32_t offset;
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = gfxFontUtils::ReadCMAP(cmapData, cmapLen, *charmap, offset,
|
|
|
|
unicodeFont, symbolFont);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
fontData.mCharacterMap = charmap;
|
|
|
|
fontData.mUVSOffset = offset;
|
|
|
|
fontData.mSymbolFont = symbolFont;
|
|
|
|
mLoadStats.cmaps++;
|
|
|
|
}
|
|
|
|
CFRelease(cmapTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
mFontFaceData.Put(fontName, fontData);
|
|
|
|
CFRelease(faceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mLoadOtherNames && hasOtherFamilyNames) {
|
2014-04-03 04:13:14 +00:00
|
|
|
CFDataRef nameTable = CTFontCopyTable(fontRef, kCTFontTableName,
|
|
|
|
kCTFontTableOptionNoOptions);
|
|
|
|
|
2014-01-29 07:39:01 +00:00
|
|
|
if (nameTable) {
|
|
|
|
const char *nameData = (const char*)CFDataGetBytePtr(nameTable);
|
|
|
|
uint32_t nameLen = CFDataGetLength(nameTable);
|
|
|
|
gfxFontFamily::ReadOtherFamilyNamesForFace(aFamilyName,
|
|
|
|
nameData, nameLen,
|
|
|
|
otherFamilyNames,
|
|
|
|
false);
|
|
|
|
hasOtherFamilyNames = otherFamilyNames.Length() != 0;
|
|
|
|
CFRelease(nameTable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CFRelease(fontRef);
|
|
|
|
}
|
|
|
|
CFRelease(matchingFonts);
|
|
|
|
|
|
|
|
// if found other names, insert them in the hash table
|
|
|
|
if (otherFamilyNames.Length() != 0) {
|
|
|
|
mOtherFamilyNames.Put(aFamilyName, otherFamilyNames);
|
|
|
|
mLoadStats.othernames += otherFamilyNames.Length();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<FontInfoData>
|
|
|
|
gfxMacPlatformFontList::CreateFontInfoData()
|
|
|
|
{
|
|
|
|
bool loadCmaps = !UsesSystemFallback() ||
|
|
|
|
gfxPlatform::GetPlatform()->UseCmapsDuringSystemFallback();
|
|
|
|
|
|
|
|
nsRefPtr<MacFontInfo> fi =
|
|
|
|
new MacFontInfo(true, NeedFullnamePostscriptNames(), loadCmaps);
|
|
|
|
return fi.forget();
|
|
|
|
}
|
|
|
|
|
2014-05-29 12:00:55 +00:00
|
|
|
#ifdef MOZ_BUNDLED_FONTS
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxMacPlatformFontList::ActivateBundledFonts()
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIFile> localDir;
|
|
|
|
nsresult rv = NS_GetSpecialDirectory(NS_GRE_DIR, getter_AddRefs(localDir));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (NS_FAILED(localDir->Append(NS_LITERAL_STRING("fonts")))) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
bool isDir;
|
|
|
|
if (NS_FAILED(localDir->IsDirectory(&isDir)) || !isDir) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISimpleEnumerator> e;
|
|
|
|
rv = localDir->GetDirectoryEntries(getter_AddRefs(e));
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hasMore;
|
|
|
|
while (NS_SUCCEEDED(e->HasMoreElements(&hasMore)) && hasMore) {
|
|
|
|
nsCOMPtr<nsISupports> entry;
|
|
|
|
if (NS_FAILED(e->GetNext(getter_AddRefs(entry)))) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIFile> file = do_QueryInterface(entry);
|
|
|
|
if (!file) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
nsCString path;
|
|
|
|
if (NS_FAILED(file->GetNativePath(path))) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
CFURLRef fontURL =
|
|
|
|
::CFURLCreateFromFileSystemRepresentation(kCFAllocatorDefault,
|
|
|
|
(uint8_t*)path.get(),
|
|
|
|
path.Length(),
|
|
|
|
false);
|
|
|
|
if (fontURL) {
|
|
|
|
CFErrorRef error = nullptr;
|
|
|
|
::CTFontManagerRegisterFontsForURL(fontURL,
|
|
|
|
kCTFontManagerScopeProcess,
|
|
|
|
&error);
|
|
|
|
::CFRelease(fontURL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|