@@ -41,7 +41,7 @@ public static AnsiCte Create() {
4141 private DynamicScreen _screen ;
4242 public IAnsiDecoderClient DecoderClient { get => ( IAnsiDecoderClient ) _screen ; }
4343
44- private float _lineHeight ;
44+ private SizeF _charSize ;
4545 private int _linesPerPage ;
4646
4747 private float lineNumberWidth ;
@@ -118,24 +118,24 @@ public override async Task<int> RenderAsync(System.Drawing.Printing.PrinterResol
118118 g . PageUnit = GraphicsUnit . Display ; // Display is 1/100th"
119119 }
120120
121- _lineHeight = _cachedFont . GetHeight ( dpiY ) ;
121+ _charSize = MeasureString ( g , _cachedFont , "W" ) ;
122122
123- if ( PageSize . Height < _lineHeight ) {
123+ if ( PageSize . Height < ( int ) Math . Floor ( _charSize . Height ) ) {
124124 throw new InvalidOperationException ( "The line height is greater than page height." ) ;
125125 }
126126
127127 // Round down # of lines per page to ensure lines don't clip on bottom
128- _linesPerPage = ( int ) Math . Floor ( PageSize . Height / _lineHeight ) ;
128+ _linesPerPage = ( int ) Math . Floor ( PageSize . Height / ( int ) Math . Floor ( _charSize . Height ) ) ;
129129
130130 // 3 digits + 1 wide - Will support 999 lines before line numbers start to not fit
131131 // TODO: Make line number width dynamic
132132 // Note, MeasureString is actually dependent on lineNumberWidth!
133- lineNumberWidth = ContentSettings . LineNumbers ? MeasureString ( g , _cachedFont , new string ( '0' , 4 ) ) . Width : 0 ;
133+ lineNumberWidth = ContentSettings . LineNumbers ? _charSize . Width * 4 : 0 ;
134134
135135 // This is the shortest line length (in chars) that we think we'll see.
136136 // This is used as a performance optimization (probably premature) and
137137 // could be 0 with no functional change.
138- _minLineLen = ( int ) ( ( PageSize . Width - lineNumberWidth ) / MeasureString ( g , _cachedFont , "W" ) . Width ) ;
138+ _minLineLen = ( int ) ( ( PageSize . Width - lineNumberWidth ) / ( int ) Math . Floor ( _charSize . Width ) ) ;
139139
140140 // Note, MeasureLines may increment numPages due to form feeds and line wrapping
141141 _screen = new DynamicScreen ( _minLineLen ) ;
@@ -177,9 +177,9 @@ private SizeF MeasureString(Graphics g, string text, System.Drawing.Font font, o
177177 g . TextRenderingHint = ContentTypeEngineBase . TextRenderingHint ;
178178
179179 // determine width
180- var fontHeight = _lineHeight ;
180+ var fontHeight = ( int ) Math . Floor ( _charSize . Height ) ;
181181 // Use page settings including lineNumberWidth
182- var proposedSize = new SizeF ( PageSize . Width , _lineHeight + ( _lineHeight / 2 ) ) ;
182+ var proposedSize = new SizeF ( PageSize . Width , ( int ) Math . Floor ( _charSize . Height ) + ( ( int ) Math . Floor ( _charSize . Height ) / 2 ) ) ;
183183 var size = g . MeasureString ( text , font , proposedSize , ContentTypeEngineBase . StringFormat , out charsFitted , out linesFilled ) ;
184184
185185 // TODO: HACK to work around MeasureString not working right on Linux
@@ -206,7 +206,7 @@ public override void PaintPage(Graphics g, int pageNum) {
206206 var firstLineOnPage = _linesPerPage * ( pageNum - 1 ) ;
207207 int i ;
208208 for ( i = firstLineOnPage ; i < firstLineOnPage + _linesPerPage && i < _screen . Lines . Count ; i ++ ) {
209- var yPos = ( i - ( _linesPerPage * ( pageNum - 1 ) ) ) * _lineHeight ;
209+ var yPos = ( i - ( _linesPerPage * ( pageNum - 1 ) ) ) * ( int ) Math . Floor ( _charSize . Height ) ;
210210 var x = ContentSettings . LineNumberSeparator ? ( int ) ( lineNumberWidth - 6 - MeasureString ( g , _cachedFont , $ "{ _screen . Lines [ i ] . LineNumber } ") . Width ) : 0 ;
211211 // Line #s
212212 if ( _screen . Lines [ i ] . LineNumber > 0 ) {
@@ -220,7 +220,7 @@ public override void PaintPage(Graphics g, int pageNum) {
220220 // Line # separator (draw even if there's no line number, but stop at end of doc)
221221 // TODO: Support setting color of line #s and separator
222222 if ( ContentSettings . LineNumbers && ContentSettings . LineNumberSeparator && lineNumberWidth != 0 ) {
223- g . DrawLine ( Pens . Gray , lineNumberWidth - 2 , yPos , lineNumberWidth - 2 , yPos + _lineHeight ) ;
223+ g . DrawLine ( Pens . Gray , lineNumberWidth - 2 , yPos , lineNumberWidth - 2 , yPos + ( int ) Math . Floor ( _charSize . Height ) ) ;
224224 }
225225
226226 // Text
@@ -244,14 +244,25 @@ public override void PaintPage(Graphics g, int pageNum) {
244244
245245 var text = _screen . Lines [ i ] . Text [ run . Start ..( run . Start + run . Length ) ] ;
246246
247- var proposedSize = new SizeF ( PageSize . Width , _lineHeight ) ;
248- var size = g . MeasureString ( text , font , proposedSize , ContentTypeEngineBase . StringFormat , out int charsFitted , out int linesFilled ) ;
249- g . DrawString ( text , font , new SolidBrush ( fg ) , xPos , yPos , ContentTypeEngineBase . StringFormat ) ;
247+ for ( var c = 0 ; c < text . Length ; c ++ ) {
248+ g . DrawString ( $ "{ text [ c ] } ", font , new SolidBrush ( fg ) , xPos + ( c * ( int ) Math . Floor ( _charSize . Width ) ) , yPos , ContentTypeEngineBase . StringFormat ) ;
249+ }
250+
251+ if ( ContentSettings . Diagnostics && run . HasTab ) {
252+ var pen = new Pen ( Color . Red , 1 ) ;
253+ g . DrawRectangle ( pen , xPos , yPos , text . Length * ( int ) Math . Floor ( _charSize . Width ) , ( int ) Math . Floor ( _charSize . Height ) ) ;
254+ g . DrawString ( $ "→", font , new SolidBrush ( Color . DarkGray ) , xPos , yPos , ContentTypeEngineBase . StringFormat ) ;
255+ }
256+ xPos += ( int ) Math . Floor ( _charSize . Width ) * text . Length ;
257+
258+ //var proposedSize = new SizeF(PageSize.Width, _lineHeight);
259+ //var size = g.MeasureString(text, font, proposedSize, ContentTypeEngineBase.StringFormat, out int charsFitted, out int linesFilled);
260+ //g.DrawString(text, font, new SolidBrush(fg), xPos, yPos, ContentTypeEngineBase.StringFormat);
250261
251- xPos += size . Width ;
262+ // xPos += size.Width;
252263 }
253264 if ( ContentSettings . Diagnostics ) {
254- g . DrawRectangle ( Pens . Red , lineNumberWidth , yPos , PageSize . Width - lineNumberWidth , _lineHeight ) ;
265+ g . DrawRectangle ( Pens . Red , lineNumberWidth , yPos , PageSize . Width - lineNumberWidth , ( int ) Math . Floor ( _charSize . Height ) ) ;
255266 }
256267 }
257268
0 commit comments