angular.module('wtmaker', ['colorpicker.module']).controller('WTDemoController', [ function() { // qr code object this.qr = new QRCode(); this.error = ""; // defaults this.version = 0; this.ecmode = QR__EC.M; this.maskMethod = QR__MaskMethod.Random; this.scale = 10; this.newSegType = QR__Mode.smart; this.fgColor = 'rgb(0,0,0)'; this.bgColor = 'rgb(255,255,255)'; this.renderer = 'Fast'; // fancy renderer options this.roundModules = false; this.squareCardinalConnections = false; this.squareDiagonalConnections = false; this.roundInsideCorners = false; this.roundDiagonalCorners = false; this.blankDots = false; this.blankDotsScale = 0.05; this.blankDotsColor = '#888888'; // generation and render timers this.genTime = 0; this.renderTime = 0; // autogen on change this.autogen = true; // value tables this.versions = [{v:0,d:'Auto'},{v:1,d:1},{v:2,d:2},{v:3,d:3},{v:4,d:4},{v:5,d:5},{v:6,d:6},{v:7,d:7},{v:8,d:8},{v:9,d:9},{v:10,d:10},{v:11,d:11},{v:12,d:12},{v:13,d:13},{v:14,d:14},{v:15,d:15},{v:16,d:16},{v:17,d:17},{v:18,d:18},{v:19,d:19},{v:20,d:20},{v:21,d:21},{v:22,d:22},{v:23,d:23},{v:24,d:24},{v:25,d:25},{v:26,d:26},{v:27,d:27},{v:28,d:28},{v:29,d:29},{v:30,d:30},{v:31,d:31},{v:32,d:32},{v:33,d:33},{v:34,d:34},{v:35,d:35},{v:36,d:36},{v:37,d:37},{v:38,d:38},{v:39,d:39},{v:40,d:40}]; this.ecmodes = [{v:QR__EC.L,d:'L (7% correction)'},{v:QR__EC.M,d:'M (15% correction)'},{v:QR__EC.Q,d:'Q (25% correction)'},{v:QR__EC.H,d:'H (30% correction)'}]; this.segTypes = [{ v: QR__Mode.smart, d: 'Smart Encode' },{ v: QR__Mode.num, d: 'Numeric' },{ v: QR__Mode.alNum, d: 'Alphanumeric' },{ v: QR__Mode.eightBit, d: '8-bit' },{ v: QR__Mode.ECI, d: 'ECI' },{ v: QR__Mode.FNC11, d: 'FNC1 (First Position)' },{ v: QR__Mode.FNC12, d: 'FNC1 (Second Position)' }]; this.renderers = ['Fast','Fancy']; this.maskMethods = [{v:QR__MaskMethod.Random,d:'Random (fastest)'},{v:QR__MaskMethod.BWBalance,d:'Black/White Balance'},{v:QR__MaskMethod.Canonical,d:'Canonical (Safest)'}]; this.ECIEncodings = [{v:'0',d:'Default'},{v:'1',d:'???'},{v:'2',d:'???'},{v:'3',d:'ISO-8859-1 (Latin-1/Western European)'},{v:'4',d:'ISO-8859-2 (Latin-2/Central European)'},{v:'5',d:'ISO-8859-3 (Latin-3/Southern European)'},{v:'6',d:'ISO-8859-4 (Latin-4/Northern European)'},{v:'7',d:'ISO-8859-5 (Latin/Cyrillic)'},{v:'8',d:'ISO-8859-6 (Latin/Arabic)'},{v:'9',d:'ISO-8859-7 (Latin/Greek)'},{v:'10',d:'ISO-8859-8 (Latin/Hebrew)'},{v:'11',d:'ISO-8859-9 (Latin-5/Turkish)'},{v:'12',d:'ISO-8859-10 (Latin-6/Nordic)'},{v:'13',d:'ISO-8859-11 (Latin/Thai)'},{v:'14',d:'ISO-8859-12 (Latin/Devanagari)'},{v:'15',d:'ISO-8859-13 (Latin-7/Baltic Rim)'},{v:'16',d:'ISO-8859-14 (Latin-8/Celtic)'},{v:'17',d:'ISO-8859-15 (Latin-9)'},{v:'18',d:'ISO-8859-16 (Latin-10/South-Eastern European)'},{v:'19',d:'RESERVED'},{v:'20',d:'Shift JIS'},{v:'21',d:'Windows 1250 (Latin-2/Central European)'},{v:'22',d:'Windows 1251 (Cyrillic)'},{v:'23',d:'Windows 1252 (Latin-1/Western European)'},{v:'24',d:'Windows 1256 (Arabic)'},{v:'25',d:'ISO-10646 UCS-2'},{v:'26',d:'ISO-10646 UTF-8'},{v:'27',d:'ISO-646 (ASCII)'},{v:'28',d:'Big 5 (Taiwan/Chinese)'},{v:'29',d:'GB (China/Chinese)'},{v:'30',d:'EUC-KR (Korean)'}]; this.segModes = new Object(); // populate some of the value tables for (var mode in QR__Mode) this.segModes[mode] = QR__Mode[mode]; // segments this.segments = new Array( { mode: QR__Mode.ECI, data: '26' }, { mode: QR__Mode.smart, data: "Data goes here" } ); // adds a new data segment this.addSegment = function newSegment() { this.segments[this.segments.length] = { mode: parseInt(this.newSegType), data: "" }; this.change(); } // removes the last data segment this.removeSegment = function removeSegment(index) { this.segments.splice(index, 1); this.change(); } // generates the qr code this.generate = function generate() { // reset error message this.error = ""; // convert all ECI data to numeric values temporarily for (var i = 0; i < this.segments.length; i++) if (this.segments[i].mode == QR__Mode.ECI) this.segments[i].data = parseInt(this.segments[i].data); // set QR code options this.qr.setVersion(this.version, this.ecmode); this.qr.setData(this.segments); this.qr.maskMethod = this.maskMethod; // generate the code, and keep track of how long it takes var genStart = new Date().getTime(); try { this.qr.drawSymbol(); } catch (e) { this.error = e.message; } var genStop = new Date().getTime(); // and now convert them back, because otherwise the UI breaks for (var i = 0; i < this.segments.length; i++) if (this.segments[i].mode == QR__Mode.ECI) this.segments[i].data = this.segments[i].data.toString(); // now that we've put the data back the way we found it, check for // errors if (this.error != "") return; // now that we're sure the code was generated, calculate the time this.genTime = genStop - genStart; // now render the code var renderStart = new Date().getTime(); if (this.renderer == 'Fancy') { // since this has all the same variable names as the options // object used by the fancy renderer, we can just pass this in drawQRToCanvasFancy(this.qr, document.getElementById('qrcanvas'), this.scale, this); } else if (this.renderer == 'Fast') { drawQRToCanvas(this.qr, document.getElementById('qrcanvas'), this.scale, this.bgColor, this.fgColor); } this.renderTime = new Date().getTime() - renderStart; } // checks to see whether the code should be regenerated or not on change this.change = function change() { if (this.autogen) this.generate(); } // perform initial generation this.generate(); }]);