mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
ShapedText: Apply extra kerning only before clusters
This avoids inserting tracking between glyphs in a single cluster e.g. a base glyph and diacritic marks.
This commit is contained in:
parent
503788fd0c
commit
8693507ead
1 changed files with 9 additions and 1 deletions
|
|
@ -504,6 +504,8 @@ static std::vector<ShapedGlyph> lowLevelShape (const String& string,
|
|||
std::vector<size_t> characterLookup;
|
||||
std::vector<ShapedGlyph> glyphs;
|
||||
|
||||
std::optional<uint32_t> lastCluster;
|
||||
|
||||
for (size_t i = 0; i < infos.size(); ++i)
|
||||
{
|
||||
const auto j = (embeddingLevel % 2) == 0 ? i : infos.size() - 1 - i;
|
||||
|
|
@ -528,12 +530,18 @@ static std::vector<ShapedGlyph> lowLevelShape (const String& string,
|
|||
&& font.getTypefacePtr()->getGlyphBounds (font.getMetricsKind(), (int) glyphId).isEmpty()
|
||||
&& xAdvance > 0;
|
||||
|
||||
// Tracking is only applied at the beginning of a new cluster to avoid inserting it before
|
||||
// diacritic marks.
|
||||
const auto appliedTracking = std::exchange (lastCluster, infos[j].cluster) != infos[j].cluster
|
||||
? trackingAmount
|
||||
: 0;
|
||||
|
||||
glyphs.push_back ({
|
||||
glyphId,
|
||||
(int64) infos[j].cluster + range.getStart(),
|
||||
(infos[j].mask & HB_GLYPH_FLAG_UNSAFE_TO_BREAK) != 0,
|
||||
whitespace,
|
||||
Point<float> { HbScale::hbToJuce (xAdvance) + trackingAmount, -HbScale::hbToJuce (positions[j].y_advance) },
|
||||
Point<float> { HbScale::hbToJuce (xAdvance) + appliedTracking, -HbScale::hbToJuce (positions[j].y_advance) },
|
||||
Point<float> { HbScale::hbToJuce (positions[j].x_offset), -HbScale::hbToJuce (positions[j].y_offset) },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue