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:
|
2014-09-16 13:58:12 +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/. */
|
|
|
|
|
|
|
|
#ifndef GFX_TEXTRUN_H
|
|
|
|
#define GFX_TEXTRUN_H
|
|
|
|
|
2017-06-06 02:03:02 +03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxTypes.h"
|
|
|
|
#include "gfxPoint.h"
|
|
|
|
#include "gfxFont.h"
|
2015-09-29 04:51:28 +03:00
|
|
|
#include "gfxFontConstants.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "gfxSkipChars.h"
|
|
|
|
#include "gfxPlatform.h"
|
2019-04-27 18:37:58 +03:00
|
|
|
#include "gfxPlatformFontList.h"
|
2019-07-03 18:14:24 +03:00
|
|
|
#include "gfxUserFontSet.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2017-06-06 02:03:02 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "nsPoint.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsTArray.h"
|
|
|
|
#include "nsTextFrameUtils.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
#include "DrawMode.h"
|
|
|
|
#include "harfbuzz/hb.h"
|
2014-12-22 19:35:54 +03:00
|
|
|
#include "nsUnicodeScriptCodes.h"
|
2016-04-22 20:40:39 +03:00
|
|
|
#include "nsColor.h"
|
2017-06-06 02:03:02 +03:00
|
|
|
#include "X11UndefineNone.h"
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
# include <stdio.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
class gfxContext;
|
|
|
|
class gfxFontGroup;
|
2017-10-03 01:05:19 +03:00
|
|
|
class nsAtom;
|
2015-04-03 22:39:23 +03:00
|
|
|
class nsLanguageAtomService;
|
2014-12-22 19:35:54 +03:00
|
|
|
class gfxMissingFontRecorder;
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2016-07-22 16:56:09 +03:00
|
|
|
namespace mozilla {
|
2019-04-27 18:37:58 +03:00
|
|
|
class PostTraversalTask;
|
2016-07-22 16:56:09 +03:00
|
|
|
class SVGContextPaint;
|
2017-01-04 18:55:16 +03:00
|
|
|
enum class StyleHyphens : uint8_t;
|
2016-07-22 16:56:09 +03:00
|
|
|
}; // namespace mozilla
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Callback for Draw() to use when drawing text with mode
|
|
|
|
* DrawMode::GLYPH_PATH.
|
|
|
|
*/
|
|
|
|
struct gfxTextRunDrawCallbacks {
|
|
|
|
/**
|
|
|
|
* Constructs a new DrawCallbacks object.
|
|
|
|
*
|
2015-02-18 01:01:54 +03:00
|
|
|
* @param aShouldPaintSVGGlyphs If true, SVG glyphs will be painted. If
|
|
|
|
* false, SVG glyphs will not be painted; fallback plain glyphs are not
|
|
|
|
* emitted either.
|
2014-09-16 13:58:12 +04:00
|
|
|
*/
|
|
|
|
explicit gfxTextRunDrawCallbacks(bool aShouldPaintSVGGlyphs = false)
|
|
|
|
: mShouldPaintSVGGlyphs(aShouldPaintSVGGlyphs) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Called when a path has been emitted to the gfxContext when
|
|
|
|
* painting a text run. This can be called any number of times,
|
|
|
|
* due to partial ligatures and intervening SVG glyphs.
|
|
|
|
*/
|
|
|
|
virtual void NotifyGlyphPathEmitted() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mShouldPaintSVGGlyphs;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gfxTextRun is an abstraction for drawing and measuring substrings of a run
|
|
|
|
* of text. It stores runs of positioned glyph data, each run having a single
|
|
|
|
* gfxFont. The glyphs are associated with a string of source text, and the
|
|
|
|
* gfxTextRun APIs take parameters that are offsets into that source text.
|
2017-01-04 18:55:16 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* gfxTextRuns are mostly immutable. The only things that can change are
|
|
|
|
* inter-cluster spacing and line break placement. Spacing is always obtained
|
|
|
|
* lazily by methods that need it, it is not cached. Line breaks are stored
|
|
|
|
* persistently (insofar as they affect the shaping of glyphs; gfxTextRun does
|
|
|
|
* not actually do anything to explicitly account for line breaks). Initially
|
|
|
|
* there are no line breaks. The textrun can record line breaks before or after
|
|
|
|
* any given cluster. (Line breaks specified inside clusters are ignored.)
|
2017-01-04 18:55:16 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* It is important that zero-length substrings are handled correctly. This will
|
|
|
|
* be on the test!
|
|
|
|
*/
|
2016-08-19 15:14:22 +03:00
|
|
|
class gfxTextRun : public gfxShapedText {
|
|
|
|
NS_INLINE_DECL_REFCOUNTING(gfxTextRun);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
protected:
|
2014-09-16 13:58:12 +04:00
|
|
|
// Override operator delete to properly free the object that was
|
2015-02-19 07:51:06 +03:00
|
|
|
// allocated via malloc.
|
2014-09-16 13:58:12 +04:00
|
|
|
void operator delete(void* p) { free(p); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual ~gfxTextRun();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
typedef gfxFont::RunMetrics Metrics;
|
2015-12-16 00:56:41 +03:00
|
|
|
typedef mozilla::gfx::DrawTarget DrawTarget;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Public textrun API for general use
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-22 22:39:36 +03:00
|
|
|
bool IsClusterStart(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2014-09-16 13:58:12 +04:00
|
|
|
return mCharacterGlyphs[aPos].IsClusterStart();
|
|
|
|
}
|
2015-02-22 22:39:36 +03:00
|
|
|
bool IsLigatureGroupStart(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2014-09-16 13:58:12 +04:00
|
|
|
return mCharacterGlyphs[aPos].IsLigatureGroupStart();
|
|
|
|
}
|
2015-02-22 22:39:36 +03:00
|
|
|
bool CanBreakLineBefore(uint32_t aPos) const {
|
|
|
|
return CanBreakBefore(aPos) == CompressedGlyph::FLAG_BREAK_TYPE_NORMAL;
|
|
|
|
}
|
|
|
|
bool CanHyphenateBefore(uint32_t aPos) const {
|
|
|
|
return CanBreakBefore(aPos) == CompressedGlyph::FLAG_BREAK_TYPE_HYPHEN;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-22 22:39:36 +03:00
|
|
|
// Returns a gfxShapedText::CompressedGlyph::FLAG_BREAK_TYPE_* value
|
|
|
|
// as defined in gfxFont.h (may be NONE, NORMAL or HYPHEN).
|
|
|
|
uint8_t CanBreakBefore(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2015-02-22 22:39:36 +03:00
|
|
|
return mCharacterGlyphs[aPos].CanBreakBefore();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-02-22 22:39:36 +03:00
|
|
|
bool CharIsSpace(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2014-09-16 13:58:12 +04:00
|
|
|
return mCharacterGlyphs[aPos].CharIsSpace();
|
|
|
|
}
|
2015-02-22 22:39:36 +03:00
|
|
|
bool CharIsTab(uint32_t aPos) const {
|
2017-05-04 20:31:28 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2018-03-06 00:57:57 +03:00
|
|
|
return mCharacterGlyphs[aPos].CharIsTab();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 15:25:45 +04:00
|
|
|
bool CharIsNewline(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2014-09-16 13:58:12 +04:00
|
|
|
return mCharacterGlyphs[aPos].CharIsNewline();
|
|
|
|
}
|
2015-02-22 22:39:36 +03:00
|
|
|
bool CharMayHaveEmphasisMark(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2014-09-16 13:58:12 +04:00
|
|
|
return mCharacterGlyphs[aPos].CharMayHaveEmphasisMark();
|
|
|
|
}
|
2015-11-28 03:56:33 +03:00
|
|
|
bool CharIsFormattingControl(uint32_t aPos) const {
|
2016-05-25 02:54:37 +03:00
|
|
|
MOZ_ASSERT(aPos < GetLength());
|
2015-11-28 03:56:33 +03:00
|
|
|
return mCharacterGlyphs[aPos].CharIsFormattingControl();
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-06 00:57:57 +03:00
|
|
|
// All offsets are in terms of the string passed into MakeTextRun.
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-03-06 00:57:57 +03:00
|
|
|
// Describe range [start, end) of a text run. The range is
|
|
|
|
// restricted to grapheme cluster boundaries.
|
2016-03-08 10:56:18 +03:00
|
|
|
struct Range {
|
|
|
|
uint32_t start;
|
|
|
|
uint32_t end;
|
2018-03-06 00:57:57 +03:00
|
|
|
uint32_t Length() const { return end - start; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
Range() : start(0), end(0) {}
|
2018-03-06 00:57:57 +03:00
|
|
|
Range(uint32_t aStart, uint32_t aEnd) : start(aStart), end(aEnd) {}
|
|
|
|
explicit Range(const gfxTextRun* aTextRun)
|
|
|
|
: start(0), end(aTextRun->GetLength()) {}
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
// All coordinates are in layout/app units
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2016-03-08 10:56:18 +03:00
|
|
|
* Set the potential linebreaks for a substring of the textrun. These are
|
|
|
|
* the "allow break before" points. Initially, there are no potential
|
2014-09-16 13:58:12 +04:00
|
|
|
* linebreaks.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2016-03-08 10:56:18 +03:00
|
|
|
* This can change glyphs and/or geometry! Some textruns' shapes
|
|
|
|
* depend on potential line breaks (e.g., title-case-converting textruns).
|
|
|
|
* This function is virtual so that those textruns can reshape themselves.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2016-03-08 10:56:18 +03:00
|
|
|
* @return true if this changed the linebreaks, false if the new line
|
2014-09-16 13:58:12 +04:00
|
|
|
* breaks are the same as the old
|
|
|
|
*/
|
|
|
|
virtual bool SetPotentialLineBreaks(Range aRange,
|
|
|
|
const uint8_t* aBreakBefore);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
enum class HyphenType : uint8_t {
|
2019-02-07 15:13:19 +03:00
|
|
|
// Code in BreakAndMeasureText depends on the ordering of these values!
|
2014-09-16 13:58:12 +04:00
|
|
|
None,
|
2017-03-13 07:54:05 +03:00
|
|
|
Explicit,
|
2018-11-30 13:46:48 +03:00
|
|
|
Soft,
|
2017-03-13 07:54:05 +03:00
|
|
|
AutoWithManualInSameWord,
|
2014-09-16 13:58:12 +04:00
|
|
|
AutoWithoutManualInSameWord
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
struct HyphenationState {
|
|
|
|
uint32_t mostRecentBoundary = 0;
|
|
|
|
bool hasManualHyphen = false;
|
|
|
|
bool hasExplicitHyphen = false;
|
2017-03-13 07:54:05 +03:00
|
|
|
bool hasAutoHyphen = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Layout provides PropertyProvider objects. These allow detection of
|
|
|
|
* potential line break points and computation of spacing. We pass the data
|
|
|
|
* this way to allow lazy data acquisition; for example BreakAndMeasureText
|
|
|
|
* will want to only ask for properties of text it's actually looking at.
|
2017-01-04 18:55:16 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* NOTE that requested spacing may not actually be applied, if the textrun
|
|
|
|
* is unable to apply it in some context. Exception: spacing around a
|
|
|
|
* whitespace character MUST always be applied.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
class PropertyProvider {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
// Detect hyphenation break opportunities in the given range; breaks
|
2016-10-11 15:47:11 +03:00
|
|
|
// not at cluster boundaries will be ignored.
|
|
|
|
virtual void GetHyphenationBreaks(Range aRange,
|
|
|
|
HyphenType* aBreakBefore) const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
// Returns the provider's hyphenation setting, so callers can decide
|
|
|
|
// whether it is necessary to call GetHyphenationBreaks.
|
|
|
|
// Result is an StyleHyphens value.
|
|
|
|
virtual mozilla::StyleHyphens GetHyphensOption() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
// Returns the extra width that will be consumed by a hyphen. This should
|
|
|
|
// be constant for a given textrun.
|
|
|
|
virtual gfxFloat GetHyphenWidth() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-03-13 07:54:05 +03:00
|
|
|
typedef gfxFont::Spacing Spacing;
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Get the spacing around the indicated characters. Spacing must be zero
|
|
|
|
* inside clusters. In other words, if character i is not
|
|
|
|
* CLUSTER_START, then character i-1 must have zero after-spacing and
|
|
|
|
* character i must have zero before-spacing.
|
|
|
|
*/
|
2017-03-13 07:54:05 +03:00
|
|
|
virtual void GetSpacing(Range aRange, Spacing* aSpacing) const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Returns a gfxContext that can be used to measure the hyphen glyph.
|
|
|
|
// Only called if the hyphen width is requested.
|
|
|
|
virtual already_AddRefed<DrawTarget> GetDrawTarget() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Return the appUnitsPerDevUnit value to be used when measuring.
|
|
|
|
// Only called if the hyphen width is requested.
|
2017-03-17 13:53:15 +03:00
|
|
|
virtual uint32_t GetAppUnitsPerDevUnit() const = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
struct MOZ_STACK_CLASS DrawParams {
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxContext* context;
|
2017-03-17 13:53:15 +03:00
|
|
|
DrawMode drawMode = DrawMode::GLYPH_FILL;
|
2016-04-22 20:40:39 +03:00
|
|
|
nscolor textStrokeColor = 0;
|
2016-07-14 03:00:00 +03:00
|
|
|
gfxPattern* textStrokePattern = nullptr;
|
2017-03-17 13:53:15 +03:00
|
|
|
const mozilla::gfx::StrokeOptions* strokeOpts = nullptr;
|
2014-09-16 13:58:12 +04:00
|
|
|
const mozilla::gfx::DrawOptions* drawOpts = nullptr;
|
|
|
|
PropertyProvider* provider = nullptr;
|
|
|
|
// If non-null, the advance width of the substring is set.
|
2017-03-17 13:53:15 +03:00
|
|
|
gfxFloat* advanceWidth = nullptr;
|
2014-09-16 13:58:12 +04:00
|
|
|
mozilla::SVGContextPaint* contextPaint = nullptr;
|
|
|
|
gfxTextRunDrawCallbacks* callbacks = nullptr;
|
|
|
|
explicit DrawParams(gfxContext* aContext) : context(aContext) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Draws a substring. Uses only GetSpacing from aBreakProvider.
|
|
|
|
* The provided point is the baseline origin on the left of the string
|
|
|
|
* for LTR, on the right of the string for RTL.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Drawing should respect advance widths in the sense that for LTR runs,
|
|
|
|
* Draw(Range(start, middle), pt, ...) followed by
|
|
|
|
* Draw(Range(middle, end), gfxPoint(pt.x + advance, pt.y), ...)
|
|
|
|
* should have the same effect as
|
2016-03-08 10:56:18 +03:00
|
|
|
* Draw(Range(start, end), pt, ...)
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* For RTL runs the rule is:
|
2016-03-08 10:56:18 +03:00
|
|
|
* Draw(Range(middle, end), pt, ...) followed by
|
|
|
|
* Draw(Range(start, middle), gfxPoint(pt.x + advance, pt.y), ...)
|
2014-09-16 13:58:12 +04:00
|
|
|
* should have the same effect as
|
2016-03-08 10:56:18 +03:00
|
|
|
* Draw(Range(start, end), pt, ...)
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* Glyphs should be drawn in logical content order, which can be significant
|
|
|
|
* if they overlap (perhaps due to negative spacing).
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
void Draw(Range aRange, mozilla::gfx::Point aPt,
|
|
|
|
const DrawParams& aParams) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Draws the emphasis marks for this text run. Uses only GetSpacing
|
|
|
|
* from aProvider. The provided point is the baseline origin of the
|
2015-11-28 03:56:33 +03:00
|
|
|
* line of emphasis marks.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
void DrawEmphasisMarks(gfxContext* aContext, gfxTextRun* aMark,
|
2017-10-24 11:59:09 +03:00
|
|
|
gfxFloat aMarkAdvance, mozilla::gfx::Point aPt,
|
2014-09-16 13:58:12 +04:00
|
|
|
Range aRange, PropertyProvider* aProvider) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Computes the ReflowMetrics for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
|
|
|
* @param aBoundingBoxType which kind of bounding box (loose/tight)
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
Metrics MeasureText(Range aRange, gfxFont::BoundingBoxType aBoundingBoxType,
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawTarget* aDrawTargetForTightBoundingBox,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider* aProvider) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
Metrics MeasureText(gfxFont::BoundingBoxType aBoundingBoxType,
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawTarget* aDrawTargetForTightBoundingBox,
|
2016-03-08 10:56:18 +03:00
|
|
|
PropertyProvider* aProvider = nullptr) const {
|
2016-03-08 10:56:18 +03:00
|
|
|
return MeasureText(Range(this), aBoundingBoxType,
|
2016-03-08 10:56:18 +03:00
|
|
|
aDrawTargetForTightBoundingBox, aProvider);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Computes just the advance width for a substring.
|
|
|
|
* Uses GetSpacing from aBreakProvider.
|
|
|
|
* If aSpacing is not null, the spacing attached before and after
|
|
|
|
* the substring would be returned in it. NOTE: the spacing is
|
2017-03-17 13:53:15 +03:00
|
|
|
* included in the advance width.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2017-03-17 13:53:15 +03:00
|
|
|
gfxFloat GetAdvanceWidth(Range aRange, PropertyProvider* aProvider,
|
|
|
|
PropertyProvider::Spacing* aSpacing = nullptr) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat GetAdvanceWidth() const {
|
|
|
|
return GetAdvanceWidth(Range(this), nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Computes the minimum advance width for a substring assuming line
|
|
|
|
* breaking is allowed everywhere.
|
|
|
|
*/
|
|
|
|
gfxFloat GetMinAdvanceWidth(Range aRange);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Clear all stored line breaks for the given range (both before and after),
|
|
|
|
* and then set the line-break state before aRange.start to aBreakBefore and
|
|
|
|
* after the last cluster to aBreakAfter.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* We require that before and after line breaks be consistent. For clusters
|
|
|
|
* i and i+1, we require that if there is a break after cluster i, a break
|
|
|
|
* will be specified before cluster i+1. This may be temporarily violated
|
2017-03-17 13:53:15 +03:00
|
|
|
* (e.g. after reflowing line L and before reflowing line L+1); to handle
|
|
|
|
* these temporary violations, we say that there is a break betwen i and i+1
|
|
|
|
* if a break is specified after i OR a break is specified before i+1.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2017-03-17 13:53:15 +03:00
|
|
|
* This can change textrun geometry! The existence of a linebreak can affect
|
|
|
|
* the advance width of the cluster before the break (when kerning) or the
|
2016-04-22 20:40:39 +03:00
|
|
|
* geometry of one cluster before the break or any number of clusters
|
2016-07-14 03:00:00 +03:00
|
|
|
* after the break. (The one-cluster-before-the-break limit is somewhat
|
|
|
|
* arbitrary; if some scripts require breaking it, then we need to
|
|
|
|
* alter nsTextFrame::TrimTrailingWhitespace, perhaps drastically becase
|
|
|
|
* it could affect the layout of frames before it...)
|
2016-03-08 10:56:18 +03:00
|
|
|
*
|
|
|
|
* We return true if glyphs or geometry changed, false otherwise. This
|
|
|
|
* function is virtual so that gfxTextRun subclasses can reshape
|
2014-09-16 13:58:12 +04:00
|
|
|
* properly.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2016-03-08 10:56:18 +03:00
|
|
|
* @param aAdvanceWidthDelta if non-null, returns the change in advance
|
|
|
|
* width of the given range.
|
|
|
|
*/
|
2016-03-08 10:56:18 +03:00
|
|
|
virtual bool SetLineBreaks(Range aRange, bool aLineBreakBefore,
|
|
|
|
bool aLineBreakAfter,
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxFloat* aAdvanceWidthDelta);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-07-22 16:56:09 +03:00
|
|
|
enum SuppressBreak {
|
2014-12-22 07:17:55 +03:00
|
|
|
eNoSuppressBreak,
|
2016-07-22 16:56:09 +03:00
|
|
|
// Measure the range of text as if there is no break before it.
|
|
|
|
eSuppressInitialBreak,
|
|
|
|
// Measure the range of text as if it contains no break
|
2016-03-08 10:56:18 +03:00
|
|
|
eSuppressAllBreaks
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
void ClassifyAutoHyphenations(uint32_t aStart, Range aRange,
|
|
|
|
nsTArray<HyphenType>& aHyphenBuffer,
|
|
|
|
HyphenationState* aWordState);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Finds the longest substring that will fit into the given width.
|
|
|
|
* Uses GetHyphenationBreaks and GetSpacing from aProvider.
|
|
|
|
* Guarantees the following:
|
|
|
|
* -- 0 <= result <= aMaxLength
|
|
|
|
* -- result is the maximal value of N such that either
|
|
|
|
* N < aMaxLength && line break at N &&
|
2018-11-28 12:16:55 +03:00
|
|
|
* GetAdvanceWidth(Range(aStart, N), aProvider) <= aWidth
|
2014-09-16 13:58:12 +04:00
|
|
|
* OR N < aMaxLength && hyphen break at N &&
|
2018-11-28 12:16:55 +03:00
|
|
|
* GetAdvanceWidth(Range(aStart, N), aProvider) +
|
|
|
|
* GetHyphenWidth() <= aWidth
|
2014-09-16 13:58:12 +04:00
|
|
|
* OR N == aMaxLength &&
|
2018-11-28 12:16:55 +03:00
|
|
|
* GetAdvanceWidth(Range(aStart, N), aProvider) <= aWidth
|
2014-09-16 13:58:12 +04:00
|
|
|
* where GetAdvanceWidth assumes the effect of
|
|
|
|
* SetLineBreaks(Range(aStart, N),
|
|
|
|
* aLineBreakBefore, N < aMaxLength, aProvider)
|
|
|
|
* -- if no such N exists, then result is the smallest N such that
|
2018-11-28 12:16:55 +03:00
|
|
|
* N < aMaxLength && line break at N
|
|
|
|
* OR N < aMaxLength && hyphen break at N
|
|
|
|
* OR N == aMaxLength
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* The call has the effect of
|
2018-11-28 12:16:55 +03:00
|
|
|
* SetLineBreaks(Range(aStart, result), aLineBreakBefore,
|
|
|
|
* result < aMaxLength, aProvider)
|
2014-09-16 13:58:12 +04:00
|
|
|
* and the returned metrics and the invariants above reflect this.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* @param aMaxLength this can be UINT32_MAX, in which case the length used
|
|
|
|
* is up to the end of the string
|
|
|
|
* @param aLineBreakBefore set to true if and only if there is an actual
|
|
|
|
* line break at the start of this string.
|
|
|
|
* @param aSuppressBreak what break should be suppressed.
|
|
|
|
* @param aTrimWhitespace if non-null, then we allow a trailing run of
|
|
|
|
* spaces to be trimmed; the width of the space(s) will not be included in
|
|
|
|
* the measured string width for comparison with the limit aWidth, and
|
2016-03-08 10:56:18 +03:00
|
|
|
* trimmed spaces will not be included in returned metrics. The width
|
|
|
|
* of the trimmed spaces will be returned in aTrimWhitespace.
|
|
|
|
* Trimmed spaces are still counted in the "characters fit" result.
|
|
|
|
* @param aHangWhitespace true if we allow whitespace to overflow the
|
|
|
|
* container at a soft-wrap
|
2014-09-16 13:58:12 +04:00
|
|
|
* @param aMetrics if non-null, we fill this in for the returned substring.
|
2016-03-08 10:56:18 +03:00
|
|
|
* If a hyphenation break was used, the hyphen is NOT included in the returned
|
2014-09-16 13:58:12 +04:00
|
|
|
* metrics.
|
|
|
|
* @param aBoundingBoxType whether to make the bounding box in aMetrics tight
|
2016-03-08 10:56:18 +03:00
|
|
|
* @param aDrawTargetForTightBoundingbox a reference DrawTarget to get the
|
2014-09-16 13:58:12 +04:00
|
|
|
* tight bounding box, if requested
|
2016-03-08 10:56:18 +03:00
|
|
|
* @param aUsedHyphenation if non-null, records if we selected a hyphenation
|
2018-11-30 13:46:48 +03:00
|
|
|
* break
|
2014-09-16 13:58:12 +04:00
|
|
|
* @param aLastBreak if non-null and result is aMaxLength, we set this to
|
|
|
|
* the maximal N such that
|
2018-11-28 12:16:55 +03:00
|
|
|
* N < aMaxLength && line break at N &&
|
2016-03-08 10:56:18 +03:00
|
|
|
* GetAdvanceWidth(Range(aStart, N), aProvider) <= aWidth
|
|
|
|
* OR N < aMaxLength && hyphen break at N &&
|
|
|
|
* GetAdvanceWidth(Range(aStart, N), aProvider) +
|
|
|
|
* GetHyphenWidth() <= aWidth
|
|
|
|
* or UINT32_MAX if no such N exists, where GetAdvanceWidth assumes
|
|
|
|
* the effect of
|
|
|
|
* SetLineBreaks(Range(aStart, N), aLineBreakBefore,
|
2014-09-16 13:58:12 +04:00
|
|
|
* N < aMaxLength, aProvider)
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2014-09-16 13:58:12 +04:00
|
|
|
* @param aCanWordWrap true if we can break between any two grapheme
|
2015-11-28 03:56:33 +03:00
|
|
|
* clusters. This is set by overflow-wrap|word-wrap: break-word
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2015-11-28 03:56:33 +03:00
|
|
|
* @param aBreakPriority in/out the priority of the break opportunity
|
|
|
|
* saved in the line. If we are prioritizing break opportunities, we will
|
|
|
|
* not set a break with a lower priority. @see gfxBreakPriority.
|
2018-11-30 13:46:48 +03:00
|
|
|
*
|
2015-11-28 03:56:33 +03:00
|
|
|
* Note that negative advance widths are possible especially if negative
|
2017-09-13 21:05:51 +03:00
|
|
|
* spacing is provided.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2017-09-13 21:05:51 +03:00
|
|
|
uint32_t BreakAndMeasureText(uint32_t aStart, uint32_t aMaxLength,
|
2017-10-24 11:59:09 +03:00
|
|
|
bool aLineBreakBefore, gfxFloat aWidth,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider* aProvider,
|
2014-09-16 13:58:12 +04:00
|
|
|
SuppressBreak aSuppressBreak,
|
|
|
|
gfxFloat* aTrimWhitespace, bool aHangWhitespace,
|
2016-03-08 10:56:18 +03:00
|
|
|
Metrics* aMetrics,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aDrawTargetForTightBoundingBox,
|
2016-06-27 19:41:55 +03:00
|
|
|
bool* aUsedHyphenation, uint32_t* aLastBreak,
|
2019-06-12 13:23:49 +03:00
|
|
|
bool aCanWordWrap, bool aCanWhitespaceWrap,
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxBreakPriority* aBreakPriority);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
// Utility getters
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
void* GetUserData() const { return mUserData; }
|
|
|
|
void SetUserData(void* aUserData) { mUserData = aUserData; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
void SetFlagBits(nsTextFrameUtils::Flags aFlags) { mFlags2 |= aFlags; }
|
|
|
|
void ClearFlagBits(nsTextFrameUtils::Flags aFlags) { mFlags2 &= ~aFlags; }
|
2014-09-16 13:58:12 +04:00
|
|
|
const gfxSkipChars& GetSkipChars() const { return mSkipChars; }
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxFontGroup* GetFontGroup() const { return mFontGroup; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
// Call this, don't call "new gfxTextRun" directly. This does custom
|
|
|
|
// allocation and initialization
|
|
|
|
static already_AddRefed<gfxTextRun> Create(
|
|
|
|
const gfxTextRunFactory::Parameters* aParams, uint32_t aLength,
|
|
|
|
gfxFontGroup* aFontGroup, mozilla::gfx::ShapedTextFlags aFlags,
|
2017-05-05 00:27:05 +03:00
|
|
|
nsTextFrameUtils::Flags aFlags2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
// The text is divided into GlyphRuns as necessary. (In the vast majority
|
|
|
|
// of cases, a gfxTextRun contains just a single GlyphRun.)
|
2016-06-27 19:41:55 +03:00
|
|
|
struct GlyphRun {
|
|
|
|
RefPtr<gfxFont> mFont; // never null in a valid GlyphRun
|
|
|
|
uint32_t mCharacterOffset; // into original UTF16 string
|
|
|
|
mozilla::gfx::ShapedTextFlags
|
|
|
|
mOrientation; // gfxTextRunFactory::TEXT_ORIENT_* value
|
2019-04-01 17:32:06 +03:00
|
|
|
FontMatchType mMatchType;
|
2019-08-21 18:07:20 +03:00
|
|
|
bool mIsCJK; // Whether the text was a CJK script run (used to decide if
|
|
|
|
// text-decoration-skip-ink should not be applied)
|
2019-08-21 18:07:08 +03:00
|
|
|
|
|
|
|
// Set up the properties (but NOT offset) of the GlyphRun.
|
|
|
|
void SetProperties(gfxFont* aFont,
|
2019-08-21 18:07:20 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation, bool aIsCJK,
|
2019-08-21 18:07:08 +03:00
|
|
|
FontMatchType aMatchType) {
|
|
|
|
mFont = aFont;
|
|
|
|
mOrientation = aOrientation;
|
2019-08-21 18:07:20 +03:00
|
|
|
mIsCJK = aIsCJK;
|
2019-08-21 18:07:08 +03:00
|
|
|
mMatchType = aMatchType;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Return whether the GlyphRun matches the given properties;
|
|
|
|
// the given FontMatchType will be added to the run if not present.
|
|
|
|
bool Matches(gfxFont* aFont, mozilla::gfx::ShapedTextFlags aOrientation,
|
2019-08-21 18:07:20 +03:00
|
|
|
bool aIsCJK, FontMatchType aMatchType) {
|
|
|
|
if (mFont == aFont && mOrientation == aOrientation && mIsCJK == aIsCJK) {
|
2019-08-21 18:07:08 +03:00
|
|
|
mMatchType.kind |= aMatchType.kind;
|
|
|
|
if (mMatchType.generic == mozilla::StyleGenericFontFamily::None) {
|
|
|
|
mMatchType.generic = aMatchType.generic;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2019-08-21 18:07:20 +03:00
|
|
|
// Script run codes that we will mark as CJK to suppress skip-ink behavior.
|
|
|
|
static inline bool IsCJKScript(Script aScript) {
|
|
|
|
switch (aScript) {
|
|
|
|
case Script::BOPOMOFO:
|
|
|
|
case Script::HAN:
|
|
|
|
case Script::HANGUL:
|
|
|
|
case Script::HIRAGANA:
|
|
|
|
case Script::KATAKANA:
|
|
|
|
case Script::KATAKANA_OR_HIRAGANA:
|
|
|
|
case Script::SIMPLIFIED_HAN:
|
|
|
|
case Script::TRADITIONAL_HAN:
|
|
|
|
case Script::JAPANESE:
|
|
|
|
case Script::KOREAN:
|
|
|
|
case Script::HAN_WITH_BOPOMOFO:
|
|
|
|
case Script::JAMO:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
class MOZ_STACK_CLASS GlyphRunIterator {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2019-08-07 20:41:13 +03:00
|
|
|
GlyphRunIterator(const gfxTextRun* aTextRun, Range aRange,
|
|
|
|
bool aReverse = false)
|
2018-04-13 16:01:28 +03:00
|
|
|
: mTextRun(aTextRun),
|
2019-08-07 20:41:13 +03:00
|
|
|
mDirection(aReverse ? -1 : 1),
|
2016-03-08 10:56:18 +03:00
|
|
|
mStartOffset(aRange.start),
|
|
|
|
mEndOffset(aRange.end) {
|
2019-08-07 20:41:13 +03:00
|
|
|
mNextIndex = mTextRun->FindFirstGlyphRunContaining(
|
|
|
|
aReverse ? aRange.end - 1 : aRange.start);
|
2016-03-08 10:56:18 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
bool NextRun();
|
|
|
|
const GlyphRun* GetGlyphRun() const { return mGlyphRun; }
|
2014-11-10 04:25:09 +03:00
|
|
|
uint32_t GetStringStart() const { return mStringStart; }
|
2016-06-27 19:41:55 +03:00
|
|
|
uint32_t GetStringEnd() const { return mStringEnd; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
private:
|
|
|
|
const gfxTextRun* mTextRun;
|
2016-07-28 11:30:09 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR const GlyphRun* mGlyphRun;
|
2016-06-27 19:41:55 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR uint32_t mStringStart;
|
2016-03-08 10:56:18 +03:00
|
|
|
MOZ_INIT_OUTSIDE_CTOR uint32_t mStringEnd;
|
2019-08-07 20:41:13 +03:00
|
|
|
const int32_t mDirection;
|
|
|
|
int32_t mNextIndex;
|
2016-03-08 10:56:18 +03:00
|
|
|
uint32_t mStartOffset;
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t mEndOffset;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class GlyphRunOffsetComparator {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2016-03-08 10:56:18 +03:00
|
|
|
bool Equals(const GlyphRun& a, const GlyphRun& b) const {
|
|
|
|
return a.mCharacterOffset == b.mCharacterOffset;
|
2016-03-08 10:56:18 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool LessThan(const GlyphRun& a, const GlyphRun& b) const {
|
2016-05-24 03:27:21 +03:00
|
|
|
return a.mCharacterOffset < b.mCharacterOffset;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 03:52:38 +03:00
|
|
|
friend class GlyphRunIterator;
|
|
|
|
friend class FontSelector;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-04-13 16:01:28 +03:00
|
|
|
// API for setting up the textrun glyphs. Should only be called by
|
2016-06-27 19:41:55 +03:00
|
|
|
// things that construct textruns.
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* We've found a run of text that should use a particular font. Call this
|
|
|
|
* only during initialization when font substitution has been computed.
|
|
|
|
* Call it before setting up the glyphs for the characters in this run;
|
|
|
|
* SetMissingGlyph requires that the correct glyphrun be installed.
|
|
|
|
*
|
|
|
|
* If aForceNewRun, a new glyph run will be added, even if the
|
|
|
|
* previously added run uses the same font. If glyph runs are
|
|
|
|
* added out of strictly increasing aStartCharIndex order (via
|
|
|
|
* force), then SortGlyphRuns must be called after all glyph runs
|
2018-05-11 10:56:12 +03:00
|
|
|
* are added before any further operations are performed with this
|
2017-05-04 20:31:28 +03:00
|
|
|
* TextRun.
|
|
|
|
*/
|
2019-08-21 18:07:08 +03:00
|
|
|
void AddGlyphRun(gfxFont* aFont, FontMatchType aMatchType,
|
|
|
|
uint32_t aUTF16Offset, bool aForceNewRun,
|
2019-08-21 18:07:20 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation, bool aIsCJK);
|
2014-09-16 13:58:12 +04:00
|
|
|
void ResetGlyphRuns() {
|
|
|
|
if (mHasGlyphRunArray) {
|
|
|
|
MOZ_ASSERT(mGlyphRunArray.Length() > 1);
|
|
|
|
// Discard all but the first GlyphRun...
|
|
|
|
mGlyphRunArray.TruncateLength(1);
|
|
|
|
// ...and then convert to the single-run representation.
|
2015-11-28 03:56:33 +03:00
|
|
|
ConvertFromGlyphRunArray();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2017-05-04 20:31:28 +03:00
|
|
|
// Clear out the one remaining GlyphRun.
|
|
|
|
mSingleGlyphRun.mFont = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
void SortGlyphRuns();
|
|
|
|
void SanitizeGlyphRuns();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2018-02-06 09:46:57 +03:00
|
|
|
const CompressedGlyph* GetCharacterGlyphs() const final {
|
2016-06-27 19:41:55 +03:00
|
|
|
MOZ_ASSERT(mCharacterGlyphs, "failed to initialize mCharacterGlyphs");
|
|
|
|
return mCharacterGlyphs;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-02-06 09:46:57 +03:00
|
|
|
CompressedGlyph* GetCharacterGlyphs() final {
|
2016-06-27 19:41:55 +03:00
|
|
|
MOZ_ASSERT(mCharacterGlyphs, "failed to initialize mCharacterGlyphs");
|
|
|
|
return mCharacterGlyphs;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// clean out results from shaping in progress, used for fallback scenarios
|
|
|
|
void ClearGlyphsAndCharacters();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-10-24 11:59:09 +03:00
|
|
|
void SetSpaceGlyph(gfxFont* aFont, DrawTarget* aDrawTarget,
|
2015-12-07 01:13:25 +03:00
|
|
|
uint32_t aCharIndex,
|
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
|
|
|
// Set the glyph data for the given character index to the font's
|
|
|
|
// space glyph, IF this can be done as a "simple" glyph record
|
|
|
|
// (not requiring a DetailedGlyph entry). This avoids the need to call
|
|
|
|
// the font shaper and go through the shaped-word cache for most spaces.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// The parameter aSpaceChar is the original character code for which
|
|
|
|
// this space glyph is being used; if this is U+0020, we need to record
|
|
|
|
// that it could be trimmed at a run edge, whereas other kinds of space
|
|
|
|
// (currently just U+00A0) would not be trimmable/breakable.
|
2018-11-30 13:46:48 +03:00
|
|
|
//
|
2014-09-16 13:58:12 +04:00
|
|
|
// Returns true if it was able to set simple glyph data for the space;
|
|
|
|
// if it returns false, the caller needs to fall back to some other
|
|
|
|
// means to create the necessary (detailed) glyph data.
|
2015-12-07 01:13:25 +03:00
|
|
|
bool SetSpaceGlyphIfSimple(gfxFont* aFont, uint32_t aCharIndex,
|
2017-05-05 00:27:05 +03:00
|
|
|
char16_t aSpaceChar,
|
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Record the positions of specific characters that layout may need to
|
|
|
|
// detect in the textrun, even though it doesn't have an explicit copy
|
|
|
|
// of the original text. These are recorded using flag bits in the
|
|
|
|
// CompressedGlyph record; if necessary, we convert "simple" glyph records
|
|
|
|
// to "complex" ones as the Tab and Newline flags are not present in
|
|
|
|
// simple CompressedGlyph records.
|
2018-03-06 00:57:57 +03:00
|
|
|
void SetIsTab(uint32_t aIndex) { EnsureComplexGlyph(aIndex).SetIsTab(); }
|
2014-09-16 13:58:12 +04:00
|
|
|
void SetIsNewline(uint32_t aIndex) {
|
2015-11-28 03:56:33 +03:00
|
|
|
EnsureComplexGlyph(aIndex).SetIsNewline();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-28 03:56:33 +03:00
|
|
|
void SetNoEmphasisMark(uint32_t aIndex) {
|
|
|
|
EnsureComplexGlyph(aIndex).SetNoEmphasisMark();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2018-03-06 00:57:57 +03:00
|
|
|
void SetIsFormattingControl(uint32_t aIndex) {
|
|
|
|
EnsureComplexGlyph(aIndex).SetIsFormattingControl();
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Prefetch all the glyph extents needed to ensure that Measure calls
|
|
|
|
* on this textrun not requesting tight boundingBoxes will succeed. Note
|
|
|
|
* that some glyph extents might not be fetched due to OOM or other
|
|
|
|
* errors.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2015-12-16 00:56:41 +03:00
|
|
|
void FetchGlyphExtents(DrawTarget* aRefDrawTarget);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
uint32_t CountMissingGlyphs() const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
const GlyphRun* GetGlyphRuns(uint32_t* aNumGlyphRuns) const {
|
|
|
|
if (mHasGlyphRunArray) {
|
|
|
|
*aNumGlyphRuns = mGlyphRunArray.Length();
|
|
|
|
return mGlyphRunArray.Elements();
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2017-05-02 13:14:53 +03:00
|
|
|
*aNumGlyphRuns = mSingleGlyphRun.mFont ? 1 : 0;
|
|
|
|
return &mSingleGlyphRun;
|
2015-11-28 03:56:33 +03:00
|
|
|
}
|
2018-03-06 00:57:57 +03:00
|
|
|
}
|
2019-08-21 18:07:20 +03:00
|
|
|
|
|
|
|
const GlyphRun* TrailingGlyphRun() const {
|
|
|
|
uint32_t count;
|
|
|
|
const GlyphRun* runs = GetGlyphRuns(&count);
|
|
|
|
return count ? runs + count - 1 : nullptr;
|
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Returns the index of the GlyphRun containing the given offset.
|
|
|
|
// Returns mGlyphRuns.Length() when aOffset is mCharacterCount.
|
2017-05-02 13:14:53 +03:00
|
|
|
uint32_t FindFirstGlyphRunContaining(uint32_t aOffset) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
// Copy glyph data from a ShapedWord into this textrun.
|
|
|
|
void CopyGlyphDataFrom(gfxShapedWord* aSource, uint32_t aStart);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
// Copy glyph data for a range of characters from aSource to this
|
|
|
|
// textrun.
|
|
|
|
void CopyGlyphDataFrom(gfxTextRun* aSource, Range aRange, uint32_t aDest);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Tell the textrun to release its reference to its creating gfxFontGroup
|
|
|
|
// immediately, rather than on destruction. This is used for textruns
|
|
|
|
// that are actually owned by a gfxFontGroup, so that they don't keep it
|
|
|
|
// permanently alive due to a circular reference. (The caller of this is
|
|
|
|
// taking responsibility for ensuring the textrun will not outlive its
|
|
|
|
// mFontGroup.)
|
|
|
|
void ReleaseFontGroup();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
struct LigatureData {
|
2016-03-08 10:56:18 +03:00
|
|
|
// textrun range of the containing ligature
|
|
|
|
Range mRange;
|
2014-09-16 13:58:12 +04:00
|
|
|
// appunits advance to the start of the ligature part within the ligature;
|
|
|
|
// never includes any spacing
|
|
|
|
gfxFloat mPartAdvance;
|
|
|
|
// appunits width of the ligature part; includes before-spacing
|
|
|
|
// when the part is at the start of the ligature, and after-spacing
|
|
|
|
// when the part is as the end of the ligature
|
|
|
|
gfxFloat mPartWidth;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mClipBeforePart;
|
|
|
|
bool mClipAfterPart;
|
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// return storage used by this run, for memory reporter;
|
|
|
|
// nsTransformedTextRun needs to override this as it holds additional data
|
|
|
|
virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
|
|
|
MOZ_MUST_OVERRIDE;
|
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
|
|
|
|
MOZ_MUST_OVERRIDE;
|
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
nsTextFrameUtils::Flags GetFlags2() const { return mFlags2; }
|
2017-05-05 00:25:16 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the size, if it hasn't already been gotten, marking as it goes.
|
|
|
|
size_t MaybeSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) {
|
2019-04-26 02:03:04 +03:00
|
|
|
if (mFlags2 & nsTextFrameUtils::Flags::RunSizeAccounted) {
|
2014-09-16 13:58:12 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2019-04-26 02:03:04 +03:00
|
|
|
mFlags2 |= nsTextFrameUtils::Flags::RunSizeAccounted;
|
2014-09-16 13:58:12 +04:00
|
|
|
return SizeOfIncludingThis(aMallocSizeOf);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
void ResetSizeOfAccountingFlags() {
|
2019-04-26 02:03:04 +03:00
|
|
|
mFlags2 &= ~nsTextFrameUtils::Flags::RunSizeAccounted;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// shaping state - for some font features, fallback is required that
|
|
|
|
// affects the entire run. for example, fallback for one script/font
|
|
|
|
// portion of a textrun requires fallback to be applied to the entire run
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:25:16 +03:00
|
|
|
enum ShapingState : uint8_t {
|
2014-09-16 13:58:12 +04:00
|
|
|
eShapingState_Normal, // default state
|
|
|
|
eShapingState_ShapingWithFeature, // have shaped with feature
|
|
|
|
eShapingState_ShapingWithFallback, // have shaped with fallback
|
|
|
|
eShapingState_Aborted, // abort initial iteration
|
|
|
|
eShapingState_ForceFallbackFeature // redo with fallback forced on
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
ShapingState GetShapingState() const { return mShapingState; }
|
|
|
|
void SetShapingState(ShapingState aShapingState) {
|
|
|
|
mShapingState = aShapingState;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2016-06-27 19:41:55 +03:00
|
|
|
int32_t GetAdvanceForGlyph(uint32_t aIndex) const {
|
2015-11-28 03:56:33 +03:00
|
|
|
const CompressedGlyph& glyphData = mCharacterGlyphs[aIndex];
|
|
|
|
if (glyphData.IsSimpleGlyph()) {
|
|
|
|
return glyphData.GetSimpleAdvance();
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
2017-05-05 00:25:16 +03:00
|
|
|
uint32_t glyphCount = glyphData.GetGlyphCount();
|
2014-09-16 13:58:12 +04:00
|
|
|
if (!glyphCount) {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-11-28 03:56:33 +03:00
|
|
|
const DetailedGlyph* details = GetDetailedGlyphs(aIndex);
|
|
|
|
int32_t advance = 0;
|
|
|
|
for (uint32_t j = 0; j < glyphCount; ++j, ++details) {
|
|
|
|
advance += details->mAdvance;
|
|
|
|
}
|
|
|
|
return advance;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2015-11-28 03:56:33 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void Dump(FILE* aOutput);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Create a textrun, and set its mCharacterGlyphs to point immediately
|
|
|
|
* after the base object; this is ONLY used in conjunction with placement
|
|
|
|
* new, after allocating a block large enough for the glyph records to
|
|
|
|
* follow the base textrun object.
|
|
|
|
*/
|
|
|
|
gfxTextRun(const gfxTextRunFactory::Parameters* aParams, uint32_t aLength,
|
2017-05-05 00:27:05 +03:00
|
|
|
gfxFontGroup* aFontGroup, mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Helper for the Create() factory method to allocate the required
|
|
|
|
* glyph storage for a textrun object with the basic size aSize,
|
|
|
|
* plus room for aLength glyph records.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
static void* AllocateStorageForTextRun(size_t aSize, uint32_t aLength);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Pointer to the array of CompressedGlyph records; must be initialized
|
|
|
|
// when the object is constructed.
|
2015-11-28 03:56:33 +03:00
|
|
|
CompressedGlyph* mCharacterGlyphs;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
private:
|
2017-01-04 18:55:16 +03:00
|
|
|
// **** general helpers ****
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the total advance for a range of glyphs.
|
2016-06-27 19:41:55 +03:00
|
|
|
int32_t GetAdvanceForGlyphs(Range aRange) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Spacing for characters outside the range aSpacingStart/aSpacingEnd
|
|
|
|
// is assumed to be zero; such characters are not passed to aProvider.
|
|
|
|
// This is useful to protect aProvider from being passed character indices
|
|
|
|
// it is not currently able to handle.
|
2016-03-08 10:56:18 +03:00
|
|
|
bool GetAdjustedSpacingArray(
|
2017-10-24 11:59:09 +03:00
|
|
|
Range aRange, PropertyProvider* aProvider, Range aSpacingRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
nsTArray<PropertyProvider::Spacing>* aSpacing) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
CompressedGlyph& EnsureComplexGlyph(uint32_t aIndex) {
|
|
|
|
gfxShapedText::EnsureComplexGlyph(aIndex, mCharacterGlyphs[aIndex]);
|
|
|
|
return mCharacterGlyphs[aIndex];
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// **** ligature helpers ****
|
|
|
|
// (Platforms do the actual ligaturization, but we need to do a bunch of stuff
|
|
|
|
// to handle requests that begin or end inside a ligature)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// if aProvider is null then mBeforeSpacing and mAfterSpacing are set to zero
|
2016-03-08 10:56:18 +03:00
|
|
|
LigatureData ComputeLigatureData(Range aPartRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider* aProvider) const;
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxFloat ComputePartialLigatureWidth(Range aPartRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
PropertyProvider* aProvider) const;
|
2017-10-24 11:59:09 +03:00
|
|
|
void DrawPartialLigature(gfxFont* aFont, Range aRange,
|
|
|
|
mozilla::gfx::Point* aPt,
|
|
|
|
PropertyProvider* aProvider,
|
2016-06-27 19:41:55 +03:00
|
|
|
TextRunDrawParams& aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation) const;
|
2016-03-08 10:56:18 +03:00
|
|
|
// Advance aRange.start to the start of the nearest ligature, back
|
|
|
|
// up aRange.end to the nearest ligature end; may result in
|
|
|
|
// aRange->start == aRange->end.
|
2016-06-27 19:41:55 +03:00
|
|
|
void ShrinkToLigatureBoundaries(Range* aRange) const;
|
2014-09-16 13:58:12 +04:00
|
|
|
// result in appunits
|
2016-06-27 19:41:55 +03:00
|
|
|
gfxFloat GetPartialLigatureWidth(Range aRange,
|
|
|
|
PropertyProvider* aProvider) const;
|
2016-03-08 10:56:18 +03:00
|
|
|
void AccumulatePartialLigatureMetrics(
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont* aFont, Range aRange, gfxFont::BoundingBoxType aBoundingBoxType,
|
2016-03-08 10:56:18 +03:00
|
|
|
DrawTarget* aRefDrawTarget, PropertyProvider* aProvider,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation, Metrics* aMetrics) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// **** measurement helper ****
|
2016-03-08 10:56:18 +03:00
|
|
|
void AccumulateMetricsForRun(gfxFont* aFont, Range aRange,
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont::BoundingBoxType aBoundingBoxType,
|
2015-12-16 00:56:41 +03:00
|
|
|
DrawTarget* aRefDrawTarget,
|
2017-10-24 11:59:09 +03:00
|
|
|
PropertyProvider* aProvider, Range aSpacingRange,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation,
|
2016-06-27 19:41:55 +03:00
|
|
|
Metrics* aMetrics) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// **** drawing helper ****
|
2017-10-24 11:59:09 +03:00
|
|
|
void DrawGlyphs(gfxFont* aFont, Range aRange, mozilla::gfx::Point* aPt,
|
|
|
|
PropertyProvider* aProvider, Range aSpacingRange,
|
2016-06-27 19:41:55 +03:00
|
|
|
TextRunDrawParams& aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation) const;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
// The textrun holds either a single GlyphRun -or- an array;
|
|
|
|
// the flag mHasGlyphRunArray tells us which is present.
|
2018-11-30 13:46:48 +03:00
|
|
|
union {
|
2017-05-02 13:14:53 +03:00
|
|
|
GlyphRun mSingleGlyphRun;
|
|
|
|
nsTArray<GlyphRun> mGlyphRunArray;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
void ConvertToGlyphRunArray() {
|
|
|
|
MOZ_ASSERT(!mHasGlyphRunArray && mSingleGlyphRun.mFont);
|
2018-05-30 22:15:35 +03:00
|
|
|
GlyphRun tmp = std::move(mSingleGlyphRun);
|
2017-05-02 13:14:53 +03:00
|
|
|
mSingleGlyphRun.~GlyphRun();
|
|
|
|
new (&mGlyphRunArray) nsTArray<GlyphRun>(2);
|
2018-05-30 22:15:35 +03:00
|
|
|
mGlyphRunArray.AppendElement(std::move(tmp));
|
2017-05-02 13:14:53 +03:00
|
|
|
mHasGlyphRunArray = true;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-05-02 13:14:53 +03:00
|
|
|
void ConvertFromGlyphRunArray() {
|
|
|
|
MOZ_ASSERT(mHasGlyphRunArray && mGlyphRunArray.Length() == 1);
|
2018-05-30 22:15:35 +03:00
|
|
|
GlyphRun tmp = std::move(mGlyphRunArray[0]);
|
2017-05-02 13:14:53 +03:00
|
|
|
mGlyphRunArray.~nsTArray<GlyphRun>();
|
2018-05-30 22:15:35 +03:00
|
|
|
new (&mSingleGlyphRun) GlyphRun(std::move(tmp));
|
2017-05-02 13:14:53 +03:00
|
|
|
mHasGlyphRunArray = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
void* mUserData;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 03:52:43 +03:00
|
|
|
// mFontGroup is usually a strong reference, but refcounting is managed
|
|
|
|
// manually because it may be explicitly released by ReleaseFontGroup()
|
|
|
|
// in the case where the font group actually owns the textrun.
|
|
|
|
gfxFontGroup* MOZ_OWNING_REF mFontGroup;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxSkipChars mSkipChars;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
nsTextFrameUtils::Flags
|
|
|
|
mFlags2; // additional flags (see also gfxShapedText::mFlags)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mSkipDrawing; // true if the font group we used had a user font
|
|
|
|
// download that's in progress, so we should hide text
|
|
|
|
// until the download completes (or timeout fires)
|
|
|
|
bool mReleasedFontGroup; // we already called NS_RELEASE on
|
|
|
|
// mFontGroup, so don't do it again
|
2017-05-02 13:14:53 +03:00
|
|
|
bool mHasGlyphRunArray; // whether we're using an array or
|
|
|
|
// just storing a single glyphrun
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// shaping state for handling variant fallback features
|
|
|
|
// such as subscript/superscript variant glyphs
|
|
|
|
ShapingState mShapingState;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
|
|
|
|
class gfxFontGroup final : public gfxTextRunFactory {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-16 13:58:12 +04:00
|
|
|
typedef mozilla::unicode::Script Script;
|
|
|
|
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
static void
|
|
|
|
Shutdown(); // platform must call this to release the languageAtomService
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFontGroup(const mozilla::FontFamilyList& aFontFamilyList,
|
|
|
|
const gfxFontStyle* aStyle, gfxTextPerfMetrics* aTextPerf,
|
|
|
|
gfxUserFontSet* aUserFontSet, gfxFloat aDevToCssSize);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
virtual ~gfxFontGroup();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Returns first valid font in the fontlist or default font.
|
|
|
|
// Initiates userfont loads if userfont not loaded.
|
|
|
|
// aGeneric: if non-null, returns the CSS generic type that was mapped to
|
2018-05-25 16:07:57 +03:00
|
|
|
// this font
|
2019-04-02 00:47:59 +03:00
|
|
|
gfxFont* GetFirstValidFont(
|
|
|
|
uint32_t aCh = 0x20, mozilla::StyleGenericFontFamily* aGeneric = nullptr);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Returns the first font in the font-group that has an OpenType MATH table,
|
|
|
|
// or null if no such font is available. The GetMathConstant methods may be
|
|
|
|
// called on the returned font.
|
|
|
|
gfxFont* GetFirstMathFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
const gfxFontStyle* GetStyle() const { return &mStyle; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-01 17:42:07 +03:00
|
|
|
gfxFontGroup* Copy(const gfxFontStyle* aStyle);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* The listed characters should be treated as invisible and zero-width
|
|
|
|
* when creating textruns.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
static bool IsInvalidChar(uint8_t ch);
|
|
|
|
static bool IsInvalidChar(char16_t ch);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
|
|
|
* This calls FetchGlyphExtents on the textrun.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-04-19 19:13:28 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeTextRun(const char16_t* aString,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t aLength,
|
2016-04-19 19:13:28 +03:00
|
|
|
const Parameters* aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2016-04-19 19:13:28 +03:00
|
|
|
gfxMissingFontRecorder* aMFR);
|
2018-11-30 13:46:48 +03:00
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Make a textrun for a given string.
|
|
|
|
* If aText is not persistent (aFlags & TEXT_IS_PERSISTENT), the
|
|
|
|
* textrun will copy it.
|
|
|
|
* This calls FetchGlyphExtents on the textrun.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-04-19 19:13:28 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeTextRun(const uint8_t* aString,
|
|
|
|
uint32_t aLength,
|
|
|
|
const Parameters* aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
2016-04-19 19:13:28 +03:00
|
|
|
gfxMissingFontRecorder* aMFR);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Textrun creation helper for clients that don't want to pass
|
|
|
|
* a full Parameters record.
|
|
|
|
*/
|
|
|
|
template <typename T>
|
|
|
|
already_AddRefed<gfxTextRun> MakeTextRun(const T* aString, uint32_t aLength,
|
|
|
|
DrawTarget* aRefDrawTarget,
|
|
|
|
int32_t aAppUnitsPerDevUnit,
|
|
|
|
mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2,
|
|
|
|
gfxMissingFontRecorder* aMFR) {
|
|
|
|
gfxTextRunFactory::Parameters params = {
|
2015-12-16 00:56:41 +03:00
|
|
|
aRefDrawTarget, nullptr, nullptr, nullptr, 0, aAppUnitsPerDevUnit};
|
2017-05-05 00:25:16 +03:00
|
|
|
return MakeTextRun(aString, aLength, ¶ms, aFlags, aFlags2, aMFR);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get the (possibly-cached) width of the hyphen character.
|
|
|
|
gfxFloat GetHyphenWidth(const gfxTextRun::PropertyProvider* aProvider);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Make a text run representing a single hyphen character.
|
|
|
|
* This will use U+2010 HYPHEN if available in the first font,
|
|
|
|
* otherwise fall back to U+002D HYPHEN-MINUS.
|
|
|
|
* The caller is responsible for deleting the returned text run
|
|
|
|
* when no longer required.
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2016-04-19 19:13:28 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeHyphenTextRun(DrawTarget* aDrawTarget,
|
2014-09-16 13:58:12 +04:00
|
|
|
uint32_t aAppUnitsPerDevUnit);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
|
|
|
/**
|
2014-09-16 13:58:12 +04:00
|
|
|
* Check whether a given font (specified by its gfxFontEntry)
|
|
|
|
* is already in the fontgroup's list of actual fonts
|
2018-11-30 13:46:48 +03:00
|
|
|
*/
|
2014-09-16 13:58:12 +04:00
|
|
|
bool HasFont(const gfxFontEntry* aFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// This returns the preferred underline for this font group.
|
|
|
|
// Some CJK fonts have wrong underline offset in its metrics.
|
|
|
|
// If this group has such "bad" font, each platform's gfxFontGroup
|
|
|
|
// initialized mUnderlineOffset. The value should be lower value of
|
|
|
|
// first font's metrics and the bad font's metrics. Otherwise, this
|
|
|
|
// returns from first font's metrics.
|
|
|
|
enum { UNDERLINE_OFFSET_NOT_SET = INT16_MAX };
|
|
|
|
gfxFloat GetUnderlineOffset();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont* FindFontForChar(uint32_t ch, uint32_t prevCh, uint32_t aNextCh,
|
|
|
|
Script aRunScript, gfxFont* aPrevMatchedFont,
|
2019-04-01 17:32:06 +03:00
|
|
|
FontMatchType* aMatchType);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-01-04 18:55:16 +03:00
|
|
|
gfxUserFontSet* GetUserFontSet();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// With downloadable fonts, the composition of the font group can change as
|
|
|
|
// fonts are downloaded for each change in state of the user font set, the
|
|
|
|
// generation value is bumped to avoid picking up previously created text runs
|
|
|
|
// in the text run word cache. For font groups based on stylesheets with no
|
|
|
|
// @font-face rule, this always returns 0.
|
|
|
|
uint64_t GetGeneration();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// generation of the latest fontset rebuild, 0 when no fontset present
|
2014-09-25 07:16:54 +04:00
|
|
|
uint64_t GetRebuildGeneration();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// used when logging text performance
|
|
|
|
gfxTextPerfMetrics* GetTextPerfMetrics() { return mTextPerf; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// This will call UpdateUserFonts() if the user font set is changed.
|
|
|
|
void SetUserFontSet(gfxUserFontSet* aUserFontSet);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-18 04:26:50 +03:00
|
|
|
void ClearCachedData() {
|
2014-09-16 13:58:12 +04:00
|
|
|
mUnderlineOffset = UNDERLINE_OFFSET_NOT_SET;
|
2016-08-18 04:26:50 +03:00
|
|
|
mSkipDrawing = false;
|
|
|
|
mHyphenWidth = -1;
|
|
|
|
mCachedEllipsisTextRun = nullptr;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// If there is a user font set, check to see whether the font list or any
|
|
|
|
// caches need updating.
|
2017-06-01 17:42:07 +03:00
|
|
|
void UpdateUserFonts();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-03-06 11:44:18 +03:00
|
|
|
// search for a specific userfont in the list of fonts
|
2014-09-16 13:58:12 +04:00
|
|
|
bool ContainsUserFont(const gfxUserFontEntry* aUserFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool ShouldSkipDrawing() const { return mSkipDrawing; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
class LazyReferenceDrawTargetGetter {
|
|
|
|
public:
|
|
|
|
virtual already_AddRefed<DrawTarget> GetRefDrawTarget() = 0;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
2014-09-16 13:58:12 +04:00
|
|
|
// The gfxFontGroup keeps ownership of this textrun.
|
|
|
|
// It is only guaranteed to exist until the next call to GetEllipsisTextRun
|
2016-03-08 10:56:18 +03:00
|
|
|
// (which might use a different appUnitsPerDev value or flags) for the font
|
|
|
|
// group, or until UpdateUserFonts is called, or the fontgroup is destroyed.
|
2014-09-16 13:58:12 +04:00
|
|
|
// Get it/use it/forget it :) - don't keep a reference that might go stale.
|
2017-05-05 00:25:16 +03:00
|
|
|
gfxTextRun* GetEllipsisTextRun(
|
2017-05-05 00:27:05 +03:00
|
|
|
int32_t aAppUnitsPerDevPixel, mozilla::gfx::ShapedTextFlags aFlags,
|
2015-12-16 00:56:41 +03:00
|
|
|
LazyReferenceDrawTargetGetter& aRefDrawTargetGetter);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
protected:
|
2019-04-27 18:37:58 +03:00
|
|
|
friend class mozilla::PostTraversalTask;
|
|
|
|
|
2019-04-01 17:32:06 +03:00
|
|
|
struct TextRange {
|
|
|
|
TextRange(uint32_t aStart, uint32_t aEnd, gfxFont* aFont,
|
|
|
|
FontMatchType aMatchType,
|
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation)
|
|
|
|
: start(aStart),
|
|
|
|
end(aEnd),
|
|
|
|
font(aFont),
|
|
|
|
matchType(aMatchType),
|
|
|
|
orientation(aOrientation) {}
|
|
|
|
uint32_t Length() const { return end - start; }
|
|
|
|
uint32_t start, end;
|
|
|
|
RefPtr<gfxFont> font;
|
|
|
|
FontMatchType matchType;
|
|
|
|
mozilla::gfx::ShapedTextFlags orientation;
|
|
|
|
};
|
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
// search through pref fonts for a character, return nullptr if no matching
|
2015-03-13 06:00:10 +03:00
|
|
|
// pref font
|
2016-03-08 10:56:18 +03:00
|
|
|
gfxFont* WhichPrefFontSupportsChar(uint32_t aCh, uint32_t aNextCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2017-06-30 01:37:52 +03:00
|
|
|
gfxFont* WhichSystemFontSupportsChar(uint32_t aCh, uint32_t aNextCh,
|
|
|
|
Script aRunScript);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-03-08 10:56:18 +03:00
|
|
|
template <typename T>
|
2019-04-01 17:32:06 +03:00
|
|
|
void ComputeRanges(nsTArray<TextRange>& aRanges, const T* aString,
|
2015-11-28 03:56:33 +03:00
|
|
|
uint32_t aLength, Script aRunScript,
|
|
|
|
mozilla::gfx::ShapedTextFlags aOrientation);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:52 +04:00
|
|
|
class FamilyFace {
|
2018-11-30 13:46:48 +03:00
|
|
|
public:
|
2014-09-25 07:16:52 +04:00
|
|
|
FamilyFace()
|
2019-04-27 18:37:58 +03:00
|
|
|
: mOwnedFamily(nullptr),
|
2014-09-25 07:16:52 +04:00
|
|
|
mFontEntry(nullptr),
|
2019-04-02 00:47:59 +03:00
|
|
|
mGeneric(mozilla::StyleGenericFontFamily::None),
|
2015-11-28 03:56:33 +03:00
|
|
|
mFontCreated(false),
|
|
|
|
mLoading(false),
|
2015-11-11 15:13:33 +03:00
|
|
|
mInvalid(false),
|
2019-04-27 18:37:58 +03:00
|
|
|
mCheckForFallbackFaces(false),
|
|
|
|
mIsSharedFamily(false),
|
|
|
|
mHasFontEntry(false) {}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-28 03:56:33 +03:00
|
|
|
FamilyFace(gfxFontFamily* aFamily, gfxFont* aFont,
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily aGeneric)
|
2019-04-27 18:37:58 +03:00
|
|
|
: mOwnedFamily(aFamily),
|
2018-05-25 16:07:57 +03:00
|
|
|
mGeneric(aGeneric),
|
|
|
|
mFontCreated(true),
|
2015-11-11 15:13:33 +03:00
|
|
|
mLoading(false),
|
|
|
|
mInvalid(false),
|
2019-04-27 18:37:58 +03:00
|
|
|
mCheckForFallbackFaces(false),
|
|
|
|
mIsSharedFamily(false),
|
|
|
|
mHasFontEntry(false) {
|
2014-09-25 07:16:52 +04:00
|
|
|
NS_ASSERTION(aFont, "font pointer must not be null");
|
2015-11-28 03:56:33 +03:00
|
|
|
NS_ASSERTION(!aFamily || aFamily->ContainsFace(aFont->GetFontEntry()),
|
|
|
|
"font is not a member of the given family");
|
2019-04-27 18:37:58 +03:00
|
|
|
NS_IF_ADDREF(aFamily);
|
2014-09-25 07:16:52 +04:00
|
|
|
mFont = aFont;
|
2015-11-28 03:56:33 +03:00
|
|
|
NS_ADDREF(aFont);
|
|
|
|
}
|
|
|
|
|
2017-10-24 11:59:09 +03:00
|
|
|
FamilyFace(gfxFontFamily* aFamily, gfxFontEntry* aFontEntry,
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily aGeneric)
|
2019-04-27 18:37:58 +03:00
|
|
|
: mOwnedFamily(aFamily),
|
2016-03-08 10:56:18 +03:00
|
|
|
mGeneric(aGeneric),
|
|
|
|
mFontCreated(false),
|
2014-09-16 13:58:12 +04:00
|
|
|
mLoading(false),
|
2016-03-08 10:56:18 +03:00
|
|
|
mInvalid(false),
|
2019-04-27 18:37:58 +03:00
|
|
|
mCheckForFallbackFaces(false),
|
|
|
|
mIsSharedFamily(false),
|
|
|
|
mHasFontEntry(true) {
|
2016-03-08 10:56:18 +03:00
|
|
|
NS_ASSERTION(aFontEntry, "font entry pointer must not be null");
|
2017-05-02 13:14:53 +03:00
|
|
|
NS_ASSERTION(!aFamily || aFamily->ContainsFace(aFontEntry),
|
2018-05-30 22:15:35 +03:00
|
|
|
"font is not a member of the given family");
|
2019-04-27 18:37:58 +03:00
|
|
|
NS_IF_ADDREF(aFamily);
|
|
|
|
mFontEntry = aFontEntry;
|
|
|
|
NS_ADDREF(aFontEntry);
|
|
|
|
}
|
|
|
|
|
|
|
|
FamilyFace(mozilla::fontlist::Family* aFamily, gfxFontEntry* aFontEntry,
|
|
|
|
mozilla::StyleGenericFontFamily aGeneric)
|
|
|
|
: mSharedFamily(aFamily),
|
|
|
|
mGeneric(aGeneric),
|
|
|
|
mFontCreated(false),
|
|
|
|
mLoading(false),
|
|
|
|
mInvalid(false),
|
|
|
|
mCheckForFallbackFaces(false),
|
|
|
|
mIsSharedFamily(true),
|
|
|
|
mHasFontEntry(true) {
|
|
|
|
MOZ_ASSERT(aFamily && aFontEntry && aFontEntry->mShmemFace);
|
2017-05-02 13:14:53 +03:00
|
|
|
mFontEntry = aFontEntry;
|
2014-09-25 07:16:52 +04:00
|
|
|
NS_ADDREF(aFontEntry);
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
FamilyFace(const FamilyFace& aOtherFamilyFace)
|
2019-04-27 18:37:58 +03:00
|
|
|
: mGeneric(aOtherFamilyFace.mGeneric),
|
2014-09-25 07:16:54 +04:00
|
|
|
mFontCreated(aOtherFamilyFace.mFontCreated),
|
2017-05-02 13:14:53 +03:00
|
|
|
mLoading(aOtherFamilyFace.mLoading),
|
2015-11-11 15:13:33 +03:00
|
|
|
mInvalid(aOtherFamilyFace.mInvalid),
|
2019-04-27 18:37:58 +03:00
|
|
|
mCheckForFallbackFaces(aOtherFamilyFace.mCheckForFallbackFaces),
|
|
|
|
mIsSharedFamily(aOtherFamilyFace.mIsSharedFamily),
|
|
|
|
mHasFontEntry(aOtherFamilyFace.mHasFontEntry) {
|
|
|
|
if (mIsSharedFamily) {
|
|
|
|
mSharedFamily = aOtherFamilyFace.mSharedFamily;
|
|
|
|
if (mFontCreated) {
|
|
|
|
mFont = aOtherFamilyFace.mFont;
|
|
|
|
NS_ADDREF(mFont);
|
|
|
|
} else if (mHasFontEntry) {
|
|
|
|
mFontEntry = aOtherFamilyFace.mFontEntry;
|
|
|
|
NS_ADDREF(mFontEntry);
|
|
|
|
} else {
|
|
|
|
mSharedFace = aOtherFamilyFace.mSharedFace;
|
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
} else {
|
2019-04-27 18:37:58 +03:00
|
|
|
mOwnedFamily = aOtherFamilyFace.mOwnedFamily;
|
|
|
|
NS_IF_ADDREF(mOwnedFamily);
|
|
|
|
if (mFontCreated) {
|
|
|
|
mFont = aOtherFamilyFace.mFont;
|
|
|
|
NS_ADDREF(mFont);
|
|
|
|
} else {
|
|
|
|
mFontEntry = aOtherFamilyFace.mFontEntry;
|
|
|
|
NS_IF_ADDREF(mFontEntry);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2017-05-02 13:14:53 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2017-05-05 00:27:05 +03:00
|
|
|
~FamilyFace() {
|
2017-06-01 17:42:07 +03:00
|
|
|
if (mFontCreated) {
|
2014-09-16 13:58:12 +04:00
|
|
|
NS_RELEASE(mFont);
|
2019-04-27 18:37:58 +03:00
|
|
|
}
|
|
|
|
if (!mIsSharedFamily) {
|
|
|
|
NS_IF_RELEASE(mOwnedFamily);
|
|
|
|
}
|
|
|
|
if (mHasFontEntry) {
|
|
|
|
NS_RELEASE(mFontEntry);
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 13:53:15 +03:00
|
|
|
FamilyFace& operator=(const FamilyFace& aOther) {
|
2014-09-25 07:16:52 +04:00
|
|
|
if (mFontCreated) {
|
2017-03-17 13:53:15 +03:00
|
|
|
NS_RELEASE(mFont);
|
2019-04-27 18:37:58 +03:00
|
|
|
}
|
|
|
|
if (!mIsSharedFamily) {
|
|
|
|
NS_IF_RELEASE(mOwnedFamily);
|
|
|
|
}
|
|
|
|
if (mHasFontEntry) {
|
|
|
|
NS_RELEASE(mFontEntry);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-03-17 13:53:15 +03:00
|
|
|
mGeneric = aOther.mGeneric;
|
2014-09-25 07:16:52 +04:00
|
|
|
mFontCreated = aOther.mFontCreated;
|
2017-03-17 13:53:15 +03:00
|
|
|
mLoading = aOther.mLoading;
|
|
|
|
mInvalid = aOther.mInvalid;
|
2019-04-27 18:37:58 +03:00
|
|
|
mIsSharedFamily = aOther.mIsSharedFamily;
|
|
|
|
mHasFontEntry = aOther.mHasFontEntry;
|
|
|
|
|
|
|
|
if (mIsSharedFamily) {
|
|
|
|
mSharedFamily = aOther.mSharedFamily;
|
|
|
|
if (mFontCreated) {
|
|
|
|
mFont = aOther.mFont;
|
|
|
|
NS_ADDREF(mFont);
|
|
|
|
} else if (mHasFontEntry) {
|
|
|
|
mFontEntry = aOther.mFontEntry;
|
|
|
|
NS_ADDREF(mFontEntry);
|
|
|
|
} else {
|
|
|
|
mSharedFace = aOther.mSharedFace;
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
} else {
|
2019-04-27 18:37:58 +03:00
|
|
|
mOwnedFamily = aOther.mOwnedFamily;
|
|
|
|
NS_IF_ADDREF(mOwnedFamily);
|
|
|
|
if (mFontCreated) {
|
|
|
|
mFont = aOther.mFont;
|
|
|
|
NS_ADDREF(mFont);
|
|
|
|
} else {
|
|
|
|
mFontEntry = aOther.mFontEntry;
|
|
|
|
NS_IF_ADDREF(mFontEntry);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2017-03-17 13:53:15 +03:00
|
|
|
return *this;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2019-04-27 18:37:58 +03:00
|
|
|
gfxFontFamily* OwnedFamily() const {
|
|
|
|
MOZ_ASSERT(!mIsSharedFamily);
|
|
|
|
return mOwnedFamily;
|
|
|
|
}
|
|
|
|
mozilla::fontlist::Family* SharedFamily() const {
|
|
|
|
MOZ_ASSERT(mIsSharedFamily);
|
|
|
|
return mSharedFamily;
|
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFont* Font() const { return mFontCreated ? mFont : nullptr; }
|
|
|
|
|
|
|
|
gfxFontEntry* FontEntry() const {
|
2019-04-27 18:37:58 +03:00
|
|
|
if (mFontCreated) {
|
|
|
|
return mFont->GetFontEntry();
|
|
|
|
}
|
|
|
|
if (mHasFontEntry) {
|
|
|
|
return mFontEntry;
|
|
|
|
}
|
|
|
|
if (mIsSharedFamily) {
|
|
|
|
return gfxPlatformFontList::PlatformFontList()->GetOrCreateFontEntry(
|
|
|
|
mSharedFace, SharedFamily());
|
|
|
|
}
|
|
|
|
return nullptr;
|
2016-08-18 04:26:50 +03:00
|
|
|
}
|
|
|
|
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily Generic() const { return mGeneric; }
|
2014-09-16 13:58:12 +04:00
|
|
|
|
2019-04-27 18:37:58 +03:00
|
|
|
bool IsSharedFamily() const { return mIsSharedFamily; }
|
2015-03-06 11:44:18 +03:00
|
|
|
bool IsUserFontContainer() const {
|
|
|
|
return FontEntry()->mIsUserFontContainer;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-16 13:58:12 +04:00
|
|
|
bool IsLoading() const { return mLoading; }
|
|
|
|
bool IsInvalid() const { return mInvalid; }
|
|
|
|
void CheckState(bool& aSkipDrawing);
|
|
|
|
void SetLoading(bool aIsLoading) { mLoading = aIsLoading; }
|
2014-09-25 07:16:54 +04:00
|
|
|
void SetInvalid() { mInvalid = true; }
|
2015-11-11 15:13:33 +03:00
|
|
|
bool CheckForFallbackFaces() const { return mCheckForFallbackFaces; }
|
|
|
|
void SetCheckForFallbackFaces() { mCheckForFallbackFaces = true; }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-03 18:14:24 +03:00
|
|
|
// Return true if we're currently loading (or waiting for) a resource that
|
|
|
|
// may support the given character.
|
|
|
|
bool IsLoadingFor(uint32_t aCh) {
|
|
|
|
if (!IsLoading()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
MOZ_ASSERT(IsUserFontContainer());
|
|
|
|
return static_cast<gfxUserFontEntry*>(FontEntry())
|
|
|
|
->CharacterInUnicodeRange(aCh);
|
|
|
|
}
|
|
|
|
|
2014-09-25 07:16:52 +04:00
|
|
|
void SetFont(gfxFont* aFont) {
|
|
|
|
NS_ASSERTION(aFont, "font pointer must not be null");
|
|
|
|
NS_ADDREF(aFont);
|
|
|
|
if (mFontCreated) {
|
|
|
|
NS_RELEASE(mFont);
|
2019-04-27 18:37:58 +03:00
|
|
|
} else if (mHasFontEntry) {
|
|
|
|
NS_RELEASE(mFontEntry);
|
|
|
|
mHasFontEntry = false;
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
2014-09-25 07:16:52 +04:00
|
|
|
mFont = aFont;
|
|
|
|
mFontCreated = true;
|
2014-11-06 07:42:50 +03:00
|
|
|
mLoading = false;
|
2014-09-16 13:58:12 +04:00
|
|
|
}
|
|
|
|
|
2015-04-24 01:15:32 +03:00
|
|
|
bool EqualsUserFont(const gfxUserFontEntry* aUserFont) const;
|
2015-03-13 06:00:10 +03:00
|
|
|
|
2018-05-25 16:07:57 +03:00
|
|
|
private:
|
2019-04-27 18:37:58 +03:00
|
|
|
union {
|
|
|
|
gfxFontFamily* MOZ_OWNING_REF mOwnedFamily;
|
|
|
|
mozilla::fontlist::Family* MOZ_NON_OWNING_REF mSharedFamily;
|
|
|
|
};
|
2014-09-25 07:16:52 +04:00
|
|
|
// either a font or a font entry exists
|
|
|
|
union {
|
|
|
|
// Whichever of these fields is actually present will be a strong
|
2018-05-25 16:07:57 +03:00
|
|
|
// reference, with refcounting handled manually.
|
2015-03-06 11:44:18 +03:00
|
|
|
gfxFont* MOZ_OWNING_REF mFont;
|
2017-06-30 03:52:43 +03:00
|
|
|
gfxFontEntry* MOZ_OWNING_REF mFontEntry;
|
2019-04-27 18:37:58 +03:00
|
|
|
mozilla::fontlist::Face* MOZ_NON_OWNING_REF mSharedFace;
|
2014-09-25 07:16:52 +04:00
|
|
|
};
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily mGeneric;
|
2014-09-25 07:16:52 +04:00
|
|
|
bool mFontCreated : 1;
|
2014-09-25 07:16:54 +04:00
|
|
|
bool mLoading : 1;
|
|
|
|
bool mInvalid : 1;
|
2015-11-11 15:13:33 +03:00
|
|
|
bool mCheckForFallbackFaces : 1;
|
2019-04-27 18:37:58 +03:00
|
|
|
bool mIsSharedFamily : 1;
|
|
|
|
bool mHasFontEntry : 1;
|
2018-11-30 13:46:48 +03:00
|
|
|
};
|
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
// List of font families, either named or generic.
|
|
|
|
// Generic names map to system pref fonts based on language.
|
2014-09-16 13:58:12 +04:00
|
|
|
mozilla::FontFamilyList mFamilyList;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
// Fontlist containing a font entry for each family found. gfxFont objects
|
|
|
|
// are created as needed and userfont loads are initiated when needed.
|
|
|
|
// Code should be careful about addressing this array directly.
|
2014-09-16 13:58:12 +04:00
|
|
|
nsTArray<FamilyFace> mFonts;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> mDefaultFont;
|
2014-09-25 07:16:54 +04:00
|
|
|
gfxFontStyle mStyle;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxFloat mUnderlineOffset;
|
|
|
|
gfxFloat mHyphenWidth;
|
2015-11-20 16:01:12 +03:00
|
|
|
gfxFloat mDevToCssSize;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxUserFontSet> mUserFontSet;
|
2014-09-16 13:58:12 +04:00
|
|
|
uint64_t mCurrGeneration; // track the current user font set generation,
|
|
|
|
// rebuild font list if needed
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
gfxTextPerfMetrics* mTextPerf;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Cache a textrun representing an ellipsis (useful for CSS text-overflow)
|
2015-04-24 01:15:32 +03:00
|
|
|
// at a specific appUnitsPerDevPixel size and orientation
|
2016-08-19 15:14:22 +03:00
|
|
|
RefPtr<gfxTextRun> mCachedEllipsisTextRun;
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// cache the most recent pref font to avoid general pref font lookup
|
2019-04-01 17:33:34 +03:00
|
|
|
FontFamily mLastPrefFamily;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<gfxFont> mLastPrefFont;
|
2014-09-16 13:58:12 +04:00
|
|
|
eFontPrefLang mLastPrefLang; // lang group for last pref font
|
|
|
|
eFontPrefLang mPageLang;
|
|
|
|
bool mLastPrefFirstFont; // is this the first font in the list of pref fonts
|
|
|
|
// for this lang group?
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
bool mSkipDrawing; // hide text while waiting for a font
|
|
|
|
// download to complete (or fallback
|
|
|
|
// timer to fire)
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
/**
|
|
|
|
* Textrun creation short-cuts for special cases where we don't need to
|
|
|
|
* call a font shaper to generate glyphs.
|
|
|
|
*/
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeEmptyTextRun(
|
2017-05-05 00:27:05 +03:00
|
|
|
const Parameters* aParams, mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeSpaceTextRun(
|
2017-05-05 00:27:05 +03:00
|
|
|
const Parameters* aParams, mozilla::gfx::ShapedTextFlags aFlags,
|
|
|
|
nsTextFrameUtils::Flags aFlags2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2016-08-19 15:14:22 +03:00
|
|
|
already_AddRefed<gfxTextRun> MakeBlankTextRun(
|
2016-04-19 19:13:28 +03:00
|
|
|
uint32_t aLength, const Parameters* aParams,
|
2017-05-05 00:27:05 +03:00
|
|
|
mozilla::gfx::ShapedTextFlags aFlags, nsTextFrameUtils::Flags aFlags2);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Initialize the list of fonts
|
|
|
|
void BuildFontList();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2019-07-03 18:14:24 +03:00
|
|
|
// Get the font at index i within the fontlist, for character aCh (in case
|
|
|
|
// of fonts with multiple resources and unicode-range partitioning).
|
2014-09-25 07:16:54 +04:00
|
|
|
// Will initiate userfont load if not already loaded.
|
2019-07-03 18:14:24 +03:00
|
|
|
// May return null if userfont not loaded or if font invalid.
|
|
|
|
// If *aLoading is true, a relevant resource is already being loaded so no
|
|
|
|
// new download will be initiated; if a download is started, *aLoading will
|
|
|
|
// be set to true on return.
|
|
|
|
gfxFont* GetFontAt(int32_t i, uint32_t aCh, bool* aLoading);
|
|
|
|
|
|
|
|
// Simplified version of GetFontAt() for use where we just need a font for
|
|
|
|
// metrics, math layout tables, etc.
|
|
|
|
gfxFont* GetFontAt(int32_t i, uint32_t aCh = 0x20) {
|
|
|
|
bool loading = false;
|
|
|
|
return GetFontAt(i, aCh, &loading);
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-25 07:16:54 +04:00
|
|
|
// will always return a font or force a shutdown
|
|
|
|
gfxFont* GetDefaultFont();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Init this font group's font metrics. If there no bad fonts, you don't need
|
|
|
|
// to call this. But if there are one or more bad fonts which have bad
|
|
|
|
// underline offset, you should call this with the *first* bad font.
|
|
|
|
void InitMetricsForBadFont(gfxFont* aBadFont);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Set up the textrun glyphs for an entire text run:
|
|
|
|
// find script runs, and then call InitScriptRun for each
|
|
|
|
template <typename T>
|
2015-12-16 00:56:41 +03:00
|
|
|
void InitTextRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
2014-12-22 19:35:54 +03:00
|
|
|
const T* aString, uint32_t aLength,
|
|
|
|
gfxMissingFontRecorder* aMFR);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// InitTextRun helper to handle a single script run, by finding font ranges
|
|
|
|
// and calling each font's InitTextRun() as appropriate
|
|
|
|
template <typename T>
|
2015-12-16 00:56:41 +03:00
|
|
|
void InitScriptRun(DrawTarget* aDrawTarget, gfxTextRun* aTextRun,
|
2014-09-16 13:58:12 +04:00
|
|
|
const T* aString, uint32_t aScriptRunStart,
|
|
|
|
uint32_t aScriptRunEnd, Script aRunScript,
|
2014-12-22 19:35:54 +03:00
|
|
|
gfxMissingFontRecorder* aMFR);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// Helper for font-matching:
|
2015-11-11 15:13:33 +03:00
|
|
|
// search all faces in a family for a fallback in cases where it's unclear
|
|
|
|
// whether the family might have a font for a given character
|
2019-04-27 18:37:58 +03:00
|
|
|
gfxFont* FindFallbackFaceForChar(const FamilyFace& aFamily, uint32_t aCh);
|
|
|
|
|
|
|
|
gfxFont* FindFallbackFaceForChar(mozilla::fontlist::Family* aFamily,
|
|
|
|
uint32_t aCh);
|
|
|
|
|
2017-10-28 15:21:38 +03:00
|
|
|
gfxFont* FindFallbackFaceForChar(gfxFontFamily* aFamily, uint32_t aCh);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-11-11 15:13:33 +03:00
|
|
|
// helper methods for looking up fonts
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
// lookup and add a font with a given name (i.e. *not* a generic!)
|
2018-09-12 22:34:57 +03:00
|
|
|
void AddPlatformFont(const nsACString& aName, bool aQuotedName,
|
2018-05-25 16:07:57 +03:00
|
|
|
nsTArray<FamilyAndGeneric>& aFamilyList);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2015-09-29 04:51:28 +03:00
|
|
|
// do style selection and add entries to list
|
2018-05-25 16:07:57 +03:00
|
|
|
void AddFamilyToFontList(gfxFontFamily* aFamily,
|
2019-04-02 00:47:59 +03:00
|
|
|
mozilla::StyleGenericFontFamily aGeneric);
|
2019-04-27 18:37:58 +03:00
|
|
|
void AddFamilyToFontList(mozilla::fontlist::Family* aFamily,
|
|
|
|
mozilla::StyleGenericFontFamily aGeneric);
|
2014-09-16 13:58:12 +04:00
|
|
|
};
|
2014-12-22 19:35:54 +03:00
|
|
|
|
|
|
|
// A "missing font recorder" is to be used during text-run creation to keep
|
|
|
|
// a record of any scripts encountered for which font coverage was lacking;
|
|
|
|
// when Flush() is called, it sends a notification that front-end code can use
|
|
|
|
// to download fonts on demand (or whatever else it wants to do).
|
|
|
|
|
|
|
|
#define GFX_MISSING_FONTS_NOTIFY_PREF "gfx.missing_fonts.notify"
|
|
|
|
|
|
|
|
class gfxMissingFontRecorder {
|
|
|
|
public:
|
|
|
|
gfxMissingFontRecorder() {
|
|
|
|
MOZ_COUNT_CTOR(gfxMissingFontRecorder);
|
|
|
|
memset(&mMissingFonts, 0, sizeof(mMissingFonts));
|
|
|
|
}
|
|
|
|
|
|
|
|
~gfxMissingFontRecorder() {
|
|
|
|
#ifdef DEBUG
|
|
|
|
for (uint32_t i = 0; i < kNumScriptBitsWords; i++) {
|
|
|
|
NS_ASSERTION(mMissingFonts[i] == 0,
|
|
|
|
"failed to flush the missing-font recorder");
|
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
#endif
|
2014-12-22 19:35:54 +03:00
|
|
|
MOZ_COUNT_DTOR(gfxMissingFontRecorder);
|
2018-11-30 13:46:48 +03:00
|
|
|
}
|
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
// record this script code in our mMissingFonts bitset
|
2016-04-21 20:58:59 +03:00
|
|
|
void RecordScript(mozilla::unicode::Script aScriptCode) {
|
|
|
|
mMissingFonts[static_cast<uint32_t>(aScriptCode) >> 5] |=
|
|
|
|
(1 << (static_cast<uint32_t>(aScriptCode) & 0x1f));
|
2014-12-22 19:35:54 +03:00
|
|
|
}
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
// send a notification of any missing-scripts that have been
|
|
|
|
// recorded, and clear the mMissingFonts set for re-use
|
|
|
|
void Flush();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
// forget any missing-scripts that have been recorded up to now;
|
|
|
|
// called before discarding a recorder we no longer care about
|
|
|
|
void Clear() { memset(&mMissingFonts, 0, sizeof(mMissingFonts)); }
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2014-12-22 19:35:54 +03:00
|
|
|
private:
|
|
|
|
// Number of 32-bit words needed for the missing-script flags
|
|
|
|
static const uint32_t kNumScriptBitsWords =
|
2016-04-21 20:58:59 +03:00
|
|
|
((static_cast<int>(mozilla::unicode::Script::NUM_SCRIPT_CODES) + 31) /
|
|
|
|
32);
|
2014-12-22 19:35:54 +03:00
|
|
|
uint32_t mMissingFonts[kNumScriptBitsWords];
|
|
|
|
};
|
|
|
|
|
2014-09-16 13:58:12 +04:00
|
|
|
#endif
|