2011-03-10 14:07:55 -08:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 04:12:37 -07: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 10:27:36 -07:00
|
|
|
|
|
|
|
#include "gfxAndroidPlatform.h"
|
2011-11-02 12:55:03 -07:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2010-05-11 10:27:36 -07:00
|
|
|
|
2011-09-23 04:15:36 -07:00
|
|
|
#include "gfxFT2FontList.h"
|
2010-05-11 10:27:36 -07:00
|
|
|
#include "gfxImageSurface.h"
|
2012-02-08 14:52:57 -08:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-03-13 13:59:26 -07:00
|
|
|
#include "nsIScreen.h"
|
|
|
|
#include "nsIScreenManager.h"
|
2010-05-11 10:27:36 -07:00
|
|
|
|
2011-09-23 04:15:36 -07:00
|
|
|
#include "cairo.h"
|
2010-05-11 10:27:36 -07:00
|
|
|
|
|
|
|
#include "ft2build.h"
|
|
|
|
#include FT_FREETYPE_H
|
2011-11-02 12:55:03 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::gfx;
|
2010-05-11 10:27:36 -07:00
|
|
|
|
|
|
|
static FT_Library gPlatformFTLibrary = NULL;
|
|
|
|
|
2011-01-12 20:04:42 -08:00
|
|
|
#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "GeckoFonts" , ## args)
|
2010-05-11 10:27:36 -07:00
|
|
|
|
|
|
|
gfxAndroidPlatform::gfxAndroidPlatform()
|
|
|
|
{
|
|
|
|
FT_Init_FreeType(&gPlatformFTLibrary);
|
2012-03-13 13:59:26 -07:00
|
|
|
|
|
|
|
nsCOMPtr<nsIScreenManager> screenMgr = do_GetService("@mozilla.org/gfx/screenmanager;1");
|
|
|
|
nsCOMPtr<nsIScreen> screen;
|
|
|
|
screenMgr->GetPrimaryScreen(getter_AddRefs(screen));
|
2012-05-15 12:41:20 -07:00
|
|
|
mScreenDepth = 24;
|
|
|
|
screen->GetColorDepth(&mScreenDepth);
|
2012-03-13 13:59:26 -07:00
|
|
|
|
2012-05-15 12:41:20 -07:00
|
|
|
mOffscreenFormat = mScreenDepth == 16
|
|
|
|
? gfxASurface::ImageFormatRGB16_565
|
2012-06-11 20:41:46 -07:00
|
|
|
: gfxASurface::ImageFormatRGB24;
|
2010-05-11 10:27:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
gfxAndroidPlatform::~gfxAndroidPlatform()
|
|
|
|
{
|
|
|
|
cairo_debug_reset_static_data();
|
|
|
|
|
|
|
|
FT_Done_FreeType(gPlatformFTLibrary);
|
|
|
|
gPlatformFTLibrary = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<gfxASurface>
|
|
|
|
gfxAndroidPlatform::CreateOffscreenSurface(const gfxIntSize& size,
|
2010-09-16 14:34:53 -07:00
|
|
|
gfxASurface::gfxContentType contentType)
|
2010-05-11 10:27:36 -07:00
|
|
|
{
|
2010-06-28 23:42:28 -07:00
|
|
|
nsRefPtr<gfxASurface> newSurface;
|
2012-05-25 21:38:17 -07:00
|
|
|
newSurface = new gfxImageSurface(size, OptimalFormatForContent(contentType));
|
2010-05-11 10:27:36 -07:00
|
|
|
|
|
|
|
return newSurface.forget();
|
|
|
|
}
|
|
|
|
|
2012-05-25 21:38:17 -07:00
|
|
|
mozilla::gfx::SurfaceFormat
|
|
|
|
gfxAndroidPlatform::Optimal2DFormatForContent(gfxASurface::gfxContentType aContent)
|
|
|
|
{
|
|
|
|
// On Android we always use RGB565 for now.
|
|
|
|
if (aContent == gfxASurface::CONTENT_COLOR) {
|
|
|
|
return mozilla::gfx::FORMAT_R5G6B5;
|
|
|
|
} else {
|
|
|
|
return gfxPlatform::Optimal2DFormatForContent(aContent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-11 10:27:36 -07:00
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::GetFontList(nsIAtom *aLangGroup,
|
|
|
|
const nsACString& aGenericFamily,
|
|
|
|
nsTArray<nsString>& aListOfFonts)
|
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetFontList(aLangGroup,
|
|
|
|
aGenericFamily,
|
|
|
|
aListOfFonts);
|
2010-05-11 10:27:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-01-12 20:04:42 -08:00
|
|
|
void
|
|
|
|
gfxAndroidPlatform::GetFontList(InfallibleTArray<FontListEntry>* retValue)
|
2010-05-11 10:27:36 -07:00
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
gfxFT2FontList::PlatformFontList()->GetFontList(retValue);
|
2011-01-12 20:04:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::UpdateFontList()
|
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
gfxPlatformFontList::PlatformFontList()->UpdateFontList();
|
2010-05-11 10:27:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::ResolveFontName(const nsAString& aFontName,
|
|
|
|
FontResolverCallback aCallback,
|
|
|
|
void *aClosure,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool& aAborted)
|
2010-05-11 10:27:36 -07:00
|
|
|
{
|
2010-07-15 23:03:45 -07:00
|
|
|
nsAutoString resolvedName;
|
2011-09-23 04:15:36 -07:00
|
|
|
if (!gfxPlatformFontList::PlatformFontList()->
|
|
|
|
ResolveFontName(aFontName, resolvedName)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
aAborted = false;
|
2011-09-23 04:15:36 -07:00
|
|
|
return NS_OK;
|
2010-05-11 10:27:36 -07:00
|
|
|
}
|
2011-09-23 04:15:36 -07:00
|
|
|
aAborted = !(*aCallback)(resolvedName, aClosure);
|
2010-05-11 10:27:36 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
gfxAndroidPlatform::GetStandardFamilyName(const nsAString& aFontName, nsAString& aFamilyName)
|
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
gfxPlatformFontList::PlatformFontList()->GetStandardFamilyName(aFontName, aFamilyName);
|
|
|
|
return NS_OK;
|
2010-05-11 10:27:36 -07:00
|
|
|
}
|
|
|
|
|
2010-07-15 23:03:45 -07:00
|
|
|
gfxPlatformFontList*
|
|
|
|
gfxAndroidPlatform::CreatePlatformFontList()
|
|
|
|
{
|
2010-11-08 03:02:27 -08:00
|
|
|
gfxPlatformFontList* list = new gfxFT2FontList();
|
|
|
|
if (NS_SUCCEEDED(list->InitFontList())) {
|
|
|
|
return list;
|
|
|
|
}
|
|
|
|
gfxPlatformFontList::Shutdown();
|
|
|
|
return nsnull;
|
2010-07-15 23:03:45 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-07-15 23:03:45 -07: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-22 18:40:00 -07:00
|
|
|
if (aFormatFlags & (gfxUserFontSet::FLAG_FORMAT_OPENTYPE |
|
|
|
|
gfxUserFontSet::FLAG_FORMAT_WOFF |
|
2010-07-15 23:03:45 -07:00
|
|
|
gfxUserFontSet::FLAG_FORMAT_TRUETYPE)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-15 23:03:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// reject all other formats, known and unknown
|
|
|
|
if (aFormatFlags != 0) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2010-07-15 23:03:45 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// no format hint set, need to look at data
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2010-07-15 23:03:45 -07:00
|
|
|
}
|
|
|
|
|
2010-05-11 10:27:36 -07:00
|
|
|
gfxFontGroup *
|
|
|
|
gfxAndroidPlatform::CreateFontGroup(const nsAString &aFamilies,
|
|
|
|
const gfxFontStyle *aStyle,
|
|
|
|
gfxUserFontSet* aUserFontSet)
|
|
|
|
{
|
2011-09-23 04:15:36 -07:00
|
|
|
return new gfxFontGroup(aFamilies, aStyle, aUserFontSet);
|
2010-05-11 10:27:36 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
FT_Library
|
|
|
|
gfxAndroidPlatform::GetFTLibrary()
|
|
|
|
{
|
|
|
|
return gPlatformFTLibrary;
|
|
|
|
}
|
|
|
|
|
2010-07-15 23:03:45 -07:00
|
|
|
gfxFontEntry*
|
|
|
|
gfxAndroidPlatform::MakePlatformFont(const gfxProxyFontEntry *aProxyEntry,
|
|
|
|
const PRUint8 *aFontData, PRUint32 aLength)
|
|
|
|
{
|
|
|
|
return gfxPlatformFontList::PlatformFontList()->MakePlatformFont(aProxyEntry,
|
|
|
|
aFontData,
|
|
|
|
aLength);
|
|
|
|
}
|
|
|
|
|
2011-11-02 12:55:03 -07:00
|
|
|
RefPtr<ScaledFont>
|
|
|
|
gfxAndroidPlatform::GetScaledFontForFont(gfxFont *aFont)
|
|
|
|
{
|
2012-05-29 20:04:59 -07:00
|
|
|
NS_ASSERTION(aFont->GetType() == gfxFont::FONT_TYPE_FT2, "Expecting Freetype font");
|
2011-11-02 12:55:03 -07:00
|
|
|
NativeFont nativeFont;
|
|
|
|
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
|
2012-05-16 15:30:10 -07:00
|
|
|
nativeFont.mFont = static_cast<gfxFT2FontBase*>(aFont)->GetFontOptions();
|
2011-11-02 12:55:03 -07:00
|
|
|
RefPtr<ScaledFont> scaledFont =
|
|
|
|
Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
|
|
|
|
|
|
|
|
return scaledFont;
|
|
|
|
}
|
|
|
|
|
2012-02-08 14:52:57 -08: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 12:41:20 -07:00
|
|
|
|
|
|
|
int
|
|
|
|
gfxAndroidPlatform::GetScreenDepth() const
|
|
|
|
{
|
|
|
|
return mScreenDepth;
|
|
|
|
}
|