T168_Debug222\appl\Barcode\One文件:CodeEanExt.c

/******************************************************************************
 *                                                                            *
 *                         M O D U L E   D E F I N E                          *
 *                                                                            *
 ******************************************************************************/

#define EAN8_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 <stdio.h>
#include <string.h>
#include <ctype.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 QUIET_MU            0
#define TEXT_DIS            5
#define GuardMu                5
#define AddMu                10
#define TOTAL_CHAR            14    // (7 + 1 + 5 + 1)

/******************************************************************************
 *                                                                            *
 *                        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 STATIC BYTE Chara[3][10][5] = 
{
    3,2,1,1,1,    // A
    2,2,2,1,1,
    2,1,2,2,2,
    1,4,1,1,1,
    1,1,3,2,2,
    1,2,3,1,1,
    1,1,1,4,4,
    1,3,1,2,2,
    1,2,1,3,3,
    3,1,1,2,2,

    0,3,2,1,1,    // C
    0,2,2,2,1,
    0,2,1,2,2,
    0,1,4,1,1,
    0,1,1,3,2,
    0,1,2,3,1,
    0,1,1,1,4,
    0,1,3,1,2,
    0,1,2,1,3,
    0,3,1,1,2,

    1,1,2,3,3,    // B
    1,2,2,2,2,
    2,2,1,2,2,
    1,1,4,1,1,
    2,3,1,1,1,
    1,3,2,1,1,
    4,1,1,1,1,
    2,1,3,1,1,
    3,1,2,1,1,
    2,1,1,3,3
};

CONST STATIC BYTE Add2[4][2] = 
{
    0,0,
    0,2,
    2,0,
    2,2
};

CONST STATIC BYTE Add5[10][5] = 
{
    2,2,0,0,0,
    2,0,2,0,0,
    2,0,0,2,0,
    2,0,0,0,2,
    0,2,2,0,0,
    0,0,2,2,0,
    0,0,0,2,2,
    0,2,0,2,0,
    0,2,0,0,2,
    0,0,2,0,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     *
 *                                                                            *
 ******************************************************************************/

