2018-11-30 22:52:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
2018-11-30 18:39:55 +03:00
|
|
|
* vim: set ts=4 et sw=2 tw=80:
|
2012-05-21 15:12:37 +04: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 09:09:42 +04:00
|
|
|
|
|
|
|
#ifndef GFX_FONT_H
|
|
|
|
#define GFX_FONT_H
|
|
|
|
|
|
|
|
#include "gfxTypes.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxFontEntry.h"
|
2016-12-03 15:18:29 +03:00
|
|
|
#include "gfxFontVariations.h"
|
2005-10-08 09:09:42 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "gfxPoint.h"
|
2016-07-14 03:00:00 +03:00
|
|
|
#include "gfxPattern.h"
|
2006-02-24 08:15:21 +03:00
|
|
|
#include "nsTArray.h"
|
2007-04-04 07:32:43 +04:00
|
|
|
#include "nsTHashtable.h"
|
|
|
|
#include "nsHashKeys.h"
|
2007-01-23 11:45:52 +03:00
|
|
|
#include "gfxRect.h"
|
2007-04-04 07:32:43 +04:00
|
|
|
#include "nsExpirationTracker.h"
|
2009-10-07 19:26:58 +04:00
|
|
|
#include "gfxPlatform.h"
|
2017-10-03 01:05:19 +03:00
|
|
|
#include "nsAtom.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2012-03-23 16:14:16 +04:00
|
|
|
#include "nsIMemoryReporter.h"
|
2013-05-22 19:48:55 +04:00
|
|
|
#include "nsIObserver.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-06-13 08:14:28 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2018-04-13 22:34:37 +03:00
|
|
|
#include "mozilla/FontPropertyTypes.h"
|
2017-04-03 19:49:17 +03:00
|
|
|
#include "mozilla/TypedEnumBits.h"
|
2017-04-08 01:49:44 +03:00
|
|
|
#include "MainThreadUtils.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2013-10-02 01:02:16 +04:00
|
|
|
#include "DrawMode.h"
|
2013-10-08 03:15:59 +04:00
|
|
|
#include "nsDataHashtable.h"
|
|
|
|
#include "harfbuzz/hb.h"
|
2013-12-03 03:53:14 +04:00
|
|
|
#include "mozilla/gfx/2D.h"
|
2016-04-22 20:40:39 +03:00
|
|
|
#include "nsColor.h"
|
2019-04-01 17:32:19 +03:00
|
|
|
#include "nsFontMetrics.h"
|
2017-08-15 05:04:32 +03:00
|
|
|
#include "mozilla/ServoUtils.h"
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2015-12-16 07:10:04 +03:00
|
|
|
typedef struct _cairo cairo_t;
|
2011-12-15 20:12:40 +04:00
|
|
|
typedef struct _cairo_scaled_font cairo_scaled_font_t;
|
|
|
|
|
2008-01-21 04:23:50 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
# include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
2005-10-08 09:09:42 +04:00
|
|
|
class gfxContext;
|
2005-11-29 23:12:29 +03:00
|
|
|
class gfxTextRun;
|
2007-04-04 07:32:43 +04:00
|
|
|
class gfxFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
class gfxGlyphExtents;
|
2013-01-04 22:35:37 +04:00
|
|
|
class gfxShapedText;
|
2011-12-06 16:39:19 +04:00
|
|
|
class gfxShapedWord;
|
2014-09-16 13:58:12 +04:00
|
|
|
class gfxSkipChars;
|
2016-11-02 21:47:18 +03:00
|
|
|
class gfxMathTable;
|
2010-02-24 20:57:44 +03:00
|
|
|
|
2007-06-08 12:22:03 +04:00
|
|
|
#define FONT_MAX_SIZE 2000.0
|
|
|
|
|
2014-05-26 17:23:32 +04:00
|
|
|
#define SMALL_CAPS_SCALE_FACTOR 0.8
|
|
|
|
|
2015-01-01 01:35:40 +03: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
|
2017-11-17 13:54:21 +03:00
|
|
|
# define OBLIQUE_SKEW_FACTOR 0.3f
|
2016-07-13 03:27:57 +03:00
|
|
|
#elif defined(MOZ_WIDGET_GTK)
|
2017-11-17 13:54:21 +03:00
|
|
|
# define OBLIQUE_SKEW_FACTOR 0.2f
|
2015-01-01 01:35:40 +03:00
|
|
|
#else
|
2017-11-17 13:54:21 +03:00
|
|
|
# define OBLIQUE_SKEW_FACTOR 0.25f
|
2015-01-01 01:35:40 +03:00
|
|
|
#endif
|
|
|
|
|
2013-02-11 10:22:20 +04:00
|
|
|
struct gfxTextRunDrawCallbacks;
|
2012-03-28 01:38:39 +04:00
|
|
|
|
2013-10-08 03:15:59 +04:00
|
|
|
namespace mozilla {
|
2016-07-22 16:56:09 +03:00
|
|
|
class SVGContextPaint;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|
2013-10-08 03:15:59 +04:00
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
struct gfxFontStyle {
|
2013-05-20 06:59:20 +04:00
|
|
|
typedef mozilla::FontStretch FontStretch;
|
2010-07-14 00:31:31 +04:00
|
|
|
typedef mozilla::FontSlantStyle FontSlantStyle;
|
2012-03-15 13:03:00 +04:00
|
|
|
typedef mozilla::FontWeight FontWeight;
|
2014-12-23 15:50:10 +03:00
|
|
|
|
2007-06-08 12:22:03 +04:00
|
|
|
gfxFontStyle();
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
gfxFontStyle(FontSlantStyle aStyle, FontWeight aWeight, FontStretch aStretch,
|
|
|
|
gfxFloat aSize, nsAtom* aLanguage, bool aExplicitLanguage,
|
|
|
|
float aSizeAdjust, bool aSystemFont, bool aPrinterFont,
|
|
|
|
bool aWeightSynthesis, bool aStyleSynthesis,
|
2018-05-04 12:19:55 +03:00
|
|
|
uint32_t aLanguageOverride);
|
Bug 1449605 - part 1 - Rearrange thebes font code so that the decision whether to apply synthetic-bold is deferred until actually instantiating a font, not made during the font-matching process. r=jwatt
This rearranges how synthetic-bold use is determined in the font selection
& rendering code. Previously, we would decide during the font-selection
algorithm whether we need to apply synthetic-bold to the chosen face, and
then pass that decision through the fontgroup (storing it in the FamilyFace
entries of the mFonts array there) down to the actual rendering code that
instantiates fonts from the faces (font entries) we've selected.
That became a problem for variation fonts because in the case of a user
font, we may not have downloaded the resource yet, so we just have a "user
font container" entry, which carries the descriptors from the @font-face
rule and will fetch the actual resource when needed. But in the case of a
@font-face rule without a weight descriptor, we don't actually know at
font-selection time whether the face will support "true" bold (via a
variation axis) or not, so we can't reliably make the right decision about
applying synthetic bold.
So we now defer that decision until we actually instantiate a platform font
object to shape/measure/draw text. At that point, we have the requested
style and we also have the real font resource, so we can easily determine
whether fake-bold is required.
(This patch should not result in any visible behavior change; that will
come in a second patch now that the architecture supports it.)
2018-05-01 12:30:50 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// the language (may be an internal langGroup code rather than an actual
|
2012-03-15 13:03:00 +04:00
|
|
|
// language code) specified in the document or element's lang property,
|
|
|
|
// or inferred from the charset
|
2017-10-03 01:05:19 +03:00
|
|
|
RefPtr<nsAtom> language;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// Features are composed of (1) features from style rules (2) features
|
2017-04-04 01:24:46 +03:00
|
|
|
// from feature settings rules and (3) family-specific features. (1) and
|
2011-09-29 10:19:26 +04:00
|
|
|
// (3) are guaranteed to be mutually exclusive
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// custom opentype feature settings
|
2012-03-15 13:03:00 +04:00
|
|
|
nsTArray<gfxFontFeature> featureSettings;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// Some font-variant property values require font-specific settings
|
|
|
|
// defined via @font-feature-values rules. These are resolved after
|
2013-05-20 06:59:20 +04:00
|
|
|
// font matching occurs.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
// -- list of value tags for specific alternate features
|
|
|
|
nsTArray<gfxAlternateValue> alternateValues;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// -- object used to look these up once the font is matched
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontFeatureValueSet> featureValueLookup;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-03 15:18:29 +03:00
|
|
|
// opentype variation settings
|
2011-09-29 10:19:26 +04:00
|
|
|
nsTArray<gfxFontVariation> variationSettings;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
// The logical size of the font, in pixels
|
2005-10-08 09:09:42 +04:00
|
|
|
gfxFloat size;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2005-10-08 09:09:42 +04:00
|
|
|
// The aspect-value (ie., the ratio actualsize:actualxheight) that any
|
|
|
|
// actual physical font created from this font structure must have when
|
2015-04-21 09:10:40 +03: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 09:09:42 +04:00
|
|
|
float sizeAdjust;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-22 04:02:45 +04:00
|
|
|
// baseline offset, used when simulating sub/superscript glyphs
|
|
|
|
float baselineOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-07-14 00:31:31 +04:00
|
|
|
// Language system tag, to override document language;
|
|
|
|
// an OpenType "language system" tag represented as a 32-bit integer
|
2011-09-29 10:19:26 +04:00
|
|
|
// (see http://www.microsoft.com/typography/otspec/languagetags.htm).
|
|
|
|
// Normally 0, so font rendering will use the document or element language
|
2012-10-22 17:53:31 +04:00
|
|
|
// (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,
|
2010-07-14 00:31:31 +04:00
|
|
|
// but the font in use does not explicitly support this; the author can
|
2012-10-22 17:53:31 +04:00
|
|
|
// use font-language-override to request the Serbian option in the font
|
|
|
|
// in order to get correct glyph shapes.)
|
|
|
|
uint32_t languageOverride;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-10-22 17:53:31 +04:00
|
|
|
// The estimated background color behind the text. Enables a special
|
|
|
|
// rendering mode when NS_GET_A(.) > 0. Only used for text in the chrome.
|
2006-10-14 09:37:40 +04:00
|
|
|
nscolor fontSmoothingBackgroundColor;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2006-10-14 09:37:40 +04:00
|
|
|
// The Font{Weight,Stretch,SlantStyle} fields are each a 16-bit type.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-03 15:18:28 +03:00
|
|
|
// The weight of the font: 100, 200, ... 900.
|
|
|
|
FontWeight weight;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-12-03 15:18:28 +03:00
|
|
|
// The stretch of the font
|
|
|
|
FontStretch stretch;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-23 07:09:16 +04:00
|
|
|
// The style of font
|
2018-04-23 17:52:20 +03:00
|
|
|
FontSlantStyle style;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-02-08 13:05:56 +03:00
|
|
|
// Whether face-selection properties weight/style/stretch are all 'normal'
|
|
|
|
bool IsNormalStyle() const {
|
|
|
|
return weight.IsNormal() && style.IsNormal() && stretch.IsNormal();
|
|
|
|
}
|
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
// We pack these two small-integer fields into a single byte to avoid
|
2014-06-23 07:09:16 +04:00
|
|
|
// overflowing an 8-byte boundary [in a 64-bit build] and ending up with
|
2018-04-25 20:54:03 +03:00
|
|
|
// 7 bytes of padding at the end of the struct.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-23 07:09:16 +04:00
|
|
|
// caps variant (small-caps, petite-caps, etc.)
|
|
|
|
uint8_t variantCaps : 4; // uses range 0..6
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-22 04:02:45 +04:00
|
|
|
// sub/superscript variant
|
|
|
|
uint8_t variantSubSuper : 4; // uses range 0..2
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-22 04:02:45 +04:00
|
|
|
// Say that this font is a system font and therefore does not
|
|
|
|
// require certain fixup that we do for fonts from untrusted
|
2012-03-15 13:03:00 +04:00
|
|
|
// sources.
|
|
|
|
bool systemFont : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-19 11:08:55 +04:00
|
|
|
// Say that this font is used for print or print preview.
|
2012-03-15 13:03:00 +04:00
|
|
|
bool printerFont : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-19 11:08:55 +04:00
|
|
|
// Used to imitate -webkit-font-smoothing: antialiased
|
2013-07-30 00:00:41 +04:00
|
|
|
bool useGrayscaleAntialiasing : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-19 11:08:55 +04:00
|
|
|
// Whether synthetic styles are allowed
|
|
|
|
bool allowSyntheticWeight : 1;
|
|
|
|
bool allowSyntheticStyle : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-22 04:02:45 +04: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-23 15:50:10 +03:00
|
|
|
// whether the |language| field comes from explicit lang tagging in the
|
2014-06-19 11:08:55 +04:00
|
|
|
// document, or was inferred from charset/system locale
|
2014-12-23 15:50:10 +03:00
|
|
|
bool explicitLanguage : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-06-08 12:22:03 +04:00
|
|
|
// Return the final adjusted font size for the given aspect ratio.
|
2014-06-19 11:08:55 +04:00
|
|
|
// Not meant to be called when sizeAdjust = -1.0.
|
|
|
|
gfxFloat GetAdjustedSize(gfxFloat aspect) const {
|
2015-04-21 09:10:40 +03:00
|
|
|
NS_ASSERTION(sizeAdjust >= 0.0,
|
|
|
|
"Not meant to be called when sizeAdjust = -1.0");
|
2013-01-15 16:22:03 +04:00
|
|
|
gfxFloat adjustedSize =
|
2014-06-19 11:08:55 +04:00
|
|
|
std::max(NS_round(size * (sizeAdjust / aspect)), 1.0);
|
|
|
|
return std::min(adjustedSize, FONT_MAX_SIZE);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-04-23 17:52:20 +03:00
|
|
|
PLDHashNumber Hash() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-07-12 01:37:27 +04:00
|
|
|
// Adjust this style to simulate sub/superscript (as requested in the
|
|
|
|
// variantSubSuper field) using size and baselineOffset instead.
|
|
|
|
void AdjustForSubSuperscript(int32_t aAppUnitsPerDevPixel);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-06-19 11:08:55 +04:00
|
|
|
// Should this style cause the given font entry to use synthetic bold?
|
2006-10-14 09:37:40 +04:00
|
|
|
bool NeedsSyntheticBold(gfxFontEntry* aFontEntry) const {
|
|
|
|
return weight.IsBold() && allowSyntheticWeight &&
|
2018-05-04 12:19:55 +03:00
|
|
|
!aFontEntry->SupportsBold();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2006-10-14 09:37:40 +04:00
|
|
|
bool Equals(const gfxFontStyle& other) const {
|
2008-12-17 06:17:50 +03:00
|
|
|
return (*reinterpret_cast<const uint64_t*>(&size) ==
|
|
|
|
*reinterpret_cast<const uint64_t*>(&other.size)) &&
|
|
|
|
(style == other.style) && (weight == other.weight) &&
|
2016-04-21 20:58:59 +03:00
|
|
|
(stretch == other.stretch) && (variantCaps == other.variantCaps) &&
|
2008-12-17 06:17:50 +03:00
|
|
|
(variantSubSuper == other.variantSubSuper) &&
|
2014-06-19 11:08:55 +04:00
|
|
|
(allowSyntheticWeight == other.allowSyntheticWeight) &&
|
|
|
|
(allowSyntheticStyle == other.allowSyntheticStyle) &&
|
2012-03-15 13:03:00 +04:00
|
|
|
(systemFont == other.systemFont) &&
|
2013-01-04 22:35:37 +04:00
|
|
|
(printerFont == other.printerFont) &&
|
2013-07-30 00:00:41 +04:00
|
|
|
(useGrayscaleAntialiasing == other.useGrayscaleAntialiasing) &&
|
2014-12-23 15:50:10 +03:00
|
|
|
(explicitLanguage == other.explicitLanguage) &&
|
2010-02-24 20:57:57 +03:00
|
|
|
(language == other.language) &&
|
2014-07-22 04:02:45 +04:00
|
|
|
(baselineOffset == other.baselineOffset) &&
|
2012-10-22 17:53:31 +04:00
|
|
|
(*reinterpret_cast<const uint32_t*>(&sizeAdjust) ==
|
|
|
|
*reinterpret_cast<const uint32_t*>(&other.sizeAdjust)) &&
|
2010-12-09 14:52:03 +03:00
|
|
|
(featureSettings == other.featureSettings) &&
|
2013-05-20 06:59:20 +04:00
|
|
|
(alternateValues == other.alternateValues) &&
|
2016-12-03 15:18:28 +03:00
|
|
|
(featureValueLookup == other.featureValueLookup) &&
|
2016-12-03 15:18:29 +03:00
|
|
|
(variationSettings == other.variationSettings) &&
|
2017-11-03 04:02:30 +03:00
|
|
|
(languageOverride == other.languageOverride) &&
|
|
|
|
(fontSmoothingBackgroundColor == other.fontSmoothingBackgroundColor);
|
2006-10-14 09:37:40 +04:00
|
|
|
}
|
2005-10-08 09:09:42 +04:00
|
|
|
};
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
/**
|
|
|
|
* Font cache design:
|
|
|
|
*
|
2010-07-14 00:31:31 +04:00
|
|
|
* The mFonts hashtable contains most fonts, indexed by (gfxFontEntry*, style).
|
2007-04-04 07:32:43 +04:00
|
|
|
* It does not add a reference to the fonts it contains.
|
|
|
|
* When a font's refcount decreases to zero, instead of deleting it we
|
|
|
|
* add it to our expiration tracker.
|
|
|
|
* The expiration tracker tracks fonts with zero refcount. After a certain
|
|
|
|
* period of time, such fonts expire and are deleted.
|
|
|
|
*
|
|
|
|
* We're using 3 generations with a ten-second generation interval, so
|
|
|
|
* zero-refcount fonts will be deleted 20-30 seconds after their refcount
|
|
|
|
* goes to zero, if timer events fire in a timely manner.
|
2012-01-05 15:54:45 +04: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 07:32:43 +04:00
|
|
|
*/
|
2012-03-23 16:14:16 +04: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
|
|
|
|
};
|
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
class gfxFontCacheExpirationTracker
|
|
|
|
: public ExpirationTrackerImpl<gfxFont, 3, ::detail::PlaceholderLock,
|
|
|
|
::detail::PlaceholderAutoLock> {
|
2010-06-09 04:33:13 +04:00
|
|
|
protected:
|
2017-08-15 05:04:32 +03:00
|
|
|
typedef ::detail::PlaceholderLock Lock;
|
|
|
|
typedef ::detail::PlaceholderAutoLock AutoLock;
|
|
|
|
|
|
|
|
Lock mLock;
|
|
|
|
|
|
|
|
AutoLock FakeLock() { return AutoLock(mLock); }
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
Lock& GetMutex() override {
|
|
|
|
mozilla::AssertIsMainThreadOrServoFontMetricsLocked();
|
2017-08-15 05:04:32 +03:00
|
|
|
return mLock;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2007-04-04 07:32:43 +04:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum { FONT_TIMEOUT_SECONDS = 10 };
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
gfxFontCacheExpirationTracker(nsIEventTarget* aEventTarget)
|
2014-08-06 01:58:40 +04:00
|
|
|
: ExpirationTrackerImpl<gfxFont, 3, Lock, AutoLock>(
|
2017-06-30 03:52:43 +03:00
|
|
|
FONT_TIMEOUT_SECONDS * 1000, "gfxFontCache", aEventTarget) {}
|
2007-04-04 07:32:43 +04:00
|
|
|
};
|
2012-01-05 15:54:45 +04:00
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
class gfxFontCache final : private gfxFontCacheExpirationTracker {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2017-08-15 05:04:32 +03:00
|
|
|
enum { SHAPED_WORD_TIMEOUT_SECONDS = 60 };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-13 04:59:05 +03:00
|
|
|
explicit gfxFontCache(nsIEventTarget* aEventTarget);
|
2012-01-05 15:54:45 +04:00
|
|
|
~gfxFontCache();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/*
|
2007-04-04 07:32:43 +04:00
|
|
|
* Get the global gfxFontCache. You must call Init() before
|
|
|
|
* calling this method --- the result will not be null.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2007-04-04 07:32:43 +04:00
|
|
|
static gfxFontCache* GetCache() { return gGlobalCache; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
static nsresult Init();
|
|
|
|
// It's OK to call this even if Init() has not been called.
|
|
|
|
static void Shutdown();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
// Look up a font in the cache. Returns null if there's nothing matching
|
|
|
|
// in the cache
|
2017-04-07 00:41:02 +03:00
|
|
|
gfxFont* Lookup(const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle,
|
2017-06-30 01:37:52 +03:00
|
|
|
const gfxCharacterMap* aUnicodeRangeMap);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04: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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
// 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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-06-09 04:33:13 +04:00
|
|
|
// Cleans out the hashtable and removes expired fonts waiting for cleanup.
|
|
|
|
// Other gfxFont objects may be still in use but they will be pushed
|
|
|
|
// into the expiration queues and removed.
|
|
|
|
void Flush() {
|
|
|
|
mFonts.Clear();
|
|
|
|
AgeAllGenerations();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-07-14 05:08:16 +03:00
|
|
|
void FlushShapedWordCaches();
|
2017-05-16 08:30:15 +03:00
|
|
|
void NotifyGlyphsChanged();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-10-15 06:19:47 +04:00
|
|
|
void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
|
|
|
void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
void AgeAllGenerations() { AgeAllGenerationsLocked(FakeLock()); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
void RemoveObject(gfxFont* aFont) { RemoveObjectLocked(aFont, FakeLock()); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
protected:
|
2015-03-21 19:28:04 +03:00
|
|
|
class MemoryReporter final : public nsIMemoryReporter {
|
2014-06-23 22:49:07 +04:00
|
|
|
~MemoryReporter() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMEMORYREPORTER
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2013-05-22 19:48:55 +04:00
|
|
|
// Observer for notifications that the font cache cares about
|
2015-03-21 19:28:04 +03:00
|
|
|
class Observer final : public nsIObserver {
|
2014-06-23 22:49:07 +04:00
|
|
|
~Observer() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
public:
|
2013-12-08 09:39:47 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
2013-05-22 19:48:55 +04:00
|
|
|
NS_DECL_NSIOBSERVER
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
nsresult AddObject(gfxFont* aFont) {
|
|
|
|
return AddObjectLocked(aFont, FakeLock());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
// This gets called when the timeout has expired on a zero-refcount
|
|
|
|
// font; we just delete it.
|
|
|
|
virtual void NotifyExpiredLocked(gfxFont* aFont, const AutoLock&) override {
|
|
|
|
NotifyExpired(aFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
void NotifyExpired(gfxFont* aFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-08-15 05:04:32 +03:00
|
|
|
void DestroyFont(gfxFont* aFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
static gfxFontCache* gGlobalCache;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS Key {
|
2010-07-14 00:31:31 +04:00
|
|
|
const gfxFontEntry* mFontEntry;
|
2007-04-04 07:32:43 +04:00
|
|
|
const gfxFontStyle* mStyle;
|
2014-11-06 07:42:50 +03:00
|
|
|
const gfxCharacterMap* mUnicodeRangeMap;
|
2017-04-07 00:41:02 +03:00
|
|
|
Key(const gfxFontEntry* aFontEntry, const gfxFontStyle* aStyle,
|
2014-11-06 07:42:50 +03:00
|
|
|
const gfxCharacterMap* aUnicodeRangeMap)
|
|
|
|
: mFontEntry(aFontEntry),
|
|
|
|
mStyle(aStyle),
|
|
|
|
mUnicodeRangeMap(aUnicodeRangeMap) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
class HashEntry : public PLDHashEntryHdr {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2007-04-04 07:32:43 +04:00
|
|
|
typedef const Key& KeyType;
|
|
|
|
typedef const Key* KeyTypePointer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
// When constructing a new entry in the hashtable, we'll leave this
|
|
|
|
// blank. The caller of Put() will fill this in.
|
2014-08-06 01:58:40 +04:00
|
|
|
explicit HashEntry(KeyTypePointer aStr) : mFont(nullptr) {}
|
2007-04-04 07:32:43 +04:00
|
|
|
HashEntry(const HashEntry& toCopy) : mFont(toCopy.mFont) {}
|
|
|
|
~HashEntry() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2007-04-04 07:32:43 +04:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
2014-11-06 07:42:50 +03:00
|
|
|
return mozilla::HashGeneric(aKey->mStyle->Hash(), aKey->mFontEntry,
|
|
|
|
aKey->mUnicodeRangeMap);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 03:52:43 +03:00
|
|
|
// The cache tracks gfxFont objects whose refcount has dropped to zero,
|
|
|
|
// so they are not immediately deleted but may be "resurrected" if they
|
|
|
|
// have not yet expired from the tracker when they are needed again.
|
|
|
|
// See the custom AddRef/Release methods in gfxFont.
|
|
|
|
gfxFont* MOZ_UNSAFE_REF("tracking for deferred deletion") mFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2007-04-04 07:32:43 +04:00
|
|
|
nsTHashtable<HashEntry> mFonts;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-01-05 15:54:45 +04:00
|
|
|
static void WordCacheExpirationTimerCallback(nsITimer* aTimer, void* aCache);
|
|
|
|
nsCOMPtr<nsITimer> mWordCacheExpirationTimer;
|
2007-04-04 07:32:43 +04:00
|
|
|
};
|
2005-10-08 09:09:42 +04:00
|
|
|
|
2013-11-25 08:59:56 +04: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 04:51:28 +03:00
|
|
|
uint32_t genericLookups;
|
2013-11-25 08:59:56 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-11-25 08:59:56 +04:00
|
|
|
uint32_t reflowCount;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-11-25 08:59:56 +04:00
|
|
|
// counts per reflow operation
|
|
|
|
TextCounts current;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-11-25 08:59:56 +04:00
|
|
|
// totals for the lifetime of a document
|
|
|
|
TextCounts cumulative;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-11-25 08:59:56 +04:00
|
|
|
gfxTextPerfMetrics() { memset(this, 0, sizeof(gfxTextPerfMetrics)); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-11-25 08:59:56 +04:00
|
|
|
// 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 04:51:28 +03:00
|
|
|
cumulative.genericLookups += current.genericLookups;
|
2013-11-25 08:59:56 +04:00
|
|
|
memset(¤t, 0, sizeof(current));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace gfx {
|
|
|
|
// Flags that live in the gfxShapedText::mFlags field.
|
|
|
|
// (Note that gfxTextRun has an additional mFlags2 field for use
|
|
|
|
// by textrun clients like nsTextFrame.)
|
|
|
|
enum class ShapedTextFlags : uint16_t {
|
|
|
|
/**
|
|
|
|
* When set, the text is RTL.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_IS_RTL = 0x0001,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, spacing is enabled and the textrun needs to call GetSpacing
|
|
|
|
* on the spacing provider.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_ENABLE_SPACING = 0x0002,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, the text has no characters above 255 and it is stored
|
|
|
|
* in the textrun in 8-bit format.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_IS_8BIT = 0x0004,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, GetHyphenationBreaks may return true for some character
|
|
|
|
* positions, otherwise it will always return false for all characters.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_ENABLE_HYPHEN_BREAKS = 0x0008,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, the RunMetrics::mBoundingBox field will be initialized
|
|
|
|
* properly based on glyph extents, in particular, glyph extents that
|
|
|
|
* overflow the standard font-box (the box defined by the ascent, descent
|
|
|
|
* and advance width of the glyph). When not set, it may just be the
|
|
|
|
* standard font-box even if glyphs overflow.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_NEED_BOUNDING_BOX = 0x0010,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, optional ligatures are disabled. Ligatures that are
|
|
|
|
* required for legible text should still be enabled.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_DISABLE_OPTIONAL_LIGATURES = 0x0020,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, the textrun should favour speed of construction over
|
|
|
|
* quality. This may involve disabling ligatures and/or kerning or
|
|
|
|
* other effects.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_OPTIMIZE_SPEED = 0x0040,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, the textrun should discard control characters instead of
|
|
|
|
* turning them into hexboxes.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_HIDE_CONTROL_CHARACTERS = 0x0080,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03: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
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_TRAILING_ARABICCHAR = 0x0100,
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* When set, the previous character for this textrun was an Arabic
|
|
|
|
* character. This is used for the context detection necessary for
|
|
|
|
* bidi.numeral implementation.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_INCOMING_ARABICCHAR = 0x0200,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
/**
|
|
|
|
* Set if the textrun should use the OpenType 'math' script.
|
|
|
|
*/
|
2017-06-25 11:30:28 +03:00
|
|
|
TEXT_USE_MATH_SCRIPT = 0x0400,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-25 11:30:28 +03:00
|
|
|
/*
|
|
|
|
* Bit 0x0800 is currently unused.
|
|
|
|
*/
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03: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 = 0x7000,
|
|
|
|
TEXT_ORIENT_HORIZONTAL = 0x0000,
|
|
|
|
TEXT_ORIENT_VERTICAL_UPRIGHT = 0x1000,
|
|
|
|
TEXT_ORIENT_VERTICAL_SIDEWAYS_RIGHT = 0x2000,
|
|
|
|
TEXT_ORIENT_VERTICAL_MIXED = 0x3000,
|
|
|
|
TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT = 0x4000,
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(ShapedTextFlags)
|
|
|
|
} // namespace gfx
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2013-05-30 01:59:24 +04:00
|
|
|
class gfxTextRunFactory {
|
2017-04-08 01:49:44 +03:00
|
|
|
// Used by stylo
|
|
|
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxTextRunFactory)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
public:
|
2015-12-16 00:56:41 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
/**
|
|
|
|
* This record contains all the parameters needed to initialize a textrun.
|
|
|
|
*/
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS Parameters {
|
2015-12-16 00:56:41 +03:00
|
|
|
// Shape text params suggesting where the textrun will be rendered
|
|
|
|
DrawTarget* mDrawTarget;
|
2011-12-06 16:39:19 +04:00
|
|
|
// 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 19:56:38 +04:00
|
|
|
uint32_t* mInitialBreaks;
|
|
|
|
uint32_t mInitialBreakCount;
|
2011-12-06 16:39:19 +04:00
|
|
|
// The ratio to use to convert device pixels to application layout units
|
2013-01-28 23:01:59 +04:00
|
|
|
int32_t mAppUnitsPerDevUnit;
|
2011-12-06 16:39:19 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-04-04 20:27:02 +04:00
|
|
|
protected:
|
|
|
|
// Protected destructor, to discourage deletion outside of Release():
|
2017-04-08 01:49:44 +03:00
|
|
|
virtual ~gfxTextRunFactory();
|
2011-12-06 16:39:19 +04:00
|
|
|
};
|
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
/**
|
|
|
|
* gfxFontShaper
|
|
|
|
*
|
|
|
|
* This class implements text shaping (character to glyph mapping and
|
|
|
|
* glyph layout). There is a gfxFontShaper subclass for each text layout
|
|
|
|
* technology (uniscribe, core text, harfbuzz,....) we support.
|
|
|
|
*
|
|
|
|
* The shaper is responsible for setting up glyph data in gfxTextRuns.
|
|
|
|
*
|
|
|
|
* A generic, platform-independent shaper relies only on the standard
|
|
|
|
* gfxFont interface and can work with any concrete subclass of gfxFont.
|
|
|
|
*
|
|
|
|
* Platform-specific implementations designed to interface to platform
|
|
|
|
* shaping APIs such as Uniscribe or CoreText may rely on features of a
|
|
|
|
* specific font subclass to access native font references
|
|
|
|
* (such as CTFont, HFONT, DWriteFont, etc).
|
|
|
|
*/
|
|
|
|
|
|
|
|
class gfxFontShaper {
|
|
|
|
public:
|
2015-12-16 00:56:40 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2016-04-21 20:58:59 +03:00
|
|
|
typedef mozilla::unicode::Script Script;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
enum class RoundingFlags : uint8_t { kRoundX = 0x01, kRoundY = 0x02 };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-08-06 01:58:40 +04:00
|
|
|
explicit gfxFontShaper(gfxFont* aFont) : mFont(aFont) {
|
2009-10-07 21:16:52 +04:00
|
|
|
NS_ASSERTION(aFont, "shaper requires a valid font!");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
virtual ~gfxFontShaper() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04: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.
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool ShapeText(DrawTarget* aDrawTarget, const char16_t* aText,
|
2014-05-31 11:12:40 +04:00
|
|
|
uint32_t aOffset, uint32_t aLength, Script aScript,
|
2017-04-03 19:49:17 +03:00
|
|
|
bool aVertical, RoundingFlags aRounding,
|
2014-05-31 11:12:40 +04:00
|
|
|
gfxShapedText* aShapedText) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2009-10-07 21:16:52 +04:00
|
|
|
gfxFont* GetFont() const { return mFont; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-05-20 06:59:20 +04:00
|
|
|
static void MergeFontFeatures(
|
2012-04-26 10:26:03 +04:00
|
|
|
const gfxFontStyle* aStyle, const nsTArray<gfxFontFeature>& aFontFeatures,
|
2018-09-12 22:34:57 +03:00
|
|
|
bool aDisableLigatures, const nsACString& aFamilyName, bool aAddSmallCaps,
|
2015-09-24 18:31:30 +03:00
|
|
|
void (*aHandleFeature)(const uint32_t&, uint32_t&, void*),
|
2015-01-22 09:41:02 +03:00
|
|
|
void* aHandleFeatureData);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2010-03-10 15:46:41 +03:00
|
|
|
protected:
|
2016-04-15 22:45:37 +03:00
|
|
|
// the font this shaper is working with. The font owns a UniquePtr reference
|
2015-05-25 18:32:00 +03:00
|
|
|
// 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 15:46:41 +03:00
|
|
|
};
|
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxFontShaper::RoundingFlags)
|
2014-07-25 12:38:44 +04:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
/*
|
2013-01-04 22:35:37 +04: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
|
2011-12-06 16:39:19 +04:00
|
|
|
* x/y-offsets. 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 22:35:37 +04: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 16:39:19 +04:00
|
|
|
*/
|
2013-01-04 22:35:37 +04:00
|
|
|
class gfxShapedText {
|
2007-01-23 11:45:52 +03:00
|
|
|
public:
|
2016-04-21 20:58:59 +03:00
|
|
|
typedef mozilla::unicode::Script Script;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
gfxShapedText(uint32_t aLength, mozilla::gfx::ShapedTextFlags aFlags,
|
2019-04-02 20:00:47 +03:00
|
|
|
uint16_t aAppUnitsPerDevUnit)
|
2011-12-06 16:39:19 +04:00
|
|
|
: mLength(aLength),
|
2014-09-16 13:58:12 +04:00
|
|
|
mFlags(aFlags),
|
2011-12-06 16:39:19 +04:00
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
virtual ~gfxShapedText() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04: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.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2011-12-06 16:39:19 +04:00
|
|
|
* A character can have zero or more associated glyphs. Each glyph
|
|
|
|
* has an advance width and an x and y offset.
|
|
|
|
* A character may be the start of a cluster.
|
|
|
|
* A character may be the start of a ligature group.
|
|
|
|
* A character can be "missing", indicating that the system is unable
|
2011-12-06 16:39:19 +04:00
|
|
|
* to render the character.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2015-11-28 03:56:33 +03:00
|
|
|
* All characters in a ligature group conceptually share all the glyphs
|
|
|
|
* associated with the characters in a group.
|
2011-12-06 16:39:19 +04:00
|
|
|
*/
|
|
|
|
class CompressedGlyph {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2011-12-06 16:39:19 +04:00
|
|
|
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
|
|
|
|
// is one that fits in the available bits (currently 12) (specified
|
|
|
|
// in appunits).
|
|
|
|
FLAG_IS_SIMPLE_GLYPH = 0x80000000U,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
// Indicates whether a linebreak is allowed before this character;
|
|
|
|
// this is a two-bit field that holds a FLAG_BREAK_TYPE_xxx value
|
|
|
|
// indicating the kind of linebreak (if any) allowed here.
|
2018-03-06 00:57:57 +03:00
|
|
|
FLAGS_CAN_BREAK_BEFORE = 0x60000000U,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
FLAGS_CAN_BREAK_SHIFT = 29,
|
|
|
|
FLAG_BREAK_TYPE_NONE = 0,
|
2011-12-06 16:39:19 +04:00
|
|
|
FLAG_BREAK_TYPE_NORMAL = 1,
|
|
|
|
FLAG_BREAK_TYPE_HYPHEN = 2,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
FLAG_CHAR_IS_SPACE = 0x10000000U,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
// The advance is stored in appunits
|
2017-11-11 18:32:58 +03:00
|
|
|
ADVANCE_MASK = 0x0FFF0000U,
|
|
|
|
ADVANCE_SHIFT = 16,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
GLYPH_MASK = 0x0000FFFFU,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
// Non-simple glyphs may or may not have glyph data in the
|
|
|
|
// corresponding mDetailedGlyphs entry. They have the following
|
|
|
|
// flag bits:
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-11-11 18:32:58 +03:00
|
|
|
// 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
|
2011-12-06 16:39:19 +04:00
|
|
|
// inverted so we can memset the array to zero to indicate all missing.
|
2012-08-22 19:56:38 +04:00
|
|
|
FLAG_NOT_MISSING = 0x01,
|
2012-04-16 16:54:50 +04:00
|
|
|
FLAG_NOT_CLUSTER_START = 0x02,
|
|
|
|
FLAG_NOT_LIGATURE_GROUP_START = 0x04,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-04-16 16:54:50 +04:00
|
|
|
FLAG_CHAR_IS_TAB = 0x08,
|
2015-11-28 03:56:33 +03:00
|
|
|
FLAG_CHAR_IS_NEWLINE = 0x10,
|
2011-12-06 16:39:19 +04:00
|
|
|
// Per CSS Text Decoration Module Level 3, emphasis marks are not
|
|
|
|
// drawn for any character in Unicode categories Z*, Cc, Cf, and Cn
|
2011-12-06 16:39:19 +04:00
|
|
|
// which is not combined with any combining characters. This flag is
|
|
|
|
// set for all those characters except 0x20 whitespace.
|
2015-11-28 03:56:33 +03:00
|
|
|
FLAG_CHAR_NO_EMPHASIS_MARK = 0x20,
|
2018-03-06 00:57:57 +03:00
|
|
|
// Per CSS Text, letter-spacing is not applied to formatting chars
|
|
|
|
// (category Cf). We mark those in the textrun so as to be able to
|
|
|
|
// skip them when setting up spacing in nsTextFrame.
|
|
|
|
FLAG_CHAR_IS_FORMATTING_CONTROL = 0x40,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
CHAR_TYPE_FLAGS_MASK = 0x78,
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
GLYPH_COUNT_MASK = 0x00FFFF00U,
|
2017-10-30 17:55:42 +03:00
|
|
|
GLYPH_COUNT_SHIFT = 8
|
2011-12-06 16:39:19 +04:00
|
|
|
};
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// "Simple glyphs" have a simple glyph ID, simple advance and their
|
|
|
|
// x and y offsets are zero. Also the glyph extents do not overflow
|
|
|
|
// the font-box defined by the font ascent, descent and glyph advance width.
|
|
|
|
// These case is optimized to avoid storing DetailedGlyphs.
|
|
|
|
|
|
|
|
// Returns true if the glyph ID aGlyph fits into the compressed
|
|
|
|
// representation
|
|
|
|
static bool IsSimpleGlyphID(uint32_t aGlyph) {
|
|
|
|
return (aGlyph & GLYPH_MASK) == aGlyph;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2013-01-04 22:35:37 +04:00
|
|
|
// Returns true if the advance aAdvance fits into the compressed
|
|
|
|
// representation. aAdvance is in appunits.
|
|
|
|
static bool IsSimpleAdvance(uint32_t aAdvance) {
|
|
|
|
return (aAdvance & (ADVANCE_MASK >> ADVANCE_SHIFT)) == aAdvance;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
bool IsSimpleGlyph() const { return (mValue & FLAG_IS_SIMPLE_GLYPH) != 0; }
|
|
|
|
uint32_t GetSimpleAdvance() const {
|
|
|
|
return (mValue & ADVANCE_MASK) >> ADVANCE_SHIFT;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetSimpleGlyph() const { return mValue & GLYPH_MASK; }
|
2011-12-06 16:39:19 +04:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
bool IsMissing() const {
|
2013-01-04 22:35:37 +04:00
|
|
|
return (mValue & (FLAG_NOT_MISSING | FLAG_IS_SIMPLE_GLYPH)) == 0;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2013-01-04 22:35:37 +04:00
|
|
|
bool IsClusterStart() const {
|
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) ||
|
|
|
|
!(mValue & FLAG_NOT_CLUSTER_START);
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2014-09-16 15:25:45 +04:00
|
|
|
bool IsLigatureGroupStart() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) ||
|
|
|
|
!(mValue & FLAG_NOT_LIGATURE_GROUP_START);
|
2014-09-16 15:25:45 +04:00
|
|
|
}
|
2014-11-13 11:58:04 +03:00
|
|
|
bool IsLigatureContinuation() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (mValue & FLAG_IS_SIMPLE_GLYPH) == 0 &&
|
|
|
|
(mValue & (FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING)) ==
|
|
|
|
(FLAG_NOT_LIGATURE_GROUP_START | FLAG_NOT_MISSING);
|
2014-11-13 11:58:04 +03:00
|
|
|
}
|
|
|
|
|
2015-09-24 12:23:34 +03: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; }
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool CharIsTab() const {
|
2015-09-24 12:23:34 +03:00
|
|
|
return !IsSimpleGlyph() && (mValue & FLAG_CHAR_IS_TAB) != 0;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
bool CharIsNewline() const {
|
2014-09-16 13:58:12 +04:00
|
|
|
return !IsSimpleGlyph() && (mValue & FLAG_CHAR_IS_NEWLINE) != 0;
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
|
|
|
bool CharMayHaveEmphasisMark() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return !CharIsSpace() &&
|
|
|
|
(IsSimpleGlyph() || !(mValue & FLAG_CHAR_NO_EMPHASIS_MARK));
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
2013-01-28 23:01:59 +04:00
|
|
|
bool CharIsFormattingControl() const {
|
2011-12-06 16:39:19 +04:00
|
|
|
return !IsSimpleGlyph() &&
|
|
|
|
(mValue & FLAG_CHAR_IS_FORMATTING_CONTROL) != 0;
|
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t CharTypeFlags() const {
|
|
|
|
return IsSimpleGlyph() ? 0 : (mValue & CHAR_TYPE_FLAGS_MASK);
|
2011-12-06 16:39:19 +04:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
void SetClusterStart(bool aIsClusterStart) {
|
2012-08-22 19:56:38 +04:00
|
|
|
NS_ASSERTION(!IsSimpleGlyph(),
|
2015-11-28 03:56:33 +03:00
|
|
|
"can't call SetClusterStart on simple glyphs");
|
|
|
|
if (aIsClusterStart) {
|
|
|
|
mValue &= ~FLAG_NOT_CLUSTER_START;
|
2015-11-28 03:56:33 +03:00
|
|
|
} else {
|
2017-10-30 17:55:42 +03:00
|
|
|
mValue |= FLAG_NOT_CLUSTER_START;
|
2015-11-28 03:56:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t CanBreakBefore() const {
|
2013-01-04 22:35:37 +04:00
|
|
|
return (mValue & FLAGS_CAN_BREAK_BEFORE) >> FLAGS_CAN_BREAK_SHIFT;
|
|
|
|
}
|
|
|
|
// Returns FLAGS_CAN_BREAK_BEFORE if the setting changed, 0 otherwise
|
|
|
|
uint32_t SetCanBreakBefore(uint8_t aCanBreakBefore) {
|
2017-04-12 16:55:13 +03:00
|
|
|
NS_ASSERTION(aCanBreakBefore <= 2, "Bogus break-before value!");
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t breakMask = (uint32_t(aCanBreakBefore) << FLAGS_CAN_BREAK_SHIFT);
|
2015-02-19 07:51:06 +03:00
|
|
|
uint32_t toggle = breakMask ^ (mValue & FLAGS_CAN_BREAK_BEFORE);
|
2013-01-04 22:35:37 +04:00
|
|
|
mValue ^= toggle;
|
|
|
|
return toggle;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a CompressedGlyph value representing a simple glyph with
|
|
|
|
// no extra flags (line-break or is_space) set.
|
|
|
|
static CompressedGlyph MakeSimpleGlyph(uint32_t aAdvanceAppUnits,
|
|
|
|
uint32_t aGlyph) {
|
|
|
|
NS_ASSERTION(IsSimpleAdvance(aAdvanceAppUnits), "Advance overflow");
|
|
|
|
NS_ASSERTION(IsSimpleGlyphID(aGlyph), "Glyph overflow");
|
2015-02-19 07:51:06 +03:00
|
|
|
CompressedGlyph g;
|
2017-11-11 18:32:58 +03:00
|
|
|
g.mValue =
|
2015-02-19 07:51:06 +03:00
|
|
|
FLAG_IS_SIMPLE_GLYPH | (aAdvanceAppUnits << ADVANCE_SHIFT) | aGlyph;
|
2017-11-11 18:32:58 +03:00
|
|
|
return g;
|
2013-01-04 22:35:37 +04:00
|
|
|
}
|
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
// Assign a simple glyph value to an existing CompressedGlyph record,
|
2015-03-21 19:28:04 +03:00
|
|
|
// preserving line-break/is-space flags if present.
|
|
|
|
CompressedGlyph& SetSimpleGlyph(uint32_t aAdvanceAppUnits,
|
|
|
|
uint32_t aGlyph) {
|
|
|
|
NS_ASSERTION(!CharTypeFlags(), "Char type flags lost");
|
2013-01-04 22:35:37 +04:00
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
|
|
|
|
MakeSimpleGlyph(aAdvanceAppUnits, aGlyph).mValue;
|
|
|
|
return *this;
|
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// Create a CompressedGlyph value representing a complex glyph record,
|
|
|
|
// without any line-break or char-type flags.
|
|
|
|
static CompressedGlyph MakeComplex(bool aClusterStart, bool aLigatureStart,
|
|
|
|
uint32_t aGlyphCount) {
|
|
|
|
CompressedGlyph g;
|
2017-11-11 18:32:58 +03:00
|
|
|
g.mValue = FLAG_NOT_MISSING |
|
2013-01-04 22:35:37 +04:00
|
|
|
(aClusterStart ? 0 : FLAG_NOT_CLUSTER_START) |
|
2017-11-11 18:32:58 +03:00
|
|
|
(aLigatureStart ? 0 : FLAG_NOT_LIGATURE_GROUP_START) |
|
2013-01-04 22:35:37 +04:00
|
|
|
(aGlyphCount << GLYPH_COUNT_SHIFT);
|
|
|
|
return g;
|
|
|
|
}
|
2012-01-05 15:54:45 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Assign a complex glyph value to an existing CompressedGlyph record,
|
|
|
|
// preserving line-break/char-type flags if present.
|
|
|
|
CompressedGlyph& SetComplex(bool aClusterStart, bool aLigatureStart,
|
|
|
|
uint32_t aGlyphCount) {
|
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
|
|
|
|
CharTypeFlags() |
|
2017-11-11 18:32:58 +03:00
|
|
|
MakeComplex(aClusterStart, aLigatureStart, aGlyphCount).mValue;
|
2014-09-16 13:58:12 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Missing glyphs are treated as ligature group starts; don't mess with
|
2011-12-06 16:39:19 +04:00
|
|
|
* the cluster-start flag (see bugs 618870 and 619286).
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
CompressedGlyph& SetMissing(uint32_t aGlyphCount) {
|
2012-04-16 16:54:50 +04:00
|
|
|
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_NOT_CLUSTER_START |
|
2014-09-16 13:58:12 +04:00
|
|
|
FLAG_CHAR_IS_SPACE)) |
|
|
|
|
CharTypeFlags() | (aGlyphCount << GLYPH_COUNT_SHIFT);
|
2011-12-06 16:39:19 +04:00
|
|
|
return *this;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t GetGlyphCount() const {
|
2011-12-06 16:39:19 +04:00
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
2011-12-06 16:39:19 +04:00
|
|
|
return (mValue & GLYPH_COUNT_MASK) >> GLYPH_COUNT_SHIFT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-04-16 16:54:50 +04:00
|
|
|
void SetIsSpace() { mValue |= FLAG_CHAR_IS_SPACE; }
|
2011-12-06 16:39:19 +04:00
|
|
|
void SetIsTab() {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
mValue |= FLAG_CHAR_IS_TAB;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
void SetIsNewline() {
|
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
|
|
|
mValue |= FLAG_CHAR_IS_NEWLINE;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-28 03:56:33 +03:00
|
|
|
void SetNoEmphasisMark() {
|
2011-12-06 16:39:19 +04:00
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
2015-11-28 03:56:33 +03:00
|
|
|
mValue |= FLAG_CHAR_NO_EMPHASIS_MARK;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-03-06 00:57:57 +03:00
|
|
|
void SetIsFormattingControl() {
|
2011-12-06 16:39:19 +04:00
|
|
|
NS_ASSERTION(!IsSimpleGlyph(), "Expected non-simple-glyph");
|
2018-03-06 00:57:57 +03:00
|
|
|
mValue |= FLAG_CHAR_IS_FORMATTING_CONTROL;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mValue;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// Accessor for the array of CompressedGlyph records, which will be in
|
|
|
|
// a different place in gfxShapedWord vs gfxTextRun
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual const CompressedGlyph* GetCharacterGlyphs() const = 0;
|
2016-06-27 19:41:55 +03:00
|
|
|
virtual CompressedGlyph* GetCharacterGlyphs() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2011-12-06 16:39:19 +04:00
|
|
|
* When the glyphs for a character don't fit into a CompressedGlyph record
|
|
|
|
* in SimpleGlyph format, we use an array of DetailedGlyphs instead.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2011-12-06 16:39:19 +04:00
|
|
|
struct DetailedGlyph {
|
2017-10-30 17:55:42 +03:00
|
|
|
// The glyphID, or the Unicode character if this is a missing glyph
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mGlyphID;
|
2017-10-30 17:55:42 +03:00
|
|
|
// The advance of the glyph, in appunits.
|
|
|
|
// mAdvance is in the text direction (RTL or LTR),
|
|
|
|
// and will normally be non-negative (although this is not guaranteed)
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mAdvance;
|
2014-09-16 13:58:12 +04:00
|
|
|
// The offset from the glyph's default position, in line-relative
|
|
|
|
// coordinates (so mOffset.x is an offset in the line-right direction,
|
2017-10-30 17:55:42 +03:00
|
|
|
// and mOffset.y is an offset in line-downwards direction).
|
|
|
|
// These values are in floating-point appUnits.
|
|
|
|
mozilla::gfx::Point mOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
void SetGlyphs(uint32_t aCharIndex, CompressedGlyph aGlyph,
|
2011-12-06 16:39:19 +04:00
|
|
|
const DetailedGlyph* aGlyphs);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
void SetMissingGlyph(uint32_t aIndex, uint32_t aChar, gfxFont* aFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
void SetIsSpace(uint32_t aIndex) {
|
|
|
|
GetCharacterGlyphs()[aIndex].SetIsSpace();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
bool HasDetailedGlyphs() const { return mDetailedGlyphs != nullptr; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
bool IsLigatureGroupStart(uint32_t aPos) {
|
2014-09-16 13:58:12 +04:00
|
|
|
NS_ASSERTION(aPos < GetLength(), "aPos out of range");
|
2013-01-04 22:35:37 +04:00
|
|
|
return GetCharacterGlyphs()[aPos].IsLigatureGroupStart();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04: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.
|
2016-06-27 19:41:55 +03:00
|
|
|
DetailedGlyph* GetDetailedGlyphs(uint32_t aCharIndex) const {
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(GetCharacterGlyphs() && HasDetailedGlyphs() &&
|
|
|
|
!GetCharacterGlyphs()[aCharIndex].IsSimpleGlyph() &&
|
|
|
|
GetCharacterGlyphs()[aCharIndex].GetGlyphCount() > 0,
|
|
|
|
"invalid use of GetDetailedGlyphs; check the caller!");
|
|
|
|
return mDetailedGlyphs->Get(aCharIndex);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void AdjustAdvancesForSyntheticBold(float aSynBoldOffset, uint32_t aOffset,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aLength);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Mark clusters in the CompressedGlyph records, starting at aOffset,
|
2013-01-04 22:35:37 +04:00
|
|
|
// 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, const char16_t* aString,
|
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags GetFlags() const { return mFlags; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-24 12:23:34 +03:00
|
|
|
bool IsVertical() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (GetFlags() & mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_MASK) !=
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_HORIZONTAL;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-09-24 12:23:34 +03:00
|
|
|
bool UseCenterBaseline() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags orient =
|
|
|
|
GetFlags() & mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_MASK;
|
|
|
|
return orient ==
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_MIXED ||
|
2018-11-30 13:46:48 +03:00
|
|
|
orient ==
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_UPRIGHT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
bool IsRightToLeft() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (GetFlags() & mozilla::gfx::ShapedTextFlags::TEXT_IS_RTL) ==
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_IS_RTL;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-09-24 12:23:34 +03:00
|
|
|
bool IsSidewaysLeft() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (GetFlags() & mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_MASK) ==
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_ORIENT_VERTICAL_SIDEWAYS_LEFT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2015-09-24 12:23:34 +03:00
|
|
|
// Return true if the logical inline direction is reversed compared to
|
|
|
|
// normal physical coordinates (i.e. if it is leftwards or upwards)
|
2011-12-06 16:39:19 +04:00
|
|
|
bool IsInlineReversed() const { return IsSidewaysLeft() != IsRightToLeft(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat GetDirection() const { return IsInlineReversed() ? -1.0f : 1.0f; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
bool DisableLigatures() const {
|
2017-05-05 00:27:05 +03:00
|
|
|
return (GetFlags() &
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_DISABLE_OPTIONAL_LIGATURES) ==
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_DISABLE_OPTIONAL_LIGATURES;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool TextIs8Bit() const {
|
|
|
|
return (GetFlags() & mozilla::gfx::ShapedTextFlags::TEXT_IS_8BIT) ==
|
|
|
|
mozilla::gfx::ShapedTextFlags::TEXT_IS_8BIT;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t GetAppUnitsPerDevUnit() const { return mAppUnitsPerDevUnit; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t GetLength() const { return mLength; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
bool FilterIfIgnorable(uint32_t aIndex, uint32_t aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
protected:
|
2011-12-06 16:39:19 +04:00
|
|
|
// Allocate aCount DetailedGlyphs for the given index
|
2012-08-22 19:56:38 +04:00
|
|
|
DetailedGlyph* AllocateDetailedGlyphs(uint32_t aCharIndex, uint32_t aCount);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
// Ensure the glyph on the given index is complex glyph so that we can use
|
2014-09-16 13:58:12 +04:00
|
|
|
// it to record specific characters that layout may need to detect.
|
2015-11-28 03:56:33 +03:00
|
|
|
void EnsureComplexGlyph(uint32_t aIndex, CompressedGlyph& aGlyph) {
|
|
|
|
MOZ_ASSERT(GetCharacterGlyphs() + aIndex == &aGlyph);
|
|
|
|
if (aGlyph.IsSimpleGlyph()) {
|
2011-12-06 16:39:19 +04:00
|
|
|
DetailedGlyph details = {aGlyph.GetSimpleGlyph(),
|
2015-11-28 03:56:33 +03:00
|
|
|
(int32_t)aGlyph.GetSimpleAdvance(),
|
2017-10-30 17:55:42 +03:00
|
|
|
mozilla::gfx::Point()};
|
2014-09-16 13:58:12 +04:00
|
|
|
SetGlyphs(aIndex, CompressedGlyph().SetComplex(true, true, 1), &details);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-12-06 16:39:19 +04: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 {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
DetailedGlyphStore() : mLastUsed(0) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
// 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.
|
2013-01-04 22:35:37 +04:00
|
|
|
// NOTE that this must not be called for a character offset that does
|
|
|
|
// not have any DetailedGlyph records; callers must have verified that
|
2014-09-16 13:58:12 +04:00
|
|
|
// mCharacterGlyphs[aOffset].GetGlyphCount() is greater than zero
|
2011-12-06 16:39:19 +04:00
|
|
|
// before calling this, otherwise the assertions here will fire (in a
|
|
|
|
// debug build), and we'll probably crash.
|
2012-08-22 19:56:38 +04:00
|
|
|
DetailedGlyph* Get(uint32_t aOffset) {
|
2011-12-06 16:39:19 +04: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2014-09-16 13:58:12 +04:00
|
|
|
mLastUsed = mOffsetToIndex.BinaryIndexOf(aOffset, CompareToOffset());
|
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
NS_ASSERTION(mLastUsed != nsTArray<DGRec>::NoIndex,
|
|
|
|
"detailed glyph record missing!");
|
|
|
|
return details + mOffsetToIndex[mLastUsed].mIndex;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
DetailedGlyph* Allocate(uint32_t aOffset, uint32_t aCount) {
|
|
|
|
uint32_t detailIndex = mDetails.Length();
|
2011-12-06 16:39:19 +04: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 17:56:41 +04:00
|
|
|
mOffsetToIndex.AppendElement(DGRec(aOffset, detailIndex));
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2014-07-08 17:56:41 +04:00
|
|
|
mOffsetToIndex.InsertElementSorted(DGRec(aOffset, detailIndex),
|
|
|
|
CompareRecordOffsets());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2011-12-06 16:39:19 +04:00
|
|
|
return details;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-06-23 16:03:39 +04:00
|
|
|
size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
|
2012-01-25 12:52:51 +04:00
|
|
|
return aMallocSizeOf(this) +
|
2015-07-29 09:24:24 +03:00
|
|
|
mDetails.ShallowSizeOfExcludingThis(aMallocSizeOf) +
|
|
|
|
mOffsetToIndex.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-12-06 16:39:19 +04:00
|
|
|
struct DGRec {
|
2012-08-22 19:56:38 +04:00
|
|
|
DGRec(const uint32_t& aOffset, const uint32_t& aIndex)
|
2011-12-06 16:39:19 +04:00
|
|
|
: mOffset(aOffset), mIndex(aIndex) {}
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mOffset; // source character offset in the textrun
|
|
|
|
uint32_t mIndex; // index where this char's DetailedGlyphs begin
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-04-21 20:58:59 +03:00
|
|
|
struct CompareToOffset {
|
|
|
|
bool Equals(const DGRec& a, const uint32_t& b) const {
|
2014-09-16 13:58:12 +04:00
|
|
|
return a.mOffset == b;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2012-08-22 19:56:38 +04:00
|
|
|
bool LessThan(const DGRec& a, const uint32_t& b) const {
|
2011-12-06 16:39:19 +04:00
|
|
|
return a.mOffset < b;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-04-12 16:55:13 +03:00
|
|
|
struct CompareRecordOffsets {
|
2011-12-06 16:39:19 +04:00
|
|
|
bool Equals(const DGRec& a, const DGRec& b) const {
|
|
|
|
return a.mOffset == b.mOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-04-12 16:55:13 +03:00
|
|
|
bool LessThan(const DGRec& a, const DGRec& b) const {
|
|
|
|
return a.mOffset < b.mOffset;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2017-04-12 16:55:13 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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.
|
2011-12-06 16:39:19 +04:00
|
|
|
nsTArray<DetailedGlyph> mDetails;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
mozilla::UniquePtr<DetailedGlyphStore> mDetailedGlyphs;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
// Number of char16_t characters and CompressedGlyph glyph records
|
2016-04-21 20:58:59 +03:00
|
|
|
uint32_t mLength;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-04-12 16:55:13 +03:00
|
|
|
// Shaping flags (direction, ligature-suppression)
|
|
|
|
mozilla::gfx::ShapedTextFlags mFlags;
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
uint16_t mAppUnitsPerDevUnit;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2018-11-30 13:46:48 +03:00
|
|
|
/*
|
2013-01-04 22:35:37 +04:00
|
|
|
* gfxShapedWord: an individual (space-delimited) run of text shaped with a
|
|
|
|
* particular font, without regard to external context.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2013-01-04 22:35:37 +04:00
|
|
|
* The glyph data is copied into gfxTextRuns as needed from the cache of
|
|
|
|
* ShapedWords associated with each gfxFont instance.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2015-11-28 03:56:33 +03:00
|
|
|
class gfxShapedWord final : public gfxShapedText {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2016-04-21 20:58:59 +03:00
|
|
|
typedef mozilla::unicode::Script Script;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// Create a ShapedWord that can hold glyphs for aLength characters,
|
|
|
|
// with mCharacterGlyphs sized appropriately.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2013-01-04 22:35:37 +04:00
|
|
|
// Returns null on allocation failure (does NOT use infallible alloc)
|
|
|
|
// so caller must check for success.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2013-01-04 22:35:37 +04:00
|
|
|
// 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,
|
2019-04-02 20:00:47 +03:00
|
|
|
Script aRunScript, uint16_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
2017-04-12 16:55:13 +03:00
|
|
|
gfxFontShaper::RoundingFlags aRounding) {
|
2013-09-11 05:36:57 +04:00
|
|
|
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
|
|
|
|
"excessive length for gfxShapedWord!");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04: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 07:51:06 +03:00
|
|
|
void* storage = malloc(size);
|
2013-01-04 22:35:37 +04:00
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// Construct in the pre-allocated storage, using placement new
|
|
|
|
return new (storage) gfxShapedWord(aText, aLength, aRunScript,
|
2017-04-12 16:55:13 +03:00
|
|
|
aAppUnitsPerDevUnit, aFlags, aRounding);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
static gfxShapedWord* Create(const char16_t* aText, uint32_t aLength,
|
2019-04-02 20:00:47 +03:00
|
|
|
Script aRunScript, uint16_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
2017-04-12 16:55:13 +03:00
|
|
|
gfxFontShaper::RoundingFlags aRounding) {
|
2013-09-11 05:36:57 +04:00
|
|
|
NS_ASSERTION(aLength <= gfxPlatform::GetPlatform()->WordCacheCharLimit(),
|
|
|
|
"excessive length for gfxShapedWord!");
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// In the 16-bit version of Create, if the TEXT_IS_8BIT flag is set,
|
2013-01-04 22:35:37 +04:00
|
|
|
// then we convert the text to an 8-bit version and call the 8-bit
|
|
|
|
// Create function instead.
|
2017-05-05 00:27:05 +03:00
|
|
|
if (aFlags & mozilla::gfx::ShapedTextFlags::TEXT_IS_8BIT) {
|
2013-01-04 22:35:37 +04:00
|
|
|
nsAutoCString narrowText;
|
|
|
|
LossyAppendUTF16toASCII(nsDependentSubstring(aText, aLength), narrowText);
|
|
|
|
return Create((const uint8_t*)(narrowText.BeginReading()), aLength,
|
2017-04-12 16:55:13 +03:00
|
|
|
aRunScript, aAppUnitsPerDevUnit, aFlags, aRounding);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t size = offsetof(gfxShapedWord, mCharGlyphsStorage) +
|
2014-01-04 19:02:17 +04:00
|
|
|
aLength * (sizeof(CompressedGlyph) + sizeof(char16_t));
|
2015-02-19 07:51:06 +03:00
|
|
|
void* storage = malloc(size);
|
2013-01-04 22:35:37 +04:00
|
|
|
if (!storage) {
|
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
return new (storage) gfxShapedWord(aText, aLength, aRunScript,
|
2017-04-12 16:55:13 +03:00
|
|
|
aAppUnitsPerDevUnit, aFlags, aRounding);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2010-07-14 00:31:31 +04:00
|
|
|
// Override operator delete to properly free the object that was
|
2015-02-19 07:51:06 +03:00
|
|
|
// allocated via malloc.
|
2013-01-04 22:35:37 +04:00
|
|
|
void operator delete(void* p) { free(p); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
virtual const CompressedGlyph* GetCharacterGlyphs() const override {
|
|
|
|
return &mCharGlyphsStorage[0];
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2016-06-27 19:41:55 +03:00
|
|
|
virtual CompressedGlyph* GetCharacterGlyphs() override {
|
|
|
|
return &mCharGlyphsStorage[0];
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
const uint8_t* Text8Bit() const {
|
|
|
|
NS_ASSERTION(TextIs8Bit(), "invalid use of Text8Bit()");
|
2014-09-16 13:58:12 +04:00
|
|
|
return reinterpret_cast<const uint8_t*>(mCharGlyphsStorage + GetLength());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
const char16_t* TextUnicode() const {
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(!TextIs8Bit(), "invalid use of TextUnicode()");
|
2014-09-16 13:58:12 +04:00
|
|
|
return reinterpret_cast<const char16_t*>(mCharGlyphsStorage + GetLength());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t GetCharAt(uint32_t aOffset) const {
|
2013-01-04 22:35:37 +04:00
|
|
|
NS_ASSERTION(aOffset < GetLength(), "aOffset out of range");
|
|
|
|
return TextIs8Bit() ? char16_t(Text8Bit()[aOffset])
|
2014-09-16 13:58:12 +04:00
|
|
|
: TextUnicode()[aOffset];
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2018-09-12 22:34:57 +03:00
|
|
|
Script GetScript() const { return mScript; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-12 16:55:13 +03:00
|
|
|
gfxFontShaper::RoundingFlags GetRounding() const { return mRounding; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void ResetAge() { mAgeCounter = 0; }
|
|
|
|
uint32_t IncrementAge() { return ++mAgeCounter; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-09-16 13:58:12 +04:00
|
|
|
// so that gfxTextRun can share our DetailedGlyphStore class
|
|
|
|
friend class gfxTextRun;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Construct storage for a ShapedWord, ready to receive glyph data
|
2013-01-04 22:35:37 +04:00
|
|
|
gfxShapedWord(const uint8_t* aText, uint32_t aLength, Script aRunScript,
|
2019-04-02 20:00:47 +03:00
|
|
|
uint16_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
2017-04-12 16:55:13 +03:00
|
|
|
gfxFontShaper::RoundingFlags aRounding)
|
2017-05-05 00:27:05 +03:00
|
|
|
: gfxShapedText(aLength,
|
|
|
|
aFlags | mozilla::gfx::ShapedTextFlags::TEXT_IS_8BIT,
|
2014-09-16 13:58:12 +04:00
|
|
|
aAppUnitsPerDevUnit),
|
|
|
|
mScript(aRunScript),
|
2017-04-12 16:55:13 +03:00
|
|
|
mRounding(aRounding),
|
2014-09-16 13:58:12 +04:00
|
|
|
mAgeCounter(0) {
|
|
|
|
memset(mCharGlyphsStorage, 0, aLength * sizeof(CompressedGlyph));
|
|
|
|
uint8_t* text = reinterpret_cast<uint8_t*>(&mCharGlyphsStorage[aLength]);
|
|
|
|
memcpy(text, aText, aLength * sizeof(uint8_t));
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
gfxShapedWord(const char16_t* aText, uint32_t aLength, Script aRunScript,
|
2019-04-02 20:00:47 +03:00
|
|
|
uint16_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
2017-04-12 16:55:13 +03:00
|
|
|
gfxFontShaper::RoundingFlags aRounding)
|
2014-09-16 13:58:12 +04:00
|
|
|
: gfxShapedText(aLength, aFlags, aAppUnitsPerDevUnit),
|
|
|
|
mScript(aRunScript),
|
2017-04-12 16:55:13 +03:00
|
|
|
mRounding(aRounding),
|
2014-09-16 13:58:12 +04:00
|
|
|
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);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-04-21 20:58:59 +03:00
|
|
|
Script mScript;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
gfxFontShaper::RoundingFlags mRounding;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mAgeCounter;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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;
|
2015-11-28 03:56:33 +03:00
|
|
|
struct EmphasisMarkDrawParams;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
class gfxFont {
|
|
|
|
friend class gfxHarfBuzzShaper;
|
|
|
|
friend class gfxGraphiteShaper;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
protected:
|
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2016-04-21 20:58:59 +03:00
|
|
|
typedef mozilla::unicode::Script Script;
|
2016-07-22 16:56:09 +03:00
|
|
|
typedef mozilla::SVGContextPaint SVGContextPaint;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
typedef gfxFontShaper::RoundingFlags RoundingFlags;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
public:
|
2018-04-23 17:52:20 +03:00
|
|
|
typedef mozilla::FontSlantStyle FontSlantStyle;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
nsrefcnt AddRef(void) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt");
|
2014-09-16 13:58:12 +04:00
|
|
|
if (mExpirationState.IsTracked()) {
|
|
|
|
gfxFontCache::GetCache()->RemoveObject(this);
|
|
|
|
}
|
|
|
|
++mRefCnt;
|
|
|
|
NS_LOG_ADDREF(this, mRefCnt, "gfxFont", sizeof(*this));
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
|
|
|
nsrefcnt Release(void) {
|
2018-04-28 22:50:58 +03:00
|
|
|
MOZ_ASSERT(0 != mRefCnt, "dup release");
|
2014-09-16 13:58:12 +04:00
|
|
|
--mRefCnt;
|
|
|
|
NS_LOG_RELEASE(this, mRefCnt, "gfxFont");
|
|
|
|
if (mRefCnt == 0) {
|
|
|
|
NotifyReleased();
|
|
|
|
// |this| may have been deleted.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return mRefCnt;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t GetRefCount() { return mRefCnt; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// options to specify the kind of AA to be used when creating a font
|
|
|
|
typedef enum : uint8_t {
|
2017-04-07 00:41:02 +03:00
|
|
|
kAntialiasDefault,
|
2014-09-16 13:58:12 +04:00
|
|
|
kAntialiasNone,
|
|
|
|
kAntialiasGrayscale,
|
|
|
|
kAntialiasSubpixel
|
|
|
|
} AntialiasOption;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
protected:
|
|
|
|
nsAutoRefCnt mRefCnt;
|
|
|
|
cairo_scaled_font_t* mScaledFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void NotifyReleased() {
|
|
|
|
gfxFontCache* cache = gfxFontCache::GetCache();
|
|
|
|
if (cache) {
|
|
|
|
// Don't delete just yet; return the object to the cache for
|
|
|
|
// possibly recycling within some time limit
|
|
|
|
cache->NotifyReleased(this);
|
|
|
|
} else {
|
|
|
|
// The cache may have already been shut down.
|
|
|
|
delete this;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont(const RefPtr<mozilla::gfx::UnscaledFont>& aUnscaledFont,
|
|
|
|
gfxFontEntry* aFontEntry, const gfxFontStyle* aFontStyle,
|
|
|
|
AntialiasOption anAAOption = kAntialiasDefault,
|
|
|
|
cairo_scaled_font_t* aScaledFont = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
public:
|
|
|
|
virtual ~gfxFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-06 16:39:19 +04:00
|
|
|
bool Valid() const { return mIsValid; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// options for the kind of bounding box to return from measurement
|
|
|
|
typedef enum {
|
|
|
|
LOOSE_INK_EXTENTS,
|
|
|
|
// A box that encloses all the painted pixels, and may
|
|
|
|
// include sidebearings and/or additional ascent/descent
|
|
|
|
// within the glyph cell even if the ink is smaller.
|
|
|
|
TIGHT_INK_EXTENTS,
|
|
|
|
// A box that tightly encloses all the painted pixels
|
|
|
|
// (although actually on Windows, at least, it may be
|
|
|
|
// slightly larger than strictly necessary because
|
|
|
|
// we can't get precise extents with ClearType).
|
|
|
|
TIGHT_HINTED_OUTLINE_EXTENTS
|
|
|
|
// A box that tightly encloses the glyph outline,
|
|
|
|
// ignoring possible antialiasing pixels that extend
|
|
|
|
// beyond this.
|
2015-11-02 11:36:50 +03:00
|
|
|
// NOTE: The default implementation of gfxFont::Measure(),
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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
|
2015-02-02 12:19:28 +03:00
|
|
|
// 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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-02 12:19:28 +03:00
|
|
|
const nsCString& GetName() const { return mFontEntry->Name(); }
|
|
|
|
const gfxFontStyle* GetStyle() const { return &mStyle; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-02 12:19:28 +03:00
|
|
|
cairo_scaled_font_t* GetCairoScaledFont() { return mScaledFont; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-02 12:19:28 +03:00
|
|
|
virtual mozilla::UniquePtr<gfxFont> CopyWithAntialiasOption(
|
2014-09-16 13:58:12 +04:00
|
|
|
AntialiasOption anAAOption) {
|
|
|
|
// platforms where this actually matters should override
|
|
|
|
return nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat GetAdjustedSize() const {
|
|
|
|
return mAdjustedSize > 0.0 ? mAdjustedSize
|
|
|
|
: (mStyle.sizeAdjust == 0.0 ? 0.0 : mStyle.size);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
float FUnitsToDevUnitsFactor() const {
|
|
|
|
// check this was set up during font initialization
|
|
|
|
NS_ASSERTION(mFUnitsConvFactor >= 0.0f, "mFUnitsConvFactor not valid");
|
|
|
|
return mFUnitsConvFactor;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// check whether this is an sfnt we can potentially use with harfbuzz
|
|
|
|
bool FontCanSupportHarfBuzz() { return mFontEntry->HasCmapTable(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-01-19 13:46:53 +03:00
|
|
|
// check whether this is an sfnt we can potentially use with Graphite
|
|
|
|
bool FontCanSupportGraphite() { return mFontEntry->HasGraphiteTables(); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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'));
|
2013-01-04 22:35:37 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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)
|
2015-12-16 00:56:41 +03:00
|
|
|
bool SupportsFeature(Script aScript, uint32_t aFeatureTag);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
// whether the font supports "real" small caps, petite caps etc.
|
|
|
|
// aFallbackToSmallCaps true when petite caps should fallback to small caps
|
|
|
|
bool SupportsVariantCaps(Script aScript, uint32_t aVariantCaps,
|
2014-09-16 13:58:12 +04:00
|
|
|
bool& aFallbackToSmallCaps,
|
2017-04-03 19:49:17 +03:00
|
|
|
bool& aSyntheticLowerToSmallCaps,
|
2014-09-16 13:58:12 +04:00
|
|
|
bool& aSyntheticUpperToSmallCaps);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-03 19:49:17 +03:00
|
|
|
// whether the font supports subscript/superscript feature
|
|
|
|
// for fallback, need to verify that all characters in the run
|
2014-09-16 13:58:12 +04:00
|
|
|
// have variant substitutions
|
|
|
|
bool SupportsSubSuperscript(uint32_t aSubSuperscript, const uint8_t* aString,
|
|
|
|
uint32_t aLength, Script aRunScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool SupportsSubSuperscript(uint32_t aSubSuperscript, const char16_t* aString,
|
|
|
|
uint32_t aLength, Script aRunScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// whether the specified feature will apply to the given character
|
|
|
|
bool FeatureWillHandleChar(Script aRunScript, uint32_t aFeature,
|
|
|
|
uint32_t aUnicode);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Subclasses may choose to look up glyph ids for characters.
|
|
|
|
// If they do not override this, gfxHarfBuzzShaper will fetch the cmap
|
|
|
|
// table and use that.
|
|
|
|
virtual bool ProvidesGetGlyph() const { return false; }
|
|
|
|
// Map unicode character to glyph ID.
|
|
|
|
// Only used if ProvidesGetGlyph() returns true.
|
2014-09-30 10:38:26 +04:00
|
|
|
virtual uint32_t GetGlyph(uint32_t unicode, uint32_t variation_selector) {
|
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-30 10:38:26 +04:00
|
|
|
// Return the horizontal advance of a glyph.
|
|
|
|
gfxFloat GetGlyphHAdvance(DrawTarget* aDrawTarget, uint16_t aGID);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat SynthesizeSpaceWidth(uint32_t aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Work out whether cairo will snap inter-glyph spacing to pixels
|
|
|
|
// when rendering to the given drawTarget.
|
|
|
|
RoundingFlags GetRoundOffsetsToPixels(DrawTarget* aDrawTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Font metrics
|
|
|
|
struct Metrics {
|
2016-08-18 12:43:54 +03:00
|
|
|
gfxFloat capHeight;
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat xHeight;
|
|
|
|
gfxFloat strikeoutSize;
|
|
|
|
gfxFloat strikeoutOffset;
|
|
|
|
gfxFloat underlineSize;
|
|
|
|
gfxFloat underlineOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat internalLeading;
|
|
|
|
gfxFloat externalLeading;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat emHeight;
|
|
|
|
gfxFloat emAscent;
|
|
|
|
gfxFloat emDescent;
|
|
|
|
gfxFloat maxHeight;
|
|
|
|
gfxFloat maxAscent;
|
|
|
|
gfxFloat maxDescent;
|
|
|
|
gfxFloat maxAdvance;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat aveCharWidth;
|
|
|
|
gfxFloat spaceWidth;
|
2019-03-21 07:50:41 +03:00
|
|
|
gfxFloat zeroWidth; // -1 if there was no zero glyph
|
|
|
|
|
|
|
|
gfxFloat ZeroOrAveCharWidth() const {
|
|
|
|
return zeroWidth >= 0 ? zeroWidth : aveCharWidth;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2019-04-01 17:32:19 +03:00
|
|
|
typedef nsFontMetrics::FontOrientation Orientation;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
const Metrics& GetMetrics(Orientation aOrientation) {
|
2019-04-01 17:32:19 +03:00
|
|
|
if (aOrientation == nsFontMetrics::eHorizontal) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return GetHorizontalMetrics();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-30 10:38:26 +04:00
|
|
|
if (!mVerticalMetrics) {
|
2014-09-16 13:58:12 +04:00
|
|
|
mVerticalMetrics = CreateVerticalMetrics();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-30 10:38:26 +04:00
|
|
|
return *mVerticalMetrics;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04: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.
|
|
|
|
*/
|
2017-10-24 11:59:09 +03:00
|
|
|
struct Spacing {
|
2017-05-05 00:27:05 +03:00
|
|
|
gfxFloat mBefore;
|
2015-11-28 03:56:33 +03:00
|
|
|
gfxFloat mAfter;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2015-11-28 03:56:33 +03:00
|
|
|
/**
|
|
|
|
* Metrics for a particular string
|
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
struct RunMetrics {
|
|
|
|
RunMetrics() { mAdvanceWidth = mAscent = mDescent = 0.0; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void CombineWith(const RunMetrics& aOther, bool aOtherIsOnLeft);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
// For zero-width substrings, these must be zero!
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat mAscent; // always non-negative
|
|
|
|
gfxFloat mDescent; // always non-negative
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04: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
|
2015-12-16 00:56:40 +03:00
|
|
|
* .spacing spacing to insert before and after characters (for RTL
|
|
|
|
* glyphs, before-spacing is inserted to the right of characters). There
|
2014-09-16 13:58:12 +04:00
|
|
|
* are aEnd - aStart elements in this array, unless it's null to indicate
|
|
|
|
* that there is no spacing.
|
2015-12-16 00:56:40 +03:00
|
|
|
* .drawMode specifies whether the fill or stroke of the glyph should be
|
2018-05-09 15:49:24 +03:00
|
|
|
* drawn, or if it should be drawn into the current path
|
2018-07-04 17:56:40 +03:00
|
|
|
* .contextPaint information about how to construct the fill and
|
2014-09-16 13:58:12 +04:00
|
|
|
* 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
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Callers guarantee:
|
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
|
|
|
* -- all glyphs use this font
|
|
|
|
*/
|
|
|
|
void Draw(const gfxTextRun* aTextRun, uint32_t aStart, uint32_t aEnd,
|
|
|
|
mozilla::gfx::Point* aPt, const TextRunDrawParams& aRunParams,
|
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Draw the emphasis marks for the given text run. Its prerequisite
|
|
|
|
* and output are similiar to the method Draw().
|
2014-11-06 07:42:50 +03:00
|
|
|
* @param aPt the baseline origin of the emphasis marks.
|
|
|
|
* @param aParams some drawing parameters, see EmphasisMarkDrawParams.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-11-06 07:42:50 +03:00
|
|
|
void DrawEmphasisMarks(const gfxTextRun* aShapedText,
|
2014-09-16 13:58:12 +04:00
|
|
|
mozilla::gfx::Point* aPt, uint32_t aOffset,
|
|
|
|
uint32_t aCount,
|
|
|
|
const EmphasisMarkDrawParams& aParams);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04: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
|
2014-09-16 15:25:45 +04:00
|
|
|
* an approximation to the area actually painted by glyphs.
|
2015-12-16 00:56:41 +03:00
|
|
|
* @param aDrawTargetForTightBoundingBox when aTight is true, this must
|
|
|
|
* be non-null.
|
2018-05-11 10:56:12 +03:00
|
|
|
* @param aSpacing spacing to insert before and after glyphs. The bounding box
|
|
|
|
* need not include the spacing itself, but the spacing affects the glyph
|
2017-05-05 00:27:05 +03:00
|
|
|
* positions. null if there is no spacing.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Callers guarantee:
|
2017-05-05 00:27:05 +03:00
|
|
|
* -- aStart and aEnd are aligned to cluster and ligature boundaries
|
2014-09-16 13:58:12 +04:00
|
|
|
* -- all glyphs use this font
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2017-05-05 00:27:05 +03:00
|
|
|
* The default implementation just uses font metrics and aTextRun's
|
2014-09-16 15:25:45 +04:00
|
|
|
* advances, and assumes no characters fall outside the font box. In
|
2014-09-16 13:58:12 +04:00
|
|
|
* general this is insufficient, because that assumption is not always true.
|
|
|
|
*/
|
|
|
|
virtual RunMetrics Measure(const gfxTextRun* aTextRun, uint32_t aStart,
|
|
|
|
uint32_t aEnd, BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTargetForTightBoundingBox,
|
2014-09-16 13:58:12 +04:00
|
|
|
Spacing* aSpacing,
|
2017-10-20 13:20:18 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2014-09-16 13:58:12 +04: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.
|
2011-12-06 16:39:19 +04:00
|
|
|
* @return true if anything was changed, false otherwise
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
bool NotifyLineBreaksChanged(gfxTextRun* aTextRun, uint32_t aStart,
|
|
|
|
uint32_t aLength) {
|
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Expiration tracking
|
|
|
|
nsExpirationState* GetExpirationState() { return &mExpirationState; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the glyphID of a space
|
|
|
|
virtual uint32_t GetSpaceGlyph() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxGlyphExtents* GetOrCreateGlyphExtents(int32_t aAppUnitsPerDevUnit);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-16 00:56:40 +03:00
|
|
|
// You need to call SetupCairoFont on aDrawTarget just before calling this.
|
2017-06-01 17:42:07 +03:00
|
|
|
void SetupGlyphExtents(DrawTarget* aDrawTarget, uint32_t aGlyphID,
|
|
|
|
bool aNeedTight, gfxGlyphExtents* aExtents);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// This is called by the default Draw() implementation above.
|
2015-12-16 00:56:40 +03:00
|
|
|
virtual bool SetupCairoFont(DrawTarget* aDrawTarget) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual bool AllowSubpixelAA() { return true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-09 15:49:24 +03:00
|
|
|
bool IsSyntheticBold() const { return mApplySyntheticBold; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-05-09 15:49:24 +03:00
|
|
|
float AngleForSyntheticOblique() const;
|
|
|
|
float SkewForSyntheticOblique() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontEntry* GetFontEntry() const { return mFontEntry.get(); }
|
|
|
|
bool HasCharacter(uint32_t ch) {
|
2014-11-06 07:42:50 +03:00
|
|
|
if (!mIsValid || (mUnicodeRangeMap && !mUnicodeRangeMap->test(ch))) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return mFontEntry->HasCharacter(ch);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
const gfxCharacterMap* GetUnicodeRangeMap() const {
|
|
|
|
return mUnicodeRangeMap.get();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
void SetUnicodeRangeMap(gfxCharacterMap* aUnicodeRangeMap) {
|
|
|
|
mUnicodeRangeMap = aUnicodeRangeMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-11-11 00:41:41 +03:00
|
|
|
uint16_t GetUVSGlyph(uint32_t aCh, uint32_t aVS) {
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!mIsValid) {
|
2011-12-06 16:39:19 +04:00
|
|
|
return 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
return mFontEntry->GetUVSGlyph(aCh, aVS);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
template <typename T>
|
2015-12-16 00:56:41 +03:00
|
|
|
bool InitFakeSmallCapsRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
2013-01-04 22:35:37 +04:00
|
|
|
const T* aText, uint32_t aOffset, uint32_t aLength,
|
2019-04-01 17:32:06 +03:00
|
|
|
FontMatchType aMatchType,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScript, bool aSyntheticLower,
|
2014-09-16 15:25:45 +04:00
|
|
|
bool aSyntheticUpper);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2013-01-04 22:35:37 +04:00
|
|
|
// call the (virtual) InitTextRun method to do glyph generation/shaping,
|
2014-09-16 13:58:12 +04:00
|
|
|
// limiting the length of text passed by processing the run in multiple
|
|
|
|
// segments if necessary
|
|
|
|
template <typename T>
|
2017-06-01 17:42:07 +03:00
|
|
|
bool SplitAndInitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
2016-06-27 19:41:55 +03:00
|
|
|
const T* aString, uint32_t aRunStart,
|
2018-01-19 13:46:53 +03:00
|
|
|
uint32_t aRunLength, Script aRunScript,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get a ShapedWord representing the given text (either 8- or 16-bit)
|
|
|
|
// for use in setting up a gfxTextRun.
|
|
|
|
template <typename T>
|
2015-12-16 00:56:41 +03:00
|
|
|
gfxShapedWord* GetShapedWord(DrawTarget* aDrawTarget, const T* aText,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t aLength, uint32_t aHash,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aRunScript, bool aVertical,
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextPerfMetrics* aTextPerf);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Ensure the ShapedWord cache is initialized. This MUST be called before
|
|
|
|
// any attempt to use GetShapedWord().
|
|
|
|
void InitWordCache() {
|
|
|
|
if (!mWordCache) {
|
2016-04-15 22:45:37 +03:00
|
|
|
mWordCache = mozilla::MakeUnique<nsTHashtable<CacheHashEntry>>();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04: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 05:08:16 +03:00
|
|
|
void AgeCachedWords();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Discard all cached word records; called on memory-pressure notification.
|
|
|
|
void ClearCachedWords() {
|
|
|
|
if (mWordCache) {
|
|
|
|
mWordCache->Clear();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Glyph rendering/geometry has changed, so invalidate data as necessary.
|
|
|
|
void NotifyGlyphsChanged();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual void AddSizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
|
|
|
virtual void AddSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf,
|
|
|
|
FontCacheSizes* aSizes) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
typedef enum {
|
|
|
|
FONT_TYPE_DWRITE,
|
|
|
|
FONT_TYPE_GDI,
|
|
|
|
FONT_TYPE_FT2,
|
|
|
|
FONT_TYPE_MAC,
|
|
|
|
FONT_TYPE_OS2,
|
2016-07-20 22:07:11 +03:00
|
|
|
FONT_TYPE_CAIRO,
|
|
|
|
FONT_TYPE_FONTCONFIG
|
2014-09-16 13:58:12 +04:00
|
|
|
} FontType;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual FontType GetType() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
const RefPtr<mozilla::gfx::UnscaledFont>& GetUnscaledFont() const {
|
|
|
|
return mUnscaledFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-08-07 23:20:44 +03:00
|
|
|
virtual already_AddRefed<mozilla::gfx::ScaledFont> GetScaledFont(
|
|
|
|
DrawTarget* aTarget) = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-07-04 17:56:40 +03:00
|
|
|
void InitializeScaledFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool KerningDisabled() { return mKerningSet && !mKerningEnabled; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Subclass this object to be notified of glyph changes. Delete the object
|
|
|
|
* when no longer needed.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
class GlyphChangeObserver {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual ~GlyphChangeObserver() {
|
|
|
|
if (mFont) {
|
|
|
|
mFont->RemoveGlyphChangeObserver(this);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
// This gets called when the gfxFont dies.
|
|
|
|
void ForgetFont() { mFont = nullptr; }
|
|
|
|
virtual void NotifyGlyphsChanged() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
protected:
|
|
|
|
explicit GlyphChangeObserver(gfxFont* aFont) : mFont(aFont) {
|
|
|
|
mFont->AddGlyphChangeObserver(this);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-05-22 15:23:00 +03:00
|
|
|
// This pointer is nulled by ForgetFont in the gfxFont's
|
|
|
|
// destructor. Before the gfxFont dies.
|
|
|
|
gfxFont* MOZ_NON_OWNING_REF mFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
friend class GlyphChangeObserver;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool GlyphsMayChange() {
|
|
|
|
// Currently only fonts with SVG glyphs can have animated glyphs
|
|
|
|
return mFontEntry->TryGetSVGData(this);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
static void DestroySingletons() {
|
|
|
|
delete sScriptTagToCode;
|
|
|
|
delete sDefaultFeatures;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 21:47:18 +03:00
|
|
|
// Call TryGetMathTable() to try and load the Open Type MATH table.
|
|
|
|
// If (and ONLY if) TryGetMathTable() has returned true, the MathTable()
|
|
|
|
// method may be called to access the gfxMathTable data.
|
|
|
|
bool TryGetMathTable();
|
|
|
|
gfxMathTable* MathTable() {
|
|
|
|
MOZ_RELEASE_ASSERT(mMathTable,
|
|
|
|
"A successful call to TryGetMathTable() must be "
|
|
|
|
"performed before calling this function");
|
|
|
|
return mMathTable.get();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
// Return a cloned font resized and offset to simulate sub/superscript
|
|
|
|
// glyphs. This does not add a reference to the returned font.
|
|
|
|
gfxFont* GetSubSuperscriptFont(int32_t aAppUnitsPerDevPixel);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2015-12-16 07:10:04 +03:00
|
|
|
* Return the reference cairo_t object from aDT.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2015-12-16 07:10:04 +03:00
|
|
|
static cairo_t* RefCairo(mozilla::gfx::DrawTarget* aDT);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
protected:
|
2014-09-30 10:37:40 +04:00
|
|
|
virtual const Metrics& GetHorizontalMetrics() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-10 03:38:58 +03:00
|
|
|
mozilla::UniquePtr<const Metrics> CreateVerticalMetrics();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-24 17:06:45 +03:00
|
|
|
// Template parameters for DrawGlyphs/DrawOneGlyph, used to select
|
|
|
|
// simplified versions of the methods in the most common cases.
|
|
|
|
enum class FontComplexityT { SimpleFont, ComplexFont };
|
|
|
|
enum class SpacingT { NoSpacing, HasSpacing };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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.
|
2017-10-24 17:06:45 +03:00
|
|
|
template <FontComplexityT FC, SpacingT S>
|
2017-10-24 11:59:09 +03:00
|
|
|
bool DrawGlyphs(const gfxShapedText* aShapedText,
|
|
|
|
uint32_t aOffset, // offset in the textrun
|
|
|
|
uint32_t aCount, // length of run to draw
|
|
|
|
mozilla::gfx::Point* aPt, GlyphBufferAzure& aBuffer);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-24 17:06:45 +03:00
|
|
|
// Output a single glyph at *aPt.
|
|
|
|
// 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).
|
|
|
|
template <FontComplexityT FC>
|
|
|
|
void DrawOneGlyph(uint32_t aGlyphID, const mozilla::gfx::Point& aPt,
|
|
|
|
GlyphBufferAzure& aBuffer, bool* aEmittedGlyphs) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-24 17:06:45 +03:00
|
|
|
// Helper for DrawOneGlyph to handle missing glyphs, rendering either
|
|
|
|
// nothing (for default-ignorables) or a missing-glyph hexbox.
|
|
|
|
bool DrawMissingGlyph(const TextRunDrawParams& aRunParams,
|
|
|
|
const FontDrawParams& aFontParams,
|
|
|
|
const gfxShapedText::DetailedGlyph* aDetails,
|
|
|
|
const mozilla::gfx::Point& aPt);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// set the font size and offset used for
|
|
|
|
// synthetic subscript/superscript glyphs
|
|
|
|
void CalculateSubSuperSizeAndOffset(int32_t aAppUnitsPerDevPixel,
|
|
|
|
gfxFloat& aSubSuperSizeRatio,
|
|
|
|
float& aBaselineOffset);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Return a font that is a "clone" of this one, but reduced to 80% size
|
2017-06-30 01:37:52 +03:00
|
|
|
// (and with variantCaps set to normal). This does not add a reference to
|
|
|
|
// the returned font.
|
|
|
|
gfxFont* GetSmallCapsFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// The return value is interpreted as a horizontal advance in 16.16 fixed
|
|
|
|
// point format.
|
2018-12-31 14:43:27 +03:00
|
|
|
virtual int32_t GetGlyphWidth(uint16_t aGID) { return -1; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-12-16 00:56:41 +03:00
|
|
|
bool IsSpaceGlyphInvisible(DrawTarget* aRefDrawTarget,
|
2016-06-27 19:41:55 +03:00
|
|
|
const gfxTextRun* aTextRun);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void AddGlyphChangeObserver(GlyphChangeObserver* aObserver);
|
|
|
|
void RemoveGlyphChangeObserver(GlyphChangeObserver* aObserver);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// whether font contains substitution lookups containing spaces
|
2016-04-21 20:58:59 +03:00
|
|
|
bool HasSubstitutionRulesWithSpaceLookups(Script aRunScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// do spaces participate in shaping rules? if so, can't used word cache
|
2016-04-21 20:58:59 +03:00
|
|
|
bool SpaceMayParticipateInShaping(Script aRunScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// For 8-bit text, expand to 16-bit and then call the following method.
|
2015-12-16 00:56:41 +03:00
|
|
|
bool ShapeText(DrawTarget* aContext, const uint8_t* aText,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t aOffset, // dest offset in gfxShapedText
|
2016-04-21 20:58:59 +03:00
|
|
|
uint32_t aLength, Script aScript, bool aVertical,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxShapedText* aShapedText); // where to store the result
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Call the appropriate shaper to generate glyphs for aText and store
|
|
|
|
// them into aShapedText.
|
2015-12-16 00:56:41 +03:00
|
|
|
virtual bool ShapeText(DrawTarget* aContext, const char16_t* aText,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aOffset, uint32_t aLength, Script aScript,
|
2017-04-03 19:49:17 +03:00
|
|
|
bool aVertical, RoundingFlags aRounding,
|
2015-12-16 00:56:40 +03:00
|
|
|
gfxShapedText* aShapedText);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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.
|
2015-12-16 00:56:40 +03:00
|
|
|
void PostShapingFixup(DrawTarget* aContext, const char16_t* aText,
|
|
|
|
uint32_t aOffset, // position within aShapedText
|
2016-04-21 20:58:59 +03:00
|
|
|
uint32_t aLength, bool aVertical,
|
2015-12-16 00:56:40 +03:00
|
|
|
gfxShapedText* aShapedText);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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
|
2018-11-30 13:46:48 +03:00
|
|
|
// text.
|
2014-09-16 13:58:12 +04:00
|
|
|
template <typename T>
|
2015-12-16 00:56:41 +03:00
|
|
|
bool ShapeTextWithoutWordCache(DrawTarget* aDrawTarget, const T* aText,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aOffset, uint32_t aLength,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScript, bool aVertical,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding, gfxTextRun* aTextRun);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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>
|
2015-12-16 00:56:41 +03:00
|
|
|
bool ShapeFragmentWithoutWordCache(DrawTarget* aDrawTarget, const T* aText,
|
2013-01-04 22:35:37 +04:00
|
|
|
uint32_t aOffset, uint32_t aLength,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScript, bool aVertical,
|
2017-04-03 19:49:17 +03:00
|
|
|
RoundingFlags aRounding,
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxTextRun* aTextRun);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void CheckForFeaturesInvolvingSpace();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// used when analyzing whether a font has space contextual lookups
|
2016-04-21 20:58:59 +03:00
|
|
|
static nsDataHashtable<nsUint32HashKey, Script>* sScriptTagToCode;
|
|
|
|
static nsTHashtable<nsUint32HashKey>* sDefaultFeatures;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFontEntry> mFontEntry;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
struct CacheHashKey {
|
2018-11-30 13:46:48 +03:00
|
|
|
union {
|
2014-09-16 13:58:12 +04:00
|
|
|
const uint8_t* mSingle;
|
|
|
|
const char16_t* mDouble;
|
2018-11-30 13:46:48 +03:00
|
|
|
} mText;
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t mLength;
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags mFlags;
|
2016-04-21 20:58:59 +03:00
|
|
|
Script mScript;
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t mAppUnitsPerDevUnit;
|
|
|
|
PLDHashNumber mHashKey;
|
|
|
|
bool mTextIs8Bit;
|
2017-04-12 16:55:13 +03:00
|
|
|
RoundingFlags mRounding;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
CacheHashKey(const uint8_t* aText, uint32_t aLength, uint32_t aStringHash,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScriptCode, int32_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags, RoundingFlags aRounding)
|
2014-09-16 13:58:12 +04:00
|
|
|
: mLength(aLength),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mScript(aScriptCode),
|
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
|
2017-04-12 16:55:13 +03:00
|
|
|
mHashKey(aStringHash + static_cast<int32_t>(aScriptCode) +
|
|
|
|
aAppUnitsPerDevUnit * 0x100 + uint16_t(aFlags) * 0x10000 +
|
|
|
|
int(aRounding)),
|
|
|
|
mTextIs8Bit(true),
|
|
|
|
mRounding(aRounding) {
|
2017-05-05 00:27:05 +03:00
|
|
|
NS_ASSERTION(aFlags & mozilla::gfx::ShapedTextFlags::TEXT_IS_8BIT,
|
2014-09-16 13:58:12 +04:00
|
|
|
"8-bit flag should have been set");
|
|
|
|
mText.mSingle = aText;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
CacheHashKey(const char16_t* aText, uint32_t aLength, uint32_t aStringHash,
|
2016-04-21 20:58:59 +03:00
|
|
|
Script aScriptCode, int32_t aAppUnitsPerDevUnit,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags, RoundingFlags aRounding)
|
2014-09-16 13:58:12 +04:00
|
|
|
: mLength(aLength),
|
|
|
|
mFlags(aFlags),
|
|
|
|
mScript(aScriptCode),
|
|
|
|
mAppUnitsPerDevUnit(aAppUnitsPerDevUnit),
|
2017-04-12 16:55:13 +03:00
|
|
|
mHashKey(aStringHash + static_cast<int32_t>(aScriptCode) +
|
|
|
|
aAppUnitsPerDevUnit * 0x100 + uint16_t(aFlags) * 0x10000 +
|
|
|
|
int(aRounding)),
|
|
|
|
mTextIs8Bit(false),
|
|
|
|
mRounding(aRounding) {
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class CacheHashEntry : public PLDHashEntryHdr {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
typedef const CacheHashKey& KeyType;
|
|
|
|
typedef const CacheHashKey* KeyTypePointer;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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");
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
~CacheHashEntry() {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool KeyEquals(const KeyTypePointer aKey) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
static KeyTypePointer KeyToPointer(KeyType aKey) { return &aKey; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
static PLDHashNumber HashKey(const KeyTypePointer aKey) {
|
|
|
|
return aKey->mHashKey;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
return aMallocSizeOf(mShapedWord.get());
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
enum { ALLOW_MEMMOVE = true };
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<gfxShapedWord> mShapedWord;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<nsTHashtable<CacheHashEntry>> mWordCache;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
static const uint32_t kShapedWordCacheMaxAge = 3;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-04-19 19:13:28 +03:00
|
|
|
nsTArray<mozilla::UniquePtr<gfxGlyphExtents>> mGlyphExtentsArray;
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<nsTHashtable<nsPtrHashKey<GlyphChangeObserver>>>
|
|
|
|
mGlyphChangeObservers;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// a copy of the font without antialiasing, if needed for separate
|
|
|
|
// measurement by mathml code
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<gfxFont> mNonAAFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<gfxFontShaper> mHarfBuzzShaper;
|
|
|
|
mozilla::UniquePtr<gfxFontShaper> mGraphiteShaper;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-11-06 07:42:50 +03:00
|
|
|
// if a userfont with unicode-range specified, contains map of *possible*
|
|
|
|
// ranges supported by font
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxCharacterMap> mUnicodeRangeMap;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-04-07 00:41:02 +03:00
|
|
|
RefPtr<mozilla::gfx::UnscaledFont> mUnscaledFont;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::ScaledFont> mAzureScaledFont;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-30 10:38:06 +04:00
|
|
|
// For vertical metrics, created on demand.
|
2016-04-15 22:45:37 +03:00
|
|
|
mozilla::UniquePtr<const Metrics> mVerticalMetrics;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-11-02 21:47:18 +03:00
|
|
|
// Table used for MathML layout.
|
|
|
|
mozilla::UniquePtr<gfxMathTable> mMathTable;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
gfxFontStyle mStyle;
|
|
|
|
gfxFloat mAdjustedSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
// Conversion factor from font units to dev units; note that this may be
|
|
|
|
// zero (in the degenerate case where mAdjustedSize has become zero).
|
|
|
|
// This is OK because we only multiply by this factor, never divide.
|
|
|
|
float mFUnitsConvFactor;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
nsExpirationState mExpirationState;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-25 20:54:03 +03:00
|
|
|
// the AA setting requested for this font - may affect glyph bounds
|
|
|
|
AntialiasOption mAntialiasOption;
|
2011-03-22 17:59:25 +03:00
|
|
|
|
2017-10-24 17:06:45 +03:00
|
|
|
bool mIsValid;
|
2012-12-19 13:42:25 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// use synthetic bolding for environments where this is not supported
|
|
|
|
// by the platform
|
|
|
|
bool mApplySyntheticBold;
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mKerningSet; // kerning explicitly set?
|
|
|
|
bool mKerningEnabled; // if set, on or off?
|
2011-12-06 16:39:19 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mMathInitialized; // TryGetMathTable() called?
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Helper for subclasses that want to initialize standard metrics from the
|
|
|
|
// tables of sfnt (TrueType/OpenType) fonts.
|
|
|
|
// This will use mFUnitsConvFactor if it is already set, else compute it
|
|
|
|
// from mAdjustedSize and the unitsPerEm in the font's 'head' table.
|
|
|
|
// Returns TRUE and sets mIsValid=TRUE if successful;
|
|
|
|
// Returns TRUE but leaves mIsValid=FALSE if the font seems to be broken.
|
|
|
|
// Returns FALSE if the font does not appear to be an sfnt at all,
|
|
|
|
// and should be handled (if possible) using other APIs.
|
|
|
|
bool InitMetricsFromSfntTables(Metrics& aMetrics);
|
2011-12-06 16:39:18 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Helper to calculate various derived metrics from the results of
|
|
|
|
// InitMetricsFromSfntTables or equivalent platform code
|
|
|
|
void CalculateDerivedMetrics(Metrics& aMetrics);
|
2013-11-22 01:31:53 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// some fonts have bad metrics, this method sanitize them.
|
|
|
|
// if this font has bad underline offset, aIsBadUnderlineFont should be true.
|
|
|
|
void SanitizeMetrics(Metrics* aMetrics, bool aIsBadUnderlineFont);
|
2013-11-22 01:31:53 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool RenderSVGGlyph(gfxContext* aContext, mozilla::gfx::Point aPoint,
|
|
|
|
uint32_t aGlyphId, SVGContextPaint* aContextPaint) const;
|
2017-10-24 11:59:09 +03:00
|
|
|
bool RenderSVGGlyph(gfxContext* aContext, mozilla::gfx::Point aPoint,
|
2016-07-22 16:56:09 +03:00
|
|
|
uint32_t aGlyphId, SVGContextPaint* aContextPaint,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextRunDrawCallbacks* aCallbacks,
|
|
|
|
bool& aEmittedGlyphs) const;
|
2008-03-13 05:36:58 +03:00
|
|
|
|
2016-04-15 22:45:37 +03:00
|
|
|
bool RenderColorGlyph(DrawTarget* aDrawTarget, gfxContext* aContext,
|
|
|
|
mozilla::gfx::ScaledFont* scaledFont,
|
|
|
|
mozilla::gfx::DrawOptions drawOptions,
|
|
|
|
const mozilla::gfx::Point& aPoint,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t aGlyphId) const;
|
2008-08-06 08:34:06 +04:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Bug 674909. When synthetic bolding text by drawing twice, need to
|
|
|
|
// render using a pixel offset in device pixels, otherwise text
|
2014-11-06 07:42:50 +03:00
|
|
|
// doesn't appear bolded, it appears as if a bad text shadow exists
|
2018-04-25 20:54:03 +03:00
|
|
|
// when a non-identity transform exists. Use an offset factor so that
|
2014-09-16 13:58:12 +04:00
|
|
|
// 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.
|
2017-10-27 16:16:49 +03:00
|
|
|
static mozilla::gfx::Float CalcXScale(DrawTarget* aDrawTarget);
|
2014-09-16 13:58:12 +04:00
|
|
|
};
|
2010-02-24 10:18:49 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// proportion of ascent used for x-height, if unable to read value from font
|
|
|
|
#define DEFAULT_XHEIGHT_FACTOR 0.56f
|
2007-03-05 00:05:10 +03:00
|
|
|
|
2014-09-16 13:58:12 +04: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.
|
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS TextRunDrawParams {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::DrawTarget> dt;
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxContext* context;
|
|
|
|
gfxFont::Spacing* spacing;
|
|
|
|
gfxTextRunDrawCallbacks* callbacks;
|
2016-07-22 16:56:09 +03:00
|
|
|
mozilla::SVGContextPaint* runContextPaint;
|
2017-10-27 16:16:49 +03:00
|
|
|
mozilla::gfx::Float direction;
|
2017-10-27 00:08:29 +03:00
|
|
|
double devPerApp;
|
2016-04-22 20:40:39 +03:00
|
|
|
nscolor textStrokeColor;
|
2016-07-14 03:00:00 +03:00
|
|
|
gfxPattern* textStrokePattern;
|
|
|
|
const mozilla::gfx::StrokeOptions* strokeOpts;
|
|
|
|
const mozilla::gfx::DrawOptions* drawOpts;
|
2014-09-16 13:58:12 +04:00
|
|
|
DrawMode drawMode;
|
2014-10-01 23:25:48 +04:00
|
|
|
bool isVerticalRun;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool isRTL;
|
|
|
|
bool paintSVGGlyphs;
|
|
|
|
};
|
2009-10-07 19:26:58 +04:00
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS FontDrawParams {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::gfx::ScaledFont> scaledFont;
|
2016-07-22 16:56:09 +03:00
|
|
|
mozilla::SVGContextPaint* contextPaint;
|
2017-10-27 16:16:49 +03:00
|
|
|
mozilla::gfx::Float synBoldOnePixelOffset;
|
2018-05-09 15:49:24 +03:00
|
|
|
mozilla::gfx::Float obliqueSkew;
|
2014-09-16 13:58:12 +04:00
|
|
|
int32_t extraStrikes;
|
|
|
|
mozilla::gfx::DrawOptions drawOptions;
|
2018-01-17 15:51:20 +03:00
|
|
|
gfxFloat advanceDirection;
|
2014-10-01 23:25:48 +04:00
|
|
|
bool isVerticalFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
bool haveSVGGlyphs;
|
|
|
|
bool haveColorGlyphs;
|
2005-11-29 23:12:29 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS EmphasisMarkDrawParams {
|
2015-11-28 03:56:33 +03:00
|
|
|
gfxContext* context;
|
|
|
|
gfxFont::Spacing* spacing;
|
|
|
|
gfxTextRun* mark;
|
|
|
|
gfxFloat advance;
|
|
|
|
gfxFloat direction;
|
|
|
|
bool isVertical;
|
|
|
|
};
|
|
|
|
|
2005-10-08 09:09:42 +04:00
|
|
|
#endif
|