#ifndef _BARCODE_H_
#define _BARCODE_H_

#define MM_TEXT 0
#define MM_HIMETRIC 1


#define BINARY_WORD(b15,b14,b13,b12,b11,b10,b9,b8,b7,b6,b5,b4,b3,b2,b1,b0) \
		(((WORD)(b15<<15))+((WORD)(b14<<14))+((WORD)(b13<<13))+	((WORD)(b12<<12))+ \
		((WORD)(b11<<11))+((WORD)(b10<<10))+ \
		((WORD)(b9<<9))+((WORD)(b8<<8))+((WORD)(b7<<7))+((WORD)(b6<<6))+((WORD)(b5<<5))+ \
		((WORD)(b4<<4))+((WORD)(b3<<3))+((WORD)(b2<<2))+((WORD)(b1<<1))+((WORD)(b0<<0)))

//条形码的属性
#ifndef BARCODE_UPC_A
#define BARCODE_UPC_A    0  //UPC_A条形码的类型值
#define BARCODE_UPC_E    1  //UPC_E条形码的类型值
#define BARCODE_EAN_13   2  //EAN_13条形码的类型值
#define BARCODE_EAN_8    3  //EAN_8条形码的类型值
#define BARCODE_39       4  //39条形码的类型值
#define BARCODE_ISBN     5  //ISBN条形码的类型值
#define BARCODE_ISSN     6  //ISSN条形码的类型值
#define BARCODE_X25      7  //X25条形码的类型值
#define BARCODE_CODABAR  8  //Codabar条形码的类型值
#define BARCODE_128      9  //128条形码的类型值
#endif


//条码类
class CBarCode
{
private:
        RECT  m_Rect;
        int   m_nStyle;
        float m_fScale;
        int   m_nPens;
        BOOL  m_bModifyHeight;
        int   m_nReserve1;
        int   m_nReserve2;
        int   m_nReserve3;

        int   m_crEmptyColor;
        int   m_crBarColor;
        int   m_crBackColor;

private:
        int   GetBarCodeCodabarLocation(char nChar);
        int   GetBarCode39Location(char nChar);
        char  GetBarCode39LocationToChar(int nLocation);

        BOOL  TransrateUpcE_To_UpcA(char* pUpcA, char* pUpcE);
        BOOL  DrawPrivateEan13(char* pStrCode);
        BOOL  DrawPrivate128(char* pStrCode);
public:
		//设置条形码的图形区域
        void  SetRect(RECT* pRect){m_Rect = *pRect;}
		//设置条形码的图形区域
        void  SetRect(int nLeft,int nTop,int nWidth,int nHeight)
        {
            m_Rect.left   = nLeft;
            m_Rect.top    = nTop;
            m_Rect.right  = nLeft + nWidth - 1;
            m_Rect.bottom = nTop + nHeight - 1;
        }
		//移动图形区域
        void  MoveTo(int nLeft, int nTop)
        {
            m_Rect.right  += nLeft - m_Rect.left;
            m_Rect.bottom += nTop -  m_Rect.top;
            m_Rect.left = nLeft;
            m_Rect.top  = nTop;
        }
		//修正图形区域坐标
        void  ModifyRect();
		//设置图形高度修正属性
        void  SetModifyHeight(BOOL bModify){m_bModifyHeight = bModify;}
		//获得图形高度修正属性
        BOOL  GetModifyHeight(){return(m_bModifyHeight);}
public:
		//设置条码类型
        void  SetStyle(int nStyle){m_nStyle = nStyle;}
		//获得条码类型
        int   GetStyle(){return(m_nStyle);}
		//设置图形放大因子
        void  SetScale(float fScale){m_fScale = fScale;}
		//获得图形放大因子
        float GetScale(){return(m_fScale);}
		//设置条码的“空”颜色
        void  SetEmptyColor(int crColor){ m_crEmptyColor = crColor;}
		//获得条码的“空”颜色
        int   GetEmptyColor(){return(m_crEmptyColor);}
		//设置条码的“条”颜色
        void  SetBarColor(int crColor){m_crBarColor = crColor;}
		//获得条码的“条”颜色
        int   GetBarColor(){return(m_crBarColor);}
		//设置图形的背景色
        void  SetBackColor(int crColor){m_crBackColor = crColor;}
		//获得图形的背景色
        int   GetBackColor(){return(m_crBackColor);}
		//设置文本颜色
        void  SetPens(int nPens){m_nPens = nPens;}
		//获得文本颜色
        int   GetPens(){return(m_nPens);}
public:
		//设置ISBN条形码的属性
        void  SetISBNAttrib(int nPublicBits, int nCheck, int nGroupBits);
		//设置ISSN条形码的属性
        void  SetISSNAttrib(int nSecondVersion);
		//设置39条形码的属性
        void  Set39Attrib(BOOL bCheckSum);
		//设置X25条形码的属性
        void  SetX25Attrib(BOOL bCheckSum, BOOL bBracket);
public:
		//画EAN-8码
		BOOL  DrawEan8(char* pStrCode);
		//画UPC-E码
		BOOL  DrawUpcE(char* pStrCode);
		//画UPC-A码
		BOOL  DrawUpcA(char* pStrCode);
		//画EAN-13码
		BOOL  DrawEan13(char* pStrCode);
		//画ISBN码
		BOOL  DrawISBN(char* pStrCode, int nPublicBits, int nCheck, int nGroupBits);
		//画ISSN码
		BOOL  DrawISSN(char* pStrCode, int nSecondVersion);
		//画39码
		BOOL  Draw39(char* pStrCode, BOOL bCheckSum);
		//画交叉25码
		BOOL  DrawX25(char* pStrCode, BOOL bCheck, BOOL bBracket);
		//画128码
		BOOL  Draw128(char* pStrCode);
		//画Codabar码
		BOOL  DrawCodabar(char* pStrCode);
		//画条码总入口
		BOOL  DrawBarCode(char* pStrCode);
public:
		//条形码的构造函数
		CBarCode();
};

