Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
PrtLib
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李定达
PrtLib
Commits
878caa62
Commit
878caa62
authored
Mar 12, 2019
by
李定达
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1.添加标签打印模板支持;未做详细测试;
parent
d8f2680b
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
277 additions
and
9 deletions
+277
-9
PrtLib/PrtLib.suo
+0
-0
PrtLib/PrtLib/PrintLib.cpp
+202
-5
PrtLib/PrtLib/PrintLib.h
+37
-0
PrtLib/PrtLib/printDll.cpp
+8
-0
PrtLib/PrtLib/prtlib.cpp
+15
-1
PrtLib/PrtLib/prtlib.def
+1
-0
PrtLib/PrtLib/prtlib.h
+2
-1
PrtLib/PrtLib/test.cpp
+12
-2
No files found.
PrtLib/PrtLib.suo
View file @
878caa62
No preview for this file type
PrtLib/PrtLib/PrintLib.cpp
View file @
878caa62
...
...
@@ -53,6 +53,63 @@ PrintLib::PrintLib(void)
//m_b_load_sucfl = LoadAddress();
}
void
PrintLib
::
_LabPrintLine
(
rapidxml
::
xml_node
<>
*
node
,
rapidjson
::
Document
&
jsonDoc
,
rapidjson
::
Value
&
childNode
)
{
LabLinePrintArguments
lineArg
=
_LabParsePrintArgumnets
(
node
);
//属性值解析
//解析xml中math,获取信息
xml_node
<>
*
mathNode
=
node
->
first_node
();
while
(
mathNode
!=
NULL
)
{
std
::
string
formatRule
;
std
::
vector
<
std
::
string
>
mathVariablVec
;
MathArguments
mathArg
=
_ParseMathArgumnets
(
mathNode
);
bool
isMath
=
false
;
Calculator
::
SplitMath
(
mathArg
.
mathContent
,
mathVariablVec
,
formatRule
,
isMath
);
xml_attribute
<>*
attr
=
mathNode
->
first_attribute
(
"index"
);
std
::
string
mathIndex
=
attr
->
value
();
if
(
!
isMath
){
//从json document中查找到content中的字段信息
std
::
string
field_value
=
_GetMathValue
(
jsonDoc
,
mathArg
.
mathContent
,
childNode
);
_ReplaceText
(
mathArg
,
field_value
,
lineArg
.
text
,
mathIndex
);
//替换lineArg中的text字段
}
else
{
//math 中含有数学表达式
int
paraSize
=
mathVariablVec
.
size
();
int
itr
=
0
;
for
(
int
i
=
0
;
i
<
paraSize
;
i
++
){
std
::
string
index
=
"%"
;
char
buffer
[
8
];
sprintf
(
buffer
,
"%d"
,
i
+
1
);
index
=
index
+
buffer
;
//类似%1,%2
std
::
string
key
=
mathVariablVec
[
i
];
int
nNum
=
0
;
int
nret
=
sscanf
(
key
.
c_str
(),
"%d"
,
&
nNum
);
if
(
0
!=
nret
){
int
nPos
=
formatRule
.
find
(
index
);
if
(
nPos
!=
std
::
string
::
npos
)
{
formatRule
.
replace
(
nPos
,
2
,
key
);
}
continue
;
}
//从json childNode中查找到content中的字段信息
std
::
string
field_value
=
_GetMathValue
(
jsonDoc
,
key
,
childNode
);
_ReplaceText
(
mathArg
,
field_value
,
formatRule
,
buffer
);
}
formatRule
.
insert
(
0
,
"("
);
formatRule
.
append
(
")"
);
double
result
=
Calculator
::
parenth_final
(
formatRule
.
c_str
());
std
::
string
temp
=
std
::
to_string
(
static_cast
<
long
double
>
(
result
));
std
::
string
placeHold
=
"%"
+
mathIndex
;
int
mathPos
=
lineArg
.
text
.
find
(
placeHold
);
if
(
mathPos
!=
std
::
string
::
npos
)
{
lineArg
.
text
.
replace
(
mathPos
,
2
,
temp
);
}
}
mathNode
=
mathNode
->
next_sibling
();
}
_LabPrintData
(
lineArg
);
}
void
PrintLib
::
_PrintLine
(
rapidxml
::
xml_node
<>
*
node
,
rapidjson
::
Document
&
jsonDoc
,
rapidjson
::
Value
&
childNode
)
{
LinePrintArguments
lineArg
=
_ParsePrintArgumnets
(
node
);
//属性值解析
...
...
@@ -186,6 +243,32 @@ PrintLib& PrintLib::GetInstance()
return
fp
;
}
bool
PrintLib
::
_LabPrintOrder
(
rapidxml
::
xml_node
<>
*
xmlNode
,
rapidjson
::
Document
&
doc
)
{
rapidxml
::
xml_node
<>
*
node
;
node
=
xmlNode
->
first_node
();
//循环解析xml
for
(;
node
!=
NULL
;
node
=
node
->
next_sibling
())
{
rapidxml
::
xml_node
<>
*
childMath
=
node
->
first_node
();
//<math
if
(
childMath
==
NULL
)
continue
;
std
::
string
nodeName
=
node
->
name
();
LOG
()
<<
"_LabPrintOrder::node->name : "
<<
node
->
name
();
rapidjson
::
Value
paraValue
;
if
(
nodeName
.
compare
(
"line"
)
==
0
)
{
_LabPrintLine
(
node
,
doc
,
paraValue
);
}
}
return
true
;
}
bool
PrintLib
::
_PrintOrder
(
rapidxml
::
xml_node
<>
*
xmlNode
,
rapidjson
::
Document
&
doc
)
{
rapidxml
::
xml_node
<>
*
node
;
...
...
@@ -216,7 +299,7 @@ bool PrintLib::_PrintDoc( int typeCode,rapidxml::xml_node<> * xmlNode,rapidjson:
return
_PrintOrder
(
xmlNode
,
doc
);
break
;
case
2
:
//return _PrintLab(e,json,error
);
return
_LabPrintOrder
(
xmlNode
,
doc
);
break
;
default
:
return
_PrintOrder
(
xmlNode
,
doc
);
...
...
@@ -225,6 +308,46 @@ bool PrintLib::_PrintDoc( int typeCode,rapidxml::xml_node<> * xmlNode,rapidjson:
return
true
;
}
bool
PrintLib
::
DoLabPrint
(
std
::
string
prtStr
,
std
::
string
orderStr
,
std
::
string
xmlStr
,
std
::
string
&
error
)
{
LOG
()
<<
"Printer Config Info:"
<<
prtStr
;
LOG
()
<<
"Order Info:"
<<
orderStr
;
LOG
()
<<
"XML Info:"
<<
xmlStr
;
char
prtjson
[
1024
]
=
{
0
};
memcpy
(
prtjson
,
prtStr
.
c_str
(),
prtStr
.
size
());
if
(
!
LabPrtOpen
(
prtjson
)){
f_ClosePrinter
(
2
);
error
=
"LabPrtOpen failed"
;
LOG
()
<<
"LabPrtOpen failed"
;
return
false
;
}
Document
dJson
;
int
intType
=
2
;
if
(
_ParseJson
(
orderStr
,
dJson
))
{
stringstream
stm
;
stm
<<
xmlStr
;
file
<>
fdoc
(
stm
);
xml_document
<>
doc
;
doc
.
parse
<
0
>
(
fdoc
.
data
());
xml_node
<>*
rootTicket
=
doc
.
first_node
();
xml_attribute
<>*
p
=
rootTicket
->
first_attribute
(
"typeCode"
);
intType
=
strtol
(
p
->
value
(),
NULL
,
10
);
_PrintDoc
(
intType
,
rootTicket
,
dJson
);
}
else
{
LOG
()
<<
"_ParseJson failed"
;
}
f_ClosePrinter
(
intType
);
return
true
;
}
bool
PrintLib
::
DoPrint
(
std
::
string
prtStr
,
std
::
string
orderStr
,
std
::
string
xmlStr
,
std
::
string
&
error
)
{
LOG
()
<<
"Printer Config Info:"
<<
prtStr
;
...
...
@@ -244,7 +367,7 @@ bool PrintLib::DoPrint(std::string prtStr, std::string orderStr, std::string xml
memcpy
(
prtjson
,
prtStr
.
c_str
(),
prtStr
.
size
());
if
(
!
f_OpenPrinter
(
prtjson
)){
f_ClosePrinter
();
f_ClosePrinter
(
1
);
error
=
"OpenPrinter failed"
;
LOG
()
<<
"OpenPrinter failed"
;
return
false
;
...
...
@@ -252,6 +375,7 @@ bool PrintLib::DoPrint(std::string prtStr, std::string orderStr, std::string xml
Document
dJson
;
int
intType
=
1
;
if
(
_ParseJson
(
orderStr
,
dJson
))
{
stringstream
stm
;
...
...
@@ -261,14 +385,14 @@ bool PrintLib::DoPrint(std::string prtStr, std::string orderStr, std::string xml
doc
.
parse
<
0
>
(
fdoc
.
data
());
xml_node
<>*
rootTicket
=
doc
.
first_node
();
xml_attribute
<>*
p
=
rootTicket
->
first_attribute
(
"typeCode"
);
int
int
Type
=
strtol
(
p
->
value
(),
NULL
,
10
);
intType
=
strtol
(
p
->
value
(),
NULL
,
10
);
_PrintDoc
(
intType
,
rootTicket
,
dJson
);
}
else
{
LOG
()
<<
"_ParseJson failed"
;
}
f_ClosePrinter
();
f_ClosePrinter
(
intType
);
return
true
;
}
...
...
@@ -750,6 +874,60 @@ std::string PrintLib::_GetPrintIni()
return
parseValue
;
}
LabLinePrintArguments
PrintLib
::
_LabParsePrintArgumnets
(
const
rapidxml
::
xml_node
<>*
e
)
{
LabLinePrintArguments
arguments
;
// 打印的数据
rapidxml
::
xml_attribute
<
char
>
*
attr
=
e
->
first_attribute
(
"text"
);
if
(
attr
!=
NULL
)
{
arguments
.
text
=
attr
->
value
();
}
// 打印类型
attr
=
e
->
first_attribute
(
"printType"
);
if
(
attr
!=
NULL
)
{
arguments
.
printType
=
attr
->
value
();
}
// x
attr
=
e
->
first_attribute
(
"x"
);
if
(
attr
!=
NULL
)
{
arguments
.
x
=
std
::
atoi
(
attr
->
value
());
}
else
{
arguments
.
x
=
0
;
}
// y
attr
=
e
->
first_attribute
(
"y"
);
if
(
attr
!=
NULL
)
{
arguments
.
y
=
std
::
atoi
(
attr
->
value
());
}
else
{
arguments
.
y
=
0
;
}
//line
attr
=
e
->
first_attribute
(
"wordwrap"
);
if
(
attr
!=
NULL
)
{
arguments
.
line
=
std
::
atoi
(
attr
->
value
());
}
else
{
arguments
.
line
=
0
;
}
return
arguments
;
}
LinePrintArguments
PrintLib
::
_ParsePrintArgumnets
(
const
rapidxml
::
xml_node
<>*
e
)
{
LinePrintArguments
arguments
;
...
...
@@ -910,6 +1088,25 @@ void PrintLib::_PrintData( const LinePrintArguments& arguments )
}
void
PrintLib
::
_LabPrintData
(
const
LabLinePrintArguments
&
arguments
)
{
std
::
string
text
=
arguments
.
text
;
std
::
string
printType
=
arguments
.
printType
;
int
x
=
arguments
.
x
;
int
y
=
arguments
.
y
;
int
line
=
arguments
.
line
;
char
*
temchar
=
new
char
[
2048
];
memset
(
temchar
,
0
,
2048
);
strcpy
(
temchar
,
text
.
c_str
());
if
(
!
printType
.
compare
(
"Text"
)){
//调用FMPOSDLL打印单行数据
LabPrtLine
(
x
,
y
,
line
,
temchar
)
;
}
delete
[]
temchar
;
}
//void GetProcPath(std::string &str)
//{
// int curPos;
...
...
@@ -1036,7 +1233,7 @@ bool PrintLib::_ParseJson(std::string jsonStr,rapidjson::Document &jsonDoc)
jsonDoc
.
Parse
<
0
>
(
jsonStr
.
c_str
());
if
(
jsonDoc
.
HasParseError
())
{
printf
(
"GetParseError %s
\n
"
,
jsonDoc
.
GetParseError
()
);
LOG
()
<<
"GetParseError"
<<
jsonDoc
.
GetParseError
(
);
return
false
;
}
return
true
;
...
...
PrtLib/PrtLib/PrintLib.h
View file @
878caa62
...
...
@@ -39,7 +39,19 @@ struct LinePrintArguments{
std
::
string
text
;
// 打印类型
std
::
string
printType
;
};
struct
LabLinePrintArguments
{
// x坐标
int
x
;
// y坐标
int
y
;
// 自动换行
int
line
;
// 打印的数据
std
::
string
text
;
// 打印类型
std
::
string
printType
;
};
struct
MathArguments
{
...
...
@@ -67,6 +79,8 @@ public:
//static void GetProcPath(std::string &str);
bool
DoLabPrint
(
std
::
string
prtStr
,
std
::
string
orderStr
,
std
::
string
xmlStr
,
std
::
string
&
error
);
private
:
//typedef bool ( *OpenPrint)( void);
//typedef void ( *InitPrinter)( char str[]);
...
...
@@ -124,6 +138,11 @@ private:
* */
bool
_PrintOrder
(
rapidxml
::
xml_node
<>
*
xmlNode
,
rapidjson
::
Document
&
doc
);
/* 功能:打印订单
* 参数:[1]打印模版,[2]打印内容json,[3]错误信息
* 返回:成功与否
* */
bool
_LabPrintOrder
(
rapidxml
::
xml_node
<>
*
xmlNode
,
rapidjson
::
Document
&
doc
);
/* 功能:解析打印属性表
* 参数:[1]xml element
...
...
@@ -131,6 +150,12 @@ private:
* */
LinePrintArguments
_ParsePrintArgumnets
(
const
rapidxml
::
xml_node
<>*
e
);
/* 功能:解析打印属性表
* 参数:[1]xml element
* 返回:LinePrintArguments 对象
* */
LabLinePrintArguments
_LabParsePrintArgumnets
(
const
rapidxml
::
xml_node
<>*
e
);
/* 功能:解析math属性表
* 参数:[1]xml element
* 返回:MathArguments对象
...
...
@@ -143,6 +168,12 @@ private:
* */
void
_PrintData
(
const
LinePrintArguments
&
arguments
);
/* 功能:打印数据
* 参数:[1]打印参数
* 返回:NULL
* */
void
_LabPrintData
(
const
LabLinePrintArguments
&
arguments
);
/* 功能:从json中获取某一字段的信息
* 参数:[1]jsonDoc,json document ,[2]toMatch,待匹配字符串,[3]childNode,json子串
* 返回:NULL
...
...
@@ -165,6 +196,12 @@ private:
* 参数:[1]xml模板,[2]打印内容json[3]结点数据
* 返回:NULL
* */
void
_LabPrintLine
(
rapidxml
::
xml_node
<>
*
node
,
rapidjson
::
Document
&
jsonDoc
,
rapidjson
::
Value
&
childNode
);
/* 功能:打印单行数据
* 参数:[1]xml模板,[2]打印内容json[3]结点数据
* 返回:NULL
* */
void
_PrintMultLine
(
rapidxml
::
xml_node
<>
*
node
,
rapidjson
::
Document
&
jsonDoc
,
rapidjson
::
Value
&
jsonValue
);
/* 功能:获取json的value值
* 参数:NULL
...
...
PrtLib/PrtLib/printDll.cpp
View file @
878caa62
...
...
@@ -18,3 +18,11 @@ extern "C" void __declspec(dllexport) DoPrintWithXml(char *prtStr, char *orderS
PrintLib
::
GetInstance
().
DoPrint
(
prt
,
order
,
xml
,
err
);
}
extern
"C"
void
__declspec
(
dllexport
)
DoLabPrintWithXml
(
char
*
prtStr
,
char
*
orderStr
,
char
*
xmlStr
,
char
*
error
)
{
std
::
string
prt
=
prtStr
;
std
::
string
order
=
orderStr
;
std
::
string
xml
=
xmlStr
;
std
::
string
err
=
error
;
PrintLib
::
GetInstance
().
DoLabPrint
(
prt
,
order
,
xml
,
err
);
}
PrtLib/PrtLib/prtlib.cpp
View file @
878caa62
...
...
@@ -1324,6 +1324,12 @@ int LabPrtLine(int x, int y, int line, const char *data)
int
TscPrintClose
()
{
if
(
g_info
.
dvname
.
empty
())
{
LOG
()
<<
"标签打印机名为空"
;
return
0
;
}
char
name
[
128
]
=
{
0
};
strcpy
(
name
,
g_info
.
dvname
.
c_str
());
...
...
@@ -1937,7 +1943,14 @@ bool f_OpenPrinter(char config[])
return
TRUE
;
}
void
f_ClosePrinter
()
void
f_ClosePrinter
(
int
type
)
{
if
(
type
==
2
)
{
LabPrtClose
();
}
else
{
PrtClose
();
}
}
\ No newline at end of file
PrtLib/PrtLib/prtlib.def
View file @
878caa62
...
...
@@ -13,4 +13,5 @@ EXPORTS
LabPrtClose @11
DoPrintWithXml @12
DoPrtList @13
DoLabPrintWithXml @14
PrtLib/PrtLib/prtlib.h
View file @
878caa62
...
...
@@ -64,7 +64,7 @@ bool f_LaodAddress();
bool
f_OpenPrinter
(
char
config
[]);
void
f_ClosePrinter
();
void
f_ClosePrinter
(
int
type
);
#endif
\ No newline at end of file
PrtLib/PrtLib/test.cpp
View file @
878caa62
...
...
@@ -151,6 +151,15 @@ void testPrt()
#include "PrintLib.h"
void
DoLabPrintWithXmls
(
char
*
prtStr
,
char
*
orderStr
,
char
*
xmlStr
,
char
*
error
)
{
std
::
string
prt
=
prtStr
;
std
::
string
order
=
orderStr
;
std
::
string
xml
=
xmlStr
;
std
::
string
err
=
error
;
PrintLib
::
GetInstance
().
DoLabPrint
(
prt
,
order
,
xml
,
err
);
}
void
DoPrintWithXmls
(
char
*
prtStr
,
char
*
orderStr
,
char
*
xmlStr
,
char
*
error
)
{
string
prt
=
prtStr
;
...
...
@@ -198,7 +207,8 @@ int main()
//Unloaddll();
//char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<ticket type=\"OrderPrint\" typeCode=\"1\">\n<line printType=\"Text\" text=\"0001非码测试单\" codeType=\"1\" fontType=\"1\" fontStyle=\"1\" width=\"2\" height=\"2\" leftMargin=\"0\" AlignMode=\"1\"/>\n</ticket>";
//char xmlstr[] = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ticket type = \"OrderPrint\" typeCode = \"1\"><line printType=\"Text\" text=\"%1Bulabula%2\" fontType=\"1\" fontStyle=\"1\" width=\"1\" height=\"1\" leftMargin=\"0\" AlignMode=\"0\"><math index=\"1\" content=\"order_title\" /><math index=\"2\" content=\"order_index\" /></line></ticket>";
char
conf
[]
=
"{
\"
ip
\"
:
\"
172.16.1.252
\"
,
\"
PaperWidth
\"
:
\"
56
\"
,
\"
type
\"
:3}"
;
//char conf[] = "{\"name\":\"Xprinter\",\"paperwidth\":\"56\",\"type\":3}";
char
conf
[]
=
"{
\"
name
\"
:
\"
Xprinter
\"
,
\"
high
\"
:
\"
25
\"
,
\"
labelprttype
\"
:0,
\"
type
\"
: 4,
\"
width
\"
:
\"
40
\"
}"
;
//char order[] = "{\"order_title\":\"AAAA\",\"order_index\":\"0001\"}";
char
err
[
1024
]
=
{};
...
...
@@ -211,7 +221,7 @@ int main()
GetFileBuf
(
xmlstr
,
xmlfilename
);
GetFileBuf
(
order
,
jsonfilename
);
DoPrintWithXmls
(
conf
,
order
,
xmlstr
,
err
);
Do
Lab
PrintWithXmls
(
conf
,
order
,
xmlstr
,
err
);
system
(
"pause"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment