瀏覽代碼

Add CODE128 barcode support

Neal Wilson 7 年之前
父節點
當前提交
a51c1beb88
共有 4 個檔案被更改,包括 134 行新增0 行删除
  1. 3
    0
      README
  2. 29
    0
      config/Scripts/barcode.css
  3. 73
    0
      config/Scripts/barcode.js
  4. 29
    0
      config/Windows/batchdetailsnew.xml

+ 3
- 0
README 查看文件

77
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
77
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
78
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
79
 SOFTWARE.
79
 SOFTWARE.
80
+
81
+CODE128 support inn batch tags is based on code from:
82
+https://itlearnings.wordpress.com/2011/01/08/javascript-code128-barcode/

+ 29
- 0
config/Scripts/barcode.css 查看文件

1
+/*==============================================================
2
+                CODE 128 styles
3
+===============================================================*/
4
+
5
+.barcode128h  {
6
+    clear: both;
7
+    padding: 0 10px /*quiet zone*/;
8
+    overflow: auto;
9
+    height: 0.35in   /*size*/;
10
+    margin-top: 20px;
11
+    margin-bottom: 20px;
12
+}
13
+ 
14
+.barcode128h div {
15
+    /*float: left;*/
16
+    height: 0.2 in  /*size*/;
17
+    display: inline;
18
+}
19
+ 
20
+.barcode128h .bar1 { border-left: 2px solid black }
21
+.barcode128h .bar2 { border-left: 4px solid black }
22
+.barcode128h .bar3 { border-left: 6px solid black }
23
+.barcode128h .bar4 { border-left: 8px solid black }
24
+.barcode128h .space0 { margin-right: 0px }
25
+.barcode128h .space1 { margin-right: 2px }
26
+.barcode128h .space2 { margin-right: 4px }
27
+.barcode128h .space3 { margin-right: 6px }
28
+.barcode128h .space4 { margin-right: 8px }
29
+ 

+ 73
- 0
config/Scripts/barcode.js 查看文件

1
+BARS       = [212222,222122,222221,121223,121322,131222,122213,122312,132212,221213,221312,231212,112232,122132,122231,113222,123122,123221,223211,221132,221231,213212,223112,312131,311222,321122,321221,312212,322112,322211,212123,212321,232121,111323,131123,131321,112313,132113,132311,211313,231113,231311,112133,112331,132131,113123,113321,133121,313121,211331,231131,213113,213311,213131,311123,311321,331121,312113,312311,332111,314111,221411,431111,111224,111422,121124,121421,141122,141221,112214,112412,122114,122411,142112,142211,241211,221114,413111,241112,134111,111242,121142,121241,114212,124112,124211,411212,421112,421211,212141,214121,412121,111143,111341,131141,114113,114311,411113,411311,113141,114131,311141,411131,211412,211214,211232,23311120];
2
+START_BASE = 38
3
+STOP       = 106 //BARS[STOP]==23311120 (manually added a zero at the end)
4
+ 
5
+var fromType128 = {
6
+    A: function(charCode) {
7
+        if (charCode>=0 && charCode<32)
8
+            return charCode+64;
9
+        if (charCode>=32 && charCode<96)
10
+            return charCode-32;
11
+        return charCode;
12
+    },
13
+    B: function(charCode) {
14
+        if (charCode>=32 && charCode<128)
15
+            return charCode-32;
16
+        return charCode;
17
+    },
18
+    C: function(charCode) {
19
+        return charCode;
20
+    }
21
+};
22
+ 
23
+function code128(code, barcodeType) {
24
+    if (arguments.length<2)
25
+        barcodeType = code128Detect(code);
26
+    if (barcodeType=='C' && code.length%2==1)
27
+        code = '0'+code;
28
+    var a = parseBarcode128(code,  barcodeType);
29
+    return bar2html128(a.join('')) ;//+ '<label>' + code + '</label>';
30
+}
31
+ 
32
+ 
33
+function code128Detect(code) {
34
+    if (/^[0-9]+$/.test(code)) return 'C';
35
+    if (/[a-z]/.test(code)) return 'B';
36
+    return 'A';
37
+}
38
+ 
39
+function parseBarcode128(barcode, barcodeType) {
40
+    var bars = [];
41
+    bars.add = function(nr) {
42
+        var nrCode = BARS[nr];
43
+        this.check = this.length==0 ? nr : this.check + nr*this.length;
44
+        this.push( nrCode || format("UNDEFINED: %1->%2", nr, nrCode) );
45
+    };
46
+ 
47
+    bars.add(START_BASE + barcodeType.charCodeAt(0));
48
+    for(var i=0; i<barcode.length; i++)
49
+    {
50
+        var code = barcodeType=='C' ? +barcode.substr(i++, 2) : barcode.charCodeAt(i);
51
+        converted = fromType128[barcodeType](code);
52
+        if (isNaN(converted) || converted<0 || converted>106)
53
+            throw new Error(format("Unrecognized character (%1) at position %2 in code '%3'.", code, i, barcode));
54
+        bars.add( converted );
55
+    }
56
+    bars.push(BARS[bars.check % 103], BARS[STOP]);
57
+ 
58
+    return bars;
59
+}
60
+ 
61
+function format(c){
62
+    var d=arguments;
63
+    var e= new RegExp("%([1-"+(arguments.length-1)+"])","g");
64
+    return(c+"").replace(e,function(a,b){return d[b]})
65
+}
66
+ 
67
+function bar2html128(s) {
68
+    for(var pos=0, sb=[]; pos<s.length; pos+=2)
69
+    {
70
+        sb.push('<div class="bar' + s.charAt(pos) + ' space' + s.charAt(pos+1) + '"></div>');
71
+    }
72
+    return sb.join('');
73
+}

+ 29
- 0
config/Windows/batchdetailsnew.xml 查看文件

527
                 styleFile.open(1);
527
                 styleFile.open(1);
528
                 output.writeTextElement("style", styleFile.readToString());
528
                 output.writeTextElement("style", styleFile.readToString());
529
                 styleFile.close();
529
                 styleFile.close();
530
+                
531
+                styleFile = new QFile(QSettings.value("config") + "/Scripts/barcode.css");
532
+                styleFile.open(1);
533
+                output.writeTextElement("style", styleFile.readToString());
534
+                styleFile.close();
535
+                
530
                 output.writeStartElement("script");
536
                 output.writeStartElement("script");
531
                 scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
537
                 scriptFile = new QFile(QSettings.value("config") + "/Scripts/qrcode.js");
532
                 scriptFile.open(1);
538
                 scriptFile.open(1);
533
                 output.writeCDATA(scriptFile.readToString());
539
                 output.writeCDATA(scriptFile.readToString());
534
                 scriptFile.close();
540
                 scriptFile.close();
535
                 output.writeEndElement();
541
                 output.writeEndElement();
542
+                
543
+                output.writeStartElement("script");
544
+                scriptFile = new QFile(QSettings.value("config") + "/Scripts/barcode.js");
545
+                scriptFile.open(1);
546
+                output.writeCDATA(scriptFile.readToString());
547
+                scriptFile.close();
548
+                output.writeEndElement();
549
+                
536
                 output.writeEndElement();
550
                 output.writeEndElement();
537
                 output.writeStartElement("body");
551
                 output.writeStartElement("body");
538
                 output.writeStartElement("h1");
552
                 output.writeStartElement("h1");
541
                 output.writeTextElement("span", "Roasted at: " + batchTime);
555
                 output.writeTextElement("span", "Roasted at: " + batchTime);
542
                 output.writeTextElement("span", "On machine: " + machine);
556
                 output.writeTextElement("span", "On machine: " + machine);
543
                 output.writeTextElement("span", "Batch file: " + fileID);
557
                 output.writeTextElement("span", "Batch file: " + fileID);
558
+                
559
+                output.writeStartElement("div");
560
+                output.writeAttribute("id", "barcode");
561
+                output.writeAttribute("class", "barcode128h");
562
+                output.writeAttribute("align", "center");
563
+                output.writeEndElement();
564
+                
565
+                output.writeStartElement("script");
566
+                var c128data = 'var strBarcodeHTML = code128("';
567
+                c128data += fileID;
568
+                c128data += '", "C");'
569
+                c128data += 'document.getElementById("barcode").innerHTML = strBarcodeHTML;';
570
+                output.writeCDATA(c128data);
571
+                output.writeEndElement();
572
+                
544
                 output.writeStartElement("div");
573
                 output.writeStartElement("div");
545
                 output.writeAttribute("id", "container");
574
                 output.writeAttribute("id", "container");
546
                 output.writeEndElement();
575
                 output.writeEndElement();

Loading…
取消
儲存