//EAN-13条形码的属性
typedef struct _tagBARCODE_EAN13
{
	WORD  wLeftCodeOdd;
	WORD  wLeftArrayTo13;
	WORD  wLeftArrayToUpc_E;
}BARCODE_EAN13;

//39条形码的属性
typedef struct _tagBARCODE39
{
	BYTE  byCha;
	WORD  wCode;
	WORD  wLogic;
}BARCODE39;

//所有条形码的共有属性
struct BARCODE_ATTRIB 
{
	WORD  wStyle;
	int   nWidth;
	int   nHeight1;
	int   nHeight2;
	float fBeiFont;
	int   nMode;
	int   nLeft;
	int   nTop;
	//BarCode Text
	BOOL  bDisplayManufacturer;
	BOOL  bDisplayTime;
	float fBei;
	char  bufManufacture[256];
};


/*
//附加内容
int     HglgGetBarCode39Location(BYTE nCh);
BYTE    HglgLoopByteForEAN13(BYTE nCh);
//打印条码
BOOL    HglgPrintLabel(char* pStr);

BOOL    HglgDrawBarCodeUpcE(int nX,int nY,float fBeiWidth,char* pStr);
BOOL    HglgDrawBarCodeUpcA(int nX,int nY,float fBeiWidth,char* pStr);
BOOL    HglgDrawBarCodeEan8(int nX,int nY,float fBeiWidth,char* pStr);
BOOL    HglgDrawBarCodeEan13(int nX,int nY,float fBeiWidth,char* pStr);
BOOL    HglgDrawBarCode39(int nX,int nY,float fBei,char* pStr);
//条码属性
void    HglgDefaultBarCodeAttrib(WORD wSelect,int nMode);
void    HglgSetBarCodeAttribStyle(WORD  wStyle);
void    HglgSetBarCodeAttribWidth(int   nWidth);
void    HglgSetBarCodeAttribHeight1(int nHeight1);
void    HglgSetBarCodeAttribHeight2(int nHeight2);
void    HglgSetBarCodeAttribFont(float  fFont);
void    HglgSetBarCodeAttribMode(int    nMode);
void    HglgSetBarCodeAttribLeft(int    nLeft);
void    HglgSetBarCodeAttribTop(int    nTop);
void    HglgSetBarCodeAttribDisplayManufacturer(BOOL bDisplay);
void    HglgSetBarCodeAttribDisplayTime(BOOL bDisplay);

WORD    HglgGetBarCodeAttribStyle();
int     HglgGetBarCodeAttribWidth();
int     HglgGetBarCodeAttribHeight1();
int     HglgGetBarCodeAttribHeight2();
float   HglgGetBarCodeAttribFont();
int     HglgGetBarCodeAttribMode();
int     HglgGetBarCodeAttribLeft();
int     HglgGetBarCodeAttribTop();
BOOL    HglgGetBarCodeAttribDisplayManufacturer();
BOOL    HglgGetBarCodeAttribDisplayTime();

//------------------------------------------------------
float HglgGetBarCodeAttribBei();
void  HglgSetBarCodeAttribBei(float fBei);
char* HglgGetBarCodeAttribManufactureName();
void  HglgSetBarCodeAttribManufactureName(char *);

*/
#endif