Skip to content

Commit 6df7590

Browse files
Merge pull request #524 from SixLabors/colrv1-fixes
Separate glyph/paint transforms; SVG caching & tests
2 parents 4ca2629 + 9d5e995 commit 6df7590

21 files changed

+629
-180
lines changed

.github/workflows/build-and-test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010
branches:
1111
- main
1212
- release/*
13-
types: [ labeled, opened, synchronize, reopened ]
13+
types: [ opened, synchronize, reopened ]
1414
jobs:
1515
# Prime a single LFS cache and expose the exact key for the matrix
1616
WarmLFS:

src/SixLabors.Fonts/StreamFontMetrics.Cff.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ private GlyphMetrics CreateCffGlyphMetrics(
163163
this,
164164
glyphId,
165165
codePoint,
166-
new SvgGlyphSource(svg),
166+
this.GetOrCreateSvgGlyphSource(svg),
167167
bounds,
168168
advanceWidth,
169169
advancedHeight,

src/SixLabors.Fonts/StreamFontMetrics.TrueType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ private GlyphMetrics CreateTrueTypeGlyphMetrics(
281281
this,
282282
glyphId,
283283
codePoint,
284-
new SvgGlyphSource(svg),
284+
this.GetOrCreateSvgGlyphSource(svg),
285285
bounds,
286286
advanceWidth,
287287
advancedHeight,

src/SixLabors.Fonts/StreamFontMetrics.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SixLabors.Fonts.Tables.General;
1313
using SixLabors.Fonts.Tables.General.Kern;
1414
using SixLabors.Fonts.Tables.General.Post;
15+
using SixLabors.Fonts.Tables.General.Svg;
1516
using SixLabors.Fonts.Tables.TrueType;
1617
using SixLabors.Fonts.Tables.TrueType.Hinting;
1718
using SixLabors.Fonts.Unicode;
@@ -34,6 +35,7 @@ internal partial class StreamFontMetrics : FontMetrics
3435
private readonly ConcurrentDictionary<(int CodePoint, ushort Id, TextAttributes Attributes, ColorFontSupport ColorSupport, bool IsVerticalLayout), GlyphMetrics> glyphCache;
3536
private readonly ConcurrentDictionary<(int CodePoint, int NextCodePoint), (bool Success, ushort GlyphId, bool SkipNextCodePoint)> glyphIdCache;
3637
private readonly ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)> codePointCache;
38+
private SvgGlyphSource? svgGlyphSource;
3739
private readonly FontDescription description;
3840
private readonly HorizontalMetrics horizontalMetrics;
3941
private readonly VerticalMetrics verticalMetrics;
@@ -104,7 +106,8 @@ private StreamFontMetrics(
104106
TrueTypeFontTables tables,
105107
GlyphVariationProcessor processor,
106108
ConcurrentDictionary<(int CodePoint, int NextCodePoint), (bool Success, ushort GlyphId, bool SkipNextCodePoint)> sharedGlyphIdCache,
107-
ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)> sharedCodePointCache)
109+
ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)> sharedCodePointCache,
110+
SvgGlyphSource? svgGlyphSource)
108111
{
109112
this.trueTypeFontTables = tables;
110113
this.outlineType = OutlineType.TrueType;
@@ -113,6 +116,7 @@ private StreamFontMetrics(
113116
this.glyphIdCache = sharedGlyphIdCache;
114117
this.codePointCache = sharedCodePointCache;
115118
this.glyphCache = new();
119+
this.svgGlyphSource = svgGlyphSource;
116120

117121
(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
118122
this.horizontalMetrics = metrics.HorizontalMetrics;
@@ -130,7 +134,8 @@ private StreamFontMetrics(
130134
CompactFontTables tables,
131135
GlyphVariationProcessor processor,
132136
ConcurrentDictionary<(int CodePoint, int NextCodePoint), (bool Success, ushort GlyphId, bool SkipNextCodePoint)> sharedGlyphIdCache,
133-
ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)> sharedCodePointCache)
137+
ConcurrentDictionary<ushort, (bool Success, CodePoint CodePoint)> sharedCodePointCache,
138+
SvgGlyphSource? svgGlyphSource)
134139
{
135140
this.compactFontTables = tables;
136141
this.outlineType = OutlineType.CFF;
@@ -139,6 +144,7 @@ private StreamFontMetrics(
139144
this.glyphIdCache = sharedGlyphIdCache;
140145
this.codePointCache = sharedCodePointCache;
141146
this.glyphCache = new();
147+
this.svgGlyphSource = svgGlyphSource;
142148

143149
(HorizontalMetrics HorizontalMetrics, VerticalMetrics VerticalMetrics) metrics = this.Initialize(tables);
144150
this.horizontalMetrics = metrics.HorizontalMetrics;
@@ -519,7 +525,7 @@ internal StreamFontMetrics CreateVariationInstance(FontVariation[] variations)
519525
tables.Cvar,
520526
userCoordinates);
521527

522-
return new StreamFontMetrics(tables, processor, this.glyphIdCache, this.codePointCache);
528+
return new StreamFontMetrics(tables, processor, this.glyphIdCache, this.codePointCache, this.svgGlyphSource);
523529
}
524530
else
525531
{
@@ -535,7 +541,7 @@ internal StreamFontMetrics CreateVariationInstance(FontVariation[] variations)
535541
tables.MVar,
536542
userCoordinates: userCoordinates);
537543

538-
return new StreamFontMetrics(tables, processor, this.glyphIdCache, this.codePointCache);
544+
return new StreamFontMetrics(tables, processor, this.glyphIdCache, this.codePointCache, this.svgGlyphSource);
539545
}
540546
}
541547

@@ -825,4 +831,7 @@ private GlyphMetrics CreateGlyphMetrics(
825831
OutlineType.CFF => this.CreateCffGlyphMetrics(in codePoint, glyphId, glyphType, textAttributes, textDecorations, colorSupport, isVerticalLayout, paletteIndex),
826832
_ => throw new NotSupportedException(),
827833
};
834+
835+
private SvgGlyphSource GetOrCreateSvgGlyphSource(SvgTable svgTable)
836+
=> this.svgGlyphSource ??= new SvgGlyphSource(svgTable);
828837
}

0 commit comments

Comments
 (0)