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

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

#define CODE128_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 <ctype.h>
#include <stdlib.h>
#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 CODE_A        103
#define CODE_B        104
#define CODE_C        105
#define FNC1        102
#define FNC2        97
#define FNC3        96
#define FNC4A       101
#define FNC4B       100

#define SHIFT_MASK    0x80

#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 STATIC BYTE CodeTable[106][6] =
{
/*0*/    2,1,2,2,2,2,
        2,2,2,1,2,2,
        2,2,2,2,2,1,
        1,2,1,2,2,3,
        1,2,1,3,2,2,
        1,3,1,2,2,2,
        1,2,2,2,1,3,
        1,2,2,3,1,2,
        1,3,2,2,1,2,
        2,2,1,2,1,3,
/*10*/    2,2,1,3,1,2,
        2,3,1,2,1,2,
        1,1,2,2,3,2,
        1,2,2,1,3,2,
        1,2,2,2,3,1,
        1,1,3,2,2,2,
        1,2,3,1,2,2,
        1,2,3,2,2,1,
        2,2,3,2,1,1,
        2,2,1,1,3,2,
/*20*/    2,2,1,2,3,1,
        2,1,3,2,1,2,
        2,2,3,1,1,2,
        3,1,2,1,3,1,
        3,1,1,2,2,2,
        3,2,1,1,2,2,
        3,2,1,2,2,1,
        3,1,2,2,1,2,
        3,2,2,1,1,2,
        3,2,2,2,1,1,
/*30*/    2,1,2,1,2,3,
        2,1,2,3,2,1,
        2,3,2,1,2,1,
        1,1,1,3,2,3,
        1,3,1,1,2,3,
        1,3,1,3,2,1,
        1,1,2,3,1,3,
        1,3,2,1,1,3,
        1,3,2,3,1,1,
        2,1,1,3,1,3,
/*40*/    2,3,1,1,1,3,
        2,3,1,3,1,1,
        1,1,2,1,3,3,
        1,1,2,3,3,1,
        1,3,2,1,3,1,
        1,1,3,1,2,3,
        1,1,3,3,2,1,
        1,3,3,1,2,1,
        3,1,3,1,2,1,
        2,1,1,3,3,1,
/*50*/    2,3,1,1,3,1,
        2,1,3,1,1,3,
        2,1,3,3,1,1,
        2,1,3,1,3,1,
        3,1,1,1,2,3,
        3,1,1,3,2,1,
        3,3,1,1,2,1,
        3,1,2,1,1,3,
        3,1,2,3,1,1,
        3,3,2,1,1,1,
/*60*/    3,1,4,1,1,1,
        2,2,1,4,1,1,
        4,3,1,1,1,1,
        1,1,1,2,2,4,
        1,1,1,4,2,2,
        1,2,1,1,2,4,
        1,2,1,4,2,1,
        1,4,1,1,2,2,
        1,4,1,2,2,1,
        1,1,2,2,1,4,
/*70*/    1,1,2,4,1,2,
        1,2,2,1,1,4,
        1,2,2,4,1,1,
        1,4,2,1,1,2,
        1,4,2,2,1,1,
        2,4,1,2,1,1,
        2,2,1,1,1,4,
        4,1,3,1,1,1,
        2,4,1,1,1,2,
        1,3,4,1,1,1,
/*80*/    1,1,1,2,4,2,
        1,2,1,1,4,2,
        1,2,1,2,4,1,
        1,1,4,2,1,2,
        1,2,4,1,1,2,
        1,2,4,2,1,1,
        4,1,1,2,1,2,
        4,2,1,1,1,2,
        4,2,1,2,1,1,
        2,1,2,1,4,1,
/*90*/    2,1,4,1,2,1,
        4,1,2,1,2,1,
        1,1,1,1,4,3,
        1,1,1,3,4,1,
        1,3,1,1,4,1,
        1,1,4,1,1,3,
        1,1,4,3,1,1,
        4,1,1,1,1,3,
        4,1,1,3,1,1,
        1,1,3,1,4,1,
/*100*/ 1,1,4,1,3,1,
        3,1,1,1,4,1,
        4,1,1,1,3,1,
        2,1,1,4,1,2,
        2,1,1,2,1,4,
        2,1,1,2,3,2,
};

