2006-02-22 04:44:31 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is thebes gfx code.
|
|
|
|
*
|
2009-12-22 00:50:30 +03:00
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
2006-02-22 04:44:31 +03:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
2006-11-21 09:31:04 +03:00
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2006-02-22 04:44:31 +03:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#include "gfxPlatformMac.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxQuartzSurface.h"
|
2008-02-06 09:48:47 +03:00
|
|
|
#include "gfxQuartzImageSurface.h"
|
2006-02-22 04:44:31 +03:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
#include "gfxMacPlatformFontList.h"
|
2010-03-10 15:46:41 +03:00
|
|
|
#include "gfxMacFont.h"
|
|
|
|
#include "gfxCoreTextShaper.h"
|
2008-10-01 07:01:53 +04:00
|
|
|
#include "gfxUserFontSet.h"
|
2009-03-30 04:31:51 +04:00
|
|
|
|
2008-01-31 03:23:36 +03:00
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefLocalizedString.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsCRT.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2009-03-30 04:31:51 +04:00
|
|
|
#include "nsUnicodeRange.h"
|
2008-01-31 03:23:36 +03:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2006-02-22 04:44:31 +03:00
|
|
|
gfxPlatformMac::gfxPlatformMac()
|
|
|
|
{
|
2008-04-18 13:11:47 +04:00
|
|
|
mOSXVersion = 0;
|
2008-05-01 13:07:17 +04:00
|
|
|
mFontAntiAliasingThreshold = ReadAntiAliasingThreshold();
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxPlatformMac::~gfxPlatformMac()
|
|
|
|
{
|
2010-03-10 15:46:41 +03:00
|
|
|
gfxCoreTextShaper::Shutdown();
|
2006-02-22 04:44:31 +03:00
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxPlatformMac::CreatePlatformFontList()
|
|
|
|
{
|
2010-11-08 14:02:27 +03:00
|
|
|
gfxPlatformFontList* list = new gfxMacPlatformFontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
|
|
|
return nsnull;
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2006-03-25 03:34:48 +03:00
|
|
|
already_AddRefed<gfxASurface>
|
2007-02-08 23:47:48 +03:00
|
|
|
gfxPlatformMac::CreateOffscreenSurface(const gfxIntSize& size,
|
2010-09-17 01:34:53 +04:00
|
|
|
gfxASurface::gfxContentType contentType)
|
2006-02-22 04:44:31 +03:00
|
|
|
{
|
|
|
|
gfxASurface *newSurface = nsnull;
|
|
|
|
|
2010-09-17 01:34:53 +04:00
|
|
|
newSurface = new gfxQuartzSurface(size, gfxASurface::FormatFromContent(contentType));
|
2006-02-22 04:44:31 +03:00
|
|
|
|
2006-03-25 03:34:48 +03:00
|
|
|
NS_IF_ADDREF(newSurface);
|
2006-02-22 04:44:31 +03:00
|
|
|
return newSurface;
|
|
|
|
}
|
2006-11-21 09:31:04 +03:00
|
|
|
|
2008-02-06 09:48:47 +03:00
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxPlatformMac::OptimizeImage(gfxImageSurface *aSurface,
|
|
|
|
gfxASurface::gfxImageFormat format)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
NS_ADDREF(aSurface);
|
|
|
|
return aSurface;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRefPtr<gfxASurface> ret = new gfxQuartzImageSurface(isurf);
|
|
|
|
return ret.forget();
|
|
|
|
}
|
|
|
|
|
2006-11-21 09:31:04 +03:00
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure, PRBool& aAborted)
|
|
|
|
{
|
2006-12-22 06:56:37 +03:00
|
|
|
nsAutoString resolvedName;
|
2009-08-16 17:52:12 +04:00
|
|
|
if (!gfxPlatformFontList::PlatformFontList()->
|
2006-12-22 06:56:37 +03:00
|
|
|
ResolveFontName(aFontName, resolvedName)) {
|
|
|
|
aAborted = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
aAborted = !(*aCallback)(resolvedName, aClosure);
|
2006-11-21 09:31:04 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-03-13 13:32:50 +03:00
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
2008-03-13 13:32:50 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-04-02 23:06:16 +04:00
|
|
|
gfxFontGroup *
|
|
|
|
gfxPlatformMac::CreateFontGroup(const nsAString &aFamilies,
|
2008-10-01 07:01:53 +04:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
2007-04-02 23:06:16 +04:00
|
|
|
{
|
2009-10-07 19:26:58 +04:00
|
|
|
return new gfxFontGroup(aFamilies, aStyle, aUserFontSet);
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// these will move to gfxPlatform once all platforms support the fontlist
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxFontEntry*
|
2009-01-03 06:21:49 +03:00
|
|
|
gfxPlatformMac::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName)
|
2008-10-01 07:01:53 +04:00
|
|
|
{
|
2009-08-16 17:52:12 +04:00
|
|
|
return gfxPlatformFontList::PlatformFontList()->LookupLocalFont(aProxyEntry,
|
|
|
|
aFontName);
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2008-12-06 02:19:27 +03:00
|
|
|
gfxPlatformMac::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const PRUint8 *aFontData, PRUint32 aLength)
|
2008-10-01 07:01:53 +04:00
|
|
|
{
|
2009-10-07 18:13:40 +04: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 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
gfxPlatformMac::IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags)
|
|
|
|
{
|
2009-01-13 08:16:58 +03: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 15:03:12 +04:00
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_WOFF |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
2009-01-13 08:16:58 +03:00
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT)) {
|
|
|
|
return PR_TRUE;
|
2008-10-01 07:01:53 +04:00
|
|
|
}
|
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// no format hint set, need to look at data
|
2008-10-01 07:01:53 +04:00
|
|
|
return PR_TRUE;
|
2007-04-02 23:06:16 +04:00
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// these will also move to gfxPlatform once all platforms support the fontlist
|
2006-11-22 03:52:09 +03:00
|
|
|
nsresult
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxPlatformMac::GetFontList(nsIAtom *aLangGroup,
|
2006-11-22 03:52:09 +03:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-11-22 03:52:09 +03:00
|
|
|
{
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup, aGenericFamily, aListOfFonts);
|
2006-11-22 03:52:09 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2006-12-22 06:56:37 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformMac::UpdateFontList()
|
|
|
|
{
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2006-12-22 06:56:37 +03:00
|
|
|
return NS_OK;
|
2007-02-08 23:47:48 +03:00
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2008-04-18 13:11:47 +04:00
|
|
|
PRInt32
|
|
|
|
gfxPlatformMac::OSXVersion()
|
|
|
|
{
|
|
|
|
if (!mOSXVersion) {
|
|
|
|
// minor version is not accurate, use gestaltSystemVersionMajor, gestaltSystemVersionMinor, gestaltSystemVersionBugFix for these
|
2009-08-16 17:52:12 +04:00
|
|
|
OSErr err = ::Gestalt(gestaltSystemVersion, reinterpret_cast<SInt32*>(&mOSXVersion));
|
2008-04-18 13:11:47 +04:00
|
|
|
if (err != noErr) {
|
|
|
|
//This should probably be changed when our minimum version changes
|
|
|
|
NS_ERROR("Couldn't determine OS X version, assuming 10.4");
|
|
|
|
mOSXVersion = MAC_OS_X_VERSION_10_4_HEX;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mOSXVersion;
|
|
|
|
}
|
|
|
|
|
2008-05-01 13:07:17 +04:00
|
|
|
PRUint32
|
|
|
|
gfxPlatformMac::ReadAntiAliasingThreshold()
|
|
|
|
{
|
|
|
|
PRUint32 threshold = 0; // default == no threshold
|
|
|
|
|
|
|
|
// first read prefs flag to determine whether to use the setting or not
|
|
|
|
PRBool useAntiAliasingThreshold = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs) {
|
|
|
|
PRBool enabled;
|
|
|
|
nsresult rv =
|
|
|
|
prefs->GetBoolPref("gfx.use_text_smoothing_setting", &enabled);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
useAntiAliasingThreshold = enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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 03:23:36 +03:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_profile *
|
2007-07-24 02:02:17 +04:00
|
|
|
gfxPlatformMac::GetPlatformCMSOutputProfile()
|
|
|
|
{
|
2009-10-03 22:33:55 +04:00
|
|
|
qcms_profile *profile = nsnull;
|
|
|
|
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-24 02:02:17 +04:00
|
|
|
if (err != noErr)
|
|
|
|
return nsnull;
|
|
|
|
|
2009-10-03 22:33:55 +04:00
|
|
|
// get the size of location
|
|
|
|
err = NCMGetProfileLocation(cmProfile, NULL, &locationSize);
|
|
|
|
if (err != noErr)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// 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 17:08:09 +04:00
|
|
|
#ifndef __LP64__
|
2007-07-24 02:02:17 +04:00
|
|
|
case cmFileBasedProfile: {
|
|
|
|
FSRef fsRef;
|
2009-10-03 22:33:55 +04:00
|
|
|
if (!FSpMakeFSRef(&location->u.fileLoc.spec, &fsRef)) {
|
2007-07-24 02:02:17 +04:00
|
|
|
char path[512];
|
2009-08-16 17:52:12 +04:00
|
|
|
if (!FSRefMakePath(&fsRef, reinterpret_cast<UInt8*>(path), sizeof(path))) {
|
2009-04-07 20:02:11 +04:00
|
|
|
profile = qcms_profile_from_path(path);
|
2007-07-24 02:02:17 +04:00
|
|
|
#ifdef DEBUG_tor
|
|
|
|
if (profile)
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s fileLoc successfully\n", path);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-04-22 17:08:09 +04:00
|
|
|
#endif
|
2007-07-24 02:02:17 +04:00
|
|
|
case cmPathBasedProfile:
|
2009-10-03 22:33:55 +04:00
|
|
|
profile = qcms_profile_from_path(location->u.pathLoc.path);
|
2007-07-24 02:02:17 +04: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 22:33:55 +04:00
|
|
|
fail_location:
|
|
|
|
free(location);
|
|
|
|
fail_close:
|
|
|
|
CMCloseProfile(cmProfile);
|
2007-07-24 02:02:17 +04:00
|
|
|
return profile;
|
|
|
|
}
|