bug 467669 - pt 4 - expose additional attributes for downloaded fonts. r=roc

This commit is contained in:
Jonathan Kew 2011-06-16 07:31:37 +01:00
parent 182daf38b3
commit edc3700f8f
3 changed files with 93 additions and 8 deletions

View File

@ -372,6 +372,23 @@ SanitizeOpenTypeData(const PRUint8* aData, PRUint32 aLength,
}
}
static void
StoreUserFontData(gfxFontEntry* aFontEntry, gfxProxyFontEntry* aProxy)
{
if (!aFontEntry->mUserFontData) {
aFontEntry->mUserFontData = new gfxUserFontData;
}
gfxUserFontData* userFontData = aFontEntry->mUserFontData;
userFontData->mSrcIndex = aProxy->mSrcIndex;
const gfxFontFaceSrc& src = aProxy->mSrcList[aProxy->mSrcIndex];
if (src.mIsLocal) {
userFontData->mLocalName = src.mLocalName;
} else {
userFontData->mURI = src.mURI;
}
userFontData->mFormat = src.mFormatFlags;
}
// This is called when a font download finishes.
// Ownership of aFontData passes in here, and the font set must
// ensure that it is eventually deleted via NS_Free().
@ -447,7 +464,7 @@ gfxUserFontSet::OnLoadComplete(gfxProxyFontEntry *aProxy,
// newly-created font entry
fe->mFeatureSettings.AppendElements(aProxy->mFeatureSettings);
fe->mLanguageOverride = aProxy->mLanguageOverride;
StoreUserFontData(fe, aProxy);
#ifdef PR_LOGGING
// must do this before ReplaceFontEntry() because that will
// clear the proxy's mFamily pointer!
@ -539,6 +556,7 @@ gfxUserFontSet::LoadNext(gfxProxyFontEntry *aProxyEntry)
PRUint32(mGeneration)));
fe->mFeatureSettings.AppendElements(aProxyEntry->mFeatureSettings);
fe->mLanguageOverride = aProxyEntry->mLanguageOverride;
StoreUserFontData(fe, aProxyEntry);
ReplaceFontEntry(aProxyEntry, fe);
return STATUS_LOADED;
} else {

View File

@ -71,12 +71,25 @@ struct gfxFontFaceSrc {
};
// subclassed to store platform-specific code cleaned out when font entry is deleted
// lifetime: from when platform font is created until it is deactivated
// Subclassed to store platform-specific code cleaned out when font entry is
// deleted.
// Lifetime: from when platform font is created until it is deactivated.
// If the platform does not need to add any platform-specific code/data here,
// then the gfxUserFontSet will allocate a base gfxUserFontData and attach
// to the entry to track the basic user font info fields here.
class gfxUserFontData {
public:
gfxUserFontData() { }
gfxUserFontData()
: mSrcIndex(0), mFormat(0), mMetaOrigLen(0)
{ }
virtual ~gfxUserFontData() { }
nsTArray<PRUint8> mMetadata; // woff metadata block (compressed), if any
nsCOMPtr<nsIURI> mURI; // URI of the source, if it was url()
nsString mLocalName; // font name used for the source, if local()
PRUint32 mSrcIndex; // index in the rule's source list
PRUint32 mFormat; // format hint for the source used, if any
PRUint32 mMetaOrigLen; // length needed to decompress metadata
};
// initially contains a set of proxy font entry objects, replaced with

View File

@ -39,6 +39,7 @@
#include "nsFontFace.h"
#include "nsIDOMCSSFontFaceRule.h"
#include "nsCSSRules.h"
#include "gfxUserFontSet.h"
nsFontFace::nsFontFace(gfxFontEntry* aFontEntry,
PRUint8 aMatchType,
@ -116,28 +117,81 @@ nsFontFace::GetRule(nsIDOMCSSFontFaceRule **aRule)
NS_IMETHODIMP
nsFontFace::GetSrcIndex(PRInt32 * aSrcIndex)
{
return NS_ERROR_NOT_IMPLEMENTED;
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)
{
return NS_ERROR_NOT_IMPLEMENTED;
aURI.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
if (mFontEntry->mUserFontData->mURI) {
nsCAutoString spec;
mFontEntry->mUserFontData->mURI->GetSpec(spec);
AppendUTF8toUTF16(spec, aURI);
}
}
return NS_OK;
}
/* readonly attribute DOMString localName; */
NS_IMETHODIMP
nsFontFace::GetLocalName(nsAString & aLocalName)
{
return NS_ERROR_NOT_IMPLEMENTED;
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.AppendASCII(",");
}
aResult.AppendASCII(aFormat);
}
NS_IMETHODIMP
nsFontFace::GetFormat(nsAString & aFormat)
{
return NS_ERROR_NOT_IMPLEMENTED;
aFormat.Truncate();
if (mFontEntry->IsUserFont() && !mFontEntry->IsLocalUserFont()) {
NS_ASSERTION(mFontEntry->mUserFontData, "missing userFontData");
PRUint32 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; */