/******************************************************************************
* *
* M O D U L E D E F I N E *
* *
******************************************************************************/
#define CODE11_C
/******************************************************************************
* *
* C O M P I L E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include <string.h>
/******************************************************************************
* *
* U S E R D E F I N E D I N C L U D E F I L E S *
* *
******************************************************************************/
#include "Common.h"
#include "XGraphic.h"
#include "Barcode.h"
/******************************************************************************
* *
* L O C A L D E F I N E S *
* *
******************************************************************************/
#define CODE11_TEXT_ERROR 0x01
#define QUIET_MU 0
#define TEXT_DIS 5
/******************************************************************************
* *
* L O C A L T Y P E D E F S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L F U N C T I O N P R O T O T Y P E S *
* *
******************************************************************************/
/* None */
/******************************************************************************
* *
* L O C A L I N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
CONST BYTE CODE11_START = {0x06};
CONST BYTE CODE11_END = {0x06};
CONST BYTE CODE11_TBL[11]=
{
/*-----------------02-23-99 16:14-------------------
0,1,2,3,4,5,6,7,8,9,-
--------------------------------------------------*/
0x01,0x11,0x09,0x18,0x05,0x14,0x0c,0x03,0x12,0x10,0x04
};
CONST BYTE CODE11_CHECK_TABLE[11]=
{
'0','1','2','3','4','5','6','7','8','9','-'
};
CONST BYTE CODE11_Width[][2]=
{
// 0
{5,1},
// 1
{4,2},
// 2
{4,2},
// 3
{4,2},
// 4
{4,2},
// 5
{4,2},
// 6
{4,2},
// 7
{4,2},
// 8
{4,2},
// 9
{5,1},
// 9
{5,1},
// 9
{4,2},
};
/******************************************************************************
* *
* L O C A L U N I T I A L I Z E D D A T A D E F I N I T I O N S *
* *
******************************************************************************/
/******************************************************************************
*
* Function:
*
*
* Description:
*
*
* Input:
* None
*
* Output:
* None.
*
******************************************************************************/
/*-----------------08-16-99 17:15-------------------
name:
Code11
description:
draw code11 to image buffer
input:
_BarCodeAttr structure
Check = 0 : no check digit
Check = 1 : 2 check digit
Check = 2 : 1 check digit
output:
TRUE: OK
FALSE: ERROR
--------------------------------------------------*/
INT Code11(_BarCodeAttr *psBarCodeAttr)
{
/*-----------------08-16-99 17:18-------------------
variables
--------------------------------------------------*/
INT iProcess,iExpLenth,iTemp;
INT iCheckC,iCheckK,iTempLen;
BYTE bCodedata,bCodeMask;
BYTE bsHuman[100];
BYTE *pHuman;
BYTE *pExpress;
_BarAttr sBarAttr;
_BarCodeAttr sBarCodeAttr;
sBarCodeAttr = *psBarCodeAttr;
pHuman = bsHuman;
/*-----------------08-16-99 17:19-------------------
ImagePoint initial
--------------------------------------------------*/
sBarAttr.psImageBuffer = sBarCodeAttr.psImageBuffer;
pExpress = sBarCodeAttr.pExp;
iProcess = 0;
iCheckC = 0;
iExpLenth = 0;
/*-----------------02-10-99 11:35-------------------
decode
--------------------------------------------------*/
while(1)
{
/*-----------------02-10-99 11:29-------------------
leading quiet zone
--------------------------------------------------*/
if ( iProcess == 0 )
{
switch ( sBarCodeAttr.iRotation )
{
case 90:
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iHeight;
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sBarCodeAttr.iNarrow * QUIET_MU;
break;
case 180:
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iHeight;
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iNarrow * QUIET_MU;
break;
case 270:
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iNarrow * QUIET_MU;
break;
default:
case 0:
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sBarCodeAttr.iNarrow * QUIET_MU;
break;
}
iProcess = 1;
continue;
}
/*-----------------02-10-99 11:35-------------------
start code
--------------------------------------------------*/
else if ( iProcess == 1 )
{
bCodedata = CODE11_START;
iProcess = 2;
}
/*-----------------02-10-99 12:06-------------------
get data -> encode fisrt byte
--------------------------------------------------*/
else if ( iProcess == 2 )
{
if ( (*pExpress >= '0') && (*pExpress <= '9') )
{
iExpLenth++;
bCodedata = CODE11_TBL[(*pExpress - '0')];
*pHuman = *pExpress;
pHuman++ ;
++pExpress;
}
else if ( *pExpress == '-' )
{
iExpLenth++;
bCodedata = CODE11_TBL[10];
*pHuman = *pExpress;
pHuman++;
++pExpress;
}
else if ( *pExpress == 0 )
{
iProcess = 3;
continue;
}
else
{
/*-----------------02-23-99 17:44-------------------
error
--------------------------------------------------*/
return CODE11_TEXT_ERROR;
}
}
/*-----------------02-10-99 14:52-------------------
C check digital
--------------------------------------------------*/
else if( iProcess == 3 )
{
*pHuman = 0;
if ( sBarCodeAttr.iCheck == 0)
{
iProcess = 5;
continue;
}
pExpress = sBarCodeAttr.pExp;
iCheckC = 0;
iTempLen = iExpLenth;
while((*pExpress != 0) && (iTempLen > 0))
{
iTemp = ((iTempLen - 1) % 11) + 1;
if ( (*pExpress >= '0') && (*pExpress <= '9') )
{
iTemp = iTemp * (*pExpress - '0');
pExpress++;
}
else
{
iTemp = iTemp * 10;
pExpress++;
}
iCheckC += iTemp;
iTempLen--;
}
bCodedata = CODE11_TBL[(iCheckC % 11)];
iExpLenth++;
if ( sBarCodeAttr.eLanguage == LANG_ZPL )
{
*pHuman = CODE11_CHECK_TABLE[(iCheckC % 11)];
pHuman += 1;
}
iProcess = 4;
}
/*-----------------02-10-99 14:52-------------------
K check digital
--------------------------------------------------*/
else if( iProcess == 4 )
{
*pHuman = 0;
if ( sBarCodeAttr.iCheck == 2)
{
iProcess = 5;
continue;
}
pExpress = sBarCodeAttr.pExp;
iCheckK = 0;
iTempLen = iExpLenth;
if ( iExpLenth <= 10 && sBarCodeAttr.eLanguage != LANG_ZPL )
{
*pHuman = 0;
iProcess = 5;
continue;
}
else
{
while((*pExpress != 0) && (iTempLen > 1))
{
iTemp = ((iTempLen - 1) % 11) + 1;
if ( (*pExpress >= '0') && (*pExpress <= '9') )
{
iTemp = iTemp * (*pExpress - '0');
pExpress++;
}
else
{
iTemp = iTemp * 10;
pExpress++;
}
iCheckC = iCheckC + iTemp;
iTempLen--;
}
iCheckK = iCheckK + iCheckC;
bCodedata = CODE11_TBL[(iCheckK % 11)];
if ( sBarCodeAttr.eLanguage == LANG_ZPL )
{
*pHuman = CODE11_CHECK_TABLE[(iCheckK % 11)];
pHuman += 1;
}
iProcess = 5;
}
}
/*-----------------02-10-99 12:07-------------------
end code
--------------------------------------------------*/
else if ( iProcess == 5 )
{
*pHuman = 0;
bCodedata = CODE11_START;
iProcess = 6;
}
/*-----------------02-10-99 11:35-------------------
draw bar
--------------------------------------------------*/
bCodeMask = 0x20;
iTemp = 5;
while(iTemp >= 0)
{
iTemp--;
bCodeMask = bCodeMask >> 1;
if ( (iTemp % 2) == 0 )
{
switch ( sBarCodeAttr.iRotation )
{
case 90:
sBarAttr.sCoord.iX = sBarCodeAttr.sCoord.iX;
sBarAttr.sCoord.iY = sBarCodeAttr.sCoord.iY;
sBarAttr.iWidth = sBarCodeAttr.iHeight;
if ( (bCodedata & bCodeMask)!= 0 )
{
sBarAttr.iHeight = sBarCodeAttr.iWide;
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sBarCodeAttr.iWide;
}
else
{
sBarAttr.iHeight = sBarCodeAttr.iNarrow;
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sBarCodeAttr.iNarrow;
}
break;
case 180:
sBarAttr.sCoord.iY = sBarCodeAttr.sCoord.iY;
if ( (bCodedata & bCodeMask)!= 0 )
{
sBarAttr.iWidth = sBarCodeAttr.iWide;
sBarAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iWide;
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iWide;
}
else
{
sBarAttr.iWidth = sBarCodeAttr.iNarrow;
sBarAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iNarrow;
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iNarrow;
}
sBarAttr.iHeight = sBarCodeAttr.iHeight;
break;
case 270:
sBarAttr.sCoord.iX = sBarCodeAttr.sCoord.iX;
sBarAttr.iWidth = sBarCodeAttr.iHeight;
if ( (bCodedata & bCodeMask)!= 0 )
{
sBarAttr.iHeight = sBarCodeAttr.iWide;
sBarAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iWide;
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iWide;
}
else
{
sBarAttr.iHeight = sBarCodeAttr.iNarrow;
sBarAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iNarrow;
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iNarrow;
}
break;
default:
case 0:
sBarAttr.sCoord.iX = sBarCodeAttr.sCoord.iX;
sBarAttr.sCoord.iY = sBarCodeAttr.sCoord.iY;
if ( (bCodedata & bCodeMask)!= 0 )
{
sBarAttr.iWidth = sBarCodeAttr.iWide;
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sBarCodeAttr.iWide;
}
else
{
sBarAttr.iWidth = sBarCodeAttr.iNarrow;
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sBarCodeAttr.iNarrow;
}
sBarAttr.iHeight = sBarCodeAttr.iHeight;
break;
}
sBarAttr.iType = DRAW_BAR;
DrawBar(&sBarAttr);
}
else
{
switch ( sBarCodeAttr.iRotation )
{
case 90:
if ( (bCodedata & bCodeMask)!= 0 )
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sBarCodeAttr.iWide;
else
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sBarCodeAttr.iNarrow;
break;
case 180:
if ( (bCodedata & bCodeMask)!= 0 )
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iWide;
else
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sBarCodeAttr.iNarrow;
break;
case 270:
if ( (bCodedata & bCodeMask)!= 0 )
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iWide;
else
sBarCodeAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sBarCodeAttr.iNarrow;
break;
default:
case 0:
if ( (bCodedata & bCodeMask)!= 0 )
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sBarCodeAttr.iWide;
else
sBarCodeAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sBarCodeAttr.iNarrow;
break;
}
}
}
/*-----------------02-10-99 11:40-------------------
if draw ok
--------------------------------------------------*/
if ( iProcess == 6 )
{
switch ( sBarCodeAttr.iRotation )
{
case 90:
psBarCodeAttr->TotalWidth = sBarCodeAttr.sCoord.iY - psBarCodeAttr->sCoord.iY;
psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
break;
case 180:
psBarCodeAttr->TotalWidth = psBarCodeAttr->sCoord.iX - sBarCodeAttr.sCoord.iX;
psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
break;
case 270:
psBarCodeAttr->TotalWidth = psBarCodeAttr->sCoord.iY - sBarCodeAttr.sCoord.iY;
psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
break;
case 0:
default:
psBarCodeAttr->TotalWidth = sBarCodeAttr.sCoord.iX - psBarCodeAttr->sCoord.iX;
psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
break;
}
break;
}
}
/*-----------------02-24-99 11:26-------------------
human readable is true draw text
--------------------------------------------------*/
if ( psBarCodeAttr->iHuman != 0 )
{
_TextAttr sTextAttr;
sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX;
sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY;
sTextAttr.iDirection = psBarCodeAttr->iRotation;
sTextAttr.iRotation = psBarCodeAttr->iRotation;
sTextAttr.iDistance = 0;
sTextAttr.iHoriMulti = psBarCodeAttr->FontHoriMulti;
sTextAttr.iVertMulti = psBarCodeAttr->FontVertMulti;
sTextAttr.ExpLength = strlen((CHAR *)bsHuman);
sTextAttr.pExp = bsHuman;
sTextAttr.pFont = psBarCodeAttr->pFont;
sTextAttr.eLanguage = psBarCodeAttr->eLanguage;
sTextAttr.ePutWay = psBarCodeAttr->ePutWay;
sTextAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;
PreviewText(&sTextAttr);
switch ( psBarCodeAttr->iRotation )
{
case 90:
if ( psBarCodeAttr->AboveCode )
sTextAttr.sCoord.iX += sTextAttr.iRealHeight + TEXT_DIS;
else
sTextAttr.sCoord.iX -= psBarCodeAttr->iHeight + TEXT_DIS;
sTextAttr.sCoord.iY += psBarCodeAttr->iNarrow * QUIET_MU;
if ( psBarCodeAttr->iHuman == 2 )
sTextAttr.sCoord.iY += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
else if ( psBarCodeAttr->iHuman == 3 )
sTextAttr.sCoord.iY = sBarCodeAttr.sCoord.iY - sTextAttr.iRealWidth;
break;
case 180:
if ( psBarCodeAttr->AboveCode )
sTextAttr.sCoord.iY += sTextAttr.iRealHeight + TEXT_DIS;
else
sTextAttr.sCoord.iY -= psBarCodeAttr->iHeight + TEXT_DIS;
sTextAttr.sCoord.iX -= psBarCodeAttr->iNarrow * QUIET_MU;
if ( psBarCodeAttr->iHuman == 2 )
sTextAttr.sCoord.iX -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
else if ( psBarCodeAttr->iHuman == 3 )
sTextAttr.sCoord.iX = sBarCodeAttr.sCoord.iX + sTextAttr.iRealWidth;
break;
case 270:
if ( psBarCodeAttr->AboveCode )
sTextAttr.sCoord.iX -= sTextAttr.iRealHeight + TEXT_DIS;
else
sTextAttr.sCoord.iX += psBarCodeAttr->iHeight + TEXT_DIS;
sTextAttr.sCoord.iY -= psBarCodeAttr->iNarrow * QUIET_MU;
if ( psBarCodeAttr->iHuman == 2 )
sTextAttr.sCoord.iY -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
else if ( psBarCodeAttr->iHuman == 3 )
sTextAttr.sCoord.iY = sBarCodeAttr.sCoord.iY + sTextAttr.iRealWidth;
break;
case 0:
default:
if ( psBarCodeAttr->AboveCode )
sTextAttr.sCoord.iY -= sTextAttr.iRealHeight + TEXT_DIS;
else
sTextAttr.sCoord.iY += psBarCodeAttr->iHeight + TEXT_DIS;
sTextAttr.sCoord.iX += psBarCodeAttr->iNarrow * QUIET_MU;
if ( psBarCodeAttr->iHuman == 2 )
sTextAttr.sCoord.iX += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
else if ( psBarCodeAttr->iHuman == 3 )
sTextAttr.sCoord.iX = sBarCodeAttr.sCoord.iX - sTextAttr.iRealWidth;
break;
}
OutText(&sTextAttr);
psBarCodeAttr->TotalHeight += sTextAttr.iRealHeight + TEXT_DIS;
psBarCodeAttr->FontWidth = sTextAttr.iRealWidth;
psBarCodeAttr->FontHeight = sTextAttr.iRealHeight + TEXT_DIS;
}
return 0;
}
INT PreviewCode11(_BarCodeAttr *psBarCodeAttr)
{
CHAR *pExp;
INT TotalNarrowBar, TotalWideBar;
INT CheckC, CheckK;
INT Length;
INT iTemp, iTemp2;
pExp = (CHAR *)psBarCodeAttr->pExp;
Length = strlen((CHAR *)psBarCodeAttr->pExp);
// start and stop code
TotalNarrowBar = CODE11_Width[11][0] * 2;
TotalWideBar = CODE11_Width[11][1] * 2;
CheckC = 0;
CheckK = 0;
while ( *pExp )
{
iTemp = ((Length - 1) % 11) + 1;
iTemp2 =(Length % 11) + 1;
if ((*pExp >= '0') && (*pExp <= '9'))
{
iTemp *= (*pExp & 0x0f);
iTemp2 *= (*pExp & 0x0f);
TotalNarrowBar += CODE11_Width[*pExp & 0x0f][0];
TotalWideBar += CODE11_Width[*pExp & 0x0f][1];
}
else if (*pExp == '-')
{
iTemp *= 10;
iTemp2 *= 10;
TotalNarrowBar += CODE11_Width[10][0];
TotalWideBar += CODE11_Width[10][1];
}
CheckC += iTemp;
CheckK += iTemp;
Length--;
pExp++;
}
CheckK += CheckC;
if (psBarCodeAttr->iCheck != 0)
{
TotalNarrowBar += CODE11_Width[CheckC % 11][0];
TotalWideBar += CODE11_Width[CheckC % 11][1];
Length = strlen((CHAR *)psBarCodeAttr->pExp) + 1;
if (psBarCodeAttr->iCheck == 1)
{
if (Length > 10 || psBarCodeAttr->eLanguage == LANG_ZPL)
{
TotalNarrowBar += CODE11_Width[CheckK % 11][0];
TotalWideBar += CODE11_Width[CheckK % 11][1];
}
}
}
psBarCodeAttr->TotalWidth = TotalNarrowBar * psBarCodeAttr->iNarrow +
TotalWideBar * psBarCodeAttr->iWide + QUIET_MU;
psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
if (psBarCodeAttr->eLanguage == LANG_DPL && psBarCodeAttr->iHuman)
{
_TextAttr sTextAttr;
sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX;
sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY;
sTextAttr.iDirection = psBarCodeAttr->iRotation;
sTextAttr.iRotation = psBarCodeAttr->iRotation;
sTextAttr.iDistance = 0;
sTextAttr.iHoriMulti = psBarCodeAttr->FontHoriMulti;
sTextAttr.iVertMulti = psBarCodeAttr->FontVertMulti;
sTextAttr.ExpLength = strlen((CHAR *)psBarCodeAttr->pExp);
sTextAttr.pExp = psBarCodeAttr->pExp;
sTextAttr.pFont = psBarCodeAttr->pFont;
sTextAttr.eLanguage = psBarCodeAttr->eLanguage;
sTextAttr.ePutWay = psBarCodeAttr->ePutWay;
sTextAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;
PreviewText(&sTextAttr);
psBarCodeAttr->TotalHeight += sTextAttr.iRealHeight + TEXT_DIS;
psBarCodeAttr->FontWidth = sTextAttr.iRealWidth;
psBarCodeAttr->FontHeight = sTextAttr.iRealHeight + TEXT_DIS;
}
return TRUE;
}