| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732 |
- <?php
-
- if (!defined('QRCODEDEFS')) {
- define('QRCODEDEFS', true);
- define('QR_MODE_NL', -1);
- define('QR_MODE_NM', 0);
- define('QR_MODE_AN', 1);
- define('QR_MODE_8B', 2);
- define('QR_MODE_KJ', 3);
- define('QR_MODE_ST', 4);
- define('QR_ECLEVEL_L', 0);
- define('QR_ECLEVEL_M', 1);
- define('QR_ECLEVEL_Q', 2);
- define('QR_ECLEVEL_H', 3);
- define('QRSPEC_VERSION_MAX', 40);
- define('QRSPEC_WIDTH_MAX', 177);
- define('QRCAP_WIDTH', 0);
- define('QRCAP_WORDS', 1);
- define('QRCAP_REMINDER', 2);
- define('QRCAP_EC', 3);
- define('STRUCTURE_HEADER_BITS', 20);
- define('MAX_STRUCTURED_SYMBOLS', 16);
- define('N1', 3);
- define('N2', 3);
- define('N3', 40);
- define('N4', 10);
- define('QR_FIND_BEST_MASK', true);
- define('QR_FIND_FROM_RANDOM', 2);
- define('QR_DEFAULT_MASK', 2);
- }
-
- if (!class_exists('QRcode', false)) {
- if (!function_exists('str_split')) {
- function str_split($string, $split_length = 1)
- {
- if ($split_length < strlen($string) || !$split_length) {
- do {
- $c = strlen($string);
- $parts[] = substr($string, 0, $split_length);
- $string = substr($string, $split_length);
- } while ($string !== false);
- }
- else {
- $parts = array($string);
- }
-
- return $parts;
- }
- }
-
- class QRcode
- {
- /**
- * @var barcode array to be returned which is readable by TCPDF
- * @access protected
- */
- protected $barcode_array = array();
- /**
- * @var QR code version. Size of QRcode is defined as version. Version is from 1 to 40. Version 1 is 21*21 matrix. And 4 modules increases whenever 1 version increases. So version 40 is 177*177 matrix.
- * @access protected
- */
- protected $version = 0;
- /**
- * @var Levels of error correction. See definitions for possible values.
- * @access protected
- */
- protected $level = QR_ECLEVEL_L;
- /**
- * @var Encoding mode
- * @access protected
- */
- protected $hint = QR_MODE_8B;
- /**
- * @var if true the input string will be converted to uppercase
- * @access protected
- */
- protected $casesensitive = true;
- /**
- * @var structured QR code (not supported yet)
- * @access protected
- */
- protected $structured = 0;
- /**
- * @var mask data
- * @access protected
- */
- protected $data;
- /**
- * @var width
- * @access protected
- */
- protected $width;
- /**
- * @var frame
- * @access protected
- */
- protected $frame;
- /**
- * @var X position of bit
- * @access protected
- */
- protected $x;
- /**
- * @var Y position of bit
- * @access protected
- */
- protected $y;
- /**
- * @var direction
- * @access protected
- */
- protected $dir;
- /**
- * @var single bit
- * @access protected
- */
- protected $bit;
- /**
- * @var data code
- * @access protected
- */
- protected $datacode = array();
- /**
- * @var error correction code
- * @access protected
- */
- protected $ecccode = array();
- /**
- * @var blocks
- * @access protected
- */
- protected $blocks;
- /**
- * @var Reed-Solomon blocks
- * @access protected
- */
- protected $rsblocks = array();
- /**
- * @var counter
- * @access protected
- */
- protected $count;
- /**
- * @var data length
- * @access protected
- */
- protected $dataLength;
- /**
- * @var error correction length
- * @access protected
- */
- protected $eccLength;
- /**
- * @var b1
- * @access protected
- */
- protected $b1;
- /**
- * @var run length
- * @access protected
- */
- protected $runLength = array();
- /**
- * @var input data string
- * @access protected
- */
- protected $dataStr = '';
- /**
- * @var input items
- * @access protected
- */
- protected $items;
- /**
- * @var Reed-Solomon items
- * @access protected
- */
- protected $rsitems = array();
- /**
- * @var array of frames
- * @access protected
- */
- protected $frames = array();
- /**
- * @var alphabet-numeric convesion table
- * @access protected
- */
- protected $anTable = array(-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
- /**
- * @var array Table of the capacity of symbols
- * See Table 1 (pp.13) and Table 12-16 (pp.30-36), JIS X0510:2004.
- * @access protected
- */
- protected $capacity = array(
- array(
- 0,
- 0,
- 0,
- array(0, 0, 0, 0)
- ),
- array(
- 21,
- 26,
- 0,
- array(7, 10, 13, 17)
- ),
- array(
- 25,
- 44,
- 7,
- array(10, 16, 22, 28)
- ),
- array(
- 29,
- 70,
- 7,
- array(15, 26, 36, 44)
- ),
- array(
- 33,
- 100,
- 7,
- array(20, 36, 52, 64)
- ),
- array(
- 37,
- 134,
- 7,
- array(26, 48, 72, 88)
- ),
- array(
- 41,
- 172,
- 7,
- array(36, 64, 96, 112)
- ),
- array(
- 45,
- 196,
- 0,
- array(40, 72, 108, 130)
- ),
- array(
- 49,
- 242,
- 0,
- array(48, 88, 132, 156)
- ),
- array(
- 53,
- 292,
- 0,
- array(60, 110, 160, 192)
- ),
- array(
- 57,
- 346,
- 0,
- array(72, 130, 192, 224)
- ),
- array(
- 61,
- 404,
- 0,
- array(80, 150, 224, 264)
- ),
- array(
- 65,
- 466,
- 0,
- array(96, 176, 260, 308)
- ),
- array(
- 69,
- 532,
- 0,
- array(104, 198, 288, 352)
- ),
- array(
- 73,
- 581,
- 3,
- array(120, 216, 320, 384)
- ),
- array(
- 77,
- 655,
- 3,
- array(132, 240, 360, 432)
- ),
- array(
- 81,
- 733,
- 3,
- array(144, 280, 408, 480)
- ),
- array(
- 85,
- 815,
- 3,
- array(168, 308, 448, 532)
- ),
- array(
- 89,
- 901,
- 3,
- array(180, 338, 504, 588)
- ),
- array(
- 93,
- 991,
- 3,
- array(196, 364, 546, 650)
- ),
- array(
- 97,
- 1085,
- 3,
- array(224, 416, 600, 700)
- ),
- array(
- 101,
- 1156,
- 4,
- array(224, 442, 644, 750)
- ),
- array(
- 105,
- 1258,
- 4,
- array(252, 476, 690, 816)
- ),
- array(
- 109,
- 1364,
- 4,
- array(270, 504, 750, 900)
- ),
- array(
- 113,
- 1474,
- 4,
- array(300, 560, 810, 960)
- ),
- array(
- 117,
- 1588,
- 4,
- array(312, 588, 870, 1050)
- ),
- array(
- 121,
- 1706,
- 4,
- array(336, 644, 952, 1110)
- ),
- array(
- 125,
- 1828,
- 4,
- array(360, 700, 1020, 1200)
- ),
- array(
- 129,
- 1921,
- 3,
- array(390, 728, 1050, 1260)
- ),
- array(
- 133,
- 2051,
- 3,
- array(420, 784, 1140, 1350)
- ),
- array(
- 137,
- 2185,
- 3,
- array(450, 812, 1200, 1440)
- ),
- array(
- 141,
- 2323,
- 3,
- array(480, 868, 1290, 1530)
- ),
- array(
- 145,
- 2465,
- 3,
- array(510, 924, 1350, 1620)
- ),
- array(
- 149,
- 2611,
- 3,
- array(540, 980, 1440, 1710)
- ),
- array(
- 153,
- 2761,
- 3,
- array(570, 1036, 1530, 1800)
- ),
- array(
- 157,
- 2876,
- 0,
- array(570, 1064, 1590, 1890)
- ),
- array(
- 161,
- 3034,
- 0,
- array(600, 1120, 1680, 1980)
- ),
- array(
- 165,
- 3196,
- 0,
- array(630, 1204, 1770, 2100)
- ),
- array(
- 169,
- 3362,
- 0,
- array(660, 1260, 1860, 2220)
- ),
- array(
- 173,
- 3532,
- 0,
- array(720, 1316, 1950, 2310)
- ),
- array(
- 177,
- 3706,
- 0,
- array(750, 1372, 2040, 2430)
- )
- );
- /**
- * @var array Length indicator
- * @access protected
- */
- protected $lengthTableBits = array(
- array(10, 12, 14),
- array(9, 11, 13),
- array(8, 16, 16),
- array(8, 10, 12)
- );
- /**
- * @var array Table of the error correction code (Reed-Solomon block)
- * See Table 12-16 (pp.30-36), JIS X0510:2004.
- * @access protected
- */
- protected $eccTable = array(
- array(
- array(0, 0),
- array(0, 0),
- array(0, 0),
- array(0, 0)
- ),
- array(
- array(1, 0),
- array(1, 0),
- array(1, 0),
- array(1, 0)
- ),
- array(
- array(1, 0),
- array(1, 0),
- array(1, 0),
- array(1, 0)
- ),
- array(
- array(1, 0),
- array(1, 0),
- array(2, 0),
- array(2, 0)
- ),
- array(
- array(1, 0),
- array(2, 0),
- array(2, 0),
- array(4, 0)
- ),
- array(
- array(1, 0),
- array(2, 0),
- array(2, 2),
- array(2, 2)
- ),
- array(
- array(2, 0),
- array(4, 0),
- array(4, 0),
- array(4, 0)
- ),
- array(
- array(2, 0),
- array(4, 0),
- array(2, 4),
- array(4, 1)
- ),
- array(
- array(2, 0),
- array(2, 2),
- array(4, 2),
- array(4, 2)
- ),
- array(
- array(2, 0),
- array(3, 2),
- array(4, 4),
- array(4, 4)
- ),
- array(
- array(2, 2),
- array(4, 1),
- array(6, 2),
- array(6, 2)
- ),
- array(
- array(4, 0),
- array(1, 4),
- array(4, 4),
- array(3, 8)
- ),
- array(
- array(2, 2),
- array(6, 2),
- array(4, 6),
- array(7, 4)
- ),
- array(
- array(4, 0),
- array(8, 1),
- array(8, 4),
- array(12, 4)
- ),
- array(
- array(3, 1),
- array(4, 5),
- array(11, 5),
- array(11, 5)
- ),
- array(
- array(5, 1),
- array(5, 5),
- array(5, 7),
- array(11, 7)
- ),
- array(
- array(5, 1),
- array(7, 3),
- array(15, 2),
- array(3, 13)
- ),
- array(
- array(1, 5),
- array(10, 1),
- array(1, 15),
- array(2, 17)
- ),
- array(
- array(5, 1),
- array(9, 4),
- array(17, 1),
- array(2, 19)
- ),
- array(
- array(3, 4),
- array(3, 11),
- array(17, 4),
- array(9, 16)
- ),
- array(
- array(3, 5),
- array(3, 13),
- array(15, 5),
- array(15, 10)
- ),
- array(
- array(4, 4),
- array(17, 0),
- array(17, 6),
- array(19, 6)
- ),
- array(
- array(2, 7),
- array(17, 0),
- array(7, 16),
- array(34, 0)
- ),
- array(
- array(4, 5),
- array(4, 14),
- array(11, 14),
- array(16, 14)
- ),
- array(
- array(6, 4),
- array(6, 14),
- array(11, 16),
- array(30, 2)
- ),
- array(
- array(8, 4),
- array(8, 13),
- array(7, 22),
- array(22, 13)
- ),
- array(
- array(10, 2),
- array(19, 4),
- array(28, 6),
- array(33, 4)
- ),
- array(
- array(8, 4),
- array(22, 3),
- array(8, 26),
- array(12, 28)
- ),
- array(
- array(3, 10),
- array(3, 23),
- array(4, 31),
- array(11, 31)
- ),
- array(
- array(7, 7),
- array(21, 7),
- array(1, 37),
- array(19, 26)
- ),
- array(
- array(5, 10),
- array(19, 10),
- array(15, 25),
- array(23, 25)
- ),
- array(
- array(13, 3),
- array(2, 29),
- array(42, 1),
- array(23, 28)
- ),
- array(
- array(17, 0),
- array(10, 23),
- array(10, 35),
- array(19, 35)
- ),
- array(
- array(17, 1),
- array(14, 21),
- array(29, 19),
- array(11, 46)
- ),
- array(
- array(13, 6),
- array(14, 23),
- array(44, 7),
- array(59, 1)
- ),
- array(
- array(12, 7),
- array(12, 26),
- array(39, 14),
- array(22, 41)
- ),
- array(
- array(6, 14),
- array(6, 34),
- array(46, 10),
- array(2, 64)
- ),
- array(
- array(17, 4),
- array(29, 14),
- array(49, 10),
- array(24, 46)
- ),
- array(
- array(4, 18),
- array(13, 32),
- array(48, 14),
- array(42, 32)
- ),
- array(
- array(20, 4),
- array(40, 7),
- array(43, 22),
- array(10, 67)
- ),
- array(
- array(19, 6),
- array(18, 31),
- array(34, 34),
- array(20, 61)
- )
- );
- /**
- * @var array Positions of alignment patterns.
- * This array includes only the second and the third position of the alignment patterns. Rest of them can be calculated from the distance between them.
- * See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
- * @access protected
- */
- protected $alignmentPattern = array(
- array(0, 0),
- array(0, 0),
- array(18, 0),
- array(22, 0),
- array(26, 0),
- array(30, 0),
- array(34, 0),
- array(22, 38),
- array(24, 42),
- array(26, 46),
- array(28, 50),
- array(30, 54),
- array(32, 58),
- array(34, 62),
- array(26, 46),
- array(26, 48),
- array(26, 50),
- array(30, 54),
- array(30, 56),
- array(30, 58),
- array(34, 62),
- array(28, 50),
- array(26, 50),
- array(30, 54),
- array(28, 54),
- array(32, 58),
- array(30, 58),
- array(34, 62),
- array(26, 50),
- array(30, 54),
- array(26, 52),
- array(30, 56),
- array(34, 60),
- array(30, 58),
- array(34, 62),
- array(30, 54),
- array(24, 50),
- array(28, 54),
- array(32, 58),
- array(26, 54),
- array(30, 58)
- );
- /**
- * @var array Version information pattern (BCH coded).
- * See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
- * size: [QRSPEC_VERSION_MAX - 6]
- * @access protected
- */
- protected $versionPattern = array(31892, 34236, 39577, 42195, 48118, 51042, 55367, 58893, 63784, 68472, 70749, 76311, 79154, 84390, 87683, 92361, 96236, 102084, 102881, 110507, 110734, 117786, 119615, 126325, 127568, 133589, 136944, 141498, 145311, 150283, 152622, 158308, 161089, 167017);
- /**
- * @var array Format information
- * @access protected
- */
- protected $formatInfo = array(
- array(30660, 29427, 32170, 30877, 26159, 25368, 27713, 26998),
- array(21522, 20773, 24188, 23371, 17913, 16590, 20375, 19104),
- array(13663, 12392, 16177, 14854, 9396, 8579, 11994, 11245),
- array(5769, 5054, 7399, 6608, 1890, 597, 3340, 2107)
- );
-
- public function __construct($code, $eclevel = 'L')
- {
- $barcode_array = array();
- if (is_null($code) || $code == '\\0' || $code == '') {
- return false;
- }
-
- $this->level = array_search($eclevel, array('L', 'M', 'Q', 'H'));
-
- if ($this->level === false) {
- $this->level = QR_ECLEVEL_L;
- }
-
- if ($this->hint != QR_MODE_8B && $this->hint != QR_MODE_KJ) {
- return false;
- }
-
- if ($this->version < 0 || QRSPEC_VERSION_MAX < $this->version) {
- return false;
- }
-
- $this->items = array();
- $this->encodeString($code);
- $qrTab = $this->binarize($this->data);
- $size = count($qrTab);
- $barcode_array['num_rows'] = $size;
- $barcode_array['num_cols'] = $size;
- $barcode_array['bcode'] = array();
-
- foreach ($qrTab as $line) {
- $arrAdd = array();
-
- foreach (str_split($line) as $char) {
- $arrAdd[] = $char == '1' ? 1 : 0;
- }
-
- $barcode_array['bcode'][] = $arrAdd;
- }
-
- $this->barcode_array = $barcode_array;
- }
-
- public function getBarcodeArray()
- {
- return $this->barcode_array;
- }
-
- protected function binarize($frame)
- {
- $len = count($frame);
-
- foreach ($frame as &$frameLine) {
- for ($i = 0; $i < $len; $i++) {
- $frameLine[$i] = ord($frameLine[$i]) & 1 ? '1' : '0';
- }
- }
-
- return $frame;
- }
-
- protected function encodeString($string)
- {
- $this->dataStr = $string;
-
- if (!$this->casesensitive) {
- $this->toUpper();
- }
-
- $ret = $this->splitString();
-
- if ($ret < 0) {
- return NULL;
- }
-
- $this->encodeMask(-1);
- }
-
- protected function encodeMask($mask)
- {
- $spec = array(0, 0, 0, 0, 0);
- $this->datacode = $this->getByteStream($this->items);
-
- if (is_null($this->datacode)) {
- return NULL;
- }
-
- $spec = $this->getEccSpec($this->version, $this->level, $spec);
- $this->b1 = $this->rsBlockNum1($spec);
- $this->dataLength = $this->rsDataLength($spec);
- $this->eccLength = $this->rsEccLength($spec);
- $this->ecccode = array_fill(0, $this->eccLength, 0);
- $this->blocks = $this->rsBlockNum($spec);
- $ret = $this->init($spec);
-
- if ($ret < 0) {
- return NULL;
- }
-
- $this->count = 0;
- $this->width = $this->getWidth($this->version);
- $this->frame = $this->newFrame($this->version);
- $this->x = $this->width - 1;
- $this->y = $this->width - 1;
- $this->dir = -1;
- $this->bit = -1;
-
- for ($i = 0; $i < $this->dataLength + $this->eccLength; $i++) {
- $code = $this->getCode();
- $bit = 128;
-
- for ($j = 0; $j < 8; $j++) {
- $addr = $this->getNextPosition();
- $this->setFrameAt($addr, 2 | ($bit & $code) != 0);
- $bit = $bit >> 1;
- }
- }
-
- $j = $this->getRemainder($this->version);
-
- for ($i = 0; $i < $j; $i++) {
- $addr = $this->getNextPosition();
- $this->setFrameAt($addr, 2);
- }
-
- $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0);
-
- if ($mask < 0) {
- if (QR_FIND_BEST_MASK) {
- $masked = $this->mask($this->width, $this->frame, $this->level);
- }
- else {
- $masked = $this->makeMask($this->width, $this->frame, intval(QR_DEFAULT_MASK) % 8, $this->level);
- }
- }
- else {
- $masked = $this->makeMask($this->width, $this->frame, $mask, $this->level);
- }
-
- if ($masked == NULL) {
- return NULL;
- }
-
- $this->data = $masked;
- }
-
- protected function setFrameAt($at, $val)
- {
- $this->frame[$at['y']][$at['x']] = chr($val);
- }
-
- protected function getFrameAt($at)
- {
- return ord($this->frame[$at['y']][$at['x']]);
- }
-
- protected function getNextPosition()
- {
- do {
- if ($this->bit == -1) {
- $this->bit = 0;
- return array('x' => $this->x, 'y' => $this->y);
- }
-
- $x = $this->x;
- $y = $this->y;
- $w = $this->width;
-
- if ($this->bit == 0) {
- $x--;
- $this->bit++;
- }
- else {
- $x++;
- $y += $this->dir;
- $this->bit--;
- }
-
- if ($this->dir < 0) {
- if ($y < 0) {
- $y = 0;
- $x -= 2;
- $this->dir = 1;
-
- if ($x == 6) {
- $x--;
- $y = 9;
- }
- }
- }
- else if ($y == $w) {
- $y = $w - 1;
- $x -= 2;
- $this->dir = -1;
-
- if ($x == 6) {
- $x--;
- $y -= 8;
- }
- }
-
- if ($x < 0 || $y < 0) {
- return NULL;
- }
-
- $this->x = $x;
- $this->y = $y;
- } while (ord($this->frame[$y][$x]) & 128);
-
- return array('x' => $x, 'y' => $y);
- }
-
- protected function init($spec)
- {
- $dl = $this->rsDataCodes1($spec);
- $el = $this->rsEccCodes1($spec);
- $rs = $this->init_rs(8, 285, 0, 1, $el, 255 - $dl - $el);
- $blockNo = 0;
- $dataPos = 0;
- $eccPos = 0;
- $endfor = $this->rsBlockNum1($spec);
-
- for ($i = 0; $i < $endfor; ++$i) {
- $ecc = array_slice($this->ecccode, $eccPos);
- $this->rsblocks[$blockNo] = array();
- $this->rsblocks[$blockNo]['dataLength'] = $dl;
- $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
- $this->rsblocks[$blockNo]['eccLength'] = $el;
- $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
- $this->rsblocks[$blockNo]['ecc'] = $ecc;
- $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
- $dataPos += $dl;
- $eccPos += $el;
- $blockNo++;
- }
-
- if ($this->rsBlockNum2($spec) == 0) {
- return 0;
- }
-
- $dl = $this->rsDataCodes2($spec);
- $el = $this->rsEccCodes2($spec);
- $rs = $this->init_rs(8, 285, 0, 1, $el, 255 - $dl - $el);
-
- if ($rs == NULL) {
- return -1;
- }
-
- $endfor = $this->rsBlockNum2($spec);
-
- for ($i = 0; $i < $endfor; ++$i) {
- $ecc = array_slice($this->ecccode, $eccPos);
- $this->rsblocks[$blockNo] = array();
- $this->rsblocks[$blockNo]['dataLength'] = $dl;
- $this->rsblocks[$blockNo]['data'] = array_slice($this->datacode, $dataPos);
- $this->rsblocks[$blockNo]['eccLength'] = $el;
- $ecc = $this->encode_rs_char($rs, $this->rsblocks[$blockNo]['data'], $ecc);
- $this->rsblocks[$blockNo]['ecc'] = $ecc;
- $this->ecccode = array_merge(array_slice($this->ecccode, 0, $eccPos), $ecc);
- $dataPos += $dl;
- $eccPos += $el;
- $blockNo++;
- }
-
- return 0;
- }
-
- protected function getCode()
- {
- if ($this->count < $this->dataLength) {
- $row = $this->count % $this->blocks;
- $col = $this->count / $this->blocks;
-
- if ($this->rsblocks[0]['dataLength'] <= $col) {
- $row += $this->b1;
- }
-
- $ret = $this->rsblocks[$row]['data'][$col];
- }
- else if ($this->count < $this->dataLength + $this->eccLength) {
- $row = ($this->count - $this->dataLength) % $this->blocks;
- $col = ($this->count - $this->dataLength) / $this->blocks;
- $ret = $this->rsblocks[$row]['ecc'][$col];
- }
- else {
- return 0;
- }
-
- $this->count++;
- return $ret;
- }
-
- protected function writeFormatInformation($width, &$frame, $mask, $level)
- {
- $blacks = 0;
- $format = $this->getFormatInfo($mask, $level);
-
- for ($i = 0; $i < 8; ++$i) {
- if ($format & 1) {
- $blacks += 2;
- $v = 133;
- }
- else {
- $v = 132;
- }
-
- $frame[8][$width - 1 - $i] = chr($v);
-
- if ($i < 6) {
- $frame[$i][8] = chr($v);
- }
- else {
- $frame[$i + 1][8] = chr($v);
- }
-
- $format = $format >> 1;
- }
-
- for ($i = 0; $i < 7; ++$i) {
- if ($format & 1) {
- $blacks += 2;
- $v = 133;
- }
- else {
- $v = 132;
- }
-
- $frame[$width - 7 + $i][8] = chr($v);
-
- if ($i == 0) {
- $frame[8][7] = chr($v);
- }
- else {
- $frame[8][6 - $i] = chr($v);
- }
-
- $format = $format >> 1;
- }
-
- return $blacks;
- }
-
- protected function mask0($x, $y)
- {
- return $x + $y & 1;
- }
-
- protected function mask1($x, $y)
- {
- return $y & 1;
- }
-
- protected function mask2($x, $y)
- {
- return $x % 3;
- }
-
- protected function mask3($x, $y)
- {
- return ($x + $y) % 3;
- }
-
- protected function mask4($x, $y)
- {
- return (int) ($y / 2) + (int) ($x / 3) & 1;
- }
-
- protected function mask5($x, $y)
- {
- return ($x * $y & 1) + $x * $y % 3;
- }
-
- protected function mask6($x, $y)
- {
- return ($x * $y & 1) + $x * $y % 3 & 1;
- }
-
- protected function mask7($x, $y)
- {
- return $x * $y % 3 + ($x + $y & 1) & 1;
- }
-
- protected function generateMaskNo($maskNo, $width, $frame)
- {
- $bitMask = array_fill(0, $width, array_fill(0, $width, 0));
-
- for ($y = 0; $y < $width; ++$y) {
- for ($x = 0; $x < $width; ++$x) {
- if (ord($frame[$y][$x]) & 128) {
- $bitMask[$y][$x] = 0;
- }
- else {
- $maskFunc = call_user_func(array($this, 'mask' . $maskNo), $x, $y);
- $bitMask[$y][$x] = $maskFunc == 0 ? 1 : 0;
- }
- }
- }
-
- return $bitMask;
- }
-
- protected function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false)
- {
- $b = 0;
- $bitMask = array();
- $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d);
-
- if ($maskGenOnly) {
- return NULL;
- }
-
- $d = $s;
-
- for ($y = 0; $y < $width; ++$y) {
- for ($x = 0; $x < $width; ++$x) {
- if ($bitMask[$y][$x] == 1) {
- $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int) $bitMask[$y][$x]);
- }
-
- $b += (int) (ord($d[$y][$x]) & 1);
- }
- }
-
- return $b;
- }
-
- protected function makeMask($width, $frame, $maskNo, $level)
- {
- $masked = array_fill(0, $width, str_repeat('
|