11using EPPlus . Fonts . OpenType ;
22using EPPlus . Fonts . OpenType . Integration ;
33using EPPlus . Fonts . OpenType . TextShaping ;
4- using EPPlus . Fonts . OpenType . Integration ;
5- using EPPlus . Fonts . OpenType . TextShaping ;
6- using EPPlus . Fonts . OpenType . TrueTypeMeasurer . DataHolders ;
74using EPPlus . Fonts . OpenType . Utils ;
85using EPPlus . Graphics ;
96using EPPlusImageRenderer ;
@@ -25,7 +22,7 @@ namespace EPPlus.Export.ImageRenderer.RenderItems.Shared
2522{
2623 internal abstract class ParagraphItem : RenderItem
2724 {
28- ITextMeasurerWrap _measurer ;
25+ TextLayoutEngine _layout ;
2926
3027 double _leftMargin ;
3128 double _rightMargin ;
@@ -37,7 +34,7 @@ internal abstract class ParagraphItem : RenderItem
3734 List < string > _paragraphLines = new List < string > ( ) ;
3835 protected List < string > _textRunDisplayText = new List < string > ( ) ;
3936
40- TextFragmentCollection _textFragments ;
37+ TextFragmentCollectionSimple _textFragments ;
4138 List < EPPlus . Fonts . OpenType . Integration . TextFragment > _newTextFragments ;
4239 internal protected MeasurementFont _paragraphFont ;
4340 internal TextBodyItem ParentTextBody { get ; set ; }
@@ -56,8 +53,8 @@ public ParagraphItem(TextBodyItem textBody, DrawingBase renderer, BoundingBox pa
5653 var defaultFont = new MeasurementFont { FontFamily = "Aptos Narrow" , Size = 11 , Style = MeasurementFontStyles . Regular } ;
5754 _paragraphFont = defaultFont ;
5855
59- _measurer = new FontMeasurerTrueType ( defaultFont ) ;
60- ParagraphLineSpacing = GetParagraphLineSpacingInPoints ( 100 , _measurer ) ;
56+ _layout = OpenTypeFonts . GetTextLayoutEngineForFont ( defaultFont ) ;
57+ ParagraphLineSpacing = GetParagraphLineSpacingInPoints ( 100 , ( TextShaper ) OpenTypeFonts . GetShaperForFont ( defaultFont ) , defaultFont . Size ) ;
6158 }
6259
6360 public ParagraphItem ( TextBodyItem textBody , DrawingBase renderer , BoundingBox parent , ExcelDrawingParagraph p , string textIfEmpty = null ) : base ( renderer , parent )
@@ -140,45 +137,42 @@ public ParagraphItem(TextBodyItem textBody, DrawingBase renderer, BoundingBox pa
140137 Bounds . Width = parent . Width - _rightMargin - _leftMargin ;
141138 }
142139
140+ //---Initialize / calculate lines and runs---
141+ //measurer must be set before AddLinesAndRichText
142+ _paragraphFont = p . DefaultRunProperties . GetMeasureFont ( ) ;
143+
143144 //---Get measurer---
144- _measurer = p . _prd . Package . Settings . TextSettings . GenericTextMeasurerTrueType ;
145+ _layout = OpenTypeFonts . GetTextLayoutEngineForFont ( _paragraphFont ) ;
145146
146147 //---Calculate linespacing---
147148 int numLines = _paragraphLines . Count ;
148149 _lsType = p . LineSpacing . LineSpacingType ;
149- ParagraphLineSpacing = GetParagraphLineSpacingInPoints ( p . LineSpacing . Value , _measurer ) ;
150-
151- //---Initialize / calculate lines and runs---
152- //measurer must be set before AddLinesAndRichText
153- _paragraphFont = p . DefaultRunProperties . GetMeasureFont ( ) ;
154- _measurer . SetFont ( _paragraphFont ) ;
150+ ParagraphLineSpacing = GetParagraphLineSpacingInPoints ( p . LineSpacing . Value ,
151+ ( TextShaper ) OpenTypeFonts . GetShaperForFont ( _paragraphFont ) ,
152+ _paragraphFont . Size ) ;
155153
156154 AddLinesAndTextRuns ( p , textIfEmpty ) ;
157155 }
158156
159- private double GetParagraphLineSpacingInPoints ( double spacingValue , ITextMeasurerWrap fmExact )
157+ private double GetParagraphLineSpacingInPoints ( double spacingValue , TextShaper fmExact , float fontSize )
160158 {
161159 if ( _lsType == eDrawingTextLineSpacing . Exactly )
162160 {
163161 if ( IsFirstParagraph )
164162 {
165163 _lineSpacingAscendantOnly = spacingValue ;
166- _lineSpacingAscendantOnly = spacingValue ;
167164 }
168165 return spacingValue ;
169- return spacingValue ;
170166 }
171167 else
172168 {
173169 var multiplier = ( spacingValue / 100 ) ;
174170 _lsMultiplier = multiplier ;
175171 if ( IsFirstParagraph )
176172 {
177- _lineSpacingAscendantOnly = multiplier * fmExact . GetBaseLine ( ) ;
178- _lineSpacingAscendantOnly = multiplier * fmExact . GetBaseLine ( ) ;
173+ _lineSpacingAscendantOnly = multiplier * fmExact . GetAscentInPoints ( fontSize ) ;
179174 }
180- return multiplier * fmExact . GetSingleLineSpacing ( ) ;
181- return multiplier * fmExact . GetSingleLineSpacing ( ) ;
175+ return multiplier * fmExact . GetLineHeightInPoints ( fontSize ) ;
182176 }
183177 }
184178
@@ -201,8 +195,9 @@ public void AddText(string text, double prevWidth)
201195 }
202196 public void AddText ( string text , ExcelTextFont font , bool isOld )
203197 {
204- var measurer = new FontMeasurerTrueType ( ) ;
205- var displayText = measurer . MeasureAndWrapText ( text , font . GetMeasureFont ( ) , ParentTextBody . MaxWidth ) ;
198+ var mf = font . GetMeasureFont ( ) ;
199+ var measurer = OpenTypeFonts . GetTextLayoutEngineForFont ( mf ) ;
200+ var displayText = measurer . WrapText ( text , mf . Size , ParentTextBody . MaxWidth ) ;
206201 var container = CreateTextRun ( text , font , Bounds , string . Join ( "\r \n " , displayText . ToArray ( ) ) ) ;
207202 //container.BaseLineSpacing = _lineSpacingAscendantOnly;
208203 //container.LineSpacingPerNewLine = _lsMultiplier.Value * _measurer.GetSingleLineSpacing().PointToPixel(true);
@@ -214,7 +209,8 @@ public void AddText(string text, ExcelTextFont font, bool isOld)
214209
215210 public void AddText ( string text , ExcelTextFont font , double prevWidth )
216211 {
217- var measurer = new FontMeasurerTrueType ( ) ;
212+ var mf = font . GetMeasureFont ( ) ;
213+ var measurer = OpenTypeFonts . GetTextLayoutEngineForFont ( mf ) ;
218214 //var displayText = measurer.MeasureAndWrapTextLines(text, font.GetMeasureFont(), ParentTextBody.MaxWidth);
219215
220216 var container = CreateTextRun ( text , font , Bounds , text ) ;
@@ -278,9 +274,14 @@ internal void AddLinesAndTextRuns(string textIfEmpty)
278274 GenerateTextFragments ( textIfEmpty ) ;
279275 var lines = new List < TextLineSimple > ( ) ;
280276
281- var measurer = new FontMeasurerTrueType ( ) ;
277+ var measurer = OpenTypeFonts . GetTextLayoutEngineForFont ( _paragraphFont ) ;
282278 var maxWidth = ParentTextBody . MaxWidth + 0.001 ; //TODO: fix for equal width issue;
283- lines = measurer . MeasureAndWrapTextLines_New ( textIfEmpty , _paragraphFont , maxWidth ) ;
279+
280+ List < TextFragment > textFragments = new List < TextFragment > ( ) ;
281+ var fragment = new TextFragment ( ) { Font = _paragraphFont , Text = textIfEmpty } ;
282+ textFragments . Add ( fragment ) ;
283+
284+ lines = measurer . WrapRichTextLines ( textFragments , maxWidth ) ;
284285 bool lineSpacingIsExact = _lsMultiplier . HasValue == false ;
285286 double runLineSpacing = 0 ;
286287 double greatestWidth = 0 ;
@@ -378,9 +379,11 @@ private void AddLinesAndTextRuns(ExcelDrawingParagraph p, string textIfEmpty)
378379
379380 if ( p . TextRuns . Count == 0 && string . IsNullOrEmpty ( textIfEmpty ) == false )
380381 {
381- var measurer = new FontMeasurerTrueType ( ) ;
382+ var font = p . DefaultRunProperties . GetMeasureFont ( ) ;
383+ var measurer = OpenTypeFonts . GetTextLayoutEngineForFont ( font ) ;
382384 var maxWidth = ParentTextBody . MaxWidth + 0.001 ; //TODO: fix for equal width issue;
383- lines = measurer . MeasureAndWrapTextLines_New ( textIfEmpty , p . DefaultRunProperties . GetMeasureFont ( ) , maxWidth ) ;
385+
386+ lines = measurer . WrapRichTextLines ( textIfEmpty , font , maxWidth ) ;
384387
385388 //Bounds.Width = maxWidth;
386389 if ( HorizontalAlignment != eTextAlignment . Center )
@@ -484,13 +487,15 @@ private void AddLinesAndTextRuns(ExcelDrawingParagraph p, string textIfEmpty)
484487
485488 List < TextLineSimple > WrapToSimpleTextLines ( ExcelDrawingParagraph p )
486489 {
487- var ttMeasurer = ( FontMeasurerTrueType ) _measurer ;
488-
489490 if ( _newTextFragments . Count > 0 )
490491 {
491- ttMeasurer . SetFont ( _newTextFragments [ 0 ] . Font ) ;
492+ if ( _layout == null )
493+ {
494+ _layout = OpenTypeFonts . GetTextLayoutEngineForFont ( ( _newTextFragments [ 0 ] . Font ) ) ;
495+ }
496+
492497 var maxWidthPoints = Math . Round ( ParentTextBody . MaxWidth , 0 , MidpointRounding . AwayFromZero ) ;
493- return ttMeasurer . WrapMultipleTextFragmentsToTextLines_New ( _newTextFragments , maxWidthPoints ) ;
498+ return _layout . WrapRichTextLines ( _newTextFragments , maxWidthPoints ) ;
494499 }
495500 return new List < TextLineSimple > ( ) ;
496501 }
0 commit comments