@@ -79,24 +79,48 @@ public void DisableShapingFeature(int index, Tag feature)
7979 /// </summary>
8080 /// <param name="offset">The zero-based index within the input codepoint collection.</param>
8181 /// <param name="pointSize">The font size in PT units of the font containing this glyph.</param>
82+ /// <param name="isSubstituted">Whether the glyph is the result of a substitution.</param>
83+ /// <param name="isVerticalSubstitution">Whether the glyph is the result of a vertical substitution.</param>
8284 /// <param name="isDecomposed">Whether the glyph is the result of a decomposition substitution.</param>
8385 /// <param name="metrics">
8486 /// When this method returns, contains the glyph metrics associated with the specified offset,
8587 /// if the value is found; otherwise, the default value for the type of the metrics parameter.
8688 /// This parameter is passed uninitialized.
8789 /// </param>
8890 /// <returns>The metrics.</returns>
89- public bool TryGetGlyphMetricsAtOffset ( int offset , out float pointSize , out bool isDecomposed , [ NotNullWhen ( true ) ] out IReadOnlyList < GlyphMetrics > ? metrics )
91+ public bool TryGetGlyphMetricsAtOffset (
92+ int offset ,
93+ out float pointSize ,
94+ out bool isSubstituted ,
95+ out bool isVerticalSubstitution ,
96+ out bool isDecomposed ,
97+ [ NotNullWhen ( true ) ] out IReadOnlyList < GlyphMetrics > ? metrics )
9098 {
9199 List < GlyphMetrics > match = new ( ) ;
92100 pointSize = 0 ;
101+ isSubstituted = false ;
102+ isVerticalSubstitution = false ;
93103 isDecomposed = false ;
104+
105+ Tag vert = FeatureTags . VerticalAlternates ;
106+ Tag vrt2 = FeatureTags . VerticalAlternatesAndRotation ;
107+ Tag vrtr = FeatureTags . VerticalAlternatesForRotation ;
108+
94109 for ( int i = 0 ; i < this . glyphs . Count ; i ++ )
95110 {
96111 if ( this . glyphs [ i ] . Offset == offset )
97112 {
98113 GlyphPositioningData glyph = this . glyphs [ i ] ;
114+ isSubstituted = glyph . Data . IsSubstituted ;
99115 isDecomposed = glyph . Data . IsDecomposed ;
116+
117+ foreach ( Tag feature in glyph . Data . AppliedFeatures )
118+ {
119+ isVerticalSubstitution |= feature == vert ;
120+ isVerticalSubstitution |= feature == vrt2 ;
121+ isVerticalSubstitution |= feature == vrtr ;
122+ }
123+
100124 pointSize = glyph . PointSize ;
101125 match . AddRange ( glyph . Metrics ) ;
102126 }
@@ -147,7 +171,7 @@ public bool TryUpdate(Font font, GlyphSubstitutionCollection collection)
147171
148172 // Perform a semi-deep clone (FontMetrics is not cloned) so we can continue to
149173 // cache the original in the font metrics and only update our collection.
150- var metrics = new List < GlyphMetrics > ( data . Count ) ;
174+ List < GlyphMetrics > metrics = new ( data . Count ) ;
151175 TextAttributes textAttributes = shape . TextRun . TextAttributes ;
152176 TextDecorations textDecorations = shape . TextRun . TextDecorations ;
153177 foreach ( GlyphMetrics gm in fontMetrics . GetGlyphMetrics ( codePoint , id , textAttributes , textDecorations , layoutMode , colorFontSupport ) )
@@ -216,6 +240,10 @@ public bool TryAdd(Font font, GlyphSubstitutionCollection collection)
216240 LayoutMode layoutMode = this . TextOptions . LayoutMode ;
217241 ColorFontSupport colorFontSupport = this . TextOptions . ColorFontSupport ;
218242
243+ Tag vert = FeatureTags . VerticalAlternates ;
244+ Tag vrt2 = FeatureTags . VerticalAlternatesAndRotation ;
245+ Tag vrtr = FeatureTags . VerticalAlternatesForRotation ;
246+
219247 for ( int i = 0 ; i < collection . Count ; i ++ )
220248 {
221249 GlyphShapingData data = collection . GetGlyphShapingData ( i , out int offset ) ;
@@ -227,7 +255,14 @@ public bool TryAdd(Font font, GlyphSubstitutionCollection collection)
227255 // cache the original in the font metrics and only update our collection.
228256 TextAttributes textAttributes = data . TextRun . TextAttributes ;
229257 TextDecorations textDecorations = data . TextRun . TextDecorations ;
230- bool isVerticalLayout = AdvancedTypographicUtils . IsVerticalGlyph ( codePoint , layoutMode ) ;
258+
259+ bool isVertical = AdvancedTypographicUtils . IsVerticalGlyph ( codePoint , layoutMode ) ;
260+ foreach ( Tag feature in data . AppliedFeatures )
261+ {
262+ isVertical |= feature == vert ;
263+ isVertical |= feature == vrt2 ;
264+ isVertical |= feature == vrtr ;
265+ }
231266
232267 foreach ( GlyphMetrics gm in fontMetrics . GetGlyphMetrics ( codePoint , id , textAttributes , textDecorations , layoutMode , colorFontSupport ) )
233268 {
@@ -242,7 +277,7 @@ public bool TryAdd(Font font, GlyphSubstitutionCollection collection)
242277 if ( metrics . Count > 0 )
243278 {
244279 GlyphMetrics [ ] gm = metrics . ToArray ( ) ;
245- if ( isVerticalLayout )
280+ if ( isVertical )
246281 {
247282 this . glyphs . Add ( new ( offset , new ( data , true ) { Bounds = new ( 0 , 0 , 0 , gm [ 0 ] . AdvanceHeight ) } , font . Size , gm ) ) ;
248283 }
@@ -302,11 +337,25 @@ public void UpdatePosition(FontMetrics fontMetrics, int index)
302337 public void Advance ( FontMetrics fontMetrics , int index , ushort glyphId , short dx , short dy )
303338 {
304339 LayoutMode layoutMode = this . TextOptions . LayoutMode ;
305- foreach ( GlyphMetrics m in this . glyphs [ index ] . Metrics )
340+ Tag vert = FeatureTags . VerticalAlternates ;
341+ Tag vrt2 = FeatureTags . VerticalAlternatesAndRotation ;
342+ Tag vrtr = FeatureTags . VerticalAlternatesForRotation ;
343+
344+ GlyphPositioningData glyph = this . glyphs [ index ] ;
345+ foreach ( GlyphMetrics m in glyph . Metrics )
306346 {
307347 if ( m . GlyphId == glyphId && fontMetrics == m . FontMetrics )
308348 {
309- m . ApplyAdvance ( dx , AdvancedTypographicUtils . IsVerticalGlyph ( m . CodePoint , layoutMode ) ? dy : ( short ) 0 ) ;
349+ bool isVertical = AdvancedTypographicUtils . IsVerticalGlyph ( m . CodePoint , layoutMode ) ;
350+
351+ foreach ( Tag feature in glyph . Data . AppliedFeatures )
352+ {
353+ isVertical |= feature == vert ;
354+ isVertical |= feature == vrt2 ;
355+ isVertical |= feature == vrtr ;
356+ }
357+
358+ m . ApplyAdvance ( dx , isVertical ? dy : ( short ) 0 ) ;
310359 }
311360 }
312361 }
0 commit comments