Skip to content

Commit 14cdbb4

Browse files
committed
Add font metrics for svg
1 parent 4023e31 commit 14cdbb4

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/importexport/finale/internal/importfinaletext.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,24 @@ void FinaleParser::importTextExpressions()
692692
const auto shapeExpr = m_doc->getOthers()->get<others::ShapeExpressionDef>(m_currentMusxPartId,
693693
expressionAssignment->shapeExprId);
694694
const auto shape = m_doc->getOthers()->get<others::ShapeDef>(m_currentMusxPartId, shapeExpr->shapeDef);
695-
const std::string shapeSvgData = musx::util::SvgConvert::toSvg(*shape);
695+
const std::string shapeSvgData
696+
= musx::util::SvgConvert::toSvg(*shape, [this](const musx::dom::FontInfo& font,
697+
std::u32string_view text) -> std::optional<musx::util::SvgConvert::GlyphMetrics> {
698+
if (text.empty()) {
699+
return std::nullopt;
700+
}
701+
702+
muse::draw::FontMetrics fm(FontTracker(std::make_shared<musx::dom::FontInfo>(font),
703+
score()->style().defaultSpatium()).toFontMetrics());
704+
const char32_t& codePoint = text.front();
705+
706+
// Scaled as EvpuFloat
707+
musx::util::SvgConvert::GlyphMetrics result;
708+
result.advance = fm.horizontalAdvance(codePoint) * engraving::DPI / EVPU_PER_INCH;
709+
result.ascent = fm.tightBoundingRect(codePoint).top() * engraving::DPI / EVPU_PER_INCH;
710+
result.descent = fm.tightBoundingRect(codePoint).bottom() * engraving::DPI / EVPU_PER_INCH;
711+
return result;
712+
});
696713
if (shapeSvgData.empty()) {
697714
continue;
698715
}

0 commit comments

Comments
 (0)