这是最后一篇了..完结了 后期慢慢改把
上一篇 C# 实现虚拟打印机 HP Color LaserJet 4500 (2) True Type Font字体显示 里增加了两个获取宽..这里要用. 修正了符合TRUE的显示和一些字符的定义... 重新下载把.
我们获取到 HP Color LaserJet 4500 打印出的RPN文件...然后使用代码来显示
ImagePRN _HPGL = new ImagePRN(listBox1.SelectedItem.ToString());
m_PrintImageList = _HPGL.PrintBitmap;
属性 PrintBitmap 是返回的打印图形的结果集.
具体使用可能会出现一些PCL或则HPGL的语法不识别或则不正确什么的..可以把PRN文件发送给我.先谢谢拉.忙没时间详细测试.
WORD里添加一些图片和文字 然后打印到PRN文件 显示的效果图
下面是全部PRN的类
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;
using System.Reflection;
using System.Runtime.InteropServices;
namespace Zgke.MyImage.ImageFile
{
/// <summary>
/// Image PRN
/// zgke@sina.com
/// qq:116149
/// </summary>
public class ImagePRN
{
#region 私有方法
/// <summary>
/// 打印机缓冲区
/// </summary>
private PrintBuffer m_PrintBuffer = new PrintBuffer();
/// <summary>
/// PCL命令执行器
/// </summary>
private PCL m_PCL;
/// <summary>
/// HPGL命令执行器
/// </summary>
private HPGL m_HPGL;
/// <summary>
/// 文件头
/// </summary>
private byte[] m_HeardText = new byte[] { 0x1B, 0x25, 0x2D, 0x31, 0x32, 0x33, 0x34, 0x35, 0x58 };
/// <summary>
/// 文件头的ASCII文字信息
/// </summary>
private IList<string> m_PrintSet = new List<string>();
/// <summary>
/// 执行到的位置
/// </summary>
private int m_ReadIndex = 0;
/// <summary>
/// 打印完成的图形
/// </summary>
private IList<Image> m_PrintBitmap = new List<Image>();
#endregion
/// <summary>
/// 图形
/// </summary>
public IList<Image> PrintBitmap { get { return m_PrintBitmap; } }
/// <summary>
/// 获取打印的Image
/// </summary>
/// <param name="p_File">HP Color LaserJet 4500 打印机保存出的命令</param>
public ImagePRN(string p_File)
{
m_PCL = new PCL(m_PrintBuffer, m_PrintBitmap);
m_HPGL = new HPGL(m_PrintBuffer, m_PrintBitmap);
if (!File.Exists(p_File)) throw new Exception("文件不存在!");
byte[] _HPGLBytes = File.ReadAllBytes(p_File);
if (Encoding.ASCII.GetString(m_HeardText) != Encoding.ASCII.GetString(_HPGLBytes, 0, 9)) throw new Exception("文件格式不正确!");
m_ReadIndex = 9;
LoadFile(_HPGLBytes);
StarCommand(_HPGLBytes);
}
/// <summary>
/// 获取文件头的ASCII信息 并且保存到m_PrintSet 里
/// </summary>
/// <param name="p_FileBytes">文件字符</param>
private void LoadFile(byte[] p_FileBytes)
{
int _StarIndex = m_ReadIndex;
while (m_ReadIndex + 1 < p_FileBytes.Length)
{
m_ReadIndex++;
switch (p_FileBytes[m_ReadIndex])
{
case 0x0A: //@
m_PrintSet.Add(Encoding.ASCII.GetString(p_FileBytes, _StarIndex, m_ReadIndex - _StarIndex));
_StarIndex = m_ReadIndex + 1;
break;
case 0x0D:
m_ReadIndex++;
return;
}
}
}
/// <summary>
/// 开始执行命令
/// </summary>
/// <param name="p_FileBytes"></param>
private void StarCommand(byte[] p_FileBytes)
{
while (m_ReadIndex < p_FileBytes.Length)
{
switch (p_FileBytes[m_ReadIndex])
{
case 0x0D:
m_PrintBuffer.PCL_HorizontalCursorPositioning = 0;
m_PrintBuffer.PCL_VerticalCursorPositioning = 0;
m_ReadIndex++;
continue;
case 0x0C:
m_PrintBitmap.Add(GetPrintOfPageSize());
m_ReadIndex++;
continue;
}
m_ReadIndex++;
if (p_FileBytes[m_ReadIndex] == 0x1B) continue;
switch ((char)p_FileBytes[m_ReadIndex])
{
case 'E':
break;
case '*':
m_PCL.StartCommandLine(p_FileBytes, ref m_ReadIndex);
break;
case '&':
m_PCL.StartCommandLine(p_FileBytes, ref m_ReadIndex);
break;
case '(':
m_PCL.StartCommandLine(p_FileBytes, ref m_ReadIndex);
break;
case ')':
m_PCL.StartCommandLine(p_FileBytes, ref m_ReadIndex);
break;
case '%':
if (p_FileBytes[m_ReadIndex + 1] == 0x2D) return;
m_HPGL.StartCommandLine(p_FileBytes, ref m_ReadIndex);
break;
default:
System.Windows.Forms.MessageBox.Show(m_ReadIndex.ToString(), ((char)p_FileBytes[m_ReadIndex]).ToString());
break;
}
}
}
/// <summary>
/// 获取最终打印大小
/// </summary>
/// <returns></returns>
private Image GetPrintOfPageSize()
{
decimal _Width = 0;
decimal _Height = 0;
decimal _WidthMM = 0;
decimal _HeightMM = 0;
decimal _Scale = 25.4M;
switch (m_PrintBuffer.PCL_PageSize)
{
case 26: //A4
_WidthMM = 210;
_HeightMM = 297;
break;
default:
throw new Exception("未实现的纸张大小!");
}
switch (m_PrintBuffer.PCL_PageOrientation)
{
case 1:
_Width = _HeightMM / _Scale * 150;
_Height = _WidthMM / _Scale * 150;
break;
default:
_Width = _WidthMM / _Scale * 150;
_Height = _HeightMM / _Scale * 150;
break;
}
Bitmap _Page = new Bitmap((int)_Width, (int)_Height);
Graphics _PageGraphics = Graphics.FromImage(_Page);
_PageGraphics.Clear(Color.White);
int _StarX = (_Page.Width - m_PrintBuffer.m_PrintBitmap.Width) / 2;
int _StarY = (_Page.Height - m_PrintBuffer.m_PrintBitmap.Height) / 2;
if (_StarX < 0) _StarX = 0;
if (_StarY < 0) _StarY = 0;
_PageGraphics.DrawImage(m_PrintBuffer.m_PrintBitmap, _StarX, _StarY, m_PrintBuffer.m_PrintBitmap.Width, m_PrintBuffer.m_PrintBitmap.Height);
_PageGraphics.Dispose();
m_PrintBuffer.m_Graphics.Clear(Color.White);
return _Page;
}
#region HPGL
private class HPGL
{
/// <summary>
/// 构造类
/// </summary>
/// <param name="p_Buffer"></param>
public HPGL(PrintBuffer p_Buffer, IList<Image> p_ImageList)
{
m_Buffer = p_Buffer;
m_ImageList = p_ImageList;
MethodInfo[] _MethodList = this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
for (int i = 0; i != _MethodList.Length; i++)
{
object[] _Attributes = _MethodList[i].GetCustomAttributes(false);
if (_Attributes.Length == 1 && _Attributes[0] is PCLInfo)
{
PCLInfo _CommandInfo = (PCLInfo)_Attributes[0];
if (_CommandInfo.TitleCommand1.Length != 0) m_CommandMethodInfo.Add(_CommandInfo.TitleCommand1, _MethodList[i]);
if (_CommandInfo.TitleCommand2.Length != 0) m_CommandMethodInfo.Add(_CommandInfo.TitleCommand2, _MethodList[i]);
}
}
}
#region 私有成员
/// <summary>
/// 命令列表
/// </summary>
private Dictionary<string, MethodInfo> m_CommandMethodInfo = new Dictionary<string, MethodInfo>();
/// <summary>
/// 打印缓冲区
/// </summary>
private PrintBuffer m_Buffer;
/// <summary>
///执行到的位置
/// </summary>
private int m_ReadIndex;
/// <summary>
/// 打印的图形
/// </summary>
private IList<Image> m_ImageList;
#endregion
#region 执行命令
/// <summary>
/// 开始执行命令
/// </summary>
/// <param name="p_FileBytes">文件流</param>
/// <param name="p_ReadIndex">开始位置</param>
public void StartCommandLine(byte[] p_FileBytes, ref int p_ReadIndex)
{
p_ReadIndex++;
if (Encoding.ASCII.GetString(p_FileBytes, p_ReadIndex, 2) == "0A")
{
p_ReadIndex += 2;
return;
}
string _Command = "";
while (p_ReadIndex < p_FileBytes.Length)
{
if (p_FileBytes[p_ReadIndex] == 0x1B) return;
if ((char)p_FileBytes[p_ReadIndex] == ';')
{
p_ReadIndex++;
continue;
}
_Command = Encoding.ASCII.GetString(p_FileBytes, p_ReadIndex, 2);
p_ReadIndex += 2;
int _Count = GetCommandEndIndex(p_FileBytes, p_ReadIndex);
string _Value = "";
if (_Count != 0) _Value = Encoding.ASCII.GetString(p_FileBytes, p_ReadIndex, _Count);
p_ReadIndex += _Value.Length;
CommandStart(_Command, p_FileBytes, _Value, ref p_ReadIndex);
}
}
/// <summary>
/// 开始执行命令
/// </summary>
/// <param name="p_Command">命令结构</param>
/// <param name="p_Value">获取的字符类型</param>
/// <param name="p_ReadIndex">读去位</param>
private void CommandStart(string p_CommandText, byte[] p_FileBytes, string p_Value, ref int p_ReadIndex)
{
if (m_CommandMethodInfo.ContainsKey(p_CommandText))
{
try
{
m_ReadIndex = p_ReadIndex;
object _ReturnCount = m_CommandMethodInfo[p_CommandText].Invoke(this, new object[] { p_FileBytes, p_Value });
if (_ReturnCount != null) p_ReadIndex += (int)_ReturnCount;
}
catch (Exception ex)
{
throw new Exception("HPGL{" + p_ReadIndex.ToString() + "}" + "命令错误![" + p_CommandText + "]" + ex.InnerException);
}
}
else
{
throw new Exception("HPGL{" + p_ReadIndex.ToString() + "}" + "未知命令![" + p_CommandText + "]");
}
}
#endregion
/// <summary>
/// 进入HPGL/2模式
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "1B")]
private void HPGL2(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_Mode = 1;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "IN")]
private void IN(byte[] p_FileByte, string p_Value)
{
}
/// <summary>
/// 设置透明模式
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "TR")]
private int TransparencyMode(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_TransparencyMode = int.Parse(p_Value);
return p_Value.Length;
}
/// <summary>
/// 笔宽度类型
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "WU")]
private void PenWidthUnitSelection(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_PenWidthUnitSelection = 0;
if (p_Value.Length != 0) m_Buffer.HPGL_PenWidthUnitSelection = int.Parse(p_Value);
}
/// <summary>
/// 笔的宽度
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PW")]
private void PenWidth(byte[] p_FileByte, string p_Value)
{
if (p_Value[0] == '.') p_Value = "0" + p_Value;
m_Buffer.HPGL_PenWidth = decimal.Parse(p_Value);
}
/// <summary>
/// 线的类型
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "LT")]
private void LineType(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_LineType = p_Value;
}
/// <summary>
/// 线的类型
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "LA")]
private void LineAttributes(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_LineAttributes = p_Value;
}
/// <summary>
/// 笔号
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "NP")]
private void NumberOfPen(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_NumberOfPen = p_Value;
}
/// <summary>
/// 笔号
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PC")]
private void PenColorAssignment(byte[] p_FileBytes, string p_Value)
{
string[] _ValueList = p_Value.Split(',');
int _Key = int.Parse(_ValueList[0]);
Color _Color = Color.FromArgb(int.Parse(_ValueList[1]), int.Parse(_ValueList[2]), int.Parse(_ValueList[3]));
if (m_Buffer.HPGL_PenColorAssignment.ContainsKey(_Key))
{
m_Buffer.HPGL_PenColorAssignment[_Key] = _Color;
}
else
{
m_Buffer.HPGL_PenColorAssignment.Add(_Key, _Color);
}
}
/// <summary>
/// 相素的表示方式
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PP")]
private void PixelPlacement(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_PixelPlacement = p_Value;
}
/// <summary>
/// 填充模式
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "FT")]
private void FillType(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_FillType = p_Value;
}
/// <summary>
/// 设置笔
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "SP")]
private void SelectPen(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_SelectPen = p_Value;
}
/// <summary>
/// 设置输入框 显示的区域
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "IW")]
private void InputWindow(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_InputWindow = p_Value;
}
/// <summary>
/// 设置输入框 显示的区域
/// </summary>
/// <param name="p_FileByte"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PU")]
private void PenUP(byte[] p_FileBytes, string p_Value)
{
string[] _ValueList = p_Value.Split(',');
m_Buffer.HPGL_PointStartX = decimal.Parse(_ValueList[0]);
m_Buffer.HPGL_PointStartY = decimal.Parse(_ValueList[1]);
}
/// <summary>
/// 相对巨型
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "RR")]
private void RectangleRelative(byte[] p_FileBytes, string p_Value)
{
string[] _ValueList = p_Value.Split(',');
m_Buffer.HPGL_PointEndX = decimal.Parse(_ValueList[0]);
m_Buffer.HPGL_PointEndY = decimal.Parse(_ValueList[1]);
}
/// <summary>
/// 绘制矩形
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "ER")]
private void EdgeReangleRelative(byte[] p_FileBytes, string p_Value)
{
decimal _StartX = m_Buffer.HPGL_PointStartX / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _StartY = m_Buffer.HPGL_PointStartY / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _Width = m_Buffer.HPGL_PointEndX / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _Height = m_Buffer.HPGL_PointEndY / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
_StartX = Math.Ceiling(_StartX);
_StartY = Math.Ceiling(_StartY);
_Width = Math.Ceiling(_Width);
_Height = Math.Ceiling(_Height);
Color _Color = m_Buffer.HPGL_PenColorAssignment[int.Parse(m_Buffer.HPGL_SelectPen)];
m_Buffer.m_Graphics.FillRectangle(new SolidBrush(_Color), (int)_StartX, (int)_StartY, (int)_Width, (int)_Height);
}
/// <summary>
/// 合并控制
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "MC")]
private void MergeControl(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_MergeControl = p_Value;
}
/// <summary>
/// 情节控制 清除了HPGL_PenDown的路径
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PA")]
private void PlotAbsolute(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_PlotAbsolute = p_Value;
m_Buffer.HPGL_PenDown.Clear();
}
/// <summary>
/// 多边形类型
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PM")]
private void PolygonModel(byte[] p_FileBytes, string p_Value)
{
m_Buffer.HPGL_PolygonModel = p_Value;
}
/// <summary>
/// 落笔的位置
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "PD")]
private void PenDown(byte[] p_FileBytes, string p_Value)
{
string[] _List = p_Value.Split(',');
for (int i = 0; i != _List.Length / 2; i++)
{
m_Buffer.HPGL_PenDown.Add(new Point(int.Parse(_List[i * 2]), int.Parse(_List[i * 2 + 1])));
}
}
/// <summary>
/// 绘制模式 0 1模式不做处理
/// </summary>
/// <param name="p_FileBytes"></param>
/// <param name="p_Value"></param>
[PCLInfo(TitleCommand1 = "FP")]
private void FillPolyon(byte[] p_FileBytes, string p_Value)
{
Point[] _NewPoint = new Point[m_Buffer.HPGL_PenDown.Count];
for (int i = 0; i != _NewPoint.Length; i++)
{
decimal _X = m_Buffer.HPGL_PenDown[i].X / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _Y = m_Buffer.HPGL_PenDown[i].Y / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
_NewPoint[i] = new Point((int)Math.Ceiling(_X), (int)Math.Ceiling(_Y));
}
Color _Color = m_Buffer.HPGL_PenColorAssignment[int.Parse(m_Buffer.HPGL_SelectPen)];
switch (m_Buffer.HPGL_PolygonModel)
{
case "1":
m_Buffer.m_Graphics.DrawPolygon(new Pen(new SolidBrush(_Color)), _NewPoint);
break;
case "2":
m_Buffer.m_Graphics.FillPolygon(new SolidBrush(_Color), _NewPoint);
break;
default:
m_Buffer.m_Graphics.DrawPolygon(new Pen(Brushes.Yellow, 1), _NewPoint);
break;
}
}
[PCLInfo(TitleCommand1 = "IR")]
private void InputRelative(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_InputRelative = p_Value;
}
[PCLInfo(TitleCommand1 = "SC")]
private void Scale(byte[] p_FileByte, string p_Value)
{
m_Buffer.HPGL_Scale = p_Value;
}
#region 私有方法
/// <summary>
/// 获取命令行的中间数字
/// </summary>
/// <param name="p_Command">命令行</param>
/// <param name="p_Start">开始位置</param>
/// <returns>字符类型的命令行</returns>
private int GetCommandEndIndex(byte[] p_Command, int p_Start)
{
int _Count = 0;
for (int i = p_Start; i != p_Command.Length; i++)
{
if (p_Command[i] >= 0x30 && p_Command[i] <= 0x39 || p_Command[i] == 0x2E || p_Command[i] == 0x2E || p_Command[i] == 0x2D || p_Command[i] == 0x2C)
{
_Count++;
}
else
{
break;
}
}
return _Count;
}
#endregion
}
#endregion
#region PCL
/// <summary>
/// PCL命令的执行
/// </summary>
private class PCL
{
/// <summary>
/// 构造类
/// </summary>
/// <param name="p_Buffer"></param>
public PCL(PrintBuffer p_Buffer, IList<Image> p_ImageList)
{
m_Buffer = p_Buffer;
m_ImageList = p_ImageList;
MethodInfo[] _MethodList = this.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance);
for (int i = 0; i != _MethodList.Length; i++)
{
object[] _Attributes = _MethodList[i].GetCustomAttributes(false);
if (_Attributes.Length == 1 && _Attributes[0] is PCLInfo)
{
PCLInfo _CommandInfo = (PCLInfo)_Attributes[0];
if (_CommandInfo.TitleCommand1.Length != 0) m_CommandMethodInfo.Add(_CommandInfo.TitleCommand1, _MethodList[i]);
if (_CommandInfo.TitleCommand2.Length != 0) m_CommandMethodInfo.Add(_CommandInfo.TitleCommand2, _MethodList[i]);
}
}
}
#region 私有成员
/// <summary>
/// 命令列表
/// </summary>
private Dictionary<string, MethodInfo> m_CommandMethodInfo = new Dictionary<string, MethodInfo>();
/// <summary>
/// 打印缓冲区
/// </summary>
private PrintBuffer m_Buffer;
/// <summary>
///执行到的位置
/// </summary>
private int m_ReadIndex;
/// <summary>
/// 打印的图形
/// </summary>
private IList<Image> m_ImageList;
#endregion
#region 执行命令
/// <summary>
/// 开始执行命令
/// </summary>
/// <param name="p_FileBytes">文件流</param>
/// <param name="p_ReadIndex">开始位置</param>
public void StartCommandLine(byte[] p_FileBytes, ref int p_ReadIndex)
{
byte _TitleCommand = p_FileBytes[p_ReadIndex];
byte _StartCommand = 0x0;
byte _EndCommand = 0x0;
p_ReadIndex++;
int _Count = GetCommandEndIndex(p_FileBytes, p_ReadIndex); //判断命令的第2个字母是否是数字
if (_Count == 0) //如果不是数字说明是控制符号
{
_StartCommand = p_FileBytes[p_ReadIndex];
p_ReadIndex++;
}
while (true)
{
if (p_FileBytes[p_ReadIndex] == 0x1B || p_FileBytes[p_ReadIndex] == 0x0D || p_FileBytes[p_ReadIndex] == 0x0C) return;
_Count = GetCommandEndIndex(p_FileBytes, p_ReadIndex); //获取2个控制符后的数据
string _Value = Encoding.ASCII.GetString(p_FileBytes, p_ReadIndex, _Count);
p_ReadIndex += _Count;
_EndCommand = p_FileBytes[p_ReadIndex];
p_ReadIndex++;
string _CommandText = Encoding.ASCII.GetString(new byte[] { _TitleCommand, _StartCommand, _EndCommand }).Replace("/0", "");
CommandStart(_CommandText, p_FileBytes, _Value, ref p_ReadIndex);
}
}
/// <summary>
/// 开始执行命令
/// </summary>
/// <param name="p_Command">命令结构</param>
/// <param name="p_Value">获取的字符类型</param>
/// <param name="p_ReadIndex">读去位</param>
private void CommandStart(string p_CommandText, byte[] p_FileBytes, string p_Value, ref int p_ReadIndex)
{
if (m_CommandMethodInfo.ContainsKey(p_CommandText))
{
try
{
m_ReadIndex = p_ReadIndex;
object _ReturnCount = m_CommandMethodInfo[p_CommandText].Invoke(this, new object[] { p_FileBytes, p_Value });
if (_ReturnCount != null) p_ReadIndex += (int)_ReturnCount;
}
catch (Exception ex)
{
throw new Exception("PCL{" + p_ReadIndex.ToString() + "}" + "命令错误![" + p_CommandText + "]" + ex.InnerException.Message);
}
}
else
{
throw new Exception("PCL{" + p_ReadIndex.ToString() + "}" + "命令错误![" + p_CommandText + "]");
}
}
#endregion
#region *命令
/// <summary>
/// 光栅图形分辨率 DPI
/// </summary>
[PCLInfo(TitleCommand1 = "*tR")]
private void RasterGraphicsResolution(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_RasterGraphicsResolution = int.Parse(p_Value);
}
/// <summary>
/// X
/// </summary>
[PCLInfo(TitleCommand1 = "*px", TitleCommand2 = "*pX")]
private int HorizontalCursorPositioning(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_HorizontalCursorPositioning = int.Parse(p_Value);
byte _StarCommand = p_Command[m_ReadIndex - 1];
int _Count = GetCommandEndIndex(p_Command, m_ReadIndex);
if (_Count == 0) return GetPrintText(p_Command);
byte _EndCommand = p_Command[m_ReadIndex + _Count];
if (_StarCommand + 31 == _EndCommand || _StarCommand - 31 == _EndCommand)
{
return 0;
}
else
{
return GetPrintText(p_Command);
}
}
/// <summary>
/// Y
/// </summary>
[PCLInfo(TitleCommand1 = "*py", TitleCommand2 = "*pY")]
private int VerticalCursorPositioning(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_VerticalCursorPositioning = int.Parse(p_Value);
byte _StarCommand = p_Command[m_ReadIndex - 1];
int _Count = GetCommandEndIndex(p_Command, m_ReadIndex);
if (_Count == 0) return GetPrintText(p_Command);
byte _EndCommand = p_Command[m_ReadIndex + _Count];
if (_StarCommand + 31 == _EndCommand || _StarCommand - 31 == _EndCommand)
{
return 0;
}
else
{
return GetPrintText(p_Command);
}
}
/// <summary>
/// 设置相框安克波因特
/// </summary>
[PCLInfo(TitleCommand1 = "*ct", TitleCommand2 = "*cT")]
private void SetPictureFrameAnchorPoint(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SetPictureFrameAnchorPoint = int.Parse(p_Value);
}
/// <summary>
/// 横向尺寸
/// </summary>
[PCLInfo(TitleCommand1 = "*cx")]
private void HorizontalSize(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_HorizontalSize = int.Parse(p_Value);
}
/// <summary>
/// 垂直尺寸
/// </summary>
[PCLInfo(TitleCommand1 = "*cY")]
private void VerticalSize(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_VerticalSize = int.Parse(p_Value);
}
/// <summary>
/// 0 - 在当前的打印方向,打印的图像。3 - 图像沿物理页面宽度打印
/// </summary>
[PCLInfo(TitleCommand1 = "*rF")]
private void RasterGraphicsPresentationMode(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_RasterGraphicsPresentationMode = int.Parse(p_Value);
}
/// <summary>
/// 压缩方式
/// </summary>
[PCLInfo(TitleCommand1 = "*bM")]
private void CompressionMethod(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_CompressionMethod = int.Parse(p_Value);
}
/// <summary>
/// 来源透明方式
/// </summary>
[PCLInfo(TitleCommand1 = "*vN")]
private void SourceTransparencyMode(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SourceTransparencyMode = int.Parse(p_Value);
}
/// <summary>
/// 来源透明方式
/// </summary>
[PCLInfo(TitleCommand1 = "*vO")]
private void PatternTransparencyMode(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PatternTransparencyMode = int.Parse(p_Value);
}
/// <summary>
/// 逻辑运算
/// </summary>
[PCLInfo(TitleCommand1 = "*lO")]
private void LogicalOperation(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_LogicalOperation = int.Parse(p_Value);
}
/// <summary>
/// 配置图像数据
/// </summary>
[PCLInfo(TitleCommand1 = "*vW")]
private int ConfigureImageData(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_ConfigureImageData = new byte[int.Parse(p_Value)];
Array.Copy(p_Command, m_ReadIndex, m_Buffer.PCL_ConfigureImageData, 0, m_Buffer.PCL_ConfigureImageData.Length);
return m_Buffer.PCL_ConfigureImageData.Length;
}
/// <summary>
/// 颜色Red
/// </summary>
[PCLInfo(TitleCommand1 = "*va")]
private void ColorComponentOne(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_ColorComponentOne = int.Parse(p_Value);
}
/// <summary>
/// 颜色Green
/// </summary>
[PCLInfo(TitleCommand1 = "*vb")]
private void ColorComponentTwo(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_ColorComponentTwo = int.Parse(p_Value);
}
/// <summary>
/// 颜色Blue
/// </summary>
[PCLInfo(TitleCommand1 = "*vc")]
private void ColorComponentThree(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_ColorComponentThree = int.Parse(p_Value);
}
/// <summary>
/// 设置颜色索引
/// </summary>
[PCLInfo(TitleCommand1 = "*vi", TitleCommand2 = "*vI")]
private void AssignColorIndex(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_AssignColorIndex = int.Parse(p_Value);
if (m_Buffer.m_ColorPalette.ContainsKey(m_Buffer.PCL_AssignColorIndex))
{
m_Buffer.m_ColorPalette[m_Buffer.PCL_AssignColorIndex] = Color.FromArgb(m_Buffer.PCL_ColorComponentOne, m_Buffer.PCL_ColorComponentTwo, m_Buffer.PCL_ColorComponentThree);
}
else
{
m_Buffer.m_ColorPalette.Add(m_Buffer.PCL_AssignColorIndex, Color.FromArgb(m_Buffer.PCL_ColorComponentOne, m_Buffer.PCL_ColorComponentTwo, m_Buffer.PCL_ColorComponentThree));
}
}
/// <summary>
/// 渲染算法
/// </summary>
[PCLInfo(TitleCommand1 = "*tJ")]
private void RenderAlgorithm(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_RenderAlgorithm = int.Parse(p_Value);
}
/// <summary>
/// 前景色
/// </summary>
[PCLInfo(TitleCommand1 = "*vS")]
private void ForegroundColor(byte[] p_Command, string p_Value)
{
int _Value = int.Parse(p_Value);
m_Buffer.PCL_ForegroundColor = m_Buffer.m_ColorPalette[_Value];
}
/// <summary>
/// 选择当前模式
/// </summary>
[PCLInfo(TitleCommand1 = "*vt")]
private void SelectCurrentPattern(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SelectCurrentPattern = int.Parse(p_Value);
}
/// <summary>
/// 图形原始宽
/// </summary>
[PCLInfo(TitleCommand1 = "*rs")]
private void SourceRasterWidth(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SourceRasterWidth = int.Parse(p_Value);
}
/// <summary>
/// 图形原始高
/// </summary>
[PCLInfo(TitleCommand1 = "*rT")]
private void SourceRasterHeight(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SourceRasterHeight = int.Parse(p_Value);
}
/// <summary>
/// 图形目的宽
/// </summary>
[PCLInfo(TitleCommand1 = "*th")]
private void DestinationRasterWidth(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_DestinationRasterWidth = int.Parse(p_Value);
}
/// <summary>
/// 图形目的高
/// </summary>
[PCLInfo(TitleCommand1 = "*tV")]
private void DestinationRasterHeight(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_DestinationRasterHeight = int.Parse(p_Value);
}
/// <summary>
/// 开始光栅图形
/// </summary>
[PCLInfo(TitleCommand1 = "*rA")]
private void StartRasterGraphics(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_CompressionMethod = 0;
m_Buffer.PCL_StartRasterGraphics = int.Parse(p_Value);
if (m_Buffer.PCL_SourceRasterWidth != 0 && m_Buffer.PCL_SourceRasterHeight != 0)
{
switch (m_Buffer.PCL_SelectPalette)
{
case 6:
#region 24位色
m_Buffer.m_GraphicsBitmap = new Bitmap(m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight, PixelFormat.Format24bppRgb);
Graphics _Graphics = Graphics.FromImage(m_Buffer.m_GraphicsBitmap);
_Graphics.Clear(Color.White);
_Graphics.Dispose();
m_Buffer.m_GraphicsRowIndex = 0;
m_Buffer.m_OldBytes = new byte[m_Buffer.PCL_SourceRasterWidth * 3];
for (int i = 0; i != m_Buffer.m_OldBytes.Length / 3; i++)
{
m_Buffer.m_OldBytes[i * 3] = (byte)m_Buffer.PCL_ForegroundColor.R;
m_Buffer.m_OldBytes[i * 3 + 1] = (byte)m_Buffer.PCL_ForegroundColor.G;
m_Buffer.m_OldBytes[i * 3 + 2] = (byte)m_Buffer.PCL_ForegroundColor.B;
}
#endregion
break;
case 9:
#region 1位色
m_Buffer.m_GraphicsBitmap = new Bitmap(m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight, PixelFormat.Format1bppIndexed);
ColorPalette _Palette = m_Buffer.m_GraphicsBitmap.Palette;
_Palette.Entries[0] = m_Buffer.PCL_SourceTransparencyMode == 0 ? Color.FromArgb(0, m_Buffer.m_ColorPalette[0].R, m_Buffer.m_ColorPalette[0].G, m_Buffer.m_ColorPalette[0].B) : m_Buffer.m_ColorPalette[0];
_Palette.Entries[1] = m_Buffer.PCL_ForegroundColor;
m_Buffer.m_GraphicsBitmap.Palette = _Palette;
m_Buffer.m_GraphicsRowIndex = 0;
BitmapData _Data = m_Buffer.m_GraphicsBitmap.LockBits(new Rectangle(0, 0, m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight), ImageLockMode.ReadOnly, m_Buffer.m_GraphicsBitmap.PixelFormat);
m_Buffer.m_OldBytes = new byte[_Data.Stride];
m_Buffer.m_GraphicsBitmap.UnlockBits(_Data);
break;
#endregion
case 7:
#region 8位色
m_Buffer.m_GraphicsBitmap = new Bitmap(m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight, PixelFormat.Format8bppIndexed);
BitmapData _Data256 = m_Buffer.m_GraphicsBitmap.LockBits(new Rectangle(0, 0, m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight), ImageLockMode.ReadWrite, PixelFormat.Format8bppIndexed);
m_Buffer.m_GraphicsRowIndex = 0;
m_Buffer.m_OldBytes = new byte[_Data256.Stride];
ColorPalette _Palette256 = m_Buffer.m_GraphicsBitmap.Palette;
foreach (int _Key in m_Buffer.m_ColorPalette.Keys)
{
_Palette256.Entries[_Key] = m_Buffer.m_ColorPalette[_Key];
}
m_Buffer.m_GraphicsBitmap.Palette = _Palette256;
m_Buffer.m_GraphicsBitmap.UnlockBits(_Data256);
#endregion
break;
}
}
}
/// <summary>
/// 光栅图形行数据
/// </summary>
[PCLInfo(TitleCommand1 = "*bW")]
private int TransferRasterDatabyRow(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_TransferRasterDatabyRow = new byte[int.Parse(p_Value)];
Array.Copy(p_Command, m_ReadIndex, m_Buffer.PCL_TransferRasterDatabyRow, 0, m_Buffer.PCL_TransferRasterDatabyRow.Length);
switch (m_Buffer.PCL_CompressionMethod)
{
case 3:
TransferRasterDatabyRowOf3();
break;
case 2:
TransferRasterDatabyRowOf2();
break;
case 0:
TransferRasterDatabyRowOf0();
break;
default:
throw new Exception("未实现" + m_Buffer.PCL_CompressionMethod.ToString() + "解压方式");
}
#region 反转数据
byte[] _WriteBytes = new byte[m_Buffer.m_OldBytes.Length];
switch (m_Buffer.PCL_SelectPalette)
{
case 6:
for (int i = 0; i != _WriteBytes.Length / 3; i++)
{
_WriteBytes[i * 3] = m_Buffer.m_OldBytes[(i * 3) + 2];
_WriteBytes[(i * 3) + 1] = m_Buffer.m_OldBytes[(i * 3) + 1];
_WriteBytes[(i * 3) + 2] = m_Buffer.m_OldBytes[(i * 3)];
}
break;
case 9:
Array.Copy(m_Buffer.m_OldBytes, _WriteBytes, _WriteBytes.Length);
break;
case 7:
Array.Copy(m_Buffer.m_OldBytes, _WriteBytes, _WriteBytes.Length);
break;
}
#endregion
#region 复制到图形
BitmapData _BitmapData = m_Buffer.m_GraphicsBitmap.LockBits(new Rectangle(0, 0, m_Buffer.PCL_SourceRasterWidth, m_Buffer.PCL_SourceRasterHeight), ImageLockMode.ReadWrite, m_Buffer.m_GraphicsBitmap.PixelFormat);
IntPtr _WriteRowIndex = new IntPtr(_BitmapData.Scan0.ToInt32() + _BitmapData.Stride * m_Buffer.m_GraphicsRowIndex);
Marshal.Copy(_WriteBytes, 0, _WriteRowIndex, _WriteBytes.Length);
m_Buffer.m_GraphicsBitmap.UnlockBits(_BitmapData);
#endregion
m_Buffer.m_GraphicsRowIndex++; //获取的行数加1
return m_Buffer.PCL_TransferRasterDatabyRow.Length;
}
/// <summary>
/// 光栅图形行数据
/// </summary>
[PCLInfo(TitleCommand1 = "*rC")]
private int EndRasterGraphics(byte[] p_Command, string p_Value)
{
decimal _ValueWidth = (decimal)m_Buffer.PCL_DestinationRasterWidth / 720 * 150;
decimal _ValueHeight = (decimal)m_Buffer.PCL_DestinationRasterHeight / 720 * 150;
decimal _X = (decimal)m_Buffer.PCL_HorizontalCursorPositioning / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _Y = (decimal)m_Buffer.PCL_VerticalCursorPositioning / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
m_Buffer.m_Graphics.DrawImage(m_Buffer.m_GraphicsBitmap, new Rectangle((int)_X, (int)_Y, (int)_ValueWidth, (int)_ValueHeight));
return 0;
}
/// <summary>
/// 字体ID
/// </summary>
[PCLInfo(TitleCommand1 = "*cD")]
private void FontID(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_FontID = int.Parse(p_Value);
}
/// <summary>
/// 字体ID
/// </summary>
[PCLInfo(TitleCommand1 = "*cE")]
private void CharacterCode(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_CharacterCode = int.Parse(p_Value);
}
#endregion
#region &命令
/// <summary>
/// 0纵向 1横向 2逆纵向 3逆横向
/// </summary>
[PCLInfo(TitleCommand1 = "&lo")]
private void PageOrientation(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PageOrientation = int.Parse(p_Value);
}
/// <summary>
/// 顶部距离
/// </summary>
[PCLInfo(TitleCommand1 = "&lE")]
private void TopMargin(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_TopMargin = int.Parse(p_Value);
}
/// <summary>
/// 计量单位 DPI
/// </summary>
[PCLInfo(TitleCommand1 = "&uD")]
private void UnitOfMeasure(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_UnitOfMeasure = int.Parse(p_Value);
}
/// <summary>
/// 单纯/双面打印 0-单 1-双面长 2-双面短
/// </summary>
[PCLInfo(TitleCommand1 = "&lS")]
private void SimplexDuplexPrint(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SimplexDuplexPrint = int.Parse(p_Value);
}
/// <summary>
/// 纸张类型
/// </summary>
[PCLInfo(TitleCommand1 = "&nW")]
private int AlphanumericID(byte[] p_Command, string p_Value)
{
int _Count = 0;
m_Buffer.PCL_AlphanumericID = p_Value + "W";
for (int i = m_ReadIndex; i != p_Command.Length; i++)
{
if (p_Command[i] == 0x1B) break;
m_Buffer.PCL_AlphanumericID += (char)p_Command[i];
_Count++;
}
return _Count;
}
/// <summary>
/// 纸张来源
/// </summary>
[PCLInfo(TitleCommand1 = "&lH")]
private void PaperSource(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PaperSource = int.Parse(p_Value);
}
/// <summary>
/// 纸张大小
/// </summary>
[PCLInfo(TitleCommand1 = "&la")]
private void PapeSize(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PageSize = int.Parse(p_Value);
decimal _Width = (decimal)m_Buffer.PCL_HorizontalSize / 720 * 150;
decimal _Height = (decimal)m_Buffer.PCL_VerticalSize / 720 * 150;
m_Buffer.m_PrintBitmap = new Bitmap((int)_Width, (int)_Height, PixelFormat.Format24bppRgb);
m_Buffer.m_Graphics = Graphics.FromImage(m_Buffer.m_PrintBitmap);
m_Buffer.m_Graphics.Clear(Color.White);
m_Buffer.m_Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Invalid;
m_Buffer.m_Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
}
/// <summary>
/// 垂直运动指数 ?
/// </summary>
[PCLInfo(TitleCommand1 = "&lc")]
private void VerticalMotionIndex(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_VerticalMotionIndex = int.Parse(p_Value);
}
/// <summary>
/// 打印分数
/// </summary>
[PCLInfo(TitleCommand1 = "&lX")]
private void NumberofCopies(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_NumberofCopies = int.Parse(p_Value);
}
/// <summary>
/// 调色板控件ID
/// </summary>
[PCLInfo(TitleCommand1 = "&pi")]
private void PaletteControlID(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PaletteControlID = int.Parse(p_Value);
}
/// <summary>
/// 选择调色板
/// </summary>
[PCLInfo(TitleCommand1 = "&pS")]
private void SelectPalette(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SelectPalette = int.Parse(p_Value);
}
/// <summary>
/// 调色板控制
/// </summary>
[PCLInfo(TitleCommand1 = "&pc", TitleCommand2 = "&pC")]
private void PaletteControl(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_PaletteControl = int.Parse(p_Value);
}
/// <summary>
/// 下化线
/// </summary>
[PCLInfo(TitleCommand1 = "&d@")]
private int Underline(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_Underline = int.Parse("-1");
return GetPrintText(p_Command);
}
#endregion
#region ()命令
/// <summary>
/// 字体头命令
/// </summary>
[PCLInfo(TitleCommand1 = ")sW")]
private int FontHeaderCommand(byte[] p_Command, string p_Value)
{
byte[] _Value = new byte[int.Parse(p_Value)];
Array.Copy(p_Command, m_ReadIndex, _Value, 0, _Value.Length);
Hashtable _FontHeader = new Hashtable();
_FontHeader.Add("FontDescriptorSize", (ushort)(_Value[0] << 8 | _Value[1]));
_FontHeader.Add("HeaderFormat", _Value[2]);
_FontHeader.Add("FontType", _Value[3]);
_FontHeader.Add("StyleMSB", _Value[4]);
_FontHeader.Add("Reserved", _Value[5]);
_FontHeader.Add("BaselinePosition", (short)(_Value[6] << 8 | _Value[7]));
_FontHeader.Add("CellWidth", (short)(_Value[8] << 8 | _Value[9]));
_FontHeader.Add("CellHeight", (short)(_Value[10] << 8 | _Value[11]));
_FontHeader.Add("Orientation", _Value[12]);
_FontHeader.Add("Spacing", _Value[13]);
_FontHeader.Add("SymbolSet", (short)(_Value[14] << 8 | _Value[15]));
_FontHeader.Add("PitchHMI", (short)(_Value[16] << 8 | _Value[17]));
_FontHeader.Add("Height", (short)(_Value[18] << 8 | _Value[19]));
_FontHeader.Add("x-Height", (short)(_Value[20] << 8 | _Value[21]));
_FontHeader.Add("WidthType", _Value[22]);
_FontHeader.Add("StyleLSB", _Value[23]);
_FontHeader.Add("StrokeWeight", _Value[24]);
_FontHeader.Add("TypefaceLSB", _Value[25]);
_FontHeader.Add("TypefaceMSB", _Value[26]);
_FontHeader.Add("SerifStyle", _Value[27]);
_FontHeader.Add("Quality", _Value[28]);
_FontHeader.Add("Placement", _Value[29]);
_FontHeader.Add("UnderlinePosition", _Value[30]);
_FontHeader.Add("UnderlineThickness", _Value[31]);
_FontHeader.Add("TextHeight", (short)(_Value[32] << 8 | _Value[33]));
_FontHeader.Add("TextWidth", (short)(_Value[34] << 8 | _Value[35]));
_FontHeader.Add("FirstCode", (short)(_Value[36] << 8 | _Value[37]));
_FontHeader.Add("LastCode", (short)(_Value[38] << 8 | _Value[39]));
_FontHeader.Add("PitchExtended", _Value[40]);
_FontHeader.Add("HeightExtended", _Value[41]);
_FontHeader.Add("CapHeight", (short)(_Value[42] << 8 | _Value[43]));
_FontHeader.Add("FontNumber", (short)(_Value[44] << 24 | _Value[45] << 16 | _Value[46] << 8 | _Value[47]));
_FontHeader.Add("FontName", Encoding.ASCII.GetString(_Value, 48, 15).Trim('/0'));
switch ((ushort)_FontHeader["FontDescriptorSize"])
{
case 68: //Resolution-Specified Bitmapped)
_FontHeader.Add("XResolution", (short)(_Value[64] << 8 | _Value[65]));
_FontHeader.Add("YResolution", (short)(_Value[66] << 8 | _Value[67]));
if (_Value.Length - 68 != 0)
{
byte[] _Copyight = new byte[_Value.Length - 68];
Array.Copy(_Value, 68, _Copyight, 0, _Copyight.Length);
_FontHeader.Add("Copyright", _Copyight);
}
break;
case 72: //TrueType Scalable Fonts
_FontHeader.Add("ScaleFactor", (short)(_Value[64] << 8 | _Value[65]));
_FontHeader.Add("MasterUnderlinePosition", (short)(_Value[66] << 8 | _Value[67]));
_FontHeader.Add("MasterUnderlineThickness", (short)(_Value[68] << 8 | _Value[69]));
_FontHeader.Add("FontScalingTechnology ", _Value[70]);
_FontHeader.Add("Variety", _Value[71]);
int _ReadIndex = 72;
if (_Value[_ReadIndex] == 0x50 && _Value[_ReadIndex + 1] == 0x41)
{
ushort _AdditionalCount = (ushort)(_Value[_ReadIndex + 2] << 8 | _Value[_ReadIndex + 3]);
_AdditionalCount += 8; //5041 PA两位 大小两位 最后是4位应该是验效码
byte[] _AdditionalBytes = new byte[_AdditionalCount];
Array.Copy(_Value, _ReadIndex, _AdditionalBytes, 0, _AdditionalBytes.Length);
_ReadIndex += _AdditionalBytes.Length;
_FontHeader.Add("AdditionalData", _AdditionalBytes);
}
if (_ReadIndex <= _Value.Length - _ReadIndex)
{
byte[] _FontBytes = new byte[_Value.Length - _ReadIndex];
Array.Copy(_Value, _ReadIndex, _FontBytes, 0, _FontBytes.Length);
ImageTTF _TTF = new ImageTTF(_FontBytes);
_FontHeader.Add("FontData", _TTF);
}
break;
default:
throw new Exception("未知");
}
if (m_Buffer.PCL_FontHeaderCommand.ContainsKey(m_Buffer.PCL_FontID))
{
m_Buffer.PCL_FontHeaderCommand[m_Buffer.PCL_FontID] = _FontHeader;
}
else
{
m_Buffer.PCL_FontHeaderCommand.Add(m_Buffer.PCL_FontID, _FontHeader);
}
return _Value.Length;
}
/// <summary>
/// 字体图片
/// </summary>
[PCLInfo(TitleCommand1 = "(sW")]
private int CharacterDefinitionCommand(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_CharacterDefinitionCommand = new byte[int.Parse(p_Value)];
Array.Copy(p_Command, m_ReadIndex, m_Buffer.PCL_CharacterDefinitionCommand, 0, m_Buffer.PCL_CharacterDefinitionCommand.Length);
object _ObjectData = null;
string _FontKey = m_Buffer.PCL_FontID.ToString() + "," + m_Buffer.PCL_CharacterCode.ToString();
switch (m_Buffer.PCL_CharacterDefinitionCommand[0])
{
case 4: //PCL BITMAP
_ObjectData = GetFontBitmap(m_Buffer.PCL_CharacterDefinitionCommand);
break;
case 15: //TRUE FONT
byte[] _DrawImageLine = new byte[m_Buffer.PCL_CharacterDefinitionCommand.Length];
Array.Copy(m_Buffer.PCL_CharacterDefinitionCommand, _DrawImageLine, _DrawImageLine.Length);
_ObjectData = new object[] { m_Buffer.PCL_FontHeaderCommand[m_Buffer.PCL_FontID], _DrawImageLine };
break;
default:
throw new Exception("未对(sW的类型" + m_Buffer.PCL_CharacterDefinitionCommand[0].ToString() + "的解析");
}
if (_ObjectData != null)
{
if (m_Buffer.m_FontBitmapTable.ContainsKey(_FontKey))
{
m_Buffer.m_FontBitmapTable[_FontKey] = _ObjectData;
}
else
{
m_Buffer.m_FontBitmapTable.Add(_FontKey, _ObjectData);
}
}
return m_Buffer.PCL_CharacterDefinitionCommand.Length;
}
/// <summary>
/// 字体大小
/// </summary>
[PCLInfo(TitleCommand1 = "(sV", TitleCommand2 = "(sv")]
private void FontHeight(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_FontHeight = float.Parse(p_Value);
}
/// <summary>
/// 使用字体的编号
/// </summary>
[PCLInfo(TitleCommand1 = "(X")]
private void SelectFontID(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_SelectFontID = int.Parse(p_Value);
}
/// <summary>
/// 字体系列命令
/// </summary>
[PCLInfo(TitleCommand1 = "(st")]
private void TypefaceFamily(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_TypefaceFamily = int.Parse(p_Value);
m_Buffer.PCL_SelectFontID = -1;
if (!m_Buffer.m_TrueTypeFont.ContainsKey(m_Buffer.PCL_TypefaceFamily))
{
string _FontName = "Arial";
switch (m_Buffer.PCL_TypefaceFamily)
{
case 16602:
_FontName = "Arial";
break;
case 16901:
_FontName = "Times New Roman";
break;
default:
break;
}
//FontStyle _Style =FontStyle.Regular;
//switch(m_Buffer.PCL_StrokeWeight)
//{
// case 3:
// _Style = FontStyle.Bold;
// break;
// case 0:
// _Style = FontStyle.Regular;
// break;
//}
Microsoft.Win32.RegistryKey _FontPath = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software/Microsoft/Windows/CurrentVersion/Explorer/Shell Folders");
string _Path = _FontPath.GetValue("Fonts").ToString();
Microsoft.Win32.RegistryKey _Key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE/Microsoft/Windows NT/CurrentVersion/Fonts");
if (_Key == null) return;
object _TrueTypeFont = _Key.GetValue(_FontName + " (TrueType)");
if (_TrueTypeFont == null) return;
m_Buffer.m_TrueTypeFont.Add(m_Buffer.PCL_TypefaceFamily, new ImageTTF(_Path + "//" + _TrueTypeFont));
}
}
/// <summary>
/// 字体重量
/// </summary>
[PCLInfo(TitleCommand1 = "(sb")]
private void StrokeWeight(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_StrokeWeight = int.Parse(p_Value);
}
/// <summary>
/// 样式
/// </summary>
[PCLInfo(TitleCommand1 = "(ss")]
private void Style(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_Style = int.Parse(p_Value);
}
/// <summary>
/// 字体间距
/// </summary>
[PCLInfo(TitleCommand1 = "(sP")]
private void Spacing(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_Spacing = int.Parse(p_Value);
}
#endregion
#region 未知
/// <summary>
/// 未知数据1
/// </summary>
[PCLInfo(TitleCommand1 = "*oW")]
private int UnData1(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_UnData1 = new byte[int.Parse(p_Value)];
Array.Copy(p_Command, m_ReadIndex, m_Buffer.PCL_UnData1, 0, m_Buffer.PCL_UnData1.Length);
return m_Buffer.PCL_UnData1.Length;
}
/// <summary>
/// 未知数据2
/// </summary>
[PCLInfo(TitleCommand1 = "&bF")]
private void UnData2(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_UnData2 = int.Parse(p_Value);
}
/// <summary>
/// 未知数据3
/// </summary>
[PCLInfo(TitleCommand1 = "(U")]
private void UnData3(byte[] p_Command, string p_Value)
{
m_Buffer.PCL_UnData3 = int.Parse(p_Value);
}
#endregion
#region 绘制方法
/// <summary>
/// 绘制一行数据到图形 对应 Unencoded
/// </summary>
private void TransferRasterDatabyRowOf0()
{
Array.Copy(m_Buffer.PCL_TransferRasterDatabyRow, m_Buffer.m_OldBytes, m_Buffer.m_OldBytes.Length);
}
/// <summary>
/// 绘制一行数据到图形 对应 Tagged Imaged File Format (TIFF) rev. 4.0
/// </summary>
private void TransferRasterDatabyRowOf2()
{
int _WriteIndex = 0;
for (int i = 0; i != m_Buffer.PCL_TransferRasterDatabyRow.Length; i++)
{
byte _Count = m_Buffer.PCL_TransferRasterDatabyRow[i];
if (_Count > 0x7F)
{
_Count = (byte)(257 - _Count);
for (int z = 0; z != _Count; z++)
{
m_Buffer.m_OldBytes[_WriteIndex] = m_Buffer.PCL_TransferRasterDatabyRow[i + 1];
_WriteIndex++;
}
i++;
}
else
{
_Count++;
if (_WriteIndex + _Count > m_Buffer.m_OldBytes.Length) return;
Array.Copy(m_Buffer.PCL_TransferRasterDatabyRow, i + 1, m_Buffer.m_OldBytes, _WriteIndex, _Count);
_WriteIndex += _Count;
i += _Count;
}
}
}
/// <summary>
/// 绘制一行数据到图形 对应 Delta row compression
/// </summary>
private void TransferRasterDatabyRowOf3()
{
if (m_Buffer.PCL_TransferRasterDatabyRow.Length != 0)
{
int _Index = 0;
int _WrideIndex = 0;
while (_Index < m_Buffer.PCL_TransferRasterDatabyRow.Length)
{
byte _Count = m_Buffer.PCL_TransferRasterDatabyRow[_Index];
int _ControlColor = _Count >> 5;
_ControlColor++;
_WrideIndex += _Count & 0x1F;
if ((_Count & 0x1F) == 0x1F) //如果后5位为11111 那么后面跟的不是颜色数据是定位。如果定位是255 那下一个还是定位
{
for (int i = _Index + 1; i != m_Buffer.PCL_TransferRasterDatabyRow.Length; i++)
{
_WrideIndex += m_Buffer.PCL_TransferRasterDatabyRow[i];
_Index++;
if (m_Buffer.PCL_TransferRasterDatabyRow[i] != 0xFF) break;
}
}
for (int i = 0; i != _ControlColor; i++)
{
m_Buffer.m_OldBytes[_WrideIndex] = m_Buffer.PCL_TransferRasterDatabyRow[_Index + 1 + i];
_WrideIndex++;
}
_Index += _ControlColor + 1;
}
}
}
/// <summary>
/// 获取字体文字
/// </summary>
/// <returns>图形 为更改大小的图形</returns>
private Bitmap GetFontBitmap(byte[] p_Value)
{
byte _Format = p_Value[0]; //格式 4 LaserJet系列(光栅) 10 * Intellifont可伸缩 15 *可扩展的TrueType
byte _Continuation = p_Value[1]; //是否续传
byte _DescriptorSize = p_Value[2]; //固定为14
byte _Class = p_Value[3]; //1点阵图 2压缩位图 3 *轮廓(Intellifont可伸缩) 4 *复合轮廓(Intellifont可伸缩) 15 *可扩展的TrueType
byte _Orientation = p_Value[4]; //字符方向
short _LeftOffset = (short)(p_Value[6] << 8 | p_Value[7]);
short _TopOffset = (short)(p_Value[8] << 8 | p_Value[9]);
short _CharacterWidth = (short)(p_Value[10] << 8 | p_Value[11]);
short _CharacterHeight = (short)(p_Value[12] << 8 | p_Value[13]);
short _DeltaX = (short)(p_Value[14] << 8 | p_Value[15]);
Bitmap _Bitmap = new Bitmap(_CharacterWidth, _CharacterHeight, PixelFormat.Format1bppIndexed);
byte[] _TagAttribBytes = new byte[16];
Array.Copy(p_Value, _TagAttribBytes, 16);
_Bitmap.Tag = _TagAttribBytes;
BitmapData _Data = _Bitmap.LockBits(new Rectangle(0, 0, _CharacterWidth, _CharacterHeight), ImageLockMode.ReadWrite, _Bitmap.PixelFormat);
byte[] _WriteBytes = new byte[_Data.Stride * _Data.Height];
int _WriteCount = (p_Value.Length - 16) / _CharacterHeight;
for (int i = 0; i != _CharacterHeight; i++)
{
Array.Copy(p_Value, 16 + (i * _WriteCount), _WriteBytes, i * _Data.Stride, _WriteCount);
}
Marshal.Copy(_WriteBytes, 0, _Data.Scan0, _WriteBytes.Length);
_Bitmap.UnlockBits(_Data);
return _Bitmap;
}
/// <summary>
/// 获取TRUE TYPE FONT字体图形
/// </summary>
/// <param name="p_Value">数据结构</param>
/// <param name="p_TTF">TTF的类</param>
/// <returns>图形</returns>
private Bitmap GetFontBitmap(byte[] p_Value, Hashtable p_FontTable)
{
Bitmap _ReturnImage = null;
byte _Format = p_Value[0];
byte _Continuation = p_Value[1];
if (_Continuation == 1)
{
throw new Exception("临时");
}
else
{
byte _DescriptorSize = p_Value[2];
byte _Class = p_Value[3];
int _ReadIndex = 4;
ImageTTF _TTF = ((ImageTTF)p_FontTable["FontData"]);
_TTF.Brush = new SolidBrush(m_Buffer.PCL_ForegroundColor);
while (_ReadIndex < p_Value.Length - _DescriptorSize)
{
ushort _CharacterDataSize = (ushort)(p_Value[_ReadIndex] << 8 | p_Value[_ReadIndex + 1]);
_ReadIndex += 2;
ushort _GlyphID = (ushort)(p_Value[_ReadIndex] << 8 | p_Value[_ReadIndex + 1]);
_ReadIndex += 2;
if (_CharacterDataSize != 4)
{
byte[] _NewBytes = new byte[p_Value.Length - _ReadIndex];
Array.Copy(p_Value, _ReadIndex, _NewBytes, 0, _NewBytes.Length);
_ReturnImage = (Bitmap)_TTF.GetImageOfBytes(_NewBytes);
((int[])_ReturnImage.Tag)[4] = _TTF.GetAdvanceWidthOfGrlyID(_GlyphID);
break;
}
else
{
_ReturnImage = new Bitmap(1, 1);
_ReturnImage.Tag = new int[] { 0, 0, 0, 0, _TTF.GetAdvanceWidthOfGrlyID(_GlyphID), 0 };
break;
}
}
}
return _ReturnImage;
}
/// <summary>
/// 开始绘制文字
/// </summary>
/// <param name="p_FileBytes"></param>
/// <returns></returns>
private int GetPrintText(byte[] p_FileBytes)
{
int _ReturnCount = 0;
for (int i = m_ReadIndex; i != p_FileBytes.Length; i++)
{
if (p_FileBytes[i] == 0x1B) break;
if (p_FileBytes[i] == 0x0D && p_FileBytes[i + 1] == 0x1B) break;
if (p_FileBytes[i] == 0x0C && p_FileBytes[i + 1] == 0x1B)
{
break;
}
_ReturnCount++;
}
if (_ReturnCount != 0)
{
if (m_Buffer.PCL_SelectFontID == -1)
{
#region 自带的TRUE TYPE 文字绘制
if (m_Buffer.m_TrueTypeFont.ContainsKey(m_Buffer.PCL_TypefaceFamily))
{
decimal _WidthMove = 0; //绘制后移动的行
ImageTTF _TTF = m_Buffer.m_TrueTypeFont[m_Buffer.PCL_TypefaceFamily];
_TTF.Brush = new SolidBrush(m_Buffer.PCL_ForegroundColor);
string _PrintText = System.Text.Encoding.GetEncoding("windows-1258").GetString(p_FileBytes, m_ReadIndex, _ReturnCount);
for (int i = 0; i != _ReturnCount; i++)
{
Image _Image = _TTF[_PrintText[i]];
if (_Image != null)
{
DrawTrueFont(_Image, ref _WidthMove);
_Image.Dispose();
}
else
{
_WidthMove += (decimal)(_TTF.GetAdvanceWidthOfChar(_PrintText[i])) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M;
}
}
}
#endregion
}
else
{
decimal _WidthMove = 0; //绘制后移动的行
for (int i = 0; i != _ReturnCount; i++)
{
if (m_Buffer.m_FontBitmapTable.ContainsKey(m_Buffer.PCL_SelectFontID.ToString() + "," + p_FileBytes[i + m_ReadIndex].ToString()))
{
object _PrintBitmap = m_Buffer.m_FontBitmapTable[m_Buffer.PCL_SelectFontID.ToString() + "," + p_FileBytes[i + m_ReadIndex]];
if (_PrintBitmap is Bitmap) DrawBitmapFont((Image)_PrintBitmap);
if (_PrintBitmap is object[])
{
byte[] _ValueBytes = (byte[])((object[])_PrintBitmap)[1];
Hashtable _ValueHashTalbe = (Hashtable)((object[])_PrintBitmap)[0];
DrawTrueFont(GetFontBitmap(_ValueBytes, _ValueHashTalbe), ref _WidthMove);
}
}
else
{
System.Windows.Forms.MessageBox.Show(m_ReadIndex.ToString());
}
}
}
}
return _ReturnCount;
}
/// <summary>
/// 获取命令行的中间数字
/// </summary>
/// <param name="p_Command">命令行</param>
/// <param name="p_Start">开始位置</param>
/// <returns>字符类型的命令行</returns>
private int GetCommandEndIndex(byte[] p_Command, int p_Start)
{
int _Count = 0;
for (int i = p_Start; i != p_Command.Length; i++)
{
if (p_Command[i] >= 0x30 && p_Command[i] <= 0x39 || p_Command[i] == 0x2E)
{
_Count++;
}
else
{
break;
}
}
return _Count;
}
/// <summary>
/// 绘制TrueType文字到接
/// </summary>
/// <param name="p_Image"></param>
/// <param name="p_WidthMove"></param>
private void DrawTrueFont(Image p_Image, ref decimal p_WidthMove)
{
int[] _DrawPoint = (int[])p_Image.Tag;
decimal _DrawX = (decimal)(m_Buffer.PCL_HorizontalCursorPositioning) / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _DrawY = (decimal)(m_Buffer.PCL_VerticalCursorPositioning) / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _DrawWidth = (decimal)(p_Image.Width) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M;
decimal _DrawHeight = (decimal)(p_Image.Height) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M; //这里缩方后 位置不一定正确 等待更好的计算方式
decimal _TopOffset = (decimal)(_DrawPoint[1] + p_Image.Height) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M;
_DrawY -= (int)_TopOffset;
int _Width = (int)(_DrawWidth);
int _Height = (int)(_DrawHeight);
decimal _LeftPoint = (decimal)(_DrawPoint[0]) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M;
int _X = (int)(_DrawX + _LeftPoint);
int _Y = (int)_DrawY;
m_Buffer.m_Graphics.DrawImage(p_Image, new Rectangle(_X + (int)p_WidthMove, _Y, _Width, _Height));
p_WidthMove += (decimal)(_DrawPoint[4]) / 1454.33M * (decimal)m_Buffer.PCL_FontHeight * 1.5M;
}
/// <summary>
/// 绘制图形文字
/// </summary>
/// <param name="p_Image"></param>
private void DrawBitmapFont(Image p_Image)
{
#region 获取颜色和图形
byte[] _TagAttrib = (byte[])p_Image.Tag;
ColorPalette _Palette = p_Image.Palette;
_Palette.Entries[0] = m_Buffer.PCL_SourceTransparencyMode == 0 ? Color.FromArgb(0, m_Buffer.m_ColorPalette[0].R, m_Buffer.m_ColorPalette[0].G, m_Buffer.m_ColorPalette[0].B) : m_Buffer.m_ColorPalette[0];
_Palette.Entries[1] = m_Buffer.PCL_ForegroundColor;
p_Image.Palette = _Palette;
#endregion
short _LeftOffset = (short)(_TagAttrib[6] << 8 | _TagAttrib[7]);
short _TopOffset = (short)(_TagAttrib[8] << 8 | _TagAttrib[9]);
decimal _DeltaX = (decimal)(_TagAttrib[14] << 8 | _TagAttrib[15]) / 4;
decimal _DrawX = (decimal)(m_Buffer.PCL_HorizontalCursorPositioning + _LeftOffset) / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _DrawY = (decimal)(m_Buffer.PCL_VerticalCursorPositioning - _TopOffset) / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _DrawWidth = (decimal)p_Image.Width / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
decimal _DrawHeight = (decimal)p_Image.Height / (decimal)m_Buffer.PCL_UnitOfMeasure * 150;
int _Width = (int)(_DrawWidth + 0.511111111M); //这里缩方后 位置不一定正确 等待更好的计算方式
int _Height = (int)(_DrawHeight + 0.511111111M);
int _X = (int)(_DrawX + 1);
int _Y = (int)(_DrawY + _DrawHeight + 0.511111111M) - _Height;
m_Buffer.m_Graphics.DrawImage(p_Image, new Rectangle(_X, _Y, _Width, _Height));
m_Buffer.PCL_HorizontalCursorPositioning += (int)_DeltaX;
}
#endregion
}
#endregion
#region 缓冲区
private class PrintBuffer
{
#region 私有变量
/// <summary>
/// 打印出的图形
/// </summary>
public Bitmap m_PrintBitmap;
/// <summary>
/// 光删图形
/// </summary>
public Bitmap m_GraphicsBitmap;
/// <summary>
/// 光删图形的行
/// </summary>
public int m_GraphicsRowIndex = 0;
/// <summary>
/// 光删图形的行数据
/// </summary>
public byte[] m_OldBytes = new byte[0];
/// <summary>
/// 显示的刷子
/// </summary>
public Graphics m_Graphics;
/// <summary>
/// TrueTypeFont
/// </summary>
public Dictionary<int, ImageTTF> m_TrueTypeFont = new Dictionary<int, ImageTTF>();
/// <summary>
/// 颜色列表
/// </summary>
public Dictionary<int, Color> m_ColorPalette = new Dictionary<int, Color>();
/// <summary>
/// 字符表
/// </summary>
public Dictionary<string, object> m_FontBitmapTable = new Dictionary<string, object>();
#endregion
#region PCL用缓冲区
/// <summary>
/// 光栅图形分辨率 DPI
/// </summary>
public int PCL_RasterGraphicsResolution = 0;
/// <summary>
/// 0纵向 1横向 2逆纵向 3逆横向
/// </summary>
public int PCL_PageOrientation = 0;
/// <summary>
/// 顶部距离
/// </summary>
public int PCL_TopMargin = 0;
/// <summary>
/// X
/// </summary>
public int PCL_HorizontalCursorPositioning = 0;
/// <summary>
/// Y
/// </summary>
public int PCL_VerticalCursorPositioning = 0;
/// <summary>
/// 设置相框安克波因特
/// </summary>
public int PCL_SetPictureFrameAnchorPoint = 0;
/// <summary>
/// 横向尺寸
/// </summary>
public int PCL_VerticalSize = 0;
/// <summary>
/// 垂直尺寸
/// </summary>
public int PCL_HorizontalSize = 0;
/// <summary>
/// 0 - 在当前的打印方向,打印的图像。3 - 图像沿物理页面宽度打印
/// </summary>
public int PCL_RasterGraphicsPresentationMode = 0;
/// <summary>
/// 压缩方式 0 - Unencoded (default) 1 - Run-length encoding 2 - Tagged Image File Format (TIFF) revision 4.0 3 - Delta Row 5 - Adaptive Compression
/// </summary>
public int PCL_CompressionMethod = 0;
/// <summary>
/// 来源透明方式 0透明 1不透明
/// </summary>
public int PCL_SourceTransparencyMode = 0;
/// <summary>
/// 来源透明方式 0透明 1不透明
/// </summary>
public int PCL_PatternTransparencyMode = 0;
/// <summary>
/// 逻辑运算
/// </summary>
public int PCL_LogicalOperation = 0;
/// <summary>
/// 配置图像数据
/// </summary>
public byte[] PCL_ConfigureImageData = new byte[0];
/// <summary>
/// 颜色Red
/// </summary>
public int PCL_ColorComponentOne = 0;
/// <summary>
/// 颜色Green
/// </summary>
public int PCL_ColorComponentTwo = 0;
/// <summary>
/// 颜色Blue
/// </summary>
public int PCL_ColorComponentThree = 0;
/// <summary>
/// 设置颜色索引
/// </summary>
public int PCL_AssignColorIndex = 0;
/// <summary>
/// 渲染算法
/// </summary>
public int PCL_RenderAlgorithm = 0;
/// <summary>
/// 前景色
/// </summary>
public Color PCL_ForegroundColor = Color.Black;
/// <summary>
/// 选择当前模式 0 - 纯黑色(默认)1 - 纯白色 2 - 底纹图案 3 - 跨孵化模式 4 - 用户定义模式
/// </summary>
public int PCL_SelectCurrentPattern = 0;
/// <summary>
/// 图形原始宽
/// </summary>
public int PCL_SourceRasterWidth = 0;
/// <summary>
/// 图形原始高
/// </summary>
public int PCL_SourceRasterHeight = 0;
/// <summary>
/// 图形目的宽
/// </summary>
public int PCL_DestinationRasterWidth = 0;
/// <summary>
/// 图形目的高
/// </summary>
public int PCL_DestinationRasterHeight = 0;
/// <summary>
/// 开始光栅图形
/// </summary>
public int PCL_StartRasterGraphics = 0;
/// <summary>
/// 光栅图形行数据
/// </summary>
public byte[] PCL_TransferRasterDatabyRow = new byte[0];
/// <summary>
/// 字体ID
/// </summary>
public int PCL_FontID = 0;
/// <summary>
/// 图片文字的编号
/// </summary>
public int PCL_CharacterCode = 0;
/// <summary>
/// 计量单位 DPI
/// </summary>
public int PCL_UnitOfMeasure = 0;
/// <summary>
/// 单纯/双面打印 0-单 1-双面长 2-双面短
/// </summary>
public int PCL_SimplexDuplexPrint = 0;
/// <summary>
/// 纸张类型
/// </summary>
public string PCL_AlphanumericID = "";
/// <summary>
/// 纸张来源
/// </summary>
public int PCL_PaperSource = 0;
/// <summary>
/// 垂直运动指数 ?
/// </summary>
public int PCL_VerticalMotionIndex = 0;
/// <summary>
/// 打印分数
/// </summary>
public int PCL_NumberofCopies = 0;
/// <summary>
/// 调色板控件ID
/// </summary>
public int PCL_PaletteControlID = 0;
/// <summary>
/// 选择调色板
/// </summary>
public int PCL_SelectPalette = 0;
/// <summary>
/// 调色板控制
/// </summary>
public int PCL_PaletteControl = 0;
/// <summary>
/// 调色板控制
/// </summary>
public int PCL_Underline = 0;
/// <summary>
/// 纸张大小
/// 1 - Executive (7.25" x 10.5")
/// 2 - Letter (8.5" x 11")
/// 3 - Legal (8.5" x 14")
/// 6 - Ledger (11" x 17")
/// 25 - A5 paper (148mm x 210mm)
/// 26 - A4 paper (210mm x 297mm)
/// 27 - A3 (297mm x 420mm)
/// 45 - JIS B5 paper (182mm x 257mm)
/// 46 - JIS B4 paper (250mm x 354mm)
/// 71 - Hagaki postcard (100mm x 148mm)
/// 72 - Oufuku-Hagaki postcard (200mm x 148mm)
/// 80 - Monarch Envelope (3 7/8" x 7 1/2")
/// 81 - Commercial Envelope 10 (4 1/8" x 9 1/2")
/// 90 - International DL (110mm x 220mm)
/// 91 - International C5 (162mm x 229mm)
/// 100 - International B5 (176mm x 250mm)
/// 101 - Custom (size varies with printer)
/// </summary>
public int PCL_PageSize = 0;
/// <summary>
/// 字体头命令
/// </summary>
public Dictionary<int, object> PCL_FontHeaderCommand = new Dictionary<int, object>();
/// <summary>
/// 字体图片
/// </summary>
public byte[] PCL_CharacterDefinitionCommand = new byte[0];
/// <summary>
/// 字体大小
/// </summary>
public float PCL_FontHeight = 0.0f;
/// <summary>
/// 使用字体的编号
/// </summary>
public int PCL_SelectFontID = 0;
/// <summary>
/// 字体系列命令 0 Line Printer
/// 16602 Arial
/// 4168 Antique Olive
/// 4127 ITC Avant Garde
/// 4119 CG Century Schoolbook
/// 4101 CG Times
/// 4148 Univers
/// </summary>
public int PCL_TypefaceFamily = 0;
/// <summary>
/// 字体颜色 黑呀 超级黑啊 粗啊 什么的
/// </summary>
public int PCL_StrokeWeight = 0;
/// <summary>
/// 样式
/// </summary>
public int PCL_Style = 0;
/// <summary>
/// 字体间距
/// </summary>
public int PCL_Spacing = 0;
public byte[] PCL_UnData1 = new byte[0];
public int PCL_UnData2 = 0;
public int PCL_UnData3 = 0;
#endregion
#region HPGL缓冲区
/// <summary>
/// HPGL模式 1 为HPGL/2模式
/// </summary>
public int HPGL_Mode = 0;
/// <summary>
/// 透明模式 0关闭
/// </summary>
public int HPGL_TransparencyMode = 0;
/// <summary>
/// 笔宽度单元选择 0毫米单位 1为百分比
/// </summary>
public int HPGL_PenWidthUnitSelection = 0;
/// <summary>
/// 笔的宽
/// </summary>
public decimal HPGL_PenWidth = 0;
/// <summary>
/// 线类型
/// </summary>
public string HPGL_LineType = "";
/// <summary>
/// 线的属性
/// </summary>
public string HPGL_LineAttributes = "";
/// <summary>
/// 笔号 这个可能要把笔保存起来
/// </summary>
public string HPGL_NumberOfPen = "";
/// <summary>
/// 笔的颜色
/// </summary>
public Dictionary<int, Color> HPGL_PenColorAssignment = new Dictionary<int, Color>();
/// <summary>
/// 相素的表示方式
/// </summary>
public string HPGL_PixelPlacement = "";
/// <summary>
/// 填充模式
/// </summary>
public string HPGL_FillType = "";
/// <summary>
/// 设置笔
/// </summary>
public string HPGL_SelectPen = "";
/// <summary>
/// 设置输入框 显示的区域
/// </summary>
public string HPGL_InputWindow = "";
/// <summary>
/// 抬起笔到指定位置
/// </summary>
public decimal HPGL_PointStartX = 0;
/// <summary>
/// 抬起笔到指定位置
/// </summary>
public decimal HPGL_PointStartY = 0;
/// <summary>
/// 相对距离
/// </summary>
public decimal HPGL_PointEndX = 0;
/// <summary>
/// 相对距离
/// </summary>
public decimal HPGL_PointEndY = 0;
/// <summary>
/// 合并控制
/// </summary>
public string HPGL_MergeControl = "";
/// <summary>
/// 情节绝对
/// </summary>
public string HPGL_PlotAbsolute = "";
/// <summary>
/// 多边形类型
/// </summary>
public string HPGL_PolygonModel = "";
/// <summary>
/// 落笔的位置
/// </summary>
public IList<Point> HPGL_PenDown = new List<Point>();
/// <summary>
/// 212
/// </summary>
public string HPGL_InputRelative = "";
/// <summary>
/// 308
/// </summary>
public string HPGL_Scale = "";
#endregion
}
#endregion
#region 标签
/// <summary>
/// PCL标签类
/// </summary>
private class PCLInfo : Attribute
{
private string m_TitleCommand1 = "";
public string TitleCommand1 { get { return m_TitleCommand1; } set { m_TitleCommand1 = value; } }
private string m_TitleCommand2 = "";
public string TitleCommand2 { get { return m_TitleCommand2; } set { m_TitleCommand2 = value; } }
}
#endregion
}
}