@@ -168,7 +168,7 @@ private void CreateDisplayAtoms(List<MathAtom> preprocessedAtoms) {
168
168
case Variable _:
169
169
case UnaryOperator _:
170
170
throw new InvalidCodePathException
171
- ( $ "Type { atom . GetType ( ) } should have been removed by preprocessing") ;
171
+ ( $ "Type { atom . TypeName } should have been removed by preprocessing") ;
172
172
case Space space :
173
173
AddDisplayLine ( false ) ;
174
174
_currentPosition . X += space . ActualLength ( _mathTable , _font ) ;
@@ -232,7 +232,7 @@ private void CreateDisplayAtoms(List<MathAtom> preprocessedAtoms) {
232
232
AddInterElementSpace ( prevAtom , inner ) ;
233
233
IDisplay < TFont , TGlyph > innerDisplay ;
234
234
if ( inner . LeftBoundary != Boundary . Empty || inner . RightBoundary != Boundary . Empty ) {
235
- innerDisplay = _MakeInner ( inner , atom . IndexRange ) ;
235
+ innerDisplay = MakeInner ( inner , atom . IndexRange ) ;
236
236
} else {
237
237
innerDisplay = CreateLine ( inner . InnerList , _font , _context , _style , _cramped ) ;
238
238
}
@@ -522,6 +522,20 @@ private void AddInterElementSpace(MathAtom? prev, MathAtom current) =>
522
522
return null ;
523
523
}
524
524
private RadicalDisplay < TFont , TGlyph > MakeRadical ( MathList radicand , Range range ) {
525
+ IGlyphDisplay < TFont , TGlyph > _GetRadicalGlyph ( float radicalHeight ) {
526
+ // TODO: something related to GlyphFinder.FindGlyph
527
+ var radicalGlyph = _context . GlyphFinder . FindGlyphForCharacterAtIndex ( _font , 0 , "\u221A " ) ;
528
+ var glyph = FindGlyph ( radicalGlyph , radicalHeight ,
529
+ out float glyphAscent , out float glyphDescent , out float glyphWidth ) ;
530
+
531
+ return
532
+ glyphAscent + glyphDescent < radicalHeight
533
+ // the glyphs are not big enough, so we construct one using extenders
534
+ && ConstructGlyph ( radicalGlyph , radicalHeight ) is IGlyphDisplay < TFont , TGlyph > constructed
535
+ ? constructed
536
+ : new GlyphDisplay < TFont , TGlyph >
537
+ ( glyph , Range . NotFound , _styleFont , glyphAscent , glyphDescent , glyphWidth ) ;
538
+ }
525
539
var innerDisplay = CreateLine ( radicand , _font , _context , _style , true ) ;
526
540
var radicalVerticalGap =
527
541
_style == LineStyle . Display
@@ -562,46 +576,43 @@ private RadicalDisplay<TFont, TGlyph> MakeRadical(MathList radicand, Range range
562
576
} ;
563
577
}
564
578
565
- private float _NumeratorShiftUp ( bool hasRule ) =>
566
- ( hasRule , _style ) switch
567
- {
568
- ( true , LineStyle . Display ) => _mathTable . FractionNumeratorDisplayStyleShiftUp ( _styleFont ) ,
569
- ( true , _ ) => _mathTable . FractionNumeratorShiftUp ( _styleFont ) ,
570
- ( false , LineStyle . Display ) => _mathTable . StackTopDisplayStyleShiftUp ( _styleFont ) ,
571
- ( false , _ ) => _mathTable . StackTopShiftUp ( _styleFont )
572
- } ;
573
- private float _NumeratorGapMin =>
574
- _style == LineStyle . Display
575
- ? _mathTable . FractionNumDisplayStyleGapMin ( _styleFont )
576
- : _mathTable . FractionNumeratorGapMin ( _styleFont ) ;
577
-
578
- private float _DenominatorShiftDown ( bool hasRule ) =>
579
- ( hasRule , _style ) switch
580
- {
581
- ( true , LineStyle . Display ) => _mathTable . FractionDenominatorDisplayStyleShiftDown ( _styleFont ) ,
582
- ( true , _ ) => _mathTable . FractionDenominatorShiftDown ( _styleFont ) ,
583
- ( false , LineStyle . Display ) => _mathTable . StackBottomDisplayStyleShiftDown ( _styleFont ) ,
584
- ( false , _ ) => _mathTable . StackBottomShiftDown ( _styleFont )
585
- } ;
586
-
587
- private float _DenominatorGapMin =>
588
- _style == LineStyle . Display
589
- ? _mathTable . FractionDenomDisplayStyleGapMin ( _styleFont )
590
- : _mathTable . FractionDenominatorGapMin ( _styleFont ) ;
591
-
592
- private float _StackGapMin =>
593
- _style == LineStyle . Display
594
- ? _mathTable . StackDisplayStyleGapMin ( _styleFont )
595
- : _mathTable . StackGapMin ( _styleFont ) ;
596
-
597
- private float _FractionDelimiterHeight =>
598
- _style == LineStyle . Display
599
- ? _mathTable . FractionDelimiterDisplayStyleSize ( _styleFont )
600
- : _mathTable . FractionDelimiterSize ( _styleFont ) ;
601
-
602
579
private IDisplay < TFont , TGlyph > MakeFraction ( Fraction fraction ) {
580
+ float _NumeratorShiftUp ( bool hasRule ) =>
581
+ ( hasRule , _style ) switch
582
+ {
583
+ ( true , LineStyle . Display ) => _mathTable . FractionNumeratorDisplayStyleShiftUp ( _styleFont ) ,
584
+ ( true , _ ) => _mathTable . FractionNumeratorShiftUp ( _styleFont ) ,
585
+ ( false , LineStyle . Display ) => _mathTable . StackTopDisplayStyleShiftUp ( _styleFont ) ,
586
+ ( false , _ ) => _mathTable . StackTopShiftUp ( _styleFont )
587
+ } ;
588
+ float _NumeratorGapMin ( ) =>
589
+ _style == LineStyle . Display
590
+ ? _mathTable . FractionNumDisplayStyleGapMin ( _styleFont )
591
+ : _mathTable . FractionNumeratorGapMin ( _styleFont ) ;
592
+
593
+ float _DenominatorShiftDown ( bool hasRule ) =>
594
+ ( hasRule , _style ) switch
595
+ {
596
+ ( true , LineStyle . Display ) => _mathTable . FractionDenominatorDisplayStyleShiftDown ( _styleFont ) ,
597
+ ( true , _ ) => _mathTable . FractionDenominatorShiftDown ( _styleFont ) ,
598
+ ( false , LineStyle . Display ) => _mathTable . StackBottomDisplayStyleShiftDown ( _styleFont ) ,
599
+ ( false , _ ) => _mathTable . StackBottomShiftDown ( _styleFont )
600
+ } ;
601
+ float _DenominatorGapMin ( ) =>
602
+ _style == LineStyle . Display
603
+ ? _mathTable . FractionDenomDisplayStyleGapMin ( _styleFont )
604
+ : _mathTable . FractionDenominatorGapMin ( _styleFont ) ;
605
+ float _StackGapMin ( ) =>
606
+ _style == LineStyle . Display
607
+ ? _mathTable . StackDisplayStyleGapMin ( _styleFont )
608
+ : _mathTable . StackGapMin ( _styleFont ) ;
609
+ float _FractionDelimiterHeight ( ) =>
610
+ _style == LineStyle . Display
611
+ ? _mathTable . FractionDelimiterDisplayStyleSize ( _styleFont )
612
+ : _mathTable . FractionDelimiterSize ( _styleFont ) ;
613
+
603
614
var numeratorDisplay =
604
- CreateLine ( fraction . Numerator , _font , _context , _fractionStyle , false ) ;
615
+ CreateLine ( fraction . Numerator , _font , _context , _fractionStyle , false ) ;
605
616
var denominatorDisplay =
606
617
CreateLine ( fraction . Denominator , _font , _context , _fractionStyle , true ) ;
607
618
@@ -616,20 +627,20 @@ private IDisplay<TFont, TGlyph> MakeFraction(Fraction fraction) {
616
627
var distanceFromNumeratorToBar =
617
628
numeratorShiftUp - numeratorDisplay . Descent - ( barLocation + barThickness / 2 ) ;
618
629
// The distance should be at least displayGap
619
- if ( distanceFromNumeratorToBar < _NumeratorGapMin ) {
620
- numeratorShiftUp += ( _NumeratorGapMin - distanceFromNumeratorToBar ) ;
630
+ if ( distanceFromNumeratorToBar < _NumeratorGapMin ( ) ) {
631
+ numeratorShiftUp += ( _NumeratorGapMin ( ) - distanceFromNumeratorToBar ) ;
621
632
}
622
633
// now, do the same for the denominator
623
634
var distanceFromDenominatorToBar =
624
635
barLocation - barThickness / 2 - ( denominatorDisplay . Ascent - denominatorShiftDown ) ;
625
- if ( distanceFromDenominatorToBar < _DenominatorGapMin ) {
626
- denominatorShiftDown += _DenominatorGapMin - distanceFromDenominatorToBar ;
636
+ if ( distanceFromDenominatorToBar < _DenominatorGapMin ( ) ) {
637
+ denominatorShiftDown += _DenominatorGapMin ( ) - distanceFromDenominatorToBar ;
627
638
}
628
639
} else {
629
640
float clearance =
630
641
numeratorShiftUp - numeratorDisplay . Descent
631
642
- ( denominatorDisplay . Ascent - denominatorShiftDown ) ;
632
- float minClearance = _StackGapMin ;
643
+ float minClearance = _StackGapMin ( ) ;
633
644
if ( clearance < minClearance ) {
634
645
numeratorShiftUp += ( minClearance - clearance / 2 ) ;
635
646
denominatorShiftDown += ( minClearance - clearance ) / 2 ;
@@ -649,11 +660,11 @@ private IDisplay<TFont, TGlyph> MakeFraction(Fraction fraction) {
649
660
650
661
if ( fraction . LeftDelimiter is null && fraction . RightDelimiter is null )
651
662
return display ;
652
- var glyphHeight = _FractionDelimiterHeight ;
663
+ var glyphHeight = _FractionDelimiterHeight ( ) ;
653
664
var position = new PointF ( ) ;
654
665
var innerGlyphs = new List < IDisplay < TFont , TGlyph > > ( ) ;
655
666
if ( fraction . LeftDelimiter ? . Length > 0 ) {
656
- var leftGlyph = _FindGlyphForBoundary ( fraction . LeftDelimiter , glyphHeight ) ;
667
+ var leftGlyph = FindGlyphForBoundary ( fraction . LeftDelimiter , glyphHeight ) ;
657
668
leftGlyph . Position = position ;
658
669
innerGlyphs . Add ( leftGlyph ) ;
659
670
position . X += leftGlyph . Width ;
@@ -662,7 +673,7 @@ private IDisplay<TFont, TGlyph> MakeFraction(Fraction fraction) {
662
673
position . X += display . Width ;
663
674
innerGlyphs . Add ( display ) ;
664
675
if ( fraction . RightDelimiter ? . Length > 0 ) {
665
- var rightGlyph = _FindGlyphForBoundary ( fraction . RightDelimiter , glyphHeight ) ;
676
+ var rightGlyph = FindGlyphForBoundary ( fraction . RightDelimiter , glyphHeight ) ;
666
677
rightGlyph . Position = position ;
667
678
innerGlyphs . Add ( rightGlyph ) ;
668
679
position . X += rightGlyph . Width ;
@@ -672,7 +683,7 @@ private IDisplay<TFont, TGlyph> MakeFraction(Fraction fraction) {
672
683
} ;
673
684
}
674
685
675
- private InnerDisplay < TFont , TGlyph > _MakeInner ( Inner inner , Range range ) {
686
+ private InnerDisplay < TFont , TGlyph > MakeInner ( Inner inner , Range range ) {
676
687
if ( inner . LeftBoundary == Boundary . Empty && inner . RightBoundary == Boundary . Empty ) {
677
688
throw new InvalidCodePathException ( "Inner should have a boundary to call this function." ) ;
678
689
}
@@ -689,24 +700,24 @@ private InnerDisplay<TFont, TGlyph> _MakeInner(Inner inner, Range range) {
689
700
690
701
var leftGlyph =
691
702
inner . LeftBoundary is Boundary { Nucleus : var left } && left . Length > 0
692
- ? _FindGlyphForBoundary ( left , glyphHeight )
703
+ ? FindGlyphForBoundary ( left , glyphHeight )
693
704
: null ;
694
705
695
706
var rightGlyph =
696
707
inner . RightBoundary is Boundary { Nucleus : var right } && right . Length > 0
697
- ? _FindGlyphForBoundary ( right , glyphHeight )
708
+ ? FindGlyphForBoundary ( right , glyphHeight )
698
709
: null ;
699
710
return new InnerDisplay < TFont , TGlyph > ( innerListDisplay , leftGlyph , rightGlyph , range ) ;
700
711
}
701
712
702
- private IGlyphDisplay < TFont , TGlyph > _FindGlyphForBoundary (
713
+ private IGlyphDisplay < TFont , TGlyph > FindGlyphForBoundary (
703
714
string delimiter , float glyphHeight ) {
704
715
var leftGlyph = _context . GlyphFinder . FindGlyphForCharacterAtIndex ( _font , 0 , delimiter ) ;
705
- var glyph = _FindGlyph ( leftGlyph , glyphHeight ,
716
+ var glyph = FindGlyph ( leftGlyph , glyphHeight ,
706
717
out float glyphAscent , out float glyphDescent , out float glyphWidth ) ;
707
718
var glyphDisplay =
708
719
glyphAscent + glyphDescent < glyphHeight
709
- && _ConstructGlyph ( leftGlyph , glyphHeight ) is IGlyphDisplay < TFont , TGlyph > constructed
720
+ && ConstructGlyph ( leftGlyph , glyphHeight ) is IGlyphDisplay < TFont , TGlyph > constructed
710
721
? constructed
711
722
: new GlyphDisplay < TFont , TGlyph >
712
723
( glyph , Range . NotFound , _styleFont , glyphAscent , glyphDescent , glyphWidth ) ;
@@ -718,35 +729,21 @@ private IGlyphDisplay<TFont, TGlyph> _FindGlyphForBoundary(
718
729
return glyphDisplay ;
719
730
}
720
731
721
- private IGlyphDisplay < TFont , TGlyph > _GetRadicalGlyph ( float radicalHeight ) {
722
- // TODO: something related to GlyphFinder.FindGlyph
723
- var radicalGlyph = _context . GlyphFinder . FindGlyphForCharacterAtIndex ( _font , 0 , "\u221A " ) ;
724
- var glyph = _FindGlyph ( radicalGlyph , radicalHeight ,
725
- out float glyphAscent , out float glyphDescent , out float glyphWidth ) ;
726
-
727
- return
728
- glyphAscent + glyphDescent < radicalHeight
729
- // the glyphs are not big enough, so we construct one using extenders
730
- && _ConstructGlyph ( radicalGlyph , radicalHeight ) is IGlyphDisplay < TFont , TGlyph > constructed
731
- ? constructed
732
- : new GlyphDisplay < TFont , TGlyph >
733
- ( glyph , Range . NotFound , _styleFont , glyphAscent , glyphDescent , glyphWidth ) ;
734
- }
735
732
736
- private GlyphConstructionDisplay < TFont , TGlyph > ? _ConstructGlyph ( TGlyph glyph , float glyphHeight ) {
733
+ private GlyphConstructionDisplay < TFont , TGlyph > ? ConstructGlyph ( TGlyph glyph , float glyphHeight ) {
737
734
var parts = _mathTable . GetVerticalGlyphAssembly ( glyph , _styleFont ) ;
738
735
if ( parts is null ) return null ;
739
736
var glyphs = new List < TGlyph > ( ) ;
740
737
var offsets = new List < float > ( ) ;
741
- float height = _ConstructGlyphWithParts ( parts , glyphHeight , glyphs , offsets ) ;
738
+ float height = ConstructGlyphWithParts ( parts , glyphHeight , glyphs , offsets ) ;
742
739
using var singleGlyph = new Structures . RentedArray < TGlyph > ( glyphs [ 0 ] ) ;
743
740
// descent:0 because it's up to the rendering to adjust the display glyph up or down by setting ShiftDown
744
741
return new GlyphConstructionDisplay < TFont , TGlyph >
745
742
( glyphs , offsets , _styleFont , height , 0 , _context . GlyphBoundsProvider
746
743
. GetAdvancesForGlyphs ( _styleFont , singleGlyph . Result , 1 ) . Total ) ;
747
744
}
748
745
749
- private float _ConstructGlyphWithParts ( IEnumerable < GlyphPart < TGlyph > > parts ,
746
+ private float ConstructGlyphWithParts ( IEnumerable < GlyphPart < TGlyph > > parts ,
750
747
float glyphHeight , List < TGlyph > glyphs , List < float > offsets ) {
751
748
for ( int nExtenders = 0 ; ; nExtenders ++ ) {
752
749
glyphs . Clear ( ) ;
@@ -800,7 +797,7 @@ private float _ConstructGlyphWithParts(IEnumerable<GlyphPart<TGlyph>> parts,
800
797
}
801
798
}
802
799
803
- private TGlyph _FindGlyph ( TGlyph rawGlyph , float height ,
800
+ private TGlyph FindGlyph ( TGlyph rawGlyph , float height ,
804
801
out float glyphAscent , out float glyphDescent , out float glyphWidth ) {
805
802
// in iosMath.
806
803
glyphAscent = glyphDescent = glyphWidth = float . NaN ;
0 commit comments