INT CodeEanExt(_BarCodeAttr *psBarCodeAttr)
{
    _BarAttr sBarAttr;
    _TextAttr sTextAttr;
    
    BYTE aValue[15], aHum[15], *pValue, *pHum, *pText;
    INT i, j, k, iQuiet, iGuard, iAdd;
    INT iSum, iCheck;    // Used by check sum
    BYTE TargetData[10];

    i = strlen((CHAR *)psBarCodeAttr->pExp);

    if ( i > 5 )
    {
        strncpy( (CHAR *)TargetData, (CHAR *)psBarCodeAttr->pExp , 5 );
        TargetData[5] = '\0';
    }
    else if ( i < 2 )
    {
        memset( TargetData, '0', 2 - i );
        strcpy( (CHAR *)(TargetData + 2 - i), (CHAR *)psBarCodeAttr->pExp);
    }
    else if ( i > 2 && i < 5 )
    {
        memset( TargetData, '0', 5 - i );
        strcpy( (CHAR *)(TargetData + 5 - i), (CHAR *)psBarCodeAttr->pExp);
    }
    else 
        strcpy( (CHAR *)TargetData, (CHAR *)psBarCodeAttr->pExp);

    pText = TargetData;
    while (*pText)
    {
        if ( !isdigit(*pText) )
            *pText = '0';
        pText += 1;
    }
    
    sBarAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;
    sBarAttr.iType = DRAW_BAR;
    pText = TargetData;
    iQuiet = QUIET_MU * psBarCodeAttr->iNarrow;
    iGuard = GuardMu * psBarCodeAttr->iNarrow; // 5

    iAdd = 0;

    // Check digit character 
    pValue = aValue;
    pHum = aHum;

    // Start position
    switch ( psBarCodeAttr->iRotation )
    {
        case 0:
        {
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX + iQuiet;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY;
            sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX + iQuiet + 3 * psBarCodeAttr->iNarrow;
            sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY + psBarCodeAttr->iHeight;
            break;
        }
        case 90:
        {
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - psBarCodeAttr->iHeight - iGuard;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY + iQuiet;
            sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - psBarCodeAttr->iHeight;
            sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY + iQuiet + 3 * psBarCodeAttr->iNarrow;
            break;
        }
        case 180:
        {
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - iQuiet;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - psBarCodeAttr->iHeight - iGuard;
            sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - iQuiet - 3 * psBarCodeAttr->iNarrow;
            sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - psBarCodeAttr->iHeight;
            break;
        }
        case 270:
        {
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - iQuiet;
            sTextAttr.sCoord.iX = psBarCodeAttr->sCoord.iX + psBarCodeAttr->iHeight;
            sTextAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - iQuiet - 3 * psBarCodeAttr->iNarrow;
            break;
        }
    }
    pHum = aHum;
    pValue = aValue;

    /* human readable */
    if ( psBarCodeAttr->iHuman != 0 )
    {
        sTextAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;
        sTextAttr.iDirection = psBarCodeAttr->iRotation;
        sTextAttr.iRotation = psBarCodeAttr->iRotation;
        sTextAttr.iHoriMulti = psBarCodeAttr->FontHoriMulti;
        sTextAttr.iVertMulti = psBarCodeAttr->FontVertMulti;
        
        switch ( psBarCodeAttr->iRotation )
        {
            case 0:
                sTextAttr.sCoord.iX += (4 * 7 + 4) * psBarCodeAttr->iNarrow;
                break;
            case 90:
                sTextAttr.sCoord.iY += (4 * 7 + 4) * psBarCodeAttr->iNarrow;
                break;
            case 180:
                sTextAttr.sCoord.iX -= (4 * 7 + 4) * psBarCodeAttr->iNarrow;
                break;
            case 270:
                sTextAttr.sCoord.iY -= (4 * 7 + 4) * psBarCodeAttr->iNarrow;
                break;
        }
    }

    /* Add on 2 or 5 */
    if ( psBarCodeAttr->iCheck == 2 || psBarCodeAttr->iCheck == 5 )
    {
        pValue = aValue;
        pHum = aHum;

        for ( i = 0 ; i < psBarCodeAttr->iCheck ; i++ )
        {
            if ( *pText < 48 || *pText > 57 )
                return FALSE;

            aValue[i] = *pText - 48;
            aHum[i] = *pText;
            pText += 1;
        }
        aHum[i] = 0;

        if ( psBarCodeAttr->iCheck == 2 )
        {
            iSum = 10 * aValue[0] + aValue[1];
            iCheck = iSum % 4;
        }
        else
        {
            iSum = 3 * (aValue[0] + aValue[2] + aValue[4]) +
                     9 * (aValue[1] + aValue[3]);
            iCheck = iSum % 10;
        }

          switch ( psBarCodeAttr->iRotation )
          {
              case 0:
              {                                         
                  sTextAttr.sCoord.iX = sBarAttr.sCoord.iX + 6 * psBarCodeAttr->iNarrow;
                  sTextAttr.sCoord.iY = sBarAttr.sCoord.iY;
                sBarAttr.sCoord.iY += iAdd;
                  sBarAttr.iHeight = psBarCodeAttr->iHeight - iAdd;
                  sBarAttr.iWidth = psBarCodeAttr->iNarrow;     /* draw bar 1011 */
                  DrawBar(&sBarAttr);
                  sBarAttr.sCoord.iX += psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  sBarAttr.iWidth = psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  DrawBar(&sBarAttr);
                  
                sBarAttr.sCoord.iX += sBarAttr.iWidth;
                  break;
              }
              case 90:
              {
                  sTextAttr.sCoord.iX = sBarAttr.sCoord.iX + sBarAttr.iWidth;
                  sTextAttr.sCoord.iY = sBarAttr.sCoord.iY + 6 * psBarCodeAttr->iNarrow;
                  sBarAttr.sCoord.iX += iGuard; 
                  sBarAttr.iWidth = psBarCodeAttr->iHeight - iAdd;
                 sBarAttr.iHeight = psBarCodeAttr->iNarrow;    /* draw bar 1011 */
                  DrawBar(&sBarAttr);

                  sBarAttr.sCoord.iY += psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  sBarAttr.iHeight = psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  DrawBar(&sBarAttr);
                  
                sBarAttr.sCoord.iY += sBarAttr.iHeight;
                break;
              }
              case 180:
              {
                  sTextAttr.sCoord.iX = sBarAttr.sCoord.iX - 6 * psBarCodeAttr->iNarrow;
                sTextAttr.sCoord.iY = sBarAttr.sCoord.iY + sBarAttr.iHeight;
                sBarAttr.sCoord.iY += iGuard;
                sBarAttr.iHeight = psBarCodeAttr->iHeight - iAdd;
                  sBarAttr.iWidth = psBarCodeAttr->iNarrow;     /* draw bar 1011 */
                  sBarAttr.sCoord.iX -= psBarCodeAttr->iNarrow;
                  DrawBar(&sBarAttr);

                  sBarAttr.sCoord.iX -= psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  sBarAttr.iWidth = psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  DrawBar(&sBarAttr);
                  break;
              }
              case 270:
              {
                  sTextAttr.sCoord.iX = sBarAttr.sCoord.iX;
                  sTextAttr.sCoord.iY = sBarAttr.sCoord.iY - 6 * psBarCodeAttr->iNarrow;
                  sBarAttr.sCoord.iX += iAdd;
                   sBarAttr.iWidth = psBarCodeAttr->iHeight - iAdd;
                   sBarAttr.iHeight = psBarCodeAttr->iNarrow;    /* draw bar 1011 */
                sBarAttr.sCoord.iY -= psBarCodeAttr->iNarrow;
                  DrawBar(&sBarAttr);

                  sBarAttr.sCoord.iY -= psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                  sBarAttr.iHeight = psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                DrawBar(&sBarAttr);
                  break;
              }
          }


  
        /* add 2 or add 5*/
          switch ( psBarCodeAttr->iRotation )
          {
              case 0:
              {
                  for ( k = 0 ; k < psBarCodeAttr->iCheck ; k++ )
                  {
                      if ( psBarCodeAttr->iCheck == 5 )
                      {
                          j = Add5[iCheck][k];
                      }
                      else
                      {
                          j = Add2[iCheck][k];
                      }

                    for ( i = 0 ; i < 4 ; i++ )
                    {
                          sBarAttr.sCoord.iX += Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                          i += 1;

                          sBarAttr.iWidth = Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                          DrawBar(&sBarAttr);
                          sBarAttr.sCoord.iX += Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                      }

                      pValue += 1;

                      if ( k != (psBarCodeAttr->iCheck - 1) )     /* center character */
                      {
                          sBarAttr.iWidth = psBarCodeAttr->iNarrow;     /* draw bar 01 */
                          sBarAttr.sCoord.iX += psBarCodeAttr->iNarrow;
                          DrawBar(&sBarAttr);
                          sBarAttr.sCoord.iX += psBarCodeAttr->iNarrow;
                      }
                  }
                  break;
              }
              case 90:
              {
                  for ( k = 0 ; k < psBarCodeAttr->iCheck ; k++ )
                  {
                      if ( psBarCodeAttr->iCheck == 5 )
                      {
                          j = Add5[iCheck][k];
                      }
                      else
                      {
                          j = Add2[iCheck][k];
                      }

                    for ( i = 0 ; i < 4 ; i++ )
                    {
                        sBarAttr.sCoord.iY +=  Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                        i += 1;

                        sBarAttr.iHeight = Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                        DrawBar(&sBarAttr);
                        sBarAttr.sCoord.iY +=  Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                    }

                    pValue += 1;

                    if ( k != (psBarCodeAttr->iCheck - 1 ) )    /* center character */
                    {
                        sBarAttr.iHeight = psBarCodeAttr->iNarrow;     /* draw bar 01 */
                        sBarAttr.sCoord.iY += psBarCodeAttr->iNarrow;
                        DrawBar(&sBarAttr);
                        sBarAttr.sCoord.iY += psBarCodeAttr->iNarrow;
                    }
                }
                break;
              }
              case 180:
              {
                  for ( k = 0 ; k < psBarCodeAttr->iCheck ; k++ )
                  {
                    if ( psBarCodeAttr->iCheck == 5 )
                      {
                          j = Add5[iCheck][k];
                      }
                      else
                    {
                          j = Add2[iCheck][k];
                      }

                      for ( i = 0 ; i < 4 ; i++ )
                      {
                          sBarAttr.sCoord.iX -= Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                          i += 1;

                          sBarAttr.iWidth = Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                          sBarAttr.sCoord.iX -= sBarAttr.iWidth;
                          DrawBar(&sBarAttr);
                      }

                      pValue += 1;

                      if ( k != (psBarCodeAttr->iCheck - 1) )     /* center character */
                    {

                          sBarAttr.iWidth = psBarCodeAttr->iNarrow;     /* draw bar 01 */
                          sBarAttr.sCoord.iX -= psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow ;
                          DrawBar(&sBarAttr);
                      }
                  }
                  break;
              }
              case 270:
              {
                for ( k = 0 ; k < psBarCodeAttr->iCheck ; k++ )
                {
                    if ( psBarCodeAttr->iCheck == 5 )
                    {
                        j = Add5[iCheck][k];
                    }
                    else
                    {
                        j = Add2[iCheck][k];
                    }

                    for ( i = 0 ; i < 4 ; i++ )
                    {
                        sBarAttr.sCoord.iY -= Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                        i += 1;

                        sBarAttr.iHeight = Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                        sBarAttr.sCoord.iY -= Chara[j][*pValue][i] * psBarCodeAttr->iNarrow;
                        DrawBar(&sBarAttr);
                    }

                    pValue += 1;

                    if ( k != ( psBarCodeAttr->iCheck - 1 ) )     /* center character */
                    {
                        sBarAttr.iHeight = psBarCodeAttr->iNarrow;    /* draw bar 01 */
                        sBarAttr.sCoord.iY -= psBarCodeAttr->iNarrow + psBarCodeAttr->iNarrow;
                        DrawBar(&sBarAttr);
                    }
                }
                break;
            }
        }

        if ( psBarCodeAttr->iCheck == 5 )
            psBarCodeAttr->TotalWidth = psBarCodeAttr->iNarrow * 47;
        else 
            psBarCodeAttr->TotalWidth = psBarCodeAttr->iNarrow * 20;

        psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
        
        if ( psBarCodeAttr->iHuman != 0 )
        {
            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 *)pHum);
            sTextAttr.pExp       = pHum;

            switch(psBarCodeAttr->iNarrow)
            {
                case 1:
                    sTextAttr.pFont = (BYTE *)"@0";
                    break;
                case 2:
                    sTextAttr.pFont = (BYTE *)"@1";
                    break;
                case 3:
                case 4:
                case 5:
                case 6:
                default:
                    sTextAttr.pFont = (BYTE *)"@2";
                    break;
            }

            sTextAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;

            PreviewText(&sTextAttr);
            psBarCodeAttr->FontWidth  = sTextAttr.iRealWidth;
            psBarCodeAttr->FontHeight = sTextAttr.iRealHeight + TEXT_DIS;
            psBarCodeAttr->TotalHeight += psBarCodeAttr->FontHeight;
            psBarCodeAttr->AboveCode = TRUE;
            switch ( psBarCodeAttr->iRotation )
            {
                case 0:
                    sTextAttr.sCoord.iX += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                    sTextAttr.sCoord.iY -= psBarCodeAttr->FontHeight;
                    break;
                case 90:
                    sTextAttr.sCoord.iY += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                    sTextAttr.sCoord.iX += psBarCodeAttr->FontHeight;
                    break;
                case 180:
                    sTextAttr.sCoord.iX -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                    sTextAttr.sCoord.iY += psBarCodeAttr->FontHeight;
                    break;
                case 270:
                    sTextAttr.sCoord.iY -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                    sTextAttr.sCoord.iX -= psBarCodeAttr->FontHeight;
                    break;
            }

            sTextAttr.ExpLength = strlen((CHAR *)pHum);
            sTextAttr.pExp = pHum;
            OutText(&sTextAttr);
        }        
    }
    return TRUE;
}

INT PreviewCodeEanExt(_BarCodeAttr *psBarCodeAttr)
{

    if ( psBarCodeAttr->iCheck == 5 )
        psBarCodeAttr->TotalWidth = psBarCodeAttr->iNarrow * 47;
    else 
        psBarCodeAttr->TotalWidth = psBarCodeAttr->iNarrow * 20;

    psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;

    return TRUE;
}

  • 19
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值