2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Foundation code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Mozilla Foundation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2005
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* Stuart Parmenter <stuart@mozilla.com>
|
|
|
|
* Masayuki Nakano <masayuki@d-toybox.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifndef GFX_FONT_H
|
|
|
|
#define GFX_FONT_H
|
|
|
|
|
|
|
|
#include "prtypes.h"
|
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "nsTArray.h"
|
2007-04-03 20:32:43 -07:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "gfxSkipChars.h"
|
|
|
|
#include "gfxRect.h"
|
2007-04-03 20:32:43 -07:00
|
|
|
#include "nsExpirationTracker.h"
|
2007-06-08 01:22:03 -07:00
|
|
|
#include "nsMathUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class gfxContext;
|
|
|
|
class gfxTextRun;
|
|
|
|
class nsIAtom;
|
2007-04-03 20:32:43 -07:00
|
|
|
class gfxFont;
|
2007-03-22 10:30:00 -07:00
|
|
|
class gfxFontGroup;
|
|
|
|
typedef struct _cairo cairo_t;
|
|
|
|
|
|
|
|
#define FONT_STYLE_NORMAL 0
|
|
|
|
#define FONT_STYLE_ITALIC 1
|
|
|
|
#define FONT_STYLE_OBLIQUE 2
|
|
|
|
|
|
|
|
#define FONT_WEIGHT_NORMAL 400
|
|
|
|
#define FONT_WEIGHT_BOLD 700
|
|
|
|
|
2007-06-08 01:22:03 -07:00
|
|
|
#define FONT_MAX_SIZE 2000.0
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct THEBES_API gfxFontStyle {
|
2007-05-20 19:18:04 -07:00
|
|
|
gfxFontStyle(PRUint8 aStyle, PRUint16 aWeight, gfxFloat aSize,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsACString& aLangGroup,
|
|
|
|
float aSizeAdjust, PRPackedBool aSystemFont,
|
|
|
|
PRPackedBool aFamilyNameQuirks);
|
2007-04-03 20:32:43 -07:00
|
|
|
gfxFontStyle(const gfxFontStyle& aStyle);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The style of font (normal, italic, oblique)
|
|
|
|
PRUint8 style : 7;
|
|
|
|
|
|
|
|
// Say that this font is a system font and therefore does not
|
|
|
|
// require certain fixup that we do for fonts from untrusted
|
|
|
|
// sources.
|
|
|
|
PRPackedBool systemFont : 1;
|
|
|
|
|
|
|
|
// True if the character set quirks (for treatment of "Symbol",
|
|
|
|
// "Wingdings", etc.) should be applied.
|
|
|
|
PRPackedBool familyNameQuirks : 1;
|
|
|
|
|
|
|
|
// The weight of the font. 100, 200, ... 900 are the weights, and
|
|
|
|
// single integer offsets request the next bolder/lighter font
|
|
|
|
// available. For example, for a font available in weights 200,
|
|
|
|
// 400, 700, and 900, a weight of 898 should lead to the weight 400
|
|
|
|
// font being used, since it is two weights lighter than 900.
|
|
|
|
PRUint16 weight;
|
|
|
|
|
|
|
|
// The logical size of the font, in pixels
|
|
|
|
gfxFloat size;
|
|
|
|
|
|
|
|
// the language group
|
|
|
|
nsCString langGroup;
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2007-06-08 01:22:03 -07: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");
|
|
|
|
gfxFloat adjustedSize = PR_MAX(NS_round(size*(sizeAdjust/aspect)), 1.0);
|
|
|
|
return PR_MIN(adjustedSize, FONT_MAX_SIZE);
|
|
|
|
}
|
|
|
|
|
2007-04-03 20:32:43 -07:00
|
|
|
PLDHashNumber Hash() const {
|
|
|
|
return ((style + (systemFont << 7) + (familyNameQuirks << 8) +
|
|
|
|
(weight << 9)) + PRUint32(size*1000) + PRUint32(sizeAdjust*1000)) ^
|
|
|
|
HashString(langGroup);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void ComputeWeightAndOffset(PRInt8 *outBaseWeight,
|
|
|
|
PRInt8 *outOffset) const;
|
|
|
|
|
|
|
|
PRBool Equals(const gfxFontStyle& other) const {
|
|
|
|
return (size == other.size) &&
|
|
|
|
(style == other.style) &&
|
|
|
|
(systemFont == other.systemFont) &&
|
|
|
|
(familyNameQuirks == other.familyNameQuirks) &&
|
|
|
|
(weight == other.weight) &&
|
|
|
|
(langGroup.Equals(other.langGroup)) &&
|
|
|
|
(sizeAdjust == other.sizeAdjust);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2007-04-03 20:32:43 -07:00
|
|
|
/**
|
|
|
|
* Font cache design:
|
|
|
|
*
|
|
|
|
* The mFonts hashtable contains most fonts, indexed by (name, style).
|
|
|
|
* 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-20 18:54:13 -07:00
|
|
|
enum { TIMEOUT_SECONDS = 10 };
|
2007-04-03 20:32:43 -07: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-03 20:24:04 -07:00
|
|
|
// All fonts should be gone.
|
|
|
|
NS_WARN_IF_FALSE(mFonts.Count() == 0,
|
|
|
|
"Fonts still alive while shutting down gfxFontCache");
|
2007-04-03 20:32:43 -07: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
|
|
|
|
already_AddRefed<gfxFont> Lookup(const nsAString &aName,
|
|
|
|
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);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void DestroyFont(gfxFont *aFont);
|
|
|
|
|
|
|
|
static gfxFontCache *gGlobalCache;
|
|
|
|
|
|
|
|
struct Key {
|
|
|
|
const nsAString& mString;
|
|
|
|
const gfxFontStyle* mStyle;
|
|
|
|
Key(const nsAString& aString, const gfxFontStyle* aStyle)
|
|
|
|
: mString(aString), mStyle(aStyle) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
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() { }
|
|
|
|
|
|
|
|
PRBool KeyEquals(const KeyTypePointer aKey) const;
|
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
|
|
|
return HashString(aKey->mString) ^ aKey->mStyle->Hash();
|
|
|
|
}
|
|
|
|
enum { ALLOW_MEMMOVE = PR_TRUE };
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-04-03 20:32:43 -07:00
|
|
|
gfxFont* mFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<HashEntry> mFonts;
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* a SPECIFIC single font family */
|
|
|
|
class THEBES_API gfxFont {
|
2007-04-03 20:32:43 -07:00
|
|
|
public:
|
|
|
|
nsrefcnt AddRef(void) {
|
|
|
|
NS_PRECONDITION(PRInt32(mRefCnt) >= 0, "illegal refcnt");
|
|
|
|
++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) {
|
|
|
|
// Don't delete just yet; return the object to the cache for
|
|
|
|
// possibly recycling within some time limit
|
|
|
|
gfxFontCache::GetCache()->NotifyReleased(this);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 GetRefCount() { return mRefCnt; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsAutoRefCnt mRefCnt;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
public:
|
|
|
|
gfxFont(const nsAString &aName, const gfxFontStyle *aFontGroup);
|
|
|
|
virtual ~gfxFont() {}
|
|
|
|
|
|
|
|
const nsString& GetName() const { return mName; }
|
2007-04-03 20:32:43 -07:00
|
|
|
const gfxFontStyle *GetStyle() const { return &mStyle; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
virtual nsString GetUniqueName() = 0;
|
|
|
|
|
|
|
|
// Font metrics
|
|
|
|
struct Metrics {
|
|
|
|
gfxFloat xHeight;
|
|
|
|
gfxFloat superscriptOffset;
|
|
|
|
gfxFloat subscriptOffset;
|
|
|
|
gfxFloat strikeoutSize;
|
|
|
|
gfxFloat strikeoutOffset;
|
|
|
|
gfxFloat underlineSize;
|
|
|
|
gfxFloat underlineOffset;
|
|
|
|
gfxFloat height;
|
|
|
|
|
|
|
|
gfxFloat internalLeading;
|
|
|
|
gfxFloat externalLeading;
|
|
|
|
|
|
|
|
gfxFloat emHeight;
|
|
|
|
gfxFloat emAscent;
|
|
|
|
gfxFloat emDescent;
|
|
|
|
gfxFloat maxHeight;
|
|
|
|
gfxFloat maxAscent;
|
|
|
|
gfxFloat maxDescent;
|
|
|
|
gfxFloat maxAdvance;
|
|
|
|
|
|
|
|
gfxFloat aveCharWidth;
|
|
|
|
gfxFloat spaceWidth;
|
|
|
|
};
|
|
|
|
virtual const gfxFont::Metrics& GetMetrics() = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
struct Spacing {
|
|
|
|
gfxFloat mBefore;
|
|
|
|
gfxFloat mAfter;
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Metrics for a particular string
|
|
|
|
*/
|
|
|
|
struct RunMetrics {
|
|
|
|
RunMetrics() {
|
|
|
|
mAdvanceWidth = mAscent = mDescent = 0.0;
|
|
|
|
mBoundingBox = gfxRect(0,0,0,0);
|
|
|
|
mClusterCount = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CombineWith(const RunMetrics& aOtherOnRight) {
|
|
|
|
mAscent = PR_MAX(mAscent, aOtherOnRight.mAscent);
|
|
|
|
mDescent = PR_MAX(mDescent, aOtherOnRight.mDescent);
|
|
|
|
mBoundingBox =
|
|
|
|
mBoundingBox.Union(aOtherOnRight.mBoundingBox + gfxPoint(mAdvanceWidth, 0));
|
|
|
|
mAdvanceWidth += aOtherOnRight.mAdvanceWidth;
|
|
|
|
mClusterCount += aOtherOnRight.mClusterCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
// If aTightBoundingBox was set to true when these metrics were
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
// Count of the number of grapheme clusters. Layout needs
|
|
|
|
// this to compute tab offsets. For SpecialStrings, this is always 1.
|
|
|
|
PRInt32 mClusterCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
* this should be updated to the other end of the baseline. In application
|
|
|
|
* units, really!
|
|
|
|
* @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,
|
|
|
|
gfxContext *aContext, PRBool aDrawToPath, gfxPoint *aBaselineOrigin,
|
|
|
|
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.
|
|
|
|
* @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,
|
|
|
|
PRBool aTightBoundingBox,
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
PRBool NotifyLineBreaksChanged(gfxTextRun *aTextRun,
|
|
|
|
PRUint32 aStart, PRUint32 aLength)
|
|
|
|
{ return PR_FALSE; }
|
|
|
|
|
2007-04-03 20:32:43 -07:00
|
|
|
// Expiration tracking
|
|
|
|
nsExpirationState *GetExpirationState() { return &mExpirationState; }
|
|
|
|
|
2007-05-08 15:46:14 -07:00
|
|
|
// Get the glyphID of a space
|
|
|
|
virtual PRUint32 GetSpaceGlyph() = 0;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
// The family name of the font
|
2007-04-03 20:32:43 -07:00
|
|
|
nsString mName;
|
|
|
|
nsExpirationState mExpirationState;
|
|
|
|
gfxFontStyle mStyle;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This is called by the default Draw() implementation above.
|
|
|
|
virtual void SetupCairoFont(cairo_t *aCR) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
class THEBES_API gfxTextRunFactory {
|
|
|
|
THEBES_INLINE_DECL_REFCOUNTING(gfxTextRunFactory)
|
|
|
|
|
|
|
|
public:
|
|
|
|
// 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.
|
|
|
|
enum {
|
2007-06-12 13:56:04 -07:00
|
|
|
USER_TEXT_FLAGS = 0xFFFF0000,
|
|
|
|
PLATFORM_TEXT_FLAGS = 0x0000F000,
|
|
|
|
TEXTRUN_TEXT_FLAGS = 0x00000FFF,
|
|
|
|
|
2007-03-22 10:30:00 -07: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, GetSpacing can return negative spacing.
|
|
|
|
*/
|
|
|
|
TEXT_ENABLE_NEGATIVE_SPACING = 0x0010,
|
|
|
|
/**
|
|
|
|
* When set, mAfter spacing for a character already includes the character
|
|
|
|
* width. Otherwise, it does not include the character width.
|
|
|
|
*/
|
|
|
|
TEXT_ABSOLUTE_SPACING = 0x0020,
|
|
|
|
/**
|
|
|
|
* When set, GetHyphenationBreaks may return true for some character
|
|
|
|
* positions, otherwise it will always return false for all characters.
|
|
|
|
*/
|
|
|
|
TEXT_ENABLE_HYPHEN_BREAKS = 0x0040,
|
|
|
|
/**
|
|
|
|
* When set, the text has no characters above 255.
|
|
|
|
*/
|
|
|
|
TEXT_IS_8BIT = 0x0080,
|
|
|
|
/**
|
|
|
|
* When set, the text may have UTF16 surrogate pairs, otherwise it
|
|
|
|
* doesn't.
|
|
|
|
*/
|
|
|
|
TEXT_HAS_SURROGATES = 0x0100,
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2007-05-30 22:01:56 -07:00
|
|
|
TEXT_NEED_BOUNDING_BOX = 0x0200,
|
|
|
|
/**
|
|
|
|
* When set, ligatures are disabled.
|
|
|
|
*/
|
2007-05-30 22:21:56 -07:00
|
|
|
TEXT_DISABLE_LIGATURES = 0x0400
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This record contains all the parameters needed to initialize a textrun.
|
|
|
|
*/
|
|
|
|
struct Parameters {
|
|
|
|
// A reference context suggesting where the textrun will be rendered
|
|
|
|
gfxContext *mContext;
|
|
|
|
// Pointer to arbitrary user data (which should outlive the textrun)
|
|
|
|
void *mUserData;
|
|
|
|
// A description of which characters have been stripped from the original
|
|
|
|
// DOM string to produce the characters in the textrun. May be null
|
|
|
|
// if that information is not relevant.
|
|
|
|
gfxSkipChars *mSkipChars;
|
|
|
|
// A list of where linebreaks are currently placed in the textrun. May
|
|
|
|
// be null if mInitialBreakCount is zero.
|
|
|
|
PRUint32 *mInitialBreaks;
|
|
|
|
PRUint32 mInitialBreakCount;
|
|
|
|
// The ratio to use to convert device pixels to application layout units
|
|
|
|
PRUint32 mAppUnitsPerDevUnit;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtual ~gfxTextRunFactory() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxTextRun is an abstraction for drawing and measuring substrings of a run
|
|
|
|
* 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-05-22 20:45:51 -07:00
|
|
|
* \r, \t and \n characters (for which gfxFontGroup::IsInvisibleChar returns
|
|
|
|
* PR_TRUE) should be set to a CompressedGlyph with SetMissing() to make them
|
|
|
|
* invisible and zero-width.
|
2007-03-22 10:30:00 -07: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
|
|
|
|
* 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.)
|
|
|
|
*
|
|
|
|
* It is important that zero-length substrings are handled correctly. This will
|
|
|
|
* be on the test!
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class THEBES_API gfxTextRun {
|
|
|
|
public:
|
2007-05-08 15:46:14 -07:00
|
|
|
virtual ~gfxTextRun();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
typedef gfxFont::RunMetrics Metrics;
|
|
|
|
|
|
|
|
// Public textrun API for general use
|
|
|
|
|
|
|
|
PRBool IsClusterStart(PRUint32 aPos) {
|
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
|
|
|
return mCharacterGlyphs[aPos].IsClusterStart();
|
|
|
|
}
|
|
|
|
PRBool IsLigatureContinuation(PRUint32 aPos) {
|
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
|
|
|
return mCharacterGlyphs[aPos].IsLigatureContinuation();
|
|
|
|
}
|
|
|
|
PRBool CanBreakLineBefore(PRUint32 aPos) {
|
|
|
|
NS_ASSERTION(0 <= aPos && aPos < mCharacterCount, "aPos out of range");
|
|
|
|
return mCharacterGlyphs[aPos].CanBreakBefore();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRUint32 GetLength() { return mCharacterCount; }
|
|
|
|
|
|
|
|
// 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-22 16:07:18 -07: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-03-22 10:30:00 -07:00
|
|
|
* @return true if this changed the linebreaks, false if the new line
|
|
|
|
* breaks are the same as the old
|
|
|
|
*/
|
2007-03-22 16:07:18 -07:00
|
|
|
virtual PRBool SetPotentialLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
2007-06-26 21:22:21 -07:00
|
|
|
PRPackedBool *aBreakBefore,
|
|
|
|
gfxContext *aRefContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
2007-03-22 16:07:18 -07: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-22 10:30:00 -07:00
|
|
|
*/
|
2007-03-22 16:07:18 -07:00
|
|
|
class PropertyProvider {
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
|
|
|
// Detect hyphenation break opportunities in the given range; breaks
|
|
|
|
// not at cluster boundaries will be ignored.
|
|
|
|
virtual void GetHyphenationBreaks(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PRPackedBool *aBreakBefore) = 0;
|
|
|
|
|
|
|
|
// Returns the extra width that will be consumed by a hyphen. This should
|
|
|
|
// be constant for a given textrun.
|
|
|
|
virtual gfxFloat GetHyphenWidth() = 0;
|
|
|
|
|
|
|
|
typedef gfxFont::Spacing Spacing;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
Spacing *aSpacing) = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 aDirtyRect if non-null, drawing outside of the rectangle can be
|
|
|
|
* (but does not need to be) dropped. Note that if this is null, we cannot
|
|
|
|
* draw partial ligatures and we will assert if partial ligatures
|
|
|
|
* are detected.
|
|
|
|
* @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).
|
|
|
|
*/
|
|
|
|
void Draw(gfxContext *aContext, gfxPoint aPt,
|
|
|
|
PRUint32 aStart, PRUint32 aLength,
|
|
|
|
const gfxRect *aDirtyRect,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
gfxFloat *aAdvanceWidth);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
void DrawToPath(gfxContext *aContext, gfxPoint aPt,
|
|
|
|
PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PropertyProvider *aBreakProvider,
|
|
|
|
gfxFloat *aAdvanceWidth);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes the ReflowMetrics for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
|
|
|
* @param aTightBoundingBox if true, we make the bounding box tight
|
|
|
|
*/
|
|
|
|
Metrics MeasureText(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PRBool aTightBoundingBox,
|
|
|
|
PropertyProvider *aProvider);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Computes just the advance width for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
|
|
|
*/
|
|
|
|
gfxFloat GetAdvanceWidth(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PropertyProvider *aProvider);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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-22 16:07:18 -07:00
|
|
|
* We return true if glyphs or geometry changed, false otherwise. This
|
|
|
|
* function is virtual so that gfxTextRun subclasses can reshape
|
|
|
|
* properly.
|
|
|
|
*
|
2007-03-22 10:30:00 -07:00
|
|
|
* @param aAdvanceWidthDelta if non-null, returns the change in advance
|
|
|
|
* width of the given range.
|
|
|
|
*/
|
2007-03-22 16:07:18 -07:00
|
|
|
virtual PRBool SetLineBreaks(PRUint32 aStart, PRUint32 aLength,
|
|
|
|
PRBool aLineBreakBefore, PRBool aLineBreakAfter,
|
2007-06-26 21:22:21 -07:00
|
|
|
gfxFloat *aAdvanceWidthDelta,
|
|
|
|
gfxContext *aRefContext);
|
2007-03-22 10:30:00 -07: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-22 16:40:07 -07: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-03-22 10:30:00 -07: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.
|
|
|
|
* @param aTightBoundingBox if true, we make the bounding box in aMetrics tight
|
|
|
|
* @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)
|
|
|
|
*
|
|
|
|
* Note that negative advance widths are possible especially if negative
|
|
|
|
* spacing is provided.
|
|
|
|
*/
|
|
|
|
PRUint32 BreakAndMeasureText(PRUint32 aStart, PRUint32 aMaxLength,
|
|
|
|
PRBool aLineBreakBefore, gfxFloat aWidth,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
PRBool aSuppressInitialBreak,
|
2007-05-22 16:40:07 -07:00
|
|
|
gfxFloat *aTrimWhitespace,
|
2007-03-22 10:30:00 -07:00
|
|
|
Metrics *aMetrics, PRBool aTightBoundingBox,
|
|
|
|
PRBool *aUsedHyphenation,
|
|
|
|
PRUint32 *aLastBreak);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the reference context.
|
|
|
|
* XXX this is a hack. New text frame does not call this. Use only
|
|
|
|
* temporarily for old text frame.
|
|
|
|
*/
|
|
|
|
void SetContext(gfxContext *aContext) {}
|
|
|
|
|
|
|
|
// Utility getters
|
|
|
|
|
|
|
|
PRBool IsRightToLeft() const { return (mFlags & gfxTextRunFactory::TEXT_IS_RTL) != 0; }
|
|
|
|
gfxFloat GetDirection() const { return (mFlags & gfxTextRunFactory::TEXT_IS_RTL) ? -1.0 : 1.0; }
|
|
|
|
void *GetUserData() const { return mUserData; }
|
2007-05-08 15:46:14 -07:00
|
|
|
void SetUserData(void *aUserData) { mUserData = aUserData; }
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 GetFlags() const { return mFlags; }
|
2007-06-12 13:56:04 -07:00
|
|
|
void SetFlagBits(PRUint32 aFlags) {
|
|
|
|
NS_ASSERTION(!(aFlags & ~gfxTextRunFactory::USER_TEXT_FLAGS),
|
|
|
|
"Only user flags should be mutable");
|
|
|
|
mFlags |= aFlags;
|
|
|
|
}
|
|
|
|
void ClearFlagBits(PRUint32 aFlags) {
|
|
|
|
NS_ASSERTION(!(aFlags & ~gfxTextRunFactory::USER_TEXT_FLAGS),
|
|
|
|
"Only user flags should be mutable");
|
|
|
|
mFlags &= ~aFlags;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
const gfxSkipChars& GetSkipChars() const { return mSkipChars; }
|
|
|
|
PRUint32 GetAppUnitsPerDevUnit() const { return mAppUnitsPerDevUnit; }
|
2007-05-08 15:46:14 -07: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-12 13:56:04 -07:00
|
|
|
const void *GetTextAt(PRUint32 aIndex) {
|
|
|
|
return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT)
|
|
|
|
? NS_STATIC_CAST(const void *, mText.mSingle + aIndex)
|
|
|
|
: NS_STATIC_CAST(const void *, mText.mDouble + aIndex);
|
|
|
|
}
|
2007-05-14 20:06:52 -07:00
|
|
|
const PRUnichar GetChar(PRUint32 i) const
|
|
|
|
{ return (mFlags & gfxTextRunFactory::TEXT_IS_8BIT) ? mText.mSingle[i] : mText.mDouble[i]; }
|
2007-05-11 22:51:15 -07:00
|
|
|
PRUint32 GetHashCode() const { return mHashCode; }
|
|
|
|
void SetHashCode(PRUint32 aHash) { mHashCode = aHash; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// The caller is responsible for initializing our glyphs after construction.
|
|
|
|
// Initially all glyphs are such that GetCharacterGlyphs()[i].IsMissing() is true.
|
2007-05-14 20:56:47 -07:00
|
|
|
// If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
// textrun will copy it.
|
2007-05-08 15:46:14 -07:00
|
|
|
gfxTextRun(const gfxTextRunFactory::Parameters *aParams, const void *aText,
|
|
|
|
PRUint32 aLength, gfxFontGroup *aFontGroup, PRUint32 aFlags);
|
|
|
|
|
|
|
|
// Clone this textrun, according to the given parameters. This textrun's
|
|
|
|
// glyph data is copied, so the text and length must be the same as this
|
|
|
|
// textrun's. If there's a problem, return null. Actual linebreaks will
|
|
|
|
// be set as per aParams; there will be no potential linebreaks.
|
2007-05-14 20:56:47 -07:00
|
|
|
// If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
// textrun will copy it.
|
2007-05-08 15:46:14 -07:00
|
|
|
virtual gfxTextRun *Clone(const gfxTextRunFactory::Parameters *aParams, const void *aText,
|
|
|
|
PRUint32 aLength, gfxFontGroup *aFontGroup, PRUint32 aFlags);
|
2007-03-22 10:30:00 -07: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.
|
|
|
|
*/
|
|
|
|
class CompressedGlyph {
|
|
|
|
public:
|
|
|
|
CompressedGlyph() { mValue = 0; }
|
|
|
|
|
|
|
|
enum {
|
|
|
|
// Indicates that a cluster starts at this character and can be
|
|
|
|
// rendered using a single glyph with a reasonable advance offset
|
|
|
|
// and no special glyph offset. A "reasonable" advance offset is
|
|
|
|
// one that is a) a multiple of a pixel and b) fits in the available
|
|
|
|
// bits (currently 14). We should revisit this, especially a),
|
|
|
|
// if we want to support subpixel-aligned text.
|
|
|
|
FLAG_IS_SIMPLE_GLYPH = 0x80000000U,
|
|
|
|
// Indicates that a linebreak is allowed before this character
|
|
|
|
FLAG_CAN_BREAK_BEFORE = 0x40000000U,
|
|
|
|
|
|
|
|
// The advance is stored in appunits
|
|
|
|
ADVANCE_MASK = 0x3FFF0000U,
|
|
|
|
ADVANCE_SHIFT = 16,
|
|
|
|
|
|
|
|
GLYPH_MASK = 0x0000FFFFU,
|
|
|
|
|
|
|
|
// Non-simple glyphs have the following tags
|
|
|
|
|
|
|
|
TAG_MASK = 0x000000FFU,
|
|
|
|
// Indicates that this character corresponds to a missing glyph
|
|
|
|
// and should be skipped (or possibly, render the character
|
|
|
|
// Unicode value in some special way)
|
|
|
|
TAG_MISSING = 0x00U,
|
|
|
|
// Indicates that a cluster starts at this character and is rendered
|
|
|
|
// using one or more glyphs which cannot be represented here.
|
|
|
|
// Look up the DetailedGlyph table instead.
|
|
|
|
TAG_COMPLEX_CLUSTER = 0x01U,
|
|
|
|
// Indicates that a cluster starts at this character but is rendered
|
|
|
|
// as part of a ligature starting in a previous cluster.
|
|
|
|
// NOTE: we divide up the ligature's width by the number of clusters
|
|
|
|
// to get the width assigned to each cluster.
|
|
|
|
TAG_LIGATURE_CONTINUATION = 0x21U,
|
|
|
|
|
|
|
|
// Values where the upper 28 bits equal 0x80 are reserved for
|
|
|
|
// non-cluster-start characters (see IsClusterStart below)
|
|
|
|
|
|
|
|
// Indicates that a cluster does not start at this character, this is
|
|
|
|
// a low UTF16 surrogate
|
|
|
|
TAG_LOW_SURROGATE = 0x80U,
|
|
|
|
// Indicates that a cluster does not start at this character, this is
|
|
|
|
// part of a cluster starting with an earlier character (but not
|
|
|
|
// a low surrogate).
|
|
|
|
TAG_CLUSTER_CONTINUATION = 0x81U
|
|
|
|
};
|
|
|
|
|
|
|
|
// "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
|
|
|
|
static PRBool IsSimpleGlyphID(PRUint32 aGlyph) {
|
|
|
|
return (aGlyph & GLYPH_MASK) == aGlyph;
|
|
|
|
}
|
|
|
|
// Returns true if the advance aAdvance fits into the compressed representation.
|
2007-05-11 22:52:43 -07:00
|
|
|
// aAdvance is in appunits.
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool IsSimpleAdvance(PRUint32 aAdvance) {
|
|
|
|
return (aAdvance & (ADVANCE_MASK >> ADVANCE_SHIFT)) == aAdvance;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool IsSimpleGlyph() const { return (mValue & FLAG_IS_SIMPLE_GLYPH) != 0; }
|
|
|
|
PRBool IsComplex(PRUint32 aTag) const { return (mValue & (FLAG_IS_SIMPLE_GLYPH|TAG_MASK)) == aTag; }
|
|
|
|
PRBool IsMissing() const { return IsComplex(TAG_MISSING); }
|
|
|
|
PRBool IsComplexCluster() const { return IsComplex(TAG_COMPLEX_CLUSTER); }
|
2007-03-26 20:24:49 -07:00
|
|
|
PRBool IsComplexOrMissing() const {
|
|
|
|
return IsComplex(TAG_COMPLEX_CLUSTER) || IsComplex(TAG_MISSING);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
PRBool IsLigatureContinuation() const { return IsComplex(TAG_LIGATURE_CONTINUATION); }
|
|
|
|
PRBool IsClusterContinuation() const { return IsComplex(TAG_CLUSTER_CONTINUATION); }
|
|
|
|
PRBool IsLowSurrogate() const { return IsComplex(TAG_LOW_SURROGATE); }
|
|
|
|
PRBool IsClusterStart() const { return (mValue & (FLAG_IS_SIMPLE_GLYPH|0x80U)) != 0x80U; }
|
|
|
|
|
|
|
|
PRUint32 GetSimpleAdvance() const { return (mValue & ADVANCE_MASK) >> ADVANCE_SHIFT; }
|
|
|
|
PRUint32 GetSimpleGlyph() const { return mValue & GLYPH_MASK; }
|
|
|
|
|
|
|
|
PRUint32 GetComplexTag() const { return mValue & TAG_MASK; }
|
|
|
|
|
|
|
|
PRBool CanBreakBefore() const { return (mValue & FLAG_CAN_BREAK_BEFORE) != 0; }
|
|
|
|
// Returns FLAG_CAN_BREAK_BEFORE if the setting changed, 0 otherwise
|
|
|
|
PRUint32 SetCanBreakBefore(PRBool aCanBreakBefore) {
|
|
|
|
PRUint32 breakMask = aCanBreakBefore*FLAG_CAN_BREAK_BEFORE;
|
|
|
|
PRUint32 toggle = breakMask ^ (mValue & FLAG_CAN_BREAK_BEFORE);
|
|
|
|
mValue ^= toggle;
|
|
|
|
return toggle;
|
|
|
|
}
|
|
|
|
|
2007-05-11 22:52:43 -07:00
|
|
|
CompressedGlyph& SetSimpleGlyph(PRUint32 aAdvanceAppUnits, PRUint32 aGlyph) {
|
|
|
|
NS_ASSERTION(IsSimpleAdvance(aAdvanceAppUnits), "Advance overflow");
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ASSERTION(IsSimpleGlyphID(aGlyph), "Glyph overflow");
|
|
|
|
mValue = (mValue & FLAG_CAN_BREAK_BEFORE) | FLAG_IS_SIMPLE_GLYPH |
|
2007-05-11 22:52:43 -07:00
|
|
|
(aAdvanceAppUnits << ADVANCE_SHIFT) | aGlyph;
|
2007-03-22 10:30:00 -07:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CompressedGlyph& SetComplex(PRUint32 aTag) {
|
|
|
|
mValue = (mValue & FLAG_CAN_BREAK_BEFORE) | aTag;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CompressedGlyph& SetMissing() { return SetComplex(TAG_MISSING); }
|
|
|
|
CompressedGlyph& SetComplexCluster() { return SetComplex(TAG_COMPLEX_CLUSTER); }
|
|
|
|
CompressedGlyph& SetLowSurrogate() { return SetComplex(TAG_LOW_SURROGATE); }
|
|
|
|
CompressedGlyph& SetLigatureContinuation() { return SetComplex(TAG_LIGATURE_CONTINUATION); }
|
|
|
|
CompressedGlyph& SetClusterContinuation() { return SetComplex(TAG_CLUSTER_CONTINUATION); }
|
|
|
|
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 {
|
|
|
|
/** This is true for the last DetailedGlyph in the array. This lets
|
|
|
|
* us track the length of the array. */
|
|
|
|
PRUint32 mIsLastGlyph:1;
|
2007-03-26 20:24:49 -07:00
|
|
|
/** The glyphID if this is a ComplexCluster, or the Unicode character
|
|
|
|
* if this is a Missing glyph */
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 mGlyphID:31;
|
2007-04-24 23:59:34 -07: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
|
|
|
|
* mYOffset is always from bottom to top */
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 mAdvance;
|
|
|
|
float mXOffset, mYOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
// The text is divided into GlyphRuns as necessary
|
|
|
|
struct GlyphRun {
|
|
|
|
nsRefPtr<gfxFont> mFont; // never null
|
|
|
|
PRUint32 mCharacterOffset; // into original UTF16 string
|
|
|
|
};
|
|
|
|
|
|
|
|
class GlyphRunIterator {
|
|
|
|
public:
|
|
|
|
GlyphRunIterator(gfxTextRun *aTextRun, PRUint32 aStart, PRUint32 aLength)
|
|
|
|
: mTextRun(aTextRun), mStartOffset(aStart), mEndOffset(aStart + aLength) {
|
|
|
|
mNextIndex = mTextRun->FindFirstGlyphRunContaining(aStart);
|
|
|
|
}
|
|
|
|
PRBool NextRun();
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
friend class GlyphRunIterator;
|
|
|
|
friend class FontSelector;
|
|
|
|
|
|
|
|
// API for setting up the textrun glyphs. Should only be called by
|
|
|
|
// things that construct textruns.
|
|
|
|
/**
|
|
|
|
* Record every character that is the second half of a surrogate pair.
|
|
|
|
* This should be called after creating a Unicode textrun.
|
|
|
|
*/
|
|
|
|
void RecordSurrogates(const PRUnichar *aString);
|
|
|
|
/**
|
|
|
|
* 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-26 20:24:49 -07:00
|
|
|
* Call it before setting up the glyphs for the characters in this run;
|
|
|
|
* SetMissingGlyph requires that the correct glyphrun be installed.
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
|
|
|
nsresult AddGlyphRun(gfxFont *aFont, PRUint32 aStartCharIndex);
|
2007-03-22 16:07:18 -07:00
|
|
|
void ResetGlyphRuns() { mGlyphRuns.Clear(); }
|
2007-03-22 10:30:00 -07:00
|
|
|
// Call the following glyph-setters during initialization or during reshaping
|
|
|
|
// only. It is OK to overwrite existing data for a character.
|
|
|
|
/**
|
|
|
|
* Set the glyph for a character. Also allows you to set low surrogates,
|
|
|
|
* cluster and ligature continuations.
|
|
|
|
*/
|
|
|
|
void SetCharacterGlyph(PRUint32 aCharIndex, CompressedGlyph aGlyph) {
|
|
|
|
NS_ASSERTION(aCharIndex > 0 ||
|
|
|
|
(aGlyph.IsClusterStart() && !aGlyph.IsLigatureContinuation()),
|
|
|
|
"First character must be the start of a cluster and can't be a ligature continuation!");
|
|
|
|
if (mCharacterGlyphs) {
|
|
|
|
mCharacterGlyphs[aCharIndex] = aGlyph;
|
|
|
|
}
|
|
|
|
if (mDetailedGlyphs) {
|
|
|
|
mDetailedGlyphs[aCharIndex] = nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Set some detailed glyphs for a character. The data is copied from aGlyphs,
|
|
|
|
* the caller retains ownership.
|
|
|
|
*/
|
2007-03-22 16:07:18 -07:00
|
|
|
void SetDetailedGlyphs(PRUint32 aCharIndex, const DetailedGlyph *aGlyphs,
|
2007-03-22 10:30:00 -07:00
|
|
|
PRUint32 aNumGlyphs);
|
2007-03-26 20:24:49 -07:00
|
|
|
void SetMissingGlyph(PRUint32 aCharIndex, PRUnichar aChar);
|
2007-06-12 13:56:04 -07:00
|
|
|
void SetSpaceGlyph(gfxFont *aFont, gfxContext *aContext, PRUint32 aCharIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// API for access to the raw glyph data, needed by gfxFont::Draw
|
|
|
|
// and gfxFont::GetBoundingBox
|
|
|
|
const CompressedGlyph *GetCharacterGlyphs() { return mCharacterGlyphs; }
|
|
|
|
const DetailedGlyph *GetDetailedGlyphs(PRUint32 aCharIndex) {
|
2007-05-05 11:19:17 -07:00
|
|
|
// Although mDetailedGlyphs should be non-NULL when ComplexCluster,
|
|
|
|
// Missing glyphs need not have details.
|
|
|
|
return mDetailedGlyphs ? mDetailedGlyphs[aCharIndex].get() : nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
PRUint32 CountMissingGlyphs();
|
2007-03-22 16:07:18 -07:00
|
|
|
const GlyphRun *GetGlyphRuns(PRUint32 *aNumGlyphRuns) {
|
|
|
|
*aNumGlyphRuns = mGlyphRuns.Length();
|
|
|
|
return mGlyphRuns.Elements();
|
|
|
|
}
|
2007-06-12 13:56:04 -07: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
|
|
|
|
// textrun. If aStealData is true then we actually steal the glyph data,
|
|
|
|
// setting the data in aSource to "missing". aDest should be in the last
|
|
|
|
// glyphrun.
|
|
|
|
virtual void CopyGlyphDataFrom(gfxTextRun *aSource, PRUint32 aStart,
|
|
|
|
PRUint32 aLength, PRUint32 aDest,
|
|
|
|
PRBool aStealData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-08 15:46:14 -07:00
|
|
|
nsExpirationState *GetExpirationState() { return &mExpirationState; }
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// **** general helpers ****
|
|
|
|
|
2007-03-26 20:24:49 -07:00
|
|
|
// Allocate aCount DetailedGlyphs for the given index
|
|
|
|
DetailedGlyph *AllocateDetailedGlyphs(PRUint32 aCharIndex, PRUint32 aCount);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Computes the x-advance for a given cluster starting at aClusterOffset. Does
|
|
|
|
// not include any spacing. Result is in appunits.
|
|
|
|
PRInt32 ComputeClusterAdvance(PRUint32 aClusterOffset);
|
|
|
|
|
|
|
|
// **** 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)
|
|
|
|
|
|
|
|
struct LigatureData {
|
|
|
|
PRUint32 mStartOffset;
|
|
|
|
PRUint32 mEndOffset;
|
|
|
|
PRUint32 mClusterCount;
|
|
|
|
PRUint32 mPartClusterIndex;
|
|
|
|
PRInt32 mLigatureWidth; // appunits
|
|
|
|
gfxFloat mBeforeSpacing; // appunits
|
|
|
|
gfxFloat mAfterSpacing; // appunits
|
|
|
|
};
|
|
|
|
// if aProvider is null then mBeforeSpacing and mAfterSpacing are set to zero
|
|
|
|
LigatureData ComputeLigatureData(PRUint32 aPartOffset, PropertyProvider *aProvider);
|
|
|
|
void GetAdjustedSpacing(PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
PropertyProvider *aProvider, PropertyProvider::Spacing *aSpacing);
|
|
|
|
PRBool GetAdjustedSpacingArray(PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
nsTArray<PropertyProvider::Spacing> *aSpacing);
|
|
|
|
void DrawPartialLigature(gfxFont *aFont, gfxContext *aCtx, PRUint32 aOffset,
|
|
|
|
const gfxRect *aDirtyRect, gfxPoint *aPt,
|
|
|
|
PropertyProvider *aProvider);
|
|
|
|
void ShrinkToLigatureBoundaries(PRUint32 *aStart, PRUint32 *aEnd);
|
|
|
|
// result in appunits
|
|
|
|
gfxFloat GetPartialLigatureWidth(PRUint32 aStart, PRUint32 aEnd, PropertyProvider *aProvider);
|
|
|
|
void AccumulatePartialLigatureMetrics(gfxFont *aFont,
|
|
|
|
PRUint32 aOffset, PRBool aTight,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
Metrics *aMetrics);
|
|
|
|
|
|
|
|
// **** measurement helper ****
|
|
|
|
void AccumulateMetricsForRun(gfxFont *aFont, PRUint32 aStart,
|
|
|
|
PRUint32 aEnd, PRBool aTight,
|
|
|
|
PropertyProvider *aProvider,
|
|
|
|
Metrics *aMetrics);
|
|
|
|
|
|
|
|
// **** drawing helper ****
|
|
|
|
void DrawGlyphs(gfxFont *aFont, gfxContext *aContext, PRBool aDrawToPath,
|
|
|
|
gfxPoint *aPt, PRUint32 aStart, PRUint32 aEnd,
|
|
|
|
PropertyProvider *aProvider);
|
|
|
|
|
|
|
|
// All our glyph data is in logical order, not visual
|
|
|
|
nsAutoArrayPtr<CompressedGlyph> mCharacterGlyphs;
|
|
|
|
nsAutoArrayPtr<nsAutoArrayPtr<DetailedGlyph> > mDetailedGlyphs; // only non-null if needed
|
|
|
|
// XXX this should be changed to a GlyphRun plus a maybe-null GlyphRun*,
|
|
|
|
// for smaller size especially in the super-common one-glyphrun case
|
|
|
|
nsAutoTArray<GlyphRun,1> mGlyphRuns;
|
2007-05-08 15:46:14 -07: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
|
|
|
|
// own the text and should delete it when we go away.
|
|
|
|
// 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-11 22:51:15 -07:00
|
|
|
PRUint32 mHashCode;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
class THEBES_API gfxFontGroup : public gfxTextRunFactory {
|
|
|
|
public:
|
|
|
|
gfxFontGroup(const nsAString& aFamilies, const gfxFontStyle *aStyle);
|
|
|
|
|
|
|
|
virtual ~gfxFontGroup() {
|
|
|
|
mFonts.Clear();
|
|
|
|
}
|
|
|
|
|
2007-06-10 18:31:27 -07:00
|
|
|
virtual gfxFont *GetFontAt(PRInt32 i) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_STATIC_CAST(gfxFont*, mFonts[i]);
|
|
|
|
}
|
2007-06-10 18:31:27 -07:00
|
|
|
virtual PRUint32 FontListLength() const {
|
2007-03-22 10:30:00 -07:00
|
|
|
return mFonts.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool Equals(const gfxFontGroup& other) const {
|
|
|
|
return mFamilies.Equals(other.mFamilies) &&
|
|
|
|
mStyle.Equals(other.mStyle);
|
|
|
|
}
|
|
|
|
|
|
|
|
const gfxFontStyle *GetStyle() const { return &mStyle; }
|
|
|
|
|
|
|
|
virtual gfxFontGroup *Copy(const gfxFontStyle *aStyle) = 0;
|
|
|
|
|
2007-05-22 20:45:51 -07:00
|
|
|
/**
|
2007-06-12 13:56:04 -07:00
|
|
|
* Tabs, CRs and LFs should be zero-width and invisible. They should
|
|
|
|
* break up shaping.
|
2007-05-22 20:45:51 -07:00
|
|
|
*/
|
|
|
|
static PRBool IsInvisibleChar(PRUnichar ch) {
|
|
|
|
return ch == '\t' || ch == '\r' || ch == '\n';
|
|
|
|
}
|
|
|
|
|
2007-05-08 15:46:14 -07: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-14 20:56:47 -07:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
2007-05-08 15:46:14 -07:00
|
|
|
*/
|
|
|
|
virtual gfxTextRun *MakeTextRun(const PRUnichar *aString, PRUint32 aLength,
|
|
|
|
const Parameters *aParams, PRUint32 aFlags) = 0;
|
|
|
|
/**
|
2007-05-14 20:56:47 -07:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
2007-05-08 15:46:14 -07:00
|
|
|
*/
|
|
|
|
virtual gfxTextRun *MakeTextRun(const PRUint8 *aString, PRUint32 aLength,
|
|
|
|
const Parameters *aParams, PRUint32 aFlags) = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* helper function for splitting font families on commas and
|
|
|
|
* calling a function for each family to fill the mFonts array
|
|
|
|
*/
|
|
|
|
typedef PRBool (*FontCreationCallback) (const nsAString& aName,
|
|
|
|
const nsACString& aGenericName,
|
|
|
|
void *closure);
|
|
|
|
static PRBool ForEachFont(const nsAString& aFamilies,
|
|
|
|
const nsACString& aLangGroup,
|
|
|
|
FontCreationCallback fc,
|
|
|
|
void *closure);
|
|
|
|
PRBool ForEachFont(FontCreationCallback fc, void *closure);
|
|
|
|
|
|
|
|
/* this will call back fc with the a generic font based on the style's langgroup */
|
|
|
|
void FindGenericFontFromStyle(FontCreationCallback fc, void *closure);
|
|
|
|
|
|
|
|
const nsString& GetFamilies() { return mFamilies; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsString mFamilies;
|
|
|
|
gfxFontStyle mStyle;
|
|
|
|
nsTArray< nsRefPtr<gfxFont> > mFonts;
|
|
|
|
|
|
|
|
static PRBool ForEachFontInternal(const nsAString& aFamilies,
|
|
|
|
const nsACString& aLangGroup,
|
|
|
|
PRBool aResolveGeneric,
|
|
|
|
FontCreationCallback fc,
|
|
|
|
void *closure);
|
|
|
|
|
|
|
|
static PRBool FontResolverProc(const nsAString& aName, void *aClosure);
|
|
|
|
};
|
|
|
|
#endif
|