2011-03-11 01:07:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2010-05-11 21:27:36 +04:00
|
|
|
* ***** 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 Android port code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Mozilla Foundation
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2010
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Vladimir Vukicevic <vladimir@pobox.com>
|
|
|
|
*
|
|
|
|
* 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 ***** */
|
|
|
|
|
|
|
|
#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"
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-09-17 01:34:53 +04:00
|
|
|
if (contentType == gfxImageSurface::CONTENT_COLOR)
|
2010-12-15 21:17:26 +03:00
|
|
|
newSurface = new gfxImageSurface (size, GetOffscreenFormat());
|
2010-06-29 10:42:28 +04:00
|
|
|
else
|
2010-09-17 01:34:53 +04:00
|
|
|
newSurface = new gfxImageSurface (size, gfxASurface::FormatFromContent(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();
|
|
|
|
return nsnull;
|
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>
|
|
|
|
gfxAndroidPlatform::GetScaledFontForFont(gfxFont *aFont)
|
|
|
|
{
|
|
|
|
NativeFont nativeFont;
|
|
|
|
nativeFont.mType = NATIVE_FONT_SKIA_FONT_FACE;
|
|
|
|
nativeFont.mFont = aFont;
|
|
|
|
RefPtr<ScaledFont> scaledFont =
|
|
|
|
Factory::CreateScaledFontForNativeFont(nativeFont, aFont->GetAdjustedSize());
|
|
|
|
|
|
|
|
return scaledFont;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|