2017-10-27 20:33:53 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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/. */
|
2011-06-16 10:31:36 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
#include "InspectorFontFace.h"
|
|
|
|
|
2018-05-25 16:07:57 +03:00
|
|
|
#include "gfxPlatformFontList.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTextRun.h"
|
2011-06-16 10:31:37 +04:00
|
|
|
#include "gfxUserFontSet.h"
|
2012-12-19 13:42:25 +04:00
|
|
|
#include "nsFontFaceLoader.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2017-08-09 13:45:39 +03:00
|
|
|
#include "brotli/decode.h"
|
2011-06-16 10:31:37 +04:00
|
|
|
#include "zlib.h"
|
2018-06-05 02:55:11 +03:00
|
|
|
#include "mozilla/dom/CSSFontFaceRule.h"
|
2014-10-02 06:32:05 +04:00
|
|
|
#include "mozilla/dom/FontFaceSet.h"
|
2018-05-16 08:35:59 +03:00
|
|
|
#include "mozilla/ServoBindings.h"
|
2018-01-29 16:24:11 +03:00
|
|
|
#include "mozilla/Unused.h"
|
2014-10-02 06:32:05 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-06-16 10:31:36 +04:00
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
bool
|
|
|
|
InspectorFontFace::FromFontGroup()
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-05-11 10:56:12 +03:00
|
|
|
return bool(mMatchType & gfxTextRange::MatchType::kFontGroup);
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
bool
|
|
|
|
InspectorFontFace::FromLanguagePrefs()
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-05-11 10:56:12 +03:00
|
|
|
return bool(mMatchType & gfxTextRange::MatchType::kPrefsFallback);
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
bool
|
|
|
|
InspectorFontFace::FromSystemFallback()
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-05-11 10:56:12 +03:00
|
|
|
return bool(mMatchType & gfxTextRange::MatchType::kSystemFallback);
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetName(nsAString& aName)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2011-06-16 10:31:37 +04:00
|
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
2018-09-12 22:34:57 +03:00
|
|
|
aName.Append(NS_ConvertUTF8toUTF16(mFontEntry->mUserFontData->mRealName));
|
2011-06-16 10:31:37 +04:00
|
|
|
} else {
|
2018-09-12 22:34:57 +03:00
|
|
|
aName.Append(NS_ConvertUTF8toUTF16(mFontEntry->RealFaceName()));
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetCSSFamilyName(nsAString& aCSSFamilyName)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-09-12 22:34:57 +03:00
|
|
|
aCSSFamilyName.Append(NS_ConvertUTF8toUTF16(mFontEntry->FamilyName()));
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-05-25 16:07:57 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetCSSGeneric(nsAString& aName)
|
|
|
|
{
|
|
|
|
auto genericType =
|
|
|
|
FontFamilyType(mMatchType & gfxTextRange::MatchType::kGenericMask);
|
|
|
|
if (genericType >= FontFamilyType::eFamily_generic_first &&
|
|
|
|
genericType <= FontFamilyType::eFamily_generic_last) {
|
|
|
|
aName.AssignASCII(gfxPlatformFontList::GetGenericName(genericType));
|
|
|
|
} else {
|
|
|
|
aName.Truncate(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-05 02:55:11 +03:00
|
|
|
CSSFontFaceRule*
|
2018-01-11 07:38:01 +03:00
|
|
|
InspectorFontFace::GetRule()
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
Bug 1449087 part 2 - Use Servo data to back @font-face rule. r=emilio
This patch does the following things:
* Create a new class ServoFontFaceRule for CSSOM of @font-face rule
which mostly follows how nsCSSFontFaceRule was implemented.
* Remove the old nsCSSFontFaceRule and binding code to create it.
* Have FontFace backed by Servo data via making mRule and mDescriptors
of the class hold RawServoFontFaceRule like ServoFontFaceRule.
To keep this patch small, it effectively just delays the conversion
from Servo data to nsCSSValue from parsing to using. This may cause
worse performance if the font set is flushed repeatedly. Supposing we
don't flush font set very frequently, it may not be a big deal.
We may still want to remove the intermediate nsCSSValue conversion at
some point, and have everything converted to their final form directly
when used, but that can happen in followups.
There are some unfortunate bits from this change:
* We lose style sheet for logging in FontFaceSet. This is probably not
all that worse, because we wouldn't have that before either if the
page doesn't use CSSOM to visit it. But we should figure out some
approach to fix it anyway.
* InspectorFontFace no longer shares the same rule object as CSSOM.
This isn't really a problem if the @font-face rule isn't very mutable.
Unless we want to make the rule returned from InspectorFontFace to be
mutable (i.e. via inspector), not using the same object probably isn't
too bad.
This patch switches the code we use to serialize stuff in FontFace and
CSSFontFaceRule, which leads to some failures in tests. Specifically,
the expected changes including:
* Value of font-family now can be serialized to identifier sequence like
font-family property. The old code always serializes it to string,
but it doesn't seem to have different requirement than the property.
Blink can serialize to identifier as well.
* Family name inside local() is also changed to use the same way as
family names elsewhere (i.e. can be identifier sequence). Blink has
the same behavior as the old code, but I don't think it's a big deal.
* The order of descriptors serialized gets changed. I don't think it
matters at all.
* Empty string as font-family via using string syntax is no longer
considered invalid for FontFace. I don't find it is mentioned anywhere
that it should be specifically treated invalid.
MozReview-Commit-ID: 32Fk3Fi9uTs
--HG--
extra : rebase_source : 6221ec8fc56de357b06dd27e770fb175348a2f77
2018-04-04 01:42:10 +03:00
|
|
|
if (!mRule) {
|
|
|
|
// check whether this font entry is associated with an @font-face rule
|
|
|
|
// in the relevant font group's user font set
|
|
|
|
RawServoFontFaceRule* 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);
|
|
|
|
}
|
2014-10-02 06:32:05 +04:00
|
|
|
}
|
2012-12-19 13:42:25 +04:00
|
|
|
}
|
Bug 1449087 part 2 - Use Servo data to back @font-face rule. r=emilio
This patch does the following things:
* Create a new class ServoFontFaceRule for CSSOM of @font-face rule
which mostly follows how nsCSSFontFaceRule was implemented.
* Remove the old nsCSSFontFaceRule and binding code to create it.
* Have FontFace backed by Servo data via making mRule and mDescriptors
of the class hold RawServoFontFaceRule like ServoFontFaceRule.
To keep this patch small, it effectively just delays the conversion
from Servo data to nsCSSValue from parsing to using. This may cause
worse performance if the font set is flushed repeatedly. Supposing we
don't flush font set very frequently, it may not be a big deal.
We may still want to remove the intermediate nsCSSValue conversion at
some point, and have everything converted to their final form directly
when used, but that can happen in followups.
There are some unfortunate bits from this change:
* We lose style sheet for logging in FontFaceSet. This is probably not
all that worse, because we wouldn't have that before either if the
page doesn't use CSSOM to visit it. But we should figure out some
approach to fix it anyway.
* InspectorFontFace no longer shares the same rule object as CSSOM.
This isn't really a problem if the @font-face rule isn't very mutable.
Unless we want to make the rule returned from InspectorFontFace to be
mutable (i.e. via inspector), not using the same object probably isn't
too bad.
This patch switches the code we use to serialize stuff in FontFace and
CSSFontFaceRule, which leads to some failures in tests. Specifically,
the expected changes including:
* Value of font-family now can be serialized to identifier sequence like
font-family property. The old code always serializes it to string,
but it doesn't seem to have different requirement than the property.
Blink can serialize to identifier as well.
* Family name inside local() is also changed to use the same way as
family names elsewhere (i.e. can be identifier sequence). Blink has
the same behavior as the old code, but I don't think it's a big deal.
* The order of descriptors serialized gets changed. I don't think it
matters at all.
* Empty string as font-family via using string syntax is no longer
considered invalid for FontFace. I don't find it is mentioned anywhere
that it should be specifically treated invalid.
MozReview-Commit-ID: 32Fk3Fi9uTs
--HG--
extra : rebase_source : 6221ec8fc56de357b06dd27e770fb175348a2f77
2018-04-04 01:42:10 +03:00
|
|
|
if (rule) {
|
|
|
|
// XXX It would be better if we can share this with CSSOM tree,
|
|
|
|
// but that may require us to create another map, which is not
|
|
|
|
// great either. As far as they would use the same backend, and
|
|
|
|
// we don't really support mutating @font-face rule via CSSOM,
|
|
|
|
// it's probably fine for now.
|
|
|
|
uint32_t line, column;
|
|
|
|
Servo_FontFaceRule_GetSourceLocation(rule, &line, &column);
|
2018-06-29 05:56:09 +03:00
|
|
|
mRule = new CSSFontFaceRule(do_AddRef(rule), nullptr, nullptr,
|
|
|
|
line, column);
|
Bug 1449087 part 2 - Use Servo data to back @font-face rule. r=emilio
This patch does the following things:
* Create a new class ServoFontFaceRule for CSSOM of @font-face rule
which mostly follows how nsCSSFontFaceRule was implemented.
* Remove the old nsCSSFontFaceRule and binding code to create it.
* Have FontFace backed by Servo data via making mRule and mDescriptors
of the class hold RawServoFontFaceRule like ServoFontFaceRule.
To keep this patch small, it effectively just delays the conversion
from Servo data to nsCSSValue from parsing to using. This may cause
worse performance if the font set is flushed repeatedly. Supposing we
don't flush font set very frequently, it may not be a big deal.
We may still want to remove the intermediate nsCSSValue conversion at
some point, and have everything converted to their final form directly
when used, but that can happen in followups.
There are some unfortunate bits from this change:
* We lose style sheet for logging in FontFaceSet. This is probably not
all that worse, because we wouldn't have that before either if the
page doesn't use CSSOM to visit it. But we should figure out some
approach to fix it anyway.
* InspectorFontFace no longer shares the same rule object as CSSOM.
This isn't really a problem if the @font-face rule isn't very mutable.
Unless we want to make the rule returned from InspectorFontFace to be
mutable (i.e. via inspector), not using the same object probably isn't
too bad.
This patch switches the code we use to serialize stuff in FontFace and
CSSFontFaceRule, which leads to some failures in tests. Specifically,
the expected changes including:
* Value of font-family now can be serialized to identifier sequence like
font-family property. The old code always serializes it to string,
but it doesn't seem to have different requirement than the property.
Blink can serialize to identifier as well.
* Family name inside local() is also changed to use the same way as
family names elsewhere (i.e. can be identifier sequence). Blink has
the same behavior as the old code, but I don't think it's a big deal.
* The order of descriptors serialized gets changed. I don't think it
matters at all.
* Empty string as font-family via using string syntax is no longer
considered invalid for FontFace. I don't find it is mentioned anywhere
that it should be specifically treated invalid.
MozReview-Commit-ID: 32Fk3Fi9uTs
--HG--
extra : rebase_source : 6221ec8fc56de357b06dd27e770fb175348a2f77
2018-04-04 01:42:10 +03:00
|
|
|
}
|
2012-12-19 13:42:25 +04:00
|
|
|
}
|
Bug 1449087 part 2 - Use Servo data to back @font-face rule. r=emilio
This patch does the following things:
* Create a new class ServoFontFaceRule for CSSOM of @font-face rule
which mostly follows how nsCSSFontFaceRule was implemented.
* Remove the old nsCSSFontFaceRule and binding code to create it.
* Have FontFace backed by Servo data via making mRule and mDescriptors
of the class hold RawServoFontFaceRule like ServoFontFaceRule.
To keep this patch small, it effectively just delays the conversion
from Servo data to nsCSSValue from parsing to using. This may cause
worse performance if the font set is flushed repeatedly. Supposing we
don't flush font set very frequently, it may not be a big deal.
We may still want to remove the intermediate nsCSSValue conversion at
some point, and have everything converted to their final form directly
when used, but that can happen in followups.
There are some unfortunate bits from this change:
* We lose style sheet for logging in FontFaceSet. This is probably not
all that worse, because we wouldn't have that before either if the
page doesn't use CSSOM to visit it. But we should figure out some
approach to fix it anyway.
* InspectorFontFace no longer shares the same rule object as CSSOM.
This isn't really a problem if the @font-face rule isn't very mutable.
Unless we want to make the rule returned from InspectorFontFace to be
mutable (i.e. via inspector), not using the same object probably isn't
too bad.
This patch switches the code we use to serialize stuff in FontFace and
CSSFontFaceRule, which leads to some failures in tests. Specifically,
the expected changes including:
* Value of font-family now can be serialized to identifier sequence like
font-family property. The old code always serializes it to string,
but it doesn't seem to have different requirement than the property.
Blink can serialize to identifier as well.
* Family name inside local() is also changed to use the same way as
family names elsewhere (i.e. can be identifier sequence). Blink has
the same behavior as the old code, but I don't think it's a big deal.
* The order of descriptors serialized gets changed. I don't think it
matters at all.
* Empty string as font-family via using string syntax is no longer
considered invalid for FontFace. I don't find it is mentioned anywhere
that it should be specifically treated invalid.
MozReview-Commit-ID: 32Fk3Fi9uTs
--HG--
extra : rebase_source : 6221ec8fc56de357b06dd27e770fb175348a2f77
2018-04-04 01:42:10 +03:00
|
|
|
return mRule;
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
int32_t
|
|
|
|
InspectorFontFace::SrcIndex()
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2011-06-16 10:31:37 +04:00
|
|
|
if (mFontEntry->IsUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
2018-01-11 07:38:01 +03:00
|
|
|
return mFontEntry->mUserFontData->mSrcIndex;
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2018-01-11 07:38:01 +03:00
|
|
|
|
|
|
|
return -1;
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetURI(nsAString& aURI)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2011-06-16 10:31:37 +04:00
|
|
|
aURI.Truncate();
|
|
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
|
|
|
if (mFontEntry->mUserFontData->mURI) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2018-01-11 07:38:01 +03:00
|
|
|
mFontEntry->mUserFontData->mURI->GetSpec(spec);
|
2011-06-16 10:31:37 +04:00
|
|
|
AppendUTF8toUTF16(spec, aURI);
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetLocalName(nsAString& aLocalName)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2018-09-12 22:34:57 +03:00
|
|
|
aLocalName.Truncate();
|
2011-06-16 10:31:37 +04:00
|
|
|
if (mFontEntry->IsLocalUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
2018-09-12 22:34:57 +03:00
|
|
|
aLocalName.Append(NS_ConvertUTF8toUTF16(mFontEntry->mUserFontData->mLocalName));
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2011-06-16 10:31:37 +04:00
|
|
|
static void
|
2018-01-11 07:38:01 +03:00
|
|
|
AppendToFormat(nsAString& aResult, const char* aFormat)
|
2011-06-16 10:31:37 +04:00
|
|
|
{
|
|
|
|
if (!aResult.IsEmpty()) {
|
2013-05-07 18:25:21 +04:00
|
|
|
aResult.Append(',');
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
|
|
|
aResult.AppendASCII(aFormat);
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetFormat(nsAString& aFormat)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2011-06-16 10:31:37 +04:00
|
|
|
aFormat.Truncate();
|
|
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t formatFlags = mFontEntry->mUserFontData->mFormat;
|
2011-06-16 10:31:37 +04:00
|
|
|
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");
|
|
|
|
}
|
2014-10-04 14:36:05 +04:00
|
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF2) {
|
|
|
|
AppendToFormat(aFormat, "woff2");
|
|
|
|
}
|
2018-02-15 13:56:42 +03:00
|
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_OPENTYPE_VARIATIONS) {
|
|
|
|
AppendToFormat(aFormat, "opentype-variations");
|
|
|
|
}
|
|
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_TRUETYPE_VARIATIONS) {
|
|
|
|
AppendToFormat(aFormat, "truetype-variations");
|
|
|
|
}
|
|
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF_VARIATIONS) {
|
|
|
|
AppendToFormat(aFormat, "woff-variations");
|
|
|
|
}
|
|
|
|
if (formatFlags & gfxUserFontSet::FLAG_FORMAT_WOFF2_VARIATIONS) {
|
|
|
|
AppendToFormat(aFormat, "woff2-variations");
|
|
|
|
}
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetMetadata(nsAString& aMetadata)
|
2011-06-16 10:31:36 +04:00
|
|
|
{
|
2011-06-16 10:31:37 +04:00
|
|
|
aMetadata.Truncate();
|
|
|
|
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
|
|
|
|
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
|
2016-04-15 22:45:37 +03:00
|
|
|
const gfxUserFontData* userFontData = mFontEntry->mUserFontData.get();
|
2011-06-16 10:31:37 +04:00
|
|
|
if (userFontData->mMetadata.Length() && userFontData->mMetaOrigLen) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2011-06-16 10:31:37 +04:00
|
|
|
str.SetLength(userFontData->mMetaOrigLen);
|
|
|
|
if (str.Length() == userFontData->mMetaOrigLen) {
|
2014-10-04 14:46:54 +04:00
|
|
|
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;
|
2017-08-09 13:45:39 +03:00
|
|
|
if (BrotliDecoderDecompress(userFontData->mMetadata.Length(),
|
|
|
|
userFontData->mMetadata.Elements(),
|
|
|
|
&decodedSize,
|
|
|
|
(uint8_t*)str.BeginWriting()) == 1 &&
|
2014-10-04 14:46:54 +04:00
|
|
|
decodedSize == userFontData->mMetaOrigLen) {
|
|
|
|
AppendUTF8toUTF16(str, aMetadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2011-06-16 10:31:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-16 10:31:36 +04:00
|
|
|
}
|
2018-01-11 07:38:01 +03:00
|
|
|
|
2018-01-29 16:24:11 +03:00
|
|
|
// Append an OpenType tag to a string as a 4-ASCII-character code.
|
|
|
|
static void
|
|
|
|
AppendTagAsASCII(nsAString& aString, uint32_t aTag)
|
|
|
|
{
|
|
|
|
aString.AppendPrintf("%c%c%c%c", (aTag >> 24) & 0xff,
|
|
|
|
(aTag >> 16) & 0xff,
|
|
|
|
(aTag >> 8) & 0xff,
|
|
|
|
aTag & 0xff);
|
|
|
|
}
|
|
|
|
|
2018-01-26 18:47:20 +03:00
|
|
|
void
|
2018-01-29 16:24:11 +03:00
|
|
|
InspectorFontFace::GetVariationAxes(nsTArray<InspectorVariationAxis>& aResult,
|
|
|
|
ErrorResult& aRV)
|
2018-01-26 18:47:20 +03:00
|
|
|
{
|
|
|
|
if (!mFontEntry->HasVariations()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AutoTArray<gfxFontVariationAxis,4> axes;
|
|
|
|
mFontEntry->GetVariationAxes(axes);
|
|
|
|
MOZ_ASSERT(!axes.IsEmpty());
|
2018-01-29 16:24:11 +03:00
|
|
|
if (!aResult.SetCapacity(axes.Length(), mozilla::fallible)) {
|
|
|
|
aRV.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
2018-01-26 18:47:20 +03:00
|
|
|
for (auto a : axes) {
|
|
|
|
InspectorVariationAxis& axis = *aResult.AppendElement();
|
2018-01-29 16:24:11 +03:00
|
|
|
AppendTagAsASCII(axis.mTag, a.mTag);
|
2018-09-12 22:34:57 +03:00
|
|
|
axis.mName.Append(NS_ConvertUTF8toUTF16(a.mName));
|
2018-01-26 18:47:20 +03:00
|
|
|
axis.mMinValue = a.mMinValue;
|
|
|
|
axis.mMaxValue = a.mMaxValue;
|
|
|
|
axis.mDefaultValue = a.mDefaultValue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-29 16:24:11 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetVariationInstances(
|
|
|
|
nsTArray<InspectorVariationInstance>& aResult,
|
|
|
|
ErrorResult& aRV)
|
|
|
|
{
|
|
|
|
if (!mFontEntry->HasVariations()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AutoTArray<gfxFontVariationInstance,16> instances;
|
|
|
|
mFontEntry->GetVariationInstances(instances);
|
|
|
|
if (!aResult.SetCapacity(instances.Length(), mozilla::fallible)) {
|
|
|
|
aRV.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto i : instances) {
|
|
|
|
InspectorVariationInstance& inst = *aResult.AppendElement();
|
2018-09-12 22:34:57 +03:00
|
|
|
inst.mName.Append(NS_ConvertUTF8toUTF16(i.mName));
|
2018-01-29 16:24:11 +03:00
|
|
|
// inst.mValues is a webidl sequence<>, which is a fallible array,
|
|
|
|
// so we are required to use fallible SetCapacity and AppendElement calls,
|
|
|
|
// and check the result. In practice we don't expect failure here; the
|
|
|
|
// list of values cannot get huge because of limits in the font format.
|
|
|
|
if (!inst.mValues.SetCapacity(i.mValues.Length(), mozilla::fallible)) {
|
|
|
|
aRV.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto v : i.mValues) {
|
|
|
|
InspectorVariationValue value;
|
|
|
|
AppendTagAsASCII(value.mAxis, v.mAxis);
|
|
|
|
value.mValue = v.mValue;
|
|
|
|
// This won't fail, because of SetCapacity above.
|
|
|
|
Unused << inst.mValues.AppendElement(value, mozilla::fallible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-30 12:57:39 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetFeatures(nsTArray<InspectorFontFeature>& aResult,
|
|
|
|
ErrorResult& aRV)
|
|
|
|
{
|
|
|
|
AutoTArray<gfxFontFeatureInfo,64> features;
|
|
|
|
mFontEntry->GetFeatureInfo(features);
|
|
|
|
if (features.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!aResult.SetCapacity(features.Length(), mozilla::fallible)) {
|
|
|
|
aRV.Throw(NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (auto& f : features) {
|
|
|
|
InspectorFontFeature& feat = *aResult.AppendElement();
|
|
|
|
AppendTagAsASCII(feat.mTag, f.mTag);
|
|
|
|
AppendTagAsASCII(feat.mScript, f.mScript);
|
|
|
|
AppendTagAsASCII(feat.mLanguageSystem, f.mLangSys);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-15 21:48:22 +03:00
|
|
|
void
|
|
|
|
InspectorFontFace::GetRanges(nsTArray<RefPtr<nsRange>>& aResult)
|
|
|
|
{
|
|
|
|
aResult = mRanges;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
InspectorFontFace::AddRange(nsRange* aRange)
|
|
|
|
{
|
|
|
|
mRanges.AppendElement(aRange);
|
|
|
|
}
|
|
|
|
|
2018-01-11 07:38:01 +03:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|