2005-11-29 23:29:45 +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 Mozilla Foundation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* 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>
|
2008-08-19 07:22:42 +04:00
|
|
|
* Karl Tomlinson <karlt+@karlt.net>, Mozilla Corporation
|
2005-11-29 23:29:45 +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 ***** */
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_PANGO
|
2006-04-18 19:21:42 +04:00
|
|
|
#define PANGO_ENABLE_BACKEND
|
|
|
|
#define PANGO_ENABLE_ENGINE
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif
|
2006-04-18 19:21:42 +04:00
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxPlatformGtk.h"
|
|
|
|
|
2009-09-09 19:35:08 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2007-01-30 11:20:29 +03:00
|
|
|
#include "gfxFontconfigUtils.h"
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_PANGO
|
2007-04-16 02:22:58 +04:00
|
|
|
#include "gfxPangoFonts.h"
|
2008-07-14 01:40:16 +04:00
|
|
|
#include "gfxContext.h"
|
2008-12-06 02:19:27 +03:00
|
|
|
#include "gfxUserFontSet.h"
|
2008-08-07 00:48:55 +04:00
|
|
|
#else
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#include "gfxFT2Fonts.h"
|
|
|
|
#endif
|
2006-01-10 23:26:40 +03:00
|
|
|
|
2007-01-27 05:14:19 +03:00
|
|
|
#include "cairo.h"
|
2005-11-29 23:29:45 +03:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
|
|
#include "gfxImageSurface.h"
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_X11
|
|
|
|
#include <gdk/gdkx.h>
|
2005-11-29 23:29:45 +03:00
|
|
|
#include "gfxXlibSurface.h"
|
2008-08-19 07:22:42 +04:00
|
|
|
#include "cairo-xlib.h"
|
2009-04-20 20:36:37 +04:00
|
|
|
|
|
|
|
/* Undefine the Status from Xlib since it will conflict with system headers on OSX */
|
|
|
|
#if defined(__APPLE__) && defined(Status)
|
|
|
|
#undef Status
|
|
|
|
#endif
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif /* MOZ_X11 */
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2006-01-10 23:26:40 +03:00
|
|
|
#include <fontconfig/fontconfig.h>
|
2006-11-21 09:31:04 +03:00
|
|
|
|
2007-03-23 02:01:14 +03:00
|
|
|
#include "nsMathUtils.h"
|
2007-07-24 02:02:20 +04:00
|
|
|
|
2008-11-10 02:39:41 +03:00
|
|
|
#define GDK_PIXMAP_SIZE_MAX 32767
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifndef MOZ_PANGO
|
|
|
|
#include <ft2build.h>
|
|
|
|
#include FT_FREETYPE_H
|
|
|
|
#endif
|
|
|
|
|
2007-01-30 11:20:29 +03:00
|
|
|
gfxFontconfigUtils *gfxPlatformGtk::sFontconfigUtils = nsnull;
|
2006-01-10 23:26:40 +03:00
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifndef MOZ_PANGO
|
|
|
|
typedef nsDataHashtable<nsStringHashKey, nsRefPtr<FontFamily> > FontTable;
|
2010-10-14 02:03:19 +04:00
|
|
|
typedef nsDataHashtable<nsCStringHashKey, nsTArray<nsRefPtr<gfxFontEntry> > > PrefFontTable;
|
2008-08-07 00:48:55 +04:00
|
|
|
static FontTable *gPlatformFonts = NULL;
|
|
|
|
static FontTable *gPlatformFontAliases = NULL;
|
2009-09-09 19:35:08 +04:00
|
|
|
static PrefFontTable *gPrefFonts = NULL;
|
|
|
|
static gfxSparseBitSet *gCodepointsWithNoFonts = NULL;
|
2008-08-07 00:48:55 +04:00
|
|
|
static FT_Library gPlatformFTLibrary = NULL;
|
|
|
|
#endif
|
|
|
|
|
2008-08-19 07:22:42 +04:00
|
|
|
static cairo_user_data_key_t cairo_gdk_drawable_key;
|
|
|
|
static void do_gdk_drawable_unref (void *data)
|
2007-11-27 03:22:39 +03:00
|
|
|
{
|
2008-08-19 07:22:42 +04:00
|
|
|
GdkDrawable *d = (GdkDrawable*) data;
|
|
|
|
g_object_unref (d);
|
2007-11-27 03:22:39 +03:00
|
|
|
}
|
|
|
|
|
2005-11-29 23:29:45 +03:00
|
|
|
gfxPlatformGtk::gfxPlatformGtk()
|
|
|
|
{
|
2007-01-30 11:20:29 +03:00
|
|
|
if (!sFontconfigUtils)
|
|
|
|
sFontconfigUtils = gfxFontconfigUtils::GetFontconfigUtils();
|
2007-10-06 11:26:13 +04:00
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifndef MOZ_PANGO
|
|
|
|
FT_Init_FreeType(&gPlatformFTLibrary);
|
|
|
|
|
|
|
|
gPlatformFonts = new FontTable();
|
2008-08-07 00:48:55 +04:00
|
|
|
gPlatformFonts->Init(100);
|
2008-08-07 00:48:55 +04:00
|
|
|
gPlatformFontAliases = new FontTable();
|
2008-08-07 00:48:55 +04:00
|
|
|
gPlatformFontAliases->Init(100);
|
2009-09-09 19:35:08 +04:00
|
|
|
gPrefFonts = new PrefFontTable();
|
|
|
|
gPrefFonts->Init(100);
|
|
|
|
gCodepointsWithNoFonts = new gfxSparseBitSet();
|
2008-08-07 00:48:55 +04:00
|
|
|
UpdateFontList();
|
|
|
|
#endif
|
2005-11-29 23:29:45 +03:00
|
|
|
}
|
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
gfxPlatformGtk::~gfxPlatformGtk()
|
|
|
|
{
|
|
|
|
gfxFontconfigUtils::Shutdown();
|
|
|
|
sFontconfigUtils = nsnull;
|
2007-04-16 02:22:58 +04:00
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_PANGO
|
2008-09-27 04:21:55 +04:00
|
|
|
gfxPangoFontGroup::Shutdown();
|
2008-08-07 00:48:55 +04:00
|
|
|
#else
|
|
|
|
delete gPlatformFonts;
|
|
|
|
gPlatformFonts = NULL;
|
|
|
|
delete gPlatformFontAliases;
|
|
|
|
gPlatformFontAliases = NULL;
|
2009-09-09 19:35:08 +04:00
|
|
|
delete gPrefFonts;
|
|
|
|
gPrefFonts = NULL;
|
|
|
|
delete gCodepointsWithNoFonts;
|
|
|
|
gCodepointsWithNoFonts = NULL;
|
2008-08-07 00:48:55 +04:00
|
|
|
|
2011-03-24 06:02:14 +03:00
|
|
|
#ifdef NS_FREE_PERMANENT_DATA
|
|
|
|
// do cairo cleanup *before* closing down the FTLibrary,
|
|
|
|
// otherwise we'll crash when the gfxPlatform destructor
|
|
|
|
// calls it (bug 605009)
|
|
|
|
cairo_debug_reset_static_data();
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
FT_Done_FreeType(gPlatformFTLibrary);
|
|
|
|
gPlatformFTLibrary = NULL;
|
|
|
|
#endif
|
2011-03-24 06:02:14 +03:00
|
|
|
#endif
|
2007-04-16 02:22:58 +04:00
|
|
|
|
2007-03-20 02:16:15 +03:00
|
|
|
#if 0
|
|
|
|
// It would be nice to do this (although it might need to be after
|
|
|
|
// the cairo shutdown that happens in ~gfxPlatform). It even looks
|
|
|
|
// idempotent. But it has fatal assertions that fire if stuff is
|
|
|
|
// leaked, and we hit them.
|
|
|
|
FcFini();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2006-03-25 03:34:48 +03:00
|
|
|
already_AddRefed<gfxASurface>
|
2007-02-08 23:47:48 +03:00
|
|
|
gfxPlatformGtk::CreateOffscreenSurface(const gfxIntSize& size,
|
2010-09-17 01:34:53 +04:00
|
|
|
gfxASurface::gfxContentType contentType)
|
2005-11-29 23:29:45 +03:00
|
|
|
{
|
2010-11-19 19:56:05 +03:00
|
|
|
nsRefPtr<gfxASurface> newSurface;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needsClear = true;
|
2010-09-17 01:34:53 +04:00
|
|
|
gfxASurface::gfxImageFormat imageFormat = gfxASurface::FormatFromContent(contentType);
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_X11
|
2006-02-23 03:45:55 +03:00
|
|
|
// XXX we really need a different interface here, something that passes
|
|
|
|
// in more context, including the display and/or target surface type that
|
|
|
|
// we should try to match
|
2010-07-02 07:55:24 +04:00
|
|
|
GdkScreen *gdkScreen = gdk_screen_get_default();
|
|
|
|
if (gdkScreen) {
|
|
|
|
// try to optimize it for 16bpp default screen
|
2010-12-15 21:17:26 +03:00
|
|
|
if (gfxASurface::CONTENT_COLOR == contentType) {
|
|
|
|
imageFormat = GetOffscreenFormat();
|
|
|
|
}
|
2010-07-02 07:55:24 +04:00
|
|
|
|
2010-09-24 05:00:06 +04:00
|
|
|
if (UseClientSideRendering()) {
|
|
|
|
// We're not going to use XRender, so we don't need to
|
|
|
|
// search for a render format
|
|
|
|
newSurface = new gfxImageSurface(size, imageFormat);
|
|
|
|
// The gfxImageSurface ctor zeroes this for us, no need to
|
|
|
|
// waste time clearing again
|
2011-10-17 18:59:28 +04:00
|
|
|
needsClear = false;
|
2010-09-24 05:00:06 +04:00
|
|
|
} else {
|
|
|
|
Screen *screen = gdk_x11_screen_get_xscreen(gdkScreen);
|
|
|
|
XRenderPictFormat* xrenderFormat =
|
|
|
|
gfxXlibSurface::FindRenderFormat(DisplayOfScreen(screen),
|
|
|
|
imageFormat);
|
|
|
|
|
|
|
|
if (xrenderFormat) {
|
|
|
|
newSurface = gfxXlibSurface::Create(screen, xrenderFormat, size);
|
|
|
|
}
|
2007-11-27 03:22:39 +03:00
|
|
|
}
|
2008-09-30 21:53:38 +04:00
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif
|
2005-11-29 23:29:45 +03:00
|
|
|
|
2008-11-10 02:39:41 +03:00
|
|
|
if (!newSurface) {
|
|
|
|
// We couldn't create a native surface for whatever reason;
|
2010-07-02 07:55:24 +04:00
|
|
|
// e.g., no display, no RENDER, bad size, etc.
|
2008-11-10 02:39:41 +03:00
|
|
|
// Fall back to image surface for the data.
|
2010-09-24 05:00:06 +04:00
|
|
|
newSurface = new gfxImageSurface(size, imageFormat);
|
2008-11-10 02:39:41 +03:00
|
|
|
}
|
|
|
|
|
2010-11-19 19:56:05 +03:00
|
|
|
if (newSurface->CairoStatus()) {
|
|
|
|
newSurface = nsnull; // surface isn't valid for some reason
|
|
|
|
}
|
|
|
|
|
2010-09-24 05:00:06 +04:00
|
|
|
if (newSurface && needsClear) {
|
2008-07-14 01:40:16 +04:00
|
|
|
gfxContext tmpCtx(newSurface);
|
|
|
|
tmpCtx.SetOperator(gfxContext::OPERATOR_CLEAR);
|
|
|
|
tmpCtx.Paint();
|
|
|
|
}
|
|
|
|
|
2007-11-27 04:40:03 +03:00
|
|
|
return newSurface.forget();
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_PANGO
|
|
|
|
|
2006-01-10 23:26:40 +03:00
|
|
|
nsresult
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
|
2006-01-10 23:26:40 +03:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2006-01-10 23:26:40 +03:00
|
|
|
{
|
2007-01-30 11:20:29 +03:00
|
|
|
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
|
|
|
|
aListOfFonts);
|
2006-11-21 09:31:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::UpdateFontList()
|
|
|
|
{
|
2007-01-30 11:20:29 +03:00
|
|
|
return sFontconfigUtils->UpdateFontList();
|
2006-11-21 09:31:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aAborted)
|
2006-11-21 09:31:04 +03:00
|
|
|
{
|
2007-01-30 11:20:29 +03:00
|
|
|
return sFontconfigUtils->ResolveFontName(aFontName, aCallback,
|
|
|
|
aClosure, aAborted);
|
2006-01-10 23:26:40 +03:00
|
|
|
}
|
2006-04-18 19:21:42 +04:00
|
|
|
|
2008-03-13 13:32:50 +03:00
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
}
|
|
|
|
|
2007-04-02 23:06:16 +04:00
|
|
|
gfxFontGroup *
|
|
|
|
gfxPlatformGtk::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
|
|
|
{
|
2008-10-01 07:01:53 +04:00
|
|
|
return new gfxPangoFontGroup(aFamilies, aStyle, aUserFontSet);
|
2007-04-02 23:06:16 +04:00
|
|
|
}
|
|
|
|
|
2009-01-03 06:21:49 +03:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxPlatformGtk::LookupLocalFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const nsAString& aFontName)
|
|
|
|
{
|
|
|
|
return gfxPangoFontGroup::NewFontEntry(*aProxyEntry, aFontName);
|
|
|
|
}
|
|
|
|
|
2008-12-06 02:19:27 +03:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxPlatformGtk::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const PRUint8 *aFontData, PRUint32 aLength)
|
|
|
|
{
|
2009-08-30 17:55:24 +04:00
|
|
|
// passing ownership of the font data to the new font entry
|
|
|
|
return gfxPangoFontGroup::NewFontEntry(*aProxyEntry,
|
2008-12-06 02:19:27 +03:00
|
|
|
aFontData, aLength);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-12-06 02:19:27 +03:00
|
|
|
gfxPlatformGtk::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");
|
2008-12-06 02:19:27 +03:00
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// accept supported formats
|
2008-12-06 02:19:27 +03:00
|
|
|
// 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.
|
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)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-01-13 08:16:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-12-06 02:19:27 +03:00
|
|
|
}
|
|
|
|
|
2009-01-13 08:16:58 +03:00
|
|
|
// no format hint set, need to look at data
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-12-06 02:19:27 +03:00
|
|
|
}
|
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
#else
|
|
|
|
|
|
|
|
nsresult
|
2010-10-14 02:03:19 +04:00
|
|
|
gfxPlatformGtk::GetFontList(nsIAtom *aLangGroup,
|
2008-08-07 00:48:55 +04:00
|
|
|
const nsACString& aGenericFamily,
|
2009-01-18 23:14:14 +03:00
|
|
|
nsTArray<nsString>& aListOfFonts)
|
2008-08-07 00:48:55 +04:00
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetFontList(aLangGroup, aGenericFamily,
|
|
|
|
aListOfFonts);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::UpdateFontList()
|
|
|
|
{
|
|
|
|
FcPattern *pat = NULL;
|
|
|
|
FcObjectSet *os = NULL;
|
|
|
|
FcFontSet *fs = NULL;
|
|
|
|
PRInt32 result = -1;
|
|
|
|
|
|
|
|
pat = FcPatternCreate();
|
|
|
|
os = FcObjectSetBuild(FC_FAMILY, FC_FILE, FC_INDEX, FC_WEIGHT, FC_SLANT, FC_WIDTH, NULL);
|
|
|
|
|
|
|
|
fs = FcFontList(NULL, pat, os);
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < fs->nfont; i++) {
|
|
|
|
char *str;
|
|
|
|
|
|
|
|
if (FcPatternGetString(fs->fonts[i], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
//printf("Family: %s\n", str);
|
|
|
|
|
|
|
|
nsAutoString name(NS_ConvertUTF8toUTF16(nsDependentCString(str)).get());
|
|
|
|
nsAutoString key(name);
|
2009-09-09 19:35:08 +04:00
|
|
|
ToLowerCase(key);
|
2008-08-07 00:48:55 +04:00
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!gPlatformFonts->Get(key, &ff)) {
|
|
|
|
ff = new FontFamily(name);
|
|
|
|
gPlatformFonts->Put(key, ff);
|
|
|
|
}
|
|
|
|
|
2009-09-09 19:35:08 +04:00
|
|
|
FontEntry *fe = new FontEntry(ff->Name());
|
2009-08-18 12:26:24 +04:00
|
|
|
ff->AddFontEntry(fe);
|
2008-08-07 00:48:55 +04:00
|
|
|
|
|
|
|
if (FcPatternGetString(fs->fonts[i], FC_FILE, 0, (FcChar8 **) &str) == FcResultMatch) {
|
|
|
|
fe->mFilename = nsDependentCString(str);
|
|
|
|
//printf(" - file: %s\n", str);
|
|
|
|
}
|
|
|
|
|
|
|
|
int x;
|
|
|
|
if (FcPatternGetInteger(fs->fonts[i], FC_INDEX, 0, &x) == FcResultMatch) {
|
|
|
|
//printf(" - index: %d\n", x);
|
|
|
|
fe->mFTFontIndex = x;
|
|
|
|
} else {
|
|
|
|
fe->mFTFontIndex = 0;
|
|
|
|
}
|
|
|
|
|
2008-09-16 08:40:57 +04:00
|
|
|
fe->mWeight = gfxFontconfigUtils::GetThebesWeight(fs->fonts[i]);
|
|
|
|
//printf(" - weight: %d\n", fe->mWeight);
|
2008-08-07 00:48:55 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
fe->mItalic = false;
|
2008-08-07 00:48:55 +04:00
|
|
|
if (FcPatternGetInteger(fs->fonts[i], FC_SLANT, 0, &x) == FcResultMatch) {
|
|
|
|
switch (x) {
|
|
|
|
case FC_SLANT_ITALIC:
|
|
|
|
case FC_SLANT_OBLIQUE:
|
2011-10-17 18:59:28 +04:00
|
|
|
fe->mItalic = true;
|
2008-08-07 00:48:55 +04:00
|
|
|
}
|
|
|
|
//printf(" - slant: %d\n", x);
|
|
|
|
}
|
|
|
|
|
|
|
|
//if (FcPatternGetInteger(fs->fonts[i], FC_WIDTH, 0, &x) == FcResultMatch)
|
|
|
|
//printf(" - width: %d\n", x);
|
|
|
|
// XXX deal with font-stretch stuff later
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pat)
|
|
|
|
FcPatternDestroy(pat);
|
|
|
|
if (os)
|
|
|
|
FcObjectSetDestroy(os);
|
|
|
|
if (fs)
|
|
|
|
FcFontSetDestroy(fs);
|
|
|
|
|
|
|
|
return sFontconfigUtils->UpdateFontList();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aAborted)
|
2008-08-07 00:48:55 +04:00
|
|
|
{
|
|
|
|
|
|
|
|
nsAutoString name(aFontName);
|
2009-09-09 19:35:08 +04:00
|
|
|
ToLowerCase(name);
|
2008-08-07 00:48:55 +04:00
|
|
|
|
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (gPlatformFonts->Get(name, &ff) ||
|
|
|
|
gPlatformFontAliases->Get(name, &ff)) {
|
2009-09-09 19:35:08 +04:00
|
|
|
aAborted = !(*aCallback)(ff->Name(), aClosure);
|
2008-08-07 00:48:55 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCAutoString utf8Name = NS_ConvertUTF16toUTF8(aFontName);
|
|
|
|
|
|
|
|
FcPattern *npat = FcPatternCreate();
|
|
|
|
FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get());
|
|
|
|
FcObjectSet *nos = FcObjectSetBuild(FC_FAMILY, NULL);
|
|
|
|
FcFontSet *nfs = FcFontList(NULL, npat, nos);
|
|
|
|
|
|
|
|
for (int k = 0; k < nfs->nfont; k++) {
|
|
|
|
FcChar8 *str;
|
|
|
|
if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch)
|
|
|
|
continue;
|
|
|
|
nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str)));
|
2009-09-09 19:35:08 +04:00
|
|
|
ToLowerCase(altName);
|
2008-08-07 00:48:55 +04:00
|
|
|
if (gPlatformFonts->Get(altName, &ff)) {
|
|
|
|
//printf("Adding alias: %s -> %s\n", utf8Name.get(), str);
|
|
|
|
gPlatformFontAliases->Put(name, ff);
|
|
|
|
aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure);
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FcPatternDestroy(npat);
|
|
|
|
FcObjectSetDestroy(nos);
|
|
|
|
FcFontSetDestroy(nfs);
|
|
|
|
|
|
|
|
{
|
|
|
|
npat = FcPatternCreate();
|
|
|
|
FcPatternAddString(npat, FC_FAMILY, (FcChar8*)utf8Name.get());
|
|
|
|
FcPatternDel(npat, FC_LANG);
|
|
|
|
FcConfigSubstitute(NULL, npat, FcMatchPattern);
|
|
|
|
FcDefaultSubstitute(npat);
|
|
|
|
|
|
|
|
nos = FcObjectSetBuild(FC_FAMILY, NULL);
|
|
|
|
nfs = FcFontList(NULL, npat, nos);
|
|
|
|
|
|
|
|
FcResult fresult;
|
|
|
|
|
|
|
|
FcPattern *match = FcFontMatch(NULL, npat, &fresult);
|
|
|
|
if (match)
|
|
|
|
FcFontSetAdd(nfs, match);
|
|
|
|
|
|
|
|
for (int k = 0; k < nfs->nfont; k++) {
|
|
|
|
FcChar8 *str;
|
|
|
|
if (FcPatternGetString(nfs->fonts[k], FC_FAMILY, 0, (FcChar8 **) &str) != FcResultMatch)
|
|
|
|
continue;
|
|
|
|
nsAutoString altName = NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str)));
|
2009-09-09 19:35:08 +04:00
|
|
|
ToLowerCase(altName);
|
2008-08-07 00:48:55 +04:00
|
|
|
if (gPlatformFonts->Get(altName, &ff)) {
|
|
|
|
//printf("Adding alias: %s -> %s\n", utf8Name.get(), str);
|
|
|
|
gPlatformFontAliases->Put(name, ff);
|
|
|
|
aAborted = !(*aCallback)(NS_ConvertUTF8toUTF16(nsDependentCString(reinterpret_cast<char*>(str))), aClosure);
|
|
|
|
goto DONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DONE:
|
|
|
|
FcPatternDestroy(npat);
|
|
|
|
FcObjectSetDestroy(nos);
|
|
|
|
FcFontSetDestroy(nfs);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxPlatformGtk::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
|
|
|
return sFontconfigUtils->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFontGroup *
|
|
|
|
gfxPlatformGtk::CreateFontGroup(const nsAString &aFamilies,
|
2010-10-14 02:03:19 +04:00
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet *aUserFontSet)
|
2008-08-07 00:48:55 +04:00
|
|
|
{
|
2010-10-14 02:03:19 +04:00
|
|
|
return new gfxFT2FontGroup(aFamilies, aStyle, aUserFontSet);
|
2008-08-07 00:48:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2010-08-13 13:58:01 +04:00
|
|
|
static PRInt32 sDPI = 0;
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
gfxPlatformGtk::GetDPI()
|
2007-03-23 02:01:14 +03:00
|
|
|
{
|
2010-08-13 13:58:01 +04:00
|
|
|
if (!sDPI) {
|
|
|
|
// Make sure init is run so we have a resolution
|
|
|
|
GdkScreen *screen = gdk_screen_get_default();
|
|
|
|
gtk_settings_get_for_screen(screen);
|
|
|
|
sDPI = PRInt32(round(gdk_screen_get_resolution(screen)));
|
|
|
|
if (sDPI <= 0) {
|
|
|
|
// Fall back to something sane
|
|
|
|
sDPI = 96;
|
|
|
|
}
|
2007-07-24 02:02:20 +04:00
|
|
|
}
|
2010-08-13 13:58:01 +04:00
|
|
|
return sDPI;
|
2007-07-24 02:02:20 +04:00
|
|
|
}
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2010-12-15 21:17:26 +03:00
|
|
|
gfxImageFormat
|
|
|
|
gfxPlatformGtk::GetOffscreenFormat()
|
|
|
|
{
|
|
|
|
if (gdk_visual_get_system()->depth == 16) {
|
|
|
|
return gfxASurface::ImageFormatRGB16_565;
|
|
|
|
}
|
|
|
|
|
|
|
|
return gfxASurface::ImageFormatRGB24;
|
|
|
|
}
|
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_profile *
|
2007-07-24 02:02:17 +04:00
|
|
|
gfxPlatformGtk::GetPlatformCMSOutputProfile()
|
|
|
|
{
|
2008-08-07 00:48:55 +04:00
|
|
|
#ifdef MOZ_X11
|
2007-07-24 02:02:17 +04:00
|
|
|
const char EDID1_ATOM_NAME[] = "XFree86_DDC_EDID1_RAWDATA";
|
|
|
|
const char ICC_PROFILE_ATOM_NAME[] = "_ICC_PROFILE";
|
|
|
|
|
|
|
|
Atom edidAtom, iccAtom;
|
|
|
|
Display *dpy = GDK_DISPLAY();
|
|
|
|
Window root = gdk_x11_get_default_root_xwindow();
|
|
|
|
|
|
|
|
Atom retAtom;
|
|
|
|
int retFormat;
|
|
|
|
unsigned long retLength, retAfter;
|
|
|
|
unsigned char *retProperty ;
|
|
|
|
|
|
|
|
iccAtom = XInternAtom(dpy, ICC_PROFILE_ATOM_NAME, TRUE);
|
|
|
|
if (iccAtom) {
|
|
|
|
// read once to get size, once for the data
|
|
|
|
if (Success == XGetWindowProperty(dpy, root, iccAtom,
|
|
|
|
0, 0 /* length */,
|
|
|
|
False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty)) {
|
|
|
|
XGetWindowProperty(dpy, root, iccAtom,
|
|
|
|
0, retLength,
|
|
|
|
False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty);
|
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_profile* profile = NULL;
|
2009-01-07 22:50:14 +03:00
|
|
|
|
|
|
|
if (retLength > 0)
|
2009-04-07 20:02:11 +04:00
|
|
|
profile = qcms_profile_from_memory(retProperty, retLength);
|
2007-07-24 02:02:17 +04:00
|
|
|
|
|
|
|
XFree(retProperty);
|
|
|
|
|
|
|
|
if (profile) {
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
ICC_PROFILE_ATOM_NAME);
|
|
|
|
#endif
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
edidAtom = XInternAtom(dpy, EDID1_ATOM_NAME, TRUE);
|
|
|
|
if (edidAtom) {
|
|
|
|
if (Success == XGetWindowProperty(dpy, root, edidAtom, 0, 32,
|
|
|
|
False, AnyPropertyType,
|
|
|
|
&retAtom, &retFormat, &retLength,
|
|
|
|
&retAfter, &retProperty)) {
|
|
|
|
double gamma;
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_CIE_xyY whitePoint;
|
|
|
|
qcms_CIE_xyYTRIPLE primaries;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
|
|
|
if (retLength != 128) {
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr, "Short EDID data\n");
|
|
|
|
#endif
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Format documented in "VESA E-EDID Implementation Guide"
|
|
|
|
|
|
|
|
gamma = (100 + retProperty[0x17]) / 100.0;
|
|
|
|
whitePoint.x = ((retProperty[0x21] << 2) |
|
|
|
|
(retProperty[0x1a] >> 2 & 3)) / 1024.0;
|
|
|
|
whitePoint.y = ((retProperty[0x22] << 2) |
|
|
|
|
(retProperty[0x1a] >> 0 & 3)) / 1024.0;
|
|
|
|
whitePoint.Y = 1.0;
|
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.red.x = ((retProperty[0x1b] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x19] >> 6 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.red.y = ((retProperty[0x1c] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x19] >> 4 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.red.Y = 1.0;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.green.x = ((retProperty[0x1d] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x19] >> 2 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.green.y = ((retProperty[0x1e] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x19] >> 0 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.green.Y = 1.0;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.blue.x = ((retProperty[0x1f] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x1a] >> 6 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.blue.y = ((retProperty[0x20] << 2) |
|
2007-07-24 02:02:17 +04:00
|
|
|
(retProperty[0x1a] >> 4 & 3)) / 1024.0;
|
2009-04-07 20:02:11 +04:00
|
|
|
primaries.blue.Y = 1.0;
|
2007-07-24 02:02:17 +04:00
|
|
|
|
|
|
|
XFree(retProperty);
|
|
|
|
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
fprintf(stderr, "EDID gamma: %f\n", gamma);
|
|
|
|
fprintf(stderr, "EDID whitepoint: %f %f %f\n",
|
|
|
|
whitePoint.x, whitePoint.y, whitePoint.Y);
|
|
|
|
fprintf(stderr, "EDID primaries: [%f %f %f] [%f %f %f] [%f %f %f]\n",
|
|
|
|
primaries.Red.x, primaries.Red.y, primaries.Red.Y,
|
|
|
|
primaries.Green.x, primaries.Green.y, primaries.Green.Y,
|
|
|
|
primaries.Blue.x, primaries.Blue.y, primaries.Blue.Y);
|
|
|
|
#endif
|
|
|
|
|
2009-04-07 20:02:11 +04:00
|
|
|
qcms_profile* profile =
|
|
|
|
qcms_profile_create_rgb_with_gamma(whitePoint, primaries, gamma);
|
2007-07-24 02:02:17 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_tor
|
|
|
|
if (profile) {
|
|
|
|
fprintf(stderr,
|
|
|
|
"ICM profile read from %s successfully\n",
|
|
|
|
EDID1_ATOM_NAME);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return profile;
|
|
|
|
}
|
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif
|
|
|
|
|
2007-07-24 02:02:17 +04:00
|
|
|
return nsnull;
|
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef MOZ_PANGO
|
|
|
|
FT_Library
|
|
|
|
gfxPlatformGtk::GetFTLibrary()
|
|
|
|
{
|
|
|
|
return gPlatformFTLibrary;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontFamily *
|
|
|
|
gfxPlatformGtk::FindFontFamily(const nsAString& aName)
|
|
|
|
{
|
|
|
|
nsAutoString name(aName);
|
2009-09-09 19:35:08 +04:00
|
|
|
ToLowerCase(name);
|
2008-08-07 00:48:55 +04:00
|
|
|
|
|
|
|
nsRefPtr<FontFamily> ff;
|
|
|
|
if (!gPlatformFonts->Get(name, &ff)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
return ff.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
FontEntry *
|
|
|
|
gfxPlatformGtk::FindFontEntry(const nsAString& aName, const gfxFontStyle& aFontStyle)
|
|
|
|
{
|
|
|
|
nsRefPtr<FontFamily> ff = FindFontFamily(aName);
|
|
|
|
if (!ff)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
return ff->FindFontEntry(aFontStyle);
|
|
|
|
}
|
2009-09-09 19:35:08 +04:00
|
|
|
|
|
|
|
static PLDHashOperator
|
|
|
|
FindFontForCharProc(nsStringHashKey::KeyType aKey,
|
|
|
|
nsRefPtr<FontFamily>& aFontFamily,
|
|
|
|
void* aUserArg)
|
|
|
|
{
|
|
|
|
FontSearch *data = (FontSearch*)aUserArg;
|
|
|
|
aFontFamily->FindFontForChar(data);
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxFont>
|
|
|
|
gfxPlatformGtk::FindFontForChar(PRUint32 aCh, gfxFont *aFont)
|
|
|
|
{
|
|
|
|
if (!gPlatformFonts || !gCodepointsWithNoFonts)
|
|
|
|
return nsnull;
|
|
|
|
|
|
|
|
// is codepoint with no matching font? return null immediately
|
|
|
|
if (gCodepointsWithNoFonts->test(aCh)) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
FontSearch data(aCh, aFont);
|
|
|
|
|
|
|
|
// find fonts that support the character
|
|
|
|
gPlatformFonts->Enumerate(FindFontForCharProc, &data);
|
|
|
|
|
|
|
|
if (data.mBestMatch) {
|
|
|
|
nsRefPtr<gfxFT2Font> font =
|
|
|
|
gfxFT2Font::GetOrMakeFont(static_cast<FontEntry*>(data.mBestMatch.get()),
|
|
|
|
aFont->GetStyle());
|
|
|
|
gfxFont* ret = font.forget().get();
|
|
|
|
return already_AddRefed<gfxFont>(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
// no match? add to set of non-matching codepoints
|
|
|
|
gCodepointsWithNoFonts->set(aCh);
|
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-10-14 02:03:19 +04:00
|
|
|
gfxPlatformGtk::GetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<gfxFontEntry> > *aFontEntryList)
|
2009-09-09 19:35:08 +04:00
|
|
|
{
|
|
|
|
return gPrefFonts->Get(aKey, aFontEntryList);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2010-10-14 02:03:19 +04:00
|
|
|
gfxPlatformGtk::SetPrefFontEntries(const nsCString& aKey, nsTArray<nsRefPtr<gfxFontEntry> >& aFontEntryList)
|
2009-09-09 19:35:08 +04:00
|
|
|
{
|
|
|
|
gPrefFonts->Put(aKey, aFontEntryList);
|
|
|
|
}
|
2008-08-07 00:48:55 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
gfxPlatformGtk::SetGdkDrawable(gfxASurface *target,
|
|
|
|
GdkDrawable *drawable)
|
|
|
|
{
|
|
|
|
if (target->CairoStatus())
|
|
|
|
return;
|
|
|
|
|
2009-02-02 20:49:58 +03:00
|
|
|
g_object_ref(drawable);
|
2008-08-19 07:22:42 +04:00
|
|
|
|
2008-08-07 00:48:55 +04:00
|
|
|
cairo_surface_set_user_data (target->CairoSurface(),
|
|
|
|
&cairo_gdk_drawable_key,
|
|
|
|
drawable,
|
2008-08-19 07:22:42 +04:00
|
|
|
do_gdk_drawable_unref);
|
2008-08-07 00:48:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
GdkDrawable *
|
|
|
|
gfxPlatformGtk::GetGdkDrawable(gfxASurface *target)
|
|
|
|
{
|
|
|
|
if (target->CairoStatus())
|
2010-06-23 03:11:42 +04:00
|
|
|
return NULL;
|
2008-08-07 00:48:55 +04:00
|
|
|
|
2008-08-19 07:22:42 +04:00
|
|
|
GdkDrawable *result;
|
|
|
|
|
|
|
|
result = (GdkDrawable*) cairo_surface_get_user_data (target->CairoSurface(),
|
|
|
|
&cairo_gdk_drawable_key);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
|
|
|
|
#ifdef MOZ_X11
|
2010-06-23 03:11:42 +04:00
|
|
|
if (target->GetType() != gfxASurface::SurfaceTypeXlib)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gfxXlibSurface *xs = static_cast<gfxXlibSurface*>(target);
|
|
|
|
|
|
|
|
// try looking it up in gdk's table
|
|
|
|
result = (GdkDrawable*) gdk_xid_table_lookup(xs->XDrawable());
|
|
|
|
if (result) {
|
|
|
|
SetGdkDrawable(target, result);
|
|
|
|
return result;
|
|
|
|
}
|
2010-07-02 08:04:09 +04:00
|
|
|
#endif
|
2008-08-19 07:22:42 +04:00
|
|
|
|
2010-06-23 03:11:42 +04:00
|
|
|
return NULL;
|
2008-08-07 00:48:55 +04:00
|
|
|
}
|