2011-03-11 01:07:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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/. */
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
#include "gfxAndroidPlatform.h"
|
2011-11-02 23:55:03 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2011-09-23 15:15:36 +04:00
|
|
|
#include "gfxFT2FontList.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
#include "gfxImageSurface.h"
|
2012-02-09 02:52:57 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-03-14 00:59:26 +04:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
|
2011-09-23 15:15:36 +04:00
|
|
|
#include "cairo.h"
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
2011-11-02 23:55:03 +04:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
static FT_Library gPlatformFTLibrary = NULL;
|
|
|
|
|
2011-01-13 07:04:42 +03:00
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoFonts" , ## args)
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
gfxAndroidPlatform::gfxAndroidPlatform()
|
|
|
|
{
|
|
|
|
FT_Init_FreeType(&gPlatformFTLibrary);
|
2012-03-14 00:59:26 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
2012-05-15 23:41:20 +04:00
|
|
|
mScreenDepth = 24;
|
|
|
|
screen->GetColorDepth(&mScreenDepth);
|
2012-03-14 00:59:26 +04:00
|
|
|
|
2012-05-15 23:41:20 +04:00
|
|
|
mOffscreenFormat = mScreenDepth == 16
|
|
|
|
? gfxASurface::ImageFormatRGB16_565
|
2012-06-12 07:41:46 +04:00
|
|
|
: gfxASurface::ImageFormatRGB24;
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxAndroidPlatform::~gfxAndroidPlatform()
|
|
|
|
{
|
|
|
|
cairo_debug_reset_static_data();
|
|
|
|
|
|
|
|
FT_Done_FreeType(gPlatformFTLibrary);
|
|
|
|
gPlatformFTLibrary = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxAndroidPlatform::CreateOffscreenSurface(const gfxIntSize& size,
|
2010-09-17 01:34:53 +04:00
|
|
|
gfxASurface::gfxContentType contentType)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
2010-06-29 10:42:28 +04:00
|
|
|
nsRefPtr<gfxASurface> newSurface;
|
2012-05-26 08:38:17 +04:00
|
|
|
newSurface = new gfxImageSurface(size, OptimalFormatForContent(contentType));
|
2010-05-11 21:27:36 +04:00
|
|
|
|
|
|
|
return newSurface.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::GetFontList(nsIAtom *aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
|
|
|
{
|
2011-09-23 15:15:36 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup,
|
|
|
|
aGenericFamily,
|
|
|
|
aListOfFonts);
|
2010-05-11 21:27:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-13 07:04:42 +03:00
|
|
|
void
|
|
|
|
gfxAndroidPlatform::GetFontList(InfallibleTArray<FontListEntry>* retValue)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
2011-09-23 15:15:36 +04:00
|
|
|
gfxFT2FontList::PlatformFontList()->GetFontList(retValue);
|
2011-01-13 07:04:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::UpdateFontList()
|
|
|
|
{
|
2011-09-23 15:15:36 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2010-05-11 21:27:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aAborted)
|
2010-05-11 21:27:36 +04:00
|
|
|
{
|
2010-07-16 10:03:45 +04:00
|
|
|
nsAutoString resolvedName;
|
2011-09-23 15:15:36 +04:00
|
|
|
if (!gfxPlatformFontList::PlatformFontList()->
|
|
|
|
ResolveFontName(aFontName, resolvedName)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aAborted = false;
|
2011-09-23 15:15:36 +04:00
|
|
|
return NS_OK;
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
2011-09-23 15:15:36 +04:00
|
|
|
aAborted = !(*aCallback)(resolvedName, aClosure);
|
2010-05-11 21:27:36 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2011-09-23 15:15:36 +04:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
return NS_OK;
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
2010-07-16 10:03:45 +04:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxAndroidPlatform::CreatePlatformFontList()
|
|
|
|
{
|
2010-11-08 14:02:27 +03:00
|
|
|
gfxPlatformFontList* list = new gfxFT2FontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-07-16 10:03:45 +04:00
|
|
|
gfxAndroidPlatform::IsFontFormatSupported(nsIURI *aFontURI, PRUint32 aFormatFlags)
|
|
|
|
{
|
|
|
|
// check for strange format flags
|
|
|
|
NS_ASSERTION(!(aFormatFlags & gfxUserFontSet::FLAG_FORMAT_NOT_USED),
|
|
|
|
"strange font format hint set");
|
|
|
|
|
|
|
|
// accept supported formats
|
2011-03-23 04:40:00 +03:00
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_WOFF |
|
2010-07-16 10:03:45 +04:00
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-07-16 10:03:45 +04:00
|
|
|
}
|
|
|
|
|
2010-05-11 21:27:36 +04:00
|
|
|
gfxFontGroup *
|
|
|
|
gfxAndroidPlatform::CreateFontGroup(const nsAString &aFamilies,
|
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
|
|
|
{
|
2011-09-23 15:15:36 +04:00
|
|
|
return new gfxFontGroup(aFamilies, aStyle, aUserFontSet);
|
2010-05-11 21:27:36 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_Library
|
|
|
|
gfxAndroidPlatform::GetFTLibrary()
|
|
|
|
{
|
|
|
|
return gPlatformFTLibrary;
|
|
|
|
}
|
|
|
|
|
2010-07-16 10:03:45 +04:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxAndroidPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const PRUint8 *aFontData, PRUint32 aLength)
|
|
|
|
{
|
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aProxyEntry,
|
|
|
|
aFontData,
|
|
|
|
aLength);
|
|
|
|
}
|
|
|
|
|
2011-11-02 23:55:03 +04:00
|
|
|
RefPtr<ScaledFont>
|
2012-07-24 14:18:37 +04:00
|
|
|
gfxAndroidPlatform::GetScaledFontForFont(DrawTarget* aTarget, gfxFont *aFont)
|
2011-11-02 23:55:03 +04:00
|
|
|
{
|
2012-07-26 10:48:24 +04:00
|
|
|
NativeFont nativeFont;
|
2012-07-24 14:18:39 +04:00
|
|
|
if (aTarget->GetType() == BACKEND_CAIRO) {
|
|
|
|
nativeFont.mType = NATIVE_FONT_CAIRO_FONT_FACE;
|
|
|
|
nativeFont.mFont = NULL;
|
|
|
|
return Factory::CreateScaledFontWithCairo(nativeFont, aFont->GetAdjustedSize(), aFont->GetCairoScaledFont());
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font");
|
2011-11-02 23:55:03 +04:00
|
|
|
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
|
2012-05-17 02:30:10 +04:00
|
|
|
nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions();
|
2012-07-24 14:18:39 +04:00
|
|
|
return Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
|
2011-11-02 23:55:03 +04:00
|
|
|
}
|
|
|
|
|
2012-02-09 02:52:57 +04:00
|
|
|
bool
|
|
|
|
gfxAndroidPlatform::FontHintingEnabled()
|
|
|
|
{
|
|
|
|
// In "mobile" builds, we sometimes use non-reflow-zoom, so we
|
|
|
|
// might not want hinting. Let's see.
|
|
|
|
#ifdef MOZ_USING_ANDROID_JAVA_WIDGETS
|
|
|
|
// On android-java, we currently only use gecko to render web
|
|
|
|
// content that can always be be non-reflow-zoomed. So turn off
|
|
|
|
// hinting.
|
|
|
|
//
|
|
|
|
// XXX when gecko-android-java is used as an "app runtime", we'll
|
|
|
|
// want to re-enable hinting.
|
|
|
|
return false;
|
|
|
|
#else
|
|
|
|
// Otherwise, if we're in a content process, assume we don't want
|
|
|
|
// hinting.
|
|
|
|
//
|
|
|
|
// XXX when we use content processes to load "apps", we'll want to
|
|
|
|
// configure this dynamically based on whether we're an "app
|
|
|
|
// content process" or a "browser content process". The former
|
|
|
|
// wants hinting, the latter doesn't since it might be
|
|
|
|
// non-reflow-zoomed.
|
|
|
|
return (XRE_GetProcessType() != GeckoProcessType_Content);
|
|
|
|
#endif // MOZ_USING_ANDROID_JAVA_WIDGETS
|
|
|
|
}
|
2012-05-15 23:41:20 +04:00
|
|
|
|
|
|
|
int
|
|
|
|
gfxAndroidPlatform::GetScreenDepth() const
|
|
|
|
{
|
|
|
|
return mScreenDepth;
|
|
|
|
}
|