| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- // Code39.cpp: implementation of the CCode39 class.
- //
- // Copyright 2002 Neil Van Eps
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "Code39.h"
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CCode39::CCode39()
- {
- // code 39
- m_nSymbology = CODE39;
- }
- CCode39::~CCode39()
- {
- }
- ////////////////////////////////////////////////////////////////////////////////////
- //
- // Name:
- // DrawBitmap()
- //
- // Description:
- // draws a barcode using the previously loaded data
- //
- // Arguments:
- // none
- //
- // Return:
- // void
- //
- // Called by:
- // public class interface
- //
- ////////////////////////////////////////////////////////////////////////////////////
- void CCode39::DrawBitmap()
- {
- int i;
- CString csCurrentPattern;
- // draw start character, an asterisk
- DrawPattern(RetrievePattern('*'));
-
- // draw each character in the message
- for (i=0;i<m_csMessage.GetLength();i++)
- DrawPattern(RetrievePattern(m_csMessage.GetAt(i)));
- // draw stop character, also an asterisk
- DrawPattern(RetrievePattern('*'));
- return;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- //
- // Name:
- // DrawPattern()
- //
- // Description:
- // draws the passed character pattern at the end of the barcode
- //
- // Arguments:
- // CString csPattern - the bar pattern to draw
- //
- // Return:
- // void
- //
- // Called by:
- // CRationalCodabar::DrawBitmap()
- //
- ////////////////////////////////////////////////////////////////////////////////////
- void CCode39::DrawPattern( CString csPattern )
- {
- int i,nXPixel,nYPixel,nTempWidth;
- CDC oDC;
- // attach to the device context
- oDC.Attach(m_hDC);
- // initialize X pixel value
- nXPixel = m_nStartingXPixel;
-
- for (i=0;i<csPattern.GetLength();i++)
- {
- // decide if narrow or wide bar
- if (csPattern.GetAt(i)=='n')
- nTempWidth = m_nNarrowBarPixelWidth;
- else
- nTempWidth = m_nWideBarPixelWidth;
-
- // X value for loop
- for (nXPixel=m_nStartingXPixel;nXPixel<m_nStartingXPixel+nTempWidth;nXPixel++)
- {
- // Y value for loop
- for (nYPixel=m_nStartingYPixel;nYPixel<m_nStartingYPixel+m_nPixelHeight;nYPixel++)
- {
- // if this is a bar
- if (i%2==0)
- oDC.SetPixelV(nXPixel,nYPixel,COLORBLACK);
- else
- oDC.SetPixelV(nXPixel,nYPixel,COLORWHITE);
- }
- }
- // advance the starting position
- m_nStartingXPixel+= nTempWidth;
- }
- // detach from the device context
- oDC.Detach();
-
- return;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- //
- // Name:
- // RetrievePattern()
- //
- // Description:
- // retrieves the bar pattern for a given character
- //
- // Arguments:
- // char cInputCharacter - the input character to get the bar pattern for
- //
- // Return:
- // CString - the bar pattern for the input character
- //
- // Called by:
- // CRationalCodabar::DrawBitmap()
- //
- ////////////////////////////////////////////////////////////////////////////////////
- CString CCode39::RetrievePattern(char c)
- {
- CString csCharPattern;
- switch (c)
- {
- case '1':
- csCharPattern = "wnnwnnnnwn";
- break;
- case '2':
- csCharPattern = "nnwwnnnnwn";
- break;
- case '3':
- csCharPattern = "wnwwnnnnnn";
- break;
- case '4':
- csCharPattern = "nnnwwnnnwn";
- break;
- case '5':
- csCharPattern = "wnnwwnnnnn";
- break;
- case '6':
- csCharPattern = "nnwwwnnnnn";
- break;
- case '7':
- csCharPattern = "nnnwnnwnwn";
- break;
- case '8':
- csCharPattern = "wnnwnnwnnn";
- break;
- case '9':
- csCharPattern = "nnwwnnwnnn";
- break;
- case '0':
- csCharPattern = "nnnwwnwnnn";
- break;
- case 'A':
- csCharPattern = "wnnnnwnnwn";
- break;
- case 'B':
- csCharPattern = "nnwnnwnnwn";
- break;
- case 'C':
- csCharPattern = "wnwnnwnnnn";
- break;
- case 'D':
- csCharPattern = "nnnnwwnnwn";
- break;
- case 'E':
- csCharPattern = "wnnnwwnnnn";
- break;
- case 'F':
- csCharPattern = "nnwnwwnnnn";
- break;
- case 'G':
- csCharPattern = "nnnnnwwnwn";
- break;
- case 'H':
- csCharPattern = "wnnnnwwnnn";
- break;
- case 'I':
- csCharPattern = "nnwnnwwnnn";
- break;
- case 'J':
- csCharPattern = "nnnnwwwnnn";
- break;
- case 'K':
- csCharPattern = "wnnnnnnwwn";
- break;
- case 'L':
- csCharPattern = "nnwnnnnwwn";
- break;
- case 'M':
- csCharPattern = "wnwnnnnwnn";
- break;
- case 'N':
- csCharPattern = "nnnnwnnwwn";
- break;
- case 'O':
- csCharPattern = "wnnnwnnwnn";
- break;
- case 'P':
- csCharPattern = "nnwnwnnwnn";
- break;
- case 'Q':
- csCharPattern = "nnnnnnwwwn";
- break;
- case 'R':
- csCharPattern = "wnnnnnwwnn";
- break;
- case 'S':
- csCharPattern = "nnwnnnwwnn";
- break;
- case 'T':
- csCharPattern = "nnnnwnwwnn";
- break;
- case 'U':
- csCharPattern = "wwnnnnnnwn";
- break;
- case 'V':
- csCharPattern = "nwwnnnnnwn";
- break;
- case 'W':
- csCharPattern = "wwwnnnnnnn";
- break;
- case 'X':
- csCharPattern = "nwnnwnnnwn";
- break;
- case 'Y':
- csCharPattern = "wwnnwnnnnn";
- break;
- case 'Z':
- csCharPattern = "nwwnwnnnnn";
- break;
- case '-':
- csCharPattern = "nwnnnnwnwn";
- break;
- case '.':
- csCharPattern = "wwnnnnwnnn";
- break;
- case ' ':
- csCharPattern = "nwwnnnwnnn";
- break;
- case '*':
- csCharPattern = "nwnnwnwnnn";
- break;
- case '$':
- csCharPattern = "nwnwnwnnnn";
- break;
- case '/':
- csCharPattern = "nwnwnnnwnn";
- break;
- case '+':
- csCharPattern = "nwnnnwnwnn";
- break;
- case '%':
- csCharPattern = "nnnwnwnwnn";
- break;
- }
- return csCharPattern;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- //
- // Name:
- // BitmapToClipboard()
- //
- // Description:
- // puts the specified bitmap on the clipboard
- //
- // Arguments:
- // none
- //
- // Return:
- // void
- //
- // Called by:
- // public class interface - called by users of the class
- //
- ////////////////////////////////////////////////////////////////////////////////////
- void CCode39::BitmapToClipboard()
- {
- CDC memDC;
- CBitmap oBitmap;
- memDC.CreateCompatibleDC(NULL);
- m_hDC = memDC.GetSafeHdc();
- // create compatible, correctly sized bitmap
- oBitmap.CreateCompatibleBitmap(&memDC,m_nFinalBarcodePixelWidth,m_nPixelHeight);
- // select our bitmap into the device context
- CBitmap * oldbm = memDC.SelectObject(&oBitmap);
- // turn area white - stock black bitmap is selected
- memDC.BitBlt(0,0,m_nFinalBarcodePixelWidth,m_nPixelHeight,NULL,0,0,WHITENESS);
- // draw bitmap into memory device context
- DrawBitmap();
-
- // put bitmap on clipboard
- ::OpenClipboard(NULL);
- ::EmptyClipboard();
- ::SetClipboardData(CF_BITMAP, oBitmap.m_hObject);
- ::CloseClipboard();
-
- // deselect object out of device context
- memDC.SelectObject(oldbm);
- // make sure bitmap not deleted with CBitmap object
- oBitmap.Detach();
- return;
- }
|