Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public GlyphsSerializer(GlyphRun glyphRun)
_advances = glyphRun.AdvanceWidths;
_offsets = glyphRun.GlyphOffsets;

_advanceWidthRoundingError = 0.0;

// "100,50,,0;".Length is a capacity estimate for an individual glyph
_glyphStringBuider = new StringBuilder(10);

Expand All @@ -82,6 +84,8 @@ public GlyphsSerializer(GlyphRun glyphRun)
/// </summary>
public void ComputeContentStrings(out string characters, out string indices, out string caretStops)
{
_advanceWidthRoundingError = 0.0;

if (_clusters != null)
{
// the algorithm works by finding (n:m) clusters and appending m glyphs for each cluster
Expand Down Expand Up @@ -184,7 +188,9 @@ private void AddGlyph(int glyph, int sourceCharacter)
_glyphStringBuider.Append(GlyphSubEntrySeparator);

// advance width
int normalizedAdvance = (int)Math.Round(_advances[glyph] * _milToEm);
double unroundedAdvance = _advances[glyph] * _milToEm;
int normalizedAdvance = (int)Math.Round(unroundedAdvance + _advanceWidthRoundingError);
_advanceWidthRoundingError += (unroundedAdvance - (double)normalizedAdvance);
double fontAdvance = _sideways ? _glyphTypeface.AdvanceHeights[fontIndex] : _glyphTypeface.AdvanceWidths[fontIndex];
if (normalizedAdvance != (int)Math.Round(fontAdvance * EmScaleFactor))
{
Expand Down Expand Up @@ -320,6 +326,8 @@ private string CreateCaretStopsString()

private int _glyphClusterInitialOffset;

private double _advanceWidthRoundingError;

private IList<ushort> _clusters;

private IList<ushort> _indices;
Expand Down