Skip to content

Commit

Permalink
Bug 1412355 - Replace the mXOffset/mYOffset fields in DetailedGlyph r…
Browse files Browse the repository at this point in the history
…ecords with a gfx::Point that stores glyph offsets in line-orientation-relative coordinates. r=jrmuizel
  • Loading branch information
jfkthame committed Oct 28, 2017
1 parent 23069ba commit 8397a85
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 43 deletions.
3 changes: 1 addition & 2 deletions gfx/thebes/gfxCoreTextShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,7 @@ gfxCoreTextShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
while (true) {
gfxTextRun::DetailedGlyph *details = detailedGlyphs.AppendElement();
details->mGlyphID = glyphs[glyphStart];
details->mXOffset = 0;
details->mYOffset = -positions[glyphStart].y * appUnitsPerDevUnit;
details->mOffset.y = -positions[glyphStart].y * appUnitsPerDevUnit;
details->mAdvance = advance;
if (++glyphStart >= glyphEnd) {
break;
Expand Down
2 changes: 0 additions & 2 deletions gfx/thebes/gfxFT2Fonts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,6 @@ gfxFT2Font::AddRange(const char16_t *aText, uint32_t aOffset,
NS_ASSERTION(details.mGlyphID == gid,
"Seriously weird glyph ID detected!");
details.mAdvance = advance;
details.mXOffset = 0;
details.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(charGlyphs[aOffset].IsClusterStart(), true, 1);
aShapedText->SetGlyphs(aOffset, g, &details);
Expand Down
22 changes: 4 additions & 18 deletions gfx/thebes/gfxFont.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,6 @@ gfxShapedText::SetMissingGlyph(uint32_t aIndex, uint32_t aChar, gfxFont *aFont)
mAppUnitsPerDevUnit)));
details->mAdvance = uint32_t(width * mAppUnitsPerDevUnit);
}
details->mXOffset = 0;
details->mYOffset = 0;
GetCharacterGlyphs()[aIndex].SetMissing(1);
}

