2005-10-08 05:09:42 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
2012-05-21 11:12:37 +00:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-10-08 05:09:42 +00:00
|
|
|
|
|
|
|
#ifndef GFX_FONT_H
|
|
|
|
#define GFX_FONT_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
2014-09-16 09:58:12 +00:00
|
|
|
#include "gfxFontEntry.h"
|
2005-10-08 05:09:42 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxPoint.h"
|
2006-02-24 05:15:21 +00:00
|
|
|
#include "nsTArray.h"
|
2007-04-04 03:32:43 +00:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2007-01-23 08:45:52 +00:00
|
|
|
#include "gfxRect.h"
|
2007-04-04 03:32:43 +00:00
|
|
|
#include "nsExpirationTracker.h"
|
2009-10-07 15:26:58 +00:00
|
|
|
#include "gfxPlatform.h"
|
2010-02-24 17:57:57 +00:00
|
|
|
#include "nsIAtom.h"
|
2012-03-12 22:53:18 +00:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2012-03-23 12:14:16 +00:00
|
|
|
#include "nsIMemoryReporter.h"
|
2013-05-22 15:48:55 +00:00
|
|
|
#include "nsIObserver.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-06-13 04:14:28 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2013-10-01 21:02:16 +00:00
|
|
|
#include "DrawMode.h"
|
2013-10-07 23:15:59 +00:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "harfbuzz/hb.h"
|
2013-12-02 23:53:14 +00:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2011-12-15 16:12:40 +00:00
|
|
|
typedef struct _cairo_scaled_font cairo_scaled_font_t;
|
2014-09-16 09:58:12 +00:00
|
|
|
//typedef struct gr_face gr_face;
|
2011-12-15 16:12:40 +00:00
|
|
|
|
2008-01-21 01:23:50 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
#include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
class gfxContext;
|
2005-11-29 20:12:29 +00:00
|
|
|
class gfxTextRun;
|
2007-04-04 03:32:43 +00:00
|
|
|
class gfxFont;
|
2014-09-16 09:58:12 +00:00
|
|
|
class gfxGlyphExtents;
|
2013-01-04 18:35:37 +00:00
|
|
|
class gfxShapedText;
|
2011-12-06 12:39:19 +00:00
|
|
|
class gfxShapedWord;
|
2014-09-16 09:58:12 +00:00
|
|
|
class gfxSkipChars;
|
2013-05-16 02:35:12 +00:00
|
|
|
class gfxTextContextPaint;
|
2010-02-24 17:57:44 +00:00
|
|
|
|
2007-06-08 08:22:03 +00:00
|
|
|
#define FONT_MAX_SIZE 2000.0
|
|
|
|
|
2010-07-13 20:31:31 +00:00
|
|
|
#define NO_FONT_LANGUAGE_OVERRIDE 0
|
|
|
|
|
2014-05-26 13:23:32 +00:00
|
|
|
#define SMALL_CAPS_SCALE_FACTOR 0.8
|
|
|
|
|
2014-12-31 22:35:40 +00:00
|
|
|
// The skew factor used for synthetic-italic [oblique] fonts;
|
|
|
|
// we use a platform-dependent value to harmonize with the platform's own APIs.
|
|
|
|
#ifdef XP_WIN
|
|
|
|
#define OBLIQUE_SKEW_FACTOR 0.3
|
2015-05-13 05:11:25 +00:00
|
|
|
#elif defined(MOZ_WIDGET_GTK) || defined(MOZ_WIDGET_QT)
|
|
|
|
#define OBLIQUE_SKEW_FACTOR 0.2
|
2014-12-31 22:35:40 +00:00
|
|
|
#else
|
|
|
|
#define OBLIQUE_SKEW_FACTOR 0.25
|
|
|
|
#endif
|
|
|
|
|
2013-02-11 06:22:20 +00:00
|
|
|
struct gfxTextRunDrawCallbacks;
|
2012-03-27 21:38:39 +00:00
|
|
|
|
2013-10-07 23:15:59 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
class GlyphRenderingOptions;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
2013-10-07 23:15:59 +00:00
|
|
|
|
2013-05-29 21:59:24 +00:00
|
|
|
struct gfxFontStyle {
|
2008-03-12 10:52:58 +00:00
|
|
|
gfxFontStyle();
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxFontStyle(uint8_t aStyle, uint16_t aWeight, int16_t aStretch,
|
2014-12-23 12:50:10 +00:00
|
|
|
gfxFloat aSize, nsIAtom *aLanguage, bool aExplicitLanguage,
|
2011-09-29 06:19:26 +00:00
|
|
|
float aSizeAdjust, bool aSystemFont,
|
2014-06-23 03:09:17 +00:00
|
|
|
bool aPrinterFont,
|
2014-06-19 07:08:55 +00:00
|
|
|
bool aWeightSynthesis, bool aStyleSynthesis,
|
2010-07-13 20:31:31 +00:00
|
|
|
const nsString& aLanguageOverride);
|
2007-04-04 03:32:43 +00:00
|
|
|
gfxFontStyle(const gfxFontStyle& aStyle);
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2012-03-15 09:03:00 +00: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
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsIAtom> language;
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2013-05-20 02:59:20 +00:00
|
|
|
// Features are composed of (1) features from style rules (2) features
|
|
|
|
// from feature setttings rules and (3) family-specific features. (1) and
|
|
|
|
// (3) are guaranteed to be mutually exclusive
|
|
|
|
|
2012-03-15 09:03:00 +00:00
|
|
|
// custom opentype feature settings
|
|
|
|
nsTArray<gfxFontFeature> featureSettings;
|
2009-01-29 20:39:18 +00:00
|
|
|
|
2013-05-20 02:59:20 +00:00
|
|
|
// Some font-variant property values require font-specific settings
|
|
|
|
// defined via @font-feature-values rules. These are resolved after
|
|
|
|
// font matching occurs.
|
|
|
|
|
|
|
|
// -- list of value tags for specific alternate features
|
|
|
|
nsTArray<gfxAlternateValue> alternateValues;
|
|
|
|
|
|
|
|
// -- object used to look these up once the font is matched
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxFontFeatureValueSet> featureValueLookup;
|
2013-05-20 02:59:20 +00:00
|
|
|
|
2006-01-19 20:31:59 +00:00
|
|
|
// The logical size of the font, in pixels
|
2005-10-08 05:09:42 +00:00
|
|
|
gfxFloat size;
|
|
|
|
|
|
|
|
// The aspect-value (ie., the ratio actualsize:actualxheight) that any
|
|
|
|
// actual physical font created from this font structure must have when
|
2015-04-21 06:10:40 +00:00
|
|
|
// rendering or measuring a string. A value of -1.0 means no adjustment
|
|
|
|
// needs to be done; otherwise the value must be nonnegative.
|
2005-10-08 05:09:42 +00:00
|
|
|
float sizeAdjust;
|
2006-02-22 01:44:31 +00:00
|
|
|
|
2014-07-22 00:02:45 +00:00
|
|
|
// baseline offset, used when simulating sub/superscript glyphs
|
|
|
|
float baselineOffset;
|
|
|
|
|
2010-07-13 20:31:31 +00: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.)
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t languageOverride;
|
2010-07-13 20:31:31 +00:00
|
|
|
|
2012-03-15 09:03:00 +00:00
|
|
|
// The weight of the font: 100, 200, ... 900.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t weight;
|
2012-03-15 09:03:00 +00:00
|
|
|
|
|
|
|
// The stretch of the font (the sum of various NS_FONT_STRETCH_*
|
|
|
|
// constants; see gfxFontConstants.h).
|
2012-08-22 15:56:38 +00:00
|
|
|
int8_t stretch;
|
2012-03-15 09:03:00 +00:00
|
|
|
|
|
|
|
// Say that this font is a system font and therefore does not
|
|
|
|
// require certain fixup that we do for fonts from untrusted
|
|
|
|
// sources.
|
|
|
|
bool systemFont : 1;
|
|
|
|
|
|
|
|
// Say that this font is used for print or print preview.
|
|
|
|
bool printerFont : 1;
|
|
|
|
|
2013-07-29 20:00:41 +00:00
|
|
|
// Used to imitate -webkit-font-smoothing: antialiased
|
|
|
|
bool useGrayscaleAntialiasing : 1;
|
|
|
|
|
2014-06-23 03:09:16 +00:00
|
|
|
// The style of font (normal, italic, oblique)
|
|
|
|
uint8_t style : 2;
|
2014-05-26 13:23:31 +00:00
|
|
|
|
2014-06-19 07:08:55 +00:00
|
|
|
// Whether synthetic styles are allowed
|
|
|
|
bool allowSyntheticWeight : 1;
|
|
|
|
bool allowSyntheticStyle : 1;
|
|
|
|
|
2014-07-22 00:02:45 +00:00
|
|
|
// some variant features require fallback which complicates the shaping
|
|
|
|
// code, so set up a bool to indicate when shaping with fallback is needed
|
|
|
|
bool noFallbackVariantFeatures : 1;
|
|
|
|
|
2014-12-23 12:50:10 +00:00
|
|
|
// whether the |language| field comes from explicit lang tagging in the
|
|
|
|
// document, or was inferred from charset/system locale
|
|
|
|
bool explicitLanguage : 1;
|
|
|
|
|
2014-06-23 03:09:16 +00:00
|
|
|
// caps variant (small-caps, petite-caps, etc.)
|
|
|
|
uint8_t variantCaps;
|
2010-07-13 20:31:31 +00:00
|
|
|
|
2014-07-22 00:02:45 +00:00
|
|
|
// sub/superscript variant
|
|
|
|
uint8_t variantSubSuper;
|
|
|
|
|
2007-06-08 08:22:03 +00:00
|
|
|
// Return the final adjusted font size for the given aspect ratio.
|
2015-04-21 06:10:40 +00:00
|
|
|
// Not meant to be called when sizeAdjust = -1.0.
|
2007-06-08 08:22:03 +00:00
|
|
|
gfxFloat GetAdjustedSize(gfxFloat aspect) const {
|
2015-04-21 06:10:40 +00:00
|
|
|
NS_ASSERTION(sizeAdjust >= 0.0, "Not meant to be called when sizeAdjust = -1.0");
|
2013-01-15 12:22:03 +00:00
|
|
|
gfxFloat adjustedSize = std::max(NS_round(size*(sizeAdjust/aspect)), 1.0);
|
|
|
|
return std::min(adjustedSize, FONT_MAX_SIZE);
|
2007-06-08 08:22:03 +00:00
|
|
|
}
|
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
PLDHashNumber Hash() const {
|
2011-03-03 21:18:42 +00:00
|
|
|
return ((style + (systemFont << 7) +
|
2012-08-22 15:56:38 +00:00
|
|
|
(weight << 8)) + uint32_t(size*1000) + uint32_t(sizeAdjust*1000)) ^
|
2010-02-24 17:57:57 +00:00
|
|
|
nsISupportsHashKey::HashKey(language);
|
2007-04-04 03:32:43 +00:00
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int8_t ComputeWeight() const;
|
2006-10-14 05:37:40 +00:00
|
|
|
|
2014-07-11 21:37:27 +00:00
|
|
|
// Adjust this style to simulate sub/superscript (as requested in the
|
|
|
|
// variantSubSuper field) using size and baselineOffset instead.
|
|
|
|
void AdjustForSubSuperscript(int32_t aAppUnitsPerDevPixel);
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool Equals(const gfxFontStyle& other) const {
|
2012-10-22 13:53:31 +00:00
|
|
|
return
|
|
|
|
(*reinterpret_cast<const uint64_t*>(&size) ==
|
|
|
|
*reinterpret_cast<const uint64_t*>(&other.size)) &&
|
2006-10-14 05:37:40 +00:00
|
|
|
(style == other.style) &&
|
2014-06-23 03:09:16 +00:00
|
|
|
(variantCaps == other.variantCaps) &&
|
2014-07-22 00:02:45 +00:00
|
|
|
(variantSubSuper == other.variantSubSuper) &&
|
2014-06-19 07:08:55 +00:00
|
|
|
(allowSyntheticWeight == other.allowSyntheticWeight) &&
|
|
|
|
(allowSyntheticStyle == other.allowSyntheticStyle) &&
|
2006-10-14 05:37:40 +00:00
|
|
|
(systemFont == other.systemFont) &&
|
2008-12-17 03:17:50 +00:00
|
|
|
(printerFont == other.printerFont) &&
|
2013-07-29 20:00:41 +00:00
|
|
|
(useGrayscaleAntialiasing == other.useGrayscaleAntialiasing) &&
|
2014-12-23 12:50:10 +00:00
|
|
|
(explicitLanguage == other.explicitLanguage) &&
|
2006-10-14 05:37:40 +00:00
|
|
|
(weight == other.weight) &&
|
2009-01-29 20:39:18 +00:00
|
|
|
(stretch == other.stretch) &&
|
2010-02-24 17:57:57 +00:00
|
|
|
(language == other.language) &&
|
2014-07-22 00:02:45 +00:00
|
|
|
(baselineOffset == other.baselineOffset) &&
|
2012-10-22 13:53:31 +00:00
|
|
|
(*reinterpret_cast<const uint32_t*>(&sizeAdjust) ==
|
|
|
|
*reinterpret_cast<const uint32_t*>(&other.sizeAdjust)) &&
|
2010-12-09 11:52:03 +00:00
|
|
|
(featureSettings == other.featureSettings) &&
|
2013-05-20 02:59:20 +00:00
|
|
|
(languageOverride == other.languageOverride) &&
|
|
|
|
(alternateValues == other.alternateValues) &&
|
|
|
|
(featureValueLookup == other.featureValueLookup);
|
2006-10-14 05:37:40 +00:00
|
|
|
}
|
2010-07-13 20:31:31 +00:00
|
|
|
|
|
|
|
static void ParseFontFeatureSettings(const nsString& aFeatureString,
|
|
|
|
nsTArray<gfxFontFeature>& aFeatures);
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static uint32_t ParseFontLanguageOverride(const nsString& aLangTag);
|
2005-10-08 05:09:42 +00:00
|
|
|
};
|
|
|
|
|
2008-08-06 04:34:06 +00:00
|
|
|
struct gfxTextRange {
|
2011-06-16 06:31:37 +00:00
|
|
|
enum {
|
|
|
|
// flags for recording the kind of font-matching that was used
|
|
|
|
kFontGroup = 0x0001,
|
|
|
|
kPrefsFallback = 0x0002,
|
|
|
|
kSystemFallback = 0x0004
|
|
|
|
};
|
2012-08-22 15:56:38 +00:00
|
|
|
gfxTextRange(uint32_t aStart, uint32_t aEnd,
|
2014-09-16 11:25:45 +00:00
|
|
|
gfxFont* aFont, uint8_t aMatchType,
|
|
|
|
uint16_t aOrientation)
|
2011-06-16 06:31:37 +00:00
|
|
|
: start(aStart),
|
|
|
|
end(aEnd),
|
|
|
|
font(aFont),
|
2014-09-16 11:25:45 +00:00
|
|
|
matchType(aMatchType),
|
|
|
|
orientation(aOrientation)
|
2011-06-16 06:31:37 +00:00
|
|
|
{ }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t Length() const { return end - start; }
|
|
|
|
uint32_t start, end;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxFont> font;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t matchType;
|
2014-09-16 11:25:45 +00:00
|
|
|
uint16_t orientation;
|
2008-08-06 04:34:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
/**
|
|
|
|
* Font cache design:
|
|
|
|
*
|
2010-07-13 20:31:31 +00:00
|
|
|
* The mFonts hashtable contains most fonts, indexed by (gfxFontEntry*, style).
|
2007-04-04 03:32:43 +00: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.
|
2012-01-05 11:54:45 +00:00
|
|
|
*
|
|
|
|
* The font cache also handles timed expiration of cached ShapedWords
|
|
|
|
* for "persistent" fonts: it has a repeating timer, and notifies
|
|
|
|
* each cached font to "age" its shaped words. The words will be released
|
|
|
|
* by the fonts if they get aged three times without being re-used in the
|
|
|
|
* meantime.
|
|
|
|
*
|
|
|
|
* Note that the ShapedWord timeout is much larger than the font timeout,
|
|
|
|
* so that in the case of a short-lived font, we'll discard the gfxFont
|
|
|
|
* completely, with all its words, and avoid the cost of aging the words
|
|
|
|
* individually. That only happens with longer-lived fonts.
|
2007-04-04 03:32:43 +00:00
|
|
|
*/
|
2012-03-23 12:14:16 +00:00
|
|
|
struct FontCacheSizes {
|
|
|
|
FontCacheSizes()
|
|
|
|
: mFontInstances(0), mShapedWords(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
size_t mFontInstances; // memory used by instances of gfxFont subclasses
|
|
|
|
size_t mShapedWords; // memory used by the per-font shapedWord caches
|
|
|
|
};
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
class gfxFontCache final : public nsExpirationTracker<gfxFont,3> {
|
2007-04-04 03:32:43 +00:00
|
|
|
public:
|
2012-01-05 11:54:45 +00:00
|
|
|
enum {
|
|
|
|
FONT_TIMEOUT_SECONDS = 10,
|
|
|
|
SHAPED_WORD_TIMEOUT_SECONDS = 60
|
|
|
|
};
|
|
|
|
|
|
|
|
gfxFontCache();
|
|
|
|
~gfxFontCache();
|
2007-04-04 03:32:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2014-11-06 04:42:50 +00:00
|
|
|
already_AddRefed<gfxFont>
|
|
|
|
Lookup(const gfxFontEntry* aFontEntry,
|
|
|
|
const gfxFontStyle* aStyle,
|
|
|
|
const gfxCharacterMap* aUnicodeRangeMap = nullptr);
|
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
// 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.
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void NotifyExpired(gfxFont *aFont) override;
|
2007-04-04 03:32:43 +00:00
|
|
|
|
2010-06-09 00:33:13 +00: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();
|
|
|
|
}
|
|
|
|
|
2015-07-14 02:08:16 +00:00
|
|
|
void FlushShapedWordCaches();
|
2012-01-13 11:37:46 +00:00
|
|
|
|
2013-10-15 02:19:47 +00:00
|
|
|
void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
|
|
|
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
2012-03-23 12:14:16 +00:00
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
protected:
|
2015-03-21 16:28:04 +00:00
|
|
|
class MemoryReporter final : public nsIMemoryReporter
|
2012-03-23 12:14:16 +00:00
|
|
|
{
|
2014-06-23 18:49:07 +00:00
|
|
|
~MemoryReporter() {}
|
2012-03-23 12:14:16 +00:00
|
|
|
public:
|
2013-12-08 05:39:47 +00:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2012-03-23 12:14:16 +00:00
|
|
|
};
|
|
|
|
|
2013-05-22 15:48:55 +00:00
|
|
|
// Observer for notifications that the font cache cares about
|
2015-03-21 16:28:04 +00:00
|
|
|
class Observer final
|
2013-05-22 15:48:55 +00:00
|
|
|
: public nsIObserver
|
|
|
|
{
|
2014-06-23 18:49:07 +00:00
|
|
|
~Observer() {}
|
2013-05-22 15:48:55 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIOBSERVER
|
|
|
|
};
|
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
void DestroyFont(gfxFont *aFont);
|
|
|
|
|
|
|
|
static gfxFontCache *gGlobalCache;
|
|
|
|
|
|
|
|
struct Key {
|
2010-07-13 20:31:31 +00:00
|
|
|
const gfxFontEntry* mFontEntry;
|
2007-04-04 03:32:43 +00:00
|
|
|
const gfxFontStyle* mStyle;
|
2014-11-06 04:42:50 +00:00
|
|
|
const gfxCharacterMap* mUnicodeRangeMap;
|
|
|
|
Key(const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle,
|
|
|
|
const gfxCharacterMap* aUnicodeRangeMap)
|
|
|
|
: mFontEntry(aFontEntry), mStyle(aStyle),
|
|
|
|
mUnicodeRangeMap(aUnicodeRangeMap)
|
|
|
|
{}
|
2007-04-04 03:32:43 +00: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.
|
2014-08-05 21:58:40 +00:00
|
|
|
explicit HashEntry(KeyTypePointer aStr) : mFont(nullptr) { }
|
2007-04-04 03:32:43 +00:00
|
|
|
HashEntry(const HashEntry& toCopy) : mFont(toCopy.mFont) { }
|
|
|
|
~HashEntry() { }
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2007-04-04 03:32:43 +00:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
2014-11-06 04:42:50 +00:00
|
|
|
return mozilla::HashGeneric(aKey->mStyle->Hash(), aKey->mFontEntry,
|
|
|
|
aKey->mUnicodeRangeMap);
|
2007-04-04 03:32:43 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2007-04-04 03:32:43 +00:00
|
|
|
gfxFont* mFont;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsTHashtable<HashEntry> mFonts;
|
2012-01-05 11:54:45 +00:00
|
|
|
|
|
|
|
static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache);
|
|
|
|
nsCOMPtr<nsITimer> mWordCacheExpirationTimer;
|
2007-04-04 03:32:43 +00:00
|
|
|
};
|
2005-10-08 05:09:42 +00:00
|
|
|
|
2013-11-25 04:59:56 +00:00
|
|
|
class gfxTextPerfMetrics {
|
|
|
|
public:
|
|
|
|
|
|
|
|
struct TextCounts {
|
|
|
|
uint32_t numContentTextRuns;
|
|
|
|
uint32_t numChromeTextRuns;
|
|
|
|
uint32_t numChars;
|
|
|
|
uint32_t maxTextRunLen;
|
|
|
|
uint32_t wordCacheSpaceRules;
|
|
|
|
uint32_t wordCacheLong;
|
|
|
|
uint32_t wordCacheHit;
|
|
|
|
uint32_t wordCacheMiss;
|
|
|
|
uint32_t fallbackPrefs;
|
|
|
|
uint32_t fallbackSystem;
|
|
|
|
uint32_t textrunConst;
|
|
|
|
uint32_t textrunDestr;
|
2015-09-29 01:51:28 +00:00
|
|
|
uint32_t genericLookups;
|
2013-11-25 04:59:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
uint32_t reflowCount;
|
|
|
|
|
|
|
|
// counts per reflow operation
|
|
|
|
TextCounts current;
|
|
|
|
|
|
|
|
// totals for the lifetime of a document
|
|
|
|
TextCounts cumulative;
|
|
|
|
|
|
|
|
gfxTextPerfMetrics() {
|
|
|
|
memset(this, 0, sizeof(gfxTextPerfMetrics));
|
|
|
|
}
|
|
|
|
|
|
|
|
// add current totals to cumulative ones
|
|
|
|
void Accumulate() {
|
|
|
|
if (current.numChars == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
cumulative.numContentTextRuns += current.numContentTextRuns;
|
|
|
|
cumulative.numChromeTextRuns += current.numChromeTextRuns;
|
|
|
|
cumulative.numChars += current.numChars;
|
|
|
|
if (current.maxTextRunLen > cumulative.maxTextRunLen) {
|
|
|
|
cumulative.maxTextRunLen = current.maxTextRunLen;
|
|
|
|
}
|
|
|
|
cumulative.wordCacheSpaceRules += current.wordCacheSpaceRules;
|
|
|
|
cumulative.wordCacheLong += current.wordCacheLong;
|
|
|
|
cumulative.wordCacheHit += current.wordCacheHit;
|
|
|
|
cumulative.wordCacheMiss += current.wordCacheMiss;
|
|
|
|
cumulative.fallbackPrefs += current.fallbackPrefs;
|
|
|
|
cumulative.fallbackSystem += current.fallbackSystem;
|
|
|
|
cumulative.textrunConst += current.textrunConst;
|
|
|
|
cumulative.textrunDestr += current.textrunDestr;
|
2015-09-29 01:51:28 +00:00
|
|
|
cumulative.genericLookups += current.genericLookups;
|
2013-11-25 04:59:56 +00:00
|
|
|
memset(¤t, 0, sizeof(current));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-05-29 21:59:24 +00:00
|
|
|
class gfxTextRunFactory {
|
2011-12-06 12:39:19 +00:00
|
|
|
NS_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 {
|
|
|
|
CACHE_TEXT_FLAGS = 0xF0000000,
|
|
|
|
USER_TEXT_FLAGS = 0x0FFF0000,
|
2014-09-16 11:25:45 +00:00
|
|
|
TEXTRUN_TEXT_FLAGS = 0x0000FFFF,
|
2011-12-06 12:39:19 +00:00
|
|
|
SETTABLE_FLAGS = CACHE_TEXT_FLAGS | USER_TEXT_FLAGS,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
TEXT_ENABLE_HYPHEN_BREAKS = 0x0010,
|
|
|
|
/**
|
|
|
|
* When set, the text has no characters above 255 and it is stored
|
|
|
|
* in the textrun in 8-bit format.
|
|
|
|
*/
|
|
|
|
TEXT_IS_8BIT = 0x0020,
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
TEXT_NEED_BOUNDING_BOX = 0x0040,
|
|
|
|
/**
|
|
|
|
* When set, optional ligatures are disabled. Ligatures that are
|
|
|
|
* required for legible text should still be enabled.
|
|
|
|
*/
|
|
|
|
TEXT_DISABLE_OPTIONAL_LIGATURES = 0x0080,
|
|
|
|
/**
|
|
|
|
* When set, the textrun should favour speed of construction over
|
|
|
|
* quality. This may involve disabling ligatures and/or kerning or
|
|
|
|
* other effects.
|
|
|
|
*/
|
|
|
|
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,
|
2014-02-05 10:08:58 +00:00
|
|
|
/**
|
|
|
|
* When set, the textrun should discard control characters instead of
|
|
|
|
* turning them into hexboxes.
|
|
|
|
*/
|
|
|
|
TEXT_HIDE_CONTROL_CHARACTERS = 0x0400,
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-09-16 11:25:45 +00:00
|
|
|
/**
|
|
|
|
* Field for orientation of the textrun and glyphs within it.
|
|
|
|
* Possible values of the TEXT_ORIENT_MASK field:
|
|
|
|
* TEXT_ORIENT_HORIZONTAL
|
|
|
|
* TEXT_ORIENT_VERTICAL_UPRIGHT
|
|
|
|
* TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT
|
|
|
|
* TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT
|
|
|
|
* TEXT_ORIENT_VERTICAL_MIXED
|
|
|
|
* For all VERTICAL settings, the x and y coordinates of glyph
|
|
|
|
* positions are exchanged, so that simple advances are vertical.
|
|
|
|
*
|
|
|
|
* The MIXED value indicates vertical textRuns for which the CSS
|
|
|
|
* text-orientation property is 'mixed', but is never used for
|
|
|
|
* individual glyphRuns; it will be resolved to either UPRIGHT
|
|
|
|
* or SIDEWAYS_RIGHT according to the UTR50 properties of the
|
|
|
|
* characters, and separate glyphRuns created for the resulting
|
|
|
|
* glyph orientations.
|
|
|
|
*/
|
|
|
|
TEXT_ORIENT_MASK = 0xF000,
|
|
|
|
TEXT_ORIENT_HORIZONTAL = 0x0000,
|
|
|
|
TEXT_ORIENT_VERTICAL_UPRIGHT = 0x1000,
|
|
|
|
TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT = 0x2000,
|
|
|
|
TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT = 0x4000,
|
|
|
|
TEXT_ORIENT_VERTICAL_MIXED = 0x8000,
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
/**
|
|
|
|
* nsTextFrameThebes sets these, but they're defined here rather than
|
|
|
|
* in nsTextFrameUtils.h because ShapedWord creation/caching also needs
|
|
|
|
* to check the _INCOMING flag
|
|
|
|
*/
|
|
|
|
TEXT_TRAILING_ARABICCHAR = 0x20000000,
|
|
|
|
/**
|
|
|
|
* When set, the previous character for this textrun was an Arabic
|
|
|
|
* character. This is used for the context detection necessary for
|
|
|
|
* bidi.numeral implementation.
|
|
|
|
*/
|
|
|
|
TEXT_INCOMING_ARABICCHAR = 0x40000000,
|
|
|
|
|
2014-01-30 15:59:16 +00:00
|
|
|
// Set if the textrun should use the OpenType 'math' script.
|
|
|
|
TEXT_USE_MATH_SCRIPT = 0x80000000,
|
|
|
|
|
|
|
|
TEXT_UNUSED_FLAGS = 0x10000000
|
2011-12-06 12:39:19 +00: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.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t *mInitialBreaks;
|
|
|
|
uint32_t mInitialBreakCount;
|
2011-12-06 12:39:19 +00:00
|
|
|
// The ratio to use to convert device pixels to application layout units
|
2013-01-28 19:01:59 +00:00
|
|
|
int32_t mAppUnitsPerDevUnit;
|
2011-12-06 12:39:19 +00:00
|
|
|
};
|
|
|
|
|
2014-04-04 16:27:02 +00:00
|
|
|
protected:
|
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2011-12-06 12:39:19 +00:00
|
|
|
virtual ~gfxTextRunFactory() {}
|
|
|
|
};
|
|
|
|
|
2010-03-10 12:46:41 +00: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:
|
2014-08-05 21:58:40 +00:00
|
|
|
explicit gfxFontShaper(gfxFont *aFont)
|
2009-10-07 17:16:52 +00:00
|
|
|
: mFont(aFont)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aFont, "shaper requires a valid font!");
|
|
|
|
}
|
2010-03-10 12:46:41 +00:00
|
|
|
|
|
|
|
virtual ~gfxFontShaper() { }
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
// Shape a piece of text and store the resulting glyph data into
|
|
|
|
// aShapedText. Parameters aOffset/aLength indicate the range of
|
|
|
|
// aShapedText to be updated; aLength is also the length of aText.
|
2014-05-31 07:12:40 +00:00
|
|
|
virtual bool ShapeText(gfxContext *aContext,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *aText,
|
2014-05-31 07:12:40 +00:00
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-05-31 07:12:40 +00:00
|
|
|
gfxShapedText *aShapedText) = 0;
|
2010-03-10 12:46:41 +00:00
|
|
|
|
2009-10-07 17:16:52 +00:00
|
|
|
gfxFont *GetFont() const { return mFont; }
|
|
|
|
|
2015-01-22 06:41:02 +00:00
|
|
|
static void
|
2013-05-20 02:59:20 +00:00
|
|
|
MergeFontFeatures(const gfxFontStyle *aStyle,
|
2012-04-26 06:26:03 +00:00
|
|
|
const nsTArray<gfxFontFeature>& aFontFeatures,
|
|
|
|
bool aDisableLigatures,
|
2013-05-20 02:59:20 +00:00
|
|
|
const nsAString& aFamilyName,
|
2014-06-23 03:09:16 +00:00
|
|
|
bool aAddSmallCaps,
|
2015-09-24 15:31:30 +00:00
|
|
|
void (*aHandleFeature)(const uint32_t&,
|
|
|
|
uint32_t&, void*),
|
2015-01-22 06:41:02 +00:00
|
|
|
void* aHandleFeatureData);
|
2012-04-26 06:26:03 +00:00
|
|
|
|
2010-03-10 12:46:41 +00:00
|
|
|
protected:
|
2015-05-25 15:32:00 +00:00
|
|
|
// the font this shaper is working with. The font owns a nsAutoPtr reference
|
|
|
|
// to this object, and will destroy it before it dies. Thus, mFont will always
|
|
|
|
// be valid.
|
|
|
|
gfxFont* MOZ_NON_OWNING_REF mFont;
|
2010-03-10 12:46:41 +00:00
|
|
|
};
|
|
|
|
|
2014-07-25 08:38:44 +00:00
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
/*
|
2013-01-04 18:35:37 +00:00
|
|
|
* gfxShapedText is an abstract superclass for gfxShapedWord and gfxTextRun.
|
|
|
|
* These are objects that store a list of zero or more glyphs for each character.
|
|
|
|
* For each glyph we store the glyph ID, the advance, and possibly x/y-offsets.
|
2011-12-06 12:39:19 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2013-01-04 18:35:37 +00:00
|
|
|
* gfxFontShaper can shape text into either a gfxShapedWord (cached by a gfxFont)
|
|
|
|
* or directly into a gfxTextRun (for cases where we want to shape textruns in
|
|
|
|
* their entirety rather than using cached words, because there may be layout
|
|
|
|
* features that depend on the inter-word spaces).
|
2011-12-06 12:39:19 +00:00
|
|
|
*/
|
2013-01-04 18:35:37 +00:00
|
|
|
class gfxShapedText
|
2011-12-06 12:39:19 +00:00
|
|
|
{
|
2007-01-23 08:45:52 +00:00
|
|
|
public:
|
2013-01-04 18:35:37 +00:00
|
|
|
gfxShapedText(uint32_t aLength, uint32_t aFlags,
|
2013-01-28 19:01:59 +00:00
|
|
|
int32_t aAppUnitsPerDevUnit)
|
2013-01-04 18:35:37 +00:00
|
|
|
: mLength(aLength)
|
|
|
|
, mFlags(aFlags)
|
|
|
|
, mAppUnitsPerDevUnit(aAppUnitsPerDevUnit)
|
|
|
|
{ }
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
virtual ~gfxShapedText() { }
|
2006-10-14 05:37:40 +00:00
|
|
|
|
2007-01-23 08:45:52 +00:00
|
|
|
/**
|
2011-12-06 12:39:19 +00: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.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
class CompressedGlyph {
|
|
|
|
public:
|
|
|
|
CompressedGlyph() { mValue = 0; }
|
|
|
|
|
|
|
|
enum {
|
|
|
|
// 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-12-06 12:39:19 +00:00
|
|
|
// is one that fits in the available bits (currently 12) (specified
|
2011-12-06 12:39:19 +00:00
|
|
|
// in appunits).
|
|
|
|
FLAG_IS_SIMPLE_GLYPH = 0x80000000U,
|
|
|
|
|
|
|
|
// 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,
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
FLAG_CHAR_IS_SPACE = 0x10000000U,
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
// The advance is stored in appunits
|
2011-12-06 12:39:19 +00:00
|
|
|
ADVANCE_MASK = 0x0FFF0000U,
|
2011-12-06 12:39:19 +00:00
|
|
|
ADVANCE_SHIFT = 16,
|
|
|
|
|
|
|
|
GLYPH_MASK = 0x0000FFFFU,
|
|
|
|
|
|
|
|
// 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,
|
2011-12-06 12:39:19 +00:00
|
|
|
|
|
|
|
FLAG_CHAR_IS_TAB = 0x08,
|
|
|
|
FLAG_CHAR_IS_NEWLINE = 0x10,
|
2015-10-26 10:47:16 +00:00
|
|
|
CHAR_IDENTITY_FLAGS_MASK = 0x18,
|
2012-04-16 12:54:50 +00:00
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
GLYPH_COUNT_MASK = 0x00FFFF00U,
|
|
|
|
GLYPH_COUNT_SHIFT = 8
|
|
|
|
};
|
|
|
|
|
|
|
|
// "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
|
2012-08-22 15:56:38 +00:00
|
|
|
static bool IsSimpleGlyphID(uint32_t aGlyph) {
|
2011-12-06 12:39:19 +00:00
|
|
|
return (aGlyph & GLYPH_MASK) == aGlyph;
|
|
|
|
}
|
|
|
|
// Returns true if the advance aAdvance fits into the compressed representation.
|
|
|
|
// aAdvance is in appunits.
|
2012-08-22 15:56:38 +00:00
|
|
|
static bool IsSimpleAdvance(uint32_t aAdvance) {
|
2011-12-06 12:39:19 +00:00
|
|
|
return (aAdvance & (ADVANCE_MASK >> ADVANCE_SHIFT)) == aAdvance;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsSimpleGlyph() const { return (mValue & FLAG_IS_SIMPLE_GLYPH) != 0; }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetSimpleAdvance() const { return (mValue & ADVANCE_MASK) >> ADVANCE_SHIFT; }
|
|
|
|
uint32_t GetSimpleGlyph() const { return mValue & GLYPH_MASK; }
|
2011-12-06 12:39:19 +00:00
|
|
|
|
|
|
|
bool IsMissing() const { return (mValue & (FLAG_NOT_MISSING|FLAG_IS_SIMPLE_GLYPH)) == 0; }
|
|
|
|
bool IsClusterStart() const {
|
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) || !(mValue & FLAG_NOT_CLUSTER_START);
|
|
|
|
}
|
|
|
|
bool IsLigatureGroupStart() const {
|
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) || !(mValue & FLAG_NOT_LIGATURE_GROUP_START);
|
|
|
|
}
|
|
|
|
bool IsLigatureContinuation() const {
|
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) == 0 &&
|
|
|
|
(mValue & (FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING)) ==
|
|
|
|
(FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING);
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
// Return true if the original character was a normal (breakable,
|
|
|
|
// trimmable) space (U+0020). Not true for other characters that
|
|
|
|
// may happen to map to the space glyph (U+00A0).
|
|
|
|
bool CharIsSpace() const {
|
|
|
|
return (mValue & FLAG_CHAR_IS_SPACE) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CharIsTab() const {
|
|
|
|
return !IsSimpleGlyph() && (mValue & FLAG_CHAR_IS_TAB) != 0;
|
|
|
|
}
|
|
|
|
bool CharIsNewline() const {
|
|
|
|
return !IsSimpleGlyph() && (mValue & FLAG_CHAR_IS_NEWLINE) != 0;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t CharIdentityFlags() const {
|
2012-04-16 12:54:50 +00:00
|
|
|
return IsSimpleGlyph() ? 0 : (mValue & CHAR_IDENTITY_FLAGS_MASK);
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
void SetClusterStart(bool aIsClusterStart) {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(),
|
|
|
|
"can't call SetClusterStart on simple glyphs");
|
|
|
|
if (aIsClusterStart) {
|
|
|
|
mValue &= ~FLAG_NOT_CLUSTER_START;
|
|
|
|
} else {
|
|
|
|
mValue |= FLAG_NOT_CLUSTER_START;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint8_t CanBreakBefore() const {
|
2011-12-06 12:39:19 +00:00
|
|
|
return (mValue & FLAGS_CAN_BREAK_BEFORE) >> FLAGS_CAN_BREAK_SHIFT;
|
|
|
|
}
|
|
|
|
// Returns FLAGS_CAN_BREAK_BEFORE if the setting changed, 0 otherwise
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t SetCanBreakBefore(uint8_t aCanBreakBefore) {
|
2011-12-06 12:39:19 +00:00
|
|
|
NS_ASSERTION(aCanBreakBefore <= 2,
|
|
|
|
"Bogus break-before value!");
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t breakMask = (uint32_t(aCanBreakBefore) << FLAGS_CAN_BREAK_SHIFT);
|
|
|
|
uint32_t toggle = breakMask ^ (mValue & FLAGS_CAN_BREAK_BEFORE);
|
2011-12-06 12:39:19 +00:00
|
|
|
mValue ^= toggle;
|
|
|
|
return toggle;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
CompressedGlyph& SetSimpleGlyph(uint32_t aAdvanceAppUnits, uint32_t aGlyph) {
|
2011-12-06 12:39:19 +00:00
|
|
|
NS_ASSERTION(IsSimpleAdvance(aAdvanceAppUnits), "Advance overflow");
|
|
|
|
NS_ASSERTION(IsSimpleGlyphID(aGlyph), "Glyph overflow");
|
2012-04-16 12:54:50 +00:00
|
|
|
NS_ASSERTION(!CharIdentityFlags(), "Char identity flags lost");
|
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
|
2011-12-06 12:39:19 +00:00
|
|
|
FLAG_IS_SIMPLE_GLYPH |
|
|
|
|
(aAdvanceAppUnits << ADVANCE_SHIFT) | aGlyph;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
CompressedGlyph& SetComplex(bool aClusterStart, bool aLigatureStart,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t aGlyphCount) {
|
2012-04-16 12:54:50 +00:00
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
|
2011-12-06 12:39:19 +00:00
|
|
|
FLAG_NOT_MISSING |
|
2012-04-16 12:54:50 +00:00
|
|
|
CharIdentityFlags() |
|
2011-12-06 12:39:19 +00:00
|
|
|
(aClusterStart ? 0 : FLAG_NOT_CLUSTER_START) |
|
|
|
|
(aLigatureStart ? 0 : FLAG_NOT_LIGATURE_GROUP_START) |
|
|
|
|
(aGlyphCount << GLYPH_COUNT_SHIFT);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Missing glyphs are treated as ligature group starts; don't mess with
|
|
|
|
* the cluster-start flag (see bugs 618870 and 619286).
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
CompressedGlyph& SetMissing(uint32_t aGlyphCount) {
|
2012-04-16 12:54:50 +00:00
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_NOT_CLUSTER_START |
|
|
|
|
FLAG_CHAR_IS_SPACE)) |
|
|
|
|
CharIdentityFlags() |
|
2011-12-06 12:39:19 +00:00
|
|
|
(aGlyphCount << GLYPH_COUNT_SHIFT);
|
|
|
|
return *this;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t GetGlyphCount() const {
|
2011-12-06 12:39:19 +00:00
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
return (mValue & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
void SetIsSpace() {
|
|
|
|
mValue |= FLAG_CHAR_IS_SPACE;
|
|
|
|
}
|
|
|
|
void SetIsTab() {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
mValue |= FLAG_CHAR_IS_TAB;
|
|
|
|
}
|
|
|
|
void SetIsNewline() {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
mValue |= FLAG_CHAR_IS_NEWLINE;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
private:
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mValue;
|
2011-12-06 12:39:19 +00:00
|
|
|
};
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
// Accessor for the array of CompressedGlyph records, which will be in
|
|
|
|
// a different place in gfxShapedWord vs gfxTextRun
|
|
|
|
virtual CompressedGlyph *GetCharacterGlyphs() = 0;
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
/**
|
|
|
|
* 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 {
|
|
|
|
/** The glyphID, or the Unicode character
|
|
|
|
* if this is a missing glyph */
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mGlyphID;
|
2011-12-06 12:39:19 +00: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 top to bottom */
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t mAdvance;
|
2011-12-06 12:39:19 +00:00
|
|
|
float mXOffset, mYOffset;
|
|
|
|
};
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
void SetGlyphs(uint32_t aCharIndex, CompressedGlyph aGlyph,
|
|
|
|
const DetailedGlyph *aGlyphs);
|
|
|
|
|
|
|
|
void SetMissingGlyph(uint32_t aIndex, uint32_t aChar, gfxFont *aFont);
|
|
|
|
|
|
|
|
void SetIsSpace(uint32_t aIndex) {
|
|
|
|
GetCharacterGlyphs()[aIndex].SetIsSpace();
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
bool HasDetailedGlyphs() const {
|
|
|
|
return mDetailedGlyphs != nullptr;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
bool IsLigatureGroupStart(uint32_t aPos) {
|
|
|
|
NS_ASSERTION(aPos < GetLength(), "aPos out of range");
|
|
|
|
return GetCharacterGlyphs()[aPos].IsLigatureGroupStart();
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
// NOTE that this must not be called for a character offset that does
|
|
|
|
// not have any DetailedGlyph records; callers must have verified that
|
|
|
|
// GetCharacterGlyphs()[aCharIndex].GetGlyphCount() is greater than zero.
|
|
|
|
DetailedGlyph *GetDetailedGlyphs(uint32_t aCharIndex) {
|
|
|
|
NS_ASSERTION(GetCharacterGlyphs() && HasDetailedGlyphs() &&
|
|
|
|
!GetCharacterGlyphs()[aCharIndex].IsSimpleGlyph() &&
|
|
|
|
GetCharacterGlyphs()[aCharIndex].GetGlyphCount() > 0,
|
|
|
|
"invalid use of GetDetailedGlyphs; check the caller!");
|
|
|
|
return mDetailedGlyphs->Get(aCharIndex);
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
void AdjustAdvancesForSyntheticBold(float aSynBoldOffset,
|
|
|
|
uint32_t aOffset, uint32_t aLength);
|
|
|
|
|
|
|
|
// Mark clusters in the CompressedGlyph records, starting at aOffset,
|
|
|
|
// based on the Unicode properties of the text in aString.
|
|
|
|
// This is also responsible to set the IsSpace flag for space characters.
|
|
|
|
void SetupClusterBoundaries(uint32_t aOffset,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *aString,
|
2013-01-04 18:35:37 +00:00
|
|
|
uint32_t aLength);
|
|
|
|
// In 8-bit text, there won't actually be any clusters, but we still need
|
|
|
|
// the space-marking functionality.
|
|
|
|
void SetupClusterBoundaries(uint32_t aOffset,
|
|
|
|
const uint8_t *aString,
|
|
|
|
uint32_t aLength);
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
uint32_t GetFlags() const {
|
2011-12-06 12:39:19 +00:00
|
|
|
return mFlags;
|
|
|
|
}
|
|
|
|
|
2014-09-16 11:25:45 +00:00
|
|
|
bool IsVertical() const {
|
|
|
|
return (GetFlags() & gfxTextRunFactory::TEXT_ORIENT_MASK) !=
|
|
|
|
gfxTextRunFactory::TEXT_ORIENT_HORIZONTAL;
|
|
|
|
}
|
|
|
|
|
2014-11-13 08:58:04 +00:00
|
|
|
bool UseCenterBaseline() const {
|
|
|
|
uint32_t orient = GetFlags() & gfxTextRunFactory::TEXT_ORIENT_MASK;
|
|
|
|
return orient == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_MIXED ||
|
|
|
|
orient == gfxTextRunFactory::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
bool IsRightToLeft() const {
|
2014-09-16 09:58:12 +00:00
|
|
|
return (GetFlags() & gfxTextRunFactory::TEXT_IS_RTL) != 0;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2015-09-24 09:23:34 +00:00
|
|
|
bool IsSidewaysLeft() const {
|
|
|
|
return (GetFlags() & gfxTextRunFactory::TEXT_ORIENT_MASK) ==
|
|
|
|
gfxTextRunFactory::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return true if the logical inline direction is reversed compared to
|
|
|
|
// normal physical coordinates (i.e. if it is leftwards or upwards)
|
|
|
|
bool IsInlineReversed() const {
|
|
|
|
return IsSidewaysLeft() != IsRightToLeft();
|
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat GetDirection() const {
|
2015-09-24 09:23:34 +00:00
|
|
|
return IsInlineReversed() ? -1.0f : 1.0f;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
bool DisableLigatures() const {
|
2014-09-16 09:58:12 +00:00
|
|
|
return (GetFlags() &
|
|
|
|
gfxTextRunFactory::TEXT_DISABLE_OPTIONAL_LIGATURES) != 0;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool TextIs8Bit() const {
|
2014-09-16 09:58:12 +00:00
|
|
|
return (GetFlags() & gfxTextRunFactory::TEXT_IS_8BIT) != 0;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-28 19:01:59 +00:00
|
|
|
int32_t GetAppUnitsPerDevUnit() const {
|
2011-12-06 12:39:19 +00:00
|
|
|
return mAppUnitsPerDevUnit;
|
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
uint32_t GetLength() const {
|
|
|
|
return mLength;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
bool FilterIfIgnorable(uint32_t aIndex, uint32_t aCh);
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
protected:
|
2011-12-06 12:39:19 +00:00
|
|
|
// Allocate aCount DetailedGlyphs for the given index
|
2012-08-22 15:56:38 +00:00
|
|
|
DetailedGlyph *AllocateDetailedGlyphs(uint32_t aCharIndex,
|
|
|
|
uint32_t aCount);
|
2011-12-06 12:39:19 +00: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.
|
|
|
|
// 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.
|
2012-08-22 15:56:38 +00:00
|
|
|
DetailedGlyph* Get(uint32_t aOffset) {
|
2011-12-06 12:39:19 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
DetailedGlyph* Allocate(uint32_t aOffset, uint32_t aCount) {
|
|
|
|
uint32_t detailIndex = mDetails.Length();
|
2011-12-06 12:39:19 +00:00
|
|
|
DetailedGlyph *details = mDetails.AppendElements(aCount);
|
|
|
|
// 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 ||
|
|
|
|
aOffset > mOffsetToIndex[mOffsetToIndex.Length() - 1].mOffset) {
|
2014-07-08 13:56:41 +00:00
|
|
|
mOffsetToIndex.AppendElement(DGRec(aOffset, detailIndex));
|
2011-12-06 12:39:19 +00:00
|
|
|
} else {
|
2014-07-08 13:56:41 +00:00
|
|
|
mOffsetToIndex.InsertElementSorted(DGRec(aOffset, detailIndex),
|
|
|
|
CompareRecordOffsets());
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
return details;
|
|
|
|
}
|
|
|
|
|
2013-06-23 12:03:39 +00:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
|
2012-01-25 08:52:51 +00:00
|
|
|
return aMallocSizeOf(this) +
|
2015-07-29 06:24:24 +00:00
|
|
|
mDetails.ShallowSizeOfExcludingThis(aMallocSizeOf) +
|
|
|
|
mOffsetToIndex.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
struct DGRec {
|
2012-08-22 15:56:38 +00:00
|
|
|
DGRec(const uint32_t& aOffset, const uint32_t& aIndex)
|
2011-12-06 12:39:19 +00:00
|
|
|
: mOffset(aOffset), mIndex(aIndex) { }
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mOffset; // source character offset in the textrun
|
|
|
|
uint32_t mIndex; // index where this char's DetailedGlyphs begin
|
2011-12-06 12:39:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CompareToOffset {
|
2012-08-22 15:56:38 +00:00
|
|
|
bool Equals(const DGRec& a, const uint32_t& b) const {
|
2011-12-06 12:39:19 +00:00
|
|
|
return a.mOffset == b;
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
bool LessThan(const DGRec& a, const uint32_t& b) const {
|
2011-12-06 12:39:19 +00:00
|
|
|
return a.mOffset < b;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompareRecordOffsets {
|
|
|
|
bool Equals(const DGRec& a, const DGRec& b) const {
|
|
|
|
return a.mOffset == b.mOffset;
|
|
|
|
}
|
|
|
|
bool LessThan(const DGRec& a, const DGRec& b) const {
|
|
|
|
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;
|
2007-01-23 08:45:52 +00:00
|
|
|
};
|
|
|
|
|
2011-12-06 12:39:19 +00:00
|
|
|
nsAutoPtr<DetailedGlyphStore> mDetailedGlyphs;
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
// Number of char16_t characters and CompressedGlyph glyph records
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mLength;
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
// Shaping flags (direction, ligature-suppression)
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t mFlags;
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2013-01-28 19:01:59 +00:00
|
|
|
int32_t mAppUnitsPerDevUnit;
|
2013-01-04 18:35:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gfxShapedWord: an individual (space-delimited) run of text shaped with a
|
|
|
|
* particular font, without regard to external context.
|
|
|
|
*
|
|
|
|
* The glyph data is copied into gfxTextRuns as needed from the cache of
|
|
|
|
* ShapedWords associated with each gfxFont instance.
|
|
|
|
*/
|
|
|
|
class gfxShapedWord : public gfxShapedText
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Create a ShapedWord that can hold glyphs for aLength characters,
|
|
|
|
// with mCharacterGlyphs sized appropriately.
|
|
|
|
//
|
|
|
|
// Returns null on allocation failure (does NOT use infallible alloc)
|
|
|
|
// so caller must check for success.
|
|
|
|
//
|
|
|
|
// This does NOT perform shaping, so the returned word contains no
|
|
|
|
// glyph data; the caller must call gfxFont::ShapeText() with appropriate
|
|
|
|
// parameters to set up the glyphs.
|
|
|
|
static gfxShapedWord* Create(const uint8_t *aText, uint32_t aLength,
|
|
|
|
int32_t aRunScript,
|
|
|
|
int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags) {
|
2013-09-11 01:36:57 +00:00
|
|
|
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
|
|
|
|
"excessive length for gfxShapedWord!");
|
2013-01-04 18:35:37 +00:00
|
|
|
|
|
|
|
// Compute size needed including the mCharacterGlyphs array
|
|
|
|
// and a copy of the original text
|
|
|
|
uint32_t size =
|
|
|
|
offsetof(gfxShapedWord, mCharGlyphsStorage) +
|
|
|
|
aLength * (sizeof(CompressedGlyph) + sizeof(uint8_t));
|
2015-02-19 04:51:06 +00:00
|
|
|
void *storage = malloc(size);
|
2013-01-04 18:35:37 +00:00
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Construct in the pre-allocated storage, using placement new
|
|
|
|
return new (storage) gfxShapedWord(aText, aLength, aRunScript,
|
|
|
|
aAppUnitsPerDevUnit, aFlags);
|
|
|
|
}
|
|
|
|
|
2014-01-04 15:02:17 +00:00
|
|
|
static gfxShapedWord* Create(const char16_t *aText, uint32_t aLength,
|
2013-01-04 18:35:37 +00:00
|
|
|
int32_t aRunScript,
|
|
|
|
int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags) {
|
2013-09-11 01:36:57 +00:00
|
|
|
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
|
|
|
|
"excessive length for gfxShapedWord!");
|
2013-01-04 18:35:37 +00:00
|
|
|
|
|
|
|
// In the 16-bit version of Create, if the TEXT_IS_8BIT flag is set,
|
|
|
|
// then we convert the text to an 8-bit version and call the 8-bit
|
|
|
|
// Create function instead.
|
|
|
|
if (aFlags & gfxTextRunFactory::TEXT_IS_8BIT) {
|
|
|
|
nsAutoCString narrowText;
|
|
|
|
LossyAppendUTF16toASCII(nsDependentSubstring(aText, aLength),
|
|
|
|
narrowText);
|
|
|
|
return Create((const uint8_t*)(narrowText.BeginReading()),
|
|
|
|
aLength, aRunScript, aAppUnitsPerDevUnit, aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t size =
|
|
|
|
offsetof(gfxShapedWord, mCharGlyphsStorage) +
|
2014-01-04 15:02:17 +00:00
|
|
|
aLength * (sizeof(CompressedGlyph) + sizeof(char16_t));
|
2015-02-19 04:51:06 +00:00
|
|
|
void *storage = malloc(size);
|
2013-01-04 18:35:37 +00:00
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return new (storage) gfxShapedWord(aText, aLength, aRunScript,
|
|
|
|
aAppUnitsPerDevUnit, aFlags);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Override operator delete to properly free the object that was
|
2015-02-19 04:51:06 +00:00
|
|
|
// allocated via malloc.
|
2013-01-04 18:35:37 +00:00
|
|
|
void operator delete(void* p) {
|
2015-02-19 04:51:06 +00:00
|
|
|
free(p);
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual CompressedGlyph *GetCharacterGlyphs() override {
|
2013-01-04 18:35:37 +00:00
|
|
|
return &mCharGlyphsStorage[0];
|
|
|
|
}
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2013-01-04 18:35:37 +00:00
|
|
|
const uint8_t* Text8Bit() const {
|
|
|
|
NS_ASSERTION(TextIs8Bit(), "invalid use of Text8Bit()");
|
|
|
|
return reinterpret_cast<const uint8_t*>(mCharGlyphsStorage + GetLength());
|
|
|
|
}
|
2012-01-05 11:54:45 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
const char16_t* TextUnicode() const {
|
|
|
|
NS_ASSERTION(!TextIs8Bit(), "invalid use of TextUnicode()");
|
|
|
|
return reinterpret_cast<const char16_t*>(mCharGlyphsStorage + GetLength());
|
|
|
|
}
|
|
|
|
|
|
|
|
char16_t GetCharAt(uint32_t aOffset) const {
|
|
|
|
NS_ASSERTION(aOffset < GetLength(), "aOffset out of range");
|
|
|
|
return TextIs8Bit() ?
|
|
|
|
char16_t(Text8Bit()[aOffset]) : TextUnicode()[aOffset];
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t Script() const {
|
|
|
|
return mScript;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ResetAge() {
|
|
|
|
mAgeCounter = 0;
|
|
|
|
}
|
|
|
|
uint32_t IncrementAge() {
|
|
|
|
return ++mAgeCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Helper used when hashing a word for the shaped-word caches
|
|
|
|
static uint32_t HashMix(uint32_t aHash, char16_t aCh)
|
|
|
|
{
|
|
|
|
return (aHash >> 28) ^ (aHash << 4) ^ aCh;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// so that gfxTextRun can share our DetailedGlyphStore class
|
|
|
|
friend class gfxTextRun;
|
|
|
|
|
|
|
|
// Construct storage for a ShapedWord, ready to receive glyph data
|
|
|
|
gfxShapedWord(const uint8_t *aText, uint32_t aLength,
|
|
|
|
int32_t aRunScript, int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: gfxShapedText(aLength, aFlags | gfxTextRunFactory::TEXT_IS_8BIT,
|
|
|
|
aAppUnitsPerDevUnit)
|
|
|
|
, mScript(aRunScript)
|
|
|
|
, mAgeCounter(0)
|
|
|
|
{
|
|
|
|
memset(mCharGlyphsStorage, 0, aLength * sizeof(CompressedGlyph));
|
|
|
|
uint8_t *text = reinterpret_cast<uint8_t*>(&mCharGlyphsStorage[aLength]);
|
|
|
|
memcpy(text, aText, aLength * sizeof(uint8_t));
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxShapedWord(const char16_t *aText, uint32_t aLength,
|
|
|
|
int32_t aRunScript, int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: gfxShapedText(aLength, aFlags, aAppUnitsPerDevUnit)
|
|
|
|
, mScript(aRunScript)
|
|
|
|
, mAgeCounter(0)
|
|
|
|
{
|
|
|
|
memset(mCharGlyphsStorage, 0, aLength * sizeof(CompressedGlyph));
|
|
|
|
char16_t *text = reinterpret_cast<char16_t*>(&mCharGlyphsStorage[aLength]);
|
|
|
|
memcpy(text, aText, aLength * sizeof(char16_t));
|
|
|
|
SetupClusterBoundaries(0, aText, aLength);
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t mScript;
|
|
|
|
|
|
|
|
uint32_t mAgeCounter;
|
|
|
|
|
|
|
|
// The mCharGlyphsStorage array is actually a variable-size member;
|
|
|
|
// when the ShapedWord is created, its size will be increased as necessary
|
|
|
|
// to allow the proper number of glyphs to be stored.
|
|
|
|
// The original text, in either 8-bit or 16-bit form, will be stored
|
|
|
|
// immediately following the CompressedGlyphs.
|
|
|
|
CompressedGlyph mCharGlyphsStorage[1];
|
|
|
|
};
|
|
|
|
|
|
|
|
class GlyphBufferAzure;
|
|
|
|
struct TextRunDrawParams;
|
|
|
|
struct FontDrawParams;
|
|
|
|
|
|
|
|
class gfxFont {
|
|
|
|
|
|
|
|
friend class gfxHarfBuzzShaper;
|
|
|
|
friend class gfxGraphiteShaper;
|
|
|
|
|
2014-11-10 21:41:41 +00:00
|
|
|
protected:
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
public:
|
|
|
|
nsrefcnt AddRef(void) {
|
|
|
|
NS_PRECONDITION(int32_t(mRefCnt) >= 0, "illegal refcnt");
|
|
|
|
if (mExpirationState.IsTracked()) {
|
|
|
|
gfxFontCache::GetCache()->RemoveObject(this);
|
|
|
|
}
|
|
|
|
++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) {
|
|
|
|
NotifyReleased();
|
|
|
|
// |this| may have been deleted.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t GetRefCount() { return mRefCnt; }
|
|
|
|
|
|
|
|
// options to specify the kind of AA to be used when creating a font
|
|
|
|
typedef enum {
|
|
|
|
kAntialiasDefault,
|
|
|
|
kAntialiasNone,
|
|
|
|
kAntialiasGrayscale,
|
|
|
|
kAntialiasSubpixel
|
|
|
|
} AntialiasOption;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
cairo_scaled_font_t *mScaledFont;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gfxFont(gfxFontEntry *aFontEntry, const gfxFontStyle *aFontStyle,
|
|
|
|
AntialiasOption anAAOption = kAntialiasDefault,
|
|
|
|
cairo_scaled_font_t *aScaledFont = nullptr);
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual ~gfxFont();
|
|
|
|
|
|
|
|
bool Valid() const {
|
|
|
|
return mIsValid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
const nsString& GetName() const { return mFontEntry->Name(); }
|
|
|
|
const gfxFontStyle *GetStyle() const { return &mStyle; }
|
|
|
|
|
|
|
|
virtual cairo_scaled_font_t* GetCairoScaledFont() { return mScaledFont; }
|
|
|
|
|
|
|
|
virtual gfxFont* CopyWithAntialiasOption(AntialiasOption anAAOption) {
|
|
|
|
// platforms where this actually matters should override
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual gfxFloat GetAdjustedSize() const {
|
2015-04-21 06:10:40 +00:00
|
|
|
return mAdjustedSize > 0.0
|
|
|
|
? mAdjustedSize
|
|
|
|
: (mStyle.sizeAdjust == 0.0 ? 0.0 : mStyle.size);
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
float FUnitsToDevUnitsFactor() const {
|
|
|
|
// check this was set up during font initialization
|
|
|
|
NS_ASSERTION(mFUnitsConvFactor > 0.0f, "mFUnitsConvFactor not valid");
|
|
|
|
return mFUnitsConvFactor;
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// check whether this is an sfnt we can potentially use with harfbuzz
|
|
|
|
bool FontCanSupportHarfBuzz() {
|
|
|
|
return mFontEntry->HasCmapTable();
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// check whether this is an sfnt we can potentially use with Graphite
|
|
|
|
bool FontCanSupportGraphite() {
|
|
|
|
return mFontEntry->HasGraphiteTables();
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
|
|
|
|
2015-02-02 09:19:28 +00:00
|
|
|
// Whether this is a font that may be doing full-color rendering,
|
|
|
|
// and therefore needs us to use a mask for text-shadow even when
|
|
|
|
// we're not actually blurring.
|
|
|
|
bool AlwaysNeedsMaskForShadow() {
|
|
|
|
return mFontEntry->TryGetColorGlyphs() ||
|
|
|
|
mFontEntry->TryGetSVGData(this) ||
|
|
|
|
mFontEntry->HasFontTable(TRUETYPE_TAG('C','B','D','T')) ||
|
|
|
|
mFontEntry->HasFontTable(TRUETYPE_TAG('s','b','i','x'));
|
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// whether a feature is supported by the font (limited to a small set
|
|
|
|
// of features for which some form of fallback needs to be implemented)
|
|
|
|
bool SupportsFeature(int32_t aScript, uint32_t aFeatureTag);
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// whether the font supports "real" small caps, petite caps etc.
|
|
|
|
// aFallbackToSmallCaps true when petite caps should fallback to small caps
|
|
|
|
bool SupportsVariantCaps(int32_t aScript, uint32_t aVariantCaps,
|
|
|
|
bool& aFallbackToSmallCaps,
|
|
|
|
bool& aSyntheticLowerToSmallCaps,
|
|
|
|
bool& aSyntheticUpperToSmallCaps);
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// whether the font supports subscript/superscript feature
|
|
|
|
// for fallback, need to verify that all characters in the run
|
|
|
|
// have variant substitutions
|
|
|
|
bool SupportsSubSuperscript(uint32_t aSubSuperscript,
|
|
|
|
const uint8_t *aString,
|
|
|
|
uint32_t aLength, int32_t aRunScript);
|
|
|
|
|
|
|
|
bool SupportsSubSuperscript(uint32_t aSubSuperscript,
|
|
|
|
const char16_t *aString,
|
|
|
|
uint32_t aLength, int32_t aRunScript);
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
virtual bool ProvidesGetGlyph() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Map unicode character to glyph ID.
|
|
|
|
// Only used if ProvidesGetGlyph() returns true.
|
|
|
|
virtual uint32_t GetGlyph(uint32_t unicode, uint32_t variation_selector) {
|
|
|
|
return 0;
|
2013-01-04 18:35:37 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
// Return the horizontal advance of a glyph.
|
|
|
|
gfxFloat GetGlyphHAdvance(gfxContext *aCtx, uint16_t aGID);
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Return Azure GlyphRenderingOptions for drawing this font.
|
2015-06-17 14:00:52 +00:00
|
|
|
virtual already_AddRefed<mozilla::gfx::GlyphRenderingOptions>
|
2014-10-24 16:32:23 +00:00
|
|
|
GetGlyphRenderingOptions(const TextRunDrawParams* aRunParams = nullptr)
|
|
|
|
{ return nullptr; }
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat SynthesizeSpaceWidth(uint32_t aCh);
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Font metrics
|
|
|
|
struct Metrics {
|
|
|
|
gfxFloat xHeight;
|
|
|
|
gfxFloat strikeoutSize;
|
|
|
|
gfxFloat strikeoutOffset;
|
|
|
|
gfxFloat underlineSize;
|
|
|
|
gfxFloat underlineOffset;
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat internalLeading;
|
|
|
|
gfxFloat externalLeading;
|
2013-02-11 06:22:20 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat emHeight;
|
|
|
|
gfxFloat emAscent;
|
|
|
|
gfxFloat emDescent;
|
|
|
|
gfxFloat maxHeight;
|
|
|
|
gfxFloat maxAscent;
|
|
|
|
gfxFloat maxDescent;
|
|
|
|
gfxFloat maxAdvance;
|
2013-02-11 06:22:20 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat aveCharWidth;
|
|
|
|
gfxFloat spaceWidth;
|
|
|
|
gfxFloat zeroOrAveCharWidth; // width of '0', or if there is
|
|
|
|
// no '0' glyph in this font,
|
|
|
|
// equal to .aveCharWidth
|
|
|
|
};
|
2014-09-30 06:37:40 +00:00
|
|
|
|
2014-09-30 06:38:26 +00:00
|
|
|
enum Orientation {
|
|
|
|
eHorizontal,
|
|
|
|
eVertical
|
|
|
|
};
|
|
|
|
|
|
|
|
const Metrics& GetMetrics(Orientation aOrientation)
|
2014-09-30 06:37:40 +00:00
|
|
|
{
|
2014-09-30 06:38:26 +00:00
|
|
|
if (aOrientation == eHorizontal) {
|
|
|
|
return GetHorizontalMetrics();
|
|
|
|
}
|
|
|
|
if (!mVerticalMetrics) {
|
|
|
|
mVerticalMetrics = CreateVerticalMetrics();
|
|
|
|
}
|
|
|
|
return *mVerticalMetrics;
|
2014-09-30 06:37:40 +00:00
|
|
|
}
|
2013-02-11 06:22:20 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-16 09:58:12 +00: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.
|
|
|
|
* 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.
|
2013-02-11 06:22:20 +00:00
|
|
|
*/
|
2014-09-16 09:58:12 +00:00
|
|
|
struct Spacing {
|
|
|
|
gfxFloat mBefore;
|
|
|
|
gfxFloat mAfter;
|
|
|
|
};
|
2013-02-11 06:22:20 +00:00
|
|
|
/**
|
2014-09-16 09:58:12 +00:00
|
|
|
* Metrics for a particular string
|
2013-02-11 06:22:20 +00:00
|
|
|
*/
|
2014-09-16 09:58:12 +00:00
|
|
|
struct RunMetrics {
|
|
|
|
RunMetrics() {
|
|
|
|
mAdvanceWidth = mAscent = mDescent = 0.0;
|
|
|
|
}
|
2007-01-16 20:51:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
void CombineWith(const RunMetrics& aOther, bool aOtherIsOnLeft);
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-09-16 09:58:12 +00: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.
|
|
|
|
// If a tight boundingBox was requested 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;
|
|
|
|
};
|
2007-01-16 20:51:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
/**
|
|
|
|
* 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 aPt the baseline origin; the left end of the baseline
|
|
|
|
* for LTR textruns, the right end for RTL textruns.
|
|
|
|
* On return, this will be updated to the other end of the baseline.
|
|
|
|
* In application units, really!
|
|
|
|
* @param aRunParams record with drawing parameters, see TextRunDrawParams.
|
|
|
|
* Particular fields of interest include
|
|
|
|
* .spacing 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.
|
|
|
|
* .drawMode specifies whether the fill or stroke of the glyph should be
|
|
|
|
* drawn, or if it should be drawn into the current path
|
|
|
|
* .contextPaint information about how to construct the fill and
|
|
|
|
* stroke pattern. Can be nullptr if we are not stroking the text, which
|
|
|
|
* indicates that the current source from context should be used for fill
|
|
|
|
* .context the Thebes graphics context to which we're drawing
|
|
|
|
* .dt Moz2D DrawTarget to which we're drawing
|
|
|
|
*
|
|
|
|
* Callers guarantee:
|
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
|
|
|
* -- all glyphs use this font
|
|
|
|
*/
|
|
|
|
void Draw(gfxTextRun *aTextRun, uint32_t aStart, uint32_t aEnd,
|
2014-10-01 19:25:48 +00:00
|
|
|
gfxPoint *aPt, const TextRunDrawParams& aRunParams,
|
|
|
|
uint16_t aOrientation);
|
2007-01-23 08:45:52 +00:00
|
|
|
|
|
|
|
/**
|
2014-09-16 09:58:12 +00:00
|
|
|
* 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 aContextForTightBoundingBox when aTight is true, this must
|
|
|
|
* be non-null.
|
|
|
|
* @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.
|
2007-01-23 08:45:52 +00:00
|
|
|
*
|
2014-09-16 09:58:12 +00:00
|
|
|
* Callers guarantee:
|
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
|
|
|
* -- all glyphs use this font
|
2007-03-22 23:07:18 +00:00
|
|
|
*
|
2014-09-16 09:58:12 +00:00
|
|
|
* 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.
|
2007-01-23 08:45:52 +00:00
|
|
|
*/
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual RunMetrics Measure(gfxTextRun *aTextRun,
|
|
|
|
uint32_t aStart, uint32_t aEnd,
|
|
|
|
BoundingBoxType aBoundingBoxType,
|
|
|
|
gfxContext *aContextForTightBoundingBox,
|
2014-10-16 08:40:19 +00:00
|
|
|
Spacing *aSpacing, uint16_t aOrientation);
|
2007-01-23 08:45:52 +00:00
|
|
|
/**
|
2014-09-16 09:58:12 +00:00
|
|
|
* 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
|
2007-01-23 08:45:52 +00:00
|
|
|
*/
|
2014-09-16 09:58:12 +00:00
|
|
|
bool NotifyLineBreaksChanged(gfxTextRun *aTextRun,
|
|
|
|
uint32_t aStart, uint32_t aLength)
|
|
|
|
{ return false; }
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Expiration tracking
|
|
|
|
nsExpirationState *GetExpirationState() { return &mExpirationState; }
|
2011-05-04 11:29:56 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Get the glyphID of a space
|
|
|
|
virtual uint32_t GetSpaceGlyph() = 0;
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxGlyphExtents *GetOrCreateGlyphExtents(int32_t aAppUnitsPerDevUnit);
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// You need to call SetupCairoFont on the aCR just before calling this
|
2015-04-27 08:45:55 +00:00
|
|
|
virtual void SetupGlyphExtents(gfxContext *aContext, uint32_t aGlyphID,
|
2014-09-16 09:58:12 +00:00
|
|
|
bool aNeedTight, gfxGlyphExtents *aExtents);
|
2014-03-31 10:53:09 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// This is called by the default Draw() implementation above.
|
|
|
|
virtual bool SetupCairoFont(gfxContext *aContext) = 0;
|
2014-03-31 10:53:09 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual bool AllowSubpixelAA() { return true; }
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool IsSyntheticBold() { return mApplySyntheticBold; }
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Amount by which synthetic bold "fattens" the glyphs:
|
|
|
|
// For size S up to a threshold size T, we use (0.25 + 3S / 4T),
|
|
|
|
// so that the result ranges from 0.25 to 1.0; thereafter,
|
|
|
|
// simply use (S / T).
|
|
|
|
gfxFloat GetSyntheticBoldOffset() {
|
|
|
|
gfxFloat size = GetAdjustedSize();
|
|
|
|
const gfxFloat threshold = 48.0;
|
|
|
|
return size < threshold ? (0.25 + 0.75 * size / threshold) :
|
|
|
|
(size / threshold);
|
|
|
|
}
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFontEntry *GetFontEntry() const { return mFontEntry.get(); }
|
|
|
|
bool HasCharacter(uint32_t ch) {
|
2014-11-06 04:42:50 +00:00
|
|
|
if (!mIsValid ||
|
|
|
|
(mUnicodeRangeMap && !mUnicodeRangeMap->test(ch))) {
|
2014-09-16 09:58:12 +00:00
|
|
|
return false;
|
2014-11-06 04:42:50 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
return mFontEntry->HasCharacter(ch);
|
|
|
|
}
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-11-06 04:42:50 +00:00
|
|
|
const gfxCharacterMap* GetUnicodeRangeMap() const {
|
|
|
|
return mUnicodeRangeMap.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetUnicodeRangeMap(gfxCharacterMap* aUnicodeRangeMap) {
|
|
|
|
mUnicodeRangeMap = aUnicodeRangeMap;
|
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
uint16_t GetUVSGlyph(uint32_t aCh, uint32_t aVS) {
|
|
|
|
if (!mIsValid) {
|
|
|
|
return 0;
|
2011-03-22 14:59:25 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
return mFontEntry->GetUVSGlyph(aCh, aVS);
|
|
|
|
}
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-09-16 11:25:45 +00:00
|
|
|
template<typename T>
|
|
|
|
bool InitFakeSmallCapsRun(gfxContext *aContext,
|
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const T *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
uint8_t aMatchType,
|
|
|
|
uint16_t aOrientation,
|
|
|
|
int32_t aScript,
|
|
|
|
bool aSyntheticLower,
|
|
|
|
bool aSyntheticUpper);
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-09-16 09:58:12 +00: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
|
|
|
|
template<typename T>
|
|
|
|
bool SplitAndInitTextRun(gfxContext *aContext,
|
|
|
|
gfxTextRun *aTextRun,
|
|
|
|
const T *aString,
|
|
|
|
uint32_t aRunStart,
|
|
|
|
uint32_t aRunLength,
|
2014-10-01 19:25:48 +00:00
|
|
|
int32_t aRunScript,
|
|
|
|
bool aVertical);
|
2011-03-22 14:59:25 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Get a ShapedWord representing the given text (either 8- or 16-bit)
|
|
|
|
// for use in setting up a gfxTextRun.
|
|
|
|
template<typename T>
|
|
|
|
gfxShapedWord* GetShapedWord(gfxContext *aContext,
|
|
|
|
const T *aText,
|
|
|
|
uint32_t aLength,
|
|
|
|
uint32_t aHash,
|
|
|
|
int32_t aRunScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags,
|
|
|
|
gfxTextPerfMetrics *aTextPerf);
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Ensure the ShapedWord cache is initialized. This MUST be called before
|
|
|
|
// any attempt to use GetShapedWord().
|
|
|
|
void InitWordCache() {
|
|
|
|
if (!mWordCache) {
|
|
|
|
mWordCache = new nsTHashtable<CacheHashEntry>;
|
|
|
|
}
|
|
|
|
}
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Called by the gfxFontCache timer to increment the age of all the words,
|
|
|
|
// so that they'll expire after a sufficient period of non-use
|
2015-07-14 02:08:16 +00:00
|
|
|
void AgeCachedWords();
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Discard all cached word records; called on memory-pressure notification.
|
|
|
|
void ClearCachedWords() {
|
|
|
|
if (mWordCache) {
|
|
|
|
mWordCache->Clear();
|
|
|
|
}
|
|
|
|
}
|
2007-01-23 08:45:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Glyph rendering/geometry has changed, so invalidate data as necessary.
|
|
|
|
void NotifyGlyphsChanged();
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
typedef enum {
|
|
|
|
FONT_TYPE_DWRITE,
|
|
|
|
FONT_TYPE_GDI,
|
|
|
|
FONT_TYPE_FT2,
|
|
|
|
FONT_TYPE_MAC,
|
|
|
|
FONT_TYPE_OS2,
|
|
|
|
FONT_TYPE_CAIRO
|
|
|
|
} FontType;
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual FontType GetType() const = 0;
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2015-06-17 14:00:52 +00:00
|
|
|
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(DrawTarget* aTarget)
|
2014-09-16 09:58:12 +00:00
|
|
|
{ return gfxPlatform::GetPlatform()->GetScaledFontForFont(aTarget, this); }
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool KerningDisabled() {
|
|
|
|
return mKerningSet && !mKerningEnabled;
|
|
|
|
}
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
/**
|
|
|
|
* Subclass this object to be notified of glyph changes. Delete the object
|
|
|
|
* when no longer needed.
|
|
|
|
*/
|
|
|
|
class GlyphChangeObserver {
|
2007-07-18 14:22:06 +00:00
|
|
|
public:
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual ~GlyphChangeObserver()
|
2007-07-18 14:22:06 +00:00
|
|
|
{
|
2014-09-16 09:58:12 +00:00
|
|
|
if (mFont) {
|
|
|
|
mFont->RemoveGlyphChangeObserver(this);
|
|
|
|
}
|
2007-07-18 14:22:06 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
// This gets called when the gfxFont dies.
|
|
|
|
void ForgetFont() { mFont = nullptr; }
|
|
|
|
virtual void NotifyGlyphsChanged() = 0;
|
|
|
|
protected:
|
|
|
|
explicit GlyphChangeObserver(gfxFont *aFont) : mFont(aFont)
|
2007-07-18 14:22:06 +00:00
|
|
|
{
|
2014-09-16 09:58:12 +00:00
|
|
|
mFont->AddGlyphChangeObserver(this);
|
2007-07-18 14:22:06 +00:00
|
|
|
}
|
2015-05-22 12:23:00 +00:00
|
|
|
// This pointer is nulled by ForgetFont in the gfxFont's
|
|
|
|
// destructor. Before the gfxFont dies.
|
|
|
|
gfxFont* MOZ_NON_OWNING_REF mFont;
|
2007-07-18 14:22:06 +00:00
|
|
|
};
|
2014-09-16 09:58:12 +00:00
|
|
|
friend class GlyphChangeObserver;
|
2007-07-18 14:22:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool GlyphsMayChange()
|
|
|
|
{
|
|
|
|
// Currently only fonts with SVG glyphs can have animated glyphs
|
|
|
|
return mFontEntry->TryGetSVGData(this);
|
2012-01-05 11:54:45 +00:00
|
|
|
}
|
2013-01-04 18:35:37 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
static void DestroySingletons() {
|
|
|
|
delete sScriptTagToCode;
|
|
|
|
delete sDefaultFeatures;
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
|
|
|
|
// Get a font dimension from the MATH table, scaled to appUnits;
|
|
|
|
// may only be called if mFontEntry->TryGetMathTable has succeeded
|
|
|
|
// (i.e. the font is known to be a valid OpenType math font).
|
|
|
|
nscoord GetMathConstant(gfxFontEntry::MathConstant aConstant,
|
|
|
|
uint32_t aAppUnitsPerDevPixel)
|
|
|
|
{
|
|
|
|
return NSToCoordRound(mFontEntry->GetMathConstant(aConstant) *
|
|
|
|
GetAdjustedSize() * aAppUnitsPerDevPixel);
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
2014-09-16 09:58:12 +00:00
|
|
|
|
|
|
|
// Get a dimensionless math constant (e.g. a percentage);
|
|
|
|
// may only be called if mFontEntry->TryGetMathTable has succeeded
|
|
|
|
// (i.e. the font is known to be a valid OpenType math font).
|
|
|
|
float GetMathConstant(gfxFontEntry::MathConstant aConstant)
|
|
|
|
{
|
|
|
|
return mFontEntry->GetMathConstant(aConstant);
|
2011-12-06 12:39:19 +00:00
|
|
|
}
|
2009-10-07 17:16:52 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// return a cloned font resized and offset to simulate sub/superscript glyphs
|
|
|
|
virtual already_AddRefed<gfxFont>
|
|
|
|
GetSubSuperscriptFont(int32_t aAppUnitsPerDevPixel);
|
|
|
|
|
|
|
|
protected:
|
2014-09-30 06:37:40 +00:00
|
|
|
virtual const Metrics& GetHorizontalMetrics() = 0;
|
|
|
|
|
2014-09-30 06:38:06 +00:00
|
|
|
const Metrics* CreateVerticalMetrics();
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Output a single glyph at *aPt, which is updated by the glyph's advance.
|
|
|
|
// Normal glyphs are simply accumulated in aBuffer until it is full and
|
|
|
|
// gets flushed, but SVG or color-font glyphs will instead be rendered
|
|
|
|
// directly to the destination (found from the buffer's parameters).
|
|
|
|
void DrawOneGlyph(uint32_t aGlyphID,
|
|
|
|
double aAdvance,
|
|
|
|
gfxPoint *aPt,
|
|
|
|
GlyphBufferAzure& aBuffer,
|
|
|
|
bool *aEmittedGlyphs) const;
|
|
|
|
|
|
|
|
// Output a run of glyphs at *aPt, which is updated to follow the last glyph
|
|
|
|
// in the run. This method also takes account of any letter-spacing provided
|
|
|
|
// in aRunParams.
|
|
|
|
bool DrawGlyphs(gfxShapedText *aShapedText,
|
|
|
|
uint32_t aOffset, // offset in the textrun
|
|
|
|
uint32_t aCount, // length of run to draw
|
|
|
|
gfxPoint *aPt,
|
|
|
|
const TextRunDrawParams& aRunParams,
|
|
|
|
const FontDrawParams& aFontParams);
|
|
|
|
|
|
|
|
// set the font size and offset used for
|
|
|
|
// synthetic subscript/superscript glyphs
|
|
|
|
void CalculateSubSuperSizeAndOffset(int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat& aSubSuperSizeRatio,
|
|
|
|
float& aBaselineOffset);
|
|
|
|
|
|
|
|
// Return a font that is a "clone" of this one, but reduced to 80% size
|
|
|
|
// (and with variantCaps set to normal).
|
|
|
|
// Default implementation relies on gfxFontEntry::CreateFontInstance;
|
|
|
|
// backends that don't implement that will need to override this and use
|
2015-05-20 15:44:09 +00:00
|
|
|
// an alternative technique. (gfxFontconfigFonts, I'm looking at you...)
|
2014-09-16 09:58:12 +00:00
|
|
|
virtual already_AddRefed<gfxFont> GetSmallCapsFont();
|
|
|
|
|
|
|
|
// subclasses may provide (possibly hinted) glyph widths (in font units);
|
|
|
|
// if they do not override this, harfbuzz will use unhinted widths
|
|
|
|
// derived from the font tables
|
|
|
|
virtual bool ProvidesGlyphWidths() const {
|
|
|
|
return false;
|
|
|
|
}
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// The return value is interpreted as a horizontal advance in 16.16 fixed
|
|
|
|
// point format.
|
2014-11-10 21:41:41 +00:00
|
|
|
virtual int32_t GetGlyphWidth(DrawTarget& aDrawTarget, uint16_t aGID) {
|
2014-09-16 09:58:12 +00:00
|
|
|
return -1;
|
2007-03-22 23:07:18 +00:00
|
|
|
}
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-11-18 10:23:45 +00:00
|
|
|
bool IsSpaceGlyphInvisible(gfxContext *aRefContext, gfxTextRun *aTextRun);
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
void AddGlyphChangeObserver(GlyphChangeObserver *aObserver);
|
|
|
|
void RemoveGlyphChangeObserver(GlyphChangeObserver *aObserver);
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// whether font contains substitution lookups containing spaces
|
|
|
|
bool HasSubstitutionRulesWithSpaceLookups(int32_t aRunScript);
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// do spaces participate in shaping rules? if so, can't used word cache
|
|
|
|
bool SpaceMayParticipateInShaping(int32_t aRunScript);
|
2007-05-08 22:46:14 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// For 8-bit text, expand to 16-bit and then call the following method.
|
|
|
|
bool ShapeText(gfxContext *aContext,
|
|
|
|
const uint8_t *aText,
|
|
|
|
uint32_t aOffset, // dest offset in gfxShapedText
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxShapedText *aShapedText); // where to store the result
|
2011-10-14 07:06:35 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Call the appropriate shaper to generate glyphs for aText and store
|
|
|
|
// them into aShapedText.
|
|
|
|
virtual bool ShapeText(gfxContext *aContext,
|
|
|
|
const char16_t *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxShapedText *aShapedText);
|
2014-07-22 00:02:45 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Helper to adjust for synthetic bold and set character-type flags
|
|
|
|
// in the shaped text; implementations of ShapeText should call this
|
|
|
|
// after glyph shaping has been completed.
|
|
|
|
void PostShapingFixup(gfxContext *aContext,
|
|
|
|
const char16_t *aText,
|
|
|
|
uint32_t aOffset, // position within aShapedText
|
|
|
|
uint32_t aLength,
|
2015-01-08 12:51:00 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxShapedText *aShapedText);
|
2014-07-22 00:02:45 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Shape text directly into a range within a textrun, without using the
|
|
|
|
// font's word cache. Intended for use when the font has layout features
|
|
|
|
// that involve space, and therefore require shaping complete runs rather
|
|
|
|
// than isolated words, or for long strings that are inefficient to cache.
|
|
|
|
// This will split the text on "invalid" characters (tab/newline) that are
|
|
|
|
// not handled via normal shaping, but does not otherwise divide up the
|
|
|
|
// text.
|
|
|
|
template<typename T>
|
|
|
|
bool ShapeTextWithoutWordCache(gfxContext *aContext,
|
|
|
|
const T *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxTextRun *aTextRun);
|
2014-07-22 00:02:45 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Shape a fragment of text (a run that is known to contain only
|
|
|
|
// "valid" characters, no newlines/tabs/other control chars).
|
|
|
|
// All non-wordcache shaping goes through here; this is the function
|
|
|
|
// that will ensure we don't pass excessively long runs to the various
|
|
|
|
// platform shapers.
|
|
|
|
template<typename T>
|
|
|
|
bool ShapeFragmentWithoutWordCache(gfxContext *aContext,
|
|
|
|
const T *aText,
|
|
|
|
uint32_t aOffset,
|
|
|
|
uint32_t aLength,
|
|
|
|
int32_t aScript,
|
2014-10-01 19:25:48 +00:00
|
|
|
bool aVertical,
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxTextRun *aTextRun);
|
2007-08-26 23:44:00 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
void CheckForFeaturesInvolvingSpace();
|
2010-02-18 11:52:34 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// whether a given feature is included in feature settings from both the
|
|
|
|
// font and the style. aFeatureOn set if resolved feature value is non-zero
|
|
|
|
bool HasFeatureSet(uint32_t aFeature, bool& aFeatureOn);
|
2012-01-05 11:54:45 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// used when analyzing whether a font has space contextual lookups
|
|
|
|
static nsDataHashtable<nsUint32HashKey, int32_t> *sScriptTagToCode;
|
|
|
|
static nsTHashtable<nsUint32HashKey> *sDefaultFeatures;
|
2007-11-16 01:43:47 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxFontEntry> mFontEntry;
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
struct CacheHashKey {
|
|
|
|
union {
|
|
|
|
const uint8_t *mSingle;
|
|
|
|
const char16_t *mDouble;
|
|
|
|
} mText;
|
|
|
|
uint32_t mLength;
|
|
|
|
uint32_t mFlags;
|
|
|
|
int32_t mScript;
|
|
|
|
int32_t mAppUnitsPerDevUnit;
|
|
|
|
PLDHashNumber mHashKey;
|
|
|
|
bool mTextIs8Bit;
|
2012-12-19 09:42:25 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
CacheHashKey(const uint8_t *aText, uint32_t aLength,
|
|
|
|
uint32_t aStringHash,
|
|
|
|
int32_t aScriptCode, int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: mLength(aLength),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mScript(aScriptCode),
|
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
|
|
|
|
mHashKey(aStringHash + aScriptCode +
|
|
|
|
aAppUnitsPerDevUnit * 0x100 + aFlags * 0x10000),
|
|
|
|
mTextIs8Bit(true)
|
2012-12-19 09:42:25 +00:00
|
|
|
{
|
2014-09-16 09:58:12 +00:00
|
|
|
NS_ASSERTION(aFlags & gfxTextRunFactory::TEXT_IS_8BIT,
|
|
|
|
"8-bit flag should have been set");
|
|
|
|
mText.mSingle = aText;
|
2012-12-19 09:42:25 +00:00
|
|
|
}
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
CacheHashKey(const char16_t *aText, uint32_t aLength,
|
|
|
|
uint32_t aStringHash,
|
|
|
|
int32_t aScriptCode, int32_t aAppUnitsPerDevUnit,
|
|
|
|
uint32_t aFlags)
|
|
|
|
: mLength(aLength),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mScript(aScriptCode),
|
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
|
|
|
|
mHashKey(aStringHash + aScriptCode +
|
|
|
|
aAppUnitsPerDevUnit * 0x100 + aFlags * 0x10000),
|
|
|
|
mTextIs8Bit(false)
|
|
|
|
{
|
|
|
|
// We can NOT assert that TEXT_IS_8BIT is false in aFlags here,
|
|
|
|
// because this might be an 8bit-only word from a 16-bit textrun,
|
|
|
|
// in which case the text we're passed is still in 16-bit form,
|
|
|
|
// and we'll have to use an 8-to-16bit comparison in KeyEquals.
|
|
|
|
mText.mDouble = aText;
|
|
|
|
}
|
2012-12-19 09:42:25 +00:00
|
|
|
};
|
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
class CacheHashEntry : public PLDHashEntryHdr {
|
|
|
|
public:
|
|
|
|
typedef const CacheHashKey &KeyType;
|
|
|
|
typedef const CacheHashKey *KeyTypePointer;
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// When constructing a new entry in the hashtable, the caller of Put()
|
|
|
|
// will fill us in.
|
|
|
|
explicit CacheHashEntry(KeyTypePointer aKey) { }
|
|
|
|
CacheHashEntry(const CacheHashEntry& toCopy) { NS_ERROR("Should not be called"); }
|
|
|
|
~CacheHashEntry() { }
|
2011-12-06 12:39:19 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
2011-12-06 12:39:18 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
|
|
|
return aKey->mHashKey;
|
|
|
|
}
|
2013-11-21 21:31:53 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(mShapedWord.get());
|
|
|
|
}
|
2013-11-21 21:31:53 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2008-03-13 02:36:58 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
nsAutoPtr<gfxShapedWord> mShapedWord;
|
|
|
|
};
|
2008-08-06 04:34:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
nsAutoPtr<nsTHashtable<CacheHashEntry> > mWordCache;
|
2008-08-06 04:34:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
static const uint32_t kShapedWordCacheMaxAge = 3;
|
2008-08-06 04:34:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool mIsValid;
|
2008-08-06 04:34:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// use synthetic bolding for environments where this is not supported
|
|
|
|
// by the platform
|
|
|
|
bool mApplySyntheticBold;
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool mKerningSet; // kerning explicitly set?
|
|
|
|
bool mKerningEnabled; // if set, on or off?
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
nsExpirationState mExpirationState;
|
|
|
|
gfxFontStyle mStyle;
|
|
|
|
nsAutoTArray<gfxGlyphExtents*,1> mGlyphExtentsArray;
|
|
|
|
nsAutoPtr<nsTHashtable<nsPtrHashKey<GlyphChangeObserver> > > mGlyphChangeObservers;
|
2013-11-25 04:59:56 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat mAdjustedSize;
|
2013-12-19 20:21:11 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
float mFUnitsConvFactor; // conversion factor from font units to dev units
|
2008-08-06 04:34:06 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// the AA setting requested for this font - may affect glyph bounds
|
|
|
|
AntialiasOption mAntialiasOption;
|
2011-01-05 21:48:48 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// a copy of the font without antialiasing, if needed for separate
|
|
|
|
// measurement by mathml code
|
|
|
|
nsAutoPtr<gfxFont> mNonAAFont;
|
2014-06-06 06:09:23 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// we create either or both of these shapers when needed, depending
|
|
|
|
// whether the font has graphite tables, and whether graphite shaping
|
|
|
|
// is actually enabled
|
|
|
|
nsAutoPtr<gfxFontShaper> mHarfBuzzShaper;
|
|
|
|
nsAutoPtr<gfxFontShaper> mGraphiteShaper;
|
2008-03-13 02:36:58 +00:00
|
|
|
|
2014-11-06 04:42:50 +00:00
|
|
|
// if a userfont with unicode-range specified, contains map of *possible*
|
|
|
|
// ranges supported by font
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<gfxCharacterMap> mUnicodeRangeMap;
|
2014-11-06 04:42:50 +00:00
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFont;
|
2008-10-01 03:01:53 +00:00
|
|
|
|
2014-09-30 06:38:06 +00:00
|
|
|
// For vertical metrics, created on demand.
|
|
|
|
nsAutoPtr<const Metrics> mVerticalMetrics;
|
|
|
|
|
2014-09-16 09:58:12 +00: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.
|
|
|
|
bool InitMetricsFromSfntTables(Metrics& aMetrics);
|
2013-11-25 04:59:56 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Helper to calculate various derived metrics from the results of
|
|
|
|
// InitMetricsFromSfntTables or equivalent platform code
|
|
|
|
void CalculateDerivedMetrics(Metrics& aMetrics);
|
2013-03-08 10:41:31 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// some fonts have bad metrics, this method sanitize them.
|
|
|
|
// if this font has bad underline offset, aIsBadUnderlineFont should be true.
|
2014-09-30 06:37:40 +00:00
|
|
|
void SanitizeMetrics(Metrics *aMetrics, bool aIsBadUnderlineFont);
|
2011-01-05 21:48:48 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool RenderSVGGlyph(gfxContext *aContext, gfxPoint aPoint, DrawMode aDrawMode,
|
|
|
|
uint32_t aGlyphId, gfxTextContextPaint *aContextPaint) const;
|
|
|
|
bool RenderSVGGlyph(gfxContext *aContext, gfxPoint aPoint, DrawMode aDrawMode,
|
|
|
|
uint32_t aGlyphId, gfxTextContextPaint *aContextPaint,
|
|
|
|
gfxTextRunDrawCallbacks *aCallbacks,
|
|
|
|
bool& aEmittedGlyphs) const;
|
2009-10-07 15:26:58 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
bool RenderColorGlyph(gfxContext* aContext,
|
|
|
|
mozilla::gfx::ScaledFont* scaledFont,
|
|
|
|
mozilla::gfx::GlyphRenderingOptions* renderingOptions,
|
|
|
|
mozilla::gfx::DrawOptions drawOptions,
|
|
|
|
const mozilla::gfx::Point& aPoint,
|
|
|
|
uint32_t aGlyphId) const;
|
2011-12-06 12:39:18 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Bug 674909. When synthetic bolding text by drawing twice, need to
|
|
|
|
// render using a pixel offset in device pixels, otherwise text
|
|
|
|
// doesn't appear bolded, it appears as if a bad text shadow exists
|
|
|
|
// when a non-identity transform exists. Use an offset factor so that
|
|
|
|
// the second draw occurs at a constant offset in device pixels.
|
|
|
|
// This helper calculates the scale factor we need to apply to the
|
|
|
|
// synthetic-bold offset.
|
|
|
|
static double CalcXScale(gfxContext *aContext);
|
|
|
|
};
|
2010-02-24 07:18:49 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// proportion of ascent used for x-height, if unable to read value from font
|
|
|
|
#define DEFAULT_XHEIGHT_FACTOR 0.56f
|
2007-03-04 21:05:10 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
// Parameters passed to gfxFont methods for drawing glyphs from a textrun.
|
|
|
|
// The TextRunDrawParams are set up once per textrun; the FontDrawParams
|
|
|
|
// are dependent on the specific font, so they are set per GlyphRun.
|
|
|
|
|
|
|
|
struct TextRunDrawParams {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::gfx::DrawTarget> dt;
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxContext *context;
|
|
|
|
gfxFont::Spacing *spacing;
|
|
|
|
gfxTextRunDrawCallbacks *callbacks;
|
|
|
|
gfxTextContextPaint *runContextPaint;
|
2014-10-24 16:32:23 +00:00
|
|
|
mozilla::gfx::Color fontSmoothingBGColor;
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxFloat direction;
|
|
|
|
double devPerApp;
|
|
|
|
DrawMode drawMode;
|
2014-10-01 19:25:48 +00:00
|
|
|
bool isVerticalRun;
|
2014-09-16 09:58:12 +00:00
|
|
|
bool isRTL;
|
|
|
|
bool paintSVGGlyphs;
|
|
|
|
};
|
2009-10-07 15:26:58 +00:00
|
|
|
|
2014-09-16 09:58:12 +00:00
|
|
|
struct FontDrawParams {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<mozilla::gfx::ScaledFont> scaledFont;
|
|
|
|
RefPtr<mozilla::gfx::GlyphRenderingOptions> renderingOptions;
|
2014-09-16 09:58:12 +00:00
|
|
|
gfxTextContextPaint *contextPaint;
|
|
|
|
mozilla::gfx::Matrix *passedInvMatrix;
|
|
|
|
mozilla::gfx::Matrix matInv;
|
|
|
|
double synBoldOnePixelOffset;
|
|
|
|
int32_t extraStrikes;
|
|
|
|
mozilla::gfx::DrawOptions drawOptions;
|
2014-10-01 19:25:48 +00:00
|
|
|
bool isVerticalFont;
|
2014-09-16 09:58:12 +00:00
|
|
|
bool haveSVGGlyphs;
|
|
|
|
bool haveColorGlyphs;
|
2005-11-29 20:12:29 +00:00
|
|
|
};
|
2014-09-16 09:58:12 +00:00
|
|
|
|
2005-10-08 05:09:42 +00:00
|
|
|
#endif
|