176 lines
2.7 KiB
C#
176 lines
2.7 KiB
C#
using System;
|
||
using System.Drawing;
|
||
|
||
namespace GoldPrinter
|
||
{
|
||
public class Printer : PrinterBase
|
||
{
|
||
private Sewing _sewing;
|
||
|
||
private Font _font;
|
||
|
||
private bool _isDrawAllPage;
|
||
|
||
private int _height;
|
||
|
||
private int _MoveX;
|
||
|
||
private int _MoveY;
|
||
|
||
public virtual Sewing Sewing
|
||
{
|
||
get
|
||
{
|
||
return this._sewing;
|
||
}
|
||
set
|
||
{
|
||
if (value != null)
|
||
{
|
||
this._sewing = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public virtual Font Font
|
||
{
|
||
get
|
||
{
|
||
return this._font;
|
||
}
|
||
set
|
||
{
|
||
if (value != null)
|
||
{
|
||
this._font = value;
|
||
}
|
||
}
|
||
}
|
||
|
||
public virtual bool IsDrawAllPage
|
||
{
|
||
get
|
||
{
|
||
return this._isDrawAllPage;
|
||
}
|
||
set
|
||
{
|
||
this._isDrawAllPage = value;
|
||
}
|
||
}
|
||
|
||
public virtual int Height
|
||
{
|
||
get
|
||
{
|
||
return this._height;
|
||
}
|
||
set
|
||
{
|
||
this._height = value;
|
||
if (this._height < 0)
|
||
{
|
||
this._height = 0;
|
||
}
|
||
}
|
||
}
|
||
|
||
public int MoveX
|
||
{
|
||
get
|
||
{
|
||
return this._MoveX;
|
||
}
|
||
set
|
||
{
|
||
this._MoveX = value;
|
||
}
|
||
}
|
||
|
||
public int MoveY
|
||
{
|
||
get
|
||
{
|
||
return this._MoveY;
|
||
}
|
||
set
|
||
{
|
||
this._MoveY = value;
|
||
}
|
||
}
|
||
|
||
public Printer()
|
||
{
|
||
this._sewing = new Sewing();
|
||
this._font = new Font("宋体", 10f);
|
||
this._isDrawAllPage = false;
|
||
this._height = 0;
|
||
this._MoveX = 0;
|
||
this._MoveY = 0;
|
||
}
|
||
|
||
public int TextWidth(string text)
|
||
{
|
||
return (int)base.Graphics.MeasureString(text, this.Font, base.PrinterMargins.Width).Width;
|
||
}
|
||
|
||
public int TextHeight(string text)
|
||
{
|
||
return (int)base.Graphics.MeasureString(text, this.Font, base.PrinterMargins.Width).Height;
|
||
}
|
||
|
||
public int TextHeight()
|
||
{
|
||
return this.Font.Height;
|
||
}
|
||
|
||
public virtual void DrawPrinterMargins()
|
||
{
|
||
this.CheckGraphics();
|
||
Rectangle rect = new Rectangle(base.PrinterMargins.Left, base.PrinterMargins.Top, base.PrinterMargins.Width, base.PrinterMargins.Height);
|
||
base.Graphics.DrawRectangle(base.Pen, rect);
|
||
}
|
||
|
||
public virtual void DrawSewing()
|
||
{
|
||
this.CheckGraphics();
|
||
this.Sewing.LineLen = this.GetSewingLineLength();
|
||
this.Sewing.Draw(base.Graphics);
|
||
}
|
||
|
||
private int GetSewingLineLength()
|
||
{
|
||
int result = 0;
|
||
if (this.Sewing.SewingDirection == SewingDirectionFlag.Left)
|
||
{
|
||
result = base.PageHeight;
|
||
}
|
||
else if (this.Sewing.SewingDirection == SewingDirectionFlag.Top)
|
||
{
|
||
result = base.PageWidth;
|
||
}
|
||
return result;
|
||
}
|
||
|
||
public override void Draw()
|
||
{
|
||
this.CheckGraphics();
|
||
}
|
||
|
||
protected virtual void CheckGraphics()
|
||
{
|
||
if (base.Graphics == null)
|
||
{
|
||
throw new Exception("绘图表面不能为空,请设置Graphics属性!");
|
||
}
|
||
}
|
||
|
||
public override void Dispose()
|
||
{
|
||
base.Dispose();
|
||
this._sewing.Dispose();
|
||
this._font.Dispose();
|
||
}
|
||
}
|
||
}
|