Expand All @@ -707,8 +705,6 @@ gfxShapedText::FilterIfIgnorable(uint32_t aIndex, uint32_t aCh)
DetailedGlyph *details = AllocateDetailedGlyphs(aIndex, 1);
details->mGlyphID = aCh;
details->mAdvance = 0;
details->mXOffset = 0;
details->mYOffset = 0;
GetCharacterGlyphs()[aIndex].SetMissing(1);
return true;
}
Expand All @@ -733,7 +729,7 @@ gfxShapedText::AdjustAdvancesForSyntheticBold(float aSynBoldOffset,
// rare case, tested by making this the default
uint32_t glyphIndex = glyphData->GetSimpleGlyph();
glyphData->SetComplex(true, true, 1);
DetailedGlyph detail = {glyphIndex, advance, 0, 0};
DetailedGlyph detail = { glyphIndex, advance, gfx::Point() };
SetGlyphs(i, *glyphData, &detail);
}
} else {
Expand Down Expand Up @@ -1941,14 +1937,7 @@ gfxFont::DrawGlyphs(const gfxShapedText* aShapedText,
return false;
}
} else {
gfx::Point glyphPt(*aPt);
if (aBuffer.mFontParams.isVerticalFont) {
glyphPt.x += details->mYOffset;
glyphPt.y += details->mXOffset;
} else {
glyphPt.x += details->mXOffset;
glyphPt.y += details->mYOffset;
}
gfx::Point glyphPt(*aPt + details->mOffset);
DrawOneGlyph<FC>(details->mGlyphID, glyphPt, aBuffer,
&emittedGlyphs);
}
Expand Down Expand Up @@ -2584,7 +2573,8 @@ gfxFont::Measure(const gfxTextRun *aTextRun,
uint32_t j;
for (j = 0; j < glyphCount; ++j, ++details) {
uint32_t glyphIndex = details->mGlyphID;
gfxPoint glyphPt(x + details->mXOffset, details->mYOffset);
gfxPoint glyphPt(x + details->mOffset.x,
details->mOffset.y);
double advance = details->mAdvance;
gfxRect glyphRect;
if (glyphData->IsMissing() || !extents ||
Expand All @@ -2595,10 +2585,6 @@ gfxFont::Measure(const gfxTextRun *aTextRun,
glyphRect = gfxRect(0, -metrics.mAscent,
advance, metrics.mAscent + metrics.mDescent);
}
if (orientation == eVertical) {
Swap(glyphRect.x, glyphRect.y);
Swap(glyphRect.width, glyphRect.height);
}
if (isRTL) {
glyphRect -= gfxPoint(advance, 0);
}
Expand Down
18 changes: 10 additions & 8 deletions gfx/thebes/gfxFont.h
Original file line number Diff line number Diff line change
Expand Up @@ -957,15 +957,17 @@ class gfxShapedText
* in SimpleGlyph format, we use an array of DetailedGlyphs instead.
*/
struct DetailedGlyph {
/** The glyphID, or the Unicode character
* if this is a missing glyph */
// The glyphID, or the Unicode character if this is a missing glyph
uint32_t mGlyphID;
/** 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 */
// The advance of the glyph, in appunits.
// mAdvance is in the text direction (RTL or LTR),
// and will normally be non-negative (although this is not guaranteed)
int32_t mAdvance;
float mXOffset, mYOffset;
// The offset from the glyph's default position, in line-relative
// coordinates (so mOffset.x is an offset in the line-right direction,
// and mOffset.y is an offset in line-downwards direction).
// These values are in floating-point appUnits.
mozilla::gfx::Point mOffset;
};

void SetGlyphs(uint32_t aCharIndex, CompressedGlyph aGlyph,
Expand Down Expand Up @@ -1083,7 +1085,7 @@ class gfxShapedText
DetailedGlyph details = {
aGlyph.GetSimpleGlyph(),
(int32_t) aGlyph.GetSimpleAdvance(),
0, 0
mozilla::gfx::Point()
};
SetGlyphs(aIndex, CompressedGlyph().SetComplex(true, true, 1),
&details);
Expand Down
9 changes: 4 additions & 5 deletions gfx/thebes/gfxGraphiteShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,17 +339,16 @@ gfxGraphiteShaper::SetGlyphsFromSegment(gfxShapedText *aShapedText,
for (uint32_t j = c.baseGlyph; j < c.baseGlyph + c.nGlyphs; ++j) {
gfxShapedText::DetailedGlyph* d = details.AppendElement();
d->mGlyphID = gids[j];
d->mYOffset = roundY ? NSToIntRound(-yLocs[j]) * dev2appUnits
: -yLocs[j] * dev2appUnits;
d->mOffset.y = roundY ? NSToIntRound(-yLocs[j]) * dev2appUnits
: -yLocs[j] * dev2appUnits;
if (j == c.baseGlyph) {
d->mXOffset = 0;
d->mAdvance = appAdvance;
clusterLoc = xLocs[j];
} else {
float dx = rtl ? (xLocs[j] - clusterLoc) :
(xLocs[j] - clusterLoc - adv);
d->mXOffset = roundX ? NSToIntRound(dx) * dev2appUnits
: dx * dev2appUnits;
d->mOffset.x = roundX ? NSToIntRound(dx) * dev2appUnits
: dx * dev2appUnits;
d->mAdvance = 0;
}
}
Expand Down
15 changes: 11 additions & 4 deletions gfx/thebes/gfxHarfBuzzShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,12 +1736,19 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
detailedGlyphs.AppendElement();
details->mGlyphID = ginfo[glyphStart].codepoint;

details->mXOffset = iOffset;
details->mAdvance = advance;

details->mYOffset = bPos -
(roundB ? appUnitsPerDevUnit * FixedToIntRound(b_offset)
: floor(hb2appUnits * b_offset + 0.5));
if (aVertical) {
details->mOffset.x = bPos -
(roundB ? appUnitsPerDevUnit * FixedToIntRound(b_offset)
: floor(hb2appUnits * b_offset + 0.5));
details->mOffset.y = iOffset;
} else {
details->mOffset.x = iOffset;
details->mOffset.y = bPos -
(roundB ? appUnitsPerDevUnit * FixedToIntRound(b_offset)
: floor(hb2appUnits * b_offset + 0.5));
}

if (b_advance != 0) {
bPos -=
Expand Down
1 change: 0 additions & 1 deletion gfx/thebes/gfxTextRun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2758,7 +2758,6 @@ gfxFontGroup::InitScriptRun(DrawTarget* aDrawTarget,
gfxTextRun::DetailedGlyph detailedGlyph;
detailedGlyph.mGlyphID = mainFont->GetSpaceGlyph();
detailedGlyph.mAdvance = advance;
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(true, true, 1);
aTextRun->SetGlyphs(aOffset + index,
Expand Down
2 changes: 0 additions & 2 deletions layout/generic/nsTextRunTransformations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ MergeCharactersInTextRun(gfxTextRun* aDest, gfxTextRun* aSrc,
gfxTextRun::DetailedGlyph details;
details.mGlyphID = g.GetSimpleGlyph();
details.mAdvance = g.GetSimpleAdvance();
details.mXOffset = 0;
details.mYOffset = 0;
glyphs.AppendElement(details);
}
} else {
Expand Down
1 change: 0 additions & 1 deletion layout/mathml/nsMathMLChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ nsOpenTypeTable::MakeTextRun(DrawTarget* aDrawTarget,
NSToCoordRound(aAppUnitsPerDevPixel *
aFontGroup->GetFirstValidFont()->
GetGlyphHAdvance(aDrawTarget, aGlyph.glyphID));
detailedGlyph.mXOffset = detailedGlyph.mYOffset = 0;
gfxShapedText::CompressedGlyph g;
g.SetComplex(true, true, 1);
textRun->SetGlyphs(0, g, &detailedGlyph);
Expand Down

0 comments on commit 8397a85

Please sign in to comment.