CONST STATIC BYTE StopCode[7] = { 2,3,3,1,1,1,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     *
 *                                                                            *
 ******************************************************************************/

STATIC INT CheckNumeric(_BarCodeAttr *pBarcode, BYTE *pText)
{
    INT Number = 0;

    while (*pText)
    {
        // ignore function characters
        if (pBarcode->eLanguage == LANG_EPL && (Number % 2) == 0)
        {
            if (memcmp(pText, "\"F1\"", 4) == 0 ||
                memcmp(pText, "\"F2\"", 4) == 0 ||
                memcmp(pText, "\"F3\"", 4) == 0 ||
                memcmp(pText, "\"F4\"", 4) == 0)
            {
                pText += 4;
                continue;
            }
        }

        if (!isdigit(*pText))
            break;
        pText += 1;
        Number += 1;
    }

    return Number;
}

/******************************************************************************
 *
 * Function:
 *    
 *
 * Description: 
 *        Check = 1: manual encode
 *        Check = A: Code A Start
 *        Check = B: Code B Start
 *        Check = C: Code C Start
 *
 * Input:
 *      None
 *
 * Output:
 *      None.
 *
 ******************************************************************************/
STATIC INT DecodeCode128( _BarCodeAttr *pBarcode, CHAR *Value, CHAR *Human)
{
    BYTE *pText, *pHuman;
    INT Code, Len, AutoDecode = TRUE;

    pText  = pBarcode->pExp;
    pHuman = (BYTE *)Human;
    Code   = CODE_B;    // default the START code is B
    Len    = 0;

    if (pBarcode->eLanguage == LANG_ZPL)
    {
        if (strchr((CHAR *)pText, '>'))
            AutoDecode = FALSE;
        if (pBarcode->iCheck != 0)
            AutoDecode = FALSE;
    }

    if (pBarcode->eLanguage == LANG_DPL && pBarcode->iCheck == 1)
    {
        // check the START CODE
        if (*pText == 'A')
        {
            Code = CODE_A;
            pText++;
        }
        else if (*pText == 'B')
        {
            Code = CODE_B;
            pText++;
        }
        else if (*pText == 'C')
        {
            Code = CODE_C;
            pText++;
        }

        *(Value + Len++) = Code;    // put the START value

        // encode the rest
        while (*pText)
        {
            if (*pText == '&')    // check special character
            {
                pText += 1;
                switch (*pText)
                {
                    case 'A':
                    case 'B':
                    case 'C':
                    case 'D':
                        if ((Code == CODE_A || Code == CODE_B) && *pText == 'C')
                            Code |= SHIFT_MASK;
                        *(Value + Len++) = *pText + 31;
                        if (*pText == 'D')
                            Code = CODE_C;
                        break;

                    case 'E':
                    case 'F':
                    case 'G':
                        if (Code == CODE_A && *pText == 'E')
                            Code = CODE_B;
                        if (Code == CODE_B && *pText == 'F')
                            Code = CODE_A;
                        if (Code == CODE_C && *pText == 'E')
                            Code = CODE_B;
                        if (Code == CODE_C && *pText == 'F')
                            Code = CODE_A;
                        *(Value + Len++) = *pText + 31;
                        break;

                    default:
                        break;
                }
                pText += 1;
            }
            else    // data character
            {
                switch (Code)    // change data character to value
                {
                    //  ASCII  32 - 95   0 - 31
                    //          0 - 63  64 - 95
                    case CODE_A:
                    case (CODE_B | SHIFT_MASK):
                        if (*pText >= 32 && *pText <= 95)
                        {
                            *(Value + Len++) = *pText - 32;
                            *pHuman++ = *pText++;    // put the human readable
                        }
                        else if (*pText <= 31)
                        {
                            *(Value + Len++) = *pText + 64;
                            *pHuman++ = *pText++;    // put the human readable
                        }
                        else
                        {
                            *(Value + Len++) = 100;    // special code A to B
                            Code = CODE_B;
                        }
                        break;
                    //  ASCII  32 - 95   96 - 127
                    //          0 - 63   64 - 95
                    case CODE_B:
                    case (CODE_A | SHIFT_MASK):
                        if (*pText < 32 || *pText > 126)
                            pText += 1;
                        else
                        {
                            *(Value + Len++) = *pText - 32;
                            *pHuman++ = *pText++;    // put the human readable
                        }
                        break;
                    // read pair and ASCII 48 - 57
                    case CODE_C:
                        if (isdigit(*pText) && isdigit(*(pText + 1)))
                        {
                            *(Value + Len++) = (*pText - '0') * 10 + *(pText + 1) - '0';
                            *pHuman++ = *pText++;    // put the human readable
                            *pHuman++ = *pText++;
                        }
                        else
                        {
                            *(Value + Len++) = 100;    // special code C to B 
                            Code = CODE_B;
                        }
                        break;
                }
                Code &= ~SHIFT_MASK;
            }
        }
        *pHuman = 0;
    }
    else if (pBarcode->eLanguage == LANG_ZPL && AutoDecode == FALSE)
    {
        INT UccCheck = 0;

        if (*pText == '>')    // check the START CODE 
        {
            switch (*(pText + 1))
            {
                case '9':
                    Code = CODE_A;
                    pText += 2;
                    break;
                case ':':
                    Code = CODE_B;
                    pText += 2;
                    break;
                case ';':
                    Code = CODE_C;
                    pText += 2;
                    break;
            }
        }
        *(Value + Len++) = Code;    // put the START value 

        while (*pText)
        {
            if (*pText == '>')    // check special character
            {
                switch (*(pText + 1))
                {
                    case '<':
                        pText += 2;
                        break;

                    case '0':
                        if (Code == CODE_A || Code == CODE_B)
                        {
                            *(Value + Len++) = 30;
                            *pHuman++ = '>';    // put the human readable
                        }
                        pText += 2;
                        break;

                    case '=':
                        if (Code == CODE_B)
                        {
                            *(Value + Len++) = 94;
                            *pHuman++ = '~';    // put the human readable
                        }
                        pText += 2;
                        break;

                    case '1':
                    case '2':
                    case '3':
                    case '4':
                    case '5':
                        if ((Code == CODE_A || Code == CODE_B) && *(pText + 1) == '4')
                            Code |= SHIFT_MASK;
                        *(Value + Len++) = *(pText + 1) + 46;
                        if (*(pText + 1) == '5')
                            Code = CODE_C;
                        pText += 2;
                        break;

                    case '6':
                    case '7':
                    case '8':
                        if (Code == CODE_A && *(pText + 1) == '6')
                            Code = CODE_B;
                        if (Code == CODE_B && *(pText + 1) == '7')
                            Code = CODE_A;
                        if (Code == CODE_C && *(pText + 1) == '6')
                            Code = CODE_B;
                        if (Code == CODE_C && *(pText + 1) == '7')
                            Code = CODE_A;
                        *(Value + Len++) = *(pText + 1) + 46;
                        pText += 2;
                        break;

                    case '\0':
                        pText += 1;
                        break;

                    default:
                        pText += 2;
                        break;
                }
            }
            else    // data character 
            {
                switch (Code)    // change data character to value
                {
                    //  ASCII  32 - 95   0 - 31
                    //          0 - 63  64 - 95
                    case CODE_A:
                    case (CODE_B | SHIFT_MASK):
                        if (isdigit(*pText) && isdigit(*(pText + 1)))
                        {
                            *(Value + Len) = (*pText - '0') * 10 + *(pText + 1) - '0';
                            if (*(Value + Len) > 63)
                                *pHuman++ = ' ';
                            else
                                *pHuman++ = ' ' + *(Value + Len);
                            Len += 1;
                            pText += 2;    // read pair data character 
                        }
                        else
                            pText += 1;

                        UccCheck = 0;
                        break;
                    //  ASCII  32 - 95   96 - 127
                    //          0 - 63   64 - 95
                    case CODE_B:
                    case (CODE_A | SHIFT_MASK):
                        if (*pText < 32 || *pText > 126)
                            pText += 1;
                        else
                        {
                            *(Value + Len++) = *pText - 32;
                            *pHuman++ = *pText++;    // put the human readable 
                        }
                        UccCheck = 0;
                        break;
                    // read pair and ASCII 48 - 57
                    case CODE_C:
                        if (isdigit(*pText) && isdigit(*(pText + 1)))
                        {
                            UccCheck += (*pText - '0') * 3 + *(pText + 1) - '0';
                            *(Value + Len++) = (*pText - '0') * 10 + *(pText + 1) - '0';
                            *pHuman++ = *pText++;        // put the human readable 
                            *pHuman++ = *pText++;
                        }
                        else if (pBarcode->iCheck == 'U')    // UCC check digit
                        {
                            if (isdigit(*pText) && *(pText + 1) == 0)
                            {
                                UccCheck += (*pText - '0') * 3;
                                UccCheck = (10 - UccCheck % 10) % 10;

                                *(Value + Len++) = (*pText - '0') * 10 + UccCheck;

                                *pHuman++ = *pText;            // put the human readable 
                                *pHuman++ = UccCheck + '0';    // put the check digit
                            }
                            pText += 1;
                        }
                        else
                            pText += 1;

                        break;
                }
                Code &= ~SHIFT_MASK;
            }
        }
        *pHuman = 0;
    }
    else if (pBarcode->iCheck == 1)    // Code 128M
    {
        CHAR Buf[4] = { 0,0,0,0 };
        INT Invocation;

        // check the start code
        if (*pText == '!' && pBarcode->eLanguage == LANG_TSPL)
        {
            memset(Buf, 0 ,sizeof(Buf));
            memcpy(Buf, pText + 1, 3);
            Invocation = atoi(Buf);
            if (Invocation >= 103 && Invocation <= 105) // Code A - Code C
            {
                Code = Invocation;
                pText += 4;
            }
        }

        *(Value + Len++) = Code;    // put the START value

        while (*pText != 0)
        {
            // check special character
            if (*pText == '!' && pBarcode->eLanguage == LANG_TSPL)
            {
                memset(Buf, 0 ,sizeof(Buf));
                memcpy(Buf, pText + 1, 3);
                Invocation = atoi(Buf);
                if (Invocation >= 96 && Invocation <= 102)
                {
                    *(Value + Len++) = Invocation;
                    pText += 4;
                }
                if (Invocation == 98 && (Code == CODE_A || Code == CODE_B))
                    Code |= SHIFT_MASK;
                if (Invocation == 99)
                    Code = CODE_C;
                if (Invocation == 100)
                    Code = CODE_B;
                if (Invocation == 101)
                    Code = CODE_A;
            }
            else    // data character 
            {
                switch (Code)        // change data character to value 
                {
                    //  ASCII  32 - 95   0 - 31
                    //          0 - 63  64 - 95
                    case CODE_A:
                    case (CODE_B | SHIFT_MASK):
                        if (*pText >= 32 && *pText <= 95)
                            *(Value + Len++) = *pText - 32;
                        else if (*pText <= 31)
                            *(Value + Len++) = *pText + 64;
                        else
                            return 0;
                        *pHuman++ = *pText++;    // put the human readable 
                        break;

                    //  ASCII  32 - 95   96 - 127
                    //          0 - 63   64 -  95
                    case CODE_B:
                    case (CODE_A | SHIFT_MASK):
                        if (*pText < 32 || *pText > 127)
                            return 0;
                        *(Value + Len++) = *pText - 32;
                        *pHuman++ = *pText++;    // put the human readable 
                        break;

                    // read pair and ASCII 48 - 57
                    case CODE_C:
                        if (isdigit(*pText) && isdigit(*(pText + 1)))
                        {
                            *(Value + Len++) = (*pText - '0') * 10 + *(pText + 1) - '0';
                            *pHuman++ = *pText++;    // put the human readable 
                            *pHuman++ = *pText++;
                        }
                        else
                            return 0;
                        break;
                }
                Code &= ~SHIFT_MASK;
            }
        }
        *pHuman = 0;
    }
    else    // code - 128 Auto 
    {
        INT digits;

        if (pBarcode->iCheck == 'A')
            Code = CODE_A;
        else if (pBarcode->iCheck == 'B')
            Code = CODE_B;
        else if (pBarcode->iCheck == 'C')
            Code = CODE_C;

        // four or more numeric digits causes an automatic shift to Subset C
        if ((digits = CheckNumeric(pBarcode, pText)) >= 4 && (digits % 2) == 0)
            Code = CODE_C;

        *(Value + Len++) = Code;    // put the START value

        while (*pText)
        {
            while (pBarcode->eLanguage == LANG_EPL)
            {
                if (memcmp(pText, "\"F1\"", 4) == 0)
                    *(Value + Len++) = FNC1;
                else if (memcmp(pText, "\"F2\"", 4) == 0 && Code != CODE_C)
                    *(Value + Len++) = FNC2;
                else if (memcmp(pText, "\"F3\"", 4) == 0 && Code != CODE_C)
                    *(Value + Len++) = FNC3;
                else if (memcmp(pText, "\"F4\"", 4) == 0 && Code == CODE_A)
                    *(Value + Len++) = FNC4A;
                else if (memcmp(pText, "\"F4\"", 4) == 0 && Code == CODE_B)
                    *(Value + Len++) = FNC4B;
                else
                    break;

                pText += 4;
            }

            // check special character
            if (*pText == '&' && pBarcode->eLanguage == LANG_DPL)
            {
                pText += 1;
                switch (*pText)
                {
                    case 'A':
                    case 'B':
                    case 'C':
                    case 'D':
                        if ((Code == CODE_A || Code == CODE_B) && *pText == 'C')
                            Code |= SHIFT_MASK;
                        *(Value + Len++) = *pText + 31;
                        if (*pText == 'D')
                            Code = CODE_C;
                        break;

                    case 'E':
                    case 'F':
                    case 'G':
                        if (Code == CODE_A && *pText == 'E')
                            Code = CODE_B;
                        if (Code == CODE_B && *pText == 'F')
                            Code = CODE_A;
                        if (Code == CODE_C && *pText == 'E')
                            Code = CODE_B;
                        if (Code == CODE_C && *pText == 'F')
                            Code = CODE_A;
                        *(Value + Len++) = *pText + 31;
                        break;

                    default:
                        break;
                }
                pText += 1;
            }
            else    // data character
            {
                // where to change code
                if (Code != CODE_C)
                {
                    // four or more numeric digits causes an automatic shift to Subset C
                    if ((digits = CheckNumeric(pBarcode, pText)) >= 4 && (digits % 2) == 0)
                    {
                        *(Value + Len++) = 99;    // change code B to C
                        Code = CODE_C;
                    }
                }

                switch (Code)    // change data character to value
                {
                    //  ASCII  32 - 95   96 - 127    CODE A  0 - 32
                    //          0 - 63   64 -  95           64 - 95
                    case CODE_B:
                    {
                        if (*pText < 32)    // CODE A
                        {
                            *(Value + Len++) = 98;            // shift data
                            *(Value + Len++) = *pText + 64;    // put the value
                        }
                        else
                            *(Value + Len++) = *pText - 32;    // put the value

                        *pHuman++ = *pText++;
                        break;
                    }

                    // read pair and ASCII '0' - '9'
                    case CODE_C:
                    {
                        if (isdigit(*pText) && isdigit(*(pText + 1)))
                        {
                            *(Value + Len++) = (*pText - '0') * 10 + *(pText + 1) - '0';
                            *pHuman++ = *pText++;
                            *pHuman++ = *pText++;
                        }
                        else
                        {
                            *(Value + Len++) = 100;    // change code C to B
                            Code = CODE_B;
                        }
                        break;
                    }
                }
            }
        }
        *pHuman = 0;
    }
    return Len;
}

INT Code128(_BarCodeAttr *psBarCodeAttr)
{
    _BarAttr sBarAttr;
    CHAR aValue[100], aHum[100];
    CHAR *pValue;
    INT iQuiet = QUIET_MU * psBarCodeAttr->iNarrow;
    INT iSum;    // use by check sum 
    INT i, num;

    /*
     * Decode
     */
    num = DecodeCode128(psBarCodeAttr, aValue, aHum);

    iSum = aValue[0];            /* get check character */
    for ( i = 1 ; i < num ; i++ )
    {
        iSum += aValue[i] * i;
    }
    aValue[num] = iSum % 103;
    num += 1;

    /*
     * Draw Bar
     */
    sBarAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;
    sBarAttr.iType = DRAW_BAR;

    switch ( psBarCodeAttr->iRotation )
    {
        case 0:
        {
            sBarAttr.iHeight = psBarCodeAttr->iHeight;
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX + iQuiet;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY;

            pValue = aValue;
            while ( num != 0 )            /* num is code-128 value number */
            {
                for ( i = 0 ; i < 6 ; i++ )
                {
                    sBarAttr.iWidth = CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                    DrawBar(&sBarAttr);
                    sBarAttr.sCoord.iX += sBarAttr.iWidth;

                    i += 1;
                    sBarAttr.sCoord.iX += CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                }
                pValue += 1;
                num -= 1;
            }

            for ( i = 0 ; i < 7 ; i++ )
            {
                sBarAttr.iWidth = StopCode[i] * psBarCodeAttr->iNarrow;
                DrawBar(&sBarAttr);
                sBarAttr.sCoord.iX += sBarAttr.iWidth;

                i += 1;
                sBarAttr.sCoord.iX += StopCode[i] * psBarCodeAttr->iNarrow;
            }
            psBarCodeAttr->TotalWidth = sBarAttr.sCoord.iX - (psBarCodeAttr->sCoord.iX + iQuiet);
            psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
            break;
        }
        case 90:
        {
            sBarAttr.iWidth = psBarCodeAttr->iHeight;
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - psBarCodeAttr->iHeight;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY + iQuiet;

            pValue = aValue;
            while ( num != 0 )            /* num is code-128 value number */
            {
                for ( i = 0 ; i < 6 ; i++ )
                {
                        sBarAttr.iHeight = CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                        DrawBar(&sBarAttr);
                        sBarAttr.sCoord.iY += sBarAttr.iHeight;

                        i += 1;
                        sBarAttr.sCoord.iY += CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                }
                pValue += 1;
                num -= 1;
            }

            for ( i = 0 ; i < 7 ; i++ )
            {
                    sBarAttr.iHeight = StopCode[i] * psBarCodeAttr->iNarrow;
                    DrawBar(&sBarAttr);
                    sBarAttr.sCoord.iY += sBarAttr.iHeight;

                    i += 1;
                    sBarAttr.sCoord.iY += StopCode[i] * psBarCodeAttr->iNarrow;
            }
            psBarCodeAttr->TotalWidth = sBarAttr.sCoord.iY - (psBarCodeAttr->sCoord.iY + iQuiet);
            psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
            break;
        }
        case 180:
        {
            sBarAttr.iHeight = psBarCodeAttr->iHeight;
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX - iQuiet;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - psBarCodeAttr->iHeight;

            pValue = aValue;
            while ( num != 0 )            /* num is code-128 value number */
            {
                for ( i = 0 ; i < 6 ; i++ )
                {
                    sBarAttr.iWidth = CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                    sBarAttr.sCoord.iX -= sBarAttr.iWidth;
                    DrawBar(&sBarAttr);

                    i += 1;
                    sBarAttr.sCoord.iX -= CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                }
                pValue += 1;
                num -= 1;
            }

            for ( i = 0 ; i < 7 ; i++ )
            {
                sBarAttr.iWidth = StopCode[i] * psBarCodeAttr->iNarrow;
                sBarAttr.sCoord.iX -= sBarAttr.iWidth;
                DrawBar(&sBarAttr);

                i += 1;
                sBarAttr.sCoord.iX -= StopCode[i] * psBarCodeAttr->iNarrow;
            }
            psBarCodeAttr->TotalWidth = (psBarCodeAttr->sCoord.iX - iQuiet) - sBarAttr.sCoord.iX;
            psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
            break;
        }
        case 270:
        {
            sBarAttr.iWidth = psBarCodeAttr->iHeight;
            sBarAttr.sCoord.iX = psBarCodeAttr->sCoord.iX;
            sBarAttr.sCoord.iY = psBarCodeAttr->sCoord.iY - iQuiet;

            pValue = aValue;
            while ( num != 0 )            /* num is code-128 value number */
            {
                for ( i = 0 ; i < 6 ; i++ )
                {
                    sBarAttr.iHeight = CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                    sBarAttr.sCoord.iY -= sBarAttr.iHeight;
                    DrawBar(&sBarAttr);

                    i += 1;
                    sBarAttr.sCoord.iY -= CodeTable[*pValue][i] * psBarCodeAttr->iNarrow;
                }
                pValue += 1;
                num -= 1;
            }

            for ( i = 0 ; i < 7 ; i++ )
            {
                sBarAttr.iHeight = StopCode[i] * psBarCodeAttr->iNarrow;
                sBarAttr.sCoord.iY -= sBarAttr.iHeight;
                DrawBar(&sBarAttr);

                i += 1;
                sBarAttr.sCoord.iY -= StopCode[i] * psBarCodeAttr->iNarrow;
            }
            psBarCodeAttr->TotalWidth = (psBarCodeAttr->sCoord.iY - iQuiet) - sBarAttr.sCoord.iY;
            psBarCodeAttr->TotalHeight = psBarCodeAttr->iHeight;
            break;
        }
    }
    
    /*
     * 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(aHum);
        sTextAttr.pExp       = (BYTE *)aHum;
        sTextAttr.pFont      = psBarCodeAttr->pFont;
        sTextAttr.eLanguage  = psBarCodeAttr->eLanguage;
        sTextAttr.ePutWay    = psBarCodeAttr->ePutWay;

        sTextAttr.psImageBuffer = psBarCodeAttr->psImageBuffer;

        PreviewText(&sTextAttr);

        switch ( psBarCodeAttr->iRotation )
        {
            case 0:
            {
                if ( psBarCodeAttr->AboveCode )
                    sTextAttr.sCoord.iY -= sTextAttr.iRealHeight + TEXT_DIS;
                else
                    sTextAttr.sCoord.iY += psBarCodeAttr->iHeight + TEXT_DIS;

                sTextAttr.sCoord.iX += iQuiet;
                if ( psBarCodeAttr->iHuman == 2 )
                    sTextAttr.sCoord.iX += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                else if ( psBarCodeAttr->iHuman == 3 )
                    sTextAttr.sCoord.iX = sBarAttr.sCoord.iX - sTextAttr.iRealWidth;

                break;
            }
            case 90:
            {
                if ( psBarCodeAttr->AboveCode )
                    sTextAttr.sCoord.iX += sTextAttr.iRealHeight + TEXT_DIS;
                else
                    sTextAttr.sCoord.iX -= psBarCodeAttr->iHeight + TEXT_DIS;

                sTextAttr.sCoord.iY += iQuiet;
                if ( psBarCodeAttr->iHuman == 2 )
                    sTextAttr.sCoord.iY += (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                else if ( psBarCodeAttr->iHuman == 3 )
                    sTextAttr.sCoord.iY = sBarAttr.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 -= iQuiet;
                if ( psBarCodeAttr->iHuman == 2 )
                    sTextAttr.sCoord.iX -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                else if ( psBarCodeAttr->iHuman == 3 )
                    sTextAttr.sCoord.iX = sBarAttr.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 -= iQuiet;
                if ( psBarCodeAttr->iHuman == 2 )
                    sTextAttr.sCoord.iY -= (psBarCodeAttr->TotalWidth - sTextAttr.iRealWidth) / 2;
                else if ( psBarCodeAttr->iHuman == 3 )
                    sTextAttr.sCoord.iY = sBarAttr.sCoord.iY + sTextAttr.iRealWidth;

                break;
            }
        }
        OutText(&sTextAttr);
        psBarCodeAttr->TotalHeight += sTextAttr.iRealHeight + TEXT_DIS;
        psBarCodeAttr->FontWidth = sTextAttr.iRealWidth;
        psBarCodeAttr->FontHeight = sTextAttr.iRealHeight + TEXT_DIS;
    }
    return TRUE;
}

INT PreviewCode128(_BarCodeAttr *psBarCodeAttr)
{
    CHAR aValue[100], aHum[100];
    INT Length;

    Length = DecodeCode128( psBarCodeAttr, aValue, aHum);

    psBarCodeAttr->TotalWidth = ((Length + 1) * 11 + 13) * psBarCodeAttr->iNarrow + 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(aHum);
        sTextAttr.pExp       = (BYTE *)aHum;
        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;
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值