1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

GlyphArrangement: Extend glyph bounds to encapsulate ligature characters

Previously, bounds for text with ligatures were miscalculated, leading to
incorrect positioning and getStringWidth values.
This commit is contained in:
Oliver James 2025-06-17 21:41:31 +01:00 committed by Oli
parent ae8ca6120f
commit fc80bb29ca

View file

@ -189,25 +189,37 @@ static void addGlyphsFromShapedText (GlyphArrangement& ga, const detail::ShapedT
{
st.accessTogetherWith ([&] (auto shapedGlyphs, auto positions, auto font, auto glyphRange, auto)
{
for (size_t i = 0; i < shapedGlyphs.size(); ++i)
for (auto it = shapedGlyphs.begin(); it != shapedGlyphs.end();)
{
const auto glyphIndex = (int64) i + glyphRange.getStart();
const auto& glyph = *it;
const auto isNotPlaceholder = [] (auto& shapedGlyph)
{
return ! shapedGlyph.isPlaceholderForLigature();
};
auto& glyph = shapedGlyphs[i];
auto& position = positions[i];
const auto next = std::find_if (std::next (it),
shapedGlyphs.end(),
isNotPlaceholder);
if (glyph.isPlaceholderForLigature())
continue;
const auto addWidth = [] (auto acc, auto& shapedGlyph)
{
return acc + shapedGlyph.advance.x;
};
PositionedGlyph pg { font,
const auto width = std::accumulate (it, next, 0.0f, addWidth);
const auto index = (size_t) std::distance (shapedGlyphs.begin(), it);
const auto position = positions[index];
const auto glyphIndex = (int64) index + glyphRange.getStart();
ga.addGlyph ({ font,
st.getText()[(int) st.getTextRange (glyphIndex).getStart()],
(int) glyph.glyphId,
position.getX() + x,
position.getY() + y,
glyph.advance.getX(),
glyph.isWhitespace() };
width,
glyph.isWhitespace() });
ga.addGlyph (std::move (pg));
it = next;
}
});
}