mirror of
https://github.com/roytam1/mozilla45esr.git
synced 2026-05-27 00:29:57 +00:00
89830cff26
- #334: more tele from TabBrowser; also remove gMultiProcessBrowser since we don't support it (16f8592aa) - #431: M1388354 M1388014 (da843afa1) - #438: M1393098 (539efce0c) - #388: M1354564 (d375d57d3) - #429: Brotli 1.0.1 (c69914a5a) (with ppc-only defines removed) - #429: install modules/woff2 (current to Fx57) (87b560912) (with ppc-only defines removed) - #429: update OTS to 5.2.0 plus patches and M1396026 (1ce2a83ec) (with binary literals removed) - #317: update graphite2 to 1.3.10 (f4bf5ad97) - #429: update Harfbuzz to 1.5.1 (083639c71) - #317: patch thebes for graphite2 alignment issues; enable graphite fonts (b7fead52b) - #434: adjust video queue settings; Mach factor decode delay logic (default off) (9b5b09a6c) - clean up a couple warnings (f37f7669d) - #426: M1385395 (b8ebae839) - #438: M1375599 (84bfb83b1) - #442: M1381157 (ffbe7ea3a)
225 lines
6.3 KiB
C++
225 lines
6.3 KiB
C++
/* 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/. */
|
|
|
|
#include "nsFontFace.h"
|
|
#include "nsIDOMCSSFontFaceRule.h"
|
|
#include "nsCSSRules.h"
|
|
#include "gfxTextRun.h"
|
|
#include "gfxUserFontSet.h"
|
|
#include "nsFontFaceLoader.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "brotli/decode.h"
|
|
#include "zlib.h"
|
|
#include "mozilla/dom/FontFaceSet.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::dom;
|
|
|
|
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry,
|
|
gfxFontGroup* aFontGroup,
|
|
uint8_t aMatchType)
|
|
: mFontEntry(aFontEntry),
|
|
mFontGroup(aFontGroup),
|
|
mMatchType(aMatchType)
|
|
{
|
|
}
|
|
|
|
nsFontFace::~nsFontFace()
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// nsISupports
|
|
|
|
NS_IMPL_ISUPPORTS(nsFontFace, nsIDOMFontFace)
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// nsIDOMFontFace
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromFontGroup(bool * aFromFontGroup)
|
|
{
|
|
*aFromFontGroup =
|
|
(mMatchType & gfxTextRange::kFontGroup) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromLanguagePrefs(bool * aFromLanguagePrefs)
|
|
{
|
|
*aFromLanguagePrefs =
|
|
(mMatchType & gfxTextRange::kPrefsFallback) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromSystemFallback(bool * aFromSystemFallback)
|
|
{
|
|
*aFromSystemFallback =
|
|
(mMatchType & gfxTextRange::kSystemFallback) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetName(nsAString & aName)
|
|
{
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
aName = mFontEntry->mUserFontData->mRealName;
|
|
} else {
|
|
aName = mFontEntry->RealFaceName();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetCSSFamilyName(nsAString & aCSSFamilyName)
|
|
{
|
|
aCSSFamilyName = mFontEntry->FamilyName();
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetRule(nsIDOMCSSFontFaceRule **aRule)
|
|
{
|
|
// check whether this font entry is associated with an @font-face rule
|
|
// in the relevant font group's user font set
|
|
nsCSSFontFaceRule* rule = nullptr;
|
|
if (mFontEntry->IsUserFont()) {
|
|
FontFaceSet::UserFontSet* fontSet =
|
|
static_cast<FontFaceSet::UserFontSet*>(mFontGroup->GetUserFontSet());
|
|
if (fontSet) {
|
|
FontFaceSet* fontFaceSet = fontSet->GetFontFaceSet();
|
|
if (fontFaceSet) {
|
|
rule = fontFaceSet->FindRuleForEntry(mFontEntry);
|
|
}
|
|
}
|
|
}
|
|
|
|
NS_IF_ADDREF(*aRule = rule);
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetSrcIndex(int32_t * aSrcIndex)
|
|
{
|
|
if (mFontEntry->IsUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
*aSrcIndex = mFontEntry->mUserFontData->mSrcIndex;
|
|
} else {
|
|
*aSrcIndex = -1;
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetURI(nsAString & aURI)
|
|
{
|
|
aURI.Truncate();
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
if (mFontEntry->mUserFontData->mURI) {
|
|
nsAutoCString spec;
|
|
mFontEntry->mUserFontData->mURI->GetSpec(spec);
|
|
AppendUTF8toUTF16(spec, aURI);
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetLocalName(nsAString & aLocalName)
|
|
{
|
|
if (mFontEntry->IsLocalUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
aLocalName = mFontEntry->mUserFontData->mLocalName;
|
|
} else {
|
|
aLocalName.Truncate();
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
static void
|
|
AppendToFormat(nsAString & aResult, const char* aFormat)
|
|
{
|
|
if (!aResult.IsEmpty()) {
|
|
aResult.Append(',');
|
|
}
|
|
aResult.AppendASCII(aFormat);
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFormat(nsAString & aFormat)
|
|
{
|
|
aFormat.Truncate();
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
uint32_t formatFlags = mFontEntry->mUserFontData->mFormat;
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_OPENTYPE) {
|
|
AppendToFormat(aFormat, "opentype");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE) {
|
|
AppendToFormat(aFormat, "truetype");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_AAT) {
|
|
AppendToFormat(aFormat, "truetype-aat");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_EOT) {
|
|
AppendToFormat(aFormat, "embedded-opentype");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_SVG) {
|
|
AppendToFormat(aFormat, "svg");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF) {
|
|
AppendToFormat(aFormat, "woff");
|
|
}
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF2) {
|
|
AppendToFormat(aFormat, "woff2");
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetMetadata(nsAString & aMetadata)
|
|
{
|
|
aMetadata.Truncate();
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
const gfxUserFontData* userFontData = mFontEntry->mUserFontData;
|
|
if (userFontData->mMetadata.Length() && userFontData->mMetaOrigLen) {
|
|
nsAutoCString str;
|
|
str.SetLength(userFontData->mMetaOrigLen);
|
|
if (str.Length() == userFontData->mMetaOrigLen) {
|
|
switch (userFontData->mCompression) {
|
|
case gfxUserFontData::kZlibCompression:
|
|
{
|
|
uLongf destLen = userFontData->mMetaOrigLen;
|
|
if (uncompress((Bytef *)(str.BeginWriting()), &destLen,
|
|
(const Bytef *)(userFontData->mMetadata.Elements()),
|
|
userFontData->mMetadata.Length()) == Z_OK &&
|
|
destLen == userFontData->mMetaOrigLen) {
|
|
AppendUTF8toUTF16(str, aMetadata);
|
|
}
|
|
}
|
|
break;
|
|
case gfxUserFontData::kBrotliCompression:
|
|
{
|
|
size_t decodedSize = userFontData->mMetaOrigLen;
|
|
if (BrotliDecoderDecompress(userFontData->mMetadata.Length(),
|
|
userFontData->mMetadata.Elements(),
|
|
&decodedSize,
|
|
(uint8_t*)str.BeginWriting()) == 1 &&
|
|
decodedSize == userFontData->mMetaOrigLen) {
|
|
AppendUTF8toUTF16(str, aMetadata);
|
|
}
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|