ported from UXP: Issue #457 - Remove the constructor from gfxShapedText::CompressedGlyph and make it a trivial class (c782076a)

This commit is contained in:
2022-05-31 11:35:30 +08:00
parent 03824805f1
commit ca5b2cb267
9 changed files with 108 additions and 73 deletions
+8 -7
View File
@@ -310,6 +310,8 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
CTRunRef aCTRun,
int32_t aStringOffset)
{
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
// The word has been bidi-wrapped; aStringOffset is the number
// of chars at the beginning of the CTLine that we should skip.
// aCTRun is a glyph run from the CoreText layout process.
@@ -392,8 +394,7 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
nullptr, nullptr, nullptr);
AutoTArray<gfxShapedText::DetailedGlyph,1> detailedGlyphs;
gfxShapedText::CompressedGlyph *charGlyphs =
aShapedText->GetCharacterGlyphs() + aOffset;
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
// CoreText gives us the glyphindex-to-charindex mapping, which relates each glyph
// to a source text character; we also need the charindex-to-glyphindex mapping to
@@ -614,10 +615,10 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
advance = int32_t(toNextGlyph * appUnitsPerDevUnit);
}
gfxTextRun::CompressedGlyph textRunGlyph;
textRunGlyph.SetComplex(charGlyphs[baseCharIndex].IsClusterStart(),
true, detailedGlyphs.Length());
aShapedText->SetGlyphs(aOffset + baseCharIndex, textRunGlyph,
bool isClusterStart = charGlyphs[baseCharIndex].IsClusterStart();
aShapedText->SetGlyphs(aOffset + baseCharIndex,
CompressedGlyph::MakeComplex(isClusterStart, true,
detailedGlyphs.Length()),
detailedGlyphs.Elements());
detailedGlyphs.Clear();
@@ -625,7 +626,7 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
// the rest of the chars in the group are ligature continuations, no associated glyphs
while (++baseCharIndex != endCharIndex && baseCharIndex < wordLength) {
gfxShapedText::CompressedGlyph &shapedTextGlyph = charGlyphs[baseCharIndex];
CompressedGlyph &shapedTextGlyph = charGlyphs[baseCharIndex];
NS_ASSERTION(!shapedTextGlyph.IsSimpleGlyph(), "overwriting a simple glyph");
shapedTextGlyph.SetComplex(inOrder && shapedTextGlyph.IsClusterStart(), false, 0);
}
+10 -7
View File
@@ -62,13 +62,14 @@ void
gfxFT2Font::AddRange(const char16_t *aText, uint32_t aOffset,
uint32_t aLength, gfxShapedText *aShapedText)
{
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
const uint32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
// we'll pass this in/figure it out dynamically, but at this point there can be only one face.
gfxFT2LockedFace faceLock(this);
FT_Face face = faceLock.get();
gfxShapedText::CompressedGlyph *charGlyphs =
aShapedText->GetCharacterGlyphs();
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs();
const gfxFT2Font::CachedGlyphData *cgd = nullptr, *cgdNext = nullptr;
@@ -135,8 +136,8 @@ gfxFT2Font::AddRange(const char16_t *aText, uint32_t aOffset,
}
if (advance >= 0 &&
gfxShapedText::CompressedGlyph::IsSimpleAdvance(advance) &&
gfxShapedText::CompressedGlyph::IsSimpleGlyphID(gid)) {
CompressedGlyph::IsSimpleAdvance(advance) &&
CompressedGlyph::IsSimpleGlyphID(gid)) {
charGlyphs[aOffset].SetSimpleGlyph(advance, gid);
} else if (gid == 0) {
// gid = 0 only happens when the glyph is missing from the font
@@ -149,9 +150,11 @@ gfxFT2Font::AddRange(const char16_t *aText, uint32_t aOffset,
details.mAdvance = advance;
details.mXOffset = 0;
details.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(charGlyphs[aOffset].IsClusterStart(), true, 1);
aShapedText->SetGlyphs(aOffset, g, &details);
bool isClusterStart = charGlyphs[aOffset].IsClusterStart();
aShapedText->SetGlyphs(aOffset,
CompressedGlyph::MakeComplex(isClusterStart,
true, 1),
&details);
}
}
}
+3 -3
View File
@@ -635,10 +635,10 @@ gfxShapedText::SetupClusterBoundaries(uint32_t aOffset,
const char16_t *aString,
uint32_t aLength)
{
CompressedGlyph *glyphs = GetCharacterGlyphs() + aOffset;
CompressedGlyph* glyphs = GetCharacterGlyphs() + aOffset;
gfxTextRun::CompressedGlyph extendCluster;
extendCluster.SetComplex(false, true, 0);
CompressedGlyph extendCluster =
CompressedGlyph::MakeComplex(false, true, 0);
ClusterIterator iter(aString, aLength);
+46 -21
View File
@@ -247,7 +247,7 @@ struct gfxTextRange {
/**
* Font cache design:
*
*
* The mFonts hashtable contains most fonts, indexed by (gfxFontEntry*, style).
* It does not add a reference to the fonts it contains.
* When a font's refcount decreases to zero, instead of deleting it we
@@ -701,21 +701,19 @@ public:
* This class records the information associated with a character in the
* input string. It's optimized for the case where there is one glyph
* representing that character alone.
*
*
* A character can have zero or more associated glyphs. Each glyph
* has an advance width and an x and y offset.
* A character may be the start of a cluster.
* A character may be the start of a ligature group.
* A character can be "missing", indicating that the system is unable
* to render the character.
*
*
* All characters in a ligature group conceptually share all the glyphs
* associated with the characters in a group.
*/
class CompressedGlyph {
public:
CompressedGlyph() { mValue = 0; }
enum {
// Indicates that a cluster and ligature group starts at this
// character; this character has a single glyph with a reasonable
@@ -854,25 +852,52 @@ public:
return toggle;
}
CompressedGlyph& SetSimpleGlyph(uint32_t aAdvanceAppUnits, uint32_t aGlyph) {
// 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");
CompressedGlyph g;
g.mValue = FLAG_IS_SIMPLE_GLYPH |
(aAdvanceAppUnits << ADVANCE_SHIFT) |
aGlyph;
return g;
}
// Assign a simple glyph value to an existing CompressedGlyph record,
// preserving line-break/is-space flags if present.
CompressedGlyph& SetSimpleGlyph(uint32_t aAdvanceAppUnits,
uint32_t aGlyph) {
NS_ASSERTION(!CharTypeFlags(), "Char type flags lost");
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
FLAG_IS_SIMPLE_GLYPH |
(aAdvanceAppUnits << ADVANCE_SHIFT) | aGlyph;
MakeSimpleGlyph(aAdvanceAppUnits, aGlyph).mValue;
return *this;
}
// 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;
g.mValue = FLAG_NOT_MISSING |
(aClusterStart ? 0 : FLAG_NOT_CLUSTER_START) |
(aLigatureStart ? 0 : FLAG_NOT_LIGATURE_GROUP_START) |
(aGlyphCount << GLYPH_COUNT_SHIFT);
return g;
}
// 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) {
uint32_t aGlyphCount) {
mValue = (mValue & (FLAGS_CAN_BREAK_BEFORE | FLAG_CHAR_IS_SPACE)) |
FLAG_NOT_MISSING |
CharTypeFlags() |
(aClusterStart ? 0 : FLAG_NOT_CLUSTER_START) |
(aLigatureStart ? 0 : FLAG_NOT_LIGATURE_GROUP_START) |
(aGlyphCount << GLYPH_COUNT_SHIFT);
MakeComplex(aClusterStart, aLigatureStart, aGlyphCount).mValue;
return *this;
}
/**
* Missing glyphs are treated as ligature group starts; don't mess with
* the cluster-start flag (see bugs 618870 and 619286).
@@ -929,7 +954,7 @@ public:
/** The advance, x-offset and y-offset of the glyph, in appunits
* mAdvance is in the text direction (RTL or LTR)
* mXOffset is always from left to right
* mYOffset is always from top to bottom */
* mYOffset is always from top to bottom */
int32_t mAdvance;
float mXOffset, mYOffset;
};
@@ -1054,7 +1079,7 @@ protected:
// 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
// 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.
@@ -1597,11 +1622,11 @@ public:
// (offset1, length1) plus the advance width of (offset1 + length1,
// length2) should be the advance width of (offset1, length1 + length2)
gfxFloat mAdvanceWidth;
// For zero-width substrings, these must be zero!
gfxFloat mAscent; // always non-negative
gfxFloat mDescent; // always non-negative
// Bounding box that is guaranteed to include everything drawn.
// If a tight boundingBox was requested when these metrics were
// generated, this will tightly wrap the glyphs, otherwise it is
@@ -1664,11 +1689,11 @@ public:
* @param aSpacing spacing to insert before and after glyphs. The bounding box
* need not include the spacing itself, but the spacing affects the glyph
* positions. null if there is no spacing.
*
*
* Callers guarantee:
* -- aStart and aEnd are aligned to cluster and ligature boundaries
* -- all glyphs use this font
*
*
* The default implementation just uses font metrics and aTextRun's
* advances, and assumes no characters fall outside the font box. In
* general this is insufficient, because that assumption is not always true.
@@ -1723,7 +1748,7 @@ public:
(mUnicodeRangeMap && !mUnicodeRangeMap->test(ch))) {
return false;
}
return mFontEntry->HasCharacter(ch);
return mFontEntry->HasCharacter(ch);
}
const gfxCharacterMap* GetUnicodeRangeMap() const {
@@ -1738,7 +1763,7 @@ public:
if (!mIsValid) {
return 0;
}
return mFontEntry->GetUVSGlyph(aCh, aVS);
return mFontEntry->GetUVSGlyph(aCh, aVS);
}
template<typename T>
+12 -9
View File
@@ -215,6 +215,8 @@ gfxGraphiteShaper::SetGlyphsFromSegment(DrawTarget *aDrawTarget,
const char16_t *aText,
gr_segment *aSegment)
{
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
int32_t dev2appUnits = aShapedText->GetAppUnitsPerDevUnit();
bool rtl = aShapedText->IsRightToLeft();
@@ -291,8 +293,7 @@ gfxGraphiteShaper::SetGlyphsFromSegment(DrawTarget *aDrawTarget,
bool roundX, roundY;
GetRoundOffsetsToPixels(aDrawTarget, &roundX, &roundY);
gfxShapedText::CompressedGlyph *charGlyphs =
aShapedText->GetCharacterGlyphs() + aOffset;
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
// now put glyphs into the textrun, one cluster at a time
for (uint32_t i = 0; i <= cIndex; ++i) {
@@ -325,8 +326,8 @@ gfxGraphiteShaper::SetGlyphsFromSegment(DrawTarget *aDrawTarget,
uint32_t appAdvance = roundX ? NSToIntRound(adv) * dev2appUnits :
NSToIntRound(adv * dev2appUnits);
if (c.nGlyphs == 1 &&
gfxShapedText::CompressedGlyph::IsSimpleGlyphID(gids[c.baseGlyph]) &&
gfxShapedText::CompressedGlyph::IsSimpleAdvance(appAdvance) &&
CompressedGlyph::IsSimpleGlyphID(gids[c.baseGlyph]) &&
CompressedGlyph::IsSimpleAdvance(appAdvance) &&
charGlyphs[offs].IsClusterStart() &&
yLocs[c.baseGlyph] == 0)
{
@@ -352,15 +353,17 @@ gfxGraphiteShaper::SetGlyphsFromSegment(DrawTarget *aDrawTarget,
d->mAdvance = 0;
}
}
gfxShapedText::CompressedGlyph g;
g.SetComplex(charGlyphs[offs].IsClusterStart(),
true, details.Length());
aShapedText->SetGlyphs(aOffset + offs, g, details.Elements());
bool isClusterStart = charGlyphs[offs].IsClusterStart();
aShapedText->SetGlyphs(aOffset + offs,
CompressedGlyph::MakeComplex(isClusterStart,
true,
details.Length()),
details.Elements());
}
for (uint32_t j = c.baseChar + 1; j < c.baseChar + c.nChars; ++j) {
NS_ASSERTION(j < aLength, "unexpected offset");
gfxShapedText::CompressedGlyph &g = charGlyphs[j];
CompressedGlyph &g = charGlyphs[j];
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
g.SetComplex(g.IsClusterStart(), false, 0);
}
+12 -10
View File
@@ -827,7 +827,7 @@ GetKernValueVersion1Fmt3(const void* aSubtable,
hdr->leftClassCount * hdr->rightClassCount > aSubtableLen) {
return 0;
}
if (aFirstGlyph >= glyphCount || aSecondGlyph >= glyphCount) {
// glyphs are out of range for the class tables
return 0;
@@ -1543,6 +1543,8 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(DrawTarget *aDrawTarget,
hb_buffer_t *aBuffer,
bool aVertical)
{
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
uint32_t numGlyphs;
const hb_glyph_info_t *ginfo = hb_buffer_get_glyph_infos(aBuffer, &numGlyphs);
if (numGlyphs == 0) {
@@ -1581,8 +1583,7 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(DrawTarget *aDrawTarget,
}
int32_t appUnitsPerDevUnit = aShapedText->GetAppUnitsPerDevUnit();
gfxShapedText::CompressedGlyph *charGlyphs =
aShapedText->GetCharacterGlyphs() + aOffset;
CompressedGlyph* charGlyphs = aShapedText->GetCharacterGlyphs() + aOffset;
// factor to convert 16.16 fixed-point pixels to app units
// (only used if not rounding)
@@ -1728,8 +1729,8 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(DrawTarget *aDrawTarget,
}
// Check if it's a simple one-to-one mapping
if (glyphsInClump == 1 &&
gfxTextRun::CompressedGlyph::IsSimpleGlyphID(ginfo[glyphStart].codepoint) &&
gfxTextRun::CompressedGlyph::IsSimpleAdvance(advance) &&
CompressedGlyph::IsSimpleGlyphID(ginfo[glyphStart].codepoint) &&
CompressedGlyph::IsSimpleAdvance(advance) &&
charGlyphs[baseCharIndex].IsClusterStart() &&
iOffset == 0 && b_offset == 0 &&
b_advance == 0 && bPos == 0)
@@ -1800,11 +1801,12 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(DrawTarget *aDrawTarget,
}
}
gfxShapedText::CompressedGlyph g;
g.SetComplex(charGlyphs[baseCharIndex].IsClusterStart(),
true, detailedGlyphs.Length());
bool isClusterStart = charGlyphs[baseCharIndex].IsClusterStart();
aShapedText->SetGlyphs(aOffset + baseCharIndex,
g, detailedGlyphs.Elements());
CompressedGlyph::MakeComplex(isClusterStart,
true,
detailedGlyphs.Length()),
detailedGlyphs.Elements());
detailedGlyphs.Clear();
}
@@ -1813,7 +1815,7 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(DrawTarget *aDrawTarget,
// no associated glyphs
while (++baseCharIndex != endCharIndex &&
baseCharIndex < int32_t(wordLength)) {
gfxShapedText::CompressedGlyph &g = charGlyphs[baseCharIndex];
CompressedGlyph &g = charGlyphs[baseCharIndex];
NS_ASSERTION(!g.IsSimpleGlyph(), "overwriting a simple glyph");
g.SetComplex(g.IsClusterStart(), false, 0);
}
+5 -5
View File
@@ -1441,8 +1441,8 @@ gfxTextRun::SetSpaceGlyphIfSimple(gfxFont* aFont, uint32_t aCharIndex,
AddGlyphRun(aFont, gfxTextRange::kFontGroup, aCharIndex, false,
aOrientation);
CompressedGlyph g;
g.SetSimpleGlyph(spaceWidthAppUnits, spaceGlyph);
CompressedGlyph g =
CompressedGlyph::MakeSimpleGlyph(spaceWidthAppUnits, spaceGlyph);
if (aSpaceChar == ' ') {
g.SetIsSpace();
}
@@ -2520,8 +2520,8 @@ gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget,
detailedGlyph.mGlyphID = mainFont->GetSpaceGlyph();
detailedGlyph.mAdvance = advance;
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(true, true, 1);
CompressedGlyph g =
CompressedGlyph::MakeComplex(true, true, 1);
aTextRun->SetGlyphs(aOffset + index,
g, &detailedGlyph);
}
@@ -3134,7 +3134,7 @@ gfxFontGroup::WhichPrefFontSupportsChar(uint32_t aCh, uint32_t aNextCh)
uint32_t unicodeRange = FindCharUnicodeRange(aCh);
charLang = pfl->GetFontPrefLangFor(unicodeRange);
}
// if the last pref font was the first family in the pref list, no need to recheck through a list of families
if (mLastPrefFont && charLang == mLastPrefLang &&
mLastPrefFirstFont && mLastPrefFont->HasCharacter(aCh)) {
+1
View File
@@ -773,6 +773,7 @@ private:
class gfxFontGroup : public gfxTextRunFactory {
public:
typedef mozilla::unicode::Script Script;
typedef gfxShapedText::CompressedGlyph CompressedGlyph;
static void Shutdown(); // platform must call this to release the languageAtomService
+11 -11
View File
@@ -581,9 +581,9 @@ nsOpenTypeTable::MakeTextRun(DrawTarget* aDrawTarget,
aFontGroup->GetFirstValidFont()->
GetGlyphHAdvance(aDrawTarget, aGlyph.glyphID));
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(true, true, 1);
textRun->SetGlyphs(0, g, &detailedGlyph);
textRun->SetGlyphs(0,
gfxShapedText::CompressedGlyph::MakeComplex(true, true, 1),
&detailedGlyph);
return textRun.forget();
}
@@ -1457,7 +1457,7 @@ nsMathMLChar::StretchEnumContext::EnumCallback(const FontFamilyName& aFamily,
if (!openTypeTable) {
if (context->mTablesTried.Contains(glyphTable))
return true; // already tried this one
// Only try this table once.
context->mTablesTried.AppendElement(glyphTable);
}
@@ -1624,7 +1624,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
if (!maxWidth && !largeop) {
// Doing Stretch() not GetMaxWidth(),
// and not a largeop in display mode; we're done if size fits
if ((targetSize <= 0) ||
if ((targetSize <= 0) ||
((isVertical && charSize >= targetSize) ||
IsSizeOK(charSize, targetSize, aStretchHint)))
done = true;
@@ -1676,7 +1676,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
// variables accordingly.
mUnscaledAscent = aDesiredStretchSize.ascent;
}
if (glyphFound) {
return NS_OK;
}
@@ -1693,7 +1693,7 @@ nsMathMLChar::StretchInternal(nsPresContext* aPresContext,
if (!Preferences::GetBool("mathml.scale_stretchy_operators.enabled", true)) {
return NS_OK;
}
// stretchy character
if (stretchy) {
if (isVertical) {
@@ -1861,7 +1861,7 @@ public:
nsDisplayMathMLCharForeground(nsDisplayListBuilder* aBuilder,
nsIFrame* aFrame, nsMathMLChar* aChar,
uint32_t aIndex, bool aIsSelected)
: nsDisplayItem(aBuilder, aFrame), mChar(aChar),
: nsDisplayItem(aBuilder, aFrame), mChar(aChar),
mIndex(aIndex), mIsSelected(aIsSelected) {
MOZ_COUNT_CTOR(nsDisplayMathMLCharForeground);
}
@@ -1884,7 +1884,7 @@ public:
temp.Inflate(mFrame->PresContext()->AppUnitsPerDevPixel());
return temp;
}
virtual void Paint(nsDisplayListBuilder* aBuilder,
nsRenderingContext* aCtx) override
{
@@ -1899,7 +1899,7 @@ public:
bool snap;
return GetBounds(aBuilder, &snap);
}
virtual uint32_t GetPerFrameKey() override {
return (mIndex << nsDisplayItem::TYPE_BITS)
| nsDisplayItem::GetPerFrameKey();
@@ -2353,7 +2353,7 @@ nsMathMLChar::PaintHorizontally(nsPresContext* aPresContext,
// _cairo_scaled_font_glyph_device_extents rounds outwards to the nearest
// pixel, so the bm values can include 1 row of faint pixels on each edge.
// Don't rely on this pixel as it can look like a gap.
if (bm.rightBearing - bm.leftBearing >= 2 * oneDevPixel) {
if (bm.rightBearing - bm.leftBearing >= 2 * oneDevPixel) {
start[i] = dx + bm.leftBearing + oneDevPixel; // left join
end[i] = dx + bm.rightBearing - oneDevPixel; // right join
} else {