Commit 544e7858 by 李定达

1.添加标签打印相关

parent f02d7b7b
Debug/
*.opensdf
*.ipch
fmposdll.sdf
fmposdll.suo
fmposdll.vcxproj.user
#include "StdAfx.h"
#include "LoadDll.h"
#define RESULT -1
#define LENTH_FMS 30
#define LENTH_FMS_80 -20
......@@ -19,6 +20,8 @@ int m_width = 0;
bool m_first;
extern int whole;
PrintClass m_printclass;
int heigth = 0;
vector<Function_Argv> m_label_args;
/***************通用函数******************/
POS_Open VC_POS_Open = NULL;
......@@ -916,6 +919,9 @@ void _GetPrintIni(char inidata[])
vector<string>::const_iterator iter;
svec = split(str_data, "|");
int i;
printf("******************%d\n", svec->size());
for (i=0,iter = svec->begin(); iter != svec->end(); ++iter,i++)
{
string ss = *iter;
......@@ -1022,6 +1028,7 @@ void _GetPrintIni(char inidata[])
if (ss.size()!=0)
{
m_printclass.printtscname = ss;
printf("******************%s\r\n", ss.c_str());
}
else
{
......@@ -1041,7 +1048,54 @@ void _GetPrintIni(char inidata[])
}
break;
}
case 10:
{
if (ss.size()!=0)
{
m_printclass.tsc_widgth = ss;
}
else
{
m_printclass.tsc_widgth = "40";
}
break;
}
case 11:
{
if (ss.size()!=0)
{
m_printclass.tsc_high = ss;
}
else
{
m_printclass.tsc_high = "30";
}
break;
}
case 12:
{
if (ss.size()!=0)
{
m_printclass.tsc_speed = ss;
}
else
{
m_printclass.tsc_speed = "3";
}
break;
}
case 13:
{
if (ss.size()!=0)
{
m_printclass.tsc_chroma = ss;
}
else
{
m_printclass.tsc_chroma = "1";
}
break;
}
default:
{
m_printclass.printname = "Driver";
......@@ -1089,6 +1143,176 @@ char* strmov(char *dest,const char *src,char ch)
return dest;
}
int InitTscPort()
{
//清空参数缓存;
m_label_args.clear();
return 1;
}
int getheigth(int y, int font_size, int high_len)
{
heigth = y + font_size;
VC_Log_WriteLog(0," %s :%d","当前打印行高 : ", heigth);
return 1;
}
int GetFout(int x, int *index, int font_size, double font_ratio, char *data, char *tmpdata)
{
int i = *index;
int len = strlen(data);
if(*index >= len)
return 0;
if(font_ratio*font_size > atoi(m_printclass.tsc_widgth.c_str())*1.0)
{
*index = len;
strcpy(tmpdata, data);
return 1;
}
if(font_ratio*font_size*2 > atoi(m_printclass.tsc_widgth.c_str())*1.0)
{
*index = len;
strcpy(tmpdata, data);
return 1;
}
double currlen = 0;
while(i < len)
{
if(i != *index && currlen > atoi(m_printclass.tsc_widgth.c_str()) - font_size * font_ratio - x*font_ratio*2*2)
{
memcpy(tmpdata, data + *index, i - *index);
*index = i;
return 1;
}
if(data[i] < 0)
{
i += 2;
currlen += font_size * 2 * font_ratio;
continue;
}
else
{
currlen += font_size * font_ratio*1.25;
++ i;
}
}
memcpy(tmpdata, data + (*index), len - (*index));
*index = len;
return 1;
}
int WinPrintlnTsc(int x, int y, int font_size, int rotate, int font_type, int high_len, int line, char *font_name, char *data, double font_ratio)
{
if(font_ratio == 0)
{
if(heigth > y + 1)
y = heigth + high_len;
Function_Argv argv = {0};
INIT_FUN_ARGV(x, y, font_size, font_type, line, font_name, data);
m_label_args.push_back(argv);
//TSC_windowsfont(x, heigth, font_size, rotate, font_type, line, font_name, data);
getheigth(y, font_size, high_len);
return 1;
}
int index = 0;
char tmp[256] = {0};
int tmpi = 0;
while(GetFout(x, &index, font_size, font_ratio, data, tmp))
{
if(heigth > y + 1)
y = heigth;
if(tmpi == 0)
{
y += high_len;
tmpi = 1;
}
Function_Argv argv = {0};
INIT_FUN_ARGV(x, y, font_size, font_type, line, font_name, tmp);
m_label_args.push_back(argv);
//TSC_windowsfont(x, heigth, font_size, rotate, font_type, line, font_name, tmp);
getheigth(y, font_size, 0);
memset(tmp, 0, 256);
}
return 1;
}
int PrintCloseTsc(char *page, char *num)
{
VC_Log_WriteLog(1," %s",m_printclass.printtscname.c_str());
char name[128]={0};
strcpy(name,m_printclass.printtscname.c_str());
VC_Log_WriteLog(0," %s","驱动名称 : ", name);
printf("驱动名称 : %s", name);
int var=TSC_openport(name);
if(1 != var )
{
VC_Log_WriteLog(1," %s","标签打印机打开失败或者标签打印机名字不对");
return 0;
}
char tmp0[20] = {0};
char tmp1[20] = {0};
char tmp2[20] = {0};
char tmp3[20] = {0};
strcpy(tmp0, m_printclass.tsc_widgth.c_str());
strcpy(tmp1, m_printclass.tsc_high.c_str());
strcpy(tmp2, m_printclass.tsc_speed.c_str());
strcpy(tmp3, m_printclass.tsc_chroma.c_str());
if(TSC_setup(tmp0, tmp1, tmp2, tmp3, "0", "3", "0") == 0)
VC_Log_WriteLog(1," %s","标签打印机设置打印区域失败");
heigth = 0;
TSC_sendcommand("DIRECTION 1");
TSC_clearbuffer();
int i = 0;
while(i < m_label_args.size())
{
char tmpfont_name[40] = {0};
char tmpdata[256] = {0};
Function_Argv argv = m_label_args[i];
//TSC_windowsfont(x, heigth, font_size, rotate, font_type, line, font_name, tmp);
strcpy(tmpfont_name, argv.font_name.c_str());
strcpy(tmpdata, argv.data.c_str());
TSC_windowsfont(argv.x, argv.y, argv.font_size, argv.rotate, argv.font_type, argv.line, tmpfont_name, tmpdata);
++ i;
}
if(TSC_printlabel("1", "1") == 0)
VC_Log_WriteLog(1," %s","标签打印标签页失败");
TSC_closeport();
heigth = 0;
return 1;
}
int string_replase(string &s1, const string &s2, const string &s3)
{
string::size_type pos = 0;
......
......@@ -116,9 +116,28 @@
#define POS_AREA_RIGHT_TO_LEFT 0x2 // 右下角
#define POS_AREA_TOP_TO_BOTTOM 0x3 // 右上角
typedef struct
{
int x;
int y;
int font_size;
int rotate;
int font_type;
int line;
string font_name;
string data;
} Function_Argv;
#define INIT_FUN_ARGV(tmpx, tmpheigth, tmpfont_size, tmpfont_type, tmpline, tmpfont_name, tmpdata) do { \
argv.x = tmpx; \
argv.y = tmpheigth; \
argv.font_size = tmpfont_size; \
argv.font_type = tmpfont_type; \
argv.line = tmpline; \
argv.font_name = string(tmpfont_name); \
argv.data = string(tmpdata); \
}while(0);
/***************通用函数*****************/
typedef HANDLE (__stdcall *POS_Open)( LPCTSTR lpName,
......@@ -334,7 +353,11 @@ typedef struct
int m_PrintSize; //打印的纸张设定
int type;
int m_nDays;
string tsc_widgth; //标签打印的宽度
string tsc_high; //标签打印的高度
string tsc_speed; //走纸速度
string tsc_chroma; //打印弄度
} PrintClass,*pPrintclass;
/****************加载和卸载动态库**************************/
bool _LoadPosdll(void);
......@@ -368,4 +391,31 @@ vector<string> *split(const string &str, const string &sep);
void deletelog(int nDays);
//标签打印导出函数;
//打开端口;
//每打印一页都要调用;
int InitTscPort();
//window打印一行;输出到放缓冲区;
//x : 打印字体的x坐标;
//y : 打印字体的y坐标;建议传0;
//font_size : 字体大小;
//rotate : 字体选择角度;
// 0 -> 0 degree
// 90-> 90 degree
// 180-> 180 degree
// 270-> 270 degree
//font_type : 0-> 标准(Normal);
// 1-> 斜体(Italic);
// 2-> 粗体(Bold);
// 3-> 粗斜体(Bold and Italic);
//high_len : 和上一行之间的距离;自动换行依然有效;
//line : 字体下放是否标注黑线;
//font_name : 字体名称;宋体微软雅黑等;
//data : 打印数据;
//font_ratio: 字体每个粒度数对应的毫米;宋体 0.0666665; 为0时不自动换行;
int WinPrintlnTsc(int x, int y, int font_size, int rotate, int font_type, int high_len, int line, char *font_name, char *data, double font_ratio);
//打印一页;触发打印;
//每打印一页都要调用;
int PrintCloseTsc(char *page, char *num);
#endif
......@@ -91,6 +91,21 @@ extern "C" int __declspec(dllexport)Add(int x, int y)
}
extern "C" int __declspec(dllexport)TSCInit()
{
return InitTscPort();
}
extern "C" int __declspec(dllexport)TSCWinPrintln(int x, int y, int font_size, int rotate, int font_type, int high_len, int line, char *font_name, char *data, double font_ratio)
{
return WinPrintlnTsc(x, y, font_size, rotate, font_type, high_len, line, font_name, data, font_ratio);
}
extern "C" int __declspec(dllexport)TSCWinPrintPage(char *page, char *num)
{
return PrintCloseTsc(page, num);
}
extern "C" void __declspec(dllexport)PrintData(char data[])
{
_InPrintData(data);
......@@ -98,7 +113,7 @@ extern "C" void __declspec(dllexport)PrintData(char data[])
extern "C" void __declspec(dllexport)Print2dData(char data[])
{
//_InPrint2dcode(data);
}
extern "C" void __declspec(dllexport)Unloaddll()
......

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmposdll", "fmposdll.vcxproj", "{A46CE5D4-D01B-CA08-372B-B0085099921E}"
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "fmposdll", "fmposdll.vcxproj", "{EFB2B16E-B687-DFD3-01DB-8BFCF807D36A}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "..\test\test.vcxproj", "{A3A3F622-F88F-47BC-9776-9B44676755DB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
......@@ -9,10 +11,14 @@ Global
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A46CE5D4-D01B-CA08-372B-B0085099921E}.Debug|Win32.ActiveCfg = Debug|Win32
{A46CE5D4-D01B-CA08-372B-B0085099921E}.Debug|Win32.Build.0 = Debug|Win32
{A46CE5D4-D01B-CA08-372B-B0085099921E}.Release|Win32.ActiveCfg = Release|Win32
{A46CE5D4-D01B-CA08-372B-B0085099921E}.Release|Win32.Build.0 = Release|Win32
{EFB2B16E-B687-DFD3-01DB-8BFCF807D36A}.Debug|Win32.ActiveCfg = Debug|Win32
{EFB2B16E-B687-DFD3-01DB-8BFCF807D36A}.Debug|Win32.Build.0 = Debug|Win32
{EFB2B16E-B687-DFD3-01DB-8BFCF807D36A}.Release|Win32.ActiveCfg = Release|Win32
{EFB2B16E-B687-DFD3-01DB-8BFCF807D36A}.Release|Win32.Build.0 = Release|Win32
{A3A3F622-F88F-47BC-9776-9B44676755DB}.Debug|Win32.ActiveCfg = Debug|Win32
{A3A3F622-F88F-47BC-9776-9B44676755DB}.Debug|Win32.Build.0 = Debug|Win32
{A3A3F622-F88F-47BC-9776-9B44676755DB}.Release|Win32.ActiveCfg = Release|Win32
{A3A3F622-F88F-47BC-9776-9B44676755DB}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
......@@ -11,4 +11,6 @@ EXPORTS
PrintBarCode @9
PrintQRCode @10
FreeLine @11
TSCWinPrintln @12
TSCWinPrintPage @13
TSCInit @14
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment