Barcode.txt 134 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666
  1. **********************
  2. C++ʵÏÖ
  3. **********************
  4. /*****************************************************************/
  5. /* ANSI C Functions for IDAutomation Barcode Fonts */
  6. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  7. /* All rights reserved. */
  8. /* Redistribution and use of this code in source and/or binary */
  9. /* forms, with or without modification, are permitted provided */
  10. /* that: (1) all copies of the source code retain the above */
  11. /* unmodified copyright notice and this entire unmodified */
  12. /* section of text, (2) You or Your organization owns a valid */
  13. /* Developer License to this product from IDAutomation.com */
  14. /* and, (3) when any portion of this code is bundled in any */
  15. /* form with an application, a valid notice must be provided */
  16. /* within the user documentation, start-up screen or in the */
  17. /* help-about section of the application that specifies */
  18. /* IDAutomation.com as the provider of the Software bundled */
  19. /* with the application. */
  20. /*****************************************************************/
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <math.h>
  25. #include <ctype.h>
  26. /* ------------------------ */
  27. /* System Variables */
  28. /* ------------------------ */
  29. static int StrCnt;
  30. static char StrFunction [64][257];
  31. /* ---------------------- */
  32. /* Standard Prototypes */
  33. /* ---------------------- */
  34. extern int asc (char *);
  35. extern char *mid (char *, int, int);
  36. char FindMod10Digit(char *);
  37. char *CalcMSICheckDigit(char *);
  38. /* ------------------- */
  39. /* User's Prototypes */
  40. /* ------------------- */
  41. static int TRUE = 1;
  42. static int FALSE = 0;
  43. long IDAutomation_UPCe(char *pcDataToEncode, char *szReturnVal, long iSize);;
  44. long IDAutomation_Codabar(char *pcDataToEncode, char *szReturnVal, long iSize);;
  45. long IDAutomation_Code128a(char *pcDataToEncode, char *szReturnVal, long iSize);;
  46. long IDAutomation_Code128b(char *pcDataToEncode, char *szReturnVal, long iSize);
  47. long IDAutomation_Code128c(char *pcDataToEncode, char *szReturnVal, long iSize);
  48. long IDAutomation_Interleaved2of5(char *pcDataToEncode, char *szReturnVal, long iSize);
  49. long IDAutomation_Interleaved2of5Mod10(char *pcDataToEncode, char *szReturnVal, long iSize);
  50. long IDAutomation_Code39(char *pcDataToEncode, char *szReturnVal, long iSize);
  51. long IDAutomation_Code39Mod43(char *pcDataToEncode, char *szReturnVal, long iSize);
  52. long IDAutomation_EAN8(char *pcDataToEncode, char *szReturnVal, long iSize);
  53. long IDAutomation_EAN13(char *pcDataToEncode, char *szReturnVal, long iSize);
  54. long IDAutomation_UPCa(char *pcDataToEncode, char *szReturnVal, long iSize);
  55. long IDAutomation_MSI(char *pcDataToEncode, char *szReturnVal, long iSize);
  56. long IDAutomation_Postnet(char *pcDataToEncode, char *szReturnVal, long iSize);
  57. long IDAutomation_Code128(char *DataToEncode, int ApplyTilde, char *szReturnVal, long iSize);
  58. long IDAutomation_Code128HumanReadable(char *DataToEncode, int ApplyTilde, char *szReturnVal, long iSize);
  59. long IDAutomation_UCC128(char *DataToEncode, char *szReturnVal, long iSize);
  60. long IDAutomation_Code93(char *DataToEncode, char *szReturnVal, long iSize);
  61. /* --------------------- */
  62. /* Run Time Functions */
  63. /* --------------------- */
  64. //CMemLeadDetect memLeakDetect;///mem leak
  65. char* strupr(char* str)
  66. {
  67. char returnString[512];
  68. /*//char *returnString = new char[512] ;*/
  69. int PrintBuffer=0;
  70. int x=0;
  71. for (x=1;x<= (int)strlen(str);++x)
  72. {
  73. int CurrentValue = asc(mid(str, x, 1));
  74. if (CurrentValue >= 97 && CurrentValue <= 122)
  75. PrintBuffer += sprintf(returnString + PrintBuffer ,"%c", CurrentValue - 32);
  76. else
  77. PrintBuffer += sprintf(returnString + PrintBuffer ,"%c", CurrentValue );
  78. }
  79. sprintf(str,"%s",returnString);
  80. return (char*)str;
  81. }
  82. char* strrev(char* str)
  83. {
  84. if (NULL==str)return str;
  85. int l=strlen(str)-1;
  86. if (1==l)return str;
  87. int x=0;
  88. for(x=0;x<l;x++,l--)
  89. {
  90. str[x]^=str[l];
  91. str[l]^=str[x];
  92. str[x]^=str[l];
  93. }
  94. l=0;
  95. return (char*)str;
  96. }
  97. extern char *mid(char *S, int start, int length)
  98. {
  99. if(++StrCnt==64)
  100. {
  101. StrCnt = 0;
  102. }
  103. if (start > (int) strlen(S))
  104. {
  105. StrFunction[StrCnt][0]='\0';
  106. }
  107. else
  108. {
  109. strncpy (StrFunction[StrCnt], &S [start-1], length);
  110. }
  111. StrFunction[StrCnt][length]='\0';
  112. return StrFunction[StrCnt];
  113. }
  114. extern int asc(char *z)
  115. {
  116. static int q;
  117. q = 0;
  118. memmove(&q,z,1);
  119. return q;
  120. }
  121. /* ---------------------- */
  122. /* User Subs/Functions */
  123. /* ---------------------- */
  124. long IDAutomation_Code128a(char *DataToEncode, char *output, long iSize)
  125. {
  126. if(DataToEncode == NULL)
  127. return 1;
  128. if(strlen(DataToEncode) == 0)
  129. return 1;
  130. char DataToPrint[512];
  131. //DataToPrint = new char[512];
  132. char PrintableString[512];
  133. //PrintableString = new char[512];
  134. int C128Start;
  135. int C128StartA;
  136. int C128StartB;
  137. int C128StartC;
  138. int C128Stop;
  139. int weightedTotal;
  140. int I;
  141. int CurrentChar;
  142. int CurrentValue;
  143. int CheckDigitValue;
  144. int CheckDigit;
  145. char C128CheckDigit;
  146. //char C128CurrentChar;
  147. int C128CurrentChar;
  148. int BufferCounter = 0;
  149. C128StartA=203;
  150. C128StartB=204;
  151. C128StartC=205;
  152. C128Stop=206;
  153. /* Here we select character set A */
  154. C128Start=C128StartA;
  155. /* <<<< Calculate Modulo 103 Check Digit >>>> */
  156. /* Set WeightedTotal to the value of the start character */
  157. weightedTotal=C128Start-100;
  158. for(I=1;I <= (int)strlen(DataToEncode);I++)
  159. {
  160. /* Get the ASCII value of each character */
  161. CurrentChar=(asc(mid(DataToEncode,I,1)));
  162. /* Get the Code 128 value of CurrentChar according to chart */
  163. if(CurrentChar<135) {CurrentValue=CurrentChar-32;}
  164. if(CurrentChar>134) {CurrentValue=CurrentChar-100;}
  165. /* Multiply by the weighting character */
  166. CurrentValue=CurrentValue*I;
  167. /* Add the values together to get the weighted total*/
  168. weightedTotal=weightedTotal+CurrentValue;
  169. }
  170. /* divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue*/
  171. CheckDigitValue = (int) (weightedTotal % 103);
  172. /* Now that we have the CheckDigitValue, find the corresponding ASCII character from the table */
  173. if(CheckDigitValue < 95 && CheckDigitValue > 0)
  174. {
  175. CheckDigit = CheckDigitValue + 32;
  176. }
  177. if(CheckDigitValue > 94)
  178. {
  179. CheckDigit = CheckDigitValue + 100;
  180. }
  181. if(CheckDigitValue == 0)
  182. {
  183. CheckDigit = 194;
  184. }
  185. C128CheckDigit=CheckDigit;
  186. /* for(I=1;I <= (int)strlen(DataToEncode);I++)
  187. {
  188. C128CurrentChar = asc((mid(DataToEncode,I,1)));
  189. //if(C128CurrentChar==' ')
  190. if(C128CurrentChar==32)
  191. {
  192. //C128CurrentChar=(char)194;
  193. C128CurrentChar=194;
  194. }
  195. //BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", DataToEncode[I-1]);
  196. BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
  197. //strcat(DataToPrint,&C128CurrentChar);
  198. }
  199. */
  200. /* Check for spaces or "00" and print ASCII 194 instead */
  201. /* place changes in DataToPrint */
  202. BufferCounter = 0;
  203. for(I=1;I <= (int)strlen(DataToEncode);I++)
  204. {
  205. C128CurrentChar=DataToEncode[I-1];
  206. if(C128CurrentChar==' ')
  207. {
  208. C128CurrentChar = (char)194;
  209. }
  210. BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
  211. }
  212. /* Get PrintableString */
  213. sprintf(PrintableString,"%c%s%c%c",C128Start,DataToPrint,C128CheckDigit,C128Stop);
  214. iSize = (long)strlen(PrintableString);
  215. strncpy(output, PrintableString, strlen(PrintableString));
  216. return 0;
  217. }
  218. long IDAutomation_Code128b(char *DataToEncode, char *output, long iSize)
  219. {
  220. if(DataToEncode == NULL)
  221. return 1;
  222. if(strlen(DataToEncode) == 0)
  223. return 1;
  224. char DataToPrint[512];
  225. //DataToPrint = new char;
  226. char PrintableString[512];
  227. //PrintableString = new char[512];
  228. int BufferCounter = 0;
  229. int C128Start;
  230. int C128StartA;
  231. int C128StartB;
  232. int C128StartC;
  233. int C128Stop;
  234. int weightedTotal;
  235. int I;
  236. int CurrentChar;
  237. int CurrentValue;
  238. int CheckDigitValue;
  239. int CheckDigit;
  240. char C128CheckDigit;
  241. char C128CurrentChar;
  242. C128StartA=203;
  243. C128StartB=204;
  244. C128StartC=205;
  245. C128Stop=206;
  246. /* Here we select character set A */
  247. C128Start=C128StartB;
  248. /* <<<< Calculate Modulo 103 Check Digit >>>> */
  249. /* Set WeightedTotal to the value of the start character */
  250. weightedTotal=C128Start-100;
  251. for(I=1;I <= (int)strlen(DataToEncode);I++)
  252. {
  253. /* Get the ASCII value of each character */
  254. CurrentChar=(asc(mid(DataToEncode,I,1)));
  255. /* Get the Code 128 value of CurrentChar according to chart */
  256. if(CurrentChar<135) {CurrentValue=CurrentChar-32;}
  257. if(CurrentChar>134) {CurrentValue=CurrentChar-100;}
  258. /* Multiply by the weighting character */
  259. CurrentValue=CurrentValue*I;
  260. /* Add the values together */
  261. weightedTotal=weightedTotal+CurrentValue;
  262. }
  263. /* divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue */
  264. CheckDigitValue = (int) (weightedTotal % 103);
  265. /* Now that we have the CheckDigitValue, find the corresponding ASCII character
  266. from the table */
  267. if(CheckDigitValue<95 && CheckDigitValue>0) {CheckDigit=CheckDigitValue+32;}
  268. if(CheckDigitValue>94) {CheckDigit=CheckDigitValue+100;}
  269. if(CheckDigitValue==0) {CheckDigit=194;}
  270. C128CheckDigit=CheckDigit;
  271. /* Check for spaces or "00" and print ASCII 194 instead */
  272. /* place changes in DataToPrint */
  273. BufferCounter = 0;
  274. for(I=1;I <= (int)strlen(DataToEncode);I++)
  275. {
  276. C128CurrentChar=DataToEncode[I-1];
  277. if(C128CurrentChar==' ')
  278. {
  279. C128CurrentChar = (char)194;
  280. }
  281. BufferCounter += sprintf(DataToPrint + BufferCounter, "%c", C128CurrentChar);
  282. }
  283. /* Get PrintableString */
  284. sprintf(PrintableString,"%c%s%c%c",C128Start, DataToPrint,C128CheckDigit,C128Stop);
  285. iSize = (long)strlen(PrintableString);
  286. strncpy(output, PrintableString, strlen(PrintableString));
  287. return 0;
  288. } //end Code128B()
  289. long IDAutomation_Code128c(char *DataToEncode, char *output, long iSize)
  290. {
  291. if(DataToEncode == NULL)
  292. return 1;
  293. if(strlen(DataToEncode) == 0)
  294. return 1;
  295. char DataToPrint[512];
  296. //DataToPrint = new char[512];
  297. char PrintableString[512];
  298. //PrintableString = new char[512];
  299. char OnlyCorrectData[512];
  300. //OnlyCorrectData = new char[512];
  301. char TempOnlyCorrectData[512];
  302. //TempOnlyCorrectData = new char[512];
  303. int C128Start;
  304. int C128Stop;
  305. int weightedTotal;
  306. int WeightValue;
  307. int I;
  308. int CurrentValue;
  309. int CheckDigitValue;
  310. char C128CheckDigit;
  311. int PrintBuffer = 0;
  312. /* Check to make sure data is numeric and remove dashes, etc. */
  313. for(I=1;I <= (int)strlen(DataToEncode);I++)
  314. {
  315. /* Add all numbers to OnlyCorrectData string */
  316. if(isdigit(asc(mid(DataToEncode,I,1))) != 0)
  317. {
  318. PrintBuffer += sprintf(TempOnlyCorrectData + PrintBuffer, "%s", mid(DataToEncode,I,1));
  319. }
  320. }
  321. /* Check for an even number of digits, add 0 if not even */
  322. int rem = (int) (strlen(TempOnlyCorrectData) % 2);
  323. if(rem == 1)
  324. {
  325. sprintf(OnlyCorrectData, "0%s", TempOnlyCorrectData);
  326. }
  327. else
  328. sprintf(OnlyCorrectData, "%s", TempOnlyCorrectData);
  329. /* Assign start & stop codes */
  330. C128Start=205;
  331. C128Stop=206;
  332. /* <<<< Calculate Modulo 103 Check Digit and generate DataToPrint >>>> */
  333. /* Set WeightedTotal to the Code 128 value of the start character */
  334. weightedTotal=105;
  335. WeightValue = 1;
  336. PrintBuffer = 0;
  337. for(I=1;I <= (int)strlen(OnlyCorrectData);I = I + 2)
  338. {
  339. /* Get the value of each number pair */
  340. CurrentValue = atoi(mid(OnlyCorrectData, I, 2));
  341. /* Get the DataToPrint */
  342. if(CurrentValue < 95 && CurrentValue > 0)
  343. {
  344. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentValue + 32);
  345. }
  346. if(CurrentValue>94)
  347. {
  348. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentValue + 100);
  349. }
  350. if(CurrentValue==0)
  351. {
  352. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", (char)194);
  353. }
  354. /* Multiply by the weighting character */
  355. CurrentValue=CurrentValue * WeightValue;
  356. /* Add the values together to get the weighted total*/
  357. weightedTotal = weightedTotal + CurrentValue;
  358. WeightValue = WeightValue + 1;
  359. }
  360. /* Divide the weighted total by 103 and get the remainder, this is the CheckDigitValue
  361. */
  362. CheckDigitValue = (int)(weightedTotal % 103);
  363. /* Now that we have the CheckDigitValue, find the corresponding ASCII character
  364. from the table */
  365. if (CheckDigitValue<95 && CheckDigitValue>0)
  366. {
  367. C128CheckDigit=CheckDigitValue+32;
  368. }
  369. if(CheckDigitValue>94)
  370. {
  371. C128CheckDigit=CheckDigitValue+100;
  372. }
  373. if (CheckDigitValue==0)
  374. {
  375. C128CheckDigit = (char)194;
  376. }
  377. /* Get PrintableString */
  378. sprintf(PrintableString,"%c%s%c%c",C128Start,DataToPrint,C128CheckDigit,C128Stop);
  379. iSize = (long)strlen(PrintableString);
  380. strncpy(output, PrintableString, strlen(PrintableString));
  381. return 0;
  382. }
  383. /*****************************************************************/
  384. /* ANSI C Functions for IDAutomation Barcode Fonts */
  385. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  386. /* All rights reserved. */
  387. /* Redistribution and use of this code in source and/or binary */
  388. /* forms, with or without modification, are permitted provided */
  389. /* that: (1) all copies of the source code retain the above */
  390. /* unmodified copyright notice and this entire unmodified */
  391. /* section of text, (2) You or Your organization owns a valid */
  392. /* Developer License to this product from IDAutomation.com */
  393. /* and, (3) when any portion of this code is bundled in any */
  394. /* form with an application, a valid notice must be provided */
  395. /* within the user documentation, start-up screen or in the */
  396. /* help-about section of the application that specifies */
  397. /* IDAutomation.com as the provider of the Software bundled */
  398. /* with the application. */
  399. /*****************************************************************/
  400. long IDAutomation_Codabar(char *DataToEncode, char *output, long iSize)
  401. {
  402. if(DataToEncode == NULL)
  403. return 1;
  404. if(strlen(DataToEncode) == 0)
  405. return 1;
  406. char OnlyCorrectData[512];
  407. //OnlyCorrectData = new char[512];
  408. char PrintableString[512];
  409. //PrintableString = new char[512];
  410. int I;
  411. int PrintBuffer = 0;
  412. /* Check to make sure data is numeric, $, +, -, /, or :, and remove all others. */
  413. for(I = 1;I <= (int)strlen(DataToEncode);I++)
  414. {
  415. if((int) asc(mid(DataToEncode, I, 1)) > 0 && isdigit(asc(mid(DataToEncode,I,1))))
  416. PrintBuffer += sprintf(OnlyCorrectData + PrintBuffer, "%s", mid(DataToEncode, I, 1));
  417. else if(DataToEncode[I - 1] == '$' || DataToEncode[I - 1] == '+' || DataToEncode[I - 1] == '-' ||
  418. DataToEncode[I - 1] == '/' || DataToEncode[I - 1] == '.' || DataToEncode[I - 1] == ':')
  419. PrintBuffer += sprintf(OnlyCorrectData + PrintBuffer, "%s", mid(DataToEncode,I,1));
  420. }
  421. /* Get Printable String */
  422. sprintf(PrintableString,"A%sB", OnlyCorrectData);
  423. iSize = (long)strlen(PrintableString);
  424. strncpy(output, PrintableString, strlen(PrintableString));
  425. return 0;
  426. }
  427. long IDAutomation_Interleaved2of5(char *DataToEncode, char *output, long iSize)
  428. {
  429. if(DataToEncode == NULL)
  430. return 1;
  431. if(strlen(DataToEncode) == 0)
  432. return 1;
  433. char PrintableString[512];
  434. //PrintableString = new char[512];
  435. char DataToPrint[512];
  436. //DataToPrint = new char[512];
  437. char OnlyCorrectData[512];
  438. //OnlyCorrectData = new char[512];
  439. char TempString[512];
  440. //TempString = new char[512];
  441. int I;
  442. int CurrentNumberPair = 0;
  443. char StartCode;
  444. char StopCode;
  445. int BufferCounter = 0;
  446. /* Check to make sure data is numeric and remove dashes, etc. */
  447. for(I=1;I <= (int)strlen(DataToEncode);I++)
  448. {
  449. /* Add all numbers to OnlyCorrectData string */
  450. if(isdigit(asc(mid(DataToEncode,I,1))))
  451. {
  452. BufferCounter += sprintf(OnlyCorrectData + BufferCounter,"%c", asc(mid(DataToEncode,I,1)));
  453. }
  454. }
  455. BufferCounter = 0;
  456. /* Check for an even number of digits, add 0 if not even */
  457. if((int)(strlen(OnlyCorrectData) % 2) == 1)
  458. {
  459. sprintf(TempString,"%d%s",0, OnlyCorrectData);
  460. }
  461. else
  462. sprintf(TempString,"%s",OnlyCorrectData);
  463. /* Assign start and stop codes */
  464. StartCode = (char)203;
  465. StopCode = (char)204;
  466. for(I=1;I <= (int)strlen(TempString);I = I + 2)
  467. {
  468. /* Get the value of each number pair */
  469. CurrentNumberPair = atoi(mid(TempString, I, 2));
  470. /* == Get the ASCII value of CurrentChar according to chart by adding to the value == */
  471. if(CurrentNumberPair < 94)
  472. {
  473. BufferCounter += sprintf(DataToPrint + BufferCounter,"%c", (char)(CurrentNumberPair + 33));
  474. }
  475. if(CurrentNumberPair > 93)
  476. {
  477. BufferCounter += sprintf(DataToPrint + BufferCounter,"%c", (char)(CurrentNumberPair + 103));
  478. }
  479. }
  480. /* Get Printable String */
  481. sprintf(PrintableString,"%c%s%c", StartCode, DataToPrint, StopCode);
  482. iSize = (long)strlen(PrintableString);
  483. strncpy(output, PrintableString, strlen(PrintableString));
  484. return 0;
  485. }
  486. /*****************************************************************/
  487. /* ANSI C Functions for IDAutomation Barcode Fonts */
  488. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  489. /* All rights reserved. */
  490. /* Redistribution and use of this code in source and/or binary */
  491. /* forms, with or without modification, are permitted provided */
  492. /* that: (1) all copies of the source code retain the above */
  493. /* unmodified copyright notice and this entire unmodified */
  494. /* section of text, (2) You or Your organization owns a valid */
  495. /* Developer License to this product from IDAutomation.com */
  496. /* and, (3) when any portion of this code is bundled in any */
  497. /* form with an application, a valid notice must be provided */
  498. /* within the user documentation, start-up screen or in the */
  499. /* help-about section of the application that specifies */
  500. /* IDAutomation.com as the provider of the Software bundled */
  501. /* with the application. */
  502. /*****************************************************************/
  503. long IDAutomation_Interleaved2of5Mod10 (char *DataToEncode, char *output, long iSize)
  504. {
  505. if(DataToEncode == NULL)
  506. return 1;
  507. if(strlen(DataToEncode) == 0)
  508. return 1;
  509. char DataToEncode2[512];
  510. //DataToEncode2 = new char[512];
  511. char PrintableString[512];
  512. //PrintableString = new char[512];
  513. char OnlyCorrectData[512];
  514. //OnlyCorrectData = new char[512];
  515. int BufferCounter = 0;
  516. char StartCode;
  517. char StopCode;
  518. int I = 0;
  519. int CurrentNumberPair = 0;
  520. /* Check to make sure data is numeric and remove dashes, etc. */
  521. for(I=1;I <= (int)strlen(DataToEncode);I++)
  522. {
  523. /* Add all numbers to OnlyCorrectData string */
  524. if(isdigit(asc(mid(DataToEncode,I,1))))
  525. {
  526. BufferCounter += sprintf(OnlyCorrectData + BufferCounter, "%s", mid(DataToEncode, I, 1));
  527. }
  528. }
  529. BufferCounter += sprintf(OnlyCorrectData + BufferCounter, "%c", FindMod10Digit(OnlyCorrectData));
  530. /* Check for an even number of digits, add 0 if not even */
  531. if((int)(strlen(OnlyCorrectData) % 2) == 1)
  532. sprintf(DataToEncode2, "0%s", OnlyCorrectData);
  533. else
  534. sprintf(DataToEncode2, "%s", OnlyCorrectData);
  535. /* Assign start and stop codes */
  536. StartCode = (char)203;
  537. StopCode = (char)204;
  538. BufferCounter = 0;
  539. BufferCounter += sprintf(PrintableString + BufferCounter, "%c", StartCode);
  540. for(I = 1;I <= (int)strlen(DataToEncode2);I = I + 2)
  541. {
  542. CurrentNumberPair = atoi(mid(DataToEncode2, I, 2));
  543. if(CurrentNumberPair < 94)
  544. BufferCounter += sprintf(PrintableString + BufferCounter, "%c", (char)(CurrentNumberPair + 33));
  545. else
  546. BufferCounter += sprintf(PrintableString + BufferCounter, "%c", (char)(CurrentNumberPair + 103));
  547. }
  548. BufferCounter += sprintf(PrintableString + BufferCounter, "%c", StopCode);
  549. iSize = (long)strlen(PrintableString);
  550. strncpy(output, PrintableString, strlen(PrintableString));
  551. return 0;
  552. }
  553. /*****************************************************************/
  554. /* ANSI C Functions for IDAutomation Barcode Fonts */
  555. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  556. /* All rights reserved. */
  557. /* Redistribution and use of this code in source and/or binary */
  558. /* forms, with or without modification, are permitted provided */
  559. /* that: (1) all copies of the source code retain the above */
  560. /* unmodified copyright notice and this entire unmodified */
  561. /* section of text, (2) You or Your organization owns a valid */
  562. /* Developer License to this product from IDAutomation.com */
  563. /* and, (3) when any portion of this code is bundled in any */
  564. /* form with an application, a valid notice must be provided */
  565. /* within the user documentation, start-up screen or in the */
  566. /* help-about section of the application that specifies */
  567. /* IDAutomation.com as the provider of the Software bundled */
  568. /* with the application. */
  569. /*****************************************************************/
  570. long IDAutomation_Code39 (char *DataToEncode, char *output, long iSize)
  571. {
  572. if(DataToEncode == NULL)
  573. return 1;
  574. if(strlen(DataToEncode) == 0)
  575. return 1;
  576. char DataToPrint[512];
  577. //DataToPrint = new char[512];
  578. char PrintableString[512];
  579. //PrintableString = new char[512];
  580. int I;
  581. int CurrentChar;
  582. int BufferCounter = 0;
  583. /* Check for spaces in code */
  584. for(I=1;I <= (int)strlen(DataToEncode);I++)
  585. {
  586. /* Get each character one at a time */
  587. CurrentChar = asc((mid(DataToEncode,I,1)));
  588. /* To print the barcode symbol representing a space you will need*/
  589. /* to type or print "=" (the equal character) instead of a space character.*/
  590. if(CurrentChar == 32)
  591. {
  592. CurrentChar = 61;
  593. }
  594. //BufferCounter += sprintf(DataToPrint + BufferCounter,"%c", CurrentChar);
  595. sprintf(DataToPrint,"%s%c", DataToPrint,CurrentChar);
  596. }
  597. /* Get Printable String */
  598. sprintf(PrintableString,"*%s*",strupr(DataToPrint));
  599. iSize = (long)strlen(PrintableString);
  600. strncpy(output, PrintableString, strlen(PrintableString));
  601. return 0;
  602. }
  603. /*****************************************************************/
  604. /* ANSI C Functions for IDAutomation Barcode Fonts */
  605. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  606. /* All rights reserved. */
  607. /* Redistribution and use of this code in source and/or binary */
  608. /* forms, with or without modification, are permitted provided */
  609. /* that: (1) all copies of the source code retain the above */
  610. /* unmodified copyright notice and this entire unmodified */
  611. /* section of text, (2) You or Your organization owns a valid */
  612. /* Developer License to this product from IDAutomation.com */
  613. /* and, (3) when any portion of this code is bundled in any */
  614. /* form with an application, a valid notice must be provided */
  615. /* within the user documentation, start-up screen or in the */
  616. /* help-about section of the application that specifies */
  617. /* IDAutomation.com as the provider of the Software bundled */
  618. /* with the application. */
  619. /*****************************************************************/
  620. long IDAutomation_Code39Mod43 (char *DataToEncode, char *output, long iSize)
  621. {
  622. if(DataToEncode == NULL)
  623. return 1;
  624. if(strlen(DataToEncode) == 0)
  625. return 1;
  626. //char DataToEncode2[512];
  627. //DataToEncode2 = new char[512];
  628. char DataToPrint[512];
  629. //DataToPrint = new char[512];
  630. char PrintableString[512];
  631. //PrintableString = new char[512];
  632. int I;
  633. int weightedTotal;
  634. int CurrentChar;
  635. char CurrentValue;
  636. char CheckDigit;
  637. char CheckDigitValue;
  638. int bufferCounter = 0;
  639. /* Get data from user, this is the DataToEncode */
  640. // sprintf(DataToEncode2,"%s",DataToEncode);
  641. weightedTotal = 0;
  642. /* only pass correct data */
  643. for(I = 1;I <= (int)strlen(DataToEncode);I++)
  644. {
  645. // Get each character one at a time
  646. CurrentChar = asc(strupr(mid(DataToEncode,I,1)));
  647. // Get the value of CurrentChar according to MOD43
  648. // 0-9
  649. if(CurrentChar < 58 && CurrentChar > 47)
  650. {
  651. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  652. CurrentValue = CurrentChar - 48;
  653. }
  654. else if(CurrentChar < 91 && CurrentChar > 64)
  655. {
  656. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  657. CurrentValue = CurrentChar - 55;
  658. }
  659. else if(CurrentChar == 32) // Space
  660. {
  661. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", "=");
  662. CurrentValue = 38;
  663. }
  664. else if(CurrentChar == 45) // -
  665. {
  666. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  667. CurrentValue = 36;
  668. }
  669. else if(CurrentChar == 46) // .
  670. {
  671. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  672. CurrentValue = 37;
  673. }
  674. else if(CurrentChar == 36) // $
  675. {
  676. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  677. CurrentValue = 39;
  678. }
  679. else if(CurrentChar == 47) // /
  680. {
  681. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  682. CurrentValue = 40;
  683. }
  684. else if(CurrentChar == 43) // +
  685. {
  686. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  687. CurrentValue = 41;
  688. }
  689. else if(CurrentChar == 37) // %
  690. {
  691. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  692. CurrentValue = 42;
  693. }
  694. else
  695. {
  696. CurrentValue = 0;
  697. }
  698. // add the values together
  699. weightedTotal = weightedTotal + CurrentValue;
  700. }
  701. // divide the WeightedTotal by 43 and get the remainder, this is the CheckDigit
  702. CheckDigitValue = (int)((weightedTotal % 43));
  703. // Assign values to characters
  704. if(CheckDigitValue < 10) // 0-9
  705. {
  706. CheckDigit = CheckDigitValue + 48;
  707. }
  708. else if((CheckDigitValue < 36) && (CheckDigitValue > 9)) // A-Z
  709. {
  710. CheckDigit = CheckDigitValue + 55;
  711. }
  712. else if(CheckDigitValue == 38) // Space
  713. {
  714. CheckDigit = 61;
  715. }
  716. else if(CheckDigitValue == 36) // -
  717. {
  718. CheckDigit = 45;
  719. }
  720. else if(CheckDigitValue == 37) // .
  721. {
  722. CheckDigit = 46;
  723. }
  724. else if(CheckDigitValue == 39) // $
  725. {
  726. CheckDigit = 36;
  727. }
  728. else if(CheckDigitValue == 40) // /
  729. {
  730. CheckDigit = 47;
  731. }
  732. else if(CheckDigitValue == 41) // +
  733. {
  734. CheckDigit = 43;
  735. }
  736. else if(CheckDigitValue == 42) // %
  737. {
  738. CheckDigit = 37;
  739. }
  740. // Get Printable String
  741. sprintf(PrintableString,"*%s%c*", strupr(DataToPrint), CheckDigit);
  742. iSize = (long)strlen(PrintableString);
  743. strncpy(output, PrintableString, strlen(PrintableString));
  744. return 0;
  745. }
  746. /*****************************************************************/
  747. /* ANSI C Functions for IDAutomation Barcode Fonts */
  748. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  749. /* All rights reserved. */
  750. /* Redistribution and use of this code in source and/or binary */
  751. /* forms, with or without modification, are permitted provided */
  752. /* that: (1) all copies of the source code retain the above */
  753. /* unmodified copyright notice and this entire unmodified */
  754. /* section of text, (2) You or Your organization owns a valid */
  755. /* Developer License to this product from IDAutomation.com */
  756. /* and, (3) when any portion of this code is bundled in any */
  757. /* form with an application, a valid notice must be provided */
  758. /* within the user documentation, start-up screen or in the */
  759. /* help-about section of the application that specifies */
  760. /* IDAutomation.com as the provider of the Software bundled */
  761. /* with the application. */
  762. /*****************************************************************/
  763. long IDAutomation_Code93(char *DataToEncode, char *output, long iSize)
  764. {
  765. if(DataToEncode == NULL)
  766. return 1;
  767. if(strlen(DataToEncode) == 0)
  768. return 1;
  769. //char DataToEncode2[512];
  770. //DataToEncode2 = new char[512];
  771. char DataToPrint[512];
  772. //DataToPrint = new char[512];
  773. char PrintableString[512];
  774. //PrintableString = new char[512];
  775. int I;
  776. char CurrentChar;
  777. char CurrentValue;
  778. char CheckDigitC;
  779. char CheckDigitK;
  780. char CheckDigitValue;
  781. int CW = 1;
  782. int KW = 2;
  783. int CWSum =0;
  784. int KWSum =0;
  785. int bufferCounter = 0;
  786. /* Get data from user, this is the DataToEncode */
  787. //sprintf(DataToEncode2,"%s",strupr(DataToEncode));
  788. /* only pass correct data */
  789. for(I = 1;I <= (int)strlen(DataToEncode);I++)
  790. {
  791. /* Get each character one at a time */
  792. CurrentChar = asc(strupr(mid(DataToEncode,I,1)));
  793. /* Get the value of CurrentChar according to MOD43 */
  794. /* 0-9 */
  795. if(CurrentChar < 58 && CurrentChar > 47)
  796. {
  797. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  798. CurrentValue = CurrentChar - 48;
  799. }
  800. else if(CurrentChar < 91 && CurrentChar > 64)
  801. {
  802. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  803. CurrentValue = CurrentChar - 55;
  804. }
  805. else if(CurrentChar == 32) /* Space */
  806. {
  807. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", "=");
  808. CurrentValue = 38;
  809. }
  810. else if(CurrentChar == 45) /* - */
  811. {
  812. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  813. CurrentValue = 36;
  814. }
  815. else if(CurrentChar == 46) /* . */
  816. {
  817. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  818. CurrentValue = 37;
  819. }
  820. else if(CurrentChar == 36) /* $ */
  821. {
  822. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  823. CurrentValue = 39;
  824. }
  825. else if(CurrentChar == 47) /* / */
  826. {
  827. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  828. CurrentValue = 40;
  829. }
  830. else if(CurrentChar == 43) /* + */
  831. {
  832. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  833. CurrentValue = 41;
  834. }
  835. else if(CurrentChar == 37) /* % */
  836. {
  837. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s", mid(DataToEncode,I,1));
  838. CurrentValue = 42;
  839. }
  840. else
  841. {
  842. CurrentValue = 0;
  843. }
  844. /* To print the barcode symbol representing a space you will */
  845. /* to type or print "=" (the equal character) instead of a space character.*/
  846. if(CurrentChar == 32)
  847. {
  848. CurrentChar = 61;
  849. }
  850. }
  851. for(I= (int)strlen(DataToEncode);I>0;I--)
  852. {
  853. /* Get each character one at a time */
  854. CurrentChar=asc(strupr(mid(DataToEncode,I,1)));
  855. /* Get the value of CurrentChar according to 93 */
  856. if((CurrentChar<58)&&(CurrentChar>47))
  857. /* 0-9 */
  858. {
  859. CurrentValue=CurrentChar-48;
  860. }
  861. /* A-Z */
  862. if((CurrentChar<91)&&(CurrentChar>64))
  863. {
  864. CurrentValue=CurrentChar-55;
  865. }
  866. /* - */
  867. if(CurrentChar==45)
  868. {
  869. CurrentValue=36;
  870. }
  871. /* . */
  872. if(CurrentChar==46)
  873. {
  874. CurrentValue=37;
  875. }
  876. /* Space */
  877. if(CurrentChar==32)
  878. {
  879. CurrentValue=38;
  880. }
  881. /* $ */
  882. if(CurrentChar==36)
  883. {
  884. CurrentValue=39;
  885. }
  886. /* / */
  887. if(CurrentChar==47)
  888. {
  889. CurrentValue=40;
  890. }
  891. /* + */
  892. if(CurrentChar==43)
  893. {
  894. CurrentValue=41;
  895. }
  896. /* % */
  897. if(CurrentChar==37)
  898. {
  899. CurrentValue=42;
  900. }
  901. /* ! */
  902. if(CurrentChar==33 )
  903. {
  904. CurrentValue=43;
  905. }
  906. /* # */
  907. if(CurrentChar==35 )
  908. {
  909. CurrentValue=44;
  910. }
  911. /* & */
  912. if(CurrentChar==38 )
  913. {
  914. CurrentValue=45;
  915. }
  916. /* @ */
  917. if(CurrentChar==64 )
  918. {
  919. CurrentValue=46;
  920. }
  921. CWSum += CurrentValue * CW;
  922. KWSum += CurrentValue * KW;
  923. if (CW == 20) {
  924. CW = 0;
  925. }
  926. if (KW == 15) {
  927. KW = 0;
  928. }
  929. CW++;
  930. KW++;
  931. }
  932. /* divide the WeightedTotal by 47 and get the remainder, this is the CheckDigit for C */
  933. CheckDigitValue = ((int)(CWSum % 47));
  934. /* Assign values to characters for Check digit C */
  935. /* 0-9 */
  936. if(CheckDigitValue<10)
  937. {
  938. CheckDigitC=CheckDigitValue+48;
  939. }
  940. /* A-Z */
  941. if((CheckDigitValue<36)&&(CheckDigitValue>9))
  942. {
  943. CheckDigitC=CheckDigitValue+55;
  944. }
  945. /* = */
  946. if(CheckDigitValue==38)
  947. {
  948. CheckDigitC=61;
  949. }
  950. /* Space */
  951. if(CheckDigitValue==38)
  952. {
  953. CheckDigitC=32;
  954. }
  955. /* - */
  956. if(CheckDigitValue==36)
  957. {
  958. CheckDigitC=45;
  959. }
  960. /* . */
  961. if(CheckDigitValue==37)
  962. {
  963. CheckDigitC=46;
  964. }
  965. /* $ */
  966. if(CheckDigitValue==39)
  967. {
  968. CheckDigitC=36;
  969. }
  970. /* / */
  971. if(CheckDigitValue==40)
  972. {
  973. CheckDigitC=47;
  974. }
  975. /* + */
  976. if(CheckDigitValue==41)
  977. {
  978. CheckDigitC=43;
  979. }
  980. /* % */
  981. if(CheckDigitValue==42)
  982. {
  983. CheckDigitC=37;
  984. }
  985. /* ! */
  986. if(CheckDigitValue == 43 )
  987. {
  988. CheckDigitC=33;
  989. }
  990. /* # */
  991. if(CheckDigitValue == 44 )
  992. {
  993. CheckDigitC=35;
  994. }
  995. /* & */
  996. if(CheckDigitValue == 45 )
  997. {
  998. CheckDigitC=38;
  999. }
  1000. /* @ */
  1001. if(CheckDigitValue == 46 )
  1002. {
  1003. CheckDigitC=64;
  1004. }
  1005. /* divide the WeightedTotal by 47 and get the remainder, this is the CheckDigit for K*/
  1006. CheckDigitValue = (int)((KWSum+CheckDigitValue) % 47);
  1007. /* 0-9 */
  1008. if(CheckDigitValue<10)
  1009. {
  1010. CheckDigitK=CheckDigitValue+48;
  1011. }
  1012. /* A-Z */
  1013. if((CheckDigitValue<36)&&(CheckDigitValue>9))
  1014. {
  1015. CheckDigitK=CheckDigitValue+55;
  1016. }
  1017. /* Space */
  1018. if(CheckDigitValue == 38)
  1019. {
  1020. CheckDigitK=32;
  1021. }
  1022. /* - */
  1023. if(CheckDigitValue == 36)
  1024. {
  1025. CheckDigitK=45;
  1026. }
  1027. /* . */
  1028. if(CheckDigitValue == 37)
  1029. {
  1030. CheckDigitK=46;
  1031. }
  1032. /* $ */
  1033. if(CheckDigitValue == 39)
  1034. {
  1035. CheckDigitK=36;
  1036. }
  1037. /* / */
  1038. if(CheckDigitValue == 40)
  1039. {
  1040. CheckDigitK=47;
  1041. }
  1042. /* + */
  1043. if(CheckDigitValue == 41)
  1044. {
  1045. CheckDigitK=43;
  1046. }
  1047. /* % */
  1048. if(CheckDigitValue == 42)
  1049. {
  1050. CheckDigitK=37;
  1051. }
  1052. /* ! */
  1053. if(CheckDigitValue == 43)
  1054. {
  1055. CheckDigitK=33;
  1056. }
  1057. /* # */
  1058. if(CheckDigitValue == 44)
  1059. {
  1060. CheckDigitK=35;
  1061. }
  1062. /* & */
  1063. if(CheckDigitValue == 45)
  1064. {
  1065. CheckDigitK=38;
  1066. }
  1067. /* @ */
  1068. if(CheckDigitValue == 46 )
  1069. {
  1070. CheckDigitK=64;
  1071. }
  1072. /* Get Printable String */
  1073. sprintf(PrintableString,"(%s%c%c)",strupr(DataToPrint),CheckDigitC,CheckDigitK);
  1074. iSize = (long)strlen(PrintableString);
  1075. strncpy(output, PrintableString, strlen(PrintableString));
  1076. return 0;
  1077. }
  1078. /*****************************************************************/
  1079. /* ANSI C Functions for IDAutomation Barcode Fonts */
  1080. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  1081. /* All rights reserved. */
  1082. /* Redistribution and use of this code in source and/or binary */
  1083. /* forms, with or without modification, are permitted provided */
  1084. /* that: (1) all copies of the source code retain the above */
  1085. /* unmodified copyright notice and this entire unmodified */
  1086. /* section of text, (2) You or Your organization owns a valid */
  1087. /* Developer License to this product from IDAutomation.com */
  1088. /* and, (3) when any portion of this code is bundled in any */
  1089. /* form with an application, a valid notice must be provided */
  1090. /* within the user documentation, start-up screen or in the */
  1091. /* help-about section of the application that specifies */
  1092. /* IDAutomation.com as the provider of the Software bundled */
  1093. /* with the application. */
  1094. /*****************************************************************/
  1095. long IDAutomation_Postnet (char *DataToEncode, char *output, long iSize)
  1096. {
  1097. /* Enter all the numbers without dashes */
  1098. if(DataToEncode == NULL)
  1099. return 1;
  1100. if(strlen(DataToEncode) == 0)
  1101. return 1;
  1102. char OnlyCorrectData[512];
  1103. //OnlyCorrectData = new char[512];
  1104. char PrintableString[512];
  1105. //PrintableString = new char[512];
  1106. int BufferCounter = 0;
  1107. int I;
  1108. int weightedTotal;
  1109. int CheckDigit;
  1110. /* Check to make sure data is numeric and remove dashes, etc. */
  1111. for(I=1;I <= (int)strlen(DataToEncode);I++)
  1112. {
  1113. /* Add all numbers to OnlyCorrectData string */
  1114. if(isdigit(asc(mid(DataToEncode,I,1))))
  1115. BufferCounter += sprintf(OnlyCorrectData + BufferCounter,"%s", mid(DataToEncode,I,1));
  1116. }
  1117. /* <<<< Calculate Check Digit >>>>. which is just the sum of the numbers */
  1118. weightedTotal=0;
  1119. for(I = 1;I <= (int)strlen(OnlyCorrectData);I++)
  1120. {
  1121. weightedTotal += atoi(mid(OnlyCorrectData, I, 1));
  1122. }
  1123. /* Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10 */
  1124. /* divide by 10, get the remainder and subtract from 10 */
  1125. I = (int)((weightedTotal % 10));
  1126. if( I!= 0)
  1127. CheckDigit=(10-I);
  1128. else
  1129. CheckDigit=0;
  1130. BufferCounter = 0;
  1131. BufferCounter += sprintf(PrintableString + BufferCounter,"(%s%i)", OnlyCorrectData, CheckDigit);
  1132. iSize = (long)strlen(PrintableString);
  1133. strncpy(output, PrintableString, strlen(PrintableString));
  1134. return 0;
  1135. }
  1136. /*****************************************************************/
  1137. /* ANSI C Functions for IDAutomation Barcode Fonts */
  1138. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  1139. /* All rights reserved. */
  1140. /* Redistribution and use of this code in source and/or binary */
  1141. /* forms, with or without modification, are permitted provided */
  1142. /* that: (1) all copies of the source code retain the above */
  1143. /* unmodified copyright notice and this entire unmodified */
  1144. /* section of text, (2) You or Your organization owns a valid */
  1145. /* Developer License to this product from IDAutomation.com */
  1146. /* and, (3) when any portion of this code is bundled in any */
  1147. /* form with an application, a valid notice must be provided */
  1148. /* within the user documentation, start-up screen or in the */
  1149. /* help-about section of the application that specifies */
  1150. /* IDAutomation.com as the provider of the Software bundled */
  1151. /* with the application. */
  1152. /*****************************************************************/
  1153. long IDAutomation_EAN8 (char *DataToEncode, char *output, long iSize)
  1154. {
  1155. /* The purpose of this code is to calculate the EAN-8 barcode */
  1156. /* Enter all the numbers without dashes */
  1157. if(DataToEncode == NULL)
  1158. return 1;
  1159. if(strlen(DataToEncode) == 0)
  1160. return 1;
  1161. char DataToEncode2[512];
  1162. //DataToEncode2 = new char[512];
  1163. char DataToPrint[512];
  1164. //DataToPrint = new char[512];
  1165. char OnlyCorrectData[512];
  1166. //OnlyCorrectData = new char[512];
  1167. char PrintableString[512];
  1168. //PrintableString = new char[512];
  1169. int I;
  1170. int Factor;
  1171. int weightedTotal;
  1172. char CurrentChar;
  1173. int CheckDigit;
  1174. int PrintBuffer = 0;
  1175. sprintf(DataToEncode2,"%s",DataToEncode);
  1176. /* Check to make sure data is numeric and remove dashes, etc. */
  1177. for(I=1;I <= (int)strlen(DataToEncode2);I++)
  1178. {
  1179. /* Add all numbers to OnlyCorrectData string */
  1180. if(isdigit(asc(mid(DataToEncode2,I,1))))
  1181. {
  1182. PrintBuffer += sprintf(OnlyCorrectData + PrintBuffer,"%c", asc(mid(DataToEncode2,I,1)));
  1183. }
  1184. }
  1185. if(strlen(OnlyCorrectData) >= 7)
  1186. sprintf(DataToEncode2,"%s",mid(OnlyCorrectData, 1, 7));
  1187. else
  1188. sprintf(DataToEncode2,"%s","0005000");
  1189. /* <<<< Calculate Check Digit >>>> */
  1190. Factor=3;
  1191. weightedTotal=0;
  1192. for(I = (int)strlen(DataToEncode2);I >= 1;I = I +- 1)
  1193. {
  1194. /* Get the value of each number starting at the end */
  1195. CurrentChar=asc(mid(DataToEncode2,I,1));
  1196. /* multiply by the weighting factor which is 3,1,3,1... */
  1197. /* and add the sum together */
  1198. weightedTotal=weightedTotal+CurrentChar*Factor;
  1199. /* change factor for next calculation */
  1200. Factor=4-Factor;
  1201. }
  1202. /* Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10 */
  1203. /* divide by 10, get the remainder and subtract from 10 */
  1204. I = (int)(weightedTotal % 10);
  1205. if(I!=0)
  1206. CheckDigit=(10-I);
  1207. else
  1208. CheckDigit=0;
  1209. sprintf(DataToEncode2,"%s%i", DataToEncode2, CheckDigit);
  1210. /* Now that have the total number including the check digit, determine character to print */
  1211. /* for proper barcoding */
  1212. PrintBuffer = 0;
  1213. for(I = 1;I <= (int)strlen(DataToEncode2);I++)
  1214. {
  1215. /* Get the ASCII value of each number */
  1216. CurrentChar = asc(mid(DataToEncode2,I,1));
  1217. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  1218. if(I==1)
  1219. {
  1220. /* For the first character print the normal guard pattern */
  1221. /* and then the barcode without the human readable character */
  1222. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"(%c",CurrentChar);
  1223. }
  1224. if(I==2)
  1225. {
  1226. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar);
  1227. }
  1228. if(I==3)
  1229. {
  1230. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar);
  1231. }
  1232. if(I==4)
  1233. {
  1234. /* Print the center guard pattern after the 6th character */
  1235. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c*", CurrentChar);
  1236. }
  1237. if(I==5)
  1238. {
  1239. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
  1240. }
  1241. if(I==6)
  1242. {
  1243. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
  1244. }
  1245. if(I==7)
  1246. {
  1247. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c", CurrentChar+27);
  1248. }
  1249. if(I==8)
  1250. {
  1251. /* Print the check digit as 8th character + normal guard pattern */
  1252. PrintBuffer += sprintf(DataToPrint + PrintBuffer,"%c(", CurrentChar+27);
  1253. }
  1254. }
  1255. /* Get Printable String */
  1256. sprintf(PrintableString,"%s",DataToPrint);
  1257. iSize = (long)strlen(PrintableString);
  1258. strncpy(output, PrintableString, strlen(PrintableString));
  1259. return 0;
  1260. }
  1261. /*****************************************************************/
  1262. /* ANSI C Functions for IDAutomation Barcode Fonts */
  1263. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  1264. /* All rights reserved. */
  1265. /* Redistribution and use of this code in source and/or binary */
  1266. /* forms, with or without modification, are permitted provided */
  1267. /* that: (1) all copies of the source code retain the above */
  1268. /* unmodified copyright notice and this entire unmodified */
  1269. /* section of text, (2) You or Your organization owns a valid */
  1270. /* Developer License to this product from IDAutomation.com */
  1271. /* and, (3) when any portion of this code is bundled in any */
  1272. /* form with an application, a valid notice must be provided */
  1273. /* within the user documentation, start-up screen or in the */
  1274. /* help-about section of the application that specifies */
  1275. /* IDAutomation.com as the provider of the Software bundled */
  1276. /* with the application. */
  1277. /*****************************************************************/
  1278. long IDAutomation_EAN13 (char *DataToEncode, char *output, long iSize)
  1279. {
  1280. if(DataToEncode == NULL)
  1281. return 1;
  1282. if(strlen(DataToEncode) == 0)
  1283. return 1;
  1284. int StringLength = 0;
  1285. int I = 0;
  1286. int Factor = 3;
  1287. int weightedTotal = 0;
  1288. int CurrentChar = 0;
  1289. int DataToPrintBuffer = 0;
  1290. int CheckDigit = 0;
  1291. int LeadingDigit = 0;
  1292. int CurrentEncoding = 0;
  1293. char LPrintableString[512];
  1294. //LPrintableString = new char[512];
  1295. char ActualDataToEncode[20];
  1296. //ActualDataToEncode = new char[20];
  1297. char DataToPrint[20];
  1298. //DataToPrint = new char[20];
  1299. char EAN2AddOn[3];
  1300. //EAN2AddOn = new char[3];
  1301. char OnlyCorrectData[20];
  1302. //OnlyCorrectData = new char[20];
  1303. char EAN5AddOn[6];
  1304. //EAN5AddOn = new char[6];
  1305. char EANAddOnToPrint[15];
  1306. //EANAddOnToPrint = new char[15];
  1307. char Encoding[20];
  1308. //Encoding = new char[20];
  1309. char Temp[512];
  1310. //Temp = new char[512];
  1311. StringLength = (int)strlen(DataToEncode);
  1312. for(I = 0;I < StringLength;I++)
  1313. {
  1314. if(isdigit((int)DataToEncode[I]))
  1315. {
  1316. DataToPrintBuffer += sprintf(OnlyCorrectData + DataToPrintBuffer, "%c", DataToEncode[I]);
  1317. }
  1318. }
  1319. DataToPrintBuffer = 0;
  1320. if(strlen(OnlyCorrectData) < 12 || strlen(OnlyCorrectData) == 16 || strlen(OnlyCorrectData) > 18)
  1321. {
  1322. sprintf(OnlyCorrectData, "%s", "0000000000000");
  1323. }
  1324. if(strlen(OnlyCorrectData) == 12 || strlen(OnlyCorrectData) == 13)
  1325. {
  1326. sprintf(LPrintableString, "%s", mid(OnlyCorrectData, 1, 12));
  1327. }
  1328. else if(strlen(OnlyCorrectData) == 14)
  1329. {
  1330. sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
  1331. sprintf(EAN2AddOn,"%s", mid(OnlyCorrectData, 13, 2));
  1332. }
  1333. else if(strlen(OnlyCorrectData) == 15)
  1334. {
  1335. sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
  1336. sprintf(EAN2AddOn,"%s", mid(OnlyCorrectData, 14, 2));
  1337. }
  1338. else if(strlen(OnlyCorrectData) == 17)
  1339. {
  1340. sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
  1341. sprintf(EAN5AddOn,"%s", mid(OnlyCorrectData, 13, 5));
  1342. }
  1343. else if(strlen(OnlyCorrectData) == 18)
  1344. {
  1345. sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 12));
  1346. sprintf(EAN5AddOn,"%s", mid(OnlyCorrectData, 14, 5));
  1347. }
  1348. /* <<<< Calculate Check Digit >>>> */
  1349. for(I = (int)strlen(LPrintableString);I >= 1;I--)
  1350. {
  1351. /* Get the value of each number starting at the end */
  1352. CurrentChar = asc(mid(LPrintableString,I,1)) - 48;
  1353. /* multiply by the weighting factor which is 3,1,3,1... */
  1354. /* and add the sum together */
  1355. weightedTotal = weightedTotal + (CurrentChar * Factor);
  1356. /* change factor for next calculation */
  1357. Factor = 4 - Factor;
  1358. }
  1359. /* Find the CheckDigitValue by finding the number + weightedTotal that = a multiple of 10 */
  1360. /* divide by 10, get the remainder and subtract from 10 */
  1361. I = (int)(weightedTotal % 10);
  1362. if(I != 0)
  1363. CheckDigit=(10 - I);
  1364. else
  1365. CheckDigit = 0;
  1366. /* Now we must encode the leading digit into the left half of the EAN-13 symbol */
  1367. /* by using variable parity between character sets A and B */
  1368. LeadingDigit = (((asc(mid(LPrintableString, 1, 1))))-48);
  1369. if(LeadingDigit == 0)
  1370. sprintf(Encoding, "AAAAAACCCCCC");
  1371. else if(LeadingDigit == 1)
  1372. sprintf(Encoding, "AABABBCCCCCC");
  1373. else if(LeadingDigit == 2)
  1374. sprintf(Encoding, "AABBABCCCCCC");
  1375. else if(LeadingDigit == 3)
  1376. sprintf(Encoding, "AABBBACCCCCC");
  1377. else if(LeadingDigit == 4)
  1378. sprintf(Encoding, "ABAABBCCCCCC");
  1379. else if(LeadingDigit == 5)
  1380. sprintf(Encoding, "ABBAABCCCCCC");
  1381. else if(LeadingDigit == 6)
  1382. sprintf(Encoding, "ABBBAACCCCCC");
  1383. else if(LeadingDigit == 7)
  1384. sprintf(Encoding, "ABABABCCCCCC");
  1385. else if(LeadingDigit == 8)
  1386. sprintf(Encoding, "ABABBACCCCCC");
  1387. else if(LeadingDigit == 9)
  1388. sprintf(Encoding, "ABBABACCCCCC");
  1389. /* add the check digit to the end of the barcode & remove the leading digit */
  1390. sprintf(ActualDataToEncode, "%s%i", mid(LPrintableString, 2, 11), CheckDigit);
  1391. /* Now that we have the total number including the check digit, determine character to print */
  1392. /* for proper barcoding: */
  1393. for(I = 1;I <= (int)strlen(ActualDataToEncode);I++)
  1394. {
  1395. /* Get the ASCII value of each number excluding the first number because */
  1396. /* it is encoded with variable parity */
  1397. CurrentChar = asc(mid(ActualDataToEncode, I, 1));
  1398. CurrentEncoding = asc(mid(Encoding, I, 1));
  1399. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  1400. if(CurrentEncoding == 'A')
  1401. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar);
  1402. else if(CurrentEncoding == 'B')
  1403. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar + 17);
  1404. else if(CurrentEncoding=='C')
  1405. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%c", CurrentChar + 27);
  1406. /* add in the 1st character along with guard patterns */
  1407. if(I == 1)
  1408. {
  1409. DataToPrintBuffer = 0;
  1410. /* For the LeadingDigit print the human readable character, */
  1411. /* the normal guard pattern and then the rest of the barcode */
  1412. sprintf(Temp,"%i",LeadingDigit);
  1413. if(LeadingDigit > 4)
  1414. {
  1415. sprintf(Temp,"%c(%s",asc(Temp) + 64, DataToPrint);
  1416. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "%s", Temp);
  1417. }
  1418. else if(LeadingDigit < 5)
  1419. {
  1420. sprintf(Temp,"%c(%s",asc(Temp) + 37, DataToPrint);
  1421. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer,"%s",Temp);
  1422. }
  1423. }
  1424. else if(I==6)
  1425. {
  1426. /* Print the center guard pattern after the 6th character */
  1427. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "*");
  1428. }
  1429. else if(I==12)
  1430. {
  1431. /* For the last character (12) print the normal guard pattern */
  1432. /* after the barcode */
  1433. DataToPrintBuffer += sprintf(DataToPrint + DataToPrintBuffer, "(");
  1434. }
  1435. }
  1436. /* Process 5 digit add on if it exists */
  1437. if(strlen(EAN5AddOn) == 5)
  1438. {
  1439. /* Get check digit for add on */
  1440. Factor = 3;
  1441. weightedTotal=0;
  1442. for(I = (int)strlen(EAN5AddOn);I >= 1;I--)
  1443. {
  1444. /* Get the value of each number starting at the end */
  1445. CurrentChar = asc(mid(EAN5AddOn, I, 1)) - 48;
  1446. /* multiply by the weighting factor which is 3,9,3,9. */
  1447. /* and add the sum together */
  1448. if(Factor == 3)
  1449. weightedTotal = weightedTotal + (CurrentChar * 3);
  1450. else if(Factor == 1)
  1451. weightedTotal = weightedTotal + CurrentChar * 9;
  1452. /* change factor for next calculation */
  1453. Factor = 4 - Factor;
  1454. }
  1455. /* Find the CheckDigit by extracting the right-most number from weightedTotal */
  1456. sprintf(Temp,"%i",weightedTotal);
  1457. CheckDigit = asc(mid(Temp,(int)strlen(Temp), 1)) - 48;
  1458. /* Now we must encode the add-on CheckDigit into the number sets */
  1459. /* by using variable parity between character sets A and B */
  1460. if(CheckDigit == 0)
  1461. sprintf(Encoding,"BBAAA");
  1462. else if(CheckDigit == 1)
  1463. sprintf(Encoding,"BABAA");
  1464. else if(CheckDigit == 2)
  1465. sprintf(Encoding,"BAABA");
  1466. else if(CheckDigit == 3)
  1467. sprintf(Encoding,"BAAAB");
  1468. else if(CheckDigit == 4)
  1469. sprintf(Encoding,"ABBAA");
  1470. else if(CheckDigit == 5)
  1471. sprintf(Encoding,"AABBA");
  1472. else if(CheckDigit == 6)
  1473. sprintf(Encoding,"AAABB");
  1474. else if(CheckDigit == 7)
  1475. sprintf(Encoding,"ABABA");
  1476. else if(CheckDigit == 8)
  1477. sprintf(Encoding,"ABAAB");
  1478. else if(CheckDigit == 9)
  1479. sprintf(Encoding,"AABAB");
  1480. /* Now that we have the total number including the check digit, determine character to print */
  1481. /* for proper barcoding: */
  1482. DataToPrintBuffer = 0;
  1483. for(I = 1;I <= (int)strlen(EAN5AddOn);I++)
  1484. {
  1485. /* Get the value of each number. It is encoded with variable parity */
  1486. CurrentChar = asc(mid(EAN5AddOn,I,1)) - 48;
  1487. CurrentEncoding = asc(mid(Encoding, I, 1));
  1488. if(I == 1)
  1489. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c%c", 32, 43);
  1490. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  1491. if(CurrentEncoding == 'A')
  1492. {
  1493. if(CurrentChar == 0)
  1494. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 34);
  1495. else if(CurrentChar == 1)
  1496. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 35);
  1497. else if(CurrentChar == 2)
  1498. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 36);
  1499. else if(CurrentChar == 3)
  1500. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 37);
  1501. else if(CurrentChar == 4)
  1502. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 38);
  1503. else if(CurrentChar == 5)
  1504. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 44);
  1505. else if(CurrentChar == 6)
  1506. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 46);
  1507. else if(CurrentChar == 7)
  1508. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 47);
  1509. else if(CurrentChar == 8)
  1510. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 58);
  1511. else if(CurrentChar == 9)
  1512. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 59);
  1513. }
  1514. if(CurrentEncoding == 'B')
  1515. {
  1516. if(CurrentChar == 0)
  1517. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 122);
  1518. else if(CurrentChar == 1)
  1519. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 61);
  1520. else if(CurrentChar == 2)
  1521. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 63);
  1522. else if(CurrentChar == 3)
  1523. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 64);
  1524. else if(CurrentChar == 4)
  1525. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 91);
  1526. else if(CurrentChar == 5)
  1527. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 92);
  1528. else if(CurrentChar == 6)
  1529. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 93);
  1530. else if(CurrentChar == 7)
  1531. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 95);
  1532. else if(CurrentChar == 8)
  1533. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 123);
  1534. else if(CurrentChar == 9)
  1535. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 125);
  1536. }
  1537. /* add in the space & add-on guard pattern */
  1538. if(I==1)
  1539. {
  1540. /* Now print add-on delineators between each add-on character */
  1541. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 33);
  1542. }
  1543. else if(I == 2)
  1544. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 33);
  1545. else if(I == 3)
  1546. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 33);
  1547. else if(I == 4)
  1548. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 33);
  1549. else if(I == 5)
  1550. {
  1551. }
  1552. }
  1553. }
  1554. /* Process 2 digit add on if it exists */
  1555. if(strlen(EAN2AddOn)==2)
  1556. {
  1557. int Tempi = atoi(mid(EAN2AddOn, 1, 2));
  1558. /* Get encoding for add on */
  1559. for(I = 0;I <= 99;I = I + 4)
  1560. {
  1561. if(Tempi == I)
  1562. sprintf(Encoding, "AA");
  1563. if(Tempi == I + 1)
  1564. sprintf(Encoding, "AB");
  1565. if(Tempi == I + 2)
  1566. sprintf(Encoding, "BA");
  1567. if(Tempi == I + 3)
  1568. sprintf(Encoding, "BB");
  1569. }
  1570. /* Now that we have the total number including the encoding */
  1571. /* determine what to print */
  1572. DataToPrintBuffer = 0;
  1573. for(I = 1;I <= (int)strlen(EAN2AddOn);I++)
  1574. {
  1575. /* Get the value of each number. It is encoded with variable parity */
  1576. if(I == 1)
  1577. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, " %c", 43);
  1578. CurrentChar = asc(mid(EAN2AddOn, I, 1)) - 48;
  1579. CurrentEncoding = asc(mid(Encoding, I, 1));
  1580. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  1581. if(CurrentEncoding == 'A')
  1582. {
  1583. if(CurrentChar == 0)
  1584. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 34);
  1585. else if(CurrentChar == 1)
  1586. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 35);
  1587. else if(CurrentChar == 2)
  1588. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 36);
  1589. else if(CurrentChar == 3)
  1590. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 37);
  1591. else if(CurrentChar == 4)
  1592. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 38);
  1593. else if(CurrentChar == 5)
  1594. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 44);
  1595. else if(CurrentChar == 6)
  1596. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 46);
  1597. else if(CurrentChar == 7)
  1598. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 47);
  1599. else if(CurrentChar == 8)
  1600. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 58);
  1601. else if(CurrentChar == 9)
  1602. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 59);
  1603. }
  1604. if(CurrentEncoding == 'B')
  1605. {
  1606. if(CurrentChar == 0)
  1607. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 122);
  1608. else if(CurrentChar == 1)
  1609. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 61);
  1610. else if(CurrentChar == 2)
  1611. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 63);
  1612. else if(CurrentChar == 3)
  1613. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 64);
  1614. else if(CurrentChar == 4)
  1615. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 91);
  1616. else if(CurrentChar == 5)
  1617. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 92);
  1618. else if(CurrentChar == 6)
  1619. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 93);
  1620. else if(CurrentChar == 7)
  1621. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 95);
  1622. else if(CurrentChar == 8)
  1623. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 123);
  1624. else if(CurrentChar == 9)
  1625. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 125);
  1626. }
  1627. /* add in the space & add-on guard pattern */
  1628. if(I==1)
  1629. {
  1630. DataToPrintBuffer += sprintf(EANAddOnToPrint + DataToPrintBuffer, "%c", 33);
  1631. }
  1632. }
  1633. }
  1634. LPrintableString[512];
  1635. if(strlen(EAN2AddOn) == 2 || strlen(EAN5AddOn) == 5)
  1636. sprintf(LPrintableString, "%s%s", DataToPrint, EANAddOnToPrint);
  1637. else
  1638. sprintf(LPrintableString, "%s", DataToPrint);
  1639. iSize = (long)strlen(LPrintableString);
  1640. strncpy(output, LPrintableString, strlen(LPrintableString));
  1641. return 0;
  1642. }
  1643. /*****************************************************************/
  1644. /* ANSI C Functions for IDAutomation Barcode Fonts */
  1645. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  1646. /* All rights reserved. */
  1647. /* Redistribution and use of this code in source and/or binary */
  1648. /* forms, with or without modification, are permitted provided */
  1649. /* that: (1) all copies of the source code retain the above */
  1650. /* unmodified copyright notice and this entire unmodified */
  1651. /* section of text, (2) You or Your organization owns a valid */
  1652. /* Developer License to this product from IDAutomation.com */
  1653. /* and, (3) when any portion of this code is bundled in any */
  1654. /* form with an application, a valid notice must be provided */
  1655. /* within the user documentation, start-up screen or in the */
  1656. /* help-about section of the application that specifies */
  1657. /* IDAutomation.com as the provider of the Software bundled */
  1658. /* with the application. */
  1659. /*****************************************************************/
  1660. long IDAutomation_UPCa (char *DataToEncode, char *output, long iSize)
  1661. {
  1662. if(DataToEncode == NULL)
  1663. return 1;
  1664. if(strlen(DataToEncode) == 0)
  1665. return 1;
  1666. char DataToPrint[512];
  1667. char DataToEncode2[512];
  1668. char OnlyCorrectData[512];
  1669. char EAN2AddOn[512];
  1670. char EAN5AddOn[512];
  1671. char EANAddOnToPrint[512];
  1672. char Encoding[512];
  1673. char Temp[512];
  1674. static char PrintableString[512];
  1675. char CurrentChar;
  1676. char CurrentEncoding;
  1677. int Factor;
  1678. int weightedTotal;
  1679. int CheckDigit;
  1680. int Tempi;
  1681. int I;
  1682. DataToPrint[0]=(char)0;
  1683. DataToEncode2[0]=(char)0;
  1684. OnlyCorrectData[0]=(char)0;
  1685. EAN2AddOn[0]=(char)0;
  1686. EAN5AddOn[0]=(char)0;
  1687. EANAddOnToPrint[0]=(char)0;
  1688. Encoding[0]=(char)0;
  1689. Temp[0]=(char)0;
  1690. PrintableString[0]=(char)0;
  1691. sprintf(DataToEncode2,"%s",DataToEncode);
  1692. /* Check to make sure data is numeric and remove dashes, etc. */
  1693. for(I=1;I <= (int)strlen(DataToEncode2);I++)
  1694. {
  1695. /* Add all numbers to OnlyCorrectData string */
  1696. if(isdigit(asc(mid(DataToEncode2,I,1))))
  1697. {
  1698. sprintf(OnlyCorrectData,"%s%s",&OnlyCorrectData,mid(DataToEncode2,I,1));
  1699. }
  1700. }
  1701. /* Remove check digits if they added one */
  1702. if(strlen(OnlyCorrectData)==12)
  1703. {
  1704. sprintf(OnlyCorrectData,"%s",mid(OnlyCorrectData,1,11));
  1705. }
  1706. if(strlen(OnlyCorrectData)==14)
  1707. {
  1708. sprintf(OnlyCorrectData,"%s%s",mid(OnlyCorrectData,1,11),mid(OnlyCorrectData,13,2));
  1709. }
  1710. if(strlen(OnlyCorrectData)==17)
  1711. {
  1712. sprintf(OnlyCorrectData,"%s%s",mid(OnlyCorrectData,1,11),mid(OnlyCorrectData,13,5));
  1713. }
  1714. if(strlen(OnlyCorrectData)==16)
  1715. {
  1716. sprintf(EAN5AddOn,"%s",mid(OnlyCorrectData,12,5));
  1717. }
  1718. if(strlen(OnlyCorrectData)==13)
  1719. {
  1720. sprintf(EAN2AddOn,"%s",mid(OnlyCorrectData,12,2));
  1721. }
  1722. if(strlen(OnlyCorrectData) != 11 && strlen(OnlyCorrectData) != 12 && strlen(OnlyCorrectData) != 14 &&
  1723. strlen(OnlyCorrectData) != 17 && strlen(OnlyCorrectData) != 16 && strlen(OnlyCorrectData) != 13)
  1724. {
  1725. sprintf(OnlyCorrectData,"%s","00000000000");
  1726. }
  1727. /* split 12 digit number from add-on */
  1728. sprintf(DataToEncode2,"%s",mid(OnlyCorrectData,1,11));
  1729. /* <<<< Calculate Check Digit >>>> */
  1730. Factor=3;
  1731. weightedTotal=0;
  1732. for(I = (int)strlen(DataToEncode2);I >= 1;I = I + -1)
  1733. {
  1734. /* Get the value of each number starting at the end */
  1735. CurrentChar=(asc(mid(DataToEncode2,I,1)))-48;
  1736. /* multiply by the weighting factor which is 3,1,3,1... */
  1737. /* and add the sum together */
  1738. weightedTotal=weightedTotal+CurrentChar*Factor;
  1739. /* change factor for next calculation */
  1740. Factor=4-Factor;
  1741. }
  1742. /* Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10 */
  1743. /* divide by 10, get the remainder and subtract from 10 */
  1744. I = (int)(weightedTotal % 10);
  1745. if(I!=0)
  1746. {
  1747. CheckDigit=(10-I);
  1748. }
  1749. else
  1750. {
  1751. CheckDigit=0;
  1752. }
  1753. sprintf(DataToEncode2,"%s%i",&DataToEncode2,CheckDigit);
  1754. /* Now that have the total number including the check digit, determine character to print */
  1755. /* for proper barcoding */
  1756. for(I=1;I <= (int)strlen(DataToEncode2);I++)
  1757. {
  1758. /* Get the ASCII value of each number */
  1759. CurrentChar=asc(mid(DataToEncode2,I,1));
  1760. /* Print different barcodes according to the location of the CurrentChar */
  1761. for(;;)
  1762. {
  1763. if(I==1)
  1764. {
  1765. /* For the first character print the human readable character, the normal */
  1766. /* guard pattern and then the barcode without the human readable character */
  1767. if((CurrentChar-48)>4)
  1768. {
  1769. sprintf(DataToPrint,"%c(%c",CurrentChar+64,CurrentChar+49);
  1770. }
  1771. if((CurrentChar-48)<5)
  1772. {
  1773. sprintf(DataToPrint,"%c(%c",CurrentChar+37,CurrentChar+49);
  1774. }
  1775. break;
  1776. }
  1777. if(I==2)
  1778. {
  1779. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar);
  1780. break;
  1781. }
  1782. if(I==3)
  1783. {
  1784. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar);
  1785. break;
  1786. }
  1787. if(I==4)
  1788. {
  1789. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar);
  1790. break;
  1791. }
  1792. if(I==5)
  1793. {
  1794. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar);
  1795. break;
  1796. }
  1797. if(I==6)
  1798. {
  1799. /* Print the center guard pattern after the 6th character */
  1800. sprintf(DataToPrint,"%s%c*",&DataToPrint,CurrentChar);
  1801. break;
  1802. }
  1803. if(I==7)
  1804. {
  1805. /* Add 27 to the ASII value of characters 6-12 to print from character set+ C */
  1806. /* this is required when printing to the right of the center guard pattern */
  1807. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar+27);
  1808. break;
  1809. }
  1810. if(I==8)
  1811. {
  1812. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar+27);
  1813. break;
  1814. }
  1815. if(I==9)
  1816. {
  1817. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar+27);
  1818. break;
  1819. }
  1820. if(I==10)
  1821. {
  1822. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar+27);
  1823. break;
  1824. }
  1825. if(I==11)
  1826. {
  1827. sprintf(DataToPrint,"%s%c",&DataToPrint,CurrentChar+27);
  1828. break;
  1829. }
  1830. if(I==12)
  1831. {
  1832. /* For the last character print the barcode without the human readable character, */
  1833. /* the normal guard pattern and then the human readable character. */
  1834. if((CurrentChar-48)>4)
  1835. {
  1836. sprintf(DataToPrint,"%s%c(%c",&DataToPrint,CurrentChar+59,CurrentChar+64);
  1837. }
  1838. if((CurrentChar-48)<5)
  1839. {
  1840. sprintf(DataToPrint,"%s%c(%c",&DataToPrint,CurrentChar+59,CurrentChar+37);
  1841. }
  1842. }
  1843. break;
  1844. }
  1845. }
  1846. /* Process 5 digit add on if it exists */
  1847. if(strlen(EAN5AddOn)==5)
  1848. {
  1849. /* Get check digit for add on */
  1850. Factor=3;
  1851. weightedTotal=0;
  1852. for(I = (int)strlen(EAN5AddOn);I >= 1;I--)
  1853. {
  1854. /* Get the value of each number starting at the end */
  1855. CurrentChar=asc(mid(EAN5AddOn,I,1))-48;
  1856. /* multiply by the weighting factor which is 3,9,3,9. */
  1857. /* and add the sum together */
  1858. if(Factor==3)
  1859. {
  1860. weightedTotal=weightedTotal+(CurrentChar*3);
  1861. }
  1862. if(Factor==1)
  1863. {
  1864. weightedTotal=weightedTotal+CurrentChar*9;
  1865. }
  1866. /* change factor for next calculation */
  1867. Factor=4-Factor;
  1868. }
  1869. /* Find the CheckDigit by extracting the right-most number from weightedTotal */
  1870. sprintf(Temp,"%i",weightedTotal);
  1871. CheckDigit = asc(mid(Temp, (int)strlen(Temp), 1)) - 48;
  1872. /* Now we must encode the add-on CheckDigit into the number sets */
  1873. /* by using variable parity between character sets A and B */
  1874. for(;;)
  1875. {
  1876. if(CheckDigit==0)
  1877. {
  1878. sprintf(Encoding,"BBAAA");
  1879. break;
  1880. }
  1881. if(CheckDigit==1)
  1882. {
  1883. sprintf(Encoding,"BABAA");
  1884. break;
  1885. }
  1886. if(CheckDigit==2)
  1887. {
  1888. sprintf(Encoding,"BAABA");
  1889. break;
  1890. }
  1891. if(CheckDigit==3)
  1892. {
  1893. sprintf(Encoding,"BAAAB");
  1894. break;
  1895. }
  1896. if(CheckDigit==4)
  1897. {
  1898. sprintf(Encoding,"ABBAA");
  1899. break;
  1900. }
  1901. if(CheckDigit==5)
  1902. {
  1903. sprintf(Encoding,"AABBA");
  1904. break;
  1905. }
  1906. if(CheckDigit==6)
  1907. {
  1908. sprintf(Encoding,"AAABB");
  1909. break;
  1910. }
  1911. if(CheckDigit==7)
  1912. {
  1913. sprintf(Encoding,"ABABA");
  1914. break;
  1915. }
  1916. if(CheckDigit==8)
  1917. {
  1918. sprintf(Encoding,"ABAAB");
  1919. break;
  1920. }
  1921. if(CheckDigit==9)
  1922. {
  1923. sprintf(Encoding,"AABAB");
  1924. }
  1925. break;
  1926. }
  1927. /* Now that we have the total number including the check digit, determine character to print */
  1928. /* for proper barcoding: */
  1929. for(I=1;I <= (int)strlen(EAN5AddOn);I++)
  1930. {
  1931. /* Get the value of each number */
  1932. /* it is encoded with variable parity */
  1933. CurrentChar=asc(mid(EAN5AddOn,I,1))-48;
  1934. CurrentEncoding=asc(mid(Encoding,I,1));
  1935. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  1936. for(;;)
  1937. {
  1938. if(CurrentEncoding=='A')
  1939. {
  1940. if(CurrentChar==0)
  1941. {
  1942. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,34);
  1943. }
  1944. if(CurrentChar==1)
  1945. {
  1946. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,35);
  1947. }
  1948. if(CurrentChar==2)
  1949. {
  1950. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,36);
  1951. }
  1952. if(CurrentChar==3)
  1953. {
  1954. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,37);
  1955. }
  1956. if(CurrentChar==4)
  1957. {
  1958. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,38);
  1959. }
  1960. if(CurrentChar==5)
  1961. {
  1962. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,44);
  1963. }
  1964. if(CurrentChar==6)
  1965. {
  1966. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,46);
  1967. }
  1968. if(CurrentChar==7)
  1969. {
  1970. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,47);
  1971. }
  1972. if(CurrentChar==8)
  1973. {
  1974. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,58);
  1975. }
  1976. if(CurrentChar==9)
  1977. {
  1978. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,59);
  1979. }
  1980. break;
  1981. }
  1982. if(CurrentEncoding=='B')
  1983. {
  1984. if(CurrentChar==0)
  1985. {
  1986. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,122);
  1987. }
  1988. if(CurrentChar==1)
  1989. {
  1990. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,61);
  1991. }
  1992. if(CurrentChar==2)
  1993. {
  1994. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,63);
  1995. }
  1996. if(CurrentChar==3)
  1997. {
  1998. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,64);
  1999. }
  2000. if(CurrentChar==4)
  2001. {
  2002. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,91);
  2003. }
  2004. if(CurrentChar==5)
  2005. {
  2006. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,92);
  2007. }
  2008. if(CurrentChar==6)
  2009. {
  2010. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,93);
  2011. }
  2012. if(CurrentChar==7)
  2013. {
  2014. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,95);
  2015. }
  2016. if(CurrentChar==8)
  2017. {
  2018. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,123);
  2019. }
  2020. if(CurrentChar==9)
  2021. {
  2022. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,125);
  2023. }
  2024. }
  2025. break;
  2026. }
  2027. /* add in the space & add-on guard pattern */
  2028. for(;;)
  2029. {
  2030. if(I==1)
  2031. {
  2032. sprintf(Temp,"%c%s%c",43,&EANAddOnToPrint,33);
  2033. sprintf(EANAddOnToPrint,"%s",&Temp);
  2034. /* Now print add-on delineators between each add-on character */
  2035. break;
  2036. }
  2037. if(I==2)
  2038. {
  2039. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,33);
  2040. break;
  2041. }
  2042. if(I==3)
  2043. {
  2044. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,33);
  2045. break;
  2046. }
  2047. if(I==4)
  2048. {
  2049. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,33);
  2050. break;
  2051. }
  2052. if(I==5)
  2053. {
  2054. }
  2055. break;
  2056. }
  2057. }
  2058. }
  2059. /* Process 2 digit add on if it exists */
  2060. if(strlen(EAN2AddOn)==2)
  2061. {
  2062. Tempi=(((asc(mid(EAN2AddOn,1,1))))-48)*10;
  2063. Tempi=(Tempi + (asc(mid(EAN2AddOn,2,1))))-48;
  2064. /* Get encoding for add on */
  2065. for(I=0;I<=99;I=I+4)
  2066. {
  2067. if(Tempi==I)
  2068. {
  2069. sprintf(Encoding,"AA");
  2070. }
  2071. if(Tempi==I+1)
  2072. {
  2073. sprintf(Encoding,"AB");
  2074. }
  2075. if(Tempi==I+2)
  2076. {
  2077. sprintf(Encoding,"BA");
  2078. }
  2079. if(Tempi==I+3)
  2080. {
  2081. sprintf(Encoding,"BB");
  2082. }
  2083. }
  2084. /* Now that we have the total number including the encoding */
  2085. /* determine what to print */
  2086. for(I=1;I <= (int)strlen(EAN2AddOn);I++)
  2087. {
  2088. /* Get the value of each number */
  2089. /* it is encoded with variable parity */
  2090. CurrentChar=asc(mid(EAN2AddOn,I,1))-48;
  2091. CurrentEncoding=asc(mid(Encoding,I,1));
  2092. /* Print different barcodes according to the location of the CurrentChar and CurrentEncoding */
  2093. for(;;)
  2094. {
  2095. if(CurrentEncoding=='A')
  2096. {
  2097. if(CurrentChar==0)
  2098. {
  2099. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,34);
  2100. }
  2101. if(CurrentChar==1)
  2102. {
  2103. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,35);
  2104. }
  2105. if(CurrentChar==2)
  2106. {
  2107. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,36);
  2108. }
  2109. if(CurrentChar==3)
  2110. {
  2111. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,37);
  2112. }
  2113. if(CurrentChar==4)
  2114. {
  2115. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,38);
  2116. }
  2117. if(CurrentChar==5)
  2118. {
  2119. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,44);
  2120. }
  2121. if(CurrentChar==6)
  2122. {
  2123. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,46);
  2124. }
  2125. if(CurrentChar==7)
  2126. {
  2127. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,47);
  2128. }
  2129. if(CurrentChar==8)
  2130. {
  2131. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,58);
  2132. }
  2133. if(CurrentChar==9)
  2134. {
  2135. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,59);
  2136. }
  2137. break;
  2138. }
  2139. if(CurrentEncoding=='B')
  2140. {
  2141. if(CurrentChar==0)
  2142. {
  2143. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,122);
  2144. }
  2145. if(CurrentChar==1)
  2146. {
  2147. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,61);
  2148. }
  2149. if(CurrentChar==2)
  2150. {
  2151. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,63);
  2152. }
  2153. if(CurrentChar==3)
  2154. {
  2155. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,64);
  2156. }
  2157. if(CurrentChar==4)
  2158. {
  2159. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,91);
  2160. }
  2161. if(CurrentChar==5)
  2162. {
  2163. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,92);
  2164. }
  2165. if(CurrentChar==6)
  2166. {
  2167. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,93);
  2168. }
  2169. if(CurrentChar==7)
  2170. {
  2171. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,95);
  2172. }
  2173. if(CurrentChar==8)
  2174. {
  2175. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,123);
  2176. }
  2177. if(CurrentChar==9)
  2178. {
  2179. sprintf(EANAddOnToPrint,"%s%c",&EANAddOnToPrint,125);
  2180. }
  2181. }
  2182. break;
  2183. }
  2184. /* add in the space & add-on guard pattern */
  2185. for(;;)
  2186. {
  2187. if(I==1)
  2188. {
  2189. sprintf(Temp,"%c%s%c",43,&EANAddOnToPrint,33);
  2190. sprintf(EANAddOnToPrint,"%s",&Temp);
  2191. /* Now print add-on delineators between each add-on character */
  2192. break;
  2193. }
  2194. if(I==2)
  2195. {
  2196. }
  2197. break;
  2198. }
  2199. }
  2200. }
  2201. /* Get Printable String */
  2202. sprintf(PrintableString,"%s%s", &DataToPrint, &EANAddOnToPrint);
  2203. iSize = (long)strlen(PrintableString);
  2204. strncpy(output, PrintableString, strlen(PrintableString));
  2205. return 0;
  2206. }
  2207. /*****************************************************************/
  2208. /* ANSI C Functions for IDAutomation Barcode Fonts */
  2209. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  2210. /* All rights reserved. */
  2211. /* Redistribution and use of this code in source and/or binary */
  2212. /* forms, with or without modification, are permitted provided */
  2213. /* that: (1) all copies of the source code retain the above */
  2214. /* unmodified copyright notice and this entire unmodified */
  2215. /* section of text, (2) You or Your organization owns a valid */
  2216. /* Developer License to this product from IDAutomation.com */
  2217. /* and, (3) when any portion of this code is bundled in any */
  2218. /* form with an application, a valid notice must be provided */
  2219. /* within the user documentation, start-up screen or in the */
  2220. /* help-about section of the application that specifies */
  2221. /* IDAutomation.com as the provider of the Software bundled */
  2222. /* with the application. */
  2223. /*****************************************************************/
  2224. long IDAutomation_MSI (char *DataToEncode, char *output, long iSize)
  2225. {
  2226. if(DataToEncode == NULL)
  2227. return 1;
  2228. if(strlen(DataToEncode) == 0)
  2229. return 1;
  2230. char DataToPrint[512];
  2231. //DataToPrint = new char[512];
  2232. char OnlyCorrectData[512];
  2233. //OnlyCorrectData = new char[512];
  2234. int sprintBuffer = 0;
  2235. int I;
  2236. for(I = 1;I <= (int)strlen(DataToEncode);I++)
  2237. {
  2238. if(isdigit(asc(mid(DataToEncode, I, 1))))
  2239. {
  2240. sprintBuffer += sprintf(OnlyCorrectData + sprintBuffer, "%s", mid(DataToEncode, I, 1));
  2241. }
  2242. }
  2243. sprintf(DataToPrint,"(%s%s)", OnlyCorrectData, CalcMSICheckDigit(OnlyCorrectData));
  2244. iSize = (long)strlen(DataToPrint);
  2245. strncpy(output, DataToPrint, strlen(DataToPrint));
  2246. return 0;
  2247. }
  2248. char *CalcMSICheckDigit(char DataToEncode[])
  2249. {
  2250. int StringLength = (int)strlen(DataToEncode);
  2251. char OddNumbers[30];
  2252. char sOddNumberProduct[8];
  2253. int OddDigit = TRUE;
  2254. // int OddDigit = 1;
  2255. int EvenNumberSum = 0;
  2256. int BufferCounterOdd = 0;
  2257. int BufferCounterEven = 0;
  2258. int OddNumberProduct = 0;
  2259. int OddNumberSum = 0;
  2260. int CD = 0;
  2261. int Idx = 0;
  2262. static char sCD[1];
  2263. for(Idx = StringLength;Idx >= 0;Idx--)
  2264. {
  2265. if(OddDigit == TRUE)
  2266. {
  2267. BufferCounterOdd += sprintf(OddNumbers + BufferCounterOdd, "%s", mid(DataToEncode, Idx, 1));
  2268. //OddDigit = FALSE;
  2269. OddDigit = 0;
  2270. }
  2271. else
  2272. {
  2273. EvenNumberSum += atoi(mid(DataToEncode, Idx, 1));
  2274. //OddDigit = TRUE;
  2275. OddDigit = 1;
  2276. }
  2277. }
  2278. OddNumberProduct = atoi(OddNumbers) * 2;
  2279. sprintf(sOddNumberProduct, "%d", OddNumberProduct);
  2280. StringLength = (int)strlen(sOddNumberProduct);
  2281. OddNumberSum = 0;
  2282. for(Idx = 1;Idx <= StringLength;Idx++)
  2283. {
  2284. OddNumberSum += atoi(mid(sOddNumberProduct, Idx, 1));
  2285. }
  2286. OddNumberSum = OddNumberSum + EvenNumberSum;
  2287. OddNumberSum = OddNumberSum % 10;
  2288. if(OddNumberSum != 0)
  2289. CD = 10 - OddNumberSum;
  2290. else
  2291. CD = 0;
  2292. sprintf(sCD, "%i", CD);
  2293. return sCD;
  2294. }
  2295. long IDAutomation_Code128HumanReadable (char *DataToEncode, int ApplyTilde, char *output, long iSize)
  2296. {
  2297. if(DataToEncode == NULL)
  2298. return 1;
  2299. if(strlen(DataToEncode) == 0)
  2300. return 1;
  2301. char ReadableText[512];
  2302. //ReadableText = new char[512];
  2303. char StringToCheckFiltered[512];
  2304. //StringToCheckFiltered = new char[512];
  2305. char *RevFilteredString;
  2306. int BufferCounter = 0;
  2307. int BufferCounter2 = 0;
  2308. int i = 0;
  2309. int q = 0;
  2310. int GoodData = 0;
  2311. int FNCDone;
  2312. for(i = 0;i < (int)strlen(DataToEncode);i++)
  2313. {
  2314. FNCDone = FALSE;
  2315. if((int)asc(mid(DataToEncode, i + 1, 1)) != 126 || ApplyTilde == FALSE || strlen(DataToEncode) < 4)
  2316. {
  2317. if(asc(mid(DataToEncode, i + 1, 1)) == 212 && i <= (int)strlen(DataToEncode) - 3) {
  2318. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 2), ") ");
  2319. i += 2;
  2320. }
  2321. else if(asc(mid(DataToEncode, i + 1, 1)) == 213 && i <= (int)strlen(DataToEncode) - 4)
  2322. {
  2323. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 3), ") ");
  2324. i += 3;
  2325. }
  2326. else if(asc(mid(DataToEncode, i + 1, 1)) == 214 && i <= (int)strlen(DataToEncode) - 5)
  2327. {
  2328. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 4), ") ");
  2329. i += 4;
  2330. }
  2331. else if(asc(mid(DataToEncode, i + 1, 1)) == 215 && i <= (int)strlen(DataToEncode) - 6)
  2332. {
  2333. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 5), ") ");
  2334. i += 5;
  2335. }
  2336. else if(asc(mid(DataToEncode, i + 1, 1)) == 216 && i <= (int)strlen(DataToEncode) - 7)
  2337. {
  2338. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 6), ") ");
  2339. i += 6;
  2340. }
  2341. else if(asc(mid(DataToEncode, i + 1, 1)) == 217 && i <= (int)strlen(DataToEncode) - 8)
  2342. {
  2343. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 7), ") ");
  2344. i += 7;
  2345. }
  2346. else if(asc(mid(DataToEncode, i + 1, 1)) == 202 && i <= (int)strlen(DataToEncode) - 4 &&
  2347. isdigit((int) DataToEncode[i + 1]) && isdigit((int) DataToEncode[i + 2]))
  2348. {
  2349. if(atoi(mid(DataToEncode, i + 2, 2)) == 80 || atoi(mid(DataToEncode, i + 2, 2)) == 81 ||
  2350. (atoi(mid(DataToEncode, i + 2, 2)) <= 34 && atoi(mid(DataToEncode, i + 2, 2)) >= 31))
  2351. {
  2352. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 4), ") ");
  2353. i += 4;
  2354. FNCDone = TRUE;
  2355. }
  2356. if(FNCDone == FALSE)
  2357. {
  2358. if((atoi(mid(DataToEncode, i + 2, 2)) <= 49 && atoi(mid(DataToEncode, i + 2, 2)) >= 40) ||
  2359. (atoi(mid(DataToEncode, i + 2, 2)) <= 25 && atoi(mid(DataToEncode, i + 2, 2)) >= 23))
  2360. {
  2361. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 3), ") ");
  2362. i += 3;
  2363. FNCDone = TRUE;
  2364. }
  2365. }
  2366. if(FNCDone == FALSE)
  2367. {
  2368. if((atoi(mid(DataToEncode, i + 2, 2)) <= 30 && atoi(mid(DataToEncode, i + 2, 2)) >= 0) ||
  2369. (atoi(mid(DataToEncode, i + 2, 2)) <= 99 && atoi(mid(DataToEncode, i + 2, 2)) >= 90))
  2370. {
  2371. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 2, 2), ") ");
  2372. i += 2;
  2373. FNCDone = TRUE;
  2374. }
  2375. }
  2376. if(FNCDone == FALSE)
  2377. {
  2378. BufferCounter += sprintf(ReadableText + BufferCounter, "%s%s%s"," (", mid(DataToEncode, i + 4, 4), ") ");
  2379. i += 4;
  2380. FNCDone = TRUE;
  2381. }
  2382. }
  2383. else if(asc(mid(DataToEncode, i + 1, 1)) < 32)
  2384. BufferCounter += sprintf(ReadableText + BufferCounter, "%s", " ");
  2385. else if(asc(mid(DataToEncode, i + 1, 1)) >= 32 && asc(mid(DataToEncode, i + 1, 1)) <= 126)
  2386. BufferCounter += sprintf(ReadableText + BufferCounter, "%s", mid(DataToEncode, i + 1, 1));
  2387. }
  2388. else
  2389. {
  2390. int char0 = (int) asc(mid(DataToEncode, i + 2, 1));
  2391. int char1 = (int) asc(mid(DataToEncode, i + 3, 1));
  2392. int char2 = (int) asc(mid(DataToEncode, i + 4, 1));
  2393. if (i <= (int)strlen(DataToEncode) - 3 && isdigit(char0) && isdigit(char1)
  2394. && isdigit(char2) )
  2395. {
  2396. char *tempNum = mid(DataToEncode,i + 2, 3);
  2397. int convertedValue = atoi(mid(DataToEncode, i + 2, 3));
  2398. if((convertedValue > 0 && convertedValue < 32))
  2399. {
  2400. BufferCounter += sprintf(ReadableText + BufferCounter, "%s", " ");
  2401. i = i + 3;
  2402. }
  2403. else if(convertedValue == 197)
  2404. i = i + 3;
  2405. else if(convertedValue != 197)
  2406. BufferCounter += sprintf(ReadableText + BufferCounter, "%c", DataToEncode[i]);
  2407. }
  2408. else if(((int)strlen(DataToEncode) > 5 && i > 1 && i <= (int)strlen(DataToEncode) - 3) && (int) DataToEncode[i + 1] == 109)
  2409. {
  2410. if(isdigit(DataToEncode[i + 2]) && isdigit(DataToEncode[i + 3]))
  2411. {
  2412. int NumCharsToConvert = atoi(mid(DataToEncode, i + 3, 2));
  2413. if(i - (NumCharsToConvert - 1) >= 0)
  2414. {
  2415. char *StringToCheck = mid(DataToEncode, i - NumCharsToConvert + 1, NumCharsToConvert);
  2416. int NumCharsFiltered = 0;
  2417. GoodData = 0;
  2418. BufferCounter2 = 0;
  2419. for(q = (int)strlen(StringToCheck);q > 0 ;q--)
  2420. {
  2421. GoodData = FALSE;
  2422. if((int)StringToCheck[q - 1] > 0 && (int)StringToCheck[q - 1] <= 126 && isdigit((int)StringToCheck[q - 1]))
  2423. GoodData = TRUE;;
  2424. if(GoodData)
  2425. {
  2426. if(NumCharsFiltered < NumCharsToConvert )
  2427. {
  2428. BufferCounter2 += sprintf(StringToCheckFiltered + BufferCounter2, "%s", mid(StringToCheck, q, 1));
  2429. NumCharsFiltered++;
  2430. }
  2431. else
  2432. break;
  2433. }
  2434. }
  2435. if(StringToCheckFiltered == "")
  2436. GoodData = FALSE;
  2437. else
  2438. {
  2439. GoodData = TRUE;
  2440. RevFilteredString = strrev(StringToCheckFiltered);
  2441. }
  2442. if(GoodData != FALSE)
  2443. {
  2444. BufferCounter += sprintf(ReadableText + BufferCounter, "%c", FindMod10Digit(RevFilteredString));
  2445. i += 3;
  2446. }
  2447. else
  2448. BufferCounter += sprintf(ReadableText + BufferCounter, "%c", DataToEncode[i]);
  2449. }
  2450. else
  2451. BufferCounter += sprintf(ReadableText + BufferCounter, "%c", DataToEncode[i]);
  2452. }
  2453. else
  2454. BufferCounter += sprintf(ReadableText + BufferCounter, "%c", DataToEncode[i]);
  2455. }
  2456. }
  2457. }
  2458. iSize = (long)strlen(ReadableText);
  2459. strncpy(output, ReadableText, strlen(ReadableText));
  2460. return 0;
  2461. }
  2462. long IDAutomation_UCC128 (char *DataToEncode, char *output, long iSize)
  2463. {
  2464. char StringToPass[512];
  2465. //StringToPass = new char[512];
  2466. int char0 = (int) asc(mid(DataToEncode, 1, 1));
  2467. // check for FNC1 character, if one is there; do nothing
  2468. if(char0 == 202 || (char0 > 211 && char0 < 218))
  2469. sprintf(StringToPass, "%s", DataToEncode);
  2470. else//insert FNC1 in the begining of the string
  2471. sprintf(StringToPass, "%c%s", (char)202, DataToEncode);
  2472. int iTilde = 1;
  2473. IDAutomation_Code128(StringToPass, iTilde, output, iSize);
  2474. return 0;
  2475. }
  2476. /*****************************************************************/
  2477. /* ANSI C Functions for IDAutomation Barcode Fonts */
  2478. /* ?Copyright 2002- 2007, IDAutomation.com, Inc. */
  2479. /* All rights reserved. */
  2480. /* Redistribution and use of this code in source and/or binary */
  2481. /* forms, with or without modification, are permitted provided */
  2482. /* that: (1) all copies of the source code retain the above */
  2483. /* unmodified copyright notice and this entire unmodified */
  2484. /* section of text, (2) You or Your organization owns a valid */
  2485. /* Developer License to this product from IDAutomation.com */
  2486. /* and, (3) when any portion of this code is bundled in any */
  2487. /* form with an application, a valid notice must be provided */
  2488. /* within the user documentation, start-up screen or in the */
  2489. /* help-about section of the application that specifies */
  2490. /* IDAutomation.com as the provider of the Software bundled */
  2491. /* with the application. */
  2492. /*****************************************************************/
  2493. long IDAutomation_Code128 (char *DataToEncode, int ApplyTilde, char *output, long iSize)
  2494. {
  2495. if(DataToEncode == NULL)
  2496. return 1;
  2497. if(strlen(DataToEncode) == 0)
  2498. return 1;
  2499. char PrintableString[512];
  2500. //PrintableString = new char[512];
  2501. char OnlyCorrectData[512];
  2502. //OnlyCorrectData = new char[512];
  2503. char StringToCheckFiltered[512];
  2504. //StringToCheckFiltered = new char[512];
  2505. char tildeStringToCheck[512];
  2506. //tildeStringToCheck = new char[512];
  2507. char CurrentEncoding;
  2508. char StartChar;
  2509. char StopChar;
  2510. int DataToEncodeLength = 0;
  2511. int CurrentValue = 0;
  2512. int i = 0;
  2513. int GoodData = 0;
  2514. int q = 0;
  2515. char *RevFilteredString;
  2516. int BufferCounter = 0;
  2517. int L_BufferCounter = 0;
  2518. int WeightedTotal = 0;
  2519. int StringLength = 0;
  2520. int CurrentCharNumber = 0;
  2521. int CheckDigitValue = 0;
  2522. DataToEncodeLength = (int)strlen(DataToEncode);
  2523. PrintableString[0]=(char)0;
  2524. StopChar = (char)206;
  2525. if(((int)asc(mid(DataToEncode, 1, 1))) < 32)
  2526. {
  2527. StartChar = (char) 203;
  2528. CurrentEncoding = 'A';
  2529. }
  2530. if(((int) asc(mid(DataToEncode, 1, 1)) > 31 && (int) asc(mid(DataToEncode, 1, 1)) < 127) || ((int) asc(mid(DataToEncode, 1, 1)) == 197))
  2531. {
  2532. StartChar = (char) 204;
  2533. CurrentEncoding = 'B';
  2534. }
  2535. if(DataToEncodeLength > 3 && isdigit(DataToEncode[0]) && isdigit(DataToEncode[1]) &&
  2536. isdigit(DataToEncode[2]) && isdigit(DataToEncode[3]))
  2537. {
  2538. StartChar = (char) 205;
  2539. CurrentEncoding = 'C';
  2540. }
  2541. if ((int) asc(mid(DataToEncode, 1, 1)) == 202 || ((int) asc(mid(DataToEncode, 1, 1)) >= 212 && (int) asc(mid(DataToEncode, 1, 1)) <= 217))
  2542. {
  2543. StartChar = (char) 205;
  2544. CurrentEncoding = 'C';
  2545. }
  2546. for(i = 0; i <= DataToEncodeLength - 1; i++)
  2547. {
  2548. if((DataToEncodeLength > 5 && i > 1 && i <= DataToEncodeLength - 3) && (int) DataToEncode[i] == 126
  2549. && (int) DataToEncode[i + 1] == 109 && ApplyTilde)
  2550. {
  2551. if(isdigit(DataToEncode[i + 2]) && isdigit(DataToEncode[i + 3]))
  2552. {
  2553. int NumCharsToConvert = atoi(mid(DataToEncode, i + 3, 2));
  2554. if(i - (NumCharsToConvert - 1) >= 0)
  2555. {
  2556. char *StringToCheck = mid(DataToEncode, i - NumCharsToConvert + 1, NumCharsToConvert);
  2557. char StringToCheckFiltered[40];
  2558. int NumCharsFiltered = 0;
  2559. GoodData = 0;
  2560. BufferCounter = 0;
  2561. for(q = (int)strlen(StringToCheck);q > 0 ;q--)
  2562. {
  2563. GoodData = isdigit((int)StringToCheck[q - 1]);
  2564. if(GoodData)
  2565. {
  2566. if(NumCharsFiltered < NumCharsToConvert )
  2567. {
  2568. BufferCounter += sprintf(StringToCheckFiltered + BufferCounter, "%s", mid(StringToCheck, q, 1));
  2569. NumCharsFiltered++;
  2570. }
  2571. else
  2572. break;
  2573. }
  2574. }
  2575. if(StringToCheckFiltered == "")
  2576. GoodData = FALSE;
  2577. else
  2578. {
  2579. GoodData = TRUE;
  2580. RevFilteredString = strrev(StringToCheckFiltered);
  2581. }
  2582. if(GoodData != FALSE)
  2583. {
  2584. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", FindMod10Digit(RevFilteredString));
  2585. i += 3;
  2586. }
  2587. else
  2588. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2589. }
  2590. else
  2591. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2592. }
  2593. else
  2594. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2595. }
  2596. else if ((DataToEncodeLength >= 4 && i <= DataToEncodeLength - 3) && (int) DataToEncode[i] == 126
  2597. && isdigit((int) DataToEncode[i + 1]) && isdigit((int) DataToEncode[i + 2])
  2598. && isdigit((int) DataToEncode[i + 3]) && ApplyTilde)
  2599. {
  2600. int convertedValue = atoi(mid(DataToEncode, i + 2, 3));
  2601. if((convertedValue > 0 && convertedValue < 32) || convertedValue == 197 || convertedValue == 202 ||
  2602. (convertedValue > 211 && convertedValue < 218))
  2603. {
  2604. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", (char) (convertedValue));
  2605. i = i + 3;
  2606. }
  2607. else
  2608. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2609. }
  2610. else if((DataToEncodeLength >= 2 && i <= DataToEncodeLength - 2) && (int) DataToEncode[i] == 126
  2611. && (int) DataToEncode[i + 1] == 126 && ApplyTilde)
  2612. {
  2613. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2614. i = i + 1;
  2615. }
  2616. else
  2617. L_BufferCounter += sprintf(OnlyCorrectData + L_BufferCounter,"%c", DataToEncode[i]);
  2618. }
  2619. L_BufferCounter = 0;
  2620. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", StartChar);
  2621. DataToEncodeLength = (int)strlen(OnlyCorrectData);
  2622. for(i = 0; i <= DataToEncodeLength - 1; i++)
  2623. {
  2624. if( i < DataToEncodeLength - 1 && ((int) asc(mid(OnlyCorrectData, i + 1, 1)) == 202 || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 212 || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 213
  2625. || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 214 || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 215
  2626. || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 216 || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 217 || (int) asc(mid(OnlyCorrectData, i + 1, 1)) == 218))
  2627. {
  2628. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)202);
  2629. }
  2630. else if
  2631. ( (DataToEncodeLength > 3 && i <= (DataToEncodeLength - 2)) &&
  2632. ((isdigit((int) OnlyCorrectData[i]) && isdigit((int) OnlyCorrectData[i + 1]) &&
  2633. isdigit((int) OnlyCorrectData[i + 2]) && isdigit((int) OnlyCorrectData[i + 3]) ) ||
  2634. (i <= DataToEncodeLength - 1 && isdigit((int) OnlyCorrectData[i]) &&
  2635. isdigit((int) OnlyCorrectData[i + 1]) && CurrentEncoding == 'C' )))
  2636. {
  2637. if (CurrentEncoding != 'C')
  2638. {
  2639. int j = i;
  2640. int Factor = 3;
  2641. while (j <= DataToEncodeLength-1 && isdigit((int)(OnlyCorrectData[j])))
  2642. {
  2643. Factor = (4 - Factor);
  2644. j++;
  2645. }
  2646. if (Factor == 1)
  2647. {
  2648. L_BufferCounter += sprintf(PrintableString + L_BufferCounter ,"%c", DataToEncode[i]);
  2649. i++;
  2650. }
  2651. Factor = 0;
  2652. }
  2653. if(CurrentEncoding != 'C')
  2654. {
  2655. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)199);
  2656. CurrentEncoding = 'C';
  2657. }
  2658. /* Get the value of each number pair */
  2659. CurrentValue = atoi(mid(OnlyCorrectData, i + 1, 2));
  2660. /* Get the DataToPrint */
  2661. if(CurrentValue < 95 && CurrentValue > 0)
  2662. {
  2663. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)(CurrentValue + 32));
  2664. }
  2665. if(CurrentValue > 94)
  2666. {
  2667. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)(CurrentValue + 100));
  2668. }
  2669. if(CurrentValue == 0)
  2670. {
  2671. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)194);
  2672. }
  2673. i++;
  2674. }
  2675. else if((i <= DataToEncodeLength - 1) && (((int) asc(mid(OnlyCorrectData, i + 1, 1)) < 32) || ((CurrentEncoding == 'A') && ((int) asc(mid(OnlyCorrectData, i + 1, 1)) < 96))))
  2676. {
  2677. if (CurrentEncoding != 'A')
  2678. {
  2679. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)201);
  2680. CurrentEncoding = 'A';
  2681. }
  2682. if ((int) OnlyCorrectData[i] < 32)
  2683. {
  2684. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)((int) OnlyCorrectData[i] + 96));
  2685. }
  2686. else if ((int) OnlyCorrectData[i] > 31)
  2687. {
  2688. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)OnlyCorrectData[i]);
  2689. }
  2690. else if ((int) OnlyCorrectData[i] == 32)
  2691. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)194);
  2692. }
  2693. else if((int) asc(mid(OnlyCorrectData, i + 1, 1)) == 197)
  2694. {
  2695. if(CurrentEncoding == 'C')
  2696. {
  2697. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)200);
  2698. CurrentEncoding = 'B';
  2699. }
  2700. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", OnlyCorrectData[i]);
  2701. }
  2702. else if ((i <= DataToEncodeLength - 1) && ((int) asc(mid(OnlyCorrectData, i + 1, 1)) > 31 && (int) asc(mid(OnlyCorrectData, i + 1, 1)) < 127))
  2703. {
  2704. if (CurrentEncoding != 'B')
  2705. {
  2706. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)200);
  2707. CurrentEncoding = 'B';
  2708. }
  2709. if ((int) OnlyCorrectData[i] == 32)
  2710. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)194);
  2711. else
  2712. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", OnlyCorrectData[i]);
  2713. }
  2714. }
  2715. WeightedTotal = (asc(&StartChar) - 100);
  2716. StringLength = (int)strlen(PrintableString);
  2717. CurrentCharNumber = 0;
  2718. CurrentValue = 0;
  2719. CheckDigitValue = 0;
  2720. for(q = 2;q <= StringLength;q++)
  2721. {
  2722. CurrentCharNumber = asc(mid(PrintableString, q, 1));
  2723. if(CurrentCharNumber < 135)
  2724. CurrentValue = (CurrentCharNumber - 32);
  2725. else if(CurrentCharNumber > 134 && CurrentCharNumber != 194)
  2726. CurrentValue = (CurrentCharNumber - 100);
  2727. else if(CurrentCharNumber == 194)
  2728. CurrentValue = 0;
  2729. CurrentValue = CurrentValue * (q - 1);
  2730. WeightedTotal = WeightedTotal + CurrentValue;
  2731. }
  2732. CheckDigitValue = (WeightedTotal % 103);
  2733. if(CheckDigitValue < 95 && CheckDigitValue > 0)
  2734. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)(CheckDigitValue + 32));
  2735. else if(CheckDigitValue > 94)
  2736. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)(CheckDigitValue + 100));
  2737. else if(CheckDigitValue == 0)
  2738. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", (char)(194));
  2739. L_BufferCounter += sprintf(PrintableString + L_BufferCounter,"%c", StopChar);
  2740. iSize = (long)strlen(PrintableString);
  2741. strncpy(output, PrintableString, strlen(PrintableString));
  2742. return 0;
  2743. }
  2744. char FindMod10Digit(char *input)
  2745. {
  2746. int remainder;
  2747. int M10Factor = 0;
  2748. int M10WeightedTotal = 0;
  2749. int M10StringLength = 0;
  2750. int M10I = 0;
  2751. M10Factor = 3;
  2752. M10WeightedTotal = 0;
  2753. M10StringLength = (int)strlen(input);
  2754. for(M10I = M10StringLength;M10I > 0;M10I--)
  2755. {
  2756. M10WeightedTotal = M10WeightedTotal + (atoi(mid(input, M10I, 1)) * M10Factor);
  2757. M10Factor = 4 - M10Factor;
  2758. }
  2759. remainder = M10WeightedTotal % 10;
  2760. if (remainder == 0)
  2761. return (char)48;
  2762. else
  2763. return (char) ((10 - remainder) + 48);
  2764. }
  2765. void UPCe7to11(char DataToExpand[])
  2766. {
  2767. if (strlen(DataToExpand) == 6)
  2768. {
  2769. char buf[255];
  2770. int n = 1 + (int)strlen(DataToExpand);
  2771. int i =0;
  2772. for (i=n-1;i>=0;i--)
  2773. {
  2774. buf[n] = DataToExpand[i];
  2775. n--;
  2776. }
  2777. buf[0] = '0';
  2778. strcpy(DataToExpand,buf);
  2779. }
  2780. char D1 = DataToExpand[0];
  2781. char D2 = DataToExpand[1];
  2782. char D3 = DataToExpand[2];
  2783. char D4 = DataToExpand[3];
  2784. char D5 = DataToExpand[4];
  2785. char D6 = DataToExpand[5];
  2786. char D7 = DataToExpand[6];
  2787. switch (D7)
  2788. {
  2789. case '0':
  2790. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2791. DataToExpand[3] = '0'; DataToExpand[4] = '0'; DataToExpand[5] = '0';
  2792. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = D4;
  2793. DataToExpand[9] = D5; DataToExpand[10] = D6;
  2794. break;
  2795. case '1':
  2796. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2797. DataToExpand[3] = D7; DataToExpand[4] = '0'; DataToExpand[5] = '0';
  2798. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = D4;
  2799. DataToExpand[9] = D5; DataToExpand[10] = D6;
  2800. break;
  2801. case '2':
  2802. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2803. DataToExpand[3] = D7; DataToExpand[4] = '0'; DataToExpand[5] = '0';
  2804. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = D4;
  2805. DataToExpand[9] = D5; DataToExpand[10] = D6;
  2806. break;
  2807. case '3':
  2808. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2809. DataToExpand[3] = D4; DataToExpand[4] = '0'; DataToExpand[5] = '0';
  2810. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2811. DataToExpand[9] = D5; DataToExpand[10] = D6;
  2812. break;
  2813. case '4':
  2814. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2815. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = '0';
  2816. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2817. DataToExpand[9] = '0'; DataToExpand[10] = D6;
  2818. break;
  2819. case '5':
  2820. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2821. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = D6;
  2822. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2823. DataToExpand[9] = '0'; DataToExpand[10] = D7;
  2824. break;
  2825. case '6':
  2826. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2827. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = D6;
  2828. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2829. DataToExpand[9] = '0'; DataToExpand[10] = D7;
  2830. break;
  2831. case '7':
  2832. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2833. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = D6;
  2834. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2835. DataToExpand[9] = '0'; DataToExpand[10] = D7;
  2836. break;
  2837. case '8':
  2838. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2839. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = D6;
  2840. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2841. DataToExpand[9] = '0'; DataToExpand[10] = D7;
  2842. break;
  2843. case '9':
  2844. DataToExpand[0] = D1; DataToExpand[1] = D2; DataToExpand[2] = D3;
  2845. DataToExpand[3] = D4; DataToExpand[4] = D5; DataToExpand[5] = D6;
  2846. DataToExpand[6] = '0'; DataToExpand[7] = '0'; DataToExpand[8] = '0';
  2847. DataToExpand[9] = '0'; DataToExpand[10] = D7;
  2848. break;
  2849. }
  2850. DataToExpand[11] =(int) NULL;
  2851. }
  2852. /*********************************************************************/
  2853. /* Visual Basic / VBA Functions for Bar Code Fonts 5.01*/
  2854. /* Copyright, IDAutomation.com, Inc. 2000-2005. All rights reserved.*/
  2855. /**/
  2856. /* Visit http://www.idautomation.com/fonts/tools/vba/ for more*/
  2857. /* information about the functions in this file.*/
  2858. /**/
  2859. /* You may incorporate our Source Code in your application*/
  2860. /* only if you own a valid license from IDAutomation.com, Inc.*/
  2861. /* for the associated font and this text and the copyright notices*/
  2862. /* are not removed from the source code.(/
  2863. /**/
  2864. /* Distributing our source code or fonts outside your*/
  2865. /* organization requires a Developer License. */
  2866. /*********************************************************************/
  2867. long IDAutomation_UPCe (char *DataToEncode, char *output, long iSize)
  2868. {
  2869. if(DataToEncode == NULL)
  2870. return 1;
  2871. if(strlen(DataToEncode) == 0)
  2872. return 1;
  2873. int StringLength = 0;
  2874. int I = 0;
  2875. char LPrintableString[512];
  2876. //LPrintableString = new char[512];
  2877. char ActualDataToEncode[20];
  2878. //ActualDataToEncode = new char[20];
  2879. char DataToPrint[512];
  2880. //DataToPrint = new char[512];
  2881. char EAN2AddOn[3];
  2882. //EAN2AddOn = new char[3];
  2883. char OnlyCorrectData[20];
  2884. //OnlyCorrectData = new char[20];
  2885. char EAN5AddOn[6];
  2886. //EAN5AddOn = new char[6];
  2887. char EANAddOnToPrint[11];
  2888. //EANAddOnToPrint = new char[11];
  2889. int Factor = 3;
  2890. int WeightedTotal = 0;
  2891. int CheckDigit = 0;
  2892. char *Encoding;
  2893. int CurrentNumber;
  2894. char midEncoding;
  2895. char *sCheck = 0;
  2896. int bufferCounter = 0;
  2897. char *D1;
  2898. char *D2;
  2899. char *D3;
  2900. char *D4;
  2901. char *D5;
  2902. char *D6;
  2903. char *D7;
  2904. char *D8;
  2905. char *D9;
  2906. char *D10;
  2907. char *D11;
  2908. char *D12;
  2909. StringLength = (int)strlen(DataToEncode);
  2910. LPrintableString[0]=(char)0;
  2911. if(StringLength > 20)
  2912. StringLength = 20;
  2913. for(I = 0;I < StringLength;I++)
  2914. {
  2915. if(isdigit((int)DataToEncode[I]))
  2916. {
  2917. bufferCounter += sprintf(OnlyCorrectData + bufferCounter, "%c", DataToEncode[I]);
  2918. }
  2919. }
  2920. if(strlen(OnlyCorrectData) == 6 || strlen(OnlyCorrectData) == 7 || strlen(OnlyCorrectData) == 8)
  2921. {
  2922. UPCe7to11(OnlyCorrectData);
  2923. }
  2924. if(strlen(OnlyCorrectData) < 11)
  2925. {
  2926. sprintf(LPrintableString,"%s","00005000000");
  2927. return 0;
  2928. }
  2929. if(strlen(OnlyCorrectData) == 15)
  2930. {
  2931. sprintf(LPrintableString,"%s","00005000000");
  2932. return 0;
  2933. }
  2934. if(strlen(OnlyCorrectData) > 18 && OnlyCorrectData[11] != (int) NULL)
  2935. {
  2936. sprintf(LPrintableString,"%s","00005000000");
  2937. return 0;
  2938. }
  2939. if(strlen(OnlyCorrectData) == 12)
  2940. sprintf(LPrintableString,"%s", mid(OnlyCorrectData, 1, 11));
  2941. if(strlen(OnlyCorrectData) == 14)
  2942. sprintf(LPrintableString,"%s%s", mid(OnlyCorrectData, 1, 11), mid(OnlyCorrectData, 13, 2));
  2943. if(strlen(OnlyCorrectData) == 17)
  2944. sprintf(LPrintableString,"%s%s", mid(OnlyCorrectData, 1, 11), mid(OnlyCorrectData, 13, 5));
  2945. if(strlen(OnlyCorrectData) == 16)
  2946. sprintf(EAN5AddOn,"%s", mid(OnlyCorrectData, 12, 5));
  2947. else if(strlen(OnlyCorrectData) == 13)
  2948. {
  2949. sprintf(EAN2AddOn,"%s", mid(OnlyCorrectData, 12, 2));
  2950. }
  2951. else
  2952. {
  2953. sprintf(EAN2AddOn,"%s", "");
  2954. sprintf(EAN5AddOn,"%s", "");
  2955. sprintf(EANAddOnToPrint,"%s", "");
  2956. }
  2957. if(strlen(OnlyCorrectData) > 11)
  2958. sprintf(OnlyCorrectData,"%s", mid(OnlyCorrectData, 1, 11));
  2959. Factor = 3;
  2960. WeightedTotal = 0;
  2961. for(I = (int)strlen(OnlyCorrectData);I >= 0;I--)
  2962. {
  2963. CurrentNumber = atoi(mid(OnlyCorrectData, I, 1));
  2964. WeightedTotal = WeightedTotal + (CurrentNumber * Factor);
  2965. Factor = 4 - Factor;
  2966. }
  2967. I = (WeightedTotal % 10);
  2968. if(I != 0)
  2969. CheckDigit = (10 - I);
  2970. else
  2971. CheckDigit = 0;
  2972. sprintf(OnlyCorrectData,"%s%i", OnlyCorrectData, CheckDigit);
  2973. D1 = mid(OnlyCorrectData, 1, 1);
  2974. D2 = mid(OnlyCorrectData, 2, 1);
  2975. D3 = mid(OnlyCorrectData, 3, 1);
  2976. D4 = mid(OnlyCorrectData, 4, 1);
  2977. D5 = mid(OnlyCorrectData, 5, 1);
  2978. D6 = mid(OnlyCorrectData, 6, 1);
  2979. D7 = mid(OnlyCorrectData, 7, 1);
  2980. D8 = mid(OnlyCorrectData, 8, 1);
  2981. D9 = mid(OnlyCorrectData, 9, 1);
  2982. D10 = mid(OnlyCorrectData, 10, 1);
  2983. D11 = mid(OnlyCorrectData, 11, 1);
  2984. D12 = mid(OnlyCorrectData, 12, 1);
  2985. if((atoi(D11) == 5 || atoi(D11) == 6 || atoi(D11) == 7 || atoi(D11) == 8 || atoi(D11) == 9) &&
  2986. (atoi(D6) != 0 && atoi(D7) == 0 && atoi(D8) == 0 && atoi(D9) == 0 && atoi(D10) == 0))
  2987. {
  2988. sprintf(ActualDataToEncode, "%s%s%s%s%s%s", D2, D3, D4, D5, D6, D11);
  2989. }
  2990. else if((atoi(D6) == 0 && atoi(D7) == 0 && atoi(D8) == 0 && atoi(D9) == 0 && atoi(D10) == 0) && atoi(D5) != 0)
  2991. {
  2992. sprintf(ActualDataToEncode, "%s%s%s%s%s%s", D2, D3, D4, D5, D11, "4");
  2993. }
  2994. else if((atoi(D5) == 0 && atoi(D6) == 0 && atoi(D7) == 0 && atoi(D8) == 0)
  2995. && (atoi(D4) == 1 || atoi(D4) == 2 || atoi(D4) == 0))
  2996. {
  2997. sprintf(ActualDataToEncode, "%s%s%s%s%s%s", D2, D3, D9, D10, D11, D4);
  2998. }
  2999. else if((atoi(D5) == 0 && atoi(D6) == 0 && atoi(D7) == 0 && atoi(D8) == 0 && atoi(D9) == 0) &&
  3000. (atoi(D4) == 3 || atoi(D4) == 4 || atoi(D4) == 5 || atoi(D4) == 6 || atoi(D4) == 7 || atoi(D4) == 8 || atoi(D4) == 9) )
  3001. {
  3002. sprintf(ActualDataToEncode, "%s%s%s%s%s%s", D2, D3, D4, D10, D11, "3");
  3003. }
  3004. else
  3005. {
  3006. sprintf(ActualDataToEncode, "%s", OnlyCorrectData);
  3007. }
  3008. if(strlen(ActualDataToEncode) == 6)
  3009. {
  3010. if(atoi(D1) == 1)
  3011. {
  3012. switch(atoi(D12))
  3013. {
  3014. case 0:
  3015. Encoding = "AAABBB";
  3016. break;
  3017. case 1:
  3018. Encoding = "AABABB";
  3019. break;
  3020. case 2:
  3021. Encoding = "AABBAB";
  3022. break;
  3023. case 3:
  3024. Encoding = "AABBBA";
  3025. break;
  3026. case 4:
  3027. Encoding = "ABAABB";
  3028. break;
  3029. case 5:
  3030. Encoding = "ABBAAB";
  3031. break;
  3032. case 6:
  3033. Encoding = "ABBBAA";
  3034. break;
  3035. case 7:
  3036. Encoding = "ABABAB";
  3037. break;
  3038. case 8:
  3039. Encoding = "ABABBA";
  3040. break;
  3041. case 9:
  3042. Encoding = "ABBABA";
  3043. break;
  3044. }
  3045. }
  3046. else
  3047. {
  3048. switch(atoi(D12))
  3049. {
  3050. case 0:
  3051. Encoding = "BBBAAA";
  3052. break;
  3053. case 1:
  3054. Encoding = "BBABAA";
  3055. break;
  3056. case 2:
  3057. Encoding = "BBAABA";
  3058. break;
  3059. case 3:
  3060. Encoding = "BBAAAB";
  3061. break;
  3062. case 4:
  3063. Encoding = "BABBAA";
  3064. break;
  3065. case 5:
  3066. Encoding = "BAABBA";
  3067. break;
  3068. case 6:
  3069. Encoding = "BAAABB";
  3070. break;
  3071. case 7:
  3072. Encoding = "BABABA";
  3073. break;
  3074. case 8:
  3075. Encoding = "BABAAB";
  3076. break;
  3077. case 9:
  3078. Encoding = "BAABAB";
  3079. break;
  3080. }
  3081. }
  3082. bufferCounter = 0;
  3083. for(I = 1;I <= (int)strlen(ActualDataToEncode);I++)
  3084. {
  3085. if(I == 1)
  3086. {
  3087. if(asc(mid(OnlyCorrectData, I, 1)) == 48)
  3088. {
  3089. bufferCounter += sprintf(DataToPrint, "%c%s", (char)85, "(");
  3090. }
  3091. else
  3092. {
  3093. bufferCounter += sprintf(DataToPrint, "%c%s", (char)86, "(");
  3094. }
  3095. }
  3096. CurrentNumber = asc(mid(ActualDataToEncode, I, 1));
  3097. midEncoding = Encoding[I - 1];
  3098. switch(midEncoding)
  3099. {
  3100. case 'A':
  3101. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)CurrentNumber);
  3102. break;
  3103. case 'B':
  3104. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 17));
  3105. break;
  3106. }
  3107. switch(I)
  3108. {
  3109. case 1:
  3110. /* if(atoi(D1) == 0)
  3111. {
  3112. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s", (char)85, "(");
  3113. }
  3114. if(atoi(D1) == 1)
  3115. {
  3116. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s", (char)86, "(");
  3117. }*/
  3118. break;
  3119. case 6:
  3120. if(atoi(D12) > 4)
  3121. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s%c", ")", (char)(asc(D12) + 64));
  3122. if(atoi(D12) < 5)
  3123. bufferCounter += sprintf(DataToPrint + bufferCounter, "%s%c", ")", (char)(asc(D12) + 37));
  3124. break;
  3125. }
  3126. }
  3127. }
  3128. bufferCounter = 0;
  3129. if(strlen(ActualDataToEncode) != 6)
  3130. {
  3131. for(I = 1;I <= (int)strlen(ActualDataToEncode);I++)
  3132. {
  3133. CurrentNumber = asc(mid(ActualDataToEncode, I, 1));
  3134. switch(I)
  3135. {
  3136. case 1:
  3137. if(atoi(mid(ActualDataToEncode, I, 1)) > 4)
  3138. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s%c", (char)(CurrentNumber + 64), "(", (char)(CurrentNumber + 49));
  3139. if(atoi(mid(ActualDataToEncode, I, 1)) < 5)
  3140. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s%c", (char)(CurrentNumber + 37), "(", (char)(CurrentNumber + 49));
  3141. break;
  3142. case 2:
  3143. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", mid(ActualDataToEncode, I, 1));
  3144. break;
  3145. case 3:
  3146. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", mid(ActualDataToEncode, I, 1));
  3147. break;
  3148. case 4:
  3149. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", mid(ActualDataToEncode, I, 1));
  3150. break;
  3151. case 5:
  3152. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", mid(ActualDataToEncode, I, 1));
  3153. break;
  3154. case 6:
  3155. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s", mid(ActualDataToEncode, I, 1), "*");
  3156. break;
  3157. case 7:
  3158. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 27));
  3159. break;
  3160. case 8:
  3161. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 27));
  3162. break;
  3163. case 9:
  3164. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 27));
  3165. break;
  3166. case 10:
  3167. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 27));
  3168. break;
  3169. case 11:
  3170. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c", (char)(CurrentNumber + 27));
  3171. break;
  3172. case 12:
  3173. if(atoi(mid(ActualDataToEncode, I, 1)) > 4)
  3174. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s%c", (char)(CurrentNumber + 59), ")", (char)(CurrentNumber + 64));
  3175. if(atoi(mid(ActualDataToEncode, I, 1)) < 5)
  3176. bufferCounter += sprintf(DataToPrint + bufferCounter, "%c%s%c", (char)(CurrentNumber + 59), ")", (char)(CurrentNumber + 37));
  3177. break;
  3178. }
  3179. }
  3180. }
  3181. if(strlen(EAN5AddOn) == 5)
  3182. {
  3183. Factor = 3;
  3184. WeightedTotal = 0;
  3185. for(I= (int)strlen(EAN5AddOn);I >= 0;I--)
  3186. {
  3187. CurrentNumber = atoi(mid(EAN5AddOn, I, 1));
  3188. if(Factor = 3)
  3189. WeightedTotal = WeightedTotal + (CurrentNumber * 3);
  3190. if(Factor = 1 )
  3191. WeightedTotal = WeightedTotal + (CurrentNumber * 9);
  3192. Factor = 4 - Factor;
  3193. }
  3194. sprintf(sCheck,"%i", WeightedTotal);
  3195. CheckDigit = atoi(mid(sCheck, (int)strlen(sCheck), 1));
  3196. switch(CheckDigit)
  3197. {
  3198. case 0:
  3199. Encoding = "BBAAA";
  3200. break;
  3201. case 1:
  3202. Encoding = "BABAA";
  3203. break;
  3204. case 2:
  3205. Encoding = "BAABA";
  3206. break;
  3207. case 3:
  3208. Encoding = "BAAAB";
  3209. break;
  3210. case 4:
  3211. Encoding = "ABBAA";
  3212. break;
  3213. case 5:
  3214. Encoding = "AABBA";
  3215. break;
  3216. case 6:
  3217. Encoding = "AAABB";
  3218. break;
  3219. case 7:
  3220. Encoding = "ABABA";
  3221. break;
  3222. case 8:
  3223. Encoding = "ABAAB";
  3224. break;
  3225. case 9:
  3226. Encoding = "AABAB";
  3227. break;
  3228. }
  3229. //Now that we have the total number including the check digit, determine character to print for proper barcoding:
  3230. bufferCounter = 0;
  3231. for(I = 1;I <= (int)strlen(EAN5AddOn);I++)
  3232. {
  3233. //Get the value of each number. It is encoded with variable parity
  3234. CurrentNumber = atoi(mid(EAN5AddOn, I, 1));
  3235. //Print different barcodes according to the location of the CurrentChar and CurrentEncoding
  3236. midEncoding = Encoding[I - 1];
  3237. switch(midEncoding)
  3238. {
  3239. case 'A':
  3240. if(CurrentNumber == 0)
  3241. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)34);
  3242. if(CurrentNumber == 1)
  3243. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)35);
  3244. if(CurrentNumber == 2)
  3245. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)36);
  3246. if(CurrentNumber == 3)
  3247. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)37);
  3248. if(CurrentNumber == 4)
  3249. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)38);
  3250. if(CurrentNumber == 5)
  3251. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)44);
  3252. if(CurrentNumber == 6)
  3253. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)46);
  3254. if(CurrentNumber == 7)
  3255. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)47);
  3256. if(CurrentNumber == 8)
  3257. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)58);
  3258. if(CurrentNumber == 9)
  3259. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)59);
  3260. break;
  3261. case 'B':
  3262. if(CurrentNumber == 0)
  3263. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)122);
  3264. if(CurrentNumber == 1)
  3265. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)61);
  3266. if(CurrentNumber == 2)
  3267. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)63);
  3268. if(CurrentNumber == 3)
  3269. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)64);
  3270. if(CurrentNumber == 4)
  3271. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)91);
  3272. if(CurrentNumber == 5)
  3273. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)92);
  3274. if(CurrentNumber == 6)
  3275. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)93);
  3276. if(CurrentNumber == 7)
  3277. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)95);
  3278. if(CurrentNumber == 8)
  3279. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)123);
  3280. if(CurrentNumber == 9)
  3281. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)125);
  3282. break;
  3283. }
  3284. //add in the space & add-on guard pattern
  3285. switch(I)
  3286. {
  3287. case 1:
  3288. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c%s%c", (char)43, EANAddOnToPrint, (char)33);
  3289. break;
  3290. //Now print add-on delineators between each add-on character
  3291. case 2:
  3292. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)33);
  3293. break;
  3294. case 3:
  3295. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)33);
  3296. break;
  3297. case 4:
  3298. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)33);
  3299. break;
  3300. case 5:
  3301. //EANAddOnToPrint = EANAddOnToPrint
  3302. break;
  3303. }
  3304. } //end for loop
  3305. } //end 5 digit supplement work
  3306. //Now for the 2 digit add on
  3307. if(strlen(EAN2AddOn) == 2)
  3308. {
  3309. //Get encoding for add on
  3310. for(I = 0;I <= 99;I++)
  3311. {
  3312. if(atoi(EAN2AddOn) == I)
  3313. Encoding = "AA";
  3314. if(atoi(EAN2AddOn) == I + 1)
  3315. Encoding = "AB";
  3316. if(atoi(EAN2AddOn) == I + 2)
  3317. Encoding = "BA";
  3318. if(atoi(EAN2AddOn) == I + 3)
  3319. Encoding = "BB";
  3320. }//end for loop
  3321. bufferCounter = 0;
  3322. //Now that we have the total number including the encoding determine what to print
  3323. for(I = 1;I <= (int)strlen(EAN2AddOn);I++)
  3324. {
  3325. CurrentNumber = atoi(mid(EAN2AddOn, I, 1));
  3326. midEncoding = Encoding[I - 1];
  3327. //Print different barcodes according to the location of the CurrentChar and CurrentEncoding
  3328. switch(midEncoding)
  3329. {
  3330. case 'A':
  3331. if(CurrentNumber == 0)
  3332. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)34);
  3333. if(CurrentNumber == 1)
  3334. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)35);
  3335. if(CurrentNumber == 2)
  3336. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)36);
  3337. if(CurrentNumber == 3)
  3338. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)37);
  3339. if(CurrentNumber == 4)
  3340. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)38);
  3341. if(CurrentNumber == 5)
  3342. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)44);
  3343. if(CurrentNumber == 6)
  3344. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)46);
  3345. if(CurrentNumber == 7)
  3346. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)47);
  3347. if(CurrentNumber == 8)
  3348. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)58);
  3349. if(CurrentNumber == 9)
  3350. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)59);
  3351. break;
  3352. case 'B':
  3353. if(CurrentNumber == 0)
  3354. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)122);
  3355. if(CurrentNumber == 1)
  3356. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)61);
  3357. if(CurrentNumber == 2)
  3358. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)63);
  3359. if(CurrentNumber == 3)
  3360. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)64);
  3361. if(CurrentNumber == 4)
  3362. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)91);
  3363. if(CurrentNumber == 5)
  3364. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)92);
  3365. if(CurrentNumber == 6)
  3366. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)93);
  3367. if(CurrentNumber == 7)
  3368. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)95);
  3369. if(CurrentNumber == 8)
  3370. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)123);
  3371. if(CurrentNumber == 9)
  3372. bufferCounter += sprintf(EANAddOnToPrint + bufferCounter, "%c", (char)125);
  3373. break;
  3374. } //end switch
  3375. //add in the space & add-on guard pattern
  3376. switch(I)
  3377. {
  3378. case 1:
  3379. bufferCounter += sprintf(EANAddOnToPrint, "%c%s%c", (char)43, EANAddOnToPrint, (char)33);
  3380. break;
  3381. case 2:
  3382. //EANAddOnToPrint = EANAddOnToPrint
  3383. break;
  3384. }
  3385. }//end loop thru characers
  3386. } //end ean 2 digit supp processing
  3387. //Now we have everything together
  3388. sprintf(LPrintableString, "%s%s", DataToPrint, EANAddOnToPrint);
  3389. // Allow the string to return to the proper size.
  3390. iSize = (long)strlen(LPrintableString);
  3391. strncpy(output, LPrintableString, strlen(LPrintableString));
  3392. return 0;
  3393. } //end upce
  3394. **********************
  3395. javaʵÏÖ
  3396. **********************
  3397. /********************************************************************
  3398. /* Java Source Code for Linear Barcode Fonts Version 2006
  3399. /* Copyright ?2000-2006 IDAutomation.com, Inc. All rights reserved.
  3400. /* US Registered Copyright #Txu983-177
  3401. /*
  3402. /* You may incorporate this Source Code in your application
  3403. /* only if you own a valid license from IDAutomation.com, Inc.
  3404. /* for the associated product, provided that this copyright
  3405. /* notice and text are not removed from the source code.
  3406. /*
  3407. /* Distributing this source code outside your
  3408. /* organization requires a Developer License.
  3409. /********************************************************************/
  3410. class FontIDAutomation
  3411. {
  3412. public static void main ( String [] args )
  3413. {
  3414. //This is an example of how to format the barcode font for output
  3415. System.out.println( "Output: " + Code128b("123456789") );
  3416. }
  3417. /** This is the complete method for Code128a
  3418. */
  3419. static String Code128a( String DataToEncode )
  3420. {
  3421. char C128_Start = (char)203;
  3422. char C128_Stop = (char)206;
  3423. String Printable_string = "";
  3424. char CurrentChar;
  3425. int CurrentValue=0;
  3426. int weightedTotal=0;
  3427. int CheckDigitValue=0;
  3428. char C128_CheckDigit='w';
  3429. DataToEncode = DataToEncode.trim();
  3430. weightedTotal = ((int)C128_Start) - 100;
  3431. for( int i = 1; i <= DataToEncode.length(); i++ )
  3432. {
  3433. //get the value of each character
  3434. CurrentChar = DataToEncode.charAt(i-1);
  3435. if( ((int)CurrentChar) < 135 )
  3436. CurrentValue = ((int)CurrentChar) - 32;
  3437. if( ((int)CurrentChar) > 134 )
  3438. CurrentValue = ((int)CurrentChar) - 100;
  3439. CurrentValue = CurrentValue * i;
  3440. weightedTotal = weightedTotal + CurrentValue;
  3441. }
  3442. //divide the WeightedTotal by 103 and get the remainder,
  3443. //this is the CheckDigitValue
  3444. CheckDigitValue = weightedTotal % 103;
  3445. if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )
  3446. C128_CheckDigit = (char)(CheckDigitValue + 32);
  3447. if( CheckDigitValue > 94 )
  3448. C128_CheckDigit = (char)(CheckDigitValue + 100);
  3449. if( CheckDigitValue == 0 ){
  3450. C128_CheckDigit = (char)194;
  3451. }
  3452. Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";
  3453. return Printable_string;
  3454. }
  3455. /** This is the complete method for Code128b
  3456. */
  3457. static String Code128b( String DataToEncode )
  3458. {
  3459. char C128_Start = (char)204;
  3460. char C128_Stop = (char)206;
  3461. String Printable_string = "";
  3462. String temp = "";
  3463. char CurrentChar;
  3464. int CurrentValue=0;
  3465. int weightedTotal=0;
  3466. int CheckDigitValue=0;
  3467. char C128_CheckDigit='w';
  3468. DataToEncode = DataToEncode.trim();
  3469. weightedTotal = ((int)C128_Start) - 100;
  3470. for( int i = 1; i <= DataToEncode.length(); i++ )
  3471. {
  3472. //get the value of each character
  3473. CurrentChar = DataToEncode.charAt(i-1);
  3474. if( ((int)CurrentChar) < 135 )
  3475. CurrentValue = ((int)CurrentChar) - 32;
  3476. if( ((int)CurrentChar) > 134 )
  3477. CurrentValue = ((int)CurrentChar) - 100;
  3478. CurrentValue = CurrentValue * i;
  3479. weightedTotal = weightedTotal + CurrentValue;
  3480. //added by tb, replaces the spaces with the 194 character
  3481. if (CurrentChar == ' ')
  3482. {
  3483. CurrentChar = (char) 194;
  3484. }
  3485. temp = temp + CurrentChar;
  3486. }
  3487. //divide the WeightedTotal by 103 and get the remainder,
  3488. //this is the CheckDigitValue
  3489. CheckDigitValue = weightedTotal % 103;
  3490. if( (CheckDigitValue < 95) && (CheckDigitValue > 0) )
  3491. C128_CheckDigit = (char)(CheckDigitValue + 32);
  3492. if( CheckDigitValue > 94 )
  3493. C128_CheckDigit = (char)(CheckDigitValue + 100);
  3494. if( CheckDigitValue == 0 ){
  3495. C128_CheckDigit = (char)194;
  3496. }
  3497. //Printable_string = C128_Start + DataToEncode + C128_CheckDigit + C128_Stop + " ";
  3498. Printable_string = C128_Start + temp + C128_CheckDigit + C128_Stop + " ";
  3499. return Printable_string;
  3500. }
  3501. /** This is the complete method for Code128c
  3502. */
  3503. static String Code128c( String DataToEncode )
  3504. {
  3505. char C128_Start = (char)205;
  3506. char C128_Stop = (char)206;
  3507. String Printable_string = "";
  3508. String DataToPrint = "";
  3509. String OnlyCorrectData = "";
  3510. int i=1;
  3511. int CurrentChar=0;
  3512. int CurrentValue=0;
  3513. int weightedTotal=0;
  3514. int CheckDigitValue=0;
  3515. char C128_CheckDigit='w';
  3516. DataToPrint = "";
  3517. DataToEncode = DataToEncode.trim();
  3518. for(i = 1; i <= DataToEncode.length(); i++ )
  3519. {
  3520. //Add only numbers to OnlyCorrectData string
  3521. CurrentChar = (int)DataToEncode.charAt(i-1);
  3522. if((CurrentChar < 58) && (CurrentChar > 47))
  3523. {
  3524. OnlyCorrectData = OnlyCorrectData + (char)DataToEncode.charAt(i-1);
  3525. }
  3526. }
  3527. DataToEncode = OnlyCorrectData;
  3528. //Check for an even number of digits, add 0 if not even
  3529. if( (DataToEncode.length() % 2) == 1 )
  3530. {
  3531. DataToEncode = "0" + DataToEncode;
  3532. }
  3533. //<<<< Calculate Modulo 103 Check Digit and generate DataToPrint >>>>
  3534. //Set WeightedTotal to the Code 128 value of the start character
  3535. weightedTotal = ((int)C128_Start) - 100;
  3536. int WeightValue = 1;
  3537. for( i = 1; i <= DataToEncode.length(); i += 2 )
  3538. {
  3539. //Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)
  3540. //And assign the ASCII values to DataToPrint
  3541. CurrentChar = ((((int)DataToEncode.charAt(i-1))-48)*10) + (((int)DataToEncode.charAt(i))-48);
  3542. if((CurrentChar < 95) && (CurrentChar > 0))
  3543. DataToPrint = DataToPrint + (char)(CurrentChar + 32);
  3544. if( CurrentChar > 94 )
  3545. DataToPrint = DataToPrint + (char)(CurrentChar + 100);
  3546. if( CurrentChar == 0)
  3547. DataToPrint = DataToPrint + (char)194;
  3548. //multiply by the weighting character
  3549. //add the values together to get the weighted total
  3550. weightedTotal = weightedTotal + (CurrentChar * WeightValue);
  3551. WeightValue = WeightValue + 1;
  3552. }
  3553. //divide the WeightedTotal by 103 and get the remainder,
  3554. //this is the CheckDigitValue
  3555. CheckDigitValue = weightedTotal % 103;
  3556. if((CheckDigitValue < 95) && (CheckDigitValue > 0))
  3557. C128_CheckDigit = (char)(CheckDigitValue + 32);
  3558. if( CheckDigitValue > 94 )
  3559. C128_CheckDigit = (char)(CheckDigitValue + 100);
  3560. if( CheckDigitValue == 0 ){
  3561. C128_CheckDigit = (char)194;
  3562. }
  3563. Printable_string = C128_Start + DataToPrint + C128_CheckDigit + C128_Stop + " ";
  3564. return Printable_string;
  3565. }
  3566. /** This is the complete method for Code39
  3567. */
  3568. static String Code39( String DataToEncode )
  3569. {
  3570. String DataToPrint = "";
  3571. String OnlyCorrectData = "";
  3572. String Printable_string = "";
  3573. int CurrentChar=0;
  3574. int CurrentValue=0;
  3575. DataToEncode = DataToEncode.trim();
  3576. //only pass correct data
  3577. for( int i = 1; i <= DataToEncode.length(); i++ )
  3578. {
  3579. //Get each character value one at a time
  3580. CurrentChar = (int)(DataToEncode.charAt(i-1));
  3581. //Get the value of CurrentChar according to MOD43
  3582. //0-9
  3583. if( (CurrentChar < 58) && (CurrentChar > 47) )
  3584. {
  3585. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3586. }
  3587. //A-Z
  3588. if( (CurrentChar < 91) && (CurrentChar > 64) )
  3589. {
  3590. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3591. }
  3592. //Space
  3593. if( CurrentChar == ( 32 ) )
  3594. {
  3595. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3596. }
  3597. //-
  3598. if( CurrentChar == ( 45 ) )
  3599. {
  3600. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3601. }
  3602. //.
  3603. if( CurrentChar == ( 46 ) )
  3604. {
  3605. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3606. }
  3607. //$
  3608. if( CurrentChar == ( 36 ) )
  3609. {
  3610. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3611. }
  3612. ///
  3613. if( CurrentChar == ( 47 ) )
  3614. {
  3615. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3616. }
  3617. //+
  3618. if( CurrentChar == ( 43 ) )
  3619. {
  3620. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3621. }
  3622. //%
  3623. if( CurrentChar == ( 37 ) )
  3624. {
  3625. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3626. }
  3627. }
  3628. DataToEncode = OnlyCorrectData;
  3629. //Get Printable String
  3630. Printable_string = "!" + DataToPrint + "!" + " ";
  3631. //Return PrintableString
  3632. return Printable_string;
  3633. }
  3634. /** This is the complete method for Code39Mod43
  3635. */
  3636. static String Code39Mod43( String DataToEncode )
  3637. {
  3638. String DataToPrint = "";
  3639. int CheckDigit='0';
  3640. String OnlyCorrectData = "";
  3641. String Printable_string = "";
  3642. int CurrentChar=0;
  3643. int CurrentValue=0;
  3644. int weightedTotal=0;
  3645. int CheckDigitValue=0;
  3646. DataToEncode = DataToEncode.trim();
  3647. //only pass correct data
  3648. for( int i = 1; i <= DataToEncode.length(); i++ )
  3649. {
  3650. //Get each character value one at a time
  3651. CurrentChar = (int)(DataToEncode.charAt(i-1));
  3652. //Get the value of CurrentChar according to MOD43
  3653. //0-9
  3654. if( (CurrentChar < 58) && (CurrentChar > 47) )
  3655. {
  3656. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3657. }
  3658. //A-Z
  3659. if( (CurrentChar < 91) && (CurrentChar > 64) )
  3660. {
  3661. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3662. }
  3663. //Space
  3664. if( CurrentChar == ( 32 ) )
  3665. {
  3666. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3667. }
  3668. //-
  3669. if( CurrentChar == ( 45 ) )
  3670. {
  3671. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3672. }
  3673. //.
  3674. if( CurrentChar == ( 46 ) )
  3675. {
  3676. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3677. }
  3678. //$
  3679. if( CurrentChar == ( 36 ) )
  3680. {
  3681. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3682. }
  3683. ///
  3684. if( CurrentChar == ( 47 ) )
  3685. {
  3686. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3687. }
  3688. //+
  3689. if( CurrentChar == ( 43 ) )
  3690. {
  3691. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3692. }
  3693. //%
  3694. if( CurrentChar == ( 37 ) )
  3695. {
  3696. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3697. }
  3698. }
  3699. DataToEncode = OnlyCorrectData;
  3700. weightedTotal = 0;
  3701. for( int i = 1; i <= DataToEncode.length(); i++ )
  3702. {
  3703. //Get each character value one at a time
  3704. CurrentChar = (int)(DataToEncode.charAt(i-1));
  3705. //Get the value of CurrentChar according to MOD43
  3706. //0-9
  3707. if( (CurrentChar < 58) && (CurrentChar > 47) )
  3708. {
  3709. CurrentValue = (int)CurrentChar - 48;
  3710. }
  3711. //A-Z
  3712. if( ((int)CurrentChar < 91) && ((int)CurrentChar > 64) )
  3713. {
  3714. CurrentValue = (int)CurrentChar - 55;
  3715. }
  3716. //Space
  3717. if( CurrentChar == ( 32 ) )
  3718. {
  3719. CurrentValue = 38;
  3720. }
  3721. //-
  3722. if( CurrentChar == ( 45 ) )
  3723. {
  3724. CurrentValue = 36;
  3725. }
  3726. //.
  3727. if( CurrentChar == ( 46 ) )
  3728. {
  3729. CurrentValue = 37;
  3730. }
  3731. //$
  3732. if( CurrentChar == ( 36 ) )
  3733. {
  3734. CurrentValue = 39;
  3735. }
  3736. ///
  3737. if( CurrentChar == ( 47 ) )
  3738. {
  3739. CurrentValue = 40;
  3740. }
  3741. //+
  3742. if( CurrentChar == ( 43 ) )
  3743. {
  3744. CurrentValue = 41;
  3745. }
  3746. //%
  3747. if( CurrentChar == ( 37 ) )
  3748. {
  3749. CurrentValue = 42;
  3750. }
  3751. //To print the barcode symbol representing a space you will
  3752. //to type or print "=" (the equal character) instead of a space character.
  3753. if( CurrentChar == ( 32 ) )
  3754. {
  3755. CurrentChar = ( 61 );
  3756. }
  3757. //gather data to print
  3758. DataToPrint = DataToPrint + (char)CurrentChar;
  3759. //add the values together
  3760. weightedTotal = weightedTotal + CurrentValue;
  3761. }
  3762. //divide the WeightedTotal by 43 and get the remainder, this is the CheckDigit
  3763. CheckDigitValue = weightedTotal % 43;
  3764. //Assign values to characters
  3765. //0-9
  3766. if( CheckDigitValue < 10 )
  3767. {
  3768. CheckDigit = CheckDigitValue + 48;
  3769. }
  3770. //A-Z
  3771. if( (CheckDigitValue < 36) && (CheckDigitValue > 9) )
  3772. {
  3773. CheckDigit = CheckDigitValue + 55;
  3774. }
  3775. //Space
  3776. if( CheckDigitValue == 38 )
  3777. {
  3778. CheckDigit = 61;
  3779. }
  3780. //-
  3781. if( CheckDigitValue == 36 )
  3782. {
  3783. CheckDigit = 45;
  3784. }
  3785. //.
  3786. if( CheckDigitValue == 37 )
  3787. {
  3788. CheckDigit = 46;
  3789. }
  3790. //$
  3791. if( CheckDigitValue == 39 )
  3792. {
  3793. CheckDigit = 36;
  3794. }
  3795. ///
  3796. if( CheckDigitValue == 40 )
  3797. {
  3798. CheckDigit = 47;
  3799. }
  3800. //+
  3801. if( CheckDigitValue == 41 )
  3802. {
  3803. CheckDigit = 43;
  3804. }
  3805. //%
  3806. if( CheckDigitValue == 42 )
  3807. {
  3808. CheckDigit = 37;
  3809. }
  3810. //Get Printable String
  3811. Printable_string = "!" + DataToPrint + (char)CheckDigit + "!" + " ";
  3812. //Return PrintableString
  3813. return Printable_string;
  3814. }
  3815. /** This is the complete method for Postnet
  3816. */
  3817. static String Postnet( String DataToEncode )
  3818. {
  3819. int CheckDigit=0;
  3820. int i=1;
  3821. String OnlyCorrectData = "";
  3822. String Printable_string = "";
  3823. char CurrentChar;
  3824. int CurrentValue=0;
  3825. int weightedTotal=0;
  3826. String DataToPrint = "";
  3827. DataToEncode = DataToEncode.trim();
  3828. // Check to make sure data is numeric and remove dashes, etc.
  3829. for( i = 1; i <= DataToEncode.length(); i++ )
  3830. {
  3831. //Add all numbers to OnlyCorrectData string
  3832. CurrentValue = (int)(DataToEncode.charAt(i-1));
  3833. if( (CurrentValue < 58) && (CurrentValue > 47) )
  3834. {
  3835. OnlyCorrectData = OnlyCorrectData + DataToEncode.charAt(i-1);
  3836. }
  3837. }
  3838. DataToEncode = OnlyCorrectData;
  3839. //<<<< Calculate Check Digit >>>>
  3840. for( i = 1; i <= DataToEncode.length(); i++ )
  3841. {
  3842. //Get the value of each number
  3843. CurrentChar = DataToEncode.charAt(i-1);
  3844. //Convert CurrentChar to Integer and add the values together
  3845. weightedTotal = weightedTotal + (((int)CurrentChar)-48);
  3846. }
  3847. //Find the CheckDigit by finding the number + weightedTotal that = a multiple of 10
  3848. //divide by 10, get the remainder and subtract from 10
  3849. i = weightedTotal % 10;
  3850. if( i != 0 )
  3851. {
  3852. CheckDigit = 10 - i;
  3853. }
  3854. else
  3855. {
  3856. CheckDigit = 0;
  3857. }
  3858. //Get Printable String
  3859. DataToPrint = DataToEncode;
  3860. Printable_string = "(" + DataToPrint + CheckDigit + ")" + " ";
  3861. //Return PrintableString
  3862. return Printable_string;
  3863. }
  3864. /** This is the complete method for Interleaved2of5Mod10
  3865. */
  3866. static String Interleaved2of5Mod10( String DataToEncode )
  3867. {
  3868. String Printable_string = "";
  3869. String OnlyCorrectData = "";
  3870. String DataToPrint = "";
  3871. int CurrentChar;
  3872. int i=1;
  3873. int CurrentValue=0;
  3874. int weightedTotal=0;
  3875. int CheckDigitValue=0;
  3876. int CheckDigit=0;
  3877. DataToEncode = DataToEncode.trim();
  3878. for(i = 1; i <= DataToEncode.length(); i++ )
  3879. {
  3880. //Add only numbers to OnlyCorrectData string
  3881. CurrentChar = (int)DataToEncode.charAt(i-1);
  3882. if((CurrentChar < 58) && (CurrentChar > 47))
  3883. {
  3884. OnlyCorrectData = OnlyCorrectData + (char)DataToEncode.charAt(i-1);
  3885. }
  3886. }
  3887. DataToEncode = OnlyCorrectData;
  3888. //<<<< Calculate Check Digit >>>>
  3889. int Factor = 3;
  3890. for( i = DataToEncode.length(); i >= 1; i-- )
  3891. {
  3892. //Get the value of each number starting at the end
  3893. CurrentChar = (((int)DataToEncode.charAt(i-1))-48);
  3894. //multiply by the weighting factor which is 3,1,3,1...
  3895. //and add the sum together
  3896. weightedTotal = weightedTotal + (CurrentChar * Factor);
  3897. //change factor for next calculation
  3898. Factor = 4 - Factor;
  3899. }
  3900. //Find the CheckDigit by finding the smallest number that = a multiple of 10
  3901. i = weightedTotal % 10;
  3902. if( i != 0 )
  3903. {
  3904. CheckDigit = 10 - i;
  3905. }
  3906. else
  3907. {
  3908. CheckDigit = 0;
  3909. }
  3910. //Add check digit number to DataToEncode
  3911. DataToEncode = DataToEncode + CheckDigit;
  3912. //Check for an even number of digits, add 0 if not even
  3913. if( (DataToEncode.length() % 2) == 1 )
  3914. {
  3915. DataToEncode = "0" + DataToEncode;
  3916. }
  3917. for( i = 1; i <= DataToEncode.length(); i += 2 )
  3918. {
  3919. //Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)
  3920. CurrentChar = ((((int)DataToEncode.charAt(i-1))-48)*10) + (((int)DataToEncode.charAt(i))-48);
  3921. //Get the ASCII value of CurrentChar according to chart by adding to the value
  3922. // (old process) DataToPrint = DataToPrint + (char)(CurrentChar + 130);
  3923. if( CurrentChar < 94 )
  3924. DataToPrint = DataToPrint + (char)(CurrentChar + 33);
  3925. if( CurrentChar > 93 )
  3926. DataToPrint = DataToPrint + (char)(CurrentChar + 103);
  3927. }
  3928. //Get PrintableString
  3929. Printable_string = (char)(203) + DataToPrint + (char)(204) + " ";
  3930. //Return PrintableString
  3931. return Printable_string;
  3932. }
  3933. /** This is the complete method for Interleaved2of5
  3934. */
  3935. static String Interleaved2of5( String DataToEncode )
  3936. {
  3937. String Printable_string = "";
  3938. String OnlyCorrectData = "";
  3939. String DataToPrint = "";
  3940. int CurrentChar;
  3941. int i=1;
  3942. int CurrentValue=0;
  3943. int weightedTotal=0;
  3944. DataToEncode = DataToEncode.trim();
  3945. for(i = 1; i <= DataToEncode.length(); i++ )
  3946. {
  3947. //Add only numbers to OnlyCorrectData string
  3948. CurrentChar = (int)DataToEncode.charAt(i-1);
  3949. if((CurrentChar < 58) && (CurrentChar > 47))
  3950. {
  3951. OnlyCorrectData = OnlyCorrectData + (char)DataToEncode.charAt(i-1);
  3952. }
  3953. }
  3954. DataToEncode = OnlyCorrectData;
  3955. //Check for an even number of digits, add 0 if not even
  3956. if( (DataToEncode.length() % 2) == 1 )
  3957. {
  3958. DataToEncode = "0" + DataToEncode;
  3959. }
  3960. for( i = 1; i <= DataToEncode.length(); i += 2 )
  3961. {
  3962. //Get the value of each number pair (ex: 5 and 6 = 5*10+6 =56)
  3963. CurrentChar = ((((int)DataToEncode.charAt(i-1))-48)*10) + (((int)DataToEncode.charAt(i))-48);
  3964. //Get the ASCII value of CurrentChar according to chart by adding to the value
  3965. // (old process) DataToPrint = DataToPrint + (char)(CurrentChar + 130);
  3966. if( CurrentChar < 94 )
  3967. DataToPrint = DataToPrint + (char)(CurrentChar + 33);
  3968. if( CurrentChar > 93 )
  3969. DataToPrint = DataToPrint + (char)(CurrentChar + 103);
  3970. }
  3971. //Get PrintableString
  3972. Printable_string = (char)(203) + DataToPrint + (char)(204) + " ";
  3973. //Return PrintableString
  3974. return Printable_string;
  3975. }
  3976. }
  3977. ******************************************************************
  3978. Barcode Fonts http://www.idautomation.com/fonts/tools/sourcecode/
  3979. ******************************************************************