Skip to content

Commit

Permalink
[drape] Use explicit font height in pixels for line metrics calculation
Browse files Browse the repository at this point in the history
The simplest approach works in the best way with different fonts, including Hebrew Noto

Signed-off-by: Alexander Borsuk <me@alex.bio>
  • Loading branch information
biodranik committed Aug 14, 2024
1 parent 026778a commit b000ec0
Showing 1 changed file with 1 addition and 18 deletions.
19 changes: 1 addition & 18 deletions drape/glyph_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,28 +255,11 @@ class Font
auto const yOffset = (currPos.y_offset + static_cast<int32_t>(metrics.horiBearingY) - metrics.height) >> 6;
int32_t const xAdvance = currPos.x_advance >> 6;
// yAdvance is always zero for horizontal text layouts.
// This height gives 16 instead of expected 22-23.
// int32_t const height = metrics.height >> 6;

outMetrics.AddGlyphMetrics(static_cast<int16_t>(fontIndex), glyphId, xOffset, yOffset, xAdvance,
GetLineHeigthPixels(metrics.vertAdvance));
outMetrics.AddGlyphMetrics(static_cast<int16_t>(fontIndex), glyphId, xOffset, yOffset, xAdvance, fontPixelSize);
}
}

private:
int32_t GetLineHeigthPixels(FT_Pos vertAdvance) const
{
// Freetype says that vertAdvance is unreliable if it contains a synthesized value in case of FT_HAS_VERTICAL
// returning false. Testing on supported fonts shows that non-zero vertAdvance can be trusted as a line height.
if (vertAdvance > 0 && vertAdvance < m_fontFace->bbox.yMax) [[likely]]
return vertAdvance >> 6;

int32_t const bboxYMax = FT_MulFix(m_fontFace->bbox.yMax, m_fontFace->size->metrics.y_scale) >> 6;
int32_t const bboxYMmin = FT_MulFix(m_fontFace->bbox.yMin, m_fontFace->size->metrics.y_scale) >> 6;

return bboxYMax - bboxYMmin;
}

private:
ReaderPtr<Reader> m_fontReader;
FT_StreamRec_ m_stream;
Expand Down

0 comments on commit b000ec0

Please sign in to comment.