2008-04-19 15:02:52 +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/. */
|
2008-04-19 15:02:52 +00:00
|
|
|
|
|
|
|
#include <QPixmap>
|
2014-02-21 02:09:02 +00:00
|
|
|
#include <QWindow>
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
2012-03-22 23:24:40 +00:00
|
|
|
#endif
|
2014-02-21 02:09:02 +00:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QScreen>
|
2008-04-19 15:02:52 +00:00
|
|
|
|
|
|
|
#include "gfxQtPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxFontconfigUtils.h"
|
|
|
|
|
2012-03-22 20:24:57 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2008-04-19 15:02:52 +00:00
|
|
|
#include "cairo.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxQPainterSurface.h"
|
2012-03-09 03:10:05 +00:00
|
|
|
#include "nsUnicodeProperties.h"
|
2008-04-19 15:02:52 +00:00
|
|
|
|
2010-03-06 13:29:55 +00:00
|
|
|
#include "gfxPangoFonts.h"
|
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxUserFontSet.h"
|
2008-04-19 15:02:52 +00:00
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
|
|
|
#include "nsMathUtils.h"
|
2009-01-18 20:14:14 +00:00
|
|
|
#include "nsTArray.h"
|
2010-02-20 03:46:54 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "gfxXlibSurface.h"
|
2014-02-21 02:09:02 +00:00
|
|
|
#include "prenv.h"
|
2010-02-20 03:46:54 +00:00
|
|
|
#endif
|
2008-04-19 15:02:52 +00:00
|
|
|
|
2009-04-07 16:02:11 +00:00
|
|
|
#include "qcms.h"
|
2008-04-19 15:02:52 +00:00
|
|
|
|
2011-06-12 02:30:16 +00:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-09 03:10:05 +00:00
|
|
|
using namespace mozilla::unicode;
|
2012-03-22 20:24:57 +00:00
|
|
|
using namespace mozilla::gfx;
|
2010-02-20 03:46:54 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
|
2008-04-19 15:02:52 +00:00
|
|
|
|
2014-01-23 18:26:40 +00:00
|
|
|
static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
|
2012-03-12 09:23:34 +00:00
|
|
|
|
2008-04-19 15:02:52 +00:00
|
|
|
gfxQtPlatform::gfxQtPlatform()
|
|
|
|
{
|
|
|
|
if (!sFontconfigUtils)
|
|
|
|
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
|
|
|
|
2014-02-21 02:09:02 +00:00
|
|
|
mScreenDepth = qApp->primaryScreen()->depth();
|
|
|
|
if (mScreenDepth == 16) {
|
2014-01-23 18:26:40 +00:00
|
|
|
sOffscreenFormat = gfxImageFormat::RGB16_565;
|
2012-03-12 09:23:34 +00:00
|
|
|
}
|
2014-01-30 07:01:16 +00:00
|
|
|
uint32_t canvasMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
|
|
|
|
uint32_t contentMask = BackendTypeBit(BackendType::CAIRO) | BackendTypeBit(BackendType::SKIA);
|
|
|
|
InitBackendPrefs(canvasMask, BackendType::CAIRO,
|
|
|
|
contentMask, BackendType::CAIRO);
|
2008-04-19 15:02:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxQtPlatform::~gfxQtPlatform()
|
|
|
|
{
|
|
|
|
gfxFontconfigUtils::Shutdown();
|
2012-07-30 14:20:58 +00:00
|
|
|
sFontconfigUtils = nullptr;
|
2008-04-19 15:02:52 +00:00
|
|
|
|
2010-03-06 13:29:55 +00:00
|
|
|
gfxPangoFontGroup::Shutdown();
|
2008-04-19 15:02:52 +00:00
|
|
|
}
|
|
|
|
|
2012-03-22 23:24:40 +00:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
Display*
|
2014-02-21 02:09:02 +00:00
|
|
|
gfxQtPlatform::GetXDisplay(QWindow* aWindow)
|
2012-03-22 23:24:40 +00:00
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
return (Display*)(qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-22 23:24:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Screen*
|
2014-02-21 02:09:02 +00:00
|
|
|
gfxQtPlatform::GetXScreen(QWindow* aWindow)
|
2012-03-22 23:24:40 +00:00
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
return ScreenOfDisplay(GetXDisplay(aWindow),
|
|
|
|
(int)(intptr_t)qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-22 23:24:40 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 15:02:52 +00:00
|
|
|
already_AddRefed<gfxASurface>
|
2014-02-09 08:04:38 +00:00
|
|
|
gfxQtPlatform::CreateOffscreenSurface(const IntSize& size,
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxContentType contentType)
|
2008-04-19 15:02:52 +00:00
|
|
|
{
|
2013-09-24 20:45:13 +00:00
|
|
|
gfxImageFormat imageFormat = OptimalFormatForContent(contentType);
|
2010-06-11 09:33:22 +00:00
|
|
|
|
2014-02-21 02:09:02 +00:00
|
|
|
nsRefPtr<gfxASurface> newSurface =
|
|
|
|
new gfxImageSurface(gfxIntSize(size.width, size.height), imageFormat);
|
2010-02-20 03:46:54 +00:00
|
|
|
|
2014-02-21 02:09:02 +00:00
|
|
|
return newSurface.forget();
|
|
|
|
}
|
2010-02-20 03:46:54 +00:00
|
|
|
|
2008-04-19 15:02:52 +00:00
|
|
|
nsresult
|
2010-02-24 17:57:57 +00:00
|
|
|
gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2008-04-19 15:02:52 +00:00
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
|
|
|
|
aListOfFonts);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxQtPlatform::UpdateFontList()
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->UpdateFontList();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxQtPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontGroup *
|
2014-06-06 06:09:23 +00:00
|
|
|
gfxQtPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2008-10-08 14:06:09 +00:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
2008-04-19 15:02:52 +00:00
|
|
|
{
|
2014-06-06 06:09:23 +00:00
|
|
|
return new gfxPangoFontGroup(aFontFamilyList, aStyle, aUserFontSet);
|
2010-03-06 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxQtPlatform::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic)
|
2010-03-06 13:29:55 +00:00
|
|
|
{
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
|
|
|
aStretch, aItalic);
|
2008-04-19 15:02:52 +00:00
|
|
|
}
|
|
|
|
|
2010-03-06 13:29:55 +00:00
|
|
|
gfxFontEntry*
|
2014-09-08 07:23:19 +00:00
|
|
|
gfxQtPlatform::MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
|
|
|
bool aItalic,
|
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength)
|
2010-03-06 13:29:55 +00:00
|
|
|
{
|
|
|
|
// passing ownership of the font data to the new font entry
|
2014-09-08 07:23:19 +00:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
|
|
|
aStretch, aItalic,
|
2010-03-06 13:29:55 +00:00
|
|
|
aFontData, aLength);
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2010-03-06 13:29:55 +00:00
|
|
|
{
|
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
|
|
|
// Pango doesn't apply features from AAT TrueType extensions.
|
|
|
|
// Assume that if this is the only SFNT format specified,
|
|
|
|
// then AAT extensions are required for complex script support.
|
2014-10-04 10:36:05 +00:00
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-03-06 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2010-03-06 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2010-03-06 13:29:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-21 02:09:02 +00:00
|
|
|
void
|
|
|
|
gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
|
2008-04-19 15:02:52 +00:00
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
mem = nullptr;
|
|
|
|
size = 0;
|
2008-04-19 15:02:52 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t
|
2010-08-13 09:58:01 +00:00
|
|
|
gfxQtPlatform::GetDPI()
|
2010-03-10 14:36:47 +00:00
|
|
|
{
|
2014-02-21 02:09:02 +00:00
|
|
|
return qApp->primaryScreen()->logicalDotsPerInch();
|
2010-03-10 14:36:47 +00:00
|
|
|
}
|
2010-12-15 18:17:26 +00:00
|
|
|
|
|
|
|
gfxImageFormat
|
|
|
|
gfxQtPlatform::GetOffscreenFormat()
|
|
|
|
{
|
2012-03-12 09:23:34 +00:00
|
|
|
return sOffscreenFormat;
|
2010-12-15 18:17:26 +00:00
|
|
|
}
|
2012-03-22 20:24:57 +00:00
|
|
|
|
2012-08-01 19:00:24 +00:00
|
|
|
int
|
|
|
|
gfxQtPlatform::GetScreenDepth() const
|
|
|
|
{
|
|
|
|
return mScreenDepth;
|
|
|
|
}
|
|
|
|
|
2014-01-30 07:01:16 +00:00
|
|
|
TemporaryRef<ScaledFont>
|
|
|
|
gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont)
|
|
|
|
{
|
|
|
|
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
|
|
|
|
}
|