1212using SixLabors . Fonts . Tables . General ;
1313using SixLabors . Fonts . Tables . General . Kern ;
1414using SixLabors . Fonts . Tables . General . Post ;
15+ using SixLabors . Fonts . Tables . General . Svg ;
1516using SixLabors . Fonts . Tables . TrueType ;
1617using SixLabors . Fonts . Tables . TrueType . Hinting ;
1718using 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