|
|
|
|
#include "StdAfx.h"
|
|
|
|
|
#include "ObjBarCode.h"
|
|
|
|
|
#include "GlobalFunction.h"
|
|
|
|
|
#include "LogMgr.h"
|
|
|
|
|
#ifdef __TBAR_CODE__
|
|
|
|
|
#include "tbarcode51.h"
|
|
|
|
|
#endif
|
|
|
|
|
#include "ObjPline.h"
|
|
|
|
|
#include "FontTypeMgr.h"
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>-- <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void PrintResult(vector<vector<CBarCodeModule>> &ModuleVec)
|
|
|
|
|
{
|
|
|
|
|
ofstream *pStream = gLogMgr->GetDebugOfstream();
|
|
|
|
|
vector<vector<CBarCodeModule>>::iterator iter = ModuleVec.begin();
|
|
|
|
|
vector<vector<CBarCodeModule>>::iterator iter_end = ModuleVec.end();
|
|
|
|
|
for(;iter!=iter_end;iter++)
|
|
|
|
|
{
|
|
|
|
|
vector<CBarCodeModule>::iterator iter1 = (*iter).begin();
|
|
|
|
|
vector<CBarCodeModule>::iterator iter1_end = (*iter).end();
|
|
|
|
|
for(;iter1!=iter1_end;iter1++)
|
|
|
|
|
{
|
|
|
|
|
(*pStream)<<(*iter1).IsBlack();
|
|
|
|
|
}
|
|
|
|
|
(*pStream)<<endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CObjBarCode::CObjBarCode(void)
|
|
|
|
|
{
|
|
|
|
|
m_ModuleW = 1;
|
|
|
|
|
m_ModuleH = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CObjBarCode::~CObjBarCode(void)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
CObjBarCode::CObjBarCode(CObjBarCode &rhs)
|
|
|
|
|
:CObjString(rhs)
|
|
|
|
|
{
|
|
|
|
|
CreatExt();
|
|
|
|
|
}
|
|
|
|
|
CString CObjBarCode::GetStr()
|
|
|
|
|
{
|
|
|
|
|
CString str = "<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD>ı<EFBFBD>
|
|
|
|
|
CString CObjBarCode::GetCurString()
|
|
|
|
|
{
|
|
|
|
|
//<2F>ɱ<EFBFBD><C9B1>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_ValStr.UpdateValStr();
|
|
|
|
|
return m_ValStr.GetString();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><F3B6A8B5>Ի<EFBFBD><D4BB><EFBFBD>
|
|
|
|
|
void CObjBarCode::BindingDlg()
|
|
|
|
|
{
|
|
|
|
|
#ifdef __DLG_PANE_VAR_STRING__
|
|
|
|
|
GetFrame()->m_DlgVariableString.BindingObjString(this);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
void CObjBarCode::CreatExt()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
m_ObjContainer.Clear();
|
|
|
|
|
//<2F><>ȡ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|
|
|
|
CString Str = GetCurString();
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CreatBarCodeEdge(Str,m_BasePt1,m_ObjContainer);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 1
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CObjBarCode::CreatBarCodeEdge(CString Str,Dbxy BasePt,CObjContainer &ObjContainer)
|
|
|
|
|
{
|
|
|
|
|
#ifdef __DLG_PANE_TEST__
|
|
|
|
|
#ifdef __TBAR_CODE__
|
|
|
|
|
m_BasePt = BasePt;
|
|
|
|
|
CTbarcode51 &Tbarcode51 = GetFrame()->m_DlgTest.GetTbarcode51();
|
|
|
|
|
|
|
|
|
|
vector<vector<CBarCodeModule>> ModuleVec;
|
|
|
|
|
CFontTypeMgr &pFontTypeMgr = CFontTypeMgr::Instance();
|
|
|
|
|
int idx = pFontTypeMgr.GetCurFontTypeIdx();
|
|
|
|
|
gLogMgr->WriteDebugLog("idx", "=", idx);
|
|
|
|
|
Tbarcode51.put_BarCode(pFontTypeMgr.GetCurFontTypeIdx());//<2F><><EFBFBD><EFBFBD>
|
|
|
|
|
Tbarcode51.put_Text(Str);//text <20><><EFBFBD><EFBFBD>
|
|
|
|
|
Tbarcode51.BCDraw((long)GetCurViewPtr()->GetHDC(),0,0,0,200);//<2F><>view <20>ϻ<EFBFBD><CFBB>Ƴ<EFBFBD><C6B3><EFBFBD>
|
|
|
|
|
if(AnlalysisBarCord(ModuleVec))
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ObjContainer
|
|
|
|
|
CreatEdge(ModuleVec,ObjContainer);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>뱣<EFBFBD>浽<EFBFBD><E6B5BD><EFBFBD><EFBFBD>ModuleVec
|
|
|
|
|
bool CObjBarCode::AnlalysisBarCord(vector<vector<CBarCodeModule>> &ModuleVec)
|
|
|
|
|
{
|
|
|
|
|
int Rows = 0;
|
|
|
|
|
#ifdef __DLG_PANE_TEST__
|
|
|
|
|
#ifdef __TBAR_CODE__
|
|
|
|
|
CTbarcode51 &Tbarcode51 = GetFrame()->m_DlgTest.GetTbarcode51();
|
|
|
|
|
//<2F>ȶ<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
|
|
|
|
|
Rows = Tbarcode51.get_CountRows();
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
ofstream *pStream = gLogMgr->GetDebugOfstream();
|
|
|
|
|
(*pStream)<<"[Rows] = "<<Rows<<endl;
|
|
|
|
|
if(Rows<1)
|
|
|
|
|
{
|
|
|
|
|
(*pStream)<<"[<5B><><EFBFBD>ɴ<EFBFBD><C9B4><EFBFBD>] "<<endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
else if(Rows ==1)
|
|
|
|
|
{
|
|
|
|
|
(*pStream)<<"[һά<D2BB><CEAC><EFBFBD><EFBFBD>] "<<endl;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
(*pStream)<<"[<5B><>ά<EFBFBD><CEAC><EFBFBD><EFBFBD>] "<<endl;
|
|
|
|
|
}
|
|
|
|
|
//<2F>Ƚ<EFBFBD><C8BD><EFBFBD><EFBFBD>ж<EFBFBD><D0B6><EFBFBD><EFBFBD><EFBFBD>-------------------------------------
|
|
|
|
|
int ModuleSize = 3;//ÿ<><C3BF>ģ<EFBFBD><C4A3><EFBFBD>ijߴ<C4B3>(<28><><EFBFBD><EFBFBD>) (modulWidth <20><>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>Ϊ800)
|
|
|
|
|
int startX=1;//barcode <20>ؼ<EFBFBD><D8BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
int startY=1;
|
|
|
|
|
int endX = 1000;
|
|
|
|
|
int endY = 400;
|
|
|
|
|
|
|
|
|
|
if(Rows>1)
|
|
|
|
|
{
|
|
|
|
|
endX = startX + Rows*ModuleSize;
|
|
|
|
|
endY = startY + Rows*ModuleSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ColCnt = 0;
|
|
|
|
|
int Pos1 = startX;
|
|
|
|
|
int Pos2 = startX;
|
|
|
|
|
|
|
|
|
|
int CurY = startY;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CreatSpaceLine(ModuleVec,Rows+2);
|
|
|
|
|
for(int i = 0;i<Rows;i++)//ÿ<>ν<EFBFBD><CEBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
{
|
|
|
|
|
vector<CBarCodeModule> vec;
|
|
|
|
|
ModuleVec.push_back(vec);
|
|
|
|
|
int size = ModuleVec.size();
|
|
|
|
|
AnlalysisOneRow(ModuleVec[size-1],startX,endX,CurY,ModuleSize);
|
|
|
|
|
CurY += ModuleSize;
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
CreatSpaceLine(ModuleVec,Rows+2);
|
|
|
|
|
return !ModuleVec.empty();
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>,<2C><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CObjBarCode::CreatSpaceLine(vector<vector<CBarCodeModule>> &ModuleVec,int cnt)
|
|
|
|
|
{
|
|
|
|
|
vector<CBarCodeModule> vec;
|
|
|
|
|
ModuleVec.push_back(vec);
|
|
|
|
|
int size = ModuleVec.size();
|
|
|
|
|
for(int i=0;i<cnt;i++)
|
|
|
|
|
{
|
|
|
|
|
CBarCodeModule ModuleSpace(false);
|
|
|
|
|
ModuleVec[size-1].push_back(ModuleSpace);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
|
|
|
|
|
void CObjBarCode::AnlalysisOneRow(vector<CBarCodeModule> &vec,int startX,int endX,int curY,int ModuleSize)
|
|
|
|
|
{
|
|
|
|
|
ofstream *pStream = gLogMgr->GetDebugOfstream();
|
|
|
|
|
HDC hdc = GetCurViewPtr()->GetHDC();
|
|
|
|
|
COLORREF Pixelcolor;//<2F><><EFBFBD>ص<EFBFBD><D8B5><EFBFBD><EFBFBD><EFBFBD>ɫ
|
|
|
|
|
|
|
|
|
|
CBarCodeModule ModuleSpace(false);
|
|
|
|
|
vec.push_back(ModuleSpace);
|
|
|
|
|
for(int i = startX;i<endX;i +=ModuleSize)
|
|
|
|
|
{
|
|
|
|
|
//<2F><>ȡ<EFBFBD><C8A1>ǰ<EFBFBD><C7B0><EFBFBD>ص<EFBFBD><D8B5><EFBFBD>ɫ
|
|
|
|
|
Pixelcolor = GetPixel(hdc,i,curY);
|
|
|
|
|
if(RGB_RED == Pixelcolor)
|
|
|
|
|
{
|
|
|
|
|
CBarCodeModule Module(true);
|
|
|
|
|
vec.push_back(Module);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CBarCodeModule Module(false);
|
|
|
|
|
vec.push_back(Module);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
vec.push_back(ModuleSpace);
|
|
|
|
|
}
|
|
|
|
|
//<2F><><EFBFBD>ݶ<EFBFBD>ά<EFBFBD><CEAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
void CObjBarCode::CreatEdge(vector<vector<CBarCodeModule>> &ModuleVec,CObjContainer &ObjContainer)
|
|
|
|
|
{
|
|
|
|
|
if(ModuleVec.empty())
|
|
|
|
|
return;
|
|
|
|
|
//<2F><>ֱ<EFBFBD><D6B1><EFBFBD><EFBFBD>--------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
int MaxCol = ModuleVec[0].size();
|
|
|
|
|
int MaxRow = ModuleVec.size();
|
|
|
|
|
for(int Col=1;Col<MaxCol;Col++)//ÿһ<C3BF><D2BB>
|
|
|
|
|
{
|
|
|
|
|
int Start = -1;
|
|
|
|
|
int End = -1;
|
|
|
|
|
bool flg = false;
|
|
|
|
|
for(int Row=0;Row<MaxRow;Row++)//ÿһ<C3BF><D2BB>
|
|
|
|
|
{
|
|
|
|
|
//<2F>ڰ<EFBFBD><DAB0>ཻ
|
|
|
|
|
if((ModuleVec[Row][Col].IsBlack()&&!ModuleVec[Row][Col-1].IsBlack())||(!ModuleVec[Row][Col].IsBlack()&&ModuleVec[Row][Col-1].IsBlack()))
|
|
|
|
|
{
|
|
|
|
|
if(-1==Start)
|
|
|
|
|
Start = Row;
|
|
|
|
|
End = Row;
|
|
|
|
|
if(Row == MaxRow-1 && (-1!=Start))
|
|
|
|
|
flg = true;
|
|
|
|
|
}
|
|
|
|
|
else if(-1 !=Start)
|
|
|
|
|
{
|
|
|
|
|
flg = true;
|
|
|
|
|
}
|
|
|
|
|
if(flg)
|
|
|
|
|
{
|
|
|
|
|
Dbxy pt1,pt2;
|
|
|
|
|
pt1.x = m_BasePt.x + m_ModuleW*Col;
|
|
|
|
|
pt1.y = m_BasePt.y - m_ModuleH*Start;
|
|
|
|
|
pt2.x = m_BasePt.x + m_ModuleW*Col;
|
|
|
|
|
pt2.y = m_BasePt.y - m_ModuleH*(End+1);
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
CObjPline *Pline = new CObjPline;
|
|
|
|
|
CDataPoint DataPoint1(pt1);
|
|
|
|
|
Pline->AddDataPoint(DataPoint1);
|
|
|
|
|
CDataPoint DataPoint2(pt2);
|
|
|
|
|
Pline->AddDataPoint(DataPoint2);
|
|
|
|
|
ObjContainer.AddObject(Pline);
|
|
|
|
|
|
|
|
|
|
Start = -1;
|
|
|
|
|
End = -1;
|
|
|
|
|
flg = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//ˮƽ<CBAE><C6BD><EFBFBD><EFBFBD>--------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
for(int Row=1;Row<MaxRow;Row++)//ÿһ<C3BF><D2BB>
|
|
|
|
|
{
|
|
|
|
|
int Start = -1;
|
|
|
|
|
int End = -1;
|
|
|
|
|
bool flg = false;
|
|
|
|
|
for(int Col=0;Col<MaxCol;Col++)//ÿһ<C3BF><D2BB>
|
|
|
|
|
{
|
|
|
|
|
//<2F>ڰ<EFBFBD><DAB0>ཻ
|
|
|
|
|
if((ModuleVec[Row][Col].IsBlack()&&!ModuleVec[Row-1][Col].IsBlack())||(!ModuleVec[Row][Col].IsBlack()&&ModuleVec[Row-1][Col].IsBlack()))
|
|
|
|
|
{
|
|
|
|
|
if(-1==Start)
|
|
|
|
|
Start = Col;
|
|
|
|
|
End = Col;
|
|
|
|
|
if(Col == MaxCol-1 && (-1!=Start))
|
|
|
|
|
flg = true;
|
|
|
|
|
}
|
|
|
|
|
else if(-1 !=Start)
|
|
|
|
|
{
|
|
|
|
|
flg = true;
|
|
|
|
|
}
|
|
|
|
|
if(flg)
|
|
|
|
|
{
|
|
|
|
|
Dbxy pt1,pt2;
|
|
|
|
|
pt1.x = m_BasePt.x + m_ModuleW*Start;
|
|
|
|
|
pt1.y = m_BasePt.y - m_ModuleH*Row;
|
|
|
|
|
pt2.x = m_BasePt.x + m_ModuleW*(End+1);
|
|
|
|
|
pt2.y = m_BasePt.y - m_ModuleH*Row;
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>߶<EFBFBD>
|
|
|
|
|
CObjPline *Pline = new CObjPline;
|
|
|
|
|
CDataPoint DataPoint1(pt1);
|
|
|
|
|
Pline->AddDataPoint(DataPoint1);
|
|
|
|
|
CDataPoint DataPoint2(pt2);
|
|
|
|
|
Pline->AddDataPoint(DataPoint2);
|
|
|
|
|
ObjContainer.AddObject(Pline);
|
|
|
|
|
|
|
|
|
|
Start = -1;
|
|
|
|
|
End = -1;
|
|
|
|
|
flg = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|