2008-09-30 20:04:10 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** 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 Mozilla Foundation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2008
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* John Daggett <jdaggett@mozilla.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 ***** */
|
|
|
|
|
|
|
|
#ifndef GFX_USER_FONT_SET_H
|
|
|
|
#define GFX_USER_FONT_SET_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "gfxFont.h"
|
|
|
|
#include "gfxFontUtils.h"
|
|
|
|
#include "nsRefPtrHashtable.h"
|
|
|
|
#include "nsAutoPtr.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsIFile.h"
|
2010-04-01 11:05:40 -07:00
|
|
|
#include "nsISupportsImpl.h"
|
2008-09-30 20:04:10 -07:00
|
|
|
|
|
|
|
class nsIURI;
|
|
|
|
class gfxMixedFontFamily;
|
|
|
|
|
|
|
|
// parsed CSS @font-face rule information
|
|
|
|
// lifetime: from when @font-face rule processed until font is loaded
|
|
|
|
struct gfxFontFaceSrc {
|
|
|
|
PRPackedBool mIsLocal; // url or local
|
2008-11-26 19:50:16 -08:00
|
|
|
|
|
|
|
// if url, whether to use the origin principal or not
|
|
|
|
PRPackedBool mUseOriginPrincipal;
|
2008-09-30 20:04:10 -07:00
|
|
|
|
|
|
|
// format hint flags, union of all possible formats
|
|
|
|
// (e.g. TrueType, EOT, SVG, etc.)
|
|
|
|
// see FLAG_FORMAT_* enum values below
|
|
|
|
PRUint32 mFormatFlags;
|
2008-11-26 19:50:16 -08:00
|
|
|
|
|
|
|
nsString mLocalName; // full font name if local
|
|
|
|
nsCOMPtr<nsIURI> mURI; // uri if url
|
|
|
|
nsCOMPtr<nsIURI> mReferrer; // referrer url if url
|
|
|
|
nsCOMPtr<nsISupports> mOriginPrincipal; // principal if url
|
|
|
|
|
2008-09-30 20:04:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// subclassed to store platform-specific code cleaned out when font entry is deleted
|
|
|
|
// lifetime: from when platform font is created until it is deactivated
|
|
|
|
class gfxUserFontData {
|
|
|
|
public:
|
|
|
|
gfxUserFontData() { }
|
|
|
|
virtual ~gfxUserFontData() { }
|
|
|
|
};
|
|
|
|
|
|
|
|
// initially contains a set of proxy font entry objects, replaced with
|
|
|
|
// platform/user fonts as downloaded
|
|
|
|
|
|
|
|
class gfxMixedFontFamily : public gfxFontFamily {
|
|
|
|
public:
|
2009-08-16 06:52:12 -07:00
|
|
|
friend class gfxUserFontSet;
|
|
|
|
|
2008-09-30 20:04:10 -07:00
|
|
|
gfxMixedFontFamily(const nsAString& aName)
|
2009-08-16 06:52:12 -07:00
|
|
|
: gfxFontFamily(aName) { }
|
2008-09-30 20:04:10 -07:00
|
|
|
|
|
|
|
virtual ~gfxMixedFontFamily() { }
|
|
|
|
|
|
|
|
void AddFontEntry(gfxFontEntry *aFontEntry) {
|
|
|
|
nsRefPtr<gfxFontEntry> fe = aFontEntry;
|
|
|
|
mAvailableFonts.AppendElement(fe);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReplaceFontEntry(gfxFontEntry *aOldFontEntry, gfxFontEntry *aNewFontEntry)
|
|
|
|
{
|
|
|
|
PRUint32 numFonts = mAvailableFonts.Length();
|
|
|
|
for (PRUint32 i = 0; i < numFonts; i++) {
|
|
|
|
gfxFontEntry *fe = mAvailableFonts[i];
|
|
|
|
if (fe == aOldFontEntry) {
|
|
|
|
mAvailableFonts[i] = aNewFontEntry;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void RemoveFontEntry(gfxFontEntry *aFontEntry)
|
|
|
|
{
|
|
|
|
PRUint32 numFonts = mAvailableFonts.Length();
|
|
|
|
for (PRUint32 i = 0; i < numFonts; i++) {
|
|
|
|
gfxFontEntry *fe = mAvailableFonts[i];
|
|
|
|
if (fe == aFontEntry) {
|
|
|
|
mAvailableFonts.RemoveElementAt(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// temp method to determine if all proxies are loaded
|
|
|
|
PRBool AllLoaded()
|
|
|
|
{
|
|
|
|
PRUint32 numFonts = mAvailableFonts.Length();
|
|
|
|
for (PRUint32 i = 0; i < numFonts; i++) {
|
|
|
|
gfxFontEntry *fe = mAvailableFonts[i];
|
|
|
|
if (fe->mIsProxy)
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class gfxProxyFontEntry;
|
|
|
|
|
|
|
|
class THEBES_API gfxUserFontSet {
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2010-04-01 11:05:40 -07:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxUserFontSet)
|
2008-09-30 20:04:10 -07:00
|
|
|
|
2008-12-11 23:31:51 -08:00
|
|
|
gfxUserFontSet();
|
2008-09-30 20:04:10 -07:00
|
|
|
virtual ~gfxUserFontSet();
|
|
|
|
|
|
|
|
enum {
|
2009-01-12 21:16:58 -08:00
|
|
|
// no flags ==> no hint set
|
|
|
|
// unknown ==> unknown format hint set
|
|
|
|
FLAG_FORMAT_UNKNOWN = 1,
|
|
|
|
FLAG_FORMAT_OPENTYPE = 1 << 1,
|
|
|
|
FLAG_FORMAT_TRUETYPE = 1 << 2,
|
|
|
|
FLAG_FORMAT_TRUETYPE_AAT = 1 << 3,
|
|
|
|
FLAG_FORMAT_EOT = 1 << 4,
|
|
|
|
FLAG_FORMAT_SVG = 1 << 5,
|
2009-09-17 04:03:12 -07:00
|
|
|
FLAG_FORMAT_WOFF = 1 << 6,
|
|
|
|
|
2009-01-12 21:16:58 -08:00
|
|
|
// mask of all unused bits, update when adding new formats
|
2009-09-17 04:03:12 -07:00
|
|
|
FLAG_FORMAT_NOT_USED = ~((1 << 7)-1)
|
2008-09-30 20:04:10 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
enum LoadStatus {
|
|
|
|
STATUS_LOADING = 0,
|
|
|
|
STATUS_LOADED,
|
|
|
|
STATUS_FORMAT_NOT_SUPPORTED,
|
|
|
|
STATUS_ERROR,
|
|
|
|
STATUS_END_OF_LIST
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// add in a font face
|
|
|
|
// weight, stretch - 0 == unknown, [1, 9] otherwise
|
2009-01-29 12:39:18 -08:00
|
|
|
// italic style = constants in gfxFontConstants.h, e.g. NS_FONT_STYLE_NORMAL
|
2008-09-30 20:04:10 -07:00
|
|
|
// TODO: support for unicode ranges not yet implemented
|
2010-07-13 13:31:31 -07:00
|
|
|
void AddFontFace(const nsAString& aFamilyName,
|
|
|
|
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
|
|
|
PRUint32 aWeight,
|
|
|
|
PRUint32 aStretch,
|
|
|
|
PRUint32 aItalicStyle,
|
|
|
|
const nsString& aFeatureSettings,
|
|
|
|
const nsString& aLanguageOverride,
|
2008-09-30 20:04:10 -07:00
|
|
|
gfxSparseBitSet *aUnicodeRanges = nsnull);
|
|
|
|
|
2008-12-05 15:19:27 -08:00
|
|
|
// Whether there is a face with this family name
|
|
|
|
PRBool HasFamily(const nsAString& aFamilyName) const
|
|
|
|
{
|
|
|
|
return GetFamily(aFamilyName) != nsnull;
|
|
|
|
}
|
|
|
|
|
2008-09-30 20:04:10 -07:00
|
|
|
// lookup a font entry for a given style, returns null if not loaded
|
|
|
|
gfxFontEntry *FindFontEntry(const nsAString& aName,
|
2008-12-11 23:31:51 -08:00
|
|
|
const gfxFontStyle& aFontStyle,
|
|
|
|
PRBool& aNeedsBold);
|
|
|
|
|
|
|
|
// initialize the process that loads external font data, which upon
|
|
|
|
// completion will call OnLoadComplete method
|
|
|
|
virtual nsresult StartLoad(gfxFontEntry *aFontToLoad,
|
|
|
|
const gfxFontFaceSrc *aFontFaceSrc) = 0;
|
2008-09-30 20:04:10 -07:00
|
|
|
|
|
|
|
// when download has been completed, pass back data here
|
|
|
|
// aDownloadStatus == NS_OK ==> download succeeded, error otherwise
|
|
|
|
// returns true if platform font creation sucessful (or local()
|
|
|
|
// reference was next in line)
|
2009-08-30 06:55:24 -07:00
|
|
|
// Ownership of aFontData is passed in here; the font set must
|
|
|
|
// ensure that it is eventually deleted with NS_Free().
|
|
|
|
PRBool OnLoadComplete(gfxFontEntry *aFontToLoad,
|
2008-10-29 11:09:50 -07:00
|
|
|
const PRUint8 *aFontData, PRUint32 aLength,
|
2008-09-30 20:04:10 -07:00
|
|
|
nsresult aDownloadStatus);
|
|
|
|
|
|
|
|
// generation - each time a face is loaded, generation is
|
|
|
|
// incremented so that the change can be recognized
|
|
|
|
PRUint64 GetGeneration() { return mGeneration; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// for a given proxy font entry, attempt to load the next resource
|
|
|
|
// in the src list
|
|
|
|
LoadStatus LoadNext(gfxProxyFontEntry *aProxyEntry);
|
|
|
|
|
|
|
|
// increment the generation on font load
|
|
|
|
void IncrementGeneration();
|
|
|
|
|
2008-12-05 15:19:27 -08:00
|
|
|
gfxMixedFontFamily *GetFamily(const nsAString& aName) const;
|
|
|
|
|
2008-09-30 20:04:10 -07:00
|
|
|
// remove family
|
|
|
|
void RemoveFamily(const nsAString& aFamilyName);
|
|
|
|
|
|
|
|
// font families defined by @font-face rules
|
|
|
|
nsRefPtrHashtable<nsStringHashKey, gfxMixedFontFamily> mFontFamilies;
|
|
|
|
|
|
|
|
PRUint64 mGeneration;
|
|
|
|
};
|
|
|
|
|
|
|
|
// acts a placeholder until the real font is downloaded
|
|
|
|
|
|
|
|
class gfxProxyFontEntry : public gfxFontEntry {
|
2009-08-16 06:52:12 -07:00
|
|
|
friend class gfxUserFontSet;
|
2008-09-30 20:04:10 -07:00
|
|
|
|
|
|
|
public:
|
2010-07-13 13:31:31 -07:00
|
|
|
gfxProxyFontEntry(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
|
2008-12-05 15:19:27 -08:00
|
|
|
gfxMixedFontFamily *aFamily,
|
2010-07-13 13:31:31 -07:00
|
|
|
PRUint32 aWeight,
|
|
|
|
PRUint32 aStretch,
|
|
|
|
PRUint32 aItalicStyle,
|
|
|
|
const nsTArray<gfxFontFeature> *aFeatureSettings,
|
|
|
|
PRUint32 aLanguageOverride,
|
2008-09-30 20:04:10 -07:00
|
|
|
gfxSparseBitSet *aUnicodeRanges);
|
|
|
|
|
|
|
|
virtual ~gfxProxyFontEntry();
|
|
|
|
|
2009-10-07 08:26:58 -07:00
|
|
|
virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, PRBool aNeedsBold);
|
|
|
|
|
2008-09-30 20:04:10 -07:00
|
|
|
PRPackedBool mIsLoading;
|
|
|
|
nsTArray<gfxFontFaceSrc> mSrcList;
|
|
|
|
PRUint32 mSrcIndex; // index of loading src item
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif /* GFX_USER_FONT_SET_H */
|