Skip to content

Commit

Permalink
Bug 1395926 - Fix up handling of glyph offsets for text shaped in ver…
Browse files Browse the repository at this point in the history
…tical mode. r=jrmuizel
  • Loading branch information
jfkthame committed Oct 27, 2017
1 parent b7659a2 commit 824ae50
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 28 deletions.
43 changes: 16 additions & 27 deletions gfx/thebes/gfxHarfBuzzShaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,17 +421,14 @@ gfxHarfBuzzShaper::HBGetGlyphVOrigin(hb_font_t *font, void *font_data,
const gfxHarfBuzzShaper::FontCallbackData *fcd =
static_cast<const gfxHarfBuzzShaper::FontCallbackData*>(font_data);
fcd->mShaper->GetGlyphVOrigin(glyph, x, y);
// Negate the value we computed from font data (see comment re coordinate
// system orientation in HBGetGlyphVAdvance).
*y = -*y;
return true;
}

void
gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
hb_position_t *aX, hb_position_t *aY) const
{
*aX = -0.5 * GetGlyphHAdvance(aGlyph);
*aX = 0.5 * GetGlyphHAdvance(aGlyph);

if (mVORGTable) {
// We checked in Initialize() that the VORG table is safely readable,
Expand All @@ -452,11 +449,11 @@ gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
}

if (lo < limit && uint16_t(lo->glyphIndex) == aGlyph) {
*aY = -FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
int16_t(lo->vertOriginY));
*aY = FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
int16_t(lo->vertOriginY));
} else {
*aY = -FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
int16_t(vorg->defaultVertOriginY));
*aY = FloatToFixed(GetFont()->FUnitsToDevUnitsFactor() *
int16_t(vorg->defaultVertOriginY));
}
return;
}
Expand Down Expand Up @@ -484,8 +481,8 @@ gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
(&metrics->metrics[mNumLongVMetrics]);
lsb = int16_t(sidebearings[aGlyph - mNumLongVMetrics]);
}
*aY = -FloatToFixed(mFont->FUnitsToDevUnitsFactor() *
(lsb + int16_t(glyf->yMax)));
*aY = FloatToFixed(mFont->FUnitsToDevUnitsFactor() *
(lsb + int16_t(glyf->yMax)));
return;
} else {
// XXX TODO: not a truetype font; need to get glyph extents
Expand All @@ -508,13 +505,13 @@ gfxHarfBuzzShaper::GetGlyphVOrigin(hb_codepoint_t aGlyph,
// to ascender:descender from the hhea table
int16_t a = int16_t(hhea->ascender);
int16_t d = int16_t(hhea->descender);
*aY = -FloatToFixed(GetFont()->GetAdjustedSize() * a / (a - d));
*aY = FloatToFixed(GetFont()->GetAdjustedSize() * a / (a - d));
return;
}
}

NS_NOTREACHED("we shouldn't be here!");
*aY = -FloatToFixed(GetFont()->GetAdjustedSize() / 2);
*aY = FloatToFixed(GetFont()->GetAdjustedSize() / 2);
}

static hb_bool_t
Expand Down Expand Up @@ -1693,11 +1690,12 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
hb_position_t i_offset, i_advance; // inline-direction offset/advance
hb_position_t b_offset, b_advance; // block-direction offset/advance
if (aVertical) {
// our inline coordinate direction is the opposite of harfbuzz's
// our coordinate directions are the opposite of harfbuzz's
// when doing top-to-bottom shaping
i_offset = -posInfo[glyphStart].y_offset;
i_advance = -posInfo[glyphStart].y_advance;
b_offset = posInfo[glyphStart].x_offset;
b_advance = posInfo[glyphStart].x_advance;
b_offset = -posInfo[glyphStart].x_offset;
b_advance = -posInfo[glyphStart].x_advance;
} else {
i_offset = posInfo[glyphStart].x_offset;
i_advance = posInfo[glyphStart].x_advance;
Expand Down Expand Up @@ -1733,14 +1731,6 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
// there must be at least one in the clump, and we already measured
// its advance, hence the placement of the loop-exit test and the
// measurement of the next glyph.
// For vertical orientation, we add a "base offset" to compensate
// for the positioning within the cluster being based on horizontal
// glyph origin/offset.
hb_position_t baseIOffset, baseBOffset;
if (aVertical) {
baseIOffset = 2 * (i_offset - i_advance);
baseBOffset = GetGlyphHAdvance(ginfo[glyphStart].codepoint);
}
while (1) {
gfxTextRun::DetailedGlyph* details =
detailedGlyphs.AppendElement();
Expand All @@ -1763,11 +1753,10 @@ gfxHarfBuzzShaper::SetGlyphsFromRun(gfxShapedText *aShapedText,
}

if (aVertical) {
// our inline coordinate direction is the opposite of HB's
i_offset = baseIOffset + posInfo[glyphStart].y_offset;
i_offset = -posInfo[glyphStart].y_offset;
i_advance = -posInfo[glyphStart].y_advance;
b_offset = baseBOffset - posInfo[glyphStart].x_offset;
b_advance = posInfo[glyphStart].x_advance;
b_offset = -posInfo[glyphStart].x_offset;
b_advance = -posInfo[glyphStart].x_advance;
} else {
i_offset = posInfo[glyphStart].x_offset;
i_advance = posInfo[glyphStart].x_advance;
Expand Down
2 changes: 1 addition & 1 deletion layout/reftests/writing-mode/reftest.list
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fuzzy-if(gtkWidget,1,25) fuzzy-if(cocoaWidget,1,2) == 1302389-scrolled-rect-2b.h
fuzzy-if(Android,54,852) == 1302389-scrolled-rect-2d.html 1302389-scrolled-rect-2-ref.html

== 1361631-mongolian-upright-1.html 1361631-mongolian-upright-1-ref.html
fails == 1395926-vertical-upright-gpos-1.html 1395926-vertical-upright-gpos-1-ref.html
== 1395926-vertical-upright-gpos-1.html 1395926-vertical-upright-gpos-1-ref.html

# Suite of tests from Gérard Talbot in bug 1079151
# Frequent Windows 7 load failed: timed out waiting for test to complete (waiting for onload scripts to complete), bug 1167155 and friends
Expand Down

0 comments on commit 824ae50

Please sign in to comment.