2006-02-22 01:44:31 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00: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/. */
|
2006-02-22 01:44:31 +00:00
|
|
|
|
|
|
|
#include "gfxPlatformMac.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxQuartzSurface.h"
|
2008-02-06 06:48:47 +00:00
|
|
|
#include "gfxQuartzImageSurface.h"
|
2011-11-02 19:55:03 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2012-11-02 20:24:37 +00:00
|
|
|
#include "mozilla/gfx/QuartzSupport.h"
|
2006-02-22 01:44:31 +00:00
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
#include "gfxMacPlatformFontList.h"
|
2010-03-10 12:46:41 +00:00
|
|
|
#include "gfxMacFont.h"
|
|
|
|
#include "gfxCoreTextShaper.h"
|
2008-10-01 03:01:53 +00:00
|
|
|
#include "gfxUserFontSet.h"
|
2009-03-30 00:31:51 +00:00
|
|
|
|
2008-01-31 00:23:36 +00:00
|
|
|
#include "nsCRT.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2009-03-30 00:31:51 +00:00
|
|
|
#include "nsUnicodeRange.h"
|
2008-01-31 00:23:36 +00:00
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
#include "qcms.h"
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
#include <dlfcn.h>
|
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
using namespace mozilla;
|
2011-11-02 19:55:03 +00:00
|
|
|
using namespace mozilla::gfx;
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2011-05-11 00:44:35 +00:00
|
|
|
// cribbed from CTFontManager.h
|
|
|
|
enum {
|
|
|
|
kAutoActivationDisabled = 1
|
|
|
|
};
|
|
|
|
typedef uint32_t AutoActivationSetting;
|
|
|
|
|
|
|
|
// bug 567552 - disable auto-activation of fonts
|
|
|
|
|
|
|
|
static void
|
|
|
|
DisableFontActivation()
|
|
|
|
{
|
|
|
|
// get the main bundle identifier
|
|
|
|
CFBundleRef mainBundle = ::CFBundleGetMainBundle();
|
2013-07-31 15:44:31 +00:00
|
|
|
CFStringRef mainBundleID = nullptr;
|
2011-05-11 00:44:35 +00:00
|
|
|
|
|
|
|
if (mainBundle) {
|
|
|
|
mainBundleID = ::CFBundleGetIdentifier(mainBundle);
|
|
|
|
}
|
|
|
|
|
|
|
|
// if possible, fetch CTFontManagerSetAutoActivationSetting
|
|
|
|
void (*CTFontManagerSetAutoActivationSettingPtr)
|
|
|
|
(CFStringRef, AutoActivationSetting);
|
|
|
|
CTFontManagerSetAutoActivationSettingPtr =
|
|
|
|
(void (*)(CFStringRef, AutoActivationSetting))
|
|
|
|
dlsym(RTLD_DEFAULT, "CTFontManagerSetAutoActivationSetting");
|
|
|
|
|
|
|
|
// bug 567552 - disable auto-activation of fonts
|
|
|
|
if (CTFontManagerSetAutoActivationSettingPtr) {
|
|
|
|
CTFontManagerSetAutoActivationSettingPtr(mainBundleID,
|
|
|
|
kAutoActivationDisabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-22 01:44:31 +00:00
|
|
|
gfxPlatformMac::gfxPlatformMac()
|
|
|
|
{
|
2008-04-18 09:11:47 +00:00
|
|
|
mOSXVersion = 0;
|
2011-05-11 00:44:35 +00:00
|
|
|
OSXVersion();
|
2013-03-07 23:00:07 +00:00
|
|
|
|
|
|
|
DisableFontActivation();
|
2008-05-01 09:07:17 +00:00
|
|
|
mFontAntiAliasingThreshold = ReadAntiAliasingThreshold();
|
2012-07-25 00:45:58 +00:00
|
|
|
|
2012-11-07 02:27:09 +00:00
|
|
|
uint32_t canvasMask = (1 << BACKEND_CAIRO) | (1 << BACKEND_SKIA) | (1 << BACKEND_COREGRAPHICS);
|
2013-07-12 21:19:29 +00:00
|
|
|
uint32_t contentMask = (1 << BACKEND_COREGRAPHICS);
|
2012-11-07 02:27:09 +00:00
|
|
|
InitBackendPrefs(canvasMask, contentMask);
|
2009-03-30 00:31:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformMac::~gfxPlatformMac()
|
|
|
|
{
|
2010-03-10 12:46:41 +00:00
|
|
|
gfxCoreTextShaper::Shutdown();
|
2006-02-22 01:44:31 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxPlatformMac::CreatePlatformFontList()
|
|
|
|
{
|
2010-11-08 11:02:27 +00:00
|
|
|
gfxPlatformFontList* list = new gfxMacPlatformFontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-08-16 13:52:12 +00:00
|
|
|
}
|
|
|
|
|
2006-03-25 00:34:48 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
2007-02-08 20:47:48 +00:00
|
|
|
gfxPlatformMac::CreateOffscreenSurface(const gfxIntSize& size,
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxContentType contentType)
|
2006-02-22 01:44:31 +00:00
|
|
|
{
|
2013-04-28 11:52:10 +00:00
|
|
|
nsRefPtr<gfxASurface> newSurface =
|
|
|
|
new gfxQuartzSurface(size, OptimalFormatForContent(contentType));
|
|
|
|
return newSurface.forget();
|
2006-02-22 01:44:31 +00:00
|
|
|
}
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2012-06-26 02:43:31 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatformMac::CreateOffscreenImageSurface(const gfxIntSize& aSize,
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxContentType aContentType)
|
2012-06-26 02:43:31 +00:00
|
|
|
{
|
|
|
|
nsRefPtr<gfxASurface> surface = CreateOffscreenSurface(aSize, aContentType);
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurface = surface->GetAsImageSurface();
|
|
|
|
NS_ASSERTION(imageSurface, "Surface cannot be converted to a gfxImageSurface");
|
|
|
|
#endif
|
|
|
|
return surface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-06 06:48:47 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatformMac::OptimizeImage(gfxImageSurface *aSurface,
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxImageFormat format)
|
2008-02-06 06:48:47 +00:00
|
|
|
{
|
|
|
|
const gfxIntSize& surfaceSize = aSurface->GetSize();
|
|
|
|
nsRefPtr<gfxImageSurface> isurf = aSurface;
|
|
|
|
|
|
|
|
if (format != aSurface->Format()) {
|
|
|
|
isurf = new gfxImageSurface (surfaceSize, format);
|
|
|
|
if (!isurf->CopyFrom (aSurface)) {
|
|
|
|
// don't even bother doing anything more
|
2013-04-28 11:52:10 +00:00
|
|
|
nsRefPtr<gfxASurface> ret = aSurface;
|
|
|
|
return ret.forget();
|
2008-02-06 06:48:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> ret = new gfxQuartzImageSurface(isurf);
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
2012-09-24 15:02:49 +00:00
|
|
|
TemporaryRef<ScaledFont>
|
2012-07-24 10:18:37 +00:00
|
|
|
gfxPlatformMac::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-11-02 19:55:03 +00:00
|
|
|
{
|
|
|
|
gfxMacFont *font = static_cast<gfxMacFont*>(aFont);
|
2012-09-24 15:02:49 +00:00
|
|
|
return font->GetScaledFont(aTarget);
|
2011-11-02 19:55:03 +00:00
|
|
|
}
|
|
|
|
|
2006-11-21 06:31:04 +00:00
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
2011-09-29 06:19:26 +00:00
|
|
|
void *aClosure, bool& aAborted)
|
2006-11-21 06:31:04 +00:00
|
|
|
{
|
2006-12-22 03:56:37 +00:00
|
|
|
nsAutoString resolvedName;
|
2009-08-16 13:52:12 +00:00
|
|
|
if (!gfxPlatformFontList::PlatformFontList()->
|
2006-12-22 03:56:37 +00:00
|
|
|
ResolveFontName(aFontName, resolvedName)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
aAborted = false;
|
2006-12-22 03:56:37 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
aAborted = !(*aCallback)(resolvedName, aClosure);
|
2006-11-21 06:31:04 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-13 10:32:50 +00:00
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
2008-03-13 10:32:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-02 19:06:16 +00:00
|
|
|
gfxFontGroup *
|
|
|
|
gfxPlatformMac::CreateFontGroup(const nsAString &aFamilies,
|
2008-10-01 03:01:53 +00:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
2007-04-02 19:06:16 +00:00
|
|
|
{
|
2009-10-07 15:26:58 +00:00
|
|
|
return new gfxFontGroup(aFamilies, aStyle, aUserFontSet);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// these will move to gfxPlatform once all platforms support the fontlist
|
2008-10-01 03:01:53 +00:00
|
|
|
gfxFontEntry*
|
2009-01-03 03:21:49 +00:00
|
|
|
gfxPlatformMac::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(aProxyEntry,
|
|
|
|
aFontName);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2008-12-05 23:19:27 +00:00
|
|
|
gfxPlatformMac::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
2012-08-22 15:56:38 +00:00
|
|
|
const uint8_t *aFontData, uint32_t aLength)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-10-07 14:13:40 +00:00
|
|
|
// Ownership of aFontData is received here, and passed on to
|
|
|
|
// gfxPlatformFontList::MakePlatformFont(), which must ensure the data
|
|
|
|
// is released with NS_Free when no longer needed
|
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aProxyEntry,
|
|
|
|
aFontData,
|
|
|
|
aLength);
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxPlatformMac::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2008-10-01 03:01:53 +00:00
|
|
|
{
|
2009-01-13 05:16:58 +00:00
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
2009-09-17 11:03:12 +00:00
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
2009-01-13 05:16:58 +00:00
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2008-10-01 03:01:53 +00:00
|
|
|
}
|
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2009-01-13 05:16:58 +00:00
|
|
|
}
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2009-01-13 05:16:58 +00:00
|
|
|
// no format hint set, need to look at data
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2007-04-02 19:06:16 +00:00
|
|
|
}
|
|
|
|
|
2009-08-16 13:52:12 +00:00
|
|
|
// these will also move to gfxPlatform once all platforms support the fontlist
|
2006-11-22 00:52:09 +00:00
|
|
|
nsresult
|
2010-02-24 17:57:57 +00:00
|
|
|
gfxPlatformMac::GetFontList(nsIAtom *aLangGroup,
|
2006-11-22 00:52:09 +00:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 20:14:14 +00:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-11-22 00:52:09 +00:00
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
|
2006-11-22 00:52:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-12-22 03:56:37 +00:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::UpdateFontList()
|
|
|
|
{
|
2009-08-16 13:52:12 +00:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2006-12-22 03:56:37 +00:00
|
|
|
return NS_OK;
|
2007-02-08 20:47:48 +00:00
|
|
|
}
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2012-03-09 02:05:24 +00:00
|
|
|
static const char kFontArialUnicodeMS[] = "Arial Unicode MS";
|
|
|
|
static const char kFontAppleBraille[] = "Apple Braille";
|
|
|
|
static const char kFontAppleSymbols[] = "Apple Symbols";
|
|
|
|
static const char kFontGeneva[] = "Geneva";
|
|
|
|
static const char kFontGeezaPro[] = "Geeza Pro";
|
|
|
|
static const char kFontHiraginoKakuGothic[] = "Hiragino Kaku Gothic ProN";
|
|
|
|
static const char kFontLucidaGrande[] = "Lucida Grande";
|
|
|
|
static const char kFontMenlo[] = "Menlo";
|
|
|
|
static const char kFontPlantagenetCherokee[] = "Plantagenet Cherokee";
|
|
|
|
static const char kFontSTHeiti[] = "STHeiti";
|
|
|
|
|
|
|
|
void
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxPlatformMac::GetCommonFallbackFonts(const uint32_t aCh,
|
|
|
|
int32_t aRunScript,
|
2012-03-09 02:05:24 +00:00
|
|
|
nsTArray<const char*>& aFontList)
|
|
|
|
{
|
|
|
|
aFontList.AppendElement(kFontLucidaGrande);
|
|
|
|
|
|
|
|
if (!IS_IN_BMP(aCh)) {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t p = aCh >> 16;
|
2012-03-09 02:05:24 +00:00
|
|
|
if (p == 1) {
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
}
|
|
|
|
} else {
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t b = (aCh >> 8) & 0xff;
|
2012-03-09 02:05:24 +00:00
|
|
|
|
|
|
|
switch (b) {
|
|
|
|
case 0x03:
|
|
|
|
case 0x05:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x07:
|
|
|
|
aFontList.AppendElement(kFontGeezaPro);
|
|
|
|
break;
|
|
|
|
case 0x10:
|
|
|
|
aFontList.AppendElement(kFontMenlo);
|
|
|
|
break;
|
|
|
|
case 0x13: // Cherokee
|
|
|
|
aFontList.AppendElement(kFontPlantagenetCherokee);
|
|
|
|
break;
|
|
|
|
case 0x18: // Mongolian
|
|
|
|
aFontList.AppendElement(kFontSTHeiti);
|
|
|
|
break;
|
|
|
|
case 0x1d:
|
|
|
|
case 0x1e:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x20: // Symbol ranges
|
|
|
|
case 0x21:
|
|
|
|
case 0x22:
|
|
|
|
case 0x23:
|
|
|
|
case 0x24:
|
|
|
|
case 0x25:
|
|
|
|
case 0x26:
|
|
|
|
case 0x27:
|
|
|
|
case 0x29:
|
|
|
|
case 0x2a:
|
|
|
|
case 0x2b:
|
|
|
|
case 0x2e:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
aFontList.AppendElement(kFontMenlo);
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
aFontList.AppendElement(kFontHiraginoKakuGothic);
|
|
|
|
break;
|
|
|
|
case 0x2c:
|
|
|
|
case 0x2d:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
break;
|
|
|
|
case 0x28: // Braille
|
|
|
|
aFontList.AppendElement(kFontAppleBraille);
|
|
|
|
break;
|
|
|
|
case 0x4d:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
|
|
|
case 0xa0: // Yi
|
|
|
|
case 0xa1:
|
|
|
|
case 0xa2:
|
|
|
|
case 0xa3:
|
|
|
|
case 0xa4:
|
|
|
|
aFontList.AppendElement(kFontSTHeiti);
|
|
|
|
break;
|
|
|
|
case 0xa6:
|
|
|
|
case 0xa7:
|
|
|
|
aFontList.AppendElement(kFontGeneva);
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
|
|
|
case 0xfc:
|
|
|
|
case 0xff:
|
|
|
|
aFontList.AppendElement(kFontAppleSymbols);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Arial Unicode MS has lots of glyphs for obscure, use it as a last resort
|
|
|
|
aFontList.AppendElement(kFontArialUnicodeMS);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2008-04-18 09:11:47 +00:00
|
|
|
gfxPlatformMac::OSXVersion()
|
|
|
|
{
|
|
|
|
if (!mOSXVersion) {
|
|
|
|
// minor version is not accurate, use gestaltSystemVersionMajor, gestaltSystemVersionMinor, gestaltSystemVersionBugFix for these
|
2009-08-16 13:52:12 +00:00
|
|
|
OSErr err = ::Gestalt(gestaltSystemVersion, reinterpret_cast<SInt32*>(&mOSXVersion));
|
2008-04-18 09:11:47 +00:00
|
|
|
if (err != noErr) {
|
|
|
|
//This should probably be changed when our minimum version changes
|
2013-08-06 21:52:52 +00:00
|
|
|
NS_ERROR("Couldn't determine OS X version, assuming 10.6");
|
|
|
|
mOSXVersion = MAC_OS_X_VERSION_10_6_HEX;
|
2008-04-18 09:11:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mOSXVersion;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t
|
2008-05-01 09:07:17 +00:00
|
|
|
gfxPlatformMac::ReadAntiAliasingThreshold()
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t threshold = 0; // default == no threshold
|
2008-05-01 09:07:17 +00:00
|
|
|
|
|
|
|
// first read prefs flag to determine whether to use the setting or not
|
2011-09-29 06:19:26 +00:00
|
|
|
bool useAntiAliasingThreshold = Preferences::GetBool("gfx.use_text_smoothing_setting", false);
|
2011-06-12 02:30:16 +00:00
|
|
|
|
2008-05-01 09:07:17 +00:00
|
|
|
// if the pref setting is disabled, return 0 which effectively disables this feature
|
|
|
|
if (!useAntiAliasingThreshold)
|
|
|
|
return threshold;
|
|
|
|
|
|
|
|
// value set via Appearance pref panel, "Turn off text smoothing for font sizes xxx and smaller"
|
|
|
|
CFNumberRef prefValue = (CFNumberRef)CFPreferencesCopyAppValue(CFSTR("AppleAntiAliasingThreshold"), kCFPreferencesCurrentApplication);
|
|
|
|
|
|
|
|
if (prefValue) {
|
|
|
|
if (!CFNumberGetValue(prefValue, kCFNumberIntType, &threshold)) {
|
|
|
|
threshold = 0;
|
|
|
|
}
|
|
|
|
CFRelease(prefValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
return threshold;
|
|
|
|
}
|
2008-01-31 00:23:36 +00:00
|
|
|
|
2012-11-02 20:24:37 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatformMac::CreateThebesSurfaceAliasForDrawTarget_hack(mozilla::gfx::DrawTarget *aTarget)
|
|
|
|
{
|
|
|
|
if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
|
|
|
|
CGContextRef cg = static_cast<CGContextRef>(aTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
|
|
|
|
unsigned char* data = (unsigned char*)CGBitmapContextGetData(cg);
|
|
|
|
size_t bpp = CGBitmapContextGetBitsPerPixel(cg);
|
|
|
|
size_t stride = CGBitmapContextGetBytesPerRow(cg);
|
|
|
|
gfxIntSize size(aTarget->GetSize().width, aTarget->GetSize().height);
|
|
|
|
nsRefPtr<gfxImageSurface> imageSurface = new gfxImageSurface(data, size, stride, bpp == 2
|
2013-09-24 20:45:13 +00:00
|
|
|
? gfxImageFormatRGB16_565
|
|
|
|
: gfxImageFormatARGB32);
|
2012-11-02 20:24:37 +00:00
|
|
|
// Here we should return a gfxQuartzImageSurface but quartz will assumes that image surfaces
|
|
|
|
// don't change which wont create a proper alias to the draw target, therefore we have to
|
|
|
|
// return a plain image surface.
|
|
|
|
return imageSurface.forget();
|
|
|
|
} else {
|
|
|
|
return GetThebesSurfaceForDrawTarget(aTarget);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-01-09 18:54:44 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatformMac::GetThebesSurfaceForDrawTarget(DrawTarget *aTarget)
|
|
|
|
{
|
2012-07-31 15:17:43 +00:00
|
|
|
if (aTarget->GetType() == BACKEND_COREGRAPHICS_ACCELERATED) {
|
|
|
|
RefPtr<SourceSurface> source = aTarget->Snapshot();
|
|
|
|
RefPtr<DataSourceSurface> sourceData = source->GetDataSurface();
|
|
|
|
unsigned char* data = sourceData->GetData();
|
|
|
|
nsRefPtr<gfxImageSurface> surf = new gfxImageSurface(data, ThebesIntSize(sourceData->GetSize()), sourceData->Stride(),
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxImageFormatARGB32);
|
2012-07-31 15:17:43 +00:00
|
|
|
// We could fix this by telling gfxImageSurface it owns data.
|
2013-09-24 20:45:13 +00:00
|
|
|
nsRefPtr<gfxImageSurface> cpy = new gfxImageSurface(ThebesIntSize(sourceData->GetSize()), gfxImageFormatARGB32);
|
2012-07-31 15:17:43 +00:00
|
|
|
cpy->CopyFrom(surf);
|
|
|
|
return cpy.forget();
|
|
|
|
} else if (aTarget->GetType() == BACKEND_COREGRAPHICS) {
|
2012-07-26 02:30:20 +00:00
|
|
|
CGContextRef cg = static_cast<CGContextRef>(aTarget->GetNativeSurface(NATIVE_SURFACE_CGCONTEXT));
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2012-07-26 02:30:20 +00:00
|
|
|
//XXX: it would be nice to have an implicit conversion from IntSize to gfxIntSize
|
|
|
|
IntSize intSize = aTarget->GetSize();
|
|
|
|
gfxIntSize size(intSize.width, intSize.height);
|
2012-01-13 14:48:29 +00:00
|
|
|
|
2012-07-26 02:30:20 +00:00
|
|
|
nsRefPtr<gfxASurface> surf =
|
|
|
|
new gfxQuartzSurface(cg, size);
|
2012-07-26 06:48:24 +00:00
|
|
|
|
2012-07-26 02:30:20 +00:00
|
|
|
return surf.forget();
|
2012-01-09 18:54:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return gfxPlatform::GetThebesSurfaceForDrawTarget(aTarget);
|
|
|
|
}
|
|
|
|
|
2012-07-31 15:17:43 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformMac::UseAcceleratedCanvas()
|
|
|
|
{
|
|
|
|
// Lion or later is required
|
2012-07-31 22:48:40 +00:00
|
|
|
return OSXVersion() >= 0x1070 && Preferences::GetBool("gfx.canvas.azure.accelerated", false);
|
2012-07-31 15:17:43 +00:00
|
|
|
}
|
2012-01-09 18:54:44 +00:00
|
|
|
|
2013-06-20 21:32:04 +00:00
|
|
|
bool
|
|
|
|
gfxPlatformMac::SupportsOffMainThreadCompositing()
|
|
|
|
{
|
|
|
|
// 10.6.X has crashes on tinderbox with OMTC, so disable it
|
|
|
|
// for now.
|
|
|
|
if (OSXVersion() >= 0x1070) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return GetPrefLayersOffMainThreadCompositionForceEnabled();
|
|
|
|
}
|
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
qcms_profile *
|
2007-07-23 22:02:17 +00:00
|
|
|
gfxPlatformMac::GetPlatformCMSOutputProfile()
|
|
|
|
{
|
2012-07-30 14:20:58 +00:00
|
|
|
qcms_profile *profile = nullptr;
|
2009-10-03 18:33:55 +00:00
|
|
|
CMProfileRef cmProfile;
|
|
|
|
CMProfileLocation *location;
|
|
|
|
UInt32 locationSize;
|
|
|
|
|
|
|
|
/* There a number of different ways that we could try to get a color
|
|
|
|
profile to use. On 10.5 all of these methods seem to give the same
|
|
|
|
results. On 10.6, the results are different and the following method,
|
|
|
|
using CGMainDisplayID() seems to best match what we are looking for.
|
|
|
|
Currently, both Google Chrome and Qt4 use a similar method.
|
|
|
|
|
|
|
|
CMTypes.h describes CMDisplayIDType:
|
|
|
|
"Data type for ColorSync DisplayID reference
|
|
|
|
On 8 & 9 this is a AVIDType
|
|
|
|
On X this is a CGSDisplayID"
|
|
|
|
|
|
|
|
CGMainDisplayID gives us a CGDirectDisplayID which presumeably
|
|
|
|
corresponds directly to a CGSDisplayID */
|
|
|
|
CGDirectDisplayID displayID = CGMainDisplayID();
|
|
|
|
|
|
|
|
CMError err = CMGetProfileByAVID(static_cast<CMDisplayIDType>(displayID), &cmProfile);
|
2007-07-23 22:02:17 +00:00
|
|
|
if (err != noErr)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2007-07-23 22:02:17 +00:00
|
|
|
|
2009-10-03 18:33:55 +00:00
|
|
|
// get the size of location
|
2013-07-31 15:44:31 +00:00
|
|
|
err = NCMGetProfileLocation(cmProfile, nullptr, &locationSize);
|
2009-10-03 18:33:55 +00:00
|
|
|
if (err != noErr)
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2009-10-03 18:33:55 +00:00
|
|
|
|
|
|
|
// allocate enough room for location
|
|
|
|
location = static_cast<CMProfileLocation*>(malloc(locationSize));
|
|
|
|
if (!location)
|
|
|
|
goto fail_close;
|
|
|
|
|
|
|
|
err = NCMGetProfileLocation(cmProfile, location, &locationSize);
|
|
|
|
if (err != noErr)
|
|
|
|
goto fail_location;
|
|
|
|
|
|
|
|
switch (location->locType) {
|
2009-04-22 13:08:09 +00:00
|
|
|
#ifndef __LP64__
|
2007-07-23 22:02:17 +00:00
|
|
|
case cmFileBasedProfile: {
|
|
|
|
FSRef fsRef;
|
2009-10-03 18:33:55 +00:00
|
|
|
if (!FSpMakeFSRef(&location->u.fileLoc.spec, &fsRef)) {
|
2007-07-23 22:02:17 +00:00
|
|
|
char path[512];
|
2009-08-16 13:52:12 +00:00
|
|
|
if (!FSRefMakePath(&fsRef, reinterpret_cast<UInt8*>(path), sizeof(path))) {
|
2009-04-07 16:02:11 +00:00
|
|
|
profile = qcms_profile_from_path(path);
|
2007-07-23 22:02:17 +00:00
|
|
|
#ifdef DEBUG_tor
|
|
|
|
if (profile)
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s fileLoc successfully\n", path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-22 13:08:09 +00:00
|
|
|
#endif
|
2007-07-23 22:02:17 +00:00
|
|
|
case cmPathBasedProfile:
|
2009-10-03 18:33:55 +00:00
|
|
|
profile = qcms_profile_from_path(location->u.pathLoc.path);
|
2007-07-23 22:02:17 +00:00
|
|
|
#ifdef DEBUG_tor
|
|
|
|
if (profile)
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s pathLoc successfully\n",
|
|
|
|
device.u.pathLoc.path);
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr, "Unhandled ColorSync profile location\n");
|
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-10-03 18:33:55 +00:00
|
|
|
fail_location:
|
|
|
|
free(location);
|
|
|
|
fail_close:
|
|
|
|
CMCloseProfile(cmProfile);
|
2007-07-23 22:02:17 +00:00
|
|
|
return profile;
|
|
|
|
}
|