Barcode.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // Barcode.cpp: implementation of the CBarcode class.
  2. //
  3. // Copyright 2002 Neil Van Eps
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "stdafx.h"
  7. #include "Barcode.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CBarcode::CBarcode()
  12. {
  13. }
  14. CBarcode::~CBarcode()
  15. {
  16. }
  17. ////////////////////////////////////////////////////////////////////////////////////
  18. //
  19. // Name:
  20. // LoadData()
  21. //
  22. // Description:
  23. //
  24. //
  25. // Arguments:
  26. //
  27. //
  28. // Return:
  29. //
  30. //
  31. // Called by:
  32. //
  33. //
  34. ////////////////////////////////////////////////////////////////////////////////////
  35. void CBarcode::LoadData(CString csMessage, double dNarrowBar, double dFinalHeight, HDC pDC, int nStartingXPixel, int nStartingYPixel, double dRatio )
  36. {
  37. int i,nXAxisDpi,nYAxisDpi,nTemp;
  38. char c;
  39. // values that can be saved without translation
  40. m_csMessage = csMessage;
  41. m_nStartingXPixel = nStartingXPixel;
  42. m_nStartingYPixel = nStartingYPixel;
  43. m_hDC = pDC;
  44. // calculate X and Y Axis dots per inch
  45. if (m_hDC==NULL)
  46. {
  47. CDC memDC;
  48. // create the memory device context - will be compatible with the screen
  49. memDC.CreateCompatibleDC(NULL);
  50. // get dpi for the two axes
  51. nXAxisDpi = memDC.GetDeviceCaps(LOGPIXELSX);
  52. nYAxisDpi = memDC.GetDeviceCaps(LOGPIXELSY);
  53. }
  54. else
  55. {
  56. CDC tempDC;
  57. tempDC.Attach(m_hDC);
  58. nXAxisDpi = tempDC.GetDeviceCaps(LOGPIXELSX);
  59. nYAxisDpi = tempDC.GetDeviceCaps(LOGPIXELSY);
  60. tempDC.Detach();
  61. }
  62. // load the final attributes that depend on the device context
  63. m_nPixelHeight = (int)((nYAxisDpi*dFinalHeight)+0.5);
  64. m_nNarrowBarPixelWidth = (int)((nXAxisDpi*dNarrowBar)+0.5);
  65. m_nWideBarPixelWidth = (int)(dRatio*m_nNarrowBarPixelWidth);
  66. switch (m_nSymbology)
  67. {
  68. case RATIONALCODABAR:
  69. // initialize to zero
  70. m_nFinalBarcodePixelWidth = 0;
  71. // add the width of each character
  72. for (i=0;i<csMessage.GetLength();i++)
  73. {
  74. c = csMessage.GetAt(i);
  75. switch (c)
  76. {
  77. case '0':
  78. case '1':
  79. case '2':
  80. case '3':
  81. case '4':
  82. case '5':
  83. case '6':
  84. case '7':
  85. case '8':
  86. case '9':
  87. case '-':
  88. case '$':
  89. m_nFinalBarcodePixelWidth += (6*m_nNarrowBarPixelWidth)+(2*m_nWideBarPixelWidth);
  90. break;
  91. case ':':
  92. case '/':
  93. case '.':
  94. case '+':
  95. case 'A':
  96. case 'B':
  97. case 'C':
  98. case 'D':
  99. m_nFinalBarcodePixelWidth += (5*m_nNarrowBarPixelWidth)+(3*m_nWideBarPixelWidth);
  100. break;
  101. }
  102. }
  103. break;
  104. case I2OF5:
  105. // add start code
  106. m_nFinalBarcodePixelWidth = 4 * m_nNarrowBarPixelWidth;
  107. // add message
  108. m_nFinalBarcodePixelWidth += ((3*m_nNarrowBarPixelWidth)+(2*m_nWideBarPixelWidth))*m_csMessage.GetLength();
  109. // add stop code
  110. m_nFinalBarcodePixelWidth += (2*m_nNarrowBarPixelWidth)+(m_nWideBarPixelWidth);
  111. break;
  112. case CODE39:
  113. // get final character width
  114. nTemp = m_csMessage.GetLength() + 2;
  115. // add message
  116. m_nFinalBarcodePixelWidth = nTemp * ((3*m_nWideBarPixelWidth) + (7*m_nNarrowBarPixelWidth));
  117. break;
  118. case COD128:
  119. // get final character width
  120. nTemp = m_csMessage.GetLength();
  121. m_nFinalBarcodePixelWidth = ((nTemp*11)+35)*m_nNarrowBarPixelWidth;
  122. break;
  123. case CODE93:
  124. // get final character width
  125. nTemp = m_csMessage.GetLength();
  126. m_nFinalBarcodePixelWidth = (((nTemp+4)*9)+1)*m_nNarrowBarPixelWidth;
  127. case UPCA:
  128. case UPCE:
  129. break;
  130. case TRADITIONALCODABAR:
  131. break;
  132. case EAN13:
  133. case EAN8:
  134. break;
  135. }
  136. return;
  137. }
  138. long CBarcode::GetBarcodePixelHeight()
  139. {
  140. return m_nPixelHeight;
  141. }
  142. long CBarcode::GetBarcodePixelWidth()
  143. {
  144. return m_nFinalBarcodePixelWidth;
  145. }