158 lines
2.6 KiB
C#
158 lines
2.6 KiB
C#
using System;
|
|
using System.Drawing;
|
|
|
|
namespace GoldPrinter
|
|
{
|
|
public class DrawText : DrawBase
|
|
{
|
|
private string _text;
|
|
|
|
private Font _font;
|
|
|
|
private StringFormat _stringFormat;
|
|
|
|
private int _startChar;
|
|
|
|
private int _linesFilled;
|
|
|
|
private int _charsFitted;
|
|
|
|
//private bool _hasMorePages;
|
|
|
|
private static int intCurrentCharIndex;
|
|
|
|
public string Text
|
|
{
|
|
get
|
|
{
|
|
return this._text;
|
|
}
|
|
set
|
|
{
|
|
this._text = value;
|
|
}
|
|
}
|
|
|
|
public Font Font
|
|
{
|
|
get
|
|
{
|
|
return this._font;
|
|
}
|
|
set
|
|
{
|
|
if (value != null)
|
|
{
|
|
this._font = value;
|
|
}
|
|
}
|
|
}
|
|
|
|
public StringFormat StringFormat
|
|
{
|
|
get
|
|
{
|
|
return this._stringFormat;
|
|
}
|
|
set
|
|
{
|
|
this._stringFormat = value;
|
|
}
|
|
}
|
|
|
|
public int StartChar
|
|
{
|
|
get
|
|
{
|
|
return this._startChar;
|
|
}
|
|
set
|
|
{
|
|
this._startChar = value;
|
|
if (this._startChar < 0)
|
|
{
|
|
this._startChar = 0;
|
|
}
|
|
else if (this._startChar >= this.Text.Length)
|
|
{
|
|
this._startChar = this.Text.Length;
|
|
}
|
|
}
|
|
}
|
|
|
|
public int CharsFitted
|
|
{
|
|
get
|
|
{
|
|
return this._charsFitted;
|
|
}
|
|
}
|
|
|
|
public int LinesFilled
|
|
{
|
|
get
|
|
{
|
|
return this._linesFilled;
|
|
}
|
|
}
|
|
|
|
public DrawText()
|
|
{
|
|
this._text = "";
|
|
this._font = new Font("宋体", 10f);
|
|
this._startChar = 0;
|
|
this._linesFilled = 0;
|
|
this._charsFitted = 0;
|
|
this._stringFormat = new StringFormat(StringFormatFlags.LineLimit);
|
|
}
|
|
|
|
public DrawText(string text) : this()
|
|
{
|
|
this._text = text;
|
|
}
|
|
|
|
public override void Dispose()
|
|
{
|
|
base.Dispose();
|
|
this._font.Dispose();
|
|
this._stringFormat.Dispose();
|
|
}
|
|
|
|
private void DrawOnePage()
|
|
{
|
|
if (base.Graphics != null)
|
|
{
|
|
int charsFitted;
|
|
int linesFilled;
|
|
base.Graphics.MeasureString(this._text.Substring(this._startChar), this._font, new SizeF((float)base.Rectangle.Width, (float)base.Rectangle.Height), this._stringFormat, out charsFitted, out linesFilled);
|
|
base.Graphics.DrawString(this._text.Substring(this._startChar), this._font, base.Brush, base.Rectangle, this._stringFormat);
|
|
this._linesFilled = linesFilled;
|
|
this._charsFitted = charsFitted;
|
|
}
|
|
}
|
|
|
|
public override void Draw()
|
|
{
|
|
this.DrawOnePage();
|
|
}
|
|
|
|
private bool Draw(DrawText p_drawText, string p_text)
|
|
{
|
|
DrawText drawText = new DrawText(p_text);
|
|
this.StartChar = DrawText.intCurrentCharIndex;
|
|
DrawText.intCurrentCharIndex += this.CharsFitted;
|
|
bool result;
|
|
if (DrawText.intCurrentCharIndex < p_text.Length)
|
|
{
|
|
result = true;
|
|
}
|
|
else
|
|
{
|
|
DrawText.intCurrentCharIndex = 0;
|
|
result = false;
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|