2008-04-19 19:02:52 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 15:12:37 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2008-04-19 19:02:52 +04:00
|
|
|
|
|
|
|
#include <QPixmap>
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <QWindow>
|
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <qpa/qplatformnativeinterface.h>
|
2012-03-23 03:24:40 +04:00
|
|
|
#endif
|
2014-02-21 06:09:02 +04:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QScreen>
|
2008-04-19 19:02:52 +04:00
|
|
|
|
|
|
|
#include "gfxQtPlatform.h"
|
|
|
|
|
|
|
|
#include "gfxFontconfigUtils.h"
|
|
|
|
|
2012-03-23 00:24:57 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
|
|
|
|
2008-04-19 19:02:52 +04:00
|
|
|
#include "cairo.h"
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
|
|
|
#include "gfxQPainterSurface.h"
|
2012-03-09 07:10:05 +04:00
|
|
|
#include "nsUnicodeProperties.h"
|
2008-04-19 19:02:52 +04:00
|
|
|
|
2015-05-20 18:44:09 +03:00
|
|
|
#include "gfxFontconfigFonts.h"
|
2010-03-06 16:29:55 +03:00
|
|
|
#include "gfxContext.h"
|
|
|
|
#include "gfxUserFontSet.h"
|
2008-04-19 19:02:52 +04:00
|
|
|
|
|
|
|
#include "nsUnicharUtils.h"
|
|
|
|
|
|
|
|
#include "nsMathUtils.h"
|
2009-01-18 23:14:14 +03:00
|
|
|
#include "nsTArray.h"
|
2010-02-20 06:46:54 +03:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include "gfxXlibSurface.h"
|
2014-02-21 06:09:02 +04:00
|
|
|
#include "prenv.h"
|
2010-02-20 06:46:54 +03:00
|
|
|
#endif
|
2008-04-19 19:02:52 +04:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
#include "qcms.h"
|
2008-04-19 19:02:52 +04:00
|
|
|
|
2011-06-12 06:30:16 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
|
|
|
|
|
|
|
using namespace mozilla;
|
2012-03-09 07:10:05 +04:00
|
|
|
using namespace mozilla::unicode;
|
2012-03-23 00:24:57 +04:00
|
|
|
using namespace mozilla::gfx;
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
gfxFontconfigUtils *gfxQtPlatform::sFontconfigUtils = nullptr;
|
2008-04-19 19:02:52 +04:00
|
|
|
|
2014-01-23 22:26:40 +04:00
|
|
|
static gfxImageFormat sOffscreenFormat = gfxImageFormat::RGB24;
|
2012-03-12 13:23:34 +04:00
|
|
|
|
2008-04-19 19:02:52 +04:00
|
|
|
gfxQtPlatform::gfxQtPlatform()
|
|
|
|
{
|
|
|
|
if (!sFontconfigUtils)
|
|
|
|
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
|
|
|
|
2015-08-27 01:37:48 +03:00
|
|
|
int32_t depth = GetScreenDepth();
|
|
|
|
if (depth == 16) {
|
2014-01-23 22:26:40 +04:00
|
|
|
sOffscreenFormat = gfxImageFormat::RGB16_565;
|
2012-03-12 13:23:34 +04:00
|
|
|
}
|
2014-01-30 11:01:16 +04: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 19:02:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxQtPlatform::~gfxQtPlatform()
|
|
|
|
{
|
|
|
|
gfxFontconfigUtils::Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
sFontconfigUtils = nullptr;
|
2008-04-19 19:02:52 +04:00
|
|
|
|
2010-03-06 16:29:55 +03:00
|
|
|
gfxPangoFontGroup::Shutdown();
|
2008-04-19 19:02:52 +04:00
|
|
|
}
|
|
|
|
|
2012-03-23 03:24:40 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
Display*
|
2014-02-21 06:09:02 +04:00
|
|
|
gfxQtPlatform::GetXDisplay(QWindow* aWindow)
|
2012-03-23 03:24:40 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return (Display*)(qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("display", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-23 03:24:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
Screen*
|
2014-02-21 06:09:02 +04:00
|
|
|
gfxQtPlatform::GetXScreen(QWindow* aWindow)
|
2012-03-23 03:24:40 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return ScreenOfDisplay(GetXDisplay(aWindow),
|
|
|
|
(int)(intptr_t)qApp->platformNativeInterface()->
|
|
|
|
nativeResourceForScreen("screen", aWindow ? aWindow->screen() : qApp->primaryScreen()));
|
2012-03-23 03:24:40 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-04-19 19:02:52 +04:00
|
|
|
already_AddRefed<gfxASurface>
|
2015-07-07 04:21:47 +03:00
|
|
|
gfxQtPlatform::CreateOffscreenSurface(const IntSize& aSize,
|
|
|
|
gfxImageFormat aFormat)
|
2008-04-19 19:02:52 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxASurface> newSurface =
|
2015-07-07 04:21:47 +03:00
|
|
|
new gfxImageSurface(aSize, aFormat);
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
return newSurface.forget();
|
|
|
|
}
|
2010-02-20 06:46:54 +03:00
|
|
|
|
2008-04-19 19:02:52 +04:00
|
|
|
nsresult
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxQtPlatform::GetFontList(nsIAtom *aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2008-04-19 19:02:52 +04: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 10:09:23 +04:00
|
|
|
gfxQtPlatform::CreateFontGroup(const FontFamilyList& aFontFamilyList,
|
2008-10-08 18:06:09 +04:00
|
|
|
const gfxFontStyle *aStyle,
|
2015-09-11 07:24:33 +03:00
|
|
|
gfxTextPerfMetrics* aTextPerf,
|
2008-10-08 18:06:09 +04:00
|
|
|
gfxUserFontSet* aUserFontSet)
|
2008-04-19 19:02:52 +04:00
|
|
|
{
|
2014-06-06 10:09:23 +04:00
|
|
|
return new gfxPangoFontGroup(aFontFamilyList, aStyle, aUserFontSet);
|
2010-03-06 16:29:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontEntry*
|
2014-09-08 11:23:19 +04:00
|
|
|
gfxQtPlatform::LookupLocalFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle)
|
2010-03-06 16:29:55 +03:00
|
|
|
{
|
2014-09-08 11:23:19 +04:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStretch, aStyle);
|
2008-04-19 19:02:52 +04:00
|
|
|
}
|
|
|
|
|
2010-03-06 16:29:55 +03:00
|
|
|
gfxFontEntry*
|
2014-09-08 11:23:19 +04:00
|
|
|
gfxQtPlatform::MakePlatformFont(const nsAString& aFontName,
|
|
|
|
uint16_t aWeight,
|
|
|
|
int16_t aStretch,
|
2015-10-19 05:16:43 +03:00
|
|
|
uint8_t aStyle,
|
2014-09-08 11:23:19 +04:00
|
|
|
const uint8_t* aFontData,
|
|
|
|
uint32_t aLength)
|
2010-03-06 16:29:55 +03:00
|
|
|
{
|
|
|
|
// passing ownership of the font data to the new font entry
|
2014-09-08 11:23:19 +04:00
|
|
|
return gfxPangoFontGroup::NewFontEntry(aFontName, aWeight,
|
2015-10-19 05:16:43 +03:00
|
|
|
aStretch, aStyle,
|
2010-03-06 16:29:55 +03:00
|
|
|
aFontData, aLength);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
gfxQtPlatform::IsFontFormatSupported(nsIURI *aFontURI, uint32_t aFormatFlags)
|
2010-03-06 16:29:55 +03: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 14:36:05 +04:00
|
|
|
if (aFormatFlags & gfxUserFontSet::FLAG_FORMATS_COMMON) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-03-06 16:29:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-03-06 16:29:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-03-06 16:29:55 +03:00
|
|
|
}
|
|
|
|
|
2014-02-21 06:09:02 +04:00
|
|
|
void
|
|
|
|
gfxQtPlatform::GetPlatformCMSOutputProfile(void *&mem, size_t &size)
|
2008-04-19 19:02:52 +04:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
mem = nullptr;
|
|
|
|
size = 0;
|
2008-04-19 19:02:52 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2010-08-13 13:58:01 +04:00
|
|
|
gfxQtPlatform::GetDPI()
|
2010-03-10 17:36:47 +03:00
|
|
|
{
|
2014-02-21 06:09:02 +04:00
|
|
|
return qApp->primaryScreen()->logicalDotsPerInch();
|
2010-03-10 17:36:47 +03:00
|
|
|
}
|
2010-12-15 21:17:26 +03:00
|
|
|
|
|
|
|
gfxImageFormat
|
|
|
|
gfxQtPlatform::GetOffscreenFormat()
|
|
|
|
{
|
2012-03-12 13:23:34 +04:00
|
|
|
return sOffscreenFormat;
|
2010-12-15 21:17:26 +03:00
|
|
|
}
|
2012-03-23 00:24:57 +04:00
|
|
|
|
2015-06-17 17:00:52 +03:00
|
|
|
already_AddRefed<ScaledFont>
|
2014-01-30 11:01:16 +04:00
|
|
|
gfxQtPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont* aFont)
|
|
|
|
{
|
|
|
|
return GetScaledFontForFontWithCairoSkia(aTarget, aFont);
|
|
|
|
}
|