Code128.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  1. // Code128.cpp: implementation of the CCode128 class.
  2. //
  3. // Copyright 2002 Neil Van Eps
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "stdafx.h"
  7. #include "Code128.h"
  8. //////////////////////////////////////////////////////////////////////
  9. // Construction/Destruction
  10. //////////////////////////////////////////////////////////////////////
  11. CCode128::CCode128()
  12. {
  13. // default to subset a
  14. m_nCurrentSubset = SUBSETA;
  15. // code 128
  16. m_nSymbology = COD128;
  17. }
  18. CCode128::~CCode128()
  19. {
  20. }
  21. ////////////////////////////////////////////////////////////////////////////////////
  22. //
  23. // Name:
  24. // DrawBitmap()
  25. //
  26. // Description:
  27. // draws a barcode using the previously loaded data
  28. //
  29. // Arguments:
  30. // none
  31. //
  32. // Return:
  33. // void
  34. //
  35. // Called by:
  36. // public class interface
  37. //
  38. ////////////////////////////////////////////////////////////////////////////////////
  39. void CCode128::DrawBitmap()
  40. {
  41. long nChar,nNextChar,nCharacterPosition,nCheckDigit;
  42. // calculate the check digit
  43. nCheckDigit = GetCheckDigit();
  44. // draw start character for current subset
  45. if (m_nCurrentSubset==SUBSETA)
  46. DrawPattern(RetrievePattern(103));
  47. else if (m_nCurrentSubset==SUBSETB)
  48. DrawPattern(RetrievePattern(104));
  49. else if (m_nCurrentSubset==SUBSETC)
  50. DrawPattern(RetrievePattern(105));
  51. // initialize position in message
  52. nCharacterPosition = 0;
  53. while (nCharacterPosition < m_csMessage.GetLength())
  54. {
  55. if (m_nCurrentSubset==SUBSETC)
  56. {
  57. // if it's a switch to subsetA - same character (103) for all subsets
  58. if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==101)
  59. {
  60. // draw the startA code
  61. DrawPattern(RetrievePattern(101));
  62. // we've moved one message character
  63. nCharacterPosition++;
  64. // actually change the subset
  65. m_nCurrentSubset = SUBSETA;
  66. }
  67. // if it's a switch to subsetB - same character (104) for all subsets
  68. else if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==100)
  69. {
  70. // draw the startB code
  71. DrawPattern(RetrievePattern(100));
  72. // we've moved one message character
  73. nCharacterPosition++;
  74. // actually change the subset
  75. m_nCurrentSubset = SUBSETB;
  76. }
  77. // it's FNC1 - just print it out
  78. else if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==102)
  79. {
  80. // draw the FNC1
  81. DrawPattern(RetrievePattern(100));
  82. // we've moved one message character
  83. nCharacterPosition++;
  84. }
  85. // it's a digit - pull two at a time
  86. else
  87. {
  88. CString csTemp;
  89. // get the next two characters
  90. csTemp = m_csMessage.Mid(nCharacterPosition,2);
  91. // convert them to longs
  92. nChar = atol((const char *)csTemp);
  93. // draw the code 128 character
  94. DrawPattern(RetrievePattern(nChar));
  95. // we've moved two message characters
  96. nCharacterPosition += 2;
  97. }
  98. }
  99. // we're in SUBSETA or SUBSETB
  100. else
  101. {
  102. // handle upper ASCII characters if necessary
  103. long nTemp2 = m_csMessage.GetAt(nCharacterPosition);
  104. if (nTemp2<-1)
  105. nTemp2 = nTemp2&255;
  106. // retrieve the message character
  107. nChar = g_nASCIItoCode128SubsetAB[m_nCurrentSubset][nTemp2];
  108. // draw the char
  109. DrawPattern(RetrievePattern(nChar));
  110. // we've moved one character position
  111. nCharacterPosition++;
  112. // if switch in SUBSETA
  113. if (m_nCurrentSubset==SUBSETA)
  114. {
  115. if (nChar==100)
  116. m_nCurrentSubset = SUBSETB;
  117. else if (nChar==99)
  118. m_nCurrentSubset = SUBSETC;
  119. }
  120. // if switch in SUBSETB
  121. else if (m_nCurrentSubset==SUBSETB)
  122. {
  123. if (nChar==101)
  124. m_nCurrentSubset = SUBSETA;
  125. else if (nChar==99)
  126. m_nCurrentSubset = SUBSETC;
  127. }
  128. // if a shift character
  129. else if (nChar==98)
  130. {
  131. // shift subsets for the next character only
  132. if (m_nCurrentSubset==SUBSETA)
  133. nNextChar = g_nASCIItoCode128SubsetAB[SUBSETB][m_csMessage.GetAt(nCharacterPosition)];
  134. else
  135. nNextChar = g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)];
  136. // draw the shifted character
  137. DrawPattern(RetrievePattern(nChar));
  138. // since we've handled two characters advance character position again
  139. nCharacterPosition++;
  140. }
  141. }
  142. }
  143. // draw check digit
  144. DrawPattern(RetrievePattern(nCheckDigit));
  145. // draw stop character
  146. DrawPattern(RetrievePattern(106));
  147. return;
  148. }
  149. ////////////////////////////////////////////////////////////////////////////////////
  150. //
  151. // Name:
  152. // BitmapToClipboard()
  153. //
  154. // Description:
  155. // puts the specified bitmap on the clipboard
  156. //
  157. // Arguments:
  158. // none
  159. //
  160. // Return:
  161. // void
  162. //
  163. // Called by:
  164. // public class interface - called by users of the class
  165. //
  166. ////////////////////////////////////////////////////////////////////////////////////
  167. void CCode128::BitmapToClipboard()
  168. {
  169. CDC memDC;
  170. CBitmap oBitmap;
  171. memDC.CreateCompatibleDC(NULL);
  172. m_hDC = memDC.GetSafeHdc();
  173. // create compatible, correctly sized bitmap
  174. oBitmap.CreateCompatibleBitmap(&memDC,m_nFinalBarcodePixelWidth,m_nPixelHeight);
  175. // select our bitmap into the device context
  176. CBitmap * oldbm = memDC.SelectObject(&oBitmap);
  177. // turn area white - stock black bitmap is selected
  178. memDC.BitBlt(0,0,m_nFinalBarcodePixelWidth,m_nPixelHeight,NULL,0,0,WHITENESS);
  179. // draw bitmap into memory device context
  180. DrawBitmap();
  181. // put bitmap on clipboard
  182. ::OpenClipboard(NULL);
  183. ::EmptyClipboard();
  184. ::SetClipboardData(CF_BITMAP, oBitmap.m_hObject);
  185. ::CloseClipboard();
  186. // deselect object out of device context
  187. memDC.SelectObject(oldbm);
  188. // make sure bitmap not deleted with CBitmap object
  189. oBitmap.Detach();
  190. return;
  191. }
  192. ////////////////////////////////////////////////////////////////////////////////////
  193. //
  194. // Name:
  195. // DrawPattern()
  196. //
  197. // Description:
  198. // draws the passed character pattern at the end of the barcode
  199. //
  200. // Arguments:
  201. // CString csPattern - the bar pattern to draw
  202. //
  203. // Return:
  204. // void
  205. //
  206. // Called by:
  207. // CCode128::DrawBitmap()
  208. //
  209. ////////////////////////////////////////////////////////////////////////////////////
  210. void CCode128::DrawPattern(CString csPattern)
  211. {
  212. int i,nXPixel,nYPixel;
  213. CDC oDC;
  214. // attach to the device context
  215. oDC.Attach(m_hDC);
  216. // initialize X pixel value
  217. nXPixel = m_nStartingXPixel;
  218. for (i=0;i<csPattern.GetLength();i++)
  219. {
  220. // X value for loop
  221. for (nXPixel=m_nStartingXPixel;nXPixel<m_nStartingXPixel+m_nNarrowBarPixelWidth;nXPixel++)
  222. {
  223. // Y value for loop
  224. for (nYPixel=m_nStartingYPixel;nYPixel<m_nStartingYPixel+m_nPixelHeight;nYPixel++)
  225. {
  226. // if this is a bar
  227. if (csPattern.GetAt(i)=='b')
  228. oDC.SetPixelV(nXPixel,nYPixel,COLORBLACK);
  229. else
  230. oDC.SetPixelV(nXPixel,nYPixel,COLORWHITE);
  231. }
  232. }
  233. // advance the starting position
  234. m_nStartingXPixel+= m_nNarrowBarPixelWidth;
  235. }
  236. // detach from the device context
  237. oDC.Detach();
  238. return;
  239. }
  240. ////////////////////////////////////////////////////////////////////////////////////
  241. //
  242. // Name:
  243. // RetrievePattern()
  244. //
  245. // Description:
  246. // retrieves the bar pattern for a given character
  247. //
  248. // Arguments:
  249. // char cInputCharacter - the input character to get the bar pattern for
  250. //
  251. // Return:
  252. // CString - the bar pattern for the input character
  253. //
  254. // Called by:
  255. // CCode128::DrawBitmap()
  256. //
  257. ////////////////////////////////////////////////////////////////////////////////////
  258. CString CCode128::RetrievePattern(long c)
  259. {
  260. CString csCharPattern;
  261. switch (c)
  262. {
  263. case 0:
  264. csCharPattern = "bbsbbssbbss";
  265. break;
  266. case 1:
  267. csCharPattern = "bbssbbsbbss";
  268. break;
  269. case 2:
  270. csCharPattern = "bbssbbssbbs";
  271. break;
  272. case 3:
  273. csCharPattern = "bssbssbbsss";
  274. break;
  275. case 4:
  276. csCharPattern = "bssbsssbbss";
  277. break;
  278. case 5:
  279. csCharPattern = "bsssbssbbss";
  280. break;
  281. case 6:
  282. csCharPattern = "bssbbssbsss";
  283. break;
  284. case 7:
  285. csCharPattern = "bssbbsssbss";
  286. break;
  287. case 8:
  288. csCharPattern = "bsssbbssbss";
  289. break;
  290. case 9:
  291. csCharPattern = "bbssbssbsss";
  292. break;
  293. case 10:
  294. csCharPattern = "bbssbsssbss";
  295. break;
  296. case 11:
  297. csCharPattern = "bbsssbssbss";
  298. break;
  299. case 12:
  300. csCharPattern = "bsbbssbbbss";
  301. break;
  302. case 13:
  303. csCharPattern = "bssbbsbbbss";
  304. break;
  305. case 14:
  306. csCharPattern = "bssbbssbbbs";
  307. break;
  308. case 15:
  309. csCharPattern = "bsbbbssbbss";
  310. break;
  311. case 16:
  312. csCharPattern = "bssbbbsbbss";
  313. break;
  314. case 17:
  315. csCharPattern = "bssbbbssbbs";
  316. break;
  317. case 18:
  318. csCharPattern = "bbssbbbssbs";
  319. break;
  320. case 19:
  321. csCharPattern = "bbssbsbbbss";
  322. break;
  323. case 20:
  324. csCharPattern = "bbssbssbbbs";
  325. break;
  326. case 21:
  327. csCharPattern = "bbsbbbssbss";
  328. break;
  329. case 22:
  330. csCharPattern = "bbssbbbsbss";
  331. break;
  332. case 23:
  333. csCharPattern = "bbbsbbsbbbs";
  334. break;
  335. case 24:
  336. csCharPattern = "bbbsbssbbss";
  337. break;
  338. case 25:
  339. csCharPattern = "bbbssbsbbss";
  340. break;
  341. case 26:
  342. csCharPattern = "bbbssbssbbs";
  343. break;
  344. case 27:
  345. csCharPattern = "bbbsbbssbss";
  346. break;
  347. case 28:
  348. csCharPattern = "bbbssbbsbss";
  349. break;
  350. case 29:
  351. csCharPattern = "bbbssbbssbs";
  352. break;
  353. case 30:
  354. csCharPattern = "bbsbbsbbsss";
  355. break;
  356. case 31:
  357. csCharPattern = "bbsbbsssbbs";
  358. break;
  359. case 32:
  360. csCharPattern = "bbsssbbsbbs";
  361. break;
  362. case 33:
  363. csCharPattern = "bsbsssbbsss";
  364. break;
  365. case 34:
  366. csCharPattern = "bsssbsbbsss";
  367. break;
  368. case 35:
  369. csCharPattern = "bsssbsssbbs";
  370. break;
  371. case 36:
  372. csCharPattern = "bsbbsssbsss";
  373. break;
  374. case 37:
  375. csCharPattern = "bsssbbsbsss";
  376. break;
  377. case 38:
  378. csCharPattern = "bsssbbsssbs";
  379. break;
  380. case 39:
  381. csCharPattern = "bbsbsssbsss";
  382. break;
  383. case 40:
  384. csCharPattern = "bbsssbsbsss";
  385. break;
  386. case 41:
  387. csCharPattern = "bbsssbsssbs";
  388. break;
  389. case 42:
  390. csCharPattern = "bsbbsbbbsss";
  391. break;
  392. case 43:
  393. csCharPattern = "bsbbsssbbbs";
  394. break;
  395. case 44:
  396. csCharPattern = "bsssbbsbbbs";
  397. break;
  398. case 45:
  399. csCharPattern = "bsbbbsbbsss";
  400. break;
  401. case 46:
  402. csCharPattern = "bsbbbsssbbs";
  403. break;
  404. case 47:
  405. csCharPattern = "bsssbbbsbbs";
  406. break;
  407. case 48:
  408. csCharPattern = "bbbsbbbsbbs";
  409. break;
  410. case 49:
  411. csCharPattern = "bbsbsssbbbs";
  412. break;
  413. case 50:
  414. csCharPattern = "bbsssbsbbbs";
  415. break;
  416. case 51:
  417. csCharPattern = "bbsbbbsbsss";
  418. break;
  419. case 52:
  420. csCharPattern = "bbsbbbsssbs";
  421. break;
  422. case 53:
  423. csCharPattern = "bbsbbbsbbbs";
  424. break;
  425. case 54:
  426. csCharPattern = "bbbsbsbbsss";
  427. break;
  428. case 55:
  429. csCharPattern = "bbbsbsssbbs";
  430. break;
  431. case 56:
  432. csCharPattern = "bbbsssbsbbs";
  433. break;
  434. case 57:
  435. csCharPattern = "bbbsbbsbsss";
  436. break;
  437. case 58:
  438. csCharPattern = "bbbsbbsssbs";
  439. break;
  440. case 59:
  441. csCharPattern = "bbbsssbbsbs";
  442. break;
  443. case 60:
  444. csCharPattern = "bbbsbbbbsbs";
  445. break;
  446. case 61:
  447. csCharPattern = "bbssbssssbs";
  448. break;
  449. case 62:
  450. csCharPattern = "bbbbsssbsbs";
  451. break;
  452. case 63:
  453. csCharPattern = "bsbssbbssss";
  454. break;
  455. case 64:
  456. csCharPattern = "bsbssssbbss";
  457. break;
  458. case 65:
  459. csCharPattern = "bssbsbbssss";
  460. break;
  461. case 66:
  462. csCharPattern = "bssbssssbbs";
  463. break;
  464. case 67:
  465. csCharPattern = "bssssbsbbss";
  466. break;
  467. case 68:
  468. csCharPattern = "bssssbssbbs";
  469. break;
  470. case 69:
  471. csCharPattern = "bsbbssbssss";
  472. break;
  473. case 70:
  474. csCharPattern = "bsbbssssbss";
  475. break;
  476. case 71:
  477. csCharPattern = "bssbbsbssss";
  478. break;
  479. case 72:
  480. csCharPattern = "bssbbssssbs";
  481. break;
  482. case 73:
  483. csCharPattern = "bssssbbsbss";
  484. break;
  485. case 74:
  486. csCharPattern = "bssssbbssbs";
  487. break;
  488. case 75:
  489. csCharPattern = "bbssssbssbs";
  490. break;
  491. case 76:
  492. csCharPattern = "bbssbsbssss";
  493. break;
  494. case 77:
  495. csCharPattern = "bbbbsbbbsbs";
  496. break;
  497. case 78:
  498. csCharPattern = "bbssssbsbss";
  499. break;
  500. case 79:
  501. csCharPattern = "bsssbbbbsbs";
  502. break;
  503. case 80:
  504. csCharPattern = "bsbssbbbbss";
  505. break;
  506. case 81:
  507. csCharPattern = "bssbsbbbbss";
  508. break;
  509. case 82:
  510. csCharPattern = "bssbssbbbbs";
  511. break;
  512. case 83:
  513. csCharPattern = "bsbbbbssbss";
  514. break;
  515. case 84:
  516. csCharPattern = "bssbbbbsbss";
  517. break;
  518. case 85:
  519. csCharPattern = "bssbbbbssbs";
  520. break;
  521. case 86:
  522. csCharPattern = "bbbbsbssbss";
  523. break;
  524. case 87:
  525. csCharPattern = "bbbbssbsbss";
  526. break;
  527. case 88:
  528. csCharPattern = "bbbbssbssbs";
  529. break;
  530. case 89:
  531. csCharPattern = "bbsbbsbbbbs";
  532. break;
  533. case 90:
  534. csCharPattern = "bbsbbbbsbbs";
  535. break;
  536. case 91:
  537. csCharPattern = "bbbbsbbsbbs";
  538. break;
  539. case 92:
  540. csCharPattern = "bsbsbbbbsss";
  541. break;
  542. case 93:
  543. csCharPattern = "bsbsssbbbbs";
  544. break;
  545. case 94:
  546. csCharPattern = "bsssbsbbbbs";
  547. break;
  548. case 95:
  549. csCharPattern = "bsbbbbsbsss";
  550. break;
  551. case 96:
  552. csCharPattern = "bsbbbbsssbs";
  553. break;
  554. case 97:
  555. csCharPattern = "bbbbsbsbsss";
  556. break;
  557. case 98:
  558. csCharPattern = "bbbbsbsssbs";
  559. break;
  560. case 99:
  561. csCharPattern = "bsbbbsbbbbs";
  562. break;
  563. case 100:
  564. csCharPattern = "bsbbbbsbbbs";
  565. break;
  566. case 101:
  567. csCharPattern = "bbbsbsbbbbs";
  568. break;
  569. case 102:
  570. csCharPattern = "bbbbsbsbbbs";
  571. break;
  572. case 103:
  573. csCharPattern = "bbsbsbbbbss";
  574. break;
  575. case 104:
  576. csCharPattern = "bbsbssbssss";
  577. break;
  578. case 105:
  579. csCharPattern = "bbsbssbbbss";
  580. break;
  581. case 106:
  582. csCharPattern = "bbsssbbbsbsbb";
  583. break;
  584. }
  585. return csCharPattern;
  586. }
  587. ////////////////////////////////////////////////////////////////////////////////////
  588. //
  589. // Name:
  590. // AddCheckDigitToMessage()
  591. //
  592. // Description:
  593. // adds the code 128 check digit to the end of the message
  594. //
  595. // Arguments:
  596. // none
  597. //
  598. // Return:
  599. // void
  600. //
  601. // Called by:
  602. // DrawBitmap()
  603. //
  604. ////////////////////////////////////////////////////////////////////////////////////
  605. long CCode128::GetCheckDigit()
  606. {
  607. long nSum=0,nCurrentSubset=0,nCode128Char,nNextChar,nWeight,nCharacterPosition;
  608. // start character
  609. if (m_nCurrentSubset==SUBSETA)
  610. {
  611. nSum = 103;
  612. nCurrentSubset = SUBSETA;
  613. }
  614. else if (m_nCurrentSubset==SUBSETB)
  615. {
  616. nSum = 104;
  617. nCurrentSubset = SUBSETB;
  618. }
  619. else if (m_nCurrentSubset==SUBSETC)
  620. {
  621. nSum = 105;
  622. nCurrentSubset = SUBSETC;
  623. }
  624. // intialize the values
  625. nCharacterPosition = 0;
  626. nWeight = 1;
  627. while (nCharacterPosition<(m_csMessage.GetLength()))
  628. {
  629. // if SUBSETC
  630. if (nCurrentSubset==SUBSETC)
  631. {
  632. // if it's a switch to SUBSETA - same character in all subsets
  633. if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==101)
  634. {
  635. // we're switching to subsetA
  636. nCode128Char = 101;
  637. // add the change subset character to the sum
  638. nSum+= (nWeight*nCode128Char);
  639. // we've moved one message character
  640. nCharacterPosition++;
  641. // we've moved one weight value
  642. nWeight++;
  643. // actually change the subset
  644. nCurrentSubset = SUBSETA;
  645. }
  646. // if it's a switch to SUBSETB - same character in all subsets
  647. else if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==100)
  648. {
  649. // we're switching to subset B
  650. nCode128Char = 100;
  651. // add the change subset character to the sum
  652. nSum+= (nWeight*nCode128Char);
  653. // we've moved one message character
  654. nCharacterPosition++;
  655. // we've moved one weight value
  656. nWeight++;
  657. // actually switch the subset
  658. nCurrentSubset = SUBSETB;
  659. }
  660. // it's FNC1 - just print it out
  661. else if (g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)]==102)
  662. {
  663. // we're switching to subset B
  664. nCode128Char = 102;
  665. // add the change subset character to the sum
  666. nSum+= (nWeight*nCode128Char);
  667. // we've moved one message character
  668. nCharacterPosition++;
  669. // we've moved one weight value
  670. nWeight++;
  671. }
  672. // its a digit - process two at a time
  673. else
  674. {
  675. CString csTemp;
  676. // get the next two characters
  677. csTemp = m_csMessage.Mid(nCharacterPosition,2);
  678. // convert them to longs
  679. nCode128Char = atol((const char *)csTemp);
  680. // add the weighted balue
  681. nSum += (nWeight*nCode128Char);
  682. // we've moved two message characters
  683. nCharacterPosition += 2;
  684. // we've moved one weight value
  685. nWeight++;
  686. }
  687. }
  688. // it's SUBSETA or SUBSETB
  689. else
  690. {
  691. // handle upper ASCII characters if necessary
  692. long nTemp2 = m_csMessage.GetAt(nCharacterPosition);
  693. if (nTemp2<-1)
  694. nTemp2 = nTemp2&255;
  695. // retrieve the message character
  696. nCode128Char = g_nASCIItoCode128SubsetAB[nCurrentSubset][nTemp2];
  697. // add the weighted value to our sum
  698. nSum+= (nWeight*nCode128Char);
  699. // we've moved one character position
  700. nCharacterPosition++;
  701. // we've moved one weight value
  702. nWeight++;
  703. // if switch in SUBSETA
  704. if (nCurrentSubset==SUBSETA)
  705. {
  706. if (nCode128Char==100)
  707. nCurrentSubset = SUBSETB;
  708. else if (nCode128Char==99)
  709. nCurrentSubset = SUBSETC;
  710. }
  711. // if switch in SUBSETB
  712. else if (nCurrentSubset==SUBSETB)
  713. {
  714. if (nCode128Char==101)
  715. nCurrentSubset = SUBSETA;
  716. else if (nCode128Char==99)
  717. nCurrentSubset = SUBSETC;
  718. }
  719. // handle single character switch
  720. else if (nCode128Char==98)
  721. {
  722. // shift subsets for the next character only
  723. if (nCurrentSubset==SUBSETA)
  724. nNextChar = g_nASCIItoCode128SubsetAB[SUBSETB][m_csMessage.GetAt(nCharacterPosition)];
  725. else
  726. nNextChar = g_nASCIItoCode128SubsetAB[SUBSETA][m_csMessage.GetAt(nCharacterPosition)];
  727. // add weighted value to the sum
  728. nSum += (nWeight*nNextChar);
  729. // since we've handled two characters advance position and weight again
  730. nCharacterPosition++;
  731. nWeight++;
  732. }
  733. }
  734. }
  735. // return the modulus
  736. return (nSum%103);
  737. }
  738. ////////////////////////////////////////////////////////////////////////////////////
  739. //
  740. // Name:
  741. // LoadData()
  742. //
  743. // Description:
  744. // overridden to include starting subset
  745. //
  746. // Arguments:
  747. // CString csMessage
  748. // int nSymbology
  749. // double dNarrowBar
  750. // double dFinalHeight
  751. // HDC pDC
  752. // int nStartingXPixel
  753. // int nStartingYPixel
  754. // double dRatio
  755. // long nStartingSubset
  756. //
  757. // Return:
  758. // void
  759. //
  760. // Called by:
  761. // public class interface
  762. //
  763. ////////////////////////////////////////////////////////////////////////////////////
  764. void CCode128::LoadData(CString csMessage, double dNarrowBar, double dFinalHeight, HDC pDC, int nStartingXPixel, int nStartingYPixel, long nStartingSubset )
  765. {
  766. // call base class version
  767. CBarcode::LoadData(csMessage, dNarrowBar, dFinalHeight, pDC, nStartingXPixel, nStartingYPixel);
  768. // set additional data
  769. m_nCurrentSubset = nStartingSubset;
  770. }