2005-10-08 09:09:42 +04: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.
|
2009-08-16 17:52:12 +04:00
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005-2009
|
2005-10-08 09:09:42 +04:00
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Stuart Parmenter <stuart@mozilla.com>
|
2006-11-21 09:31:04 +03:00
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
2008-08-06 08:34:06 +04:00
|
|
|
* John Daggett <jdaggett@mozilla.com>
|
2009-08-16 17:52:12 +04:00
|
|
|
* Jonathan Kew <jfkthame@gmail.com>
|
2005-10-08 09:09:42 +04:00
|
|
|
*
|
|
|
|
* 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_FONT_H
|
|
|
|
#define GFX_FONT_H
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
2011-06-25 18:06:02 +04:00
|
|
|
#include "nsAlgorithm.h"
|
2005-10-08 09:09:42 +04:00
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxPoint.h"
|
2008-08-06 08:34:06 +04:00
|
|
|
#include "gfxFontUtils.h"
|
2006-02-24 08:15:21 +03:00
|
|
|
#include "nsTArray.h"
|
2007-04-04 07:32:43 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2007-01-23 11:45:52 +03:00
|
|
|
#include "gfxSkipChars.h"
|
|
|
|
#include "gfxRect.h"
|
2007-04-04 07:32:43 +04:00
|
|
|
#include "nsExpirationTracker.h"
|
2009-01-29 23:39:18 +03:00
|
|
|
#include "gfxFontConstants.h"
|
2009-10-07 19:26:58 +04:00
|
|
|
#include "gfxPlatform.h"
|
2010-02-24 20:57:57 +03:00
|
|
|
#include "nsIAtom.h"
|
2010-04-01 22:05:40 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2008-01-21 04:23:50 +03:00
|
|
|
|
2008-01-21 04:23:50 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-08 09:09:42 +04:00
|
|
|
class gfxContext;
|
2005-11-29 23:12:29 +03:00
|
|
|
class gfxTextRun;
|
2007-04-04 07:32:43 +04:00
|
|
|
class gfxFont;
|
2009-08-16 17:52:12 +04:00
|
|
|
class gfxFontFamily;
|
2007-03-05 00:05:10 +03:00
|
|
|
class gfxFontGroup;
|
2008-10-01 07:01:53 +04:00
|
|
|
class gfxUserFontSet;
|
|
|
|
class gfxUserFontData;
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2010-02-24 20:57:44 +03:00
|
|
|
class nsILanguageAtomService;
|
|
|
|
|
2010-06-11 23:14:38 +04:00
|
|
|
typedef struct _hb_blob_t hb_blob_t;
|
|
|
|
|
2009-01-29 23:39:18 +03:00
|
|
|
// We should eliminate these synonyms when it won't cause many merge conflicts.
|
|
|
|
#define FONT_STYLE_NORMAL NS_FONT_STYLE_NORMAL
|
|
|
|
#define FONT_STYLE_ITALIC NS_FONT_STYLE_ITALIC
|
|
|
|
#define FONT_STYLE_OBLIQUE NS_FONT_STYLE_OBLIQUE
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2009-01-29 23:39:18 +03:00
|
|
|
// We should eliminate these synonyms when it won't cause many merge conflicts.
|
|
|
|
#define FONT_WEIGHT_NORMAL NS_FONT_WEIGHT_NORMAL
|
|
|
|
#define FONT_WEIGHT_BOLD NS_FONT_WEIGHT_BOLD
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2007-06-08 12:22:03 +04:00
|
|
|
#define FONT_MAX_SIZE 2000.0
|
|
|
|
|
2010-07-14 00:31:31 +04:00
|
|
|
#define NO_FONT_LANGUAGE_OVERRIDE 0
|
|
|
|
|
|
|
|
// An OpenType feature tag and value pair
|
|
|
|
struct THEBES_API gfxFontFeature {
|
|
|
|
PRUint32 mTag; // see http://www.microsoft.com/typography/otspec/featuretags.htm
|
|
|
|
PRUint32 mValue; // 0 = off, 1 = on, larger values may be used as parameters
|
|
|
|
// to features that select among multiple alternatives
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2010-07-14 00:31:31 +04:00
|
|
|
operator<(const gfxFontFeature& a, const gfxFontFeature& b)
|
|
|
|
{
|
|
|
|
return (a.mTag < b.mTag) || ((a.mTag == b.mTag) && (a.mValue < b.mValue));
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2010-07-14 00:31:31 +04:00
|
|
|
operator==(const gfxFontFeature& a, const gfxFontFeature& b)
|
|
|
|
{
|
|
|
|
return (a.mTag == b.mTag) && (a.mValue == b.mValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-27 18:41:11 +04:00
|
|
|
struct THEBES_API gfxFontStyle {
|
2008-03-12 13:52:58 +03:00
|
|
|
gfxFontStyle();
|
2009-01-29 23:39:18 +03:00
|
|
|
gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, PRInt16 aStretch,
|
2010-02-24 20:57:57 +03:00
|
|
|
gfxFloat aSize, nsIAtom *aLanguage,
|
2011-09-29 10:19:26 +04:00
|
|
|
float aSizeAdjust, bool aSystemFont,
|
|
|
|
bool aPrinterFont,
|
2010-07-14 00:31:31 +04:00
|
|
|
const nsString& aFeatureSettings,
|
|
|
|
const nsString& aLanguageOverride);
|
2007-04-04 07:32:43 +04:00
|
|
|
gfxFontStyle(const gfxFontStyle& aStyle);
|
2005-10-08 09:09:42 +04:00
|
|
|
|
|
|
|
// The style of font (normal, italic, oblique)
|
|
|
|
PRUint8 style : 7;
|
|
|
|
|
2006-01-19 23:31:59 +03:00
|
|
|
// Say that this font is a system font and therefore does not
|
|
|
|
// require certain fixup that we do for fonts from untrusted
|
|
|
|
// sources.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool systemFont : 1;
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2008-12-17 06:17:50 +03:00
|
|
|
// Say that this font is used for print or print preview.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool printerFont : 1;
|
2008-12-17 06:17:50 +03:00
|
|
|
|
2010-11-10 18:49:52 +03:00
|
|
|
// The weight of the font: 100, 200, ... 900.
|
2005-10-08 09:09:42 +04:00
|
|
|
PRUint16 weight;
|
|
|
|
|
2009-01-29 23:39:18 +03:00
|
|
|
// The stretch of the font (the sum of various NS_FONT_STRETCH_*
|
|
|
|
// constants; see gfxFontConstants.h).
|
|
|
|
PRInt16 stretch;
|
|
|
|
|
2006-01-19 23:31:59 +03:00
|
|
|
// The logical size of the font, in pixels
|
2005-10-08 09:09:42 +04:00
|
|
|
gfxFloat size;
|
|
|
|
|
|
|
|
// The aspect-value (ie., the ratio actualsize:actualxheight) that any
|
|
|
|
// actual physical font created from this font structure must have when
|
|
|
|
// rendering or measuring a string. A value of 0 means no adjustment
|
|
|
|
// needs to be done.
|
|
|
|
float sizeAdjust;
|
2006-02-22 04:44:31 +03:00
|
|
|
|
2010-07-14 00:31:31 +04:00
|
|
|
// the language (may be an internal langGroup code rather than an actual
|
|
|
|
// language code) specified in the document or element's lang property,
|
|
|
|
// or inferred from the charset
|
2010-11-10 22:44:32 +03:00
|
|
|
nsRefPtr<nsIAtom> language;
|
2010-07-14 00:31:31 +04:00
|
|
|
|
|
|
|
// Language system tag, to override document language;
|
|
|
|
// an OpenType "language system" tag represented as a 32-bit integer
|
|
|
|
// (see http://www.microsoft.com/typography/otspec/languagetags.htm).
|
|
|
|
// Normally 0, so font rendering will use the document or element language
|
|
|
|
// (see above) to control any language-specific rendering, but the author
|
|
|
|
// can override this for cases where the options implemented in the font
|
|
|
|
// do not directly match the actual language. (E.g. lang may be Macedonian,
|
|
|
|
// but the font in use does not explicitly support this; the author can
|
|
|
|
// use font-language-override to request the Serbian option in the font
|
|
|
|
// in order to get correct glyph shapes.)
|
|
|
|
PRUint32 languageOverride;
|
|
|
|
|
|
|
|
// custom opentype feature settings
|
2010-12-09 14:52:03 +03:00
|
|
|
nsTArray<gfxFontFeature> featureSettings;
|
2010-07-14 00:31:31 +04:00
|
|
|
|
2007-06-08 12:22:03 +04:00
|
|
|
// Return the final adjusted font size for the given aspect ratio.
|
|
|
|
// Not meant to be called when sizeAdjust = 0.
|
|
|
|
gfxFloat GetAdjustedSize(gfxFloat aspect) const {
|
|
|
|
NS_ASSERTION(sizeAdjust != 0.0, "Not meant to be called when sizeAdjust = 0");
|
2011-06-25 18:06:02 +04:00
|
|
|
gfxFloat adjustedSize = NS_MAX(NS_round(size*(sizeAdjust/aspect)), 1.0);
|
|
|
|
return NS_MIN(adjustedSize, FONT_MAX_SIZE);
|
2007-06-08 12:22:03 +04:00
|
|
|
}
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
PLDHashNumber Hash() const {
|
2011-03-04 00:18:42 +03:00
|
|
|
return ((style + (systemFont << 7) +
|
|
|
|
(weight << 8)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^
|
2010-02-24 20:57:57 +03:00
|
|
|
nsISupportsHashKey::HashKey(language);
|
2007-04-04 07:32:43 +04:00
|
|
|
}
|
|
|
|
|
2010-11-10 18:49:52 +03:00
|
|
|
PRInt8 ComputeWeight() const;
|
2006-10-14 09:37:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const gfxFontStyle& other) const {
|
2006-10-14 09:37:40 +04:00
|
|
|
return (size == other.size) &&
|
|
|
|
(style == other.style) &&
|
|
|
|
(systemFont == other.systemFont) &&
|
2008-12-17 06:17:50 +03:00
|
|
|
(printerFont == other.printerFont) &&
|
2006-10-14 09:37:40 +04:00
|
|
|
(weight == other.weight) &&
|
2009-01-29 23:39:18 +03:00
|
|
|
(stretch == other.stretch) &&
|
2010-02-24 20:57:57 +03:00
|
|
|
(language == other.language) &&
|
2010-07-14 00:31:31 +04:00
|
|
|
(sizeAdjust == other.sizeAdjust) &&
|
2010-12-09 14:52:03 +03:00
|
|
|
(featureSettings == other.featureSettings) &&
|
2010-07-14 00:31:31 +04:00
|
|
|
(languageOverride == other.languageOverride);
|
2006-10-14 09:37:40 +04:00
|
|
|
}
|
2010-07-14 00:31:31 +04:00
|
|
|
|
|
|
|
static void ParseFontFeatureSettings(const nsString& aFeatureString,
|
|
|
|
nsTArray<gfxFontFeature>& aFeatures);
|
|
|
|
|
|
|
|
static PRUint32 ParseFontLanguageOverride(const nsString& aLangTag);
|
2005-10-08 09:09:42 +04:00
|
|
|
};
|
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
class gfxFontEntry {
|
|
|
|
public:
|
2010-04-01 22:05:40 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxFontEntry)
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxFontEntry(const nsAString& aName, gfxFontFamily *aFamily = nsnull,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aIsStandardFace = false) :
|
2011-10-17 18:59:28 +04:00
|
|
|
mName(aName), mItalic(false), mFixedPitch(false),
|
|
|
|
mIsProxy(false), mIsValid(true),
|
|
|
|
mIsBadUnderlineFont(false), mIsUserFont(false),
|
|
|
|
mIsLocalUserFont(false), mStandardFace(aIsStandardFace),
|
|
|
|
mSymbolFont(false),
|
|
|
|
mIgnoreGDEF(false),
|
2009-02-06 02:10:39 +03:00
|
|
|
mWeight(500), mStretch(NS_FONT_STRETCH_NORMAL),
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasCmapTable(false),
|
|
|
|
mCmapInitialized(false),
|
2010-06-01 17:42:37 +04:00
|
|
|
mUVSOffset(0), mUVSData(nsnull),
|
|
|
|
mUserFontData(nsnull),
|
2010-07-14 00:31:31 +04:00
|
|
|
mLanguageOverride(NO_FONT_LANGUAGE_OVERRIDE),
|
2009-08-16 17:52:12 +04:00
|
|
|
mFamily(aFamily)
|
2008-08-06 08:34:06 +04:00
|
|
|
{ }
|
|
|
|
|
|
|
|
virtual ~gfxFontEntry();
|
|
|
|
|
2011-06-16 10:31:37 +04:00
|
|
|
// unique name for the face, *not* the family; not necessarily the
|
|
|
|
// "real" or user-friendly name, may be an internal identifier
|
2008-08-06 08:34:06 +04:00
|
|
|
const nsString& Name() const { return mName; }
|
|
|
|
|
2011-06-16 10:31:37 +04:00
|
|
|
// the "real" name of the face, if available from the font resource
|
|
|
|
// (may be expensive); returns Name() if nothing better is available
|
|
|
|
virtual nsString RealFaceName();
|
|
|
|
|
2011-03-24 06:01:14 +03:00
|
|
|
gfxFontFamily* Family() const { return mFamily; }
|
|
|
|
|
2009-10-07 18:13:40 +04:00
|
|
|
PRUint16 Weight() const { return mWeight; }
|
|
|
|
PRInt16 Stretch() const { return mStretch; }
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsUserFont() const { return mIsUserFont; }
|
|
|
|
bool IsLocalUserFont() const { return mIsLocalUserFont; }
|
|
|
|
bool IsFixedPitch() const { return mFixedPitch; }
|
|
|
|
bool IsItalic() const { return mItalic; }
|
|
|
|
bool IsBold() const { return mWeight >= 600; } // bold == weights 600 and above
|
|
|
|
bool IgnoreGDEF() const { return mIgnoreGDEF; }
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool IsSymbolFont();
|
2011-05-20 10:09:30 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool HasCmapTable() {
|
2009-10-07 21:16:52 +04:00
|
|
|
if (!mCmapInitialized) {
|
|
|
|
ReadCMAP();
|
|
|
|
}
|
|
|
|
return mHasCmapTable;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool HasCharacter(PRUint32 ch) {
|
2008-08-06 08:34:06 +04:00
|
|
|
if (mCharacterMap.test(ch))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-06-01 17:42:37 +04:00
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
return TestCharacterMap(ch);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SkipDuringSystemFallback() { return false; }
|
|
|
|
virtual bool TestCharacterMap(PRUint32 aCh);
|
2010-06-01 17:42:37 +04:00
|
|
|
nsresult InitializeUVSMap();
|
|
|
|
PRUint16 GetUVSGlyph(PRUint32 aCh, PRUint32 aVS);
|
2009-08-16 17:52:12 +04:00
|
|
|
virtual nsresult ReadCMAP();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool MatchesGenericFamily(const nsACString& aGeneric) const {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SupportsLangGroup(nsIAtom *aLangGroup) const {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2009-10-07 18:13:40 +04:00
|
|
|
}
|
|
|
|
|
2011-01-07 07:45:10 +03:00
|
|
|
virtual nsresult GetFontTable(PRUint32 aTableTag, FallibleTArray<PRUint8>& aBuffer) {
|
2010-07-11 23:33:56 +04:00
|
|
|
return NS_ERROR_FAILURE; // all platform subclasses should reimplement this!
|
|
|
|
}
|
|
|
|
|
2010-01-09 06:52:32 +03:00
|
|
|
void SetFamily(gfxFontFamily* aFamily) {
|
|
|
|
mFamily = aFamily;
|
|
|
|
}
|
|
|
|
|
2011-06-16 10:31:37 +04:00
|
|
|
virtual nsString FamilyName() const;
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2010-06-11 23:14:38 +04:00
|
|
|
already_AddRefed<gfxFont> FindOrMakeFont(const gfxFontStyle *aStyle,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNeedsBold);
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2010-12-09 10:28:47 +03:00
|
|
|
// Get an existing font table cache entry in aBlob if it has been
|
2011-10-17 18:59:28 +04:00
|
|
|
// registered, or return false if not. Callers must call
|
|
|
|
// hb_blob_destroy on aBlob if true is returned.
|
2010-06-11 23:14:38 +04:00
|
|
|
//
|
|
|
|
// Note that some gfxFont implementations may not call this at all,
|
|
|
|
// if it is more efficient to get the table from the OS at that level.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetExistingFontTable(PRUint32 aTag, hb_blob_t** aBlob);
|
2010-12-09 10:28:47 +03:00
|
|
|
|
|
|
|
// Elements of aTable are transferred (not copied) to and returned in a
|
|
|
|
// new hb_blob_t which is registered on the gfxFontEntry, but the initial
|
|
|
|
// reference is owned by the caller. Removing the last reference
|
|
|
|
// unregisters the table from the font entry.
|
|
|
|
//
|
|
|
|
// Pass NULL for aBuffer to indicate that the table is not present and
|
|
|
|
// NULL will be returned. Also returns NULL on OOM.
|
|
|
|
hb_blob_t *ShareFontTableAndGetBlob(PRUint32 aTag,
|
2011-01-07 07:45:10 +03:00
|
|
|
FallibleTArray<PRUint8>* aTable);
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
nsString mName;
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mItalic : 1;
|
|
|
|
bool mFixedPitch : 1;
|
|
|
|
bool mIsProxy : 1;
|
|
|
|
bool mIsValid : 1;
|
|
|
|
bool mIsBadUnderlineFont : 1;
|
|
|
|
bool mIsUserFont : 1;
|
|
|
|
bool mIsLocalUserFont : 1;
|
|
|
|
bool mStandardFace : 1;
|
|
|
|
bool mSymbolFont : 1;
|
|
|
|
bool mIgnoreGDEF : 1;
|
2008-08-06 08:34:06 +04:00
|
|
|
|
|
|
|
PRUint16 mWeight;
|
2009-08-16 17:52:12 +04:00
|
|
|
PRInt16 mStretch;
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasCmapTable;
|
|
|
|
bool mCmapInitialized;
|
2008-08-06 08:34:06 +04:00
|
|
|
gfxSparseBitSet mCharacterMap;
|
2010-06-01 17:42:37 +04:00
|
|
|
PRUint32 mUVSOffset;
|
|
|
|
nsAutoArrayPtr<PRUint8> mUVSData;
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxUserFontData* mUserFontData;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2010-12-09 14:52:03 +03:00
|
|
|
nsTArray<gfxFontFeature> mFeatureSettings;
|
2010-07-14 00:31:31 +04:00
|
|
|
PRUint32 mLanguageOverride;
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
protected:
|
|
|
|
friend class gfxPlatformFontList;
|
|
|
|
friend class gfxMacPlatformFontList;
|
2010-11-22 01:21:19 +03:00
|
|
|
friend class gfxUserFcFontEntry;
|
2009-08-16 17:52:12 +04:00
|
|
|
friend class gfxFontFamily;
|
2010-01-29 04:41:25 +03:00
|
|
|
friend class gfxSingleFaceMacFontFamily;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
gfxFontEntry() :
|
2011-10-17 18:59:28 +04:00
|
|
|
mItalic(false), mFixedPitch(false),
|
|
|
|
mIsProxy(false), mIsValid(true),
|
|
|
|
mIsBadUnderlineFont(false),
|
|
|
|
mIsUserFont(false),
|
|
|
|
mIsLocalUserFont(false),
|
|
|
|
mStandardFace(false),
|
|
|
|
mSymbolFont(false),
|
|
|
|
mIgnoreGDEF(false),
|
2009-08-16 17:52:12 +04:00
|
|
|
mWeight(500), mStretch(NS_FONT_STRETCH_NORMAL),
|
2011-10-17 18:59:28 +04:00
|
|
|
mHasCmapTable(false),
|
|
|
|
mCmapInitialized(false),
|
2010-06-01 17:42:37 +04:00
|
|
|
mUVSOffset(0), mUVSData(nsnull),
|
2009-08-16 17:52:12 +04:00
|
|
|
mUserFontData(nsnull),
|
2010-07-14 00:31:31 +04:00
|
|
|
mLanguageOverride(NO_FONT_LANGUAGE_OVERRIDE),
|
2009-08-16 17:52:12 +04:00
|
|
|
mFamily(nsnull)
|
|
|
|
{ }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual gfxFont *CreateFontInstance(const gfxFontStyle *aFontStyle, bool aNeedsBold) {
|
2009-10-07 19:26:58 +04:00
|
|
|
NS_NOTREACHED("oops, somebody didn't override CreateFontInstance");
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
gfxFontFamily *mFamily;
|
2010-06-01 17:42:37 +04:00
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
private:
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Font table hashtable, to support GetFontTable for harfbuzz.
|
2010-06-11 23:14:38 +04:00
|
|
|
*
|
|
|
|
* The harfbuzz shaper (and potentially other clients) needs access to raw
|
|
|
|
* font table data. This needs to be cached so that it can be used
|
|
|
|
* repeatedly (each time we construct a text run; in some cases, for
|
|
|
|
* each character/glyph within the run) without re-fetching large tables
|
|
|
|
* every time.
|
|
|
|
*
|
|
|
|
* Because we may instantiate many gfxFonts for the same physical font
|
|
|
|
* file (at different sizes), we should ensure that they can share a
|
|
|
|
* single cached copy of the font tables. To do this, we implement table
|
2010-11-26 04:07:09 +03:00
|
|
|
* access and sharing on the fontEntry rather than the font itself.
|
2010-06-11 23:14:38 +04:00
|
|
|
*
|
|
|
|
* The default implementation uses GetFontTable() to read font table
|
2010-11-26 04:07:09 +03:00
|
|
|
* data into byte arrays, and wraps them in blobs which are registered in
|
|
|
|
* a hashtable. The hashtable can then return pre-existing blobs to
|
|
|
|
* harfbuzz.
|
2010-06-11 23:14:38 +04:00
|
|
|
*
|
2010-11-26 04:07:09 +03:00
|
|
|
* Harfbuzz will "destroy" the blobs when it is finished with them. When
|
|
|
|
* the last blob reference is removed, the FontTableBlobData user data
|
|
|
|
* will remove the blob from the hashtable if still registered.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class FontTableBlobData;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* FontTableHashEntry manages the entries of hb_blob_ts for two
|
|
|
|
* different situations:
|
|
|
|
*
|
|
|
|
* The common situation is to share font table across fonts with the same
|
|
|
|
* font entry (but different sizes) for use by HarfBuzz. The hashtable
|
|
|
|
* does not own a strong reference to the blob, but keeps a weak pointer,
|
|
|
|
* managed by FontTableBlobData. Similarly FontTableBlobData keeps only a
|
|
|
|
* weak pointer to the hashtable, managed by FontTableHashEntry.
|
|
|
|
*
|
|
|
|
* Some font tables are saved here before they would get stripped by OTS
|
|
|
|
* sanitizing. These are retained for harfbuzz, which does its own
|
|
|
|
* sanitizing. The hashtable owns a reference, so ownership is simple.
|
2010-06-11 23:14:38 +04:00
|
|
|
*/
|
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
class FontTableHashEntry : public nsUint32HashKey
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Declarations for nsTHashtable
|
|
|
|
|
|
|
|
typedef nsUint32HashKey KeyClass;
|
|
|
|
typedef KeyClass::KeyType KeyType;
|
|
|
|
typedef KeyClass::KeyTypePointer KeyTypePointer;
|
|
|
|
|
|
|
|
FontTableHashEntry(KeyTypePointer aTag)
|
|
|
|
: KeyClass(aTag), mBlob() { };
|
|
|
|
// Copying transfers blob association.
|
|
|
|
FontTableHashEntry(FontTableHashEntry& toCopy)
|
|
|
|
: KeyClass(toCopy), mBlob(toCopy.mBlob)
|
|
|
|
{
|
|
|
|
toCopy.mBlob = nsnull;
|
2010-06-11 23:14:38 +04:00
|
|
|
}
|
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
~FontTableHashEntry() { Clear(); }
|
|
|
|
|
|
|
|
// FontTable/Blob API
|
|
|
|
|
|
|
|
// Transfer (not copy) elements of aTable to a new hb_blob_t and
|
|
|
|
// return ownership to the caller. A weak reference to the blob is
|
|
|
|
// recorded in the hashtable entry so that others may use the same
|
|
|
|
// table.
|
|
|
|
hb_blob_t *
|
2011-01-07 07:45:10 +03:00
|
|
|
ShareTableAndGetBlob(FallibleTArray<PRUint8>& aTable,
|
2010-11-26 04:07:09 +03:00
|
|
|
nsTHashtable<FontTableHashEntry> *aHashtable);
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
// Transfer (not copy) elements of aTable to a new hb_blob_t that is
|
|
|
|
// owned by the hashtable entry.
|
2011-01-07 07:45:10 +03:00
|
|
|
void SaveTable(FallibleTArray<PRUint8>& aTable);
|
2010-11-26 04:07:09 +03:00
|
|
|
|
|
|
|
// Return a strong reference to the blob.
|
|
|
|
// Callers must hb_blob_destroy the returned blob.
|
|
|
|
hb_blob_t *GetBlob() const;
|
|
|
|
|
|
|
|
void Clear();
|
2010-06-11 23:14:38 +04:00
|
|
|
|
|
|
|
private:
|
2010-11-26 04:07:09 +03:00
|
|
|
static void DeleteFontTableBlobData(void *aBlobData);
|
2010-06-11 23:14:38 +04:00
|
|
|
// not implemented
|
2010-11-26 04:07:09 +03:00
|
|
|
FontTableHashEntry& operator=(FontTableHashEntry& toCopy);
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
FontTableBlobData *mSharedBlobData;
|
|
|
|
hb_blob_t *mBlob;
|
2010-06-11 23:14:38 +04:00
|
|
|
};
|
|
|
|
|
2010-11-26 04:07:09 +03:00
|
|
|
nsTHashtable<FontTableHashEntry> mFontTableCache;
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2010-06-01 17:42:37 +04:00
|
|
|
gfxFontEntry(const gfxFontEntry&);
|
|
|
|
gfxFontEntry& operator=(const gfxFontEntry&);
|
2009-08-16 17:52:12 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// used when picking fallback font
|
|
|
|
struct FontSearch {
|
|
|
|
FontSearch(const PRUint32 aCharacter, gfxFont *aFont) :
|
2011-01-21 19:44:33 +03:00
|
|
|
mCh(aCharacter), mFontToMatch(aFont), mMatchRank(0), mCount(0) {
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
const PRUint32 mCh;
|
|
|
|
gfxFont* mFontToMatch;
|
|
|
|
PRInt32 mMatchRank;
|
|
|
|
nsRefPtr<gfxFontEntry> mBestMatch;
|
2011-01-21 19:44:33 +03:00
|
|
|
PRUint32 mCount;
|
2008-08-06 08:34:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class gfxFontFamily {
|
|
|
|
public:
|
2010-04-01 22:05:40 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxFontFamily)
|
2008-08-06 08:34:06 +04:00
|
|
|
|
|
|
|
gfxFontFamily(const nsAString& aName) :
|
2009-10-13 03:43:43 +04:00
|
|
|
mName(aName),
|
2011-10-17 18:59:28 +04:00
|
|
|
mOtherFamilyNamesInitialized(false),
|
|
|
|
mHasOtherFamilyNames(false),
|
|
|
|
mFaceNamesInitialized(false),
|
|
|
|
mHasStyles(false),
|
|
|
|
mIsSimpleFamily(false),
|
|
|
|
mIsBadUnderlineFamily(false)
|
2009-08-16 17:52:12 +04:00
|
|
|
{ }
|
2008-08-06 08:34:06 +04:00
|
|
|
|
|
|
|
virtual ~gfxFontFamily() { }
|
|
|
|
|
|
|
|
const nsString& Name() { return mName; }
|
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
virtual void LocalizedName(nsAString& aLocalizedName);
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool HasOtherFamilyNames();
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
nsTArray<nsRefPtr<gfxFontEntry> >& GetFontList() { return mAvailableFonts; }
|
|
|
|
|
|
|
|
void AddFontEntry(nsRefPtr<gfxFontEntry> aFontEntry) {
|
2011-04-19 12:01:21 +04:00
|
|
|
// bug 589682 - set the IgnoreGDEF flag on entries for Italic faces
|
|
|
|
// of Times New Roman, because of buggy table in those fonts
|
|
|
|
if (aFontEntry->IsItalic() && !aFontEntry->IsUserFont() &&
|
|
|
|
Name().EqualsLiteral("Times New Roman"))
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
aFontEntry->mIgnoreGDEF = true;
|
2011-04-19 12:01:21 +04:00
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
mAvailableFonts.AppendElement(aFontEntry);
|
2011-01-27 06:05:55 +03:00
|
|
|
aFontEntry->SetFamily(this);
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// note that the styles for this family have been added
|
2011-09-29 10:19:26 +04:00
|
|
|
void SetHasStyles(bool aHasStyles) { mHasStyles = aHasStyles; }
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
// choose a specific face to match a style using CSS font matching
|
2010-03-12 07:26:43 +03:00
|
|
|
// rules (weight matching occurs here). may return a face that doesn't
|
|
|
|
// precisely match (e.g. normal face when no italic face exists).
|
|
|
|
// aNeedsSyntheticBold is set to true when synthetic bolding is
|
|
|
|
// needed, false otherwise
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxFontEntry *FindFontForStyle(const gfxFontStyle& aFontStyle,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool& aNeedsSyntheticBold);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// iterates over faces looking for a match with a given characters
|
|
|
|
// used as part of the font fallback process
|
|
|
|
void FindFontForChar(FontSearch *aMatchData);
|
|
|
|
|
|
|
|
// read in other family names, if any, and use functor to add each into cache
|
2010-01-29 04:41:25 +03:00
|
|
|
virtual void ReadOtherFamilyNames(gfxPlatformFontList *aPlatformFontList);
|
|
|
|
|
2011-01-07 15:29:49 +03:00
|
|
|
// set when other family names have been read in
|
|
|
|
void SetOtherFamilyNamesInitialized() {
|
2011-10-17 18:59:28 +04:00
|
|
|
mOtherFamilyNamesInitialized = true;
|
2011-01-07 15:29:49 +03:00
|
|
|
}
|
|
|
|
|
2010-01-29 04:41:25 +03:00
|
|
|
// read in other localized family names, fullnames and Postscript names
|
|
|
|
// for all faces and append to lookup tables
|
|
|
|
virtual void ReadFaceNames(gfxPlatformFontList *aPlatformFontList,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNeedFullnamePostscriptNames);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2009-10-13 03:43:43 +04:00
|
|
|
// find faces belonging to this family (platform implementations override this;
|
|
|
|
// should be made pure virtual once all subclasses have been updated)
|
2009-08-16 17:52:12 +04:00
|
|
|
virtual void FindStyleVariations() { }
|
|
|
|
|
|
|
|
// search for a specific face using the Postscript name
|
|
|
|
gfxFontEntry* FindFont(const nsAString& aPostscriptName);
|
|
|
|
|
|
|
|
// read in cmaps for all the faces
|
|
|
|
void ReadCMAP() {
|
|
|
|
PRUint32 i, numFonts = mAvailableFonts.Length();
|
2011-08-13 16:34:56 +04:00
|
|
|
// called from RunLoader BEFORE CheckForSimpleFamily so that there cannot
|
|
|
|
// be any NULL entries in mAvailableFonts
|
|
|
|
for (i = 0; i < numFonts; i++)
|
|
|
|
mAvailableFonts[i]->ReadCMAP();
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2009-10-13 03:43:43 +04:00
|
|
|
// mark this family as being in the "bad" underline offset blacklist
|
|
|
|
void SetBadUnderlineFamily() {
|
2011-10-17 18:59:28 +04:00
|
|
|
mIsBadUnderlineFamily = true;
|
2009-10-13 03:43:43 +04:00
|
|
|
if (mHasStyles) {
|
|
|
|
SetBadUnderlineFonts();
|
|
|
|
}
|
2009-08-16 17:52:12 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsBadUnderlineFamily() const { return mIsBadUnderlineFamily; }
|
2010-01-28 09:56:16 +03:00
|
|
|
|
2009-08-16 17:52:12 +04:00
|
|
|
// sort available fonts to put preferred (standard) faces towards the end
|
|
|
|
void SortAvailableFonts();
|
|
|
|
|
|
|
|
// check whether the family fits into the simple 4-face model,
|
|
|
|
// so we can use simplified style-matching;
|
|
|
|
// if so set the mIsSimpleFamily flag (defaults to False before we've checked)
|
|
|
|
void CheckForSimpleFamily();
|
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
protected:
|
2009-08-16 17:52:12 +04:00
|
|
|
// fills in an array with weights of faces that match style,
|
|
|
|
// returns whether any matching entries found
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool FindWeightsForStyle(gfxFontEntry* aFontsForWeights[],
|
|
|
|
bool anItalic, PRInt16 aStretch);
|
2009-08-16 17:52:12 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ReadOtherFamilyNamesForFace(gfxPlatformFontList *aPlatformFontList,
|
2011-01-07 07:45:10 +03:00
|
|
|
FallibleTArray<PRUint8>& aNameTable,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool useFullName = false);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2009-10-13 03:43:43 +04:00
|
|
|
// set whether this font family is in "bad" underline offset blacklist.
|
|
|
|
void SetBadUnderlineFonts() {
|
|
|
|
PRUint32 i, numFonts = mAvailableFonts.Length();
|
|
|
|
for (i = 0; i < numFonts; i++) {
|
|
|
|
if (mAvailableFonts[i]) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mAvailableFonts[i]->mIsBadUnderlineFont = true;
|
2009-10-13 03:43:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
nsString mName;
|
2009-08-16 17:52:12 +04:00
|
|
|
nsTArray<nsRefPtr<gfxFontEntry> > mAvailableFonts;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mOtherFamilyNamesInitialized;
|
|
|
|
bool mHasOtherFamilyNames;
|
|
|
|
bool mFaceNamesInitialized;
|
|
|
|
bool mHasStyles;
|
|
|
|
bool mIsSimpleFamily;
|
|
|
|
bool mIsBadUnderlineFamily;
|
2009-08-16 17:52:12 +04:00
|
|
|
|
|
|
|
enum {
|
|
|
|
// for "simple" families, the faces are stored in mAvailableFonts
|
|
|
|
// with fixed positions:
|
|
|
|
kRegularFaceIndex = 0,
|
|
|
|
kBoldFaceIndex = 1,
|
|
|
|
kItalicFaceIndex = 2,
|
|
|
|
kBoldItalicFaceIndex = 3,
|
|
|
|
// mask values for selecting face with bold and/or italic attributes
|
|
|
|
kBoldMask = 0x01,
|
|
|
|
kItalicMask = 0x02
|
|
|
|
};
|
2008-08-06 08:34:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct gfxTextRange {
|
2011-06-16 10:31:37 +04:00
|
|
|
enum {
|
|
|
|
// flags for recording the kind of font-matching that was used
|
|
|
|
kFontGroup = 0x0001,
|
|
|
|
kPrefsFallback = 0x0002,
|
|
|
|
kSystemFallback = 0x0004
|
|
|
|
};
|
|
|
|
gfxTextRange(PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
gfxFont* aFont, PRUint8 aMatchType)
|
|
|
|
: start(aStart),
|
|
|
|
end(aEnd),
|
|
|
|
font(aFont),
|
|
|
|
matchType(aMatchType)
|
|
|
|
{ }
|
2008-08-06 08:34:06 +04:00
|
|
|
PRUint32 Length() const { return end - start; }
|
2011-06-16 00:52:48 +04:00
|
|
|
PRUint32 start, end;
|
2011-06-16 10:31:37 +04:00
|
|
|
nsRefPtr<gfxFont> font;
|
|
|
|
PRUint8 matchType;
|
2008-08-06 08:34:06 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
/**
|
|
|
|
* Font cache design:
|
|
|
|
*
|
2010-07-14 00:31:31 +04:00
|
|
|
* The mFonts hashtable contains most fonts, indexed by (gfxFontEntry*, style).
|
2007-04-04 07:32:43 +04:00
|
|
|
* It does not add a reference to the fonts it contains.
|
|
|
|
* When a font's refcount decreases to zero, instead of deleting it we
|
|
|
|
* add it to our expiration tracker.
|
|
|
|
* The expiration tracker tracks fonts with zero refcount. After a certain
|
|
|
|
* period of time, such fonts expire and are deleted.
|
|
|
|
*
|
|
|
|
* We're using 3 generations with a ten-second generation interval, so
|
|
|
|
* zero-refcount fonts will be deleted 20-30 seconds after their refcount
|
|
|
|
* goes to zero, if timer events fire in a timely manner.
|
|
|
|
*/
|
|
|
|
class THEBES_API gfxFontCache : public nsExpirationTracker<gfxFont,3> {
|
|
|
|
public:
|
2007-05-21 05:54:13 +04:00
|
|
|
enum { TIMEOUT_SECONDS = 10 };
|
2007-04-04 07:32:43 +04:00
|
|
|
gfxFontCache()
|
|
|
|
: nsExpirationTracker<gfxFont,3>(TIMEOUT_SECONDS*1000) { mFonts.Init(); }
|
|
|
|
~gfxFontCache() {
|
|
|
|
// Expire everything that has a zero refcount, so we don't leak them.
|
|
|
|
AgeAllGenerations();
|
2007-07-04 07:24:04 +04:00
|
|
|
// All fonts should be gone.
|
|
|
|
NS_WARN_IF_FALSE(mFonts.Count() == 0,
|
|
|
|
"Fonts still alive while shutting down gfxFontCache");
|
2007-04-04 07:32:43 +04:00
|
|
|
// Note that we have to delete everything through the expiration
|
|
|
|
// tracker, since there might be fonts not in the hashtable but in
|
|
|
|
// the tracker.
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the global gfxFontCache. You must call Init() before
|
|
|
|
* calling this method --- the result will not be null.
|
|
|
|
*/
|
|
|
|
static gfxFontCache* GetCache() {
|
|
|
|
return gGlobalCache;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult Init();
|
|
|
|
// It's OK to call this even if Init() has not been called.
|
|
|
|
static void Shutdown();
|
|
|
|
|
|
|
|
// Look up a font in the cache. Returns an addrefed pointer, or null
|
|
|
|
// if there's nothing matching in the cache
|
2010-07-14 00:31:31 +04:00
|
|
|
already_AddRefed<gfxFont> Lookup(const gfxFontEntry *aFontEntry,
|
2007-04-04 07:32:43 +04:00
|
|
|
const gfxFontStyle *aFontGroup);
|
|
|
|
// We created a new font (presumably because Lookup returned null);
|
|
|
|
// put it in the cache. The font's refcount should be nonzero. It is
|
|
|
|
// allowable to add a new font even if there is one already in the
|
|
|
|
// cache with the same key; we'll forget about the old one.
|
|
|
|
void AddNew(gfxFont *aFont);
|
|
|
|
|
|
|
|
// The font's refcount has gone to zero; give ownership of it to
|
|
|
|
// the cache. We delete it if it's not acquired again after a certain
|
|
|
|
// amount of time.
|
|
|
|
void NotifyReleased(gfxFont *aFont);
|
|
|
|
|
|
|
|
// This gets called when the timeout has expired on a zero-refcount
|
|
|
|
// font; we just delete it.
|
|
|
|
virtual void NotifyExpired(gfxFont *aFont);
|
|
|
|
|
2010-06-09 04:33:13 +04:00
|
|
|
// Cleans out the hashtable and removes expired fonts waiting for cleanup.
|
|
|
|
// Other gfxFont objects may be still in use but they will be pushed
|
|
|
|
// into the expiration queues and removed.
|
|
|
|
void Flush() {
|
|
|
|
mFonts.Clear();
|
|
|
|
AgeAllGenerations();
|
|
|
|
}
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
protected:
|
|
|
|
void DestroyFont(gfxFont *aFont);
|
|
|
|
|
|
|
|
static gfxFontCache *gGlobalCache;
|
|
|
|
|
|
|
|
struct Key {
|
2010-07-14 00:31:31 +04:00
|
|
|
const gfxFontEntry* mFontEntry;
|
2007-04-04 07:32:43 +04:00
|
|
|
const gfxFontStyle* mStyle;
|
2010-07-14 00:31:31 +04:00
|
|
|
Key(const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle)
|
|
|
|
: mFontEntry(aFontEntry), mStyle(aStyle) {}
|
2007-04-04 07:32:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class HashEntry : public PLDHashEntryHdr {
|
|
|
|
public:
|
|
|
|
typedef const Key& KeyType;
|
|
|
|
typedef const Key* KeyTypePointer;
|
|
|
|
|
|
|
|
// When constructing a new entry in the hashtable, we'll leave this
|
|
|
|
// blank. The caller of Put() will fill this in.
|
|
|
|
HashEntry(KeyTypePointer aStr) : mFont(nsnull) { }
|
|
|
|
HashEntry(const HashEntry& toCopy) : mFont(toCopy.mFont) { }
|
|
|
|
~HashEntry() { }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2007-04-04 07:32:43 +04:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
2010-07-14 00:31:31 +04:00
|
|
|
return NS_PTR_TO_INT32(aKey->mFontEntry) ^ aKey->mStyle->Hash();
|
2007-04-04 07:32:43 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2007-04-04 07:32:43 +04:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
gfxFont* mFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<HashEntry> mFonts;
|
|
|
|
};
|
2007-09-24 06:19:16 +04:00
|
|
|
|
2007-09-24 06:19:14 +04:00
|
|
|
/**
|
|
|
|
* This stores glyph bounds information for a particular gfxFont, at
|
|
|
|
* a particular appunits-per-dev-pixel ratio (because the compressed glyph
|
|
|
|
* width array is stored in appunits).
|
|
|
|
*
|
|
|
|
* We store a hashtable from glyph IDs to float bounding rects. For the
|
|
|
|
* common case where the glyph has no horizontal left bearing, and no
|
|
|
|
* y overflow above the font ascent or below the font descent, and tight
|
|
|
|
* bounding boxes are not required, we avoid storing the glyph ID in the hashtable
|
|
|
|
* and instead consult an array of 16-bit glyph XMost values (in appunits).
|
|
|
|
* This array always has an entry for the font's space glyph --- the width is
|
|
|
|
* assumed to be zero.
|
|
|
|
*/
|
|
|
|
class THEBES_API gfxGlyphExtents {
|
|
|
|
public:
|
|
|
|
gfxGlyphExtents(PRUint32 aAppUnitsPerDevUnit) :
|
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit) {
|
2007-10-02 05:47:40 +04:00
|
|
|
MOZ_COUNT_CTOR(gfxGlyphExtents);
|
2007-09-24 06:19:14 +04:00
|
|
|
mTightGlyphExtents.Init();
|
|
|
|
}
|
2007-10-02 05:47:40 +04:00
|
|
|
~gfxGlyphExtents();
|
2007-09-24 06:19:14 +04:00
|
|
|
|
|
|
|
enum { INVALID_WIDTH = 0xFFFF };
|
|
|
|
|
|
|
|
// returns INVALID_WIDTH => not a contained glyph
|
|
|
|
// Otherwise the glyph has no before-bearing or vertical bearings,
|
|
|
|
// and the result is its width measured from the baseline origin, in
|
|
|
|
// appunits.
|
|
|
|
PRUint16 GetContainedGlyphWidthAppUnits(PRUint32 aGlyphID) const {
|
2007-10-02 05:47:40 +04:00
|
|
|
return mContainedGlyphWidths.Get(aGlyphID);
|
2007-09-24 06:19:14 +04:00
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsGlyphKnown(PRUint32 aGlyphID) const {
|
2007-10-02 05:47:40 +04:00
|
|
|
return mContainedGlyphWidths.Get(aGlyphID) != INVALID_WIDTH ||
|
|
|
|
mTightGlyphExtents.GetEntry(aGlyphID) != nsnull;
|
2007-09-24 06:19:14 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsGlyphKnownWithTightExtents(PRUint32 aGlyphID) const {
|
2007-09-24 06:19:14 +04:00
|
|
|
return mTightGlyphExtents.GetEntry(aGlyphID) != nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get glyph extents; a rectangle relative to the left baseline origin
|
2007-12-21 10:09:50 +03:00
|
|
|
// Returns true on success. Can fail on OOM or when aContext is null
|
|
|
|
// and extents were not (successfully) prefetched.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetTightGlyphExtentsAppUnits(gfxFont *aFont, gfxContext *aContext,
|
2007-12-21 10:09:50 +03:00
|
|
|
PRUint32 aGlyphID, gfxRect *aExtents);
|
2007-09-24 06:19:14 +04:00
|
|
|
|
2007-10-02 05:47:40 +04:00
|
|
|
void SetContainedGlyphWidthAppUnits(PRUint32 aGlyphID, PRUint16 aWidth) {
|
|
|
|
mContainedGlyphWidths.Set(aGlyphID, aWidth);
|
|
|
|
}
|
2007-09-24 06:19:14 +04:00
|
|
|
void SetTightGlyphExtents(PRUint32 aGlyphID, const gfxRect& aExtentsAppUnits);
|
|
|
|
|
|
|
|
PRUint32 GetAppUnitsPerDevUnit() { return mAppUnitsPerDevUnit; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
class HashEntry : public nsUint32HashKey {
|
|
|
|
public:
|
|
|
|
// When constructing a new entry in the hashtable, we'll leave this
|
|
|
|
// blank. The caller of Put() will fill this in.
|
|
|
|
HashEntry(KeyTypePointer aPtr) : nsUint32HashKey(aPtr) {}
|
|
|
|
HashEntry(const HashEntry& toCopy) : nsUint32HashKey(toCopy) {
|
|
|
|
x = toCopy.x; y = toCopy.y; width = toCopy.width; height = toCopy.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
float x, y, width, height;
|
|
|
|
};
|
|
|
|
|
2009-09-05 06:46:09 +04:00
|
|
|
typedef PRUptrdiff PtrBits;
|
2007-10-02 05:47:40 +04:00
|
|
|
enum { BLOCK_SIZE_BITS = 7, BLOCK_SIZE = 1 << BLOCK_SIZE_BITS }; // 128-glyph blocks
|
|
|
|
|
|
|
|
class GlyphWidths {
|
|
|
|
public:
|
|
|
|
void Set(PRUint32 aIndex, PRUint16 aValue);
|
|
|
|
PRUint16 Get(PRUint32 aIndex) const {
|
|
|
|
PRUint32 block = aIndex >> BLOCK_SIZE_BITS;
|
|
|
|
if (block >= mBlocks.Length())
|
|
|
|
return INVALID_WIDTH;
|
|
|
|
PtrBits bits = mBlocks[block];
|
|
|
|
if (!bits)
|
|
|
|
return INVALID_WIDTH;
|
|
|
|
PRUint32 indexInBlock = aIndex & (BLOCK_SIZE - 1);
|
|
|
|
if (bits & 0x1) {
|
|
|
|
if (GetGlyphOffset(bits) != indexInBlock)
|
|
|
|
return INVALID_WIDTH;
|
|
|
|
return GetWidth(bits);
|
|
|
|
}
|
|
|
|
PRUint16 *widths = reinterpret_cast<PRUint16 *>(bits);
|
|
|
|
return widths[indexInBlock];
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRUint32 ComputeSize();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
~GlyphWidths();
|
|
|
|
|
|
|
|
private:
|
|
|
|
static PRUint32 GetGlyphOffset(PtrBits aBits) {
|
|
|
|
NS_ASSERTION(aBits & 0x1, "This is really a pointer...");
|
|
|
|
return (aBits >> 1) & ((1 << BLOCK_SIZE_BITS) - 1);
|
|
|
|
}
|
|
|
|
static PRUint32 GetWidth(PtrBits aBits) {
|
|
|
|
NS_ASSERTION(aBits & 0x1, "This is really a pointer...");
|
|
|
|
return aBits >> (1 + BLOCK_SIZE_BITS);
|
|
|
|
}
|
|
|
|
static PtrBits MakeSingle(PRUint32 aGlyphOffset, PRUint16 aWidth) {
|
|
|
|
return (aWidth << (1 + BLOCK_SIZE_BITS)) + (aGlyphOffset << 1) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTArray<PtrBits> mBlocks;
|
|
|
|
};
|
|
|
|
|
|
|
|
GlyphWidths mContainedGlyphWidths;
|
2007-09-24 06:19:14 +04:00
|
|
|
nsTHashtable<HashEntry> mTightGlyphExtents;
|
|
|
|
PRUint32 mAppUnitsPerDevUnit;
|
|
|
|
};
|
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
/**
|
|
|
|
* gfxFontShaper
|
|
|
|
*
|
|
|
|
* This class implements text shaping (character to glyph mapping and
|
|
|
|
* glyph layout). There is a gfxFontShaper subclass for each text layout
|
|
|
|
* technology (uniscribe, core text, harfbuzz,....) we support.
|
|
|
|
*
|
|
|
|
* The shaper is responsible for setting up glyph data in gfxTextRuns.
|
|
|
|
*
|
|
|
|
* A generic, platform-independent shaper relies only on the standard
|
|
|
|
* gfxFont interface and can work with any concrete subclass of gfxFont.
|
|
|
|
*
|
|
|
|
* Platform-specific implementations designed to interface to platform
|
|
|
|
* shaping APIs such as Uniscribe or CoreText may rely on features of a
|
|
|
|
* specific font subclass to access native font references
|
|
|
|
* (such as CTFont, HFONT, DWriteFont, etc).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class gfxFontShaper {
|
|
|
|
public:
|
|
|
|
gfxFontShaper(gfxFont *aFont)
|
2009-10-07 21:16:52 +04:00
|
|
|
: mFont(aFont)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFont, "shaper requires a valid font!");
|
|
|
|
}
|
2010-03-10 15:46:41 +03:00
|
|
|
|
|
|
|
virtual ~gfxFontShaper() { }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool InitTextRun(gfxContext *aContext,
|
2010-03-15 12:34:25 +03:00
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const PRUnichar *aString,
|
|
|
|
PRUint32 aRunStart,
|
2010-06-11 23:14:38 +04:00
|
|
|
PRUint32 aRunLength,
|
|
|
|
PRInt32 aRunScript) = 0;
|
2010-03-10 15:46:41 +03:00
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxFont *GetFont() const { return mFont; }
|
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
protected:
|
|
|
|
// the font this shaper is working with
|
|
|
|
gfxFont * mFont;
|
|
|
|
};
|
|
|
|
|
2005-10-08 09:09:42 +04:00
|
|
|
/* a SPECIFIC single font family */
|
2006-04-27 18:41:11 +04:00
|
|
|
class THEBES_API gfxFont {
|
2007-04-04 07:32:43 +04:00
|
|
|
public:
|
|
|
|
nsrefcnt AddRef(void) {
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
2008-01-22 06:11:46 +03:00
|
|
|
if (mExpirationState.IsTracked()) {
|
|
|
|
gfxFontCache::GetCache()->RemoveObject(this);
|
|
|
|
}
|
2007-04-04 07:32:43 +04:00
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "gfxFont", sizeof(*this));
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
nsrefcnt Release(void) {
|
|
|
|
NS_PRECONDITION(0 != mRefCnt, "dup release");
|
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "gfxFont");
|
|
|
|
if (mRefCnt == 0) {
|
2008-09-22 00:41:40 +04:00
|
|
|
NotifyReleased();
|
|
|
|
// |this| may have been deleted.
|
2008-09-19 07:02:35 +04:00
|
|
|
return 0;
|
2007-04-04 07:32:43 +04:00
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetRefCount() { return mRefCnt; }
|
|
|
|
|
2010-03-15 12:34:25 +03:00
|
|
|
// options to specify the kind of AA to be used when creating a font
|
|
|
|
typedef enum {
|
|
|
|
kAntialiasDefault,
|
|
|
|
kAntialiasNone,
|
|
|
|
kAntialiasGrayscale,
|
|
|
|
kAntialiasSubpixel
|
|
|
|
} AntialiasOption;
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
protected:
|
|
|
|
nsAutoRefCnt mRefCnt;
|
2006-02-24 08:15:21 +03:00
|
|
|
|
2008-09-22 00:41:40 +04:00
|
|
|
void NotifyReleased() {
|
|
|
|
gfxFontCache *cache = gfxFontCache::GetCache();
|
|
|
|
if (cache) {
|
|
|
|
// Don't delete just yet; return the object to the cache for
|
|
|
|
// possibly recycling within some time limit
|
|
|
|
cache->NotifyReleased(this);
|
|
|
|
} else {
|
|
|
|
// The cache may have already been shut down.
|
|
|
|
delete this;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-15 12:34:25 +03:00
|
|
|
gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
|
|
|
|
AntialiasOption anAAOption = kAntialiasDefault);
|
2008-09-22 00:41:40 +04:00
|
|
|
|
|
|
|
public:
|
2007-09-24 06:19:14 +04:00
|
|
|
virtual ~gfxFont();
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Valid() const {
|
2009-10-07 19:26:58 +04:00
|
|
|
return mIsValid;
|
|
|
|
}
|
|
|
|
|
2009-02-24 11:32:58 +03:00
|
|
|
// options for the kind of bounding box to return from measurement
|
|
|
|
typedef enum {
|
|
|
|
LOOSE_INK_EXTENTS,
|
|
|
|
// A box that encloses all the painted pixels, and may
|
|
|
|
// include sidebearings and/or additional ascent/descent
|
|
|
|
// within the glyph cell even if the ink is smaller.
|
|
|
|
TIGHT_INK_EXTENTS,
|
|
|
|
// A box that tightly encloses all the painted pixels
|
|
|
|
// (although actually on Windows, at least, it may be
|
|
|
|
// slightly larger than strictly necessary because
|
|
|
|
// we can't get precise extents with ClearType).
|
|
|
|
TIGHT_HINTED_OUTLINE_EXTENTS
|
|
|
|
// A box that tightly encloses the glyph outline,
|
|
|
|
// ignoring possible antialiasing pixels that extend
|
|
|
|
// beyond this.
|
|
|
|
// NOTE: The default implementation of gfxFont::Measure(),
|
|
|
|
// which works with the glyph extents cache, does not
|
|
|
|
// differentiate between this and TIGHT_INK_EXTENTS.
|
|
|
|
// Whether the distinction is important depends on the
|
|
|
|
// antialiasing behavior of the platform; currently the
|
|
|
|
// distinction is only implemented in the gfxWindowsFont
|
|
|
|
// subclass, because of ClearType's tendency to paint
|
|
|
|
// outside the hinted outline.
|
|
|
|
// Also NOTE: it is relatively expensive to request this,
|
|
|
|
// as it does not use cached glyph extents in the font.
|
|
|
|
} BoundingBoxType;
|
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
const nsString& GetName() const { return mFontEntry->Name(); }
|
2007-04-04 07:32:43 +04:00
|
|
|
const gfxFontStyle *GetStyle() const { return &mStyle; }
|
2006-06-10 04:21:05 +04:00
|
|
|
|
2010-03-15 12:34:25 +03:00
|
|
|
virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption) {
|
|
|
|
// platforms where this actually matters should override
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2011-01-21 19:44:32 +03:00
|
|
|
virtual gfxFloat GetAdjustedSize() {
|
2009-10-07 21:16:52 +04:00
|
|
|
return mAdjustedSize > 0.0 ? mAdjustedSize : mStyle.size;
|
|
|
|
}
|
|
|
|
|
|
|
|
float FUnitsToDevUnitsFactor() const {
|
|
|
|
// check this was set up during font initialization
|
|
|
|
NS_ASSERTION(mFUnitsConvFactor > 0.0f, "mFUnitsConvFactor not valid");
|
|
|
|
return mFUnitsConvFactor;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check whether this is an sfnt we can potentially use with harfbuzz
|
2011-09-29 10:19:26 +04:00
|
|
|
bool FontCanSupportHarfBuzz() {
|
2009-10-07 21:16:52 +04:00
|
|
|
return mFontEntry->HasCmapTable();
|
|
|
|
}
|
|
|
|
|
2010-06-11 23:14:38 +04:00
|
|
|
// Access to raw font table data (needed for Harfbuzz):
|
|
|
|
// returns a pointer to data owned by the fontEntry or the OS,
|
|
|
|
// which will remain valid until released.
|
|
|
|
//
|
2010-12-09 10:28:47 +03:00
|
|
|
// Default implementations forward to the font entry,
|
|
|
|
// and maintain a shared table.
|
|
|
|
//
|
|
|
|
// Subclasses should override this if they can provide more efficient
|
|
|
|
// access than getting tables with mFontEntry->GetFontTable() and sharing
|
|
|
|
// them via the entry.
|
|
|
|
//
|
|
|
|
// Get pointer to a specific font table, or NULL if
|
2010-06-11 23:14:38 +04:00
|
|
|
// the table doesn't exist in the font
|
2010-12-09 10:28:47 +03:00
|
|
|
virtual hb_blob_t *GetFontTable(PRUint32 aTag);
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
// Subclasses may choose to look up glyph ids for characters.
|
|
|
|
// If they do not override this, gfxHarfBuzzShaper will fetch the cmap
|
|
|
|
// table and use that.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ProvidesGetGlyph() const {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-12-09 10:28:51 +03:00
|
|
|
}
|
|
|
|
// Map unicode character to glyph ID.
|
2011-10-17 18:59:28 +04:00
|
|
|
// Only used if ProvidesGetGlyph() returns true.
|
2010-12-09 10:28:51 +03:00
|
|
|
virtual PRUint32 GetGlyph(PRUint32 unicode, PRUint32 variation_selector) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-01-21 13:35:21 +03:00
|
|
|
// subclasses may provide (possibly hinted) glyph widths (in font units);
|
2009-10-07 21:16:52 +04:00
|
|
|
// if they do not override this, harfbuzz will use unhinted widths
|
|
|
|
// derived from the font tables
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool ProvidesGlyphWidths() {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-10-07 21:16:52 +04:00
|
|
|
}
|
|
|
|
|
2010-12-09 10:28:51 +03:00
|
|
|
// The return value is interpreted as a horizontal advance in 16.16 fixed
|
|
|
|
// point format.
|
2011-01-21 13:35:21 +03:00
|
|
|
virtual PRInt32 GetGlyphWidth(gfxContext *aCtx, PRUint16 aGID) {
|
2009-10-07 21:16:52 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2011-05-02 13:01:55 +04:00
|
|
|
gfxFloat SynthesizeSpaceWidth(PRUint32 aCh);
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
// Font metrics
|
2005-10-08 09:09:42 +04:00
|
|
|
struct Metrics {
|
|
|
|
gfxFloat xHeight;
|
|
|
|
gfxFloat superscriptOffset;
|
|
|
|
gfxFloat subscriptOffset;
|
|
|
|
gfxFloat strikeoutSize;
|
|
|
|
gfxFloat strikeoutOffset;
|
|
|
|
gfxFloat underlineSize;
|
|
|
|
gfxFloat underlineOffset;
|
|
|
|
|
|
|
|
gfxFloat internalLeading;
|
|
|
|
gfxFloat externalLeading;
|
|
|
|
|
|
|
|
gfxFloat emHeight;
|
|
|
|
gfxFloat emAscent;
|
|
|
|
gfxFloat emDescent;
|
|
|
|
gfxFloat maxHeight;
|
|
|
|
gfxFloat maxAscent;
|
|
|
|
gfxFloat maxDescent;
|
|
|
|
gfxFloat maxAdvance;
|
|
|
|
|
|
|
|
gfxFloat aveCharWidth;
|
|
|
|
gfxFloat spaceWidth;
|
2008-07-16 01:31:36 +04:00
|
|
|
gfxFloat zeroOrAveCharWidth; // width of '0', or if there is
|
|
|
|
// no '0' glyph in this font,
|
|
|
|
// equal to .aveCharWidth
|
2005-10-08 09:09:42 +04:00
|
|
|
};
|
2005-11-08 23:06:16 +03:00
|
|
|
virtual const gfxFont::Metrics& GetMetrics() = 0;
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
/**
|
|
|
|
* We let layout specify spacing on either side of any
|
|
|
|
* character. We need to specify both before and after
|
|
|
|
* spacing so that substring measurement can do the right things.
|
2007-03-20 06:26:19 +03:00
|
|
|
* These values are in appunits. They're always an integral number of
|
|
|
|
* appunits, but we specify them in floats in case very large spacing
|
|
|
|
* values are required.
|
2007-03-05 00:05:10 +03:00
|
|
|
*/
|
|
|
|
struct Spacing {
|
|
|
|
gfxFloat mBefore;
|
|
|
|
gfxFloat mAfter;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Metrics for a particular string
|
|
|
|
*/
|
2008-08-12 13:34:52 +04:00
|
|
|
struct THEBES_API RunMetrics {
|
2007-03-05 00:05:10 +03:00
|
|
|
RunMetrics() {
|
|
|
|
mAdvanceWidth = mAscent = mDescent = 0.0;
|
|
|
|
mBoundingBox = gfxRect(0,0,0,0);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
void CombineWith(const RunMetrics& aOther, bool aOtherIsOnLeft);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
|
|
|
// can be negative (partly due to negative spacing).
|
|
|
|
// Advance widths should be additive: the advance width of the
|
|
|
|
// (offset1, length1) plus the advance width of (offset1 + length1,
|
|
|
|
// length2) should be the advance width of (offset1, length1 + length2)
|
|
|
|
gfxFloat mAdvanceWidth;
|
|
|
|
|
|
|
|
// For zero-width substrings, these must be zero!
|
|
|
|
gfxFloat mAscent; // always non-negative
|
|
|
|
gfxFloat mDescent; // always non-negative
|
|
|
|
|
|
|
|
// Bounding box that is guaranteed to include everything drawn.
|
2009-02-24 11:32:58 +03:00
|
|
|
// If a tight boundingBox was requested when these metrics were
|
2007-03-05 00:05:10 +03:00
|
|
|
// generated, this will tightly wrap the glyphs, otherwise it is
|
|
|
|
// "loose" and may be larger than the true bounding box.
|
|
|
|
// Coordinates are relative to the baseline left origin, so typically
|
|
|
|
// mBoundingBox.y == -mAscent
|
|
|
|
gfxRect mBoundingBox;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Draw a series of glyphs to aContext. The direction of aTextRun must
|
|
|
|
* be honoured.
|
|
|
|
* @param aStart the first character to draw
|
|
|
|
* @param aEnd draw characters up to here
|
|
|
|
* @param aBaselineOrigin the baseline origin; the left end of the baseline
|
|
|
|
* for LTR textruns, the right end of the baseline for RTL textruns. On return,
|
2007-03-20 06:26:19 +03:00
|
|
|
* this should be updated to the other end of the baseline. In application
|
|
|
|
* units, really!
|
2007-03-05 00:05:10 +03:00
|
|
|
* @param aSpacing spacing to insert before and after characters (for RTL
|
|
|
|
* glyphs, before-spacing is inserted to the right of characters). There
|
|
|
|
* are aEnd - aStart elements in this array, unless it's null to indicate
|
|
|
|
* that there is no spacing.
|
|
|
|
* @param aDrawToPath when true, add the glyph outlines to the current path
|
|
|
|
* instead of drawing the glyphs
|
|
|
|
*
|
|
|
|
* Callers guarantee:
|
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
|
|
|
* -- all glyphs use this font
|
|
|
|
*
|
|
|
|
* The default implementation builds a cairo glyph array and
|
|
|
|
* calls cairo_show_glyphs or cairo_glyph_path.
|
|
|
|
*/
|
|
|
|
virtual void Draw(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aEnd,
|
2011-09-29 10:19:26 +04:00
|
|
|
gfxContext *aContext, bool aDrawToPath, gfxPoint *aBaselineOrigin,
|
2007-03-05 00:05:10 +03:00
|
|
|
Spacing *aSpacing);
|
|
|
|
/**
|
|
|
|
* Measure a run of characters. See gfxTextRun::Metrics.
|
|
|
|
* @param aTight if false, then return the union of the glyph extents
|
|
|
|
* with the font-box for the characters (the rectangle with x=0,width=
|
|
|
|
* the advance width for the character run,y=-(font ascent), and height=
|
|
|
|
* font ascent + font descent). Otherwise, we must return as tight as possible
|
|
|
|
* an approximation to the area actually painted by glyphs.
|
2007-12-21 10:09:50 +03:00
|
|
|
* @param aContextForTightBoundingBox when aTight is true, this must
|
|
|
|
* be non-null.
|
2007-03-05 00:05:10 +03:00
|
|
|
* @param aSpacing spacing to insert before and after glyphs. The bounding box
|
|
|
|
* need not include the spacing itself, but the spacing affects the glyph
|
|
|
|
* positions. null if there is no spacing.
|
|
|
|
*
|
|
|
|
* Callers guarantee:
|
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
|
|
|
* -- all glyphs use this font
|
|
|
|
*
|
|
|
|
* The default implementation just uses font metrics and aTextRun's
|
|
|
|
* advances, and assumes no characters fall outside the font box. In
|
|
|
|
* general this is insufficient, because that assumption is not always true.
|
|
|
|
*/
|
|
|
|
virtual RunMetrics Measure(gfxTextRun *aTextRun,
|
|
|
|
PRUint32 aStart, PRUint32 aEnd,
|
2009-02-24 11:32:58 +03:00
|
|
|
BoundingBoxType aBoundingBoxType,
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxContext *aContextForTightBoundingBox,
|
2007-03-05 00:05:10 +03:00
|
|
|
Spacing *aSpacing);
|
|
|
|
/**
|
|
|
|
* Line breaks have been changed at the beginning and/or end of a substring
|
|
|
|
* of the text. Reshaping may be required; glyph updating is permitted.
|
|
|
|
* @return true if anything was changed, false otherwise
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NotifyLineBreaksChanged(gfxTextRun *aTextRun,
|
2007-03-05 00:05:10 +03:00
|
|
|
PRUint32 aStart, PRUint32 aLength)
|
2011-10-17 18:59:28 +04:00
|
|
|
{ return false; }
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
// Expiration tracking
|
|
|
|
nsExpirationState *GetExpirationState() { return &mExpirationState; }
|
|
|
|
|
2007-05-09 02:46:14 +04:00
|
|
|
// Get the glyphID of a space
|
|
|
|
virtual PRUint32 GetSpaceGlyph() = 0;
|
|
|
|
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxGlyphExtents *GetOrCreateGlyphExtents(PRUint32 aAppUnitsPerDevUnit);
|
|
|
|
|
|
|
|
// You need to call SetupCairoFont on the aCR just before calling this
|
|
|
|
virtual void SetupGlyphExtents(gfxContext *aContext, PRUint32 aGlyphID,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aNeedTight, gfxGlyphExtents *aExtents);
|
2007-09-22 17:28:16 +04:00
|
|
|
|
|
|
|
// This is called by the default Draw() implementation above.
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SetupCairoFont(gfxContext *aContext) = 0;
|
2007-09-24 06:19:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsSyntheticBold() { return mApplySyntheticBold; }
|
2011-09-03 00:18:25 +04:00
|
|
|
|
|
|
|
// Amount by which synthetic bold "fattens" the glyphs: 1/16 of the em-size
|
|
|
|
gfxFloat GetSyntheticBoldOffset() {
|
|
|
|
return GetAdjustedSize() * (1.0 / 16.0);
|
|
|
|
}
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2008-08-06 08:34:06 +04:00
|
|
|
gfxFontEntry *GetFontEntry() { return mFontEntry.get(); }
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasCharacter(PRUint32 ch) {
|
2008-08-06 08:34:06 +04:00
|
|
|
if (!mIsValid)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-08-06 08:34:06 +04:00
|
|
|
return mFontEntry->HasCharacter(ch);
|
|
|
|
}
|
|
|
|
|
2010-06-01 17:42:37 +04:00
|
|
|
PRUint16 GetUVSGlyph(PRUint32 aCh, PRUint32 aVS) {
|
|
|
|
if (!mIsValid) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mFontEntry->GetUVSGlyph(aCh, aVS);
|
|
|
|
}
|
|
|
|
|
2011-01-07 15:38:28 +03:00
|
|
|
// call the (virtual) InitTextRun method to do glyph generation/shaping,
|
|
|
|
// limiting the length of text passed by processing the run in multiple
|
|
|
|
// segments if necessary
|
2011-09-29 10:19:26 +04:00
|
|
|
bool SplitAndInitTextRun(gfxContext *aContext,
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const PRUnichar *aString,
|
|
|
|
PRUint32 aRunStart,
|
|
|
|
PRUint32 aRunLength,
|
2011-01-07 15:38:28 +03:00
|
|
|
PRInt32 aRunScript);
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2007-09-24 06:19:14 +04:00
|
|
|
protected:
|
2008-08-06 08:34:06 +04:00
|
|
|
nsRefPtr<gfxFontEntry> mFontEntry;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mIsValid;
|
2011-09-03 00:18:25 +04:00
|
|
|
|
|
|
|
// use synthetic bolding for environments where this is not supported
|
|
|
|
// by the platform
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mApplySyntheticBold;
|
2011-09-03 00:18:25 +04:00
|
|
|
|
2007-09-24 06:19:14 +04:00
|
|
|
nsExpirationState mExpirationState;
|
|
|
|
gfxFontStyle mStyle;
|
|
|
|
nsAutoTArray<gfxGlyphExtents*,1> mGlyphExtentsArray;
|
2008-02-16 00:31:38 +03:00
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxFloat mAdjustedSize;
|
|
|
|
|
|
|
|
float mFUnitsConvFactor; // conversion factor from font units to dev units
|
|
|
|
|
2010-03-15 12:34:25 +03:00
|
|
|
// the AA setting requested for this font - may affect glyph bounds
|
|
|
|
AntialiasOption mAntialiasOption;
|
|
|
|
|
2010-05-12 16:17:55 +04:00
|
|
|
// a copy of the font without antialiasing, if needed for separate
|
|
|
|
// measurement by mathml code
|
|
|
|
nsAutoPtr<gfxFont> mNonAAFont;
|
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
// we may switch between these shapers on the fly, based on the script
|
|
|
|
// of the text run being shaped
|
|
|
|
nsAutoPtr<gfxFontShaper> mPlatformShaper;
|
|
|
|
nsAutoPtr<gfxFontShaper> mHarfBuzzShaper;
|
|
|
|
|
|
|
|
// Create a default platform text shaper for this font.
|
|
|
|
// (TODO: This should become pure virtual once all font backends have
|
|
|
|
// been updated.)
|
|
|
|
virtual void CreatePlatformShaper() { }
|
2010-03-10 15:46:41 +03:00
|
|
|
|
2010-07-11 23:33:56 +04:00
|
|
|
// Helper for subclasses that want to initialize standard metrics from the
|
|
|
|
// tables of sfnt (TrueType/OpenType) fonts.
|
|
|
|
// This will use mFUnitsConvFactor if it is already set, else compute it
|
|
|
|
// from mAdjustedSize and the unitsPerEm in the font's 'head' table.
|
|
|
|
// Returns TRUE and sets mIsValid=TRUE if successful;
|
|
|
|
// Returns TRUE but leaves mIsValid=FALSE if the font seems to be broken.
|
|
|
|
// Returns FALSE if the font does not appear to be an sfnt at all,
|
|
|
|
// and should be handled (if possible) using other APIs.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool InitMetricsFromSfntTables(Metrics& aMetrics);
|
2010-07-11 23:33:56 +04:00
|
|
|
|
|
|
|
// Helper to calculate various derived metrics from the results of
|
|
|
|
// InitMetricsFromSfntTables or equivalent platform code
|
|
|
|
void CalculateDerivedMetrics(Metrics& aMetrics);
|
|
|
|
|
2008-02-16 00:31:38 +03:00
|
|
|
// some fonts have bad metrics, this method sanitize them.
|
2008-03-13 05:36:58 +03:00
|
|
|
// if this font has bad underline offset, aIsBadUnderlineFont should be true.
|
2011-09-29 10:19:26 +04:00
|
|
|
void SanitizeMetrics(gfxFont::Metrics *aMetrics, bool aIsBadUnderlineFont);
|
2011-01-07 15:38:28 +03:00
|
|
|
|
|
|
|
// Default simply calls m[Platform|HarfBuzz]Shaper->InitTextRun().
|
|
|
|
// Override if the font class wants to give special handling
|
|
|
|
// to shaper failure.
|
2011-10-17 18:59:28 +04:00
|
|
|
// Returns false if shaping failed (though currently we
|
2011-01-07 15:38:28 +03:00
|
|
|
// don't have any good way to handle that situation).
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool InitTextRun(gfxContext *aContext,
|
2011-01-07 15:38:28 +03:00
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const PRUnichar *aString,
|
|
|
|
PRUint32 aRunStart,
|
|
|
|
PRUint32 aRunLength,
|
|
|
|
PRInt32 aRunScript,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aPreferPlatformShaping = false);
|
2005-10-08 09:09:42 +04:00
|
|
|
};
|
|
|
|
|
2010-07-11 23:33:56 +04:00
|
|
|
// proportion of ascent used for x-height, if unable to read value from font
|
|
|
|
#define DEFAULT_XHEIGHT_FACTOR 0.56f
|
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
class THEBES_API gfxTextRunFactory {
|
2010-04-01 22:05:40 +04:00
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxTextRunFactory)
|
2005-11-29 23:12:29 +03:00
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
public:
|
2007-02-09 04:42:29 +03:00
|
|
|
// Flags in the mask 0xFFFF0000 are reserved for textrun clients
|
|
|
|
// Flags in the mask 0x0000F000 are reserved for per-platform fonts
|
|
|
|
// Flags in the mask 0x00000FFF are set by the textrun creator.
|
2007-01-23 11:45:52 +03:00
|
|
|
enum {
|
2007-07-04 07:39:01 +04:00
|
|
|
CACHE_TEXT_FLAGS = 0xF0000000,
|
|
|
|
USER_TEXT_FLAGS = 0x0FFF0000,
|
2007-06-13 00:56:04 +04:00
|
|
|
PLATFORM_TEXT_FLAGS = 0x0000F000,
|
|
|
|
TEXTRUN_TEXT_FLAGS = 0x00000FFF,
|
2007-07-04 07:39:01 +04:00
|
|
|
SETTABLE_FLAGS = CACHE_TEXT_FLAGS | USER_TEXT_FLAGS,
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
/**
|
|
|
|
* When set, the text string pointer used to create the text run
|
|
|
|
* is guaranteed to be available during the lifetime of the text run.
|
|
|
|
*/
|
|
|
|
TEXT_IS_PERSISTENT = 0x0001,
|
|
|
|
/**
|
|
|
|
* When set, the text is known to be all-ASCII (< 128).
|
|
|
|
*/
|
|
|
|
TEXT_IS_ASCII = 0x0002,
|
|
|
|
/**
|
|
|
|
* When set, the text is RTL.
|
|
|
|
*/
|
|
|
|
TEXT_IS_RTL = 0x0004,
|
|
|
|
/**
|
|
|
|
* When set, spacing is enabled and the textrun needs to call GetSpacing
|
|
|
|
* on the spacing provider.
|
|
|
|
*/
|
|
|
|
TEXT_ENABLE_SPACING = 0x0008,
|
|
|
|
/**
|
|
|
|
* When set, GetHyphenationBreaks may return true for some character
|
|
|
|
* positions, otherwise it will always return false for all characters.
|
|
|
|
*/
|
2009-07-30 06:59:41 +04:00
|
|
|
TEXT_ENABLE_HYPHEN_BREAKS = 0x0010,
|
2007-01-23 11:45:52 +03:00
|
|
|
/**
|
2007-07-13 12:09:25 +04:00
|
|
|
* When set, the text has no characters above 255 and it is stored
|
|
|
|
* in the textrun in 8-bit format.
|
2007-01-23 11:45:52 +03:00
|
|
|
*/
|
2009-07-30 06:59:41 +04:00
|
|
|
TEXT_IS_8BIT = 0x0020,
|
2007-03-05 00:05:10 +03:00
|
|
|
/**
|
|
|
|
* When set, the RunMetrics::mBoundingBox field will be initialized
|
|
|
|
* properly based on glyph extents, in particular, glyph extents that
|
|
|
|
* overflow the standard font-box (the box defined by the ascent, descent
|
|
|
|
* and advance width of the glyph). When not set, it may just be the
|
|
|
|
* standard font-box even if glyphs overflow.
|
|
|
|
*/
|
2009-07-30 06:59:41 +04:00
|
|
|
TEXT_NEED_BOUNDING_BOX = 0x0040,
|
2007-05-31 09:01:56 +04:00
|
|
|
/**
|
2007-07-13 12:09:25 +04:00
|
|
|
* When set, optional ligatures are disabled. Ligatures that are
|
|
|
|
* required for legible text should still be enabled.
|
2007-05-31 09:01:56 +04:00
|
|
|
*/
|
2009-07-30 06:59:41 +04:00
|
|
|
TEXT_DISABLE_OPTIONAL_LIGATURES = 0x0080,
|
2007-07-26 13:47:43 +04:00
|
|
|
/**
|
|
|
|
* When set, the textrun should favour speed of construction over
|
|
|
|
* quality. This may involve disabling ligatures and/or kerning or
|
|
|
|
* other effects.
|
|
|
|
*/
|
2011-10-14 11:06:35 +04:00
|
|
|
TEXT_OPTIMIZE_SPEED = 0x0100,
|
|
|
|
/**
|
|
|
|
* For internal use by the memory reporter when accounting for
|
|
|
|
* storage used by textruns.
|
|
|
|
* Because the reporter may visit each textrun multiple times while
|
|
|
|
* walking the frame trees and textrun cache, it needs to mark
|
|
|
|
* textruns that have been seen so as to avoid multiple-accounting.
|
|
|
|
*/
|
|
|
|
TEXT_RUN_SIZE_ACCOUNTED = 0x0200
|
2007-01-23 11:45:52 +03:00
|
|
|
};
|
2006-10-14 09:37:40 +04:00
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
/**
|
|
|
|
* This record contains all the parameters needed to initialize a textrun.
|
|
|
|
*/
|
|
|
|
struct Parameters {
|
|
|
|
// A reference context suggesting where the textrun will be rendered
|
2007-01-30 22:49:16 +03:00
|
|
|
gfxContext *mContext;
|
2007-01-23 11:45:52 +03:00
|
|
|
// Pointer to arbitrary user data (which should outlive the textrun)
|
2007-01-30 22:49:16 +03:00
|
|
|
void *mUserData;
|
2007-01-23 11:45:52 +03:00
|
|
|
// A description of which characters have been stripped from the original
|
2007-02-09 04:42:29 +03:00
|
|
|
// DOM string to produce the characters in the textrun. May be null
|
|
|
|
// if that information is not relevant.
|
2007-01-30 22:49:16 +03:00
|
|
|
gfxSkipChars *mSkipChars;
|
2007-02-09 04:42:29 +03:00
|
|
|
// A list of where linebreaks are currently placed in the textrun. May
|
|
|
|
// be null if mInitialBreakCount is zero.
|
2007-01-30 22:49:16 +03:00
|
|
|
PRUint32 *mInitialBreaks;
|
2007-01-23 11:45:52 +03:00
|
|
|
PRUint32 mInitialBreakCount;
|
|
|
|
// The ratio to use to convert device pixels to application layout units
|
2007-02-07 10:46:44 +03:00
|
|
|
PRUint32 mAppUnitsPerDevUnit;
|
2007-01-23 11:45:52 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~gfxTextRunFactory() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxTextRun is an abstraction for drawing and measuring substrings of a run
|
2007-03-05 00:05:10 +03:00
|
|
|
* of text. It stores runs of positioned glyph data, each run having a single
|
|
|
|
* gfxFont. The glyphs are associated with a string of source text, and the
|
|
|
|
* gfxTextRun APIs take parameters that are offsets into that source text.
|
2007-01-23 11:45:52 +03:00
|
|
|
*
|
|
|
|
* gfxTextRuns are not refcounted. They should be deleted when no longer required.
|
|
|
|
*
|
|
|
|
* gfxTextRuns are mostly immutable. The only things that can change are
|
|
|
|
* inter-cluster spacing and line break placement. Spacing is always obtained
|
2007-02-09 04:42:29 +03:00
|
|
|
* lazily by methods that need it, it is not cached. Line breaks are stored
|
|
|
|
* persistently (insofar as they affect the shaping of glyphs; gfxTextRun does
|
|
|
|
* not actually do anything to explicitly account for line breaks). Initially
|
|
|
|
* there are no line breaks. The textrun can record line breaks before or after
|
|
|
|
* any given cluster. (Line breaks specified inside clusters are ignored.)
|
2007-01-23 11:45:52 +03:00
|
|
|
*
|
|
|
|
* It is important that zero-length substrings are handled correctly. This will
|
|
|
|
* be on the test!
|
2007-03-05 00:05:10 +03:00
|
|
|
*
|
2007-03-20 06:26:19 +03:00
|
|
|
* gfxTextRun stores a list of zero or more glyphs for each character. For each
|
|
|
|
* glyph we store the glyph ID, the advance, and possibly an xoffset and yoffset.
|
|
|
|
* The idea is that a string is rendered by a loop that draws each glyph
|
|
|
|
* at its designated offset from the current point, then advances the current
|
|
|
|
* point by the glyph's advance in the direction of the textrun (LTR or RTL).
|
|
|
|
* Each glyph advance is always rounded to the nearest appunit; this ensures
|
|
|
|
* consistent results when dividing the text in a textrun into multiple text
|
|
|
|
* frames (frame boundaries are always aligned to appunits). We optimize
|
|
|
|
* for the case where a character has a single glyph and zero xoffset and yoffset,
|
|
|
|
* and the glyph ID and advance are in a reasonable range so we can pack all
|
|
|
|
* necessary data into 32 bits.
|
2007-08-10 05:35:32 +04:00
|
|
|
*
|
|
|
|
* gfxTextRun methods that measure or draw substrings will associate all the
|
|
|
|
* glyphs in a cluster with the first character of the cluster; if that character
|
|
|
|
* is in the substring, the glyphs will be measured or drawn, otherwise they
|
|
|
|
* won't.
|
2007-01-23 11:45:52 +03:00
|
|
|
*/
|
|
|
|
class THEBES_API gfxTextRun {
|
2007-01-17 01:25:20 +03:00
|
|
|
public:
|
2007-05-09 02:46:14 +04:00
|
|
|
virtual ~gfxTextRun();
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
typedef gfxFont::RunMetrics Metrics;
|
|
|
|
|
|
|
|
// Public textrun API for general use
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsClusterStart(PRUint32 aPos) {
|
2007-03-05 00:05:10 +03:00
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
|
|
|
return mCharacterGlyphs[aPos].IsClusterStart();
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsLigatureGroupStart(PRUint32 aPos) {
|
2007-03-05 00:05:10 +03:00
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
2007-11-09 09:27:23 +03:00
|
|
|
return mCharacterGlyphs[aPos].IsLigatureGroupStart();
|
2007-03-05 00:05:10 +03:00
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CanBreakLineBefore(PRUint32 aPos) {
|
2007-03-05 00:05:10 +03:00
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
2011-05-04 15:29:56 +04:00
|
|
|
return mCharacterGlyphs[aPos].CanBreakBefore() ==
|
|
|
|
CompressedGlyph::FLAG_BREAK_TYPE_NORMAL;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool CanHyphenateBefore(PRUint32 aPos) {
|
2011-05-04 15:29:56 +04:00
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
|
|
|
return mCharacterGlyphs[aPos].CanBreakBefore() ==
|
|
|
|
CompressedGlyph::FLAG_BREAK_TYPE_HYPHEN;
|
2009-03-30 04:31:51 +04:00
|
|
|
}
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
PRUint32 GetLength() { return mCharacterCount; }
|
2007-01-16 23:51:52 +03:00
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
// All PRUint32 aStart, PRUint32 aLength ranges below are restricted to
|
|
|
|
// grapheme cluster boundaries! All offsets are in terms of the string
|
|
|
|
// passed into MakeTextRun.
|
|
|
|
|
|
|
|
// All coordinates are in layout/app units
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the potential linebreaks for a substring of the textrun. These are
|
|
|
|
* the "allow break before" points. Initially, there are no potential
|
|
|
|
* linebreaks.
|
|
|
|
*
|
2007-03-23 02:07:18 +03:00
|
|
|
* This can change glyphs and/or geometry! Some textruns' shapes
|
|
|
|
* depend on potential line breaks (e.g., title-case-converting textruns).
|
|
|
|
* This function is virtual so that those textruns can reshape themselves.
|
|
|
|
*
|
2007-01-23 11:45:52 +03:00
|
|
|
* @return true if this changed the linebreaks, false if the new line
|
|
|
|
* breaks are the same as the old
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
2011-05-04 15:29:56 +04:00
|
|
|
PRUint8 *aBreakBefore,
|
2007-06-27 08:22:21 +04:00
|
|
|
gfxContext *aRefContext);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
|
|
|
/**
|
2007-03-23 02:07:18 +03:00
|
|
|
* Layout provides PropertyProvider objects. These allow detection of
|
|
|
|
* potential line break points and computation of spacing. We pass the data
|
|
|
|
* this way to allow lazy data acquisition; for example BreakAndMeasureText
|
|
|
|
* will want to only ask for properties of text it's actually looking at.
|
|
|
|
*
|
|
|
|
* NOTE that requested spacing may not actually be applied, if the textrun
|
|
|
|
* is unable to apply it in some context. Exception: spacing around a
|
|
|
|
* whitespace character MUST always be applied.
|
2007-03-23 02:01:14 +03:00
|
|
|
*/
|
2007-03-23 02:07:18 +03:00
|
|
|
class PropertyProvider {
|
2007-03-23 02:01:14 +03:00
|
|
|
public:
|
2007-01-23 11:45:52 +03:00
|
|
|
// Detect hyphenation break opportunities in the given range; breaks
|
|
|
|
// not at cluster boundaries will be ignored.
|
|
|
|
virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aBreakBefore) = 0;
|
2007-01-23 11:45:52 +03:00
|
|
|
|
2011-05-04 15:29:56 +04:00
|
|
|
// Returns the provider's hyphenation setting, so callers can decide
|
|
|
|
// whether it is necessary to call GetHyphenationBreaks.
|
|
|
|
// Result is an NS_STYLE_HYPHENS_* value.
|
|
|
|
virtual PRInt8 GetHyphensOption() = 0;
|
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
// Returns the extra width that will be consumed by a hyphen. This should
|
|
|
|
// be constant for a given textrun.
|
|
|
|
virtual gfxFloat GetHyphenWidth() = 0;
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
typedef gfxFont::Spacing Spacing;
|
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
/**
|
|
|
|
* Get the spacing around the indicated characters. Spacing must be zero
|
|
|
|
* inside clusters. In other words, if character i is not
|
|
|
|
* CLUSTER_START, then character i-1 must have zero after-spacing and
|
|
|
|
* character i must have zero before-spacing.
|
|
|
|
*/
|
|
|
|
virtual void GetSpacing(PRUint32 aStart, PRUint32 aLength,
|
2007-01-30 22:49:16 +03:00
|
|
|
Spacing *aSpacing) = 0;
|
2007-01-23 11:45:52 +03:00
|
|
|
};
|
|
|
|
|
2011-03-22 17:59:25 +03:00
|
|
|
class ClusterIterator {
|
|
|
|
public:
|
|
|
|
ClusterIterator(gfxTextRun *aTextRun);
|
|
|
|
|
|
|
|
void Reset();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NextCluster();
|
2011-03-22 17:59:25 +03:00
|
|
|
|
|
|
|
PRUint32 Position() const {
|
|
|
|
return mCurrentChar;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 ClusterLength() const;
|
|
|
|
|
|
|
|
gfxFloat ClusterAdvance(PropertyProvider *aProvider) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
gfxTextRun *mTextRun;
|
|
|
|
PRUint32 mCurrentChar;
|
|
|
|
};
|
|
|
|
|
2007-01-23 11:45:52 +03:00
|
|
|
/**
|
|
|
|
* Draws a substring. Uses only GetSpacing from aBreakProvider.
|
|
|
|
* The provided point is the baseline origin on the left of the string
|
|
|
|
* for LTR, on the right of the string for RTL.
|
|
|
|
* @param aAdvanceWidth if non-null, the advance width of the substring
|
|
|
|
* is returned here.
|
|
|
|
*
|
|
|
|
* Drawing should respect advance widths in the sense that for LTR runs,
|
|
|
|
* Draw(ctx, pt, offset1, length1, dirty, &provider, &advance) followed by
|
|
|
|
* Draw(ctx, gfxPoint(pt.x + advance, pt.y), offset1 + length1, length2,
|
|
|
|
* dirty, &provider, nsnull) should have the same effect as
|
|
|
|
* Draw(ctx, pt, offset1, length1+length2, dirty, &provider, nsnull).
|
|
|
|
* For RTL runs the rule is:
|
|
|
|
* Draw(ctx, pt, offset1 + length1, length2, dirty, &provider, &advance) followed by
|
|
|
|
* Draw(ctx, gfxPoint(pt.x + advance, pt.y), offset1, length1,
|
|
|
|
* dirty, &provider, nsnull) should have the same effect as
|
|
|
|
* Draw(ctx, pt, offset1, length1+length2, dirty, &provider, nsnull).
|
|
|
|
*
|
|
|
|
* Glyphs should be drawn in logical content order, which can be significant
|
|
|
|
* if they overlap (perhaps due to negative spacing).
|
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
void Draw(gfxContext *aContext, gfxPoint aPt,
|
|
|
|
PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
gfxFloat *aAdvanceWidth);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Renders a substring to a path. Uses only GetSpacing from aBreakProvider.
|
|
|
|
* The provided point is the baseline origin on the left of the string
|
|
|
|
* for LTR, on the right of the string for RTL.
|
|
|
|
* @param aAdvanceWidth if non-null, the advance width of the substring
|
|
|
|
* is returned here.
|
|
|
|
*
|
|
|
|
* Drawing should respect advance widths in the way that Draw above does.
|
|
|
|
*
|
|
|
|
* Glyphs should be drawn in logical content order.
|
|
|
|
*
|
|
|
|
* UNLIKE Draw above, this cannot be used to render substrings that start or
|
|
|
|
* end inside a ligature.
|
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
void DrawToPath(gfxContext *aContext, gfxPoint aPt,
|
|
|
|
PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PropertyProvider *aBreakProvider,
|
|
|
|
gfxFloat *aAdvanceWidth);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the ReflowMetrics for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
2009-02-24 11:32:58 +03:00
|
|
|
* @param aBoundingBoxType which kind of bounding box (loose/tight)
|
2007-01-23 11:45:52 +03:00
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
Metrics MeasureText(PRUint32 aStart, PRUint32 aLength,
|
2009-02-24 11:32:58 +03:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxContext *aRefContextForTightBoundingBox,
|
2007-03-05 00:05:10 +03:00
|
|
|
PropertyProvider *aProvider);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes just the advance width for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
gfxFloat GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PropertyProvider *aProvider);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all stored line breaks for the given range (both before and after),
|
|
|
|
* and then set the line-break state before aStart to aBreakBefore and
|
|
|
|
* after the last cluster to aBreakAfter.
|
|
|
|
*
|
|
|
|
* We require that before and after line breaks be consistent. For clusters
|
|
|
|
* i and i+1, we require that if there is a break after cluster i, a break
|
|
|
|
* will be specified before cluster i+1. This may be temporarily violated
|
|
|
|
* (e.g. after reflowing line L and before reflowing line L+1); to handle
|
|
|
|
* these temporary violations, we say that there is a break betwen i and i+1
|
|
|
|
* if a break is specified after i OR a break is specified before i+1.
|
|
|
|
*
|
|
|
|
* This can change textrun geometry! The existence of a linebreak can affect
|
|
|
|
* the advance width of the cluster before the break (when kerning) or the
|
|
|
|
* geometry of one cluster before the break or any number of clusters
|
|
|
|
* after the break. (The one-cluster-before-the-break limit is somewhat
|
|
|
|
* arbitrary; if some scripts require breaking it, then we need to
|
|
|
|
* alter nsTextFrame::TrimTrailingWhitespace, perhaps drastically becase
|
|
|
|
* it could affect the layout of frames before it...)
|
|
|
|
*
|
2007-03-23 02:07:18 +03:00
|
|
|
* We return true if glyphs or geometry changed, false otherwise. This
|
|
|
|
* function is virtual so that gfxTextRun subclasses can reshape
|
|
|
|
* properly.
|
|
|
|
*
|
2007-01-23 11:45:52 +03:00
|
|
|
* @param aAdvanceWidthDelta if non-null, returns the change in advance
|
|
|
|
* width of the given range.
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool SetLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
bool aLineBreakBefore, bool aLineBreakAfter,
|
2007-06-27 08:22:21 +04:00
|
|
|
gfxFloat *aAdvanceWidthDelta,
|
|
|
|
gfxContext *aRefContext);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Finds the longest substring that will fit into the given width.
|
|
|
|
* Uses GetHyphenationBreaks and GetSpacing from aBreakProvider.
|
|
|
|
* Guarantees the following:
|
|
|
|
* -- 0 <= result <= aMaxLength
|
|
|
|
* -- result is the maximal value of N such that either
|
|
|
|
* N < aMaxLength && line break at N && GetAdvanceWidth(aStart, N) <= aWidth
|
|
|
|
* OR N < aMaxLength && hyphen break at N && GetAdvanceWidth(aStart, N) + GetHyphenWidth() <= aWidth
|
|
|
|
* OR N == aMaxLength && GetAdvanceWidth(aStart, N) <= aWidth
|
|
|
|
* where GetAdvanceWidth assumes the effect of
|
|
|
|
* SetLineBreaks(aStart, N, aLineBreakBefore, N < aMaxLength, aProvider)
|
|
|
|
* -- if no such N exists, then result is the smallest N such that
|
|
|
|
* N < aMaxLength && line break at N
|
|
|
|
* OR N < aMaxLength && hyphen break at N
|
|
|
|
* OR N == aMaxLength
|
|
|
|
*
|
|
|
|
* The call has the effect of
|
|
|
|
* SetLineBreaks(aStart, result, aLineBreakBefore, result < aMaxLength, aProvider)
|
|
|
|
* and the returned metrics and the invariants above reflect this.
|
|
|
|
*
|
|
|
|
* @param aMaxLength this can be PR_UINT32_MAX, in which case the length used
|
|
|
|
* is up to the end of the string
|
|
|
|
* @param aLineBreakBefore set to true if and only if there is an actual
|
|
|
|
* line break at the start of this string.
|
|
|
|
* @param aSuppressInitialBreak if true, then we assume there is no possible
|
|
|
|
* linebreak before aStart. If false, then we will check the internal
|
|
|
|
* line break opportunity state before deciding whether to return 0 as the
|
|
|
|
* character to break before.
|
2007-05-23 03:40:07 +04:00
|
|
|
* @param aTrimWhitespace if non-null, then we allow a trailing run of
|
|
|
|
* spaces to be trimmed; the width of the space(s) will not be included in
|
|
|
|
* the measured string width for comparison with the limit aWidth, and
|
|
|
|
* trimmed spaces will not be included in returned metrics. The width
|
|
|
|
* of the trimmed spaces will be returned in aTrimWhitespace.
|
|
|
|
* Trimmed spaces are still counted in the "characters fit" result.
|
2007-01-23 11:45:52 +03:00
|
|
|
* @param aMetrics if non-null, we fill this in for the returned substring.
|
|
|
|
* If a hyphenation break was used, the hyphen is NOT included in the returned metrics.
|
2009-02-24 11:32:58 +03:00
|
|
|
* @param aBoundingBoxType whether to make the bounding box in aMetrics tight
|
2007-09-24 06:19:14 +04:00
|
|
|
* @param aRefContextForTightBoundingBox a reference context to get the
|
2009-02-24 11:32:58 +03:00
|
|
|
* tight bounding box, if requested
|
2007-01-23 11:45:52 +03:00
|
|
|
* @param aUsedHyphenation if non-null, records if we selected a hyphenation break
|
|
|
|
* @param aLastBreak if non-null and result is aMaxLength, we set this to
|
|
|
|
* the maximal N such that
|
|
|
|
* N < aMaxLength && line break at N && GetAdvanceWidth(aStart, N) <= aWidth
|
|
|
|
* OR N < aMaxLength && hyphen break at N && GetAdvanceWidth(aStart, N) + GetHyphenWidth() <= aWidth
|
|
|
|
* or PR_UINT32_MAX if no such N exists, where GetAdvanceWidth assumes
|
|
|
|
* the effect of
|
|
|
|
* SetLineBreaks(aStart, N, aLineBreakBefore, N < aMaxLength, aProvider)
|
2008-07-24 11:16:18 +04:00
|
|
|
*
|
|
|
|
* @param aCanWordWrap true if we can break between any two grapheme
|
|
|
|
* clusters. This is set by word-wrap: break-word
|
|
|
|
*
|
|
|
|
* @param aBreakPriority in/out the priority of the break opportunity
|
|
|
|
* saved in the line. If we are prioritizing break opportunities, we will
|
|
|
|
* not set a break with a lower priority. @see gfxBreakPriority.
|
2007-01-23 11:45:52 +03:00
|
|
|
*
|
|
|
|
* Note that negative advance widths are possible especially if negative
|
|
|
|
* spacing is provided.
|
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
PRUint32 BreakAndMeasureText(PRUint32 aStart, PRUint32 aMaxLength,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aLineBreakBefore, gfxFloat aWidth,
|
2007-03-05 00:05:10 +03:00
|
|
|
PropertyProvider *aProvider,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aSuppressInitialBreak,
|
2007-05-23 03:40:07 +04:00
|
|
|
gfxFloat *aTrimWhitespace,
|
2009-02-24 11:32:58 +03:00
|
|
|
Metrics *aMetrics,
|
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxContext *aRefContextForTightBoundingBox,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *aUsedHyphenation,
|
2008-07-24 11:16:18 +04:00
|
|
|
PRUint32 *aLastBreak,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCanWordWrap,
|
2008-07-24 11:16:18 +04:00
|
|
|
gfxBreakPriority *aBreakPriority);
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the reference context.
|
|
|
|
* XXX this is a hack. New text frame does not call this. Use only
|
|
|
|
* temporarily for old text frame.
|
|
|
|
*/
|
2007-03-05 00:05:10 +03:00
|
|
|
void SetContext(gfxContext *aContext) {}
|
2007-01-23 11:45:52 +03:00
|
|
|
|
|
|
|
// Utility getters
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsRightToLeft() const { return (mFlags & gfxTextRunFactory::TEXT_IS_RTL) != 0; }
|
2007-01-23 11:45:52 +03:00
|
|
|
gfxFloat GetDirection() const { return (mFlags & gfxTextRunFactory::TEXT_IS_RTL) ? -1.0 : 1.0; }
|
2007-01-30 22:49:16 +03:00
|
|
|
void *GetUserData() const { return mUserData; }
|
2007-05-09 02:46:14 +04:00
|
|
|
void SetUserData(void *aUserData) { mUserData = aUserData; }
|
2007-01-23 11:45:52 +03:00
|
|
|
PRUint32 GetFlags() const { return mFlags; }
|
2007-06-13 00:56:04 +04:00
|
|
|
void SetFlagBits(PRUint32 aFlags) {
|
2007-07-04 07:39:01 +04:00
|
|
|
NS_ASSERTION(!(aFlags & ~gfxTextRunFactory::SETTABLE_FLAGS),
|
2007-06-13 00:56:04 +04:00
|
|
|
"Only user flags should be mutable");
|
|
|
|
mFlags |= aFlags;
|
|
|
|
}
|
|
|
|
void ClearFlagBits(PRUint32 aFlags) {
|
2007-07-04 07:39:01 +04:00
|
|
|
NS_ASSERTION(!(aFlags & ~gfxTextRunFactory::SETTABLE_FLAGS),
|
2007-06-13 00:56:04 +04:00
|
|
|
"Only user flags should be mutable");
|
|
|
|
mFlags &= ~aFlags;
|
|
|
|
}
|
2007-01-23 11:45:52 +03:00
|
|
|
const gfxSkipChars& GetSkipChars() const { return mSkipChars; }
|
2007-03-20 11:58:53 +03:00
|
|
|
PRUint32 GetAppUnitsPerDevUnit() const { return mAppUnitsPerDevUnit; }
|
2007-05-09 02:46:14 +04:00
|
|
|
gfxFontGroup *GetFontGroup() const { return mFontGroup; }
|
|
|
|
const PRUint8 *GetText8Bit() const
|
|
|
|
{ return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT) ? mText.mSingle : nsnull; }
|
|
|
|
const PRUnichar *GetTextUnicode() const
|
|
|
|
{ return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT) ? nsnull : mText.mDouble; }
|
2007-06-13 00:56:04 +04:00
|
|
|
const void *GetTextAt(PRUint32 aIndex) {
|
|
|
|
return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT)
|
2007-07-08 11:08:04 +04:00
|
|
|
? static_cast<const void *>(mText.mSingle + aIndex)
|
|
|
|
: static_cast<const void *>(mText.mDouble + aIndex);
|
2007-06-13 00:56:04 +04:00
|
|
|
}
|
2007-05-15 07:06:52 +04:00
|
|
|
const PRUnichar GetChar(PRUint32 i) const
|
|
|
|
{ return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT) ? mText.mSingle[i] : mText.mDouble[i]; }
|
2007-05-12 09:51:15 +04:00
|
|
|
PRUint32 GetHashCode() const { return mHashCode; }
|
|
|
|
void SetHashCode(PRUint32 aHash) { mHashCode = aHash; }
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-11-16 04:43:47 +03:00
|
|
|
// Call this, don't call "new gfxTextRun" directly. This does custom
|
|
|
|
// allocation and initialization
|
|
|
|
static gfxTextRun *Create(const gfxTextRunFactory::Parameters *aParams,
|
|
|
|
const void *aText, PRUint32 aLength, gfxFontGroup *aFontGroup, PRUint32 aFlags);
|
2007-05-09 02:46:14 +04:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
/**
|
|
|
|
* This class records the information associated with a character in the
|
|
|
|
* input string. It's optimized for the case where there is one glyph
|
|
|
|
* representing that character alone.
|
2007-11-09 09:27:23 +03:00
|
|
|
*
|
|
|
|
* A character can have zero or more associated glyphs. Each glyph
|
|
|
|
* has an advance width and an x and y offset.
|
|
|
|
* A character may be the start of a cluster.
|
|
|
|
* A character may be the start of a ligature group.
|
|
|
|
* A character can be "missing", indicating that the system is unable
|
|
|
|
* to render the character.
|
|
|
|
*
|
|
|
|
* All characters in a ligature group conceptually share all the glyphs
|
|
|
|
* associated with the characters in a group.
|
2007-03-05 00:05:10 +03:00
|
|
|
*/
|
|
|
|
class CompressedGlyph {
|
|
|
|
public:
|
|
|
|
CompressedGlyph() { mValue = 0; }
|
|
|
|
|
|
|
|
enum {
|
2007-11-09 09:27:23 +03:00
|
|
|
// Indicates that a cluster and ligature group starts at this
|
|
|
|
// character; this character has a single glyph with a reasonable
|
|
|
|
// advance and zero offsets. A "reasonable" advance
|
2011-05-04 15:29:56 +04:00
|
|
|
// is one that fits in the available bits (currently 13) (specified
|
2007-11-09 09:27:23 +03:00
|
|
|
// in appunits).
|
2007-03-05 00:05:10 +03:00
|
|
|
FLAG_IS_SIMPLE_GLYPH = 0x80000000U,
|
2011-05-04 15:29:56 +04:00
|
|
|
|
|
|
|
// Indicates whether a linebreak is allowed before this character;
|
|
|
|
// this is a two-bit field that holds a FLAG_BREAK_TYPE_xxx value
|
|
|
|
// indicating the kind of linebreak (if any) allowed here.
|
|
|
|
FLAGS_CAN_BREAK_BEFORE = 0x60000000U,
|
|
|
|
|
|
|
|
FLAGS_CAN_BREAK_SHIFT = 29,
|
|
|
|
FLAG_BREAK_TYPE_NONE = 0,
|
|
|
|
FLAG_BREAK_TYPE_NORMAL = 1,
|
|
|
|
FLAG_BREAK_TYPE_HYPHEN = 2,
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2007-03-20 06:26:19 +03:00
|
|
|
// The advance is stored in appunits
|
2011-05-04 15:29:56 +04:00
|
|
|
ADVANCE_MASK = 0x1FFF0000U,
|
2007-03-05 00:05:10 +03:00
|
|
|
ADVANCE_SHIFT = 16,
|
|
|
|
|
|
|
|
GLYPH_MASK = 0x0000FFFFU,
|
|
|
|
|
2007-11-09 09:27:23 +03:00
|
|
|
// Non-simple glyphs may or may not have glyph data in the
|
|
|
|
// corresponding mDetailedGlyphs entry. They have the following
|
|
|
|
// flag bits:
|
|
|
|
|
|
|
|
// When NOT set, indicates that this character corresponds to a
|
|
|
|
// missing glyph and should be skipped (or possibly, render the character
|
|
|
|
// Unicode value in some special way). If there are glyphs,
|
|
|
|
// the mGlyphID is actually the UTF16 character code. The bit is
|
|
|
|
// inverted so we can memset the array to zero to indicate all missing.
|
|
|
|
FLAG_NOT_MISSING = 0x01,
|
|
|
|
FLAG_NOT_CLUSTER_START = 0x02,
|
|
|
|
FLAG_NOT_LIGATURE_GROUP_START = 0x04,
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2007-11-09 09:27:23 +03:00
|
|
|
GLYPH_COUNT_MASK = 0x00FFFF00U,
|
|
|
|
GLYPH_COUNT_SHIFT = 8
|
2007-03-05 00:05:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// "Simple glyphs" have a simple glyph ID, simple advance and their
|
|
|
|
// x and y offsets are zero. Also the glyph extents do not overflow
|
|
|
|
// the font-box defined by the font ascent, descent and glyph advance width.
|
|
|
|
// These case is optimized to avoid storing DetailedGlyphs.
|
|
|
|
|
|
|
|
// Returns true if the glyph ID aGlyph fits into the compressed representation
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSimpleGlyphID(PRUint32 aGlyph) {
|
2007-03-05 00:05:10 +03:00
|
|
|
return (aGlyph & GLYPH_MASK) == aGlyph;
|
2007-01-23 11:45:52 +03:00
|
|
|
}
|
2007-03-05 00:05:10 +03:00
|
|
|
// Returns true if the advance aAdvance fits into the compressed representation.
|
2007-05-12 09:52:43 +04:00
|
|
|
// aAdvance is in appunits.
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsSimpleAdvance(PRUint32 aAdvance) {
|
2007-03-05 00:05:10 +03:00
|
|
|
return (aAdvance & (ADVANCE_MASK >> ADVANCE_SHIFT)) == aAdvance;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsSimpleGlyph() const { return (mValue & FLAG_IS_SIMPLE_GLYPH) != 0; }
|
2007-03-05 00:05:10 +03:00
|
|
|
PRUint32 GetSimpleAdvance() const { return (mValue & ADVANCE_MASK) >> ADVANCE_SHIFT; }
|
|
|
|
PRUint32 GetSimpleGlyph() const { return mValue & GLYPH_MASK; }
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsMissing() const { return (mValue & (FLAG_NOT_MISSING|FLAG_IS_SIMPLE_GLYPH)) == 0; }
|
|
|
|
bool IsClusterStart() const {
|
2007-11-09 09:27:23 +03:00
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) || !(mValue & FLAG_NOT_CLUSTER_START);
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsLigatureGroupStart() const {
|
2007-11-09 09:27:23 +03:00
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) || !(mValue & FLAG_NOT_LIGATURE_GROUP_START);
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool IsLigatureContinuation() const {
|
2009-03-30 04:31:51 +04:00
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) == 0 &&
|
|
|
|
(mValue & (FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING)) ==
|
|
|
|
(FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING);
|
|
|
|
}
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2011-05-04 15:29:56 +04:00
|
|
|
PRUint8 CanBreakBefore() const {
|
|
|
|
return (mValue & FLAGS_CAN_BREAK_BEFORE) >> FLAGS_CAN_BREAK_SHIFT;
|
|
|
|
}
|
|
|
|
// Returns FLAGS_CAN_BREAK_BEFORE if the setting changed, 0 otherwise
|
|
|
|
PRUint32 SetCanBreakBefore(PRUint8 aCanBreakBefore) {
|
|
|
|
NS_ASSERTION(aCanBreakBefore <= 2,
|
2007-09-24 06:19:14 +04:00
|
|
|
"Bogus break-before value!");
|
2011-05-04 15:29:56 +04:00
|
|
|
PRUint32 breakMask = (PRUint32(aCanBreakBefore) << FLAGS_CAN_BREAK_SHIFT);
|
|
|
|
PRUint32 toggle = breakMask ^ (mValue & FLAGS_CAN_BREAK_BEFORE);
|
2007-03-05 00:05:10 +03:00
|
|
|
mValue ^= toggle;
|
|
|
|
return toggle;
|
|
|
|
}
|
|
|
|
|
2007-05-12 09:52:43 +04:00
|
|
|
CompressedGlyph& SetSimpleGlyph(PRUint32 aAdvanceAppUnits, PRUint32 aGlyph) {
|
|
|
|
NS_ASSERTION(IsSimpleAdvance(aAdvanceAppUnits), "Advance overflow");
|
2007-03-05 00:05:10 +03:00
|
|
|
NS_ASSERTION(IsSimpleGlyphID(aGlyph), "Glyph overflow");
|
2011-05-04 15:29:56 +04:00
|
|
|
mValue = (mValue & FLAGS_CAN_BREAK_BEFORE) |
|
|
|
|
FLAG_IS_SIMPLE_GLYPH |
|
2007-05-12 09:52:43 +04:00
|
|
|
(aAdvanceAppUnits << ADVANCE_SHIFT) | aGlyph;
|
2007-03-05 00:05:10 +03:00
|
|
|
return *this;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
CompressedGlyph& SetComplex(bool aClusterStart, bool aLigatureStart,
|
2007-11-09 09:27:23 +03:00
|
|
|
PRUint32 aGlyphCount) {
|
2011-05-04 15:29:56 +04:00
|
|
|
mValue = (mValue & FLAGS_CAN_BREAK_BEFORE) |
|
|
|
|
FLAG_NOT_MISSING |
|
2007-11-09 09:27:23 +03:00
|
|
|
(aClusterStart ? 0 : FLAG_NOT_CLUSTER_START) |
|
|
|
|
(aLigatureStart ? 0 : FLAG_NOT_LIGATURE_GROUP_START) |
|
|
|
|
(aGlyphCount << GLYPH_COUNT_SHIFT);
|
2007-03-05 00:05:10 +03:00
|
|
|
return *this;
|
|
|
|
}
|
2007-11-09 09:27:23 +03:00
|
|
|
/**
|
2010-12-22 17:27:43 +03:00
|
|
|
* Missing glyphs are treated as ligature group starts; don't mess with
|
|
|
|
* the cluster-start flag (see bugs 618870 and 619286).
|
2007-11-09 09:27:23 +03:00
|
|
|
*/
|
|
|
|
CompressedGlyph& SetMissing(PRUint32 aGlyphCount) {
|
2011-05-04 15:29:56 +04:00
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_NOT_CLUSTER_START)) |
|
2007-11-09 09:27:23 +03:00
|
|
|
(aGlyphCount << GLYPH_COUNT_SHIFT);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
PRUint32 GetGlyphCount() const {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
return (mValue & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT;
|
|
|
|
}
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
private:
|
|
|
|
PRUint32 mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* When the glyphs for a character don't fit into a CompressedGlyph record
|
|
|
|
* in SimpleGlyph format, we use an array of DetailedGlyphs instead.
|
|
|
|
*/
|
|
|
|
struct DetailedGlyph {
|
2007-11-09 09:27:23 +03:00
|
|
|
/** The glyphID, or the Unicode character
|
|
|
|
* if this is a missing glyph */
|
|
|
|
PRUint32 mGlyphID;
|
2007-04-25 10:59:34 +04:00
|
|
|
/** The advance, x-offset and y-offset of the glyph, in appunits
|
|
|
|
* mAdvance is in the text direction (RTL or LTR)
|
|
|
|
* mXOffset is always from left to right
|
2010-11-30 18:44:35 +03:00
|
|
|
* mYOffset is always from top to bottom */
|
2007-03-20 06:26:19 +03:00
|
|
|
PRInt32 mAdvance;
|
|
|
|
float mXOffset, mYOffset;
|
2007-03-05 00:05:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// The text is divided into GlyphRuns as necessary
|
|
|
|
struct GlyphRun {
|
|
|
|
nsRefPtr<gfxFont> mFont; // never null
|
|
|
|
PRUint32 mCharacterOffset; // into original UTF16 string
|
2011-06-16 10:31:37 +04:00
|
|
|
PRUint8 mMatchType;
|
2007-03-05 00:05:10 +03:00
|
|
|
};
|
|
|
|
|
2007-11-09 09:27:23 +03:00
|
|
|
class THEBES_API GlyphRunIterator {
|
2007-03-05 00:05:10 +03:00
|
|
|
public:
|
|
|
|
GlyphRunIterator(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aLength)
|
|
|
|
: mTextRun(aTextRun), mStartOffset(aStart), mEndOffset(aStart + aLength) {
|
|
|
|
mNextIndex = mTextRun->FindFirstGlyphRunContaining(aStart);
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool NextRun();
|
2007-03-05 00:05:10 +03:00
|
|
|
GlyphRun *GetGlyphRun() { return mGlyphRun; }
|
|
|
|
PRUint32 GetStringStart() { return mStringStart; }
|
|
|
|
PRUint32 GetStringEnd() { return mStringEnd; }
|
|
|
|
private:
|
|
|
|
gfxTextRun *mTextRun;
|
|
|
|
GlyphRun *mGlyphRun;
|
|
|
|
PRUint32 mStringStart;
|
|
|
|
PRUint32 mStringEnd;
|
|
|
|
PRUint32 mNextIndex;
|
|
|
|
PRUint32 mStartOffset;
|
|
|
|
PRUint32 mEndOffset;
|
|
|
|
};
|
|
|
|
|
2007-07-18 18:22:06 +04:00
|
|
|
class GlyphRunOffsetComparator {
|
|
|
|
public:
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const GlyphRun& a,
|
2007-07-18 18:22:06 +04:00
|
|
|
const GlyphRun& b) const
|
|
|
|
{
|
|
|
|
return a.mCharacterOffset == b.mCharacterOffset;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool LessThan(const GlyphRun& a,
|
2007-07-18 18:22:06 +04:00
|
|
|
const GlyphRun& b) const
|
|
|
|
{
|
|
|
|
return a.mCharacterOffset < b.mCharacterOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
friend class GlyphRunIterator;
|
|
|
|
friend class FontSelector;
|
2006-02-15 05:45:37 +03:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
// API for setting up the textrun glyphs. Should only be called by
|
|
|
|
// things that construct textruns.
|
|
|
|
/**
|
|
|
|
* We've found a run of text that should use a particular font. Call this
|
|
|
|
* only during initialization when font substitution has been computed.
|
2007-03-27 07:24:49 +04:00
|
|
|
* Call it before setting up the glyphs for the characters in this run;
|
|
|
|
* SetMissingGlyph requires that the correct glyphrun be installed.
|
2007-07-18 18:22:06 +04:00
|
|
|
*
|
|
|
|
* If aForceNewRun, a new glyph run will be added, even if the
|
|
|
|
* previously added run uses the same font. If glyph runs are
|
|
|
|
* added out of strictly increasing aStartCharIndex order (via
|
|
|
|
* force), then SortGlyphRuns must be called after all glyph runs
|
|
|
|
* are added before any further operations are performed with this
|
|
|
|
* TextRun.
|
2007-03-05 00:05:10 +03:00
|
|
|
*/
|
2011-06-16 10:31:37 +04:00
|
|
|
nsresult AddGlyphRun(gfxFont *aFont, PRUint8 aMatchType,
|
2011-09-29 10:19:26 +04:00
|
|
|
PRUint32 aStartCharIndex, bool aForceNewRun);
|
2007-03-23 02:07:18 +03:00
|
|
|
void ResetGlyphRuns() { mGlyphRuns.Clear(); }
|
2007-07-18 18:22:06 +04:00
|
|
|
void SortGlyphRuns();
|
2009-03-30 04:31:51 +04:00
|
|
|
void SanitizeGlyphRuns();
|
2007-07-18 18:22:06 +04:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
// Call the following glyph-setters during initialization or during reshaping
|
|
|
|
// only. It is OK to overwrite existing data for a character.
|
|
|
|
/**
|
2007-11-09 09:27:23 +03:00
|
|
|
* Set the glyph data for a character. aGlyphs may be null if aGlyph is a
|
|
|
|
* simple glyph or has no associated glyphs. If non-null the data is copied,
|
|
|
|
* the caller retains ownership.
|
2007-03-05 00:05:10 +03:00
|
|
|
*/
|
2007-11-09 09:27:23 +03:00
|
|
|
void SetSimpleGlyph(PRUint32 aCharIndex, CompressedGlyph aGlyph) {
|
|
|
|
NS_ASSERTION(aGlyph.IsSimpleGlyph(), "Should be a simple glyph here");
|
2007-03-05 00:05:10 +03:00
|
|
|
if (mCharacterGlyphs) {
|
|
|
|
mCharacterGlyphs[aCharIndex] = aGlyph;
|
|
|
|
}
|
|
|
|
}
|
2007-11-09 09:27:23 +03:00
|
|
|
void SetGlyphs(PRUint32 aCharIndex, CompressedGlyph aGlyph,
|
|
|
|
const DetailedGlyph *aGlyphs);
|
|
|
|
void SetMissingGlyph(PRUint32 aCharIndex, PRUint32 aUnicodeChar);
|
2007-06-13 00:56:04 +04:00
|
|
|
void SetSpaceGlyph(gfxFont *aFont, gfxContext *aContext, PRUint32 aCharIndex);
|
2009-10-07 21:16:52 +04:00
|
|
|
|
|
|
|
// If the character at aIndex is default-ignorable, set the glyph
|
|
|
|
// to be invisible-missing and return TRUE, else return FALSE
|
2011-09-29 10:19:26 +04:00
|
|
|
bool FilterIfIgnorable(PRUint32 aIndex);
|
2009-10-07 21:16:52 +04:00
|
|
|
|
2007-12-21 10:09:50 +03:00
|
|
|
/**
|
|
|
|
* Prefetch all the glyph extents needed to ensure that Measure calls
|
2009-02-24 11:32:58 +03:00
|
|
|
* on this textrun not requesting tight boundingBoxes will succeed. Note
|
2007-12-21 10:09:50 +03:00
|
|
|
* that some glyph extents might not be fetched due to OOM or other
|
|
|
|
* errors.
|
|
|
|
*/
|
2007-09-24 06:19:14 +04:00
|
|
|
void FetchGlyphExtents(gfxContext *aRefContext);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
|
|
|
// API for access to the raw glyph data, needed by gfxFont::Draw
|
|
|
|
// and gfxFont::GetBoundingBox
|
|
|
|
const CompressedGlyph *GetCharacterGlyphs() { return mCharacterGlyphs; }
|
2011-02-12 01:05:09 +03:00
|
|
|
|
|
|
|
// NOTE that this must not be called for a character offset that does
|
|
|
|
// not have any DetailedGlyph records; callers must have verified that
|
|
|
|
// mCharacterGlyphs[aCharIndex].GetGlyphCount() is greater than zero.
|
2011-02-10 09:50:47 +03:00
|
|
|
DetailedGlyph *GetDetailedGlyphs(PRUint32 aCharIndex) {
|
2011-02-12 01:05:09 +03:00
|
|
|
NS_ASSERTION(mDetailedGlyphs != nsnull &&
|
|
|
|
!mCharacterGlyphs[aCharIndex].IsSimpleGlyph() &&
|
|
|
|
mCharacterGlyphs[aCharIndex].GetGlyphCount() > 0,
|
|
|
|
"invalid use of GetDetailedGlyphs; check the caller!");
|
2011-02-10 09:50:47 +03:00
|
|
|
return mDetailedGlyphs->Get(aCharIndex);
|
2007-03-05 00:05:10 +03:00
|
|
|
}
|
2011-02-12 01:05:09 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasDetailedGlyphs() { return mDetailedGlyphs != nsnull; }
|
2007-03-05 00:05:10 +03:00
|
|
|
PRUint32 CountMissingGlyphs();
|
2007-03-23 02:07:18 +03:00
|
|
|
const GlyphRun *GetGlyphRuns(PRUint32 *aNumGlyphRuns) {
|
|
|
|
*aNumGlyphRuns = mGlyphRuns.Length();
|
|
|
|
return mGlyphRuns.Elements();
|
|
|
|
}
|
2007-06-13 00:56:04 +04:00
|
|
|
// Returns the index of the GlyphRun containing the given offset.
|
|
|
|
// Returns mGlyphRuns.Length() when aOffset is mCharacterCount.
|
|
|
|
PRUint32 FindFirstGlyphRunContaining(PRUint32 aOffset);
|
|
|
|
// Copy glyph data for a range of characters from aSource to this
|
2011-02-10 09:50:47 +03:00
|
|
|
// textrun.
|
2007-06-13 00:56:04 +04:00
|
|
|
virtual void CopyGlyphDataFrom(gfxTextRun *aSource, PRUint32 aStart,
|
2011-02-10 09:50:47 +03:00
|
|
|
PRUint32 aLength, PRUint32 aDest);
|
2007-11-16 04:43:49 +03:00
|
|
|
|
2007-05-09 02:46:14 +04:00
|
|
|
nsExpirationState *GetExpirationState() { return &mExpirationState; }
|
|
|
|
|
2007-08-10 05:35:32 +04:00
|
|
|
struct LigatureData {
|
|
|
|
// textrun offsets of the start and end of the containing ligature
|
|
|
|
PRUint32 mLigatureStart;
|
|
|
|
PRUint32 mLigatureEnd;
|
|
|
|
// appunits advance to the start of the ligature part within the ligature;
|
|
|
|
// never includes any spacing
|
|
|
|
gfxFloat mPartAdvance;
|
|
|
|
// appunits width of the ligature part; includes before-spacing
|
|
|
|
// when the part is at the start of the ligature, and after-spacing
|
|
|
|
// when the part is as the end of the ligature
|
|
|
|
gfxFloat mPartWidth;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mClipBeforePart;
|
|
|
|
bool mClipAfterPart;
|
2007-08-10 05:35:32 +04:00
|
|
|
};
|
2008-10-01 07:01:53 +04:00
|
|
|
|
|
|
|
// user font set generation when text run was created
|
|
|
|
PRUint64 GetUserFontSetGeneration() { return mUserFontSetGeneration; }
|
2007-08-10 05:35:32 +04:00
|
|
|
|
2011-10-14 11:06:35 +04:00
|
|
|
// return storage used by this run, for memory reporter;
|
|
|
|
// nsTransformedTextRun needs to override this as it holds additional data
|
2011-11-28 07:03:14 +04:00
|
|
|
virtual NS_MUST_OVERRIDE size_t
|
|
|
|
SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
|
|
|
virtual NS_MUST_OVERRIDE size_t
|
|
|
|
SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf);
|
2011-10-14 11:06:35 +04:00
|
|
|
|
2011-11-28 07:03:14 +04:00
|
|
|
// Get the size, if it hasn't already been gotten, marking as it goes.
|
|
|
|
size_t MaybeSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) {
|
2011-10-14 11:06:35 +04:00
|
|
|
if (mFlags & gfxTextRunFactory::TEXT_RUN_SIZE_ACCOUNTED) {
|
2011-11-28 07:03:14 +04:00
|
|
|
return 0;
|
2011-10-14 11:06:35 +04:00
|
|
|
}
|
|
|
|
mFlags |= gfxTextRunFactory::TEXT_RUN_SIZE_ACCOUNTED;
|
2011-11-28 07:03:14 +04:00
|
|
|
return SizeOfIncludingThis(aMallocSizeOf);
|
2011-10-14 11:06:35 +04:00
|
|
|
}
|
2011-11-28 07:03:14 +04:00
|
|
|
void ResetSizeOfAccountingFlags() {
|
2011-10-14 11:06:35 +04:00
|
|
|
mFlags &= ~gfxTextRunFactory::TEXT_RUN_SIZE_ACCOUNTED;
|
|
|
|
}
|
|
|
|
|
2007-08-27 03:44:00 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
// number of entries referencing this textrun in the gfxTextRunWordCache
|
|
|
|
PRUint32 mCachedWords;
|
2008-12-18 23:12:53 +03:00
|
|
|
// generation of gfxTextRunWordCache that refers to this textrun;
|
|
|
|
// if the cache gets cleared, then mCachedWords is no longer meaningful
|
|
|
|
PRUint32 mCacheGeneration;
|
2008-01-21 04:23:50 +03:00
|
|
|
|
|
|
|
void Dump(FILE* aOutput);
|
2007-08-27 03:44:00 +04:00
|
|
|
#endif
|
|
|
|
|
2008-03-20 03:02:21 +03:00
|
|
|
// post-process glyph advances to deal with synthetic bolding
|
2011-09-03 00:18:25 +04:00
|
|
|
void AdjustAdvancesForSyntheticBold(gfxContext *aContext,
|
|
|
|
PRUint32 aStart,
|
|
|
|
PRUint32 aLength);
|
2008-03-20 03:02:21 +03:00
|
|
|
|
2007-11-16 04:43:47 +03:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Initializes the textrun to blank.
|
2010-02-18 14:52:34 +03:00
|
|
|
* @param aGlyphStorage preallocated array of CompressedGlyph[aLength]
|
|
|
|
* for the textrun to use; if aText is not persistent, then it has also
|
|
|
|
* been appended to this array, so it must NOT be freed separately.
|
2007-11-16 04:43:47 +03:00
|
|
|
*/
|
|
|
|
gfxTextRun(const gfxTextRunFactory::Parameters *aParams, const void *aText,
|
|
|
|
PRUint32 aLength, gfxFontGroup *aFontGroup, PRUint32 aFlags,
|
2010-02-18 14:52:34 +03:00
|
|
|
CompressedGlyph *aGlyphStorage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper for the Create() factory method to allocate the required
|
|
|
|
* glyph storage, and copy the text (modifying the aText parameter)
|
|
|
|
* if it is not flagged as persistent.
|
|
|
|
*/
|
|
|
|
static CompressedGlyph* AllocateStorage(const void*& aText,
|
|
|
|
PRUint32 aLength,
|
|
|
|
PRUint32 aFlags);
|
2007-11-16 04:43:47 +03:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
private:
|
|
|
|
// **** general helpers ****
|
|
|
|
|
2007-03-27 07:24:49 +04:00
|
|
|
// Allocate aCount DetailedGlyphs for the given index
|
|
|
|
DetailedGlyph *AllocateDetailedGlyphs(PRUint32 aCharIndex, PRUint32 aCount);
|
2007-08-10 05:35:32 +04:00
|
|
|
|
2011-02-10 09:50:47 +03:00
|
|
|
// Get the total advance for a range of glyphs.
|
|
|
|
PRInt32 GetAdvanceForGlyphs(PRUint32 aStart, PRUint32 aEnd);
|
|
|
|
|
2007-08-10 05:35:32 +04:00
|
|
|
// Spacing for characters outside the range aSpacingStart/aSpacingEnd
|
|
|
|
// is assumed to be zero; such characters are not passed to aProvider.
|
|
|
|
// This is useful to protect aProvider from being passed character indices
|
|
|
|
// it is not currently able to handle.
|
2011-09-29 10:19:26 +04:00
|
|
|
bool GetAdjustedSpacingArray(PRUint32 aStart, PRUint32 aEnd,
|
2007-03-23 02:01:14 +03:00
|
|
|
PropertyProvider *aProvider,
|
2007-08-10 05:35:32 +04:00
|
|
|
PRUint32 aSpacingStart, PRUint32 aSpacingEnd,
|
2007-03-23 02:01:14 +03:00
|
|
|
nsTArray<PropertyProvider::Spacing> *aSpacing);
|
2007-08-10 05:35:32 +04:00
|
|
|
|
|
|
|
// **** ligature helpers ****
|
|
|
|
// (Platforms do the actual ligaturization, but we need to do a bunch of stuff
|
|
|
|
// to handle requests that begin or end inside a ligature)
|
|
|
|
|
|
|
|
// if aProvider is null then mBeforeSpacing and mAfterSpacing are set to zero
|
|
|
|
LigatureData ComputeLigatureData(PRUint32 aPartStart, PRUint32 aPartEnd,
|
|
|
|
PropertyProvider *aProvider);
|
|
|
|
gfxFloat ComputePartialLigatureWidth(PRUint32 aPartStart, PRUint32 aPartEnd,
|
|
|
|
PropertyProvider *aProvider);
|
2011-01-11 14:17:00 +03:00
|
|
|
void DrawPartialLigature(gfxFont *aFont, gfxContext *aCtx,
|
|
|
|
PRUint32 aStart, PRUint32 aEnd, gfxPoint *aPt,
|
2007-03-05 00:05:10 +03:00
|
|
|
PropertyProvider *aProvider);
|
2007-08-10 05:35:32 +04:00
|
|
|
// Advance aStart to the start of the nearest ligature; back up aEnd
|
|
|
|
// to the nearest ligature end; may result in *aStart == *aEnd
|
2007-03-20 06:00:11 +03:00
|
|
|
void ShrinkToLigatureBoundaries(PRUint32 *aStart, PRUint32 *aEnd);
|
2007-03-20 06:26:19 +03:00
|
|
|
// result in appunits
|
2007-03-05 00:05:10 +03:00
|
|
|
gfxFloat GetPartialLigatureWidth(PRUint32 aStart, PRUint32 aEnd, PropertyProvider *aProvider);
|
|
|
|
void AccumulatePartialLigatureMetrics(gfxFont *aFont,
|
2009-02-24 11:32:58 +03:00
|
|
|
PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxContext *aRefContext,
|
2007-03-05 00:05:10 +03:00
|
|
|
PropertyProvider *aProvider,
|
|
|
|
Metrics *aMetrics);
|
|
|
|
|
|
|
|
// **** measurement helper ****
|
2009-02-24 11:32:58 +03:00
|
|
|
void AccumulateMetricsForRun(gfxFont *aFont, PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2007-09-24 06:19:14 +04:00
|
|
|
gfxContext *aRefContext,
|
2007-03-05 00:05:10 +03:00
|
|
|
PropertyProvider *aProvider,
|
2007-08-10 05:35:32 +04:00
|
|
|
PRUint32 aSpacingStart, PRUint32 aSpacingEnd,
|
2007-03-05 00:05:10 +03:00
|
|
|
Metrics *aMetrics);
|
|
|
|
|
|
|
|
// **** drawing helper ****
|
2011-09-29 10:19:26 +04:00
|
|
|
void DrawGlyphs(gfxFont *aFont, gfxContext *aContext, bool aDrawToPath,
|
2007-03-05 00:05:10 +03:00
|
|
|
gfxPoint *aPt, PRUint32 aStart, PRUint32 aEnd,
|
2007-08-10 05:35:32 +04:00
|
|
|
PropertyProvider *aProvider,
|
|
|
|
PRUint32 aSpacingStart, PRUint32 aSpacingEnd);
|
2007-03-23 02:01:14 +03:00
|
|
|
|
2007-11-16 04:43:47 +03:00
|
|
|
// All our glyph data is in logical order, not visual.
|
2010-02-18 14:52:34 +03:00
|
|
|
// mCharacterGlyphs is allocated by the factory that creates the textrun,
|
|
|
|
// to avoid the possibility of failure during the constructor;
|
|
|
|
// however, ownership passes to the textrun during construction and so
|
|
|
|
// it must be deleted in the destructor.
|
2007-11-16 04:43:47 +03:00
|
|
|
CompressedGlyph* mCharacterGlyphs;
|
2011-02-10 09:50:47 +03:00
|
|
|
|
|
|
|
// For characters whose glyph data does not fit the "simple" glyph criteria
|
|
|
|
// in CompressedGlyph, we use a sorted array to store the association
|
|
|
|
// between the source character offset and an index into an array
|
|
|
|
// DetailedGlyphs. The CompressedGlyph record includes a count of
|
|
|
|
// the number of DetailedGlyph records that belong to the character,
|
|
|
|
// starting at the given index.
|
|
|
|
class DetailedGlyphStore {
|
|
|
|
public:
|
|
|
|
DetailedGlyphStore()
|
|
|
|
: mLastUsed(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
// This is optimized for the most common calling patterns:
|
|
|
|
// we rarely need random access to the records, access is most commonly
|
|
|
|
// sequential through the textRun, so we record the last-used index
|
|
|
|
// and check whether the caller wants the same record again, or the
|
|
|
|
// next; if not, it's most likely we're starting over from the start
|
|
|
|
// of the run, so we check the first entry before resorting to binary
|
|
|
|
// search as a last resort.
|
2011-02-12 01:05:09 +03:00
|
|
|
// NOTE that this must not be called for a character offset that does
|
|
|
|
// not have any DetailedGlyph records; callers must have verified that
|
|
|
|
// mCharacterGlyphs[aOffset].GetGlyphCount() is greater than zero
|
|
|
|
// before calling this, otherwise the assertions here will fire (in a
|
|
|
|
// debug build), and we'll probably crash.
|
2011-02-10 09:50:47 +03:00
|
|
|
DetailedGlyph* Get(PRUint32 aOffset) {
|
|
|
|
NS_ASSERTION(mOffsetToIndex.Length() > 0,
|
|
|
|
"no detailed glyph records!");
|
|
|
|
DetailedGlyph* details = mDetails.Elements();
|
|
|
|
// check common cases (fwd iteration, initial entry, etc) first
|
|
|
|
if (mLastUsed < mOffsetToIndex.Length() - 1 &&
|
|
|
|
aOffset == mOffsetToIndex[mLastUsed + 1].mOffset) {
|
|
|
|
++mLastUsed;
|
|
|
|
} else if (aOffset == mOffsetToIndex[0].mOffset) {
|
|
|
|
mLastUsed = 0;
|
|
|
|
} else if (aOffset == mOffsetToIndex[mLastUsed].mOffset) {
|
|
|
|
// do nothing
|
|
|
|
} else if (mLastUsed > 0 &&
|
|
|
|
aOffset == mOffsetToIndex[mLastUsed - 1].mOffset) {
|
|
|
|
--mLastUsed;
|
|
|
|
} else {
|
|
|
|
mLastUsed =
|
|
|
|
mOffsetToIndex.BinaryIndexOf(aOffset, CompareToOffset());
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mLastUsed != nsTArray<DGRec>::NoIndex,
|
|
|
|
"detailed glyph record missing!");
|
|
|
|
return details + mOffsetToIndex[mLastUsed].mIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
DetailedGlyph* Allocate(PRUint32 aOffset, PRUint32 aCount) {
|
|
|
|
PRUint32 detailIndex = mDetails.Length();
|
|
|
|
DetailedGlyph *details = mDetails.AppendElements(aCount);
|
|
|
|
if (!details) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
// We normally set up glyph records sequentially, so the common case
|
|
|
|
// here is to append new records to the mOffsetToIndex array;
|
|
|
|
// test for that before falling back to the InsertElementSorted
|
|
|
|
// method.
|
|
|
|
if (mOffsetToIndex.Length() == 0 ||
|
2011-02-12 01:07:39 +03:00
|
|
|
aOffset > mOffsetToIndex[mOffsetToIndex.Length() - 1].mOffset) {
|
2011-02-10 09:50:47 +03:00
|
|
|
if (!mOffsetToIndex.AppendElement(DGRec(aOffset, detailIndex))) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!mOffsetToIndex.InsertElementSorted(DGRec(aOffset, detailIndex),
|
|
|
|
CompareRecordOffsets())) {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
2011-10-14 11:06:35 +04:00
|
|
|
PRUint32 SizeOf() {
|
|
|
|
return sizeof(DetailedGlyphStore) +
|
|
|
|
mDetails.SizeOf() + mOffsetToIndex.SizeOf();
|
|
|
|
}
|
|
|
|
|
2011-02-10 09:50:47 +03:00
|
|
|
private:
|
|
|
|
struct DGRec {
|
|
|
|
DGRec(const PRUint32& aOffset, const PRUint32& aIndex)
|
|
|
|
: mOffset(aOffset), mIndex(aIndex) { }
|
|
|
|
PRUint32 mOffset; // source character offset in the textrun
|
|
|
|
PRUint32 mIndex; // index where this char's DetailedGlyphs begin
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompareToOffset {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const DGRec& a, const PRUint32& b) const {
|
2011-02-10 09:50:47 +03:00
|
|
|
return a.mOffset == b;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool LessThan(const DGRec& a, const PRUint32& b) const {
|
2011-02-10 09:50:47 +03:00
|
|
|
return a.mOffset < b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompareRecordOffsets {
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const DGRec& a, const DGRec& b) const {
|
2011-02-10 09:50:47 +03:00
|
|
|
return a.mOffset == b.mOffset;
|
|
|
|
}
|
2011-09-29 10:19:26 +04:00
|
|
|
bool LessThan(const DGRec& a, const DGRec& b) const {
|
2011-02-10 09:50:47 +03:00
|
|
|
return a.mOffset < b.mOffset;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
// Concatenated array of all the DetailedGlyph records needed for the
|
|
|
|
// textRun; individual character offsets are associated with indexes
|
|
|
|
// into this array via the mOffsetToIndex table.
|
|
|
|
nsTArray<DetailedGlyph> mDetails;
|
|
|
|
|
|
|
|
// For each character offset that needs DetailedGlyphs, we record the
|
|
|
|
// index in mDetails where the list of glyphs begins. This array is
|
|
|
|
// sorted by mOffset.
|
|
|
|
nsTArray<DGRec> mOffsetToIndex;
|
|
|
|
|
|
|
|
// Records the most recently used index into mOffsetToIndex, so that
|
|
|
|
// we can support sequential access more quickly than just doing
|
|
|
|
// a binary search each time.
|
|
|
|
nsTArray<DGRec>::index_type mLastUsed;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsAutoPtr<DetailedGlyphStore> mDetailedGlyphs;
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
// XXX this should be changed to a GlyphRun plus a maybe-null GlyphRun*,
|
|
|
|
// for smaller size especially in the super-common one-glyphrun case
|
2011-06-16 10:31:37 +04:00
|
|
|
nsAutoTArray<GlyphRun,1> mGlyphRuns;
|
2007-05-09 02:46:14 +04:00
|
|
|
// When TEXT_IS_8BIT is set, we use mSingle, otherwise we use mDouble.
|
|
|
|
// When TEXT_IS_PERSISTENT is set, we don't own the text, otherwise we
|
2010-02-18 14:52:34 +03:00
|
|
|
// own the text. When we own the text, it's allocated fused with the
|
|
|
|
// mCharacterGlyphs array, and therefore need not be explicitly deleted.
|
2007-05-09 02:46:14 +04:00
|
|
|
// This text is not null-terminated.
|
|
|
|
union {
|
|
|
|
const PRUint8 *mSingle;
|
|
|
|
const PRUnichar *mDouble;
|
|
|
|
} mText;
|
|
|
|
void *mUserData;
|
|
|
|
gfxFontGroup *mFontGroup; // addrefed
|
|
|
|
gfxSkipChars mSkipChars;
|
|
|
|
nsExpirationState mExpirationState;
|
|
|
|
PRUint32 mAppUnitsPerDevUnit;
|
|
|
|
PRUint32 mFlags;
|
|
|
|
PRUint32 mCharacterCount;
|
2007-05-12 09:51:15 +04:00
|
|
|
PRUint32 mHashCode;
|
2008-10-01 07:01:53 +04:00
|
|
|
PRUint64 mUserFontSetGeneration; // user font set generation when text run created
|
2011-01-06 00:48:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSkipDrawing; // true if the font group we used had a user font
|
2011-01-06 00:48:48 +03:00
|
|
|
// download that's in progress, so we should hide text
|
|
|
|
// until the download completes (or timeout fires)
|
2007-03-05 00:05:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
class THEBES_API gfxFontGroup : public gfxTextRunFactory {
|
2009-10-07 19:26:58 +04:00
|
|
|
public:
|
2010-02-24 20:57:44 +03:00
|
|
|
static void Shutdown(); // platform must call this to release the languageAtomService
|
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle, gfxUserFontSet *aUserFontSet = nsnull);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
virtual ~gfxFontGroup();
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2007-06-11 05:31:27 +04:00
|
|
|
virtual gfxFont *GetFontAt(PRInt32 i) {
|
2008-11-26 02:22:39 +03:00
|
|
|
// If it turns out to be hard for all clients that cache font
|
|
|
|
// groups to call UpdateFontList at appropriate times, we could
|
|
|
|
// instead consider just calling UpdateFontList from someplace
|
|
|
|
// more central (such as here).
|
|
|
|
NS_ASSERTION(!mUserFontSet || mCurrGeneration == GetGeneration(),
|
|
|
|
"Whoever was caching this font group should have "
|
|
|
|
"called UpdateFontList on it");
|
2009-01-23 09:24:29 +03:00
|
|
|
NS_ASSERTION(mFonts.Length() > PRUint32(i),
|
|
|
|
"Requesting a font index that doesn't exist");
|
2008-11-26 02:22:39 +03:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<gfxFont*>(mFonts[i]);
|
2007-03-05 00:05:10 +03:00
|
|
|
}
|
2007-06-11 05:31:27 +04:00
|
|
|
virtual PRUint32 FontListLength() const {
|
2007-03-05 00:05:10 +03:00
|
|
|
return mFonts.Length();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool Equals(const gfxFontGroup& other) const {
|
2007-03-05 00:05:10 +03:00
|
|
|
return mFamilies.Equals(other.mFamilies) &&
|
|
|
|
mStyle.Equals(other.mStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfxFontStyle *GetStyle() const { return &mStyle; }
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2007-05-23 07:45:51 +04:00
|
|
|
/**
|
2007-07-05 07:07:25 +04:00
|
|
|
* The listed characters should not be passed in to MakeTextRun and should
|
|
|
|
* be treated as invisible and zero-width.
|
2007-05-23 07:45:51 +04:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool IsInvalidChar(PRUnichar ch);
|
2008-10-01 07:01:53 +04:00
|
|
|
|
2007-05-09 02:46:14 +04:00
|
|
|
/**
|
|
|
|
* Make a textrun for an empty string. This is fast; if you call it,
|
|
|
|
* don't bother caching the result.
|
|
|
|
*/
|
|
|
|
gfxTextRun *MakeEmptyTextRun(const Parameters *aParams, PRUint32 aFlags);
|
|
|
|
/**
|
|
|
|
* Make a textrun for a single ASCII space. This is fast; if you call it,
|
|
|
|
* don't bother caching the result.
|
|
|
|
*/
|
|
|
|
gfxTextRun *MakeSpaceTextRun(const Parameters *aParams, PRUint32 aFlags);
|
|
|
|
|
|
|
|
/**
|
2007-05-15 07:56:47 +04:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
2007-12-21 10:09:50 +03:00
|
|
|
* This calls FetchGlyphExtents on the textrun.
|
2007-05-09 02:46:14 +04:00
|
|
|
*/
|
|
|
|
virtual gfxTextRun *MakeTextRun(const PRUnichar *aString, PRUint32 aLength,
|
2009-10-07 19:26:58 +04:00
|
|
|
const Parameters *aParams, PRUint32 aFlags);
|
2007-05-09 02:46:14 +04:00
|
|
|
/**
|
2007-05-15 07:56:47 +04:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
2007-12-21 10:09:50 +03:00
|
|
|
* This calls FetchGlyphExtents on the textrun.
|
2007-05-09 02:46:14 +04:00
|
|
|
*/
|
|
|
|
virtual gfxTextRun *MakeTextRun(const PRUint8 *aString, PRUint32 aLength,
|
2009-10-07 19:26:58 +04:00
|
|
|
const Parameters *aParams, PRUint32 aFlags);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
|
|
|
/* helper function for splitting font families on commas and
|
|
|
|
* calling a function for each family to fill the mFonts array
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
typedef bool (*FontCreationCallback) (const nsAString& aName,
|
2007-03-05 00:05:10 +03:00
|
|
|
const nsACString& aGenericName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseFontSet,
|
2007-03-05 00:05:10 +03:00
|
|
|
void *closure);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ForEachFont(const nsAString& aFamilies,
|
2010-02-24 20:57:57 +03:00
|
|
|
nsIAtom *aLanguage,
|
2010-02-24 20:57:44 +03:00
|
|
|
FontCreationCallback fc,
|
|
|
|
void *closure);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ForEachFont(FontCreationCallback fc, void *closure);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
/**
|
|
|
|
* Check whether a given font (specified by its gfxFontEntry)
|
|
|
|
* is already in the fontgroup's list of actual fonts
|
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool HasFont(const gfxFontEntry *aFontEntry);
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
const nsString& GetFamilies() { return mFamilies; }
|
|
|
|
|
2008-03-13 05:36:58 +03:00
|
|
|
// This returns the preferred underline for this font group.
|
|
|
|
// Some CJK fonts have wrong underline offset in its metrics.
|
|
|
|
// If this group has such "bad" font, each platform's gfxFontGroup initialized mUnderlineOffset.
|
|
|
|
// The value should be lower value of first font's metrics and the bad font's metrics.
|
|
|
|
// Otherwise, this returns from first font's metrics.
|
2008-04-12 12:54:18 +04:00
|
|
|
enum { UNDERLINE_OFFSET_NOT_SET = PR_INT16_MAX };
|
2008-12-22 08:01:14 +03:00
|
|
|
virtual gfxFloat GetUnderlineOffset() {
|
2008-04-12 12:54:18 +04:00
|
|
|
if (mUnderlineOffset == UNDERLINE_OFFSET_NOT_SET)
|
2008-03-13 05:36:58 +03:00
|
|
|
mUnderlineOffset = GetFontAt(0)->GetMetrics().underlineOffset;
|
|
|
|
return mUnderlineOffset;
|
|
|
|
}
|
|
|
|
|
2010-11-08 01:44:51 +03:00
|
|
|
virtual already_AddRefed<gfxFont>
|
|
|
|
FindFontForChar(PRUint32 ch, PRUint32 prevCh, PRInt32 aRunScript,
|
2011-06-16 10:31:37 +04:00
|
|
|
gfxFont *aPrevMatchedFont,
|
|
|
|
PRUint8 *aMatchType);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// search through pref fonts for a character, return nsnull if no matching pref font
|
|
|
|
virtual already_AddRefed<gfxFont> WhichPrefFontSupportsChar(PRUint32 aCh);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
virtual already_AddRefed<gfxFont> WhichSystemFontSupportsChar(PRUint32 aCh);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2010-11-08 01:44:51 +03:00
|
|
|
void ComputeRanges(nsTArray<gfxTextRange>& mRanges,
|
|
|
|
const PRUnichar *aString, PRUint32 begin, PRUint32 end,
|
|
|
|
PRInt32 aRunScript);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxUserFontSet* GetUserFontSet();
|
|
|
|
|
|
|
|
// With downloadable fonts, the composition of the font group can change as fonts are downloaded
|
|
|
|
// for each change in state of the user font set, the generation value is bumped to avoid picking up
|
|
|
|
// previously created text runs in the text run word cache. For font groups based on stylesheets
|
|
|
|
// with no @font-face rule, this always returns 0.
|
|
|
|
PRUint64 GetGeneration();
|
|
|
|
|
2008-12-06 02:19:27 +03:00
|
|
|
// If there is a user font set, check to see whether the font list or any
|
|
|
|
// caches need updating.
|
2009-10-07 19:26:58 +04:00
|
|
|
virtual void UpdateFontList();
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ShouldSkipDrawing() const {
|
2011-01-06 00:48:48 +03:00
|
|
|
return mSkipDrawing;
|
|
|
|
}
|
|
|
|
|
2007-03-05 00:05:10 +03:00
|
|
|
protected:
|
|
|
|
nsString mFamilies;
|
|
|
|
gfxFontStyle mStyle;
|
|
|
|
nsTArray< nsRefPtr<gfxFont> > mFonts;
|
2008-03-13 05:36:58 +03:00
|
|
|
gfxFloat mUnderlineOffset;
|
|
|
|
|
2008-10-01 07:01:53 +04:00
|
|
|
gfxUserFontSet* mUserFontSet;
|
|
|
|
PRUint64 mCurrGeneration; // track the current user font set generation, rebuild font list if needed
|
|
|
|
|
2009-10-07 19:26:58 +04:00
|
|
|
// cache the most recent pref font to avoid general pref font lookup
|
|
|
|
nsRefPtr<gfxFontFamily> mLastPrefFamily;
|
|
|
|
nsRefPtr<gfxFont> mLastPrefFont;
|
|
|
|
eFontPrefLang mLastPrefLang; // lang group for last pref font
|
|
|
|
eFontPrefLang mPageLang;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mLastPrefFirstFont; // is this the first font in the list of pref fonts for this lang group?
|
2011-01-06 00:48:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mSkipDrawing; // hide text while waiting for a font
|
2011-01-06 00:48:48 +03:00
|
|
|
// download to complete (or fallback
|
|
|
|
// timer to fire)
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2008-12-06 02:19:27 +03:00
|
|
|
// Used for construction/destruction. Not intended to change the font set
|
|
|
|
// as invalidation of font lists and caches is not considered.
|
|
|
|
void SetUserFontSet(gfxUserFontSet *aUserFontSet);
|
|
|
|
|
2010-02-24 10:18:49 +03:00
|
|
|
// Initialize the list of fonts
|
|
|
|
void BuildFontList();
|
|
|
|
|
2008-03-13 05:36:58 +03:00
|
|
|
// Init this font group's font metrics. If there no bad fonts, you don't need to call this.
|
|
|
|
// But if there are one or more bad fonts which have bad underline offset,
|
|
|
|
// you should call this with the *first* bad font.
|
|
|
|
void InitMetricsForBadFont(gfxFont* aBadFont);
|
2008-03-13 05:37:00 +03:00
|
|
|
|
2011-01-07 15:38:28 +03:00
|
|
|
// Set up the textrun glyphs for an entire text run:
|
|
|
|
// find script runs, and then call InitScriptRun for each
|
2010-03-10 15:46:41 +03:00
|
|
|
void InitTextRun(gfxContext *aContext,
|
|
|
|
gfxTextRun *aTextRun,
|
2009-10-07 19:26:58 +04:00
|
|
|
const PRUnichar *aString,
|
|
|
|
PRUint32 aLength);
|
|
|
|
|
2011-01-07 15:38:28 +03:00
|
|
|
// InitTextRun helper to handle a single script run, by finding font ranges
|
|
|
|
// and calling each font's InitTextRun() as appropriate
|
|
|
|
void InitScriptRun(gfxContext *aContext,
|
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const PRUnichar *aString,
|
|
|
|
PRUint32 aTotalLength,
|
|
|
|
PRUint32 aScriptRunStart,
|
|
|
|
PRUint32 aScriptRunEnd,
|
|
|
|
PRInt32 aRunScript);
|
2010-06-11 23:14:38 +04:00
|
|
|
|
2008-01-27 10:37:29 +03:00
|
|
|
/* If aResolveGeneric is true, then CSS/Gecko generic family names are
|
|
|
|
* replaced with preferred fonts.
|
|
|
|
*
|
|
|
|
* If aResolveFontName is true then fc() is called only for existing fonts
|
|
|
|
* and with actual font names. If false then fc() is called with each
|
|
|
|
* family name in aFamilies (after resolving CSS/Gecko generic family names
|
|
|
|
* if aResolveGeneric).
|
2011-07-13 12:40:32 +04:00
|
|
|
* If aUseFontSet is true, the fontgroup's user font set is checked;
|
|
|
|
* if false then it is skipped.
|
2008-01-27 10:37:29 +03:00
|
|
|
*/
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ForEachFontInternal(const nsAString& aFamilies,
|
2010-02-24 20:57:57 +03:00
|
|
|
nsIAtom *aLanguage,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aResolveGeneric,
|
|
|
|
bool aResolveFontName,
|
|
|
|
bool aUseFontSet,
|
2010-02-24 20:57:44 +03:00
|
|
|
FontCreationCallback fc,
|
|
|
|
void *closure);
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool FontResolverProc(const nsAString& aName, void *aClosure);
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool FindPlatformFont(const nsAString& aName,
|
2009-10-07 19:26:58 +04:00
|
|
|
const nsACString& aGenericName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aUseFontSet,
|
2009-10-07 19:26:58 +04:00
|
|
|
void *closure);
|
|
|
|
|
2010-02-24 20:57:44 +03:00
|
|
|
static NS_HIDDEN_(nsILanguageAtomService*) gLangService;
|
2005-11-29 23:12:29 +03:00
|
|
|
};
|
2005-10-08 09:09:42 +04:00
|
|
|
#endif
|