Bug 1115916 - Improve synthetic vertical metrics for fonts that don't have actual vhea/vmtx tables. r=smontagu
--- a/gfx/thebes/gfxFont.cpp
+++ b/gfx/thebes/gfxFont.cpp
@@ -3398,24 +3398,29 @@ gfxFont::CreateVerticalMetrics()
gfxFontEntry::AutoTable os2Table(mFontEntry, kOS_2TableTag);
if (os2Table && mFUnitsConvFactor > 0.0) {
const OS2Table *os2 =
reinterpret_cast<const OS2Table*>(hb_blob_get_data(os2Table, &len));
// These fields should always be present in any valid OS/2 table
if (len >= offsetof(OS2Table, sTypoLineGap) + sizeof(int16_t)) {
SET_SIGNED(strikeoutSize, os2->yStrikeoutSize);
- SET_SIGNED(aveCharWidth, int16_t(os2->sTypoAscender) -
- int16_t(os2->sTypoDescender));
- metrics->maxAscent =
- std::max(metrics->maxAscent, int16_t(os2->xAvgCharWidth) *
- gfxFloat(mFUnitsConvFactor));
- metrics->maxDescent =
- std::max(metrics->maxDescent, int16_t(os2->xAvgCharWidth) *
- gfxFloat(mFUnitsConvFactor));
+ // Use ascent+descent from the horizontal metrics as the default
+ // advance (aveCharWidth) in vertical mode
+ gfxFloat ascentDescent = gfxFloat(mFUnitsConvFactor) *
+ (int16_t(os2->sTypoAscender) - int16_t(os2->sTypoDescender));
+ metrics->aveCharWidth =
+ std::max(metrics->emHeight, ascentDescent);
+ // Use xAvgCharWidth from horizontal metrics as minimum font extent
+ // for vertical layout, applying half of it to ascent and half to
+ // descent (to work with a default centered baseline).
+ gfxFloat halfCharWidth =
+ int16_t(os2->xAvgCharWidth) * gfxFloat(mFUnitsConvFactor) / 2;
+ metrics->maxAscent = std::max(metrics->maxAscent, halfCharWidth);
+ metrics->maxDescent = std::max(metrics->maxDescent, halfCharWidth);
}
}
// If we didn't set aveCharWidth from OS/2, try to read 'hhea' metrics
// and use the line height from its ascent/descent.
if (!metrics->aveCharWidth) {
gfxFontEntry::AutoTable hheaTable(mFontEntry, kHheaTableTag);
if (hheaTable && mFUnitsConvFactor > 0.0) {