mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
ae14b92cc6
--HG-- rename : layout/inspector/src/inCSSValueSearch.cpp => layout/inspector/inCSSValueSearch.cpp rename : layout/inspector/src/inCSSValueSearch.h => layout/inspector/inCSSValueSearch.h rename : layout/inspector/src/inDOMUtils.cpp => layout/inspector/inDOMUtils.cpp rename : layout/inspector/src/inDOMUtils.h => layout/inspector/inDOMUtils.h rename : layout/inspector/src/inDOMView.cpp => layout/inspector/inDOMView.cpp rename : layout/inspector/src/inDOMView.h => layout/inspector/inDOMView.h rename : layout/inspector/src/inDeepTreeWalker.cpp => layout/inspector/inDeepTreeWalker.cpp rename : layout/inspector/src/inDeepTreeWalker.h => layout/inspector/inDeepTreeWalker.h rename : layout/inspector/src/inFlasher.cpp => layout/inspector/inFlasher.cpp rename : layout/inspector/src/inFlasher.h => layout/inspector/inFlasher.h rename : layout/inspector/public/inICSSValueSearch.idl => layout/inspector/inICSSValueSearch.idl rename : layout/inspector/public/inIDOMUtils.idl => layout/inspector/inIDOMUtils.idl rename : layout/inspector/public/inIDOMView.idl => layout/inspector/inIDOMView.idl rename : layout/inspector/public/inIDeepTreeWalker.idl => layout/inspector/inIDeepTreeWalker.idl rename : layout/inspector/public/inIFlasher.idl => layout/inspector/inIFlasher.idl rename : layout/inspector/public/inISearchObserver.idl => layout/inspector/inISearchObserver.idl rename : layout/inspector/public/inISearchProcess.idl => layout/inspector/inISearchProcess.idl rename : layout/inspector/src/inLayoutUtils.cpp => layout/inspector/inLayoutUtils.cpp rename : layout/inspector/src/inLayoutUtils.h => layout/inspector/inLayoutUtils.h rename : layout/inspector/src/inSearchLoop.cpp => layout/inspector/inSearchLoop.cpp rename : layout/inspector/src/inSearchLoop.h => layout/inspector/inSearchLoop.h rename : layout/inspector/src/moz.build => layout/inspector/moz.build rename : layout/inspector/src/nsFontFace.cpp => layout/inspector/nsFontFace.cpp rename : layout/inspector/src/nsFontFace.h => layout/inspector/nsFontFace.h rename : layout/inspector/src/nsFontFaceList.cpp => layout/inspector/nsFontFaceList.cpp rename : layout/inspector/src/nsFontFaceList.h => layout/inspector/nsFontFaceList.h rename : layout/inspector/public/nsIDOMFontFace.idl => layout/inspector/nsIDOMFontFace.idl rename : layout/inspector/public/nsIDOMFontFaceList.idl => layout/inspector/nsIDOMFontFaceList.idl
208 lines
5.7 KiB
C++
208 lines
5.7 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 "gfxFont.h"
|
|
#include "gfxUserFontSet.h"
|
|
#include "nsFontFaceLoader.h"
|
|
#include "mozilla/gfx/2D.h"
|
|
#include "zlib.h"
|
|
|
|
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry,
|
|
gfxFontGroup* aFontGroup,
|
|
uint8_t aMatchType)
|
|
: mFontEntry(aFontEntry),
|
|
mFontGroup(aFontGroup),
|
|
mMatchType(aMatchType)
|
|
{
|
|
}
|
|
|
|
nsFontFace::~nsFontFace()
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// nsISupports
|
|
|
|
NS_IMPL_ISUPPORTS1(nsFontFace, nsIDOMFontFace)
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
// nsIDOMFontFace
|
|
|
|
/* readonly attribute boolean fromFontGroup; */
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromFontGroup(bool * aFromFontGroup)
|
|
{
|
|
*aFromFontGroup =
|
|
(mMatchType & gfxTextRange::kFontGroup) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute boolean fromLanguagePrefs; */
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromLanguagePrefs(bool * aFromLanguagePrefs)
|
|
{
|
|
*aFromLanguagePrefs =
|
|
(mMatchType & gfxTextRange::kPrefsFallback) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute boolean fromSystemFallback; */
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetFromSystemFallback(bool * aFromSystemFallback)
|
|
{
|
|
*aFromSystemFallback =
|
|
(mMatchType & gfxTextRange::kSystemFallback) != 0;
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute DOMString name; */
|
|
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;
|
|
}
|
|
|
|
/* readonly attribute DOMString CSSFamilyName; */
|
|
NS_IMETHODIMP
|
|
nsFontFace::GetCSSFamilyName(nsAString & aCSSFamilyName)
|
|
{
|
|
aCSSFamilyName = mFontEntry->FamilyName();
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute nsIDOMCSSFontFaceRule rule; */
|
|
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()) {
|
|
nsUserFontSet* fontSet =
|
|
static_cast<nsUserFontSet*>(mFontGroup->GetUserFontSet());
|
|
if (fontSet) {
|
|
rule = fontSet->FindRuleForEntry(mFontEntry);
|
|
}
|
|
}
|
|
|
|
NS_IF_ADDREF(*aRule = rule);
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute long srcIndex; */
|
|
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;
|
|
}
|
|
|
|
/* readonly attribute DOMString URI; */
|
|
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;
|
|
}
|
|
|
|
/* readonly attribute DOMString localName; */
|
|
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;
|
|
}
|
|
|
|
/* readonly attribute DOMString format; */
|
|
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");
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
/* readonly attribute DOMString metadata; */
|
|
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) {
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return NS_OK;
|
|
}
|