├── Barcode Fx Library.xlsm
├── Images
└── Barcode Sample.PNG
├── VBComponents
├── modPdf417BackEnd.bas
├── modITF.bas
├── modPdf417.bas
├── ThisWorkbook.cls
├── modCode128.bas
├── modCode.bas
├── modMain.bas
├── modAddInMenu.bas
├── modUpcEan.bas
├── modDataMatrix.bas
├── modAztec.bas
└── modQRcode.bas
├── Barcode Fx Library Add-In 3.1.xlam
├── Previous Versions
├── Barcode Fx Library Add-In 1.0.xlam
├── Barcode Fx Library Add-In 2.0.xlam
└── Barcode Fx Library Add-In 3.0.xlam
├── References
└── pdf417 Font Codes.csv
├── BarcodeFxLibrary.xml
├── README.md
└── LICENSE
/Barcode Fx Library.xlsm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Barcode Fx Library.xlsm
--------------------------------------------------------------------------------
/Images/Barcode Sample.PNG:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Images/Barcode Sample.PNG
--------------------------------------------------------------------------------
/VBComponents/modPdf417BackEnd.bas:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/VBComponents/modPdf417BackEnd.bas
--------------------------------------------------------------------------------
/Barcode Fx Library Add-In 3.1.xlam:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Barcode Fx Library Add-In 3.1.xlam
--------------------------------------------------------------------------------
/Previous Versions/Barcode Fx Library Add-In 1.0.xlam:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Previous Versions/Barcode Fx Library Add-In 1.0.xlam
--------------------------------------------------------------------------------
/Previous Versions/Barcode Fx Library Add-In 2.0.xlam:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Previous Versions/Barcode Fx Library Add-In 2.0.xlam
--------------------------------------------------------------------------------
/Previous Versions/Barcode Fx Library Add-In 3.0.xlam:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EszopiCoder/excel-barcode-fx-library/HEAD/Previous Versions/Barcode Fx Library Add-In 3.0.xlam
--------------------------------------------------------------------------------
/References/pdf417 Font Codes.csv:
--------------------------------------------------------------------------------
1 | Symbol,Code
2 | a,00110
3 | b,00111
4 | c,01000
5 | d,01001
6 | e,01010
7 | f,01011
8 | g,01100
9 | h,01101
10 | i,01110
11 | j,01111
12 | k,10000
13 | l,10001
14 | m,10010
15 | n,10011
16 | o,10100
17 | p,10101
18 | q,10110
19 | r,10111
20 | s,11000
21 | t,11001
22 | u,11010
23 | v,11011
24 | w,11100
25 | x,11101
26 | y,11110
27 | z,11111
28 | A,00000
29 | B,00001
30 | C,00010
31 | D,00011
32 | E,00100
33 | F,00101
34 | +,1111111101010100
35 | *,01
36 | -,11111101000101001
37 |
--------------------------------------------------------------------------------
/BarcodeFxLibrary.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
16 |
22 |
23 |
30 |
37 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Barcode Function Library Excel Add-In
2 | ## Purpose and Features
3 | Custom function library to generate the following 1D and 2D barcodes using autoshapes:
4 | | Barcode Type | Barcodes |
5 | | --- | --- |
6 | | 1D Code | Code 11, Code 39, Code 93, Code 128 |
7 | | 1D UPC/EAN | EAN-2, EAN-5, EAN-8, EAN-13, UPC-A, UPC-E |
8 | | 1D ITF | ITF, ITF-14 |
9 | | 2D Barcodes | Aztec, Data Matrix, PDF417, QR Code |
10 | ## Compatibility
11 | Microsoft Excel 2013+
12 | ## Installation
13 | 1. Download 'Barcode Fx Library Add-In 3.0.xlam'
14 | 2. Follow these [instructions](https://support.office.com/en-us/article/add-or-remove-add-ins-in-excel-0af570c4-5cf3-4fa9-9b88-403625a0b460) from Microsoft
15 | ## Usage
16 | - The functions are located under the 'Formulas' tab under the 'Barcode Function Library' group (see images).
17 | - All check digits are auto-calculated.
18 |
19 | | Function Name | Data Types | Length | Author |
20 | | --- | --- | --- | --- |
21 | | `Aztec()` | ASCII | Unlimited | [Alois Zingl](http://members.chello.at/~easyfilter/barcode.html) |
22 | | `Code11()` | Numeric and dash | Unlimited | Eszopicoder |
23 | | `Code39()` | Alphanumeric and -$%./+ | Unlimited | Eszopicoder |
24 | | `Code93()` | Alphanumeric and -$%./+ | Unlimited + 2 check digits | Eszopicoder |
25 | | `Code128()` | ASCII | Unlimited | [Alois Zingl](http://members.chello.at/~easyfilter/barcode.html) |
26 | | `DataMatrix()` | ASCII | Unlimited | [Alois Zingl](http://members.chello.at/~easyfilter/barcode.html) |
27 | | `EAN_2()` | Numeric | 2 digits | Eszopicoder |
28 | | `EAN_5()` | Numeric | 5 digits | Eszopicoder |
29 | | `EAN_13()` | Numeric | 12 digits + check digit | Eszopicoder |
30 | | `ITF()` | Numeric | Unlimited | Eszopicoder |
31 | | `ITF_14()` | Numeric | 13 digits + check digit | Eszopicoder |
32 | | `PDF_417()` | ASCII | Unlimited | [Grandzebu](http://grandzebu.net/informatique/codbar-en/pdf417.htm) |
33 | | `QRCode()` | ASCII | Unlimited | [Alois Zingl](http://members.chello.at/~easyfilter/barcode.html) |
34 | | `UPCA()` | Numeric | 11 + check digit (UPC-A) or 8 digits (EAN-8) | Eszopicoder |
35 | | `UPCE()` | Numeric | ("0" or "1") + 6 digits | Eszopicoder |
36 | ## Sample Images
37 |
38 |
--------------------------------------------------------------------------------
/VBComponents/modITF.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modITF"
2 | Option Explicit
3 |
4 | 'GS1 ITF-14 barcodes: https://www.gs1standards.info/itf-14-barcodes/
5 |
6 | 'Wikipedia References
7 | 'Interleaved 2 of 5 (ITF): https://en.wikipedia.org/wiki/Interleaved_2_of_5
8 |
9 | Function ITF(source As String) As String
10 | Dim ITFTable
11 | Dim i As Integer
12 | Dim j As Integer
13 | Dim dest As String
14 |
15 | ITFTable = Array("11221", "21112", "12112", "22111", "11212", _
16 | "21211", "12211", "11122", "21121", "12121")
17 |
18 | 'ITF requires an even number of digits. If odd, add a zero to the beginning
19 | If Len(source) Mod 2 <> 0 Then
20 | source = "0" & source
21 | End If
22 |
23 | 'Start character
24 | dest = "1111"
25 | 'Middle characters
26 | For i = 1 To Len(source) Step 2
27 | 'Interleave 2 digits at a time (1st digit is bars, 2nd digit is spaces)
28 | For j = 1 To 5 Step 1
29 | dest = dest & Mid(ITFTable(Mid(source, i, 1)), j, 1) & Mid(ITFTable(Mid(source, i + 1, 1)), j, 1)
30 | Next j
31 | Next i
32 | 'End character
33 | dest = dest & "211"
34 |
35 | ITF = DRAWLINEAR(dest)
36 | End Function
37 |
38 | Function ITF_14(source As String) As String
39 | Dim ITFTable
40 | Dim i As Integer
41 | Dim j As Integer
42 | Dim dest As String
43 |
44 | ITFTable = Array("11221", "21112", "12112", "22111", "11212", _
45 | "21211", "12211", "11122", "21121", "12121")
46 |
47 | 'Validate source
48 | If Len(source) <> 14 And Len(source) <> 13 Then
49 | ITF_14 = "Improper ITF-14 barcode length (13-14 digits)"
50 | Exit Function
51 | ElseIf Len(source) = 14 And GS1_CHECK(Left(source, 13)) <> Right(source, 1) Then
52 | ITF_14 = "Invalid check digit (" & GS1_CHECK(Left(source, 13)) & ")"
53 | Exit Function
54 | End If
55 |
56 | 'Calculate check digit
57 | If Len(source) = 13 Then source = source & GS1_CHECK(Left(source, 13))
58 |
59 | 'Start character
60 | dest = "1111"
61 | 'Middle characters
62 | For i = 1 To Len(source) Step 2
63 | 'Interleave 2 digits at a time (1st digit is bars, 2nd digit is spaces)
64 | For j = 1 To 5 Step 1
65 | dest = dest & Mid(ITFTable(Mid(source, i, 1)), j, 1) & Mid(ITFTable(Mid(source, i + 1, 1)), j, 1)
66 | Next j
67 | Next i
68 | 'End character
69 | dest = dest & "211"
70 |
71 | ITF_14 = DRAWLINEAR(dest)
72 | End Function
73 |
--------------------------------------------------------------------------------
/VBComponents/modPdf417.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modPdf417"
2 | Option Explicit
3 | 'http://www.onbarcode.com/pdf417/pdf417_size_setting.html
4 |
5 | Private Sub TestPDF417()
6 | Dim strTest As String
7 | strTest = PDF417String("test", -1, 1)
8 | 'Debug.Print strTest
9 | Debug.Print PDF417ToBinary(strTest)(0)
10 | Call PDF_417("test")
11 | End Sub
12 |
13 | Public Function PDF_417(text As String, Optional security = -1, Optional nbcol = 1, Optional CodeErr) As String
14 | On Error GoTo failed
15 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "PDF417", "Call only from sheet"
16 | Dim h As Long, w As Long, x As Long, y As Long
17 | Dim K As Long, i As Long
18 | Dim shp As Shape
19 | Dim fColor As Long
20 | Dim BinPDF417
21 |
22 | fColor = vbBlack ' redraw graphic ?
23 | For Each shp In Application.Caller.Parent.Shapes
24 | If shp.Name = Application.Caller.Address Then
25 | If shp.Title = text Then Exit Function ' same as prev ?
26 | fColor = shp.Fill.ForeColor.RGB ' remember format
27 | shp.line.Visible = msoFalse
28 | shp.Delete
29 | End If
30 | Next shp
31 |
32 | ' Get binary of PDF417
33 | BinPDF417 = PDF417ToBinary(PDF417String(text, security, nbcol, CodeErr))
34 | h = UBound(BinPDF417)
35 | w = Len(BinPDF417(0))
36 |
37 | With Application.Caller.Parent.Shapes
38 | K = .count + 1 ' layout PDF417
39 | For y = 0 To h
40 | For x = 1 To w
41 | If Mid(BinPDF417(y), x, 1) = 1 Then ' apply mask
42 | .AddShape(msoShapeRectangle, x, 3 * y, 1, 3).Name = Application.Caller.Address
43 | End If
44 | Next x
45 | Next y
46 | K = .count - K
47 | ReDim shps(K) As Integer ' group all shapes
48 | For i = .count To 1 Step -1
49 | If .Range(i).Name = Application.Caller.Address Then
50 | shps(K) = i: K = K - 1
51 | If K < 0 Then Exit For
52 | End If
53 | Next i
54 |
55 | With .Range(shps).Group
56 | .Fill.ForeColor.RGB = fColor ' format barcode shape
57 | .line.Visible = msoFalse
58 | x = Application.Caller.MergeArea.Width
59 | y = Application.Caller.MergeArea.Height
60 | .Width = x * w / (w + 2) ' fit symbol in excel cell
61 | .Height = y * h / (h + 2) ' fit symbol in excel cell
62 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
63 | .Top = Application.Caller.Top + (Application.Caller.MergeArea.Height - .Height) / 2
64 | .Name = Application.Caller.Address ' link shape to data
65 | .Title = text
66 | .AlternativeText = "PDF417 barcode, security " & security & ", nbcol " & nbcol & ", " & h & "x" & w & " cells"
67 | .LockAspectRatio = True
68 | .Placement = xlMove
69 | End With
70 | End With
71 | failed:
72 | If Err.Number Then PDF_417 = "ERROR PDF417: " & Err.Description
73 | End Function
74 |
--------------------------------------------------------------------------------
/VBComponents/ThisWorkbook.cls:
--------------------------------------------------------------------------------
1 | VERSION 1.0 CLASS
2 | BEGIN
3 | MultiUse = -1 'True
4 | END
5 | Attribute VB_Name = "ThisWorkbook"
6 | Attribute VB_GlobalNameSpace = False
7 | Attribute VB_Creatable = False
8 | Attribute VB_PredeclaredId = True
9 | Attribute VB_Exposed = True
10 | Option Explicit
11 | Private WithEvents App As Application
12 | Attribute App.VB_VarHelpID = -1
13 |
14 | Private Sub App_WorkbookActivate(ByVal Wb As Workbook)
15 | ' Add macro descriptions
16 | Application.MacroOptions "Aztec", "Draw Aztec barcode.", , , , , "Barcode", , , , _
17 | Array("Text to be encoded.", _
18 | "OPTIONAL Percentage of checkwords used for security (1% to 90%) [Default=23%].", _
19 | "OPTIONAL Number of layers (0 to 32) [Default=1]")
20 |
21 | Application.MacroOptions "Code11", "Encode Code 11 barcode.", , , , , "Barcode", , , , _
22 | Array("Text to be encoded.")
23 |
24 | Application.MacroOptions "Code39", "Encode Code 39 barcode.", , , , , "Barcode", , , , _
25 | Array("Text to be encoded.", _
26 | "OPTIONAL Include check digit [Default=False]")
27 |
28 | Application.MacroOptions "Code93", "Encode Code 93 barcode.", , , , , "Barcode", , , , _
29 | Array("Text to be encoded.")
30 |
31 | Application.MacroOptions "Code128", "Draw Code 128 barcode.", , , , , "Barcode", , , , _
32 | Array("Text to be encoded.")
33 |
34 | Application.MacroOptions "EAN_2", "Encode EAN-2 barcode.", , , , , "Barcode", , , , _
35 | Array("Text to be encoded.")
36 |
37 | Application.MacroOptions "EAN_5", "Encode EAN-5 barcode.", , , , , "Barcode", , , , _
38 | Array("Text to be encoded.")
39 |
40 | Application.MacroOptions "EAN_13", "Encode EAN-13 barcode.", , , , , "Barcode", , , , _
41 | Array("Text to be encoded.")
42 |
43 | Application.MacroOptions "DataMatrix", "Draw DataMatrix barcode.", , , , , "Barcode", , , , _
44 | Array("Text to be encoded.")
45 |
46 | Application.MacroOptions "ITF", "Encode ITF barcode.", , , , , "Barcode", , , , _
47 | Array("Text to be encoded.")
48 |
49 | Application.MacroOptions "ITF_14", "Encode ITF-14 barcode.", , , , , "Barcode", , , , _
50 | Array("Text to be encoded.")
51 |
52 | Application.MacroOptions "PDF_417", "Draw PDF417 barcode.", , , , , "Barcode", , , , _
53 | Array("Text to be encoded.", _
54 | "OPTIONAL Security level [Default=-1]", _
55 | "OPTIONAL Number of columns [Default=1]", _
56 | "OPTIONAL Code Error")
57 |
58 | Application.MacroOptions "QRCode", "Draw QR code.", , , , , "Barcode", , , , _
59 | Array("Text to be encoded.", _
60 | "OPTIONAL Security level ""LMQH""" + vbCrLf + "low, medium, quartile, high" + vbCrLf + "[Default=L]", _
61 | "OPTIONAL Minimum version size(-3 to 40) [Default=1]" + vbCrLf + "MicroQR M1:-3, M2:-2, M3:-1, M4:0")
62 |
63 | Application.MacroOptions "UPCA", "Encode UPC-A or EAN-8 barcode.", , , , , "Barcode", , , , _
64 | Array("Text to be encoded.")
65 |
66 | Application.MacroOptions "UPCE", "Encode UPC-E barcode.", , , , , "Barcode", , , , _
67 | Array("Text to be encoded.")
68 |
69 | Application.MacroOptions "DRAWLINEAR", "Draw linear barcode.", , , , , "Barcode", , , , _
70 | Array("Barcode string to be drawn.")
71 | End Sub
72 |
73 | Private Sub Workbook_Open()
74 | Set App = Application
75 | End Sub
76 |
77 | Private Sub Workbook_AddinInstall()
78 | MsgBox "Thank you for installing the Barcode Fx Library." & vbNewLine & _
79 | "This is an open source project created by EszopiCoder." & vbNewLine & _
80 | "(https://github.com/EszopiCoder/excel-barcode-fx-library)", vbInformation
81 | End Sub
82 |
83 | Private Sub Workbook_AddinUninstall()
84 | MsgBox "Sorry to hear you will no longer be using the 'Barcode Fx Library'." & vbNewLine & _
85 | "Please send suggestions for improvement to pharm.coder@gmail.com", vbInformation
86 | End Sub
87 |
88 |
89 |
--------------------------------------------------------------------------------
/VBComponents/modCode128.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modCode128"
2 | Option Explicit
3 |
4 | ' Code 128 symbol creation according ISO/IEC 15417:2007
5 | Public Function Code128(text As String) As String
6 | Attribute Code128.VB_Description = "Draw Code 128 barcode"
7 | Attribute Code128.VB_ProcData.VB_Invoke_Func = " \n18"
8 | On Error GoTo failed
9 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "Code 128", "Call only from sheet"
10 | Dim m As Long, i As Long, j As Long, c As Long, l As Long, t As Long
11 | Dim shp As Shape, color As Long, txt As String ' redraw barcode ?
12 | color = vbBlack
13 | For Each shp In Application.Caller.Parent.Shapes
14 | If shp.Name = Application.Caller.Address Then
15 | If shp.Title = text Then Exit Function ' same as prev ?
16 | color = shp.Fill.ForeColor.RGB ' redraw with same color
17 | shp.Delete
18 | End If
19 | Next shp
20 | txt = utf16to8(text): m = 3: l = 0: t = Len(txt)
21 | ReDim enc(3 * t + 3) As Byte
22 | For i = 1 To t
23 | If m <> 2 Then ' alpha mode
24 | For j = 0 To t - i ' count digits
25 | If Not IsNumeric(Mid(txt, i + j, 1)) Then Exit For
26 | Next j
27 | If (j > 1 And i = 1) Or (j > 3 And (i + j < t Or (j And 1) = 0)) Then
28 | enc(l) = IIf(i = 1, 105, 99) ' start / code C
29 | l = l + 1: m = 2 ' to digit
30 | End If
31 | End If
32 | If m = 2 Then ' digit mode
33 | If IsNumeric(Mid(txt, i, 1)) And IsNumeric(Mid(txt, i + 1, 1)) Then
34 | enc(l) = val(Mid(txt, i, 2)) ' two digits
35 | l = l + 1: i = i + 1
36 | Else
37 | m = 3 ' exit digit
38 | End If
39 | End If
40 | If m <> 2 Then ' alpha mode
41 | c = Asc(Mid(txt, i, 1))
42 | If m > 2 Or ((c And 127) < 32 And m) Or ((c And 127) > 95 And m = 0) Then ' change ?
43 | For j = IIf(m > 2 Or i + 1 = t, i, i + 1) To t - 1 ' A or B needed?
44 | If Asc(Mid(txt, j, 1)) - 32 And 64 Then Exit For ' < 32 or > 95
45 | Next j
46 | j = IIf(Asc(Mid(txt, j, 1)) And 96, 1, 0) ' new set
47 | enc(l) = IIf(i = 1, 103 + j, IIf(j <> m, 101 - j, 98))
48 | l = l + 1: m = j ' change set: start,code,(shift)
49 | End If
50 | If c > 127 Then enc(l) = 101 - m: l = l + 1 ' FNC4: char > 127
51 | enc(l) = ((c And 127) + 64) Mod 96: l = l + 1
52 | End If
53 | Next i
54 | If i = 1 Then enc(0) = 103: l = 1 ' empty message
55 | j = enc(0) ' check sum
56 | For i = 1 To l
57 | j = j + i * enc(i)
58 | Next i
59 | enc(l) = j Mod 103: enc(l + 1) = 106 ' stop
60 |
61 | With Application.Caller.Parent.Shapes
62 | For i = 0 To l + 1 ' code to pattern
63 | c = Array(277, 337, 341, 69, 73, 133, 84, 88, 148, 324, 328, 388, 22, 82, 86, 37, 97, _
64 | 101, 356, 322, 326, 292, 352, 530, 517, 577, 581, 532, 592, 596, 273, 281, 401, 9, _
65 | 129, 137, 24, 144, 152, 264, 384, 392, 18, 26, 146, 33, 41, 161, 545, 266, 386, 288, _
66 | 296, 290, 513, 521, 641, 528, 536, 656, 560, 332, 896, 5, 13, 65, 77, 193, 197, 20, 28, _
67 | 80, 92, 208, 212, 452, 320, 800, 448, 176, 7, 67, 71, 52, 112, 116, 772, 832, 836, 275, _
68 | 305, 785, 3, 11, 131, 48, 56, 768, 776, 35, 50, 515, 770, 268, 260, 262, 416)(enc(i))
69 | m = c \ 256 + 1
70 | .AddShape(msoShapeRectangle, 11 * i, 0, m, 1).Name = Application.Caller.Address ' 1st bar
71 | j = 11 * i + m + ((c \ 64) And 3) + 1
72 | m = ((c \ 16) And 3) + 1
73 | .AddShape(msoShapeRectangle, j, 0, m, 1).Name = Application.Caller.Address ' 2nd bar
74 | j = j + m + ((c \ 4) And 3) + 1
75 | .AddShape(msoShapeRectangle, j, 0, (c And 3) + 1, 1).Name = Application.Caller.Address ' 3rd bar
76 | Next i
77 | .AddShape(msoShapeRectangle, 11 * i, 0, 2, 1).Name = Application.Caller.Address ' stop bar
78 | j = 3 * l + 6: m = j
79 |
80 | ReDim shps(j) As Integer ' group all shapes
81 | For i = .Count To 1 Step -1
82 | If .Range(i).Name = Application.Caller.Address Then
83 | shps(j) = i: j = j - 1
84 | If j < 0 Then Exit For
85 | End If
86 | Next i
87 | With .Range(shps).Group
88 | .Fill.ForeColor.RGB = color ' format barcode shape
89 | .line.Visible = False
90 | .Width = Application.Caller.MergeArea.Width * 2 * m / (2 * m + 1) ' fit symbol in excel cell
91 | .Height = Application.Caller.MergeArea.Height - .Width / (2 * m)
92 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
93 | .Top = Application.Caller.Top + (Application.Caller.MergeArea.Height - .Height) / 2
94 | .Name = Application.Caller.Address ' link shape to data
95 | .Title = text
96 | .AlternativeText = "Code128 barcode, " & (l + 2) & " characters"
97 | End With
98 | End With
99 | failed:
100 | If Err.Number Then Code128 = "ERROR Code128: " & Err.Description
101 | End Function
102 |
--------------------------------------------------------------------------------
/VBComponents/modCode.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modCode"
2 | Option Explicit
3 |
4 | 'Wikipedia References
5 | 'Code 39: https://en.wikipedia.org/wiki/Code_39
6 | 'Code 11: https://en.wikipedia.org/wiki/Code_11
7 | 'Code 93: https://en.wikipedia.org/wiki/Code_93
8 |
9 | Function Code11(source As String) As String
10 | Attribute Code11.VB_Description = "Encode Code 11 barcode."
11 | Attribute Code11.VB_ProcData.VB_Invoke_Func = " \n20"
12 | Const strCode11 As String = "0123456789-"
13 | Dim Coode11Table
14 | Dim i As Integer
15 | Dim count As Integer
16 | Dim dest As String
17 |
18 | Coode11Table = Array("111121", "211121", "121121", "221111", "112121", _
19 | "212111", "122111", "111221", "211211", "211111", "112111")
20 |
21 | 'Validate source
22 | For i = 1 To Len(source) Step 1
23 | If InStr(1, strCode11, Mid(source, i, 1)) = 0 Then
24 | Code11 = "Invalid character found: " & Mid(source, i, 1)
25 | Exit Function
26 | End If
27 | Next i
28 |
29 | count = 0
30 | 'Start character (asterisk)
31 | dest = "112211"
32 | 'Middle characters
33 | For i = 1 To Len(source) Step 1
34 | dest = dest & Coode11Table(InStr(1, strCode11, Mid(source, i, 1)) - 1)
35 | count = count + InStr(1, strCode11, Mid(source, i, 1)) - 1
36 | Next i
37 | 'End character (asterisk)
38 | dest = dest & "11221"
39 |
40 | Code11 = DRAWLINEAR(dest)
41 | End Function
42 |
43 | Function Code39(source As String, Optional CHECK_DIGIT As Boolean = False) As String
44 | Attribute Code39.VB_Description = "Encode Code 39 barcode."
45 | Attribute Code39.VB_ProcData.VB_Invoke_Func = " \n20"
46 | Const strCode39 As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
47 | Dim Code39Table
48 | Dim i As Integer
49 | Dim count As Integer
50 | Dim dest As String
51 |
52 | Code39Table = Array("1112212111", "2112111121", "1122111121", "2122111111", "1112211121", _
53 | "2112211111", "1122211111", "1112112121", "2112112111", "1122112111", "2111121121", _
54 | "1121121121", "2121121111", "1111221121", "2111221111", "1121221111", "1111122121", _
55 | "2111122111", "1121122111", "1111222111", "2111111221", "1121111221", "2121111211", _
56 | "1111211221", "2111211211", "1121211211", "1111112221", "2111112211", "1121112211", _
57 | "1111212211", "2211111121", "1221111121", "2221111111", "1211211121", "2211211111", _
58 | "1221211111", "1211112121", "2211112111", "1221112111", "1212121111", "1212111211", _
59 | "1211121211", "1112121211")
60 | source = UCase(source)
61 |
62 | 'Validate source
63 | For i = 1 To Len(source) Step 1
64 | If InStr(1, strCode39, Mid(source, i, 1)) = 0 Then
65 | Code39 = "Invalid character found: " & Mid(source, i, 1)
66 | Exit Function
67 | End If
68 | Next i
69 |
70 | count = 0
71 | 'Start character (asterisk)
72 | dest = "1211212111"
73 | 'Middle characters
74 | For i = 1 To Len(source) Step 1
75 | dest = dest & Code39Table(InStr(1, strCode39, Mid(source, i, 1)) - 1)
76 | count = count + InStr(1, strCode39, Mid(source, i, 1)) - 1
77 | Next i
78 | 'Check digit (Code 39 mod 43)
79 | If CHECK_DIGIT = True Then
80 | count = count Mod 43
81 | dest = dest & Code39Table(count)
82 | End If
83 | 'End character (asterisk)
84 | dest = dest & "1211212111"
85 |
86 | Code39 = DRAWLINEAR(dest)
87 | End Function
88 |
89 | Function Code93(source As String) As String
90 | Attribute Code93.VB_Description = "Encode Code 93 barcode."
91 | Attribute Code93.VB_ProcData.VB_Invoke_Func = " \n20"
92 | Const strCode93 As String = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
93 | Dim Code93Table
94 | Dim i As Integer
95 | Dim c, K As Integer
96 | Dim weight As Integer
97 | Dim dest As String
98 |
99 | Code93Table = Array("131112", "111213", "111312", "111411", "121113", "121212", "121311", _
100 | "111114", "131211", "141111", "211113", "211212", "211311", "221112", "221211", "231111", _
101 | "112113", "112212", "112311", "122112", "132111", "111123", "111222", "111321", "121122", _
102 | "131121", "212112", "212211", "211122", "211221", "221121", "222111", "112122", "112221", _
103 | "122121", "123111", "121131", "311112", "311211", "321111", "112131", "113121", "211131", _
104 | "121221", "312111", "311121", "122211")
105 | source = UCase(source)
106 |
107 | 'Validate source
108 | For i = 1 To Len(source) Step 1
109 | If InStr(1, strCode93, Mid(source, i, 1)) = 0 Then
110 | Code93 = "Invalid character found: " & Mid(source, i, 1)
111 | Exit Function
112 | End If
113 | Next i
114 |
115 | 'Start character
116 | dest = "111141"
117 | 'Middle character
118 | For i = 1 To Len(source) Step 1
119 | dest = dest & Code93Table(InStr(1, strCode93, Mid(source, i, 1)) - 1)
120 | Next i
121 | 'Check digit C
122 | c = 0
123 | weight = 1
124 | For i = Len(source) To 1 Step -1
125 | c = c + (InStr(1, strCode93, Mid(source, i, 1)) - 1) * weight
126 | weight = weight + 1
127 | If weight = 21 Then weight = 1
128 | Next i
129 | c = c Mod 47
130 | source = source & Mid(strCode93, c + 1, 1)
131 | dest = dest & Code93Table(InStr(1, strCode93, Mid(strCode93, c + 1, 1)) - 1)
132 | 'Check digit K
133 | K = 0
134 | weight = 1
135 | For i = Len(source) To 1 Step -1
136 | K = K + (InStr(1, strCode93, Mid(source, i, 1)) - 1) * weight
137 | weight = weight + 1
138 | If weight = 16 Then weight = 1
139 | Next i
140 | K = K Mod 47
141 | source = source & Mid(strCode93, K + 1, 1)
142 | dest = dest & Code93Table(InStr(1, strCode93, Mid(strCode93, K + 1, 1)) - 1)
143 | 'End character
144 | dest = dest & "1111411"
145 |
146 | Code93 = DRAWLINEAR(dest)
147 | End Function
148 |
--------------------------------------------------------------------------------
/VBComponents/modMain.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modMain"
2 | ' Barcode symbol creation by VBA
3 | ' Author: alois zingl
4 | ' Version: V1.1 jan 2016
5 | ' Copyright: Free and open-source software
6 | ' http://members.chello.at/~easyfilter/barcode.html
7 | ' Description: the indention of this library is a short and compact implementation to create barcodes
8 | ' of Code 128, Data Matrix, (micro) QR, PDF417, or Aztec symbols so it could be easily adapted for individual requirements.
9 | ' The Barcode is drawn as shape in the cell of the Excel sheet.
10 | ' The smallest bar code symbol fitting the data is automatically selected,
11 | ' but no size optimization for mixed data types in one code is done.
12 | ' Functions:
13 | ' DataMatrix(text As String, Optional rectangle As Integer)
14 | ' QuickResponse(text As String, Optional level As String = "L", Optional version As Integer = 1)
15 | ' Aztec(text As String, Optional security As Integer, Optional layers As Integer = 1)
16 | ' Code128(text As String)
17 | ' PDFIVXVII(text As String, Optional security = -1, Optional nbcol = 1, Optional CodeErr)
18 | '
19 | Option Explicit
20 |
21 | ' convert UTF-16 (Windows) to UTF-8
22 | Public Function utf16to8(text As String) As String
23 | Dim i As Integer, c As Long
24 | utf16to8 = text
25 | For i = Len(text) To 1 Step -1
26 | c = AscW(Mid(text, i, 1)) And 65535
27 | If c > 127 Then
28 | If c > 4095 Then
29 | utf16to8 = Left(utf16to8, i - 1) + Chr(224 + c \ 4096) + Chr(128 + (c \ 64 And 63)) + Chr(128 + (c And 63)) & Mid(utf16to8, i + 1)
30 | Else
31 | utf16to8 = Left(utf16to8, i - 1) + Chr(192 + c \ 64) + Chr(128 + (c And 63)) & Mid(utf16to8, i + 1)
32 | End If
33 | End If
34 | Next i
35 | End Function
36 |
37 | ' read/write kanji conversion string from/to file
38 | Public Sub Kanji()
39 | Dim p As Variant, s As Worksheet, k1 As String, c As Long
40 | Const K = "kanji" ' property name
41 | For Each s In Application.ThisWorkbook.Worksheets
42 | For Each p In s.CustomProperties ' look for kanji conversion string
43 | If p.Name = K Then If Len(p.Value) > 10000 Then k1 = p.Value
44 | Next p
45 | Next s
46 | ChDir Application.ThisWorkbook.Path
47 | If k1 = "" Then ' not found, get from file
48 | p = Application.GetOpenFilename("Excel Files (*.xlsm), *.xlsm", 1, "Read Kanji Conversion String for QRCodes from 'barcode.xlsm'")
49 | If p <> False Then
50 | Application.ScreenUpdating = False
51 | With Workbooks.Open(p, 0, True)
52 | For Each s In .Worksheets
53 | For Each p In s.CustomProperties ' look for kanji conversion string
54 | If p.Name = K Then If Len(p.Value) > 10000 Then k1 = p.Value
55 | Next p
56 | Next s
57 | .Close
58 | End With
59 | Application.ScreenUpdating = True
60 | If Len(k1) < 10000 Or (Len(k1) And 1) Then MsgBox "No Kanji conversion string for QRCodes found in Excel file."
61 | For Each s In Application.ThisWorkbook.Worksheets
62 | c = 0
63 | For Each p In s.CustomProperties ' look for kanji conversion string
64 | If p.Name = K Then p.Value = k1: c = 1
65 | Next p
66 | If c = 0 Then s.CustomProperties.Add K, k1
67 | Next s
68 | End If
69 | End If
70 | End Sub
71 |
72 | Public Function DRAWLINEAR(barcode As String) As String
73 | On Error GoTo failed
74 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "Linear Barcode", "Call only from sheet"
75 | Dim i, j, K As Integer
76 | Dim x As Integer
77 | Dim shp As Shape, color As Long, txt As String ' redraw barcode ?
78 | color = vbBlack
79 | For Each shp In Application.Caller.Parent.Shapes
80 | If shp.Name = Application.Caller.Address Then
81 | If shp.Title = barcode Then Exit Function ' same as prev ?
82 | color = shp.Fill.ForeColor.RGB ' redraw with same color
83 | shp.line.Visible = msoFalse
84 | shp.Delete
85 | End If
86 | Next shp
87 |
88 | 'Validate barcode
89 | If IsNumeric(barcode) = False Then
90 | DRAWLINEAR = barcode
91 | Exit Function
92 | End If
93 |
94 | With Application.Caller.Parent.Shapes
95 | K = .count + 1
96 | x = 0
97 | For i = 1 To Len(barcode) Step 1
98 | If i Mod 2 <> 0 Then
99 | .AddShape(msoShapeRectangle, x, 1, Mid(barcode, i, 1), 1).Name = Application.Caller.Address
100 | End If
101 | x = x + Mid(barcode, i, 1)
102 | Next i
103 | K = .count - K
104 | ReDim shps(K) As Integer ' group all shapes
105 | For j = .count To 1 Step -1
106 | If .Range(j).Name = Application.Caller.Address Then
107 | shps(K) = j: K = K - 1
108 | If K < 0 Then Exit For
109 | End If
110 | Next j
111 |
112 | With .Range(shps).Group
113 | .Fill.ForeColor.RGB = color ' format barcode shape
114 | .line.Visible = msoFalse
115 | .Width = Application.Caller.MergeArea.Width * (calcModules(barcode) - 18) / calcModules(barcode) ' fit symbol in excel cell with padding
116 | .Height = Application.Caller.MergeArea.Height
117 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
118 | .Top = Application.Caller.Top
119 | .Name = Application.Caller.Address ' link shape to data
120 | .Title = barcode
121 | .AlternativeText = "Linear barcode, " & calcModules(barcode) & " modules"
122 | .LockAspectRatio = True
123 | .Placement = xlMove
124 | End With
125 |
126 | End With
127 |
128 | failed:
129 | If Err.Number Then DRAWLINEAR = "ERROR DRAWLINEAR: " & Err.Description
130 | End Function
131 |
132 | Private Function calcModules(source As String) As Long
133 | Dim i As Long
134 | Dim count As Long
135 |
136 | count = 0
137 | For i = 1 To Len(source) Step 1
138 | count = count + Int(Mid(source, i, 1))
139 | Next i
140 |
141 | calcModules = count
142 |
143 | End Function
144 |
--------------------------------------------------------------------------------
/VBComponents/modAddInMenu.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modAddInMenu"
2 | Option Explicit
3 | Dim BarcodeList As Variant
4 |
5 | '*********************************XML CODE*********************************
6 | '
7 | '
8 | '
9 | '
10 | '
11 | '
21 | '
27 | '
28 | '
35 | '
42 | '
43 | '
44 | '
45 | '
46 | '
47 | '*********************************XML CODE*********************************
48 |
49 | Private Sub AddInMenuProperties()
50 | ' Custom function for changing file properties (not used during run time)
51 | ActiveWorkbook.BuiltinDocumentProperties("Title").Value = "Barcode Fx 3.0"
52 | ActiveWorkbook.BuiltinDocumentProperties("Comments").Value = "Function library for barcodes"
53 | End Sub
54 |
55 | Sub Auto_Open()
56 |
57 | ' Populate BarcodeList
58 | BarcodeList = Array("Aztec()", "Code11()", "Code39()", "Code93()", "Code128()", _
59 | "DataMatrix()", "EAN_2()", "EAN_5()", "EAN_13()", "ITF()", _
60 | "ITF_14()", "PDF_417()", "QRCode()", "UPCA()", "UPCE()")
61 |
62 | End Sub
63 |
64 | 'update all barcodes in active sheet
65 | Sub updateBarcodes_Click(control As IRibbonControl)
66 | Dim shp As Shape, bc As Variant, str As String
67 | On Error Resume Next
68 | For Each shp In ActiveSheet.Shapes ' delete all lost barcode shapes
69 | If shp.Type = msoGroup Then
70 | str = LCase(shp.AlternativeText)
71 | For Each bc In Array("aztec", "code128", "datamatrix", "pdf417", "quickresponse barcode", "linear barcode")
72 | If Left(str, Len(bc)) = bc Then
73 | shp.Title = "" ' force redraw
74 | If InStr(LCase(Range(shp.Name).Formula), bc) = 0 Then shp.Delete
75 | Exit For
76 | End If
77 | Next bc
78 | End If
79 | Next shp
80 | ' refresh all barcodes
81 | Application.CalculateFull
82 | 'Call Kanji
83 | End Sub
84 |
85 | Sub getHelp_Click(control As IRibbonControl)
86 |
87 | Dim URL As String
88 |
89 | URL = "https://github.com/EszopiCoder/excel-barcode-fx-library"
90 |
91 | If MsgBox("You are leaving Microsoft Excel to the following website: " & URL & _
92 | vbNewLine & vbNewLine & "Would you like to proceed?", _
93 | vbExclamation + vbYesNo) = vbNo Then Exit Sub
94 |
95 | ActiveWorkbook.FollowHyperlink URL
96 |
97 | End Sub
98 |
99 | Sub Barcode_getItemCount(control As IRibbonControl, ByRef returnedVal)
100 | ' Return the number of functions in the array
101 | returnedVal = UBound(BarcodeList) - LBound(BarcodeList) + 1
102 | End Sub
103 |
104 | Sub Barcode_getItemLabel(control As IRibbonControl, index As Integer, ByRef returnedVal)
105 | On Error Resume Next
106 | ' Return the name of the function without arguments
107 | returnedVal = Left(BarcodeList(index), InStr(1, BarcodeList(index), "(") - 1)
108 | On Error GoTo 0
109 | End Sub
110 |
111 | Sub Barcode_getItemScreentip(control As IRibbonControl, index As Integer, ByRef returnedVal)
112 | On Error Resume Next
113 | ' Return the name of the function with arguments
114 | returnedVal = BarcodeList(index)
115 | On Error GoTo 0
116 | End Sub
117 |
118 | Sub Barcode_getItemSupertip(control As IRibbonControl, index As Integer, ByRef returnedVal)
119 | Dim Supertip As Variant
120 | Supertip = _
121 | Array("Draw Aztec barcode.", _
122 | "Draw Code 11 barcode.", _
123 | "Draw Code 39 barcode.", _
124 | "Draw Code 93 barcode.", _
125 | "Draw Code 128 barcode.", _
126 | "Draw DataMatrix barcode.", _
127 | "Draw EAN-2 barcode.", _
128 | "Draw EAN-5 barcode.", _
129 | "Draw EAN-13 barcode.", _
130 | "Draw ITF barcode.", _
131 | "Draw ITF-14 barcode.", _
132 | "Draw PDF417 barcode.", _
133 | "Draw QR code.", _
134 | "Draw UPC-A or EAN-8 barcode.", _
135 | "Draw UPC-E barcode.")
136 |
137 | On Error Resume Next
138 | returnedVal = Supertip(index)
139 | On Error GoTo 0
140 | End Sub
141 |
142 | Sub insertFx_Click(control As IRibbonControl)
143 |
144 | ActiveCell.FunctionWizard
145 |
146 | End Sub
147 |
148 | Sub Barcode_Click(control As IRibbonControl, id As String, index As Integer)
149 | On Error Resume Next
150 | ' Insert function into active cell (same as the other built-in functions)
151 | If InStr(1, ActiveCell.Formula, "=") > 0 Then
152 | ActiveCell.Formula = ActiveCell.Formula & "+" & BarcodeList(index)
153 | Else
154 | ActiveCell.Formula = "=" & BarcodeList(index)
155 | End If
156 | ' Open function wizard dialog. Clear cell if user hits cancel button.
157 | If Application.Dialogs(xlDialogFunctionWizard).Show = False Then
158 | ActiveCell.Formula = ""
159 | End If
160 | On Error GoTo 0
161 | End Sub
162 |
--------------------------------------------------------------------------------
/VBComponents/modUpcEan.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modupcean"
2 | Option Explicit
3 |
4 | 'GS1 EAN/UPC barcodes: https://www.gs1.org/standards/barcodes/ean-upc
5 |
6 | 'Wikipedia References
7 | 'UPC-A & UPC-E: https://en.wikipedia.org/wiki/Universal_Product_Code
8 | 'EAN-13: https://en.wikipedia.org/wiki/International_Article_Number
9 | 'EAN-8: https://en.wikipedia.org/wiki/EAN-8
10 | 'EAN-5: https://en.wikipedia.org/wiki/EAN-5
11 | 'EAN-2: https://en.wikipedia.org/wiki/EAN-2
12 |
13 | Dim UPCParity0
14 | Dim UPCParity1
15 | Dim EAN2Parity
16 | Dim EAN5Parity
17 | Dim EAN13Parity
18 | Dim EANsetA
19 | Dim EANsetB
20 |
21 | Private Sub upceanLibraries()
22 | UPCParity0 = Array("BBBAAA", "BBABAA", "BBAABA", "BBAAAB", "BABBAA", "BAABBA", "BAAABB", _
23 | "BABABA", "BABAAB", "BAABAB") 'Number set for UPC-E symbol (EN Table 4)
24 | UPCParity1 = Array("AAABBB", "AABABB", "AABBAB", "AABBBA", "ABAABB", "ABBAAB", "ABBBAA", _
25 | "ABABAB", "ABABBA", "ABBABA") 'Not covered by BS EN 797:1995
26 | EAN2Parity = Array("AA", "AB", "BA", "BB") 'Number sets for 2-digit add-on (EN Table 6)
27 | EAN5Parity = Array("BBAAA", "BABAA", "BAABA", "BAAAB", "ABBAA", "AABBA", "AAABB", "ABABA", _
28 | "ABAAB", "AABAB") 'Number set for 5-digit add-on (EN Table 7)
29 | EAN13Parity = Array("AAAAA", "ABABB", "ABBAB", "ABBBA", "BAABB", "BBAAB", "BBBAA", "BABAB", _
30 | "BABBA", "BBABA") 'Left hand of the EAN-13 symbol (EN Table 3)
31 | EANsetA = Array("3211", "2221", "2122", "1411", "1132", "1231", "1114", "1312", "1213", _
32 | "3112") 'Representation set A and C (EN Table 1)
33 | EANsetB = Array("1123", "1222", "2212", "1141", "2311", "1321", "4111", "2131", "3121", _
34 | "2113") 'Representation set B (EN Table 1)
35 | End Sub
36 |
37 | Public Function GS1_CHECK(source As String) As String
38 | 'Calculate the correct check digit for a UPC barcode
39 | 'Source: https://www.gs1.org/services/how-calculate-check-digit-manually
40 | Dim i As Integer
41 | Dim count As Integer
42 | Dim CHECK_DIGIT As Integer
43 |
44 | 'Loop through each digit to get sum
45 | count = 0
46 | For i = 1 To Len(source) Step 1
47 | count = count + Mid(source, i, 1)
48 | 'Length is even and even-numbered digit positions (2nd, 4th, 6th, etc.)
49 | 'Length is odd and odd-numbered digit positions (1st, 3rd, 5th, etc.)
50 | If (Len(source) Mod 2 = 0 And i Mod 2 = 0) Or _
51 | (Len(source) Mod 2 <> 0 And i Mod 2 <> 0) Then
52 | count = count + (2 * Mid(source, i, 1))
53 | End If
54 | Next i
55 |
56 | 'Calculate check digit
57 | CHECK_DIGIT = 10 - (count Mod 10)
58 | If CHECK_DIGIT = 10 Then CHECK_DIGIT = 0
59 | GS1_CHECK = CHECK_DIGIT
60 | End Function
61 |
62 | 'UPC-A and EAN-8
63 | Function UPCA(source As String) As String
64 | Attribute UPCA.VB_Description = "Encode UPC-A or EAN-8 barcode."
65 | Attribute UPCA.VB_ProcData.VB_Invoke_Func = " \n20"
66 | Dim i As Integer
67 | Dim half_way As Integer
68 | Dim dest As String
69 |
70 | 'Validate source
71 | If Len(source) <> 12 And Len(source) <> 11 And Len(source) <> 8 Then
72 | UPCA = "Improper EAN-8 or UPC-A barcode length (8 or 11-12 digits)"
73 | Exit Function
74 | ElseIf Len(source) = 12 And GS1_CHECK(Left(source, 11)) <> Right(source, 1) Then
75 | UPCA = "Invalid check digit (" & GS1_CHECK(Left(source, 11)) & ")"
76 | Exit Function
77 | End If
78 |
79 | 'Calculate check digit (UPC-A only)
80 | If Len(source) = 11 Then source = source & GS1_CHECK(source)
81 |
82 | Call upceanLibraries
83 |
84 | half_way = Len(source) / 2
85 | 'Start character
86 | dest = "111"
87 | 'Left/Middle/Right characters
88 | For i = 1 To Len(source) Step 1
89 | If i = half_way + 1 Then
90 | dest = dest & "11111"
91 | End If
92 | dest = dest & EANsetA(Mid(source, i, 1))
93 | Next i
94 | 'End character
95 | dest = dest & "111"
96 |
97 | UPCA = DRAWLINEAR(dest)
98 |
99 | End Function
100 |
101 | Function UPCE(source As String) As String
102 | Attribute UPCE.VB_Description = "Encode UPC-E barcode."
103 | Attribute UPCE.VB_ProcData.VB_Invoke_Func = " \n20"
104 | Dim i As Integer
105 | Dim emode As Integer
106 | Dim equivalent As String
107 | Dim CHECK_DIGIT As Integer
108 | Dim parity As String
109 | Dim dest As String
110 |
111 | 'Two number systems can be used - system 0 and system 1
112 | If Len(source) = 7 Then
113 | If Left(source, 1) > 1 Then _
114 | source = "0" & Right(source, 6)
115 | ElseIf Len(source) = 6 Then 'Default number system is 0
116 | source = "0" & source
117 | Else
118 | UPCE = "Improper UPC-E barcode length (6-7 digits)"
119 | Exit Function
120 | End If
121 |
122 | Call upceanLibraries
123 |
124 | 'Expand the zero-compressed UPCE code to make a UPCA equivalent (EN Table 5)
125 | emode = Right(source, 1)
126 | equivalent = Left(source, 3)
127 | Select Case emode
128 | Case 0 To 2
129 | equivalent = equivalent & emode & "0000" & Mid(source, 4, 3)
130 | Case 3
131 | equivalent = equivalent & Mid(source, 4, 1) & "00000" & Mid(source, 5, 2)
132 | Case 4
133 | equivalent = equivalent & Mid(source, 4, 2) & "00000" & Mid(source, 6, 1)
134 | Case 5 To 9
135 | equivalent = equivalent & Mid(source, 4, 3) & "0000" & emode
136 | End Select
137 | 'Calculate check digit
138 | CHECK_DIGIT = GS1_CHECK(equivalent)
139 | equivalent = equivalent & CHECK_DIGIT
140 |
141 | 'Use number system and check digit to choose a parity scheme
142 | If Left(equivalent, 1) = 1 Then
143 | parity = UPCParity1(CHECK_DIGIT)
144 | Else
145 | parity = UPCParity0(CHECK_DIGIT)
146 | End If
147 |
148 | 'Start character
149 | dest = "111"
150 | 'Middle characters
151 | For i = 1 To Len(parity) Step 1
152 | Select Case Mid(parity, i, 1)
153 | Case "A"
154 | dest = dest & EANsetA(Mid(source, i + 1, 1))
155 | Case "B"
156 | dest = dest & EANsetB(Mid(source, i + 1, 1))
157 | End Select
158 | Next i
159 | 'End character
160 | dest = dest & "111111"
161 |
162 | UPCE = DRAWLINEAR(dest)
163 |
164 | End Function
165 |
166 | Function EAN_13(source As String) As String
167 | Attribute EAN_13.VB_Description = "Encode EAN-13 barcode."
168 | Attribute EAN_13.VB_ProcData.VB_Invoke_Func = " \n20"
169 | Dim parity As String
170 | Dim half_way As Integer
171 | Dim i As Integer
172 | Dim dest As String
173 |
174 | 'Validate source
175 | If Len(source) > 13 Or Len(source) < 12 Then
176 | EAN_13 = "Improper UPC-A barcode length (12-13 digits)"
177 | Exit Function
178 | ElseIf Len(source) = 13 And GS1_CHECK(Left(source, 12)) <> Right(source, 1) Then
179 | EAN_13 = "Invalid check digit (" & GS1_CHECK(Left(source, 12)) & ")"
180 | Exit Function
181 | End If
182 |
183 | 'Calculate check digit
184 | If Len(source) = 12 Then source = source & GS1_CHECK(source)
185 |
186 | Call upceanLibraries
187 |
188 | 'Get parity for first half of symbol
189 | parity = EAN13Parity(Left(source, 1))
190 |
191 | half_way = 8
192 |
193 | 'Start character
194 | dest = "111"
195 | 'Middle characters
196 | For i = 2 To Len(source) Step 1
197 | If i = half_way Then dest = dest & "11111"
198 | If i > 2 And i < 8 Then
199 | If Mid(parity, i - 2, 1) = "B" Then
200 | dest = dest & EANsetB(Mid(source, i, 1))
201 | Else
202 | dest = dest & EANsetA(Mid(source, i, 1))
203 | End If
204 | Else
205 | dest = dest & EANsetA(Mid(source, i, 1))
206 | End If
207 | Next i
208 | 'End character
209 | dest = dest & "111"
210 |
211 | EAN_13 = DRAWLINEAR(dest)
212 |
213 | End Function
214 |
215 | Function EAN_5(source As String) As String
216 | Attribute EAN_5.VB_Description = "Encode EAN-5 barcode."
217 | Attribute EAN_5.VB_ProcData.VB_Invoke_Func = " \n20"
218 | Dim i As Integer
219 | Dim parity_sum As Integer
220 | Dim parity As String
221 | Dim dest As String
222 |
223 | 'Validate source
224 | If Len(source) <> 5 Then
225 | EAN_5 = "Improper EAN-5 barcode length (5 digits)"
226 | End If
227 |
228 | Call upceanLibraries
229 |
230 | 'Determine parity
231 | parity_sum = 3 * (Int(Left(source, 1)) + Int(Mid(source, 3, 1)) + Int(Right(source, 1)))
232 | parity_sum = parity_sum + (9 * (Int(Mid(source, 2, 1)) + Int(Mid(source, 4, 1))))
233 | parity_sum = parity_sum Mod 10
234 | parity = EAN5Parity(parity_sum)
235 |
236 | 'Start character
237 | dest = "112"
238 | 'Middle characters
239 | For i = 1 To Len(parity) Step 1
240 | Select Case Mid(parity, i, 1)
241 | Case "A"
242 | dest = dest & EANsetA(Mid(source, i, 1))
243 | Case "B"
244 | dest = dest & EANsetB(Mid(source, i, 1))
245 | End Select
246 | If i <> Len(parity) Then
247 | dest = dest & "11"
248 | End If
249 | Next i
250 |
251 | EAN_5 = DRAWLINEAR(dest)
252 |
253 | End Function
254 |
255 | Function EAN_2(source As String) As String
256 | Attribute EAN_2.VB_Description = "Encode EAN-2 barcode."
257 | Attribute EAN_2.VB_ProcData.VB_Invoke_Func = " \n20"
258 | Dim i As Integer
259 | Dim parity_sum As Integer
260 | Dim parity As String
261 | Dim dest As String
262 |
263 | 'Validate source
264 | If Len(source) <> 2 Then
265 | EAN_2 = "Improper EAN-2 barcode length (2 digits)"
266 | End If
267 |
268 | Call upceanLibraries
269 |
270 | 'Determine parity
271 | parity_sum = Left(source, 1) * 10 + Right(source, 1)
272 | parity_sum = parity_sum Mod 4
273 | parity = EAN2Parity(parity_sum)
274 |
275 | 'Start character
276 | dest = "112"
277 | 'Middle characters
278 | For i = 1 To Len(parity) Step 1
279 | Select Case Mid(parity, i, 1)
280 | Case "A"
281 | dest = dest & EANsetA(Mid(source, i, 1))
282 | Case "B"
283 | dest = dest & EANsetB(Mid(source, i, 1))
284 | End Select
285 | If i <> Len(parity) Then
286 | dest = dest & "11"
287 | End If
288 | Next i
289 |
290 | EAN_2 = DRAWLINEAR(dest)
291 |
292 | End Function
293 |
--------------------------------------------------------------------------------
/VBComponents/modDataMatrix.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modDataMatrix"
2 | Option Explicit
3 |
4 | ' creates Data Matrix barcode symbol as shape in Excel cell.
5 | ' param text to encode
6 | ' param rectangle boolean, default autodetect on cell dimension
7 | ' Data Matrix symbol creation according ISO/IEC 16022:2006
8 | Public Function DataMatrix(text As String, Optional rectangle As Integer = -2) As String
9 | Attribute DataMatrix.VB_Description = "Draw DataMatrix barcode"
10 | Attribute DataMatrix.VB_ProcData.VB_Invoke_Func = " \n18"
11 | On Error GoTo failed
12 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "DataMatrix", "Call only from sheet"
13 | Dim enc As String, en As String, el As Long, k As Variant, l As Long
14 | Dim h As Long, w As Long, nc As Byte, nr As Byte, shp As Shape
15 | Dim fw As Integer, fh As Integer, i As Long, j As Long, b As Double
16 | Dim c As Long, r As Double, s As Long, x As Long, y As Long, txt As String
17 | Dim fColor As Long, bColor As Long, line As Long
18 | fColor = vbBlack: bColor = vbBlack: line = xlHairline ' redraw graphic ?
19 | For Each shp In Application.Caller.Parent.Shapes
20 | If shp.Name = Application.Caller.Address Then
21 | If shp.Title = text Then Exit Function ' same as prev ?
22 | fColor = shp.Fill.ForeColor.RGB ' remember format
23 | bColor = shp.line.ForeColor.RGB
24 | line = shp.line.Weight
25 | shp.Delete
26 | End If
27 | Next shp
28 | txt = IIf(text = "", " ", utf16to8(text)): l = Len(txt)
29 | For i = 1 To l ' ASCII mode encoding
30 | c = Asc(Mid(txt, i, 1)): r = 0
31 | If i < l Then r = Asc(Mid(txt, i + 1, 1))
32 | If c > 47 And c < 58 And r > 47 And r < 58 Then
33 | enc = enc + Chr((c - 48) * 10 + r - 48 + 130) ' 2 digits
34 | i = i + 1
35 | ElseIf (c > 127) Then ' extended char
36 | enc = enc + Chr(235) + Chr(c - 127)
37 | Else
38 | enc = enc + Chr(c + 1)
39 | End If
40 | Next i
41 | For x = 0 To 2 ' C40, TEXT and X12 modes encoding
42 | k = Array(Array(230, 31, 0, 0, 32, 9, 32 - 3, 47, 1, 33, 57, 9, 48 - 4, 64, 1, 58 - 15, 90, 9, 65 - 14, 95, 1, 91 - 22, 127, 2, 96, 255, 1, 0), _
43 | Array(239, 31, 0, 0, 32, 9, 32 - 3, 47, 1, 33, 57, 9, 48 - 4, 64, 1, 58 - 15, 90, 2, 64, 95, 1, 91 - 22, 122, 9, 97 - 14, 127, 2, 123 - 27, 255, 1, 0), _
44 | Array(238, 12, 8, 0, 13, 9, 13, 31, 8, 0, 32, 9, 32 - 3, 41, 8, 0, 42, 9, 42 - 1, 47, 8, 0, 57, 9, 48 - 4, 64, 8, 0, 90, 9, 65 - 14, 255, 8, 0))(x)
45 | b = 0: h = 0
46 | en = Chr(k(0)) ' start switch
47 | For i = 1 To l
48 | If h = 0 And i = l Then Exit For
49 | c = Asc(Mid(txt, i, 1))
50 | If c > 127 And k(0) <> 238 Then
51 | b = b * 40 + 1: b = b * 40 + 30
52 | h = h + 2: c = c - 128 ' hi bit in C40 & TEXT
53 | End If
54 | For j = 1 To 90 Step 3 ' select char set
55 | If c <= k(j) Then Exit For
56 | Next j
57 | s = k(j + 1) ' set
58 | If s = 8 Or (s = 9 And h = 0 And i = l) Then
59 | en = txt + txt
60 | Exit For ' char not in set, next mode
61 | End If
62 | If s < 5 And h = 2 And i = l Then 'Exit For ' last char in ASCII
63 | b = b * 40: h = 3 ' add padding
64 | i = i - 1
65 | Else
66 | If s < 5 Then b = b * 40 + s: h = h + 1 ' set
67 | b = b * 40 + c - k(j + 2): h = h + 1 ' char offset
68 | If h Mod 3 = 2 And k(0) <> 238 And i = l Then b = b * 40: h = h + 1 ' add padding
69 | End If
70 | Do While h > 2 ' pack 3 chars in 2 bytes
71 | h = h - 3: r = 40& ^ h
72 | c = Int(b / r) + 1
73 | en = en + Chr((c \ 256) And 255) + Chr(c And 255)
74 | b = b - c * r + r
75 | Loop
76 | Next i
77 | en = en + Chr(254) ' return to ASCII
78 | For i = i - h To l ' add last chars
79 | c = Asc(Mid(txt, i, 1))
80 | If (c > 127) Then en = en + Chr(235)
81 | en = en + Chr((c And 127) + 1)
82 | Next i
83 | If Len(en) < Len(enc) Then enc = en ' take shorter
84 | Next x
85 |
86 | j = (l + 1) And -4: b = 0: en = Chr(240) ' switch to Edifact
87 | For i = 1 To j
88 | If i < j Then ' encode char
89 | c = Asc(Mid(txt, i, 1))
90 | If c < 32 Or c > 94 Then Exit For ' not in set
91 | Else
92 | c = 31 ' return to ASCII
93 | End If
94 | b = b * 64 + (c And 63)
95 | If (i And 3) = 0 Then ' 4 data in 3 bytes
96 | en = en + Chr(b \ 65536) + Chr((b \ 256) And 255) + Chr(b And 255)
97 | b = 0
98 | End If
99 | Next i
100 | If j > 0 And i > j Then
101 | For i = i - 1 To l ' add last chars
102 | c = Asc(Mid(txt, i, 1))
103 | If (c > 127) Then en = en + Chr(235)
104 | en = en + Chr((c And 127) + 1)
105 | Next i
106 | If Len(en) < Len(enc) Then enc = en ' take shorter
107 | End If
108 |
109 | en = Chr(231) ' Base256 encoding
110 | If l > 250 Then en = en + Chr((l \ 250 + 37) And 255) ' len high byte
111 | en = en + Chr((l Mod 250 + (149 * (Len(en) + 1)) Mod 255 + 1) And 255) ' low
112 | For i = 1 To l ' data in 255 state algo
113 | en = en + Chr((Asc(Mid(txt, i, 1)) + (149 * (Len(en) + 1)) Mod 255 + 1) And 255)
114 | Next i
115 | If Len(en) < Len(enc) Then enc = en ' take shorter
116 |
117 | ' compute symbol size
118 | nc = 1: nr = 1: j = -1: b = 1: el = Len(enc) ' symbol size, regions, region size
119 | If (rectangle = -1 Or (rectangle = -2 And (Application.Caller.MergeArea.Width * 3 > Application.Caller.MergeArea.Height * 4))) And el < 50 Then ' rectangular pattern ?
120 | k = Array(16, 7, 28, 11, 24, 14, 32, 18, 32, 24, 44, 28) ' symbol width, checkwords
121 | Do
122 | j = j + 1: w = k(j) ' width w/o finder pattern
123 | h = 6 + (j And 12) ' height
124 | l = w * h / 8: j = j + 1 ' # of bytes in symbol
125 | Loop While l - k(j) < el ' data fit in symbol ?
126 | If w > 25 Then nc = 2 ' column regions
127 | Else ' square symbol
128 | w = 6: h = w
129 | i = 2 ' size increment
130 | k = Array(5, 7, 10, 12, 14, 18, 20, 24, 28, 36, 42, 48, 56, 68, 84, _
131 | 112, 144, 192, 224, 272, 336, 408, 496, 620) ' checkwords
132 | Do
133 | If j = UBound(k) Then Err.Raise 514, "DataMatrix", "Message too long"
134 | j = j + 1
135 | If w > 11 * i Then i = 4 + i And 12 ' advance increment
136 | w = w + i: h = w
137 | l = (w * h) \ 8
138 | Loop While l - k(j) < el
139 | If w > 27 Then nr = 2 * (w \ 54) + 2: nc = nr ' regions
140 | If l > 255 Then b = 2 * (l \ 512) + 2 ' blocks
141 | End If
142 | s = k(j) ' checkwords
143 | fw = w / nc: fh = h / nr ' region size
144 |
145 | If el < l - s Then enc = enc + Chr(129): el = el + 1 ' first padding
146 | Do While el < l - s ' add more padding
147 | el = el + 1
148 | enc = enc + Chr((((149 * el) Mod 253) + 130) Mod 254)
149 | Loop
150 |
151 | enc = enc + Space(s) ' compute Reed Solomon error detection and correction
152 | Dim rs(70) As Integer, rc(70) As Integer ' RS code
153 | Dim lg(256) As Integer, ex(255) As Integer ' log/exp table
154 | s = s / b: j = 1
155 | For i = 0 To 254
156 | ex(i) = j: lg(j) = i ' compute log/exp table of Galois field
157 | j = j + j: If j > 255 Then j = j Xor 301 ' GF polynomial a^8+a^5+a^3+a^2+1 = 100101101b = 301
158 | Next i
159 | rs(s + 1) = 0 ' compute RS generator polynomial
160 | For i = 0 To s
161 | rs(s - i) = 1
162 | For j = s - i + 1 To s
163 | rs(j) = rs(j + 1) Xor ex((lg(rs(j)) + i) Mod 255)
164 | Next j
165 | Next i
166 | For c = 1 To b ' compute RS correction data for each block
167 | For i = 0 To s: rc(i) = 0: Next i
168 | For i = c To el Step b
169 | x = rc(0) Xor Asc(Mid(enc, i, 1))
170 | For j = 1 To s
171 | rc(j - 1) = rc(j) Xor IIf(x, ex((lg(rs(j)) + lg(x)) Mod 255), 0)
172 | Next j
173 | Next i
174 | For i = 0 To s - 1 ' add interleaved correction data
175 | Mid(enc, el + c + i * b, 1) = Chr(rc(i))
176 | Next i
177 | Next c
178 |
179 | With Application.Caller.Parent.Shapes
180 | b = .Count + 1 ' layout DataMatrix barcode
181 | For i = 0 To h + 2 * nr - 1 Step fh + 2 ' finder horizontal
182 | For j = 0 To w + 2 * nc - 1
183 | .AddShape(msoShapeRectangle, j, i + fh + 1, 1, 1).Name = Application.Caller.Address
184 | If (j And 1) = 0 Then .AddShape(msoShapeRectangle, j, i, 1, 1).Name = Application.Caller.Address
185 | Next j
186 | Next i
187 | For i = 0 To w + 2 * nc - 1 Step fw + 2 ' finder vertical
188 | For j = 0 To h - 1
189 | .AddShape(msoShapeRectangle, i, j + (j \ fh) * 2 + 1, 1, 1).Name = Application.Caller.Address
190 | If (j And 1) = 1 Then .AddShape(msoShapeRectangle, i + fw + 1, j + (j \ fh) * 2, 1, 1).Name = Application.Caller.Address
191 | Next j
192 | Next i
193 | 'layout data
194 | s = 2: c = 0: r = 4 ' step,column,row of data position
195 | For i = 1 To l
196 | If (r = h - 3 And c = -1) Then ' corner A
197 | k = Array(w, 6 - h, w, 5 - h, w, 4 - h, w, 3 - h, w - 1, 3 - h, 3, 2, 2, 2, 1, 2)
198 | ElseIf r = h + 1 And c = 1 And (w And 7) = 0 And (h And 7) = 6 Then ' corner D
199 | k = Array(w - 2, -h, w - 3, -h, w - 4, -h, w - 2, -1 - h, w - 3, -1 - h, w - 4, -1 - h, w - 2, -2, -1, -2)
200 | Else
201 | If r = 0 And c = w - 2 And (w And 3) Then i = i - 1: GoTo continue ' corner B
202 | If r < 0 Or c >= w Or r >= h Or c < 0 Then ' outside
203 | s = -s: r = r + 2 + s / 2: c = c + 2 - s / 2 ' turn around
204 | Do While r < 0 Or c >= w Or r >= h Or c < 0
205 | r = r - s: c = c + s
206 | Loop
207 | End If
208 | If r = h - 2 And c = 0 And (w And 3) Then ' corner B
209 | k = Array(w - 1, 3 - h, w - 1, 2 - h, w - 2, 2 - h, w - 3, 2 - h, w - 4, 2 - h, 0, 1, 0, 0, 0, -1)
210 | ElseIf r = h - 2 And c = 0 And (w And 7) = 4 Then ' corner C
211 | k = Array(w - 1, 5 - h, w - 1, 4 - h, w - 1, 3 - h, w - 1, 2 - h, w - 2, 2 - h, 0, 1, 0, 0, 0, -1)
212 | ElseIf r = 1 And c = w - 1 And (w And 7) = 0 And (h And 7) = 6 Then ' omit corner D
213 | i = i - 1: GoTo continue
214 | Else
215 | k = Array(0, 0, -1, 0, -2, 0, 0, -1, -1, -1, -2, -1, -1, -2, -2, -2) ' nominal layout
216 | End If
217 | End If
218 | el = Asc(Mid(enc, i, 1))
219 | For j = 0 To 15 Step 2 ' layout each bit
220 | If el And 1 Then
221 | x = c + k(j): y = r + k(j + 1)
222 | If x < 0 Then x = x + w: y = y + 4 - ((w + 4) And 7) ' wrap around
223 | If y < 0 Then y = y + h: x = x + 4 - ((h + 4) And 7)
224 | .AddShape(msoShapeRectangle, x + 2 * (x \ fw) + 1, y + 2 * (y \ fh) + 1, 1, 1).Name = Application.Caller.Address
225 | End If
226 | el = el \ 2
227 | Next j
228 | continue:
229 | r = r - s: c = c + s ' diagonal step
230 | Next i
231 | For i = (w And -4) + 1 To w ' unfilled corner
232 | .AddShape(msoShapeRectangle, i, i, 1, 1).Name = Application.Caller.Address
233 | Next i
234 | b = .Count - b
235 | ReDim shps(b) As Integer ' group all shapes
236 | For i = .Count To 1 Step -1
237 | If .Range(i).Name = Application.Caller.Address Then
238 | shps(b) = i: b = b - 1
239 | If b < 0 Then Exit For
240 | End If
241 | Next i
242 | s = 2 ' padding around symbol
243 | x = Application.Caller.MergeArea.Width * w / (w + s)
244 | y = Application.Caller.MergeArea.Height * h / (h + s) * (w + s) / (h + s)
245 | If x > y Then x = y
246 | With .Range(shps).Group
247 | .Fill.ForeColor.RGB = fColor ' format barcode shape
248 | .line.ForeColor.RGB = bColor
249 | .line.Weight = line
250 | .Width = x ' fit symbol in excel cell
251 | .Height = .Width * (h + s) / (w + s)
252 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
253 | .Top = Application.Caller.Top + (Application.Caller.MergeArea.Height - .Height) / 2
254 | .Name = Application.Caller.Address ' link shape to data
255 | .Title = text
256 | .AlternativeText = "DataMatrix barcode, " & (w + 2 * nc) & "x" & (h + 2 * nr) & " cells"
257 | .LockAspectRatio = True
258 | .Placement = xlMove
259 | End With
260 | End With
261 | failed:
262 | If Err.Number Then DataMatrix = "ERROR DataMatrix: " & Err.Description
263 | End Function
264 |
--------------------------------------------------------------------------------
/VBComponents/modAztec.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modAztec"
2 | Option Explicit
3 | Dim typ As Long, enc(1665) As Integer
4 | Dim md As Long, eb As Long, el As Long, b As Long
5 |
6 | ' Aztec bar code symbol creation according ISO/IEC 24778:2008
7 | ' param text to encode
8 | ' param security optional: percentage of checkwords used for security 2%-90% (23%)
9 | ' param layers optional: number of layers (size), default autodetect, 0 - Aztec rune
10 | ' creates Actec and compact Aztec bar code symbol as shape in Excel cell.
11 | Public Function Aztec(text As String, Optional security As Integer, Optional layers As Integer = 1) As String
12 | Attribute Aztec.VB_Description = "Draw Aztec barcode"
13 | Attribute Aztec.VB_ProcData.VB_Invoke_Func = " \n18"
14 | Dim fColor As Long, bColor As Long, line As Long, shp As Shape, txt As String
15 | Dim x As Long, y As Long, dx As Long, dy As Long, ctr As Long, ec As Long
16 | Dim c As Long, i As Long, j As Long, k As Long, l As Long, m As Long
17 |
18 | On Error GoTo failed
19 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "Aztec code", "Call only from sheet"
20 | fColor = vbBlack: bColor = vbBlack: line = xlHairline ' redraw graphic ?
21 | For Each shp In Application.Caller.Parent.Shapes
22 | If shp.Name = Application.Caller.Address Then
23 | If shp.Title = text Then Exit Function ' same as prev ?
24 | fColor = shp.Fill.ForeColor.RGB ' remember format
25 | bColor = shp.line.ForeColor.RGB
26 | line = shp.line.Weight
27 | shp.Delete
28 | End If
29 | Next shp
30 | If security < 1 Then security = 23 Else If security > 90 Then security = 90
31 | txt = IIf(text = "", " ", utf16to8(text)) ' at least 1 char
32 | el = Len(txt): x = 4: typ = 0
33 | Do ' compute word size b: 6/8/10/12 bits
34 | i = Int(el * 100 / (100 - security) + 3) * x ' needed bits, at least 3 checkwords
35 | If i > l Then l = i
36 | b = IIf(l <= 240, 6, IIf(l <= 1920, 8, IIf(l <= 10208, 10, 12))) ' bit capacity -> word size
37 | i = IIf(layers < 3, 6, IIf(layers < 9, 8, IIf(layers < 23, 10, 12))) ' layer paramerter
38 | If i > b Then b = i
39 | If x >= b Then Exit Do
40 | el = 0: md = 0: eb = 0: enc(0) = 0 ' clr bit stream
41 | For i = 1 To Len(txt) ' scan text
42 | c = Asc(Mid(txt, i, 1)): k = 0
43 | If i < Len(txt) Then k = Asc(Mid(txt, i + 1, 1))
44 | If c = 32 Then ' space
45 | If md = 3 Then push 31: md = 0 ' punct: latch to upper
46 | c = 1 ' space in all other modes
47 | ElseIf md = 4 And c = 44 Then
48 | c = 12 ' , in digit mode
49 | ElseIf md = 4 And c = 46 Then
50 | c = 13 ' . in digit mode
51 | ElseIf ((c = 44 Or c = 46 Or c = 58) And k = 32) Or (c = 13 And k = 10) Then
52 | If md <> 3 Then push (0) ' shift to punct
53 | push IIf(c = 46, 3, IIf(c = 44, 4, IIf(c = 58, 5, 2))) ' two char encoding
54 | i = i + 1: GoTo continue
55 | Else
56 | c = IIf(c = 13 And modeOf(k) \ 32 = md, 97, modeOf(c))
57 | If c < 0 Then ' binary
58 | If md > 2 Then push IIf(md = 3, 31, 14): md = 0 ' latch to upper
59 | j = 0: push 31 ' shift to binary
60 | For k = 0 To Len(txt) - i - 1 ' calc binary length
61 | If modeOf(Asc(Mid(txt, k + i, 1))) < 0 Then
62 | j = 0
63 | Else
64 | j = j + 1
65 | If j > 5 Then Exit For ' look for at least 5 consecutive non binary chars
66 | End If
67 | Next k
68 | k = k - j
69 | If k > 30 Then
70 | push 0: push k - 30, 11
71 | Else
72 | push k + 1
73 | End If
74 | For j = 0 To k ' encode binary data
75 | push Asc(Mid(txt, i + j, 1)), 8
76 | If el > 1660 Then Exit For
77 | Next j
78 | i = i + k: GoTo continue
79 | End If
80 | m = c \ 32 ' needed mode
81 | If m = 4 And md = 2 Then push 29: md = 0 ' mixed to upper (to digit)
82 | If m <> 3 And md = 3 Then push 31: md = 0 ' exit punct: to upper
83 | If m <> 4 And md = 4 Then ' exit digit
84 | If (m = 3 Or m = 0) And modeOf(k) > 129 Then
85 | push (3 - m) * 5: push c And 31, 5 ' shift to punct/upper
86 | GoTo continue
87 | End If
88 | push 14: md = 0 ' latch to upper
89 | End If
90 | If md <> m Then ' mode change needed
91 | If m = 3 Then ' to punct
92 | If md <> 4 And modeOf(k) \ 32 = 3 Then ' 2x punct, latch to punkt
93 | If md <> 2 Then push 29 ' latch to mixed
94 | push 30 ' latch to punct
95 | md = 3 ' mode punct
96 | Else
97 | push 0 ' shift to punct
98 | End If
99 | ElseIf md = 1 And m = 0 Then ' lower to upper
100 | If modeOf(k) \ 32 = 1 Then
101 | push 28 ' shift
102 | Else
103 | push 30: push 14, 4 ' latch
104 | md = 0
105 | End If
106 | Else ' latch to ..
107 | push Array(29, 28, 29, 30, 30)(m)
108 | md = m
109 | End If
110 | End If
111 | End If
112 | push c And 31 ' add char
113 | If el > 1660 Then Exit For
114 | continue:
115 | Next i
116 | push 2 ^ (b - eb) - 1, b - eb ' add padding bits
117 | x = b
118 | Loop
119 | If el > 1660 Then Err.Raise 514, "Aztec code", "Message too long."
120 | typ = IIf(l > 608 Or el > 64, 14, 11) ' full or compact Aztec
121 | md = val(Left(txt, 3)) ' Aztec rune possible ?
122 | If md < 0 Or md > 255 Or md & "" <> txt Or layers > 0 Then
123 | i = -Int((typ - Sqr(l + typ * typ)) / 4) ' needed layers
124 | If i > layers Then layers = i
125 | If layers > 32 Then layers = 32
126 | End If
127 | ec = (8 * layers * (typ + 2 * layers)) \ b - el ' # of checkwords
128 | typ = typ \ 2: ctr = typ + 2 * layers: ctr = ctr + (ctr - 1) \ 15 ' center position
129 | security = 100 * ec / (el + ec)
130 |
131 | With Application.Caller.Parent.Shapes ' layout Aztec barcode
132 | m = .Count + 1
133 | For y = 1 - typ To typ - 1 ' layout central finder
134 | For x = 1 - typ To typ - 1
135 | If (IIf(Abs(x) > Abs(y), x, y) And 1) = 0 Then
136 | .AddShape(msoShapeRectangle, ctr + x, ctr + y, 1, 1).Name = Application.Caller.Address
137 | End If
138 | Next x
139 | Next y
140 | For i = 0 To 5 ' orientation marks
141 | x = Array(-typ, -typ, 1 - typ, typ, typ, typ)(i)
142 | y = Array(1 - typ, -typ, -typ, typ - 1, 1 - typ, -typ)(i)
143 | .AddShape(msoShapeRectangle, ctr + x, ctr + y, 1, 1).Name = Application.Caller.Address
144 | Next i
145 | If layers > 0 Then ' layout data
146 | addCheck ec, 2 ^ b - 1, Array(67, 301, 1033, 4201)(b / 2 - 3) ' error correction, generator polynomial
147 | x = -typ: y = x - 1 ' start of layer 1 at top left
148 | j = (3 * typ + 11) / 2: l = j ' length of inner side
149 | dx = 1: dy = 0 ' direction right
150 | For ec = ec + el - 1 To 0 Step -1 ' layout codeword
151 | c = enc(ec) ' data in reversed order inside to outside
152 | For i = 1 To b / 2
153 | If c And 1 Then ' odd bit
154 | .AddShape(msoShapeRectangle, ctr + x, ctr + y, 1, 1).Name = Application.Caller.Address
155 | End If
156 | move x, y, dy, -dx ' move across
157 | If c And 2 Then ' even bit
158 | .AddShape(msoShapeRectangle, ctr + x, ctr + y, 1, 1).Name = Application.Caller.Address
159 | End If
160 | move x, y, dx - dy, dx + dy ' move ahead
161 | j = j - 1
162 | If j = 0 Then ' spiral turn
163 | move x, y, dy, -dx ' move across
164 | j = dx: dx = -dy: dy = j ' rotate clockwise
165 | If dx < 1 Then
166 | move x, y, dx - dy, dx + dy ' move ahead
167 | move x, y, dx - dy, dx + dy ' move ahead
168 | Else
169 | l = l + 4 ' full turn -> next layer
170 | End If
171 | j = l ' start new side
172 | End If
173 | c = c \ 4
174 | Next i
175 | Next ec
176 | If typ = 7 Then ' layout reference grid
177 | For x = (15 - ctr) And -16 To ctr Step 16
178 | For y = (1 - ctr) And -2 To ctr Step 2
179 | If Abs(x) > typ Or Abs(y) > typ Then
180 | .AddShape(msoShapeRectangle, ctr + x, ctr + y, 1, 1).Name = Application.Caller.Address ' down
181 | If y And 15 Then
182 | .AddShape(msoShapeRectangle, ctr + y, ctr + x, 1, 1).Name = Application.Caller.Address ' across
183 | End If
184 | End If
185 | Next y
186 | Next x
187 | End If
188 | md = (layers - 1) * (typ * 992 - 4896&) + el - 1 ' 2/5 + 6/11 mode bits
189 | End If
190 | el = typ - 3 ' process modes message compact/full
191 | For i = el - 1 To 0 Step -1
192 | enc(i) = md And 15 ' mode to 4 bit words
193 | md = md \ 16
194 | Next i
195 | addCheck typ \ 2 + 3, 15, 19 ' add 5/6 words error correction
196 | el = el + typ \ 2 + 3 ' init bit stream
197 | b = (typ * 3) \ 2 ' 7/10 bits per side
198 | eb = 0: j = IIf(layers, 0, 10) 'XOR Aztec rune data
199 | For i = 0 To b - 1
200 | push j Xor enc(i), 4 ' 8/16 words to 4 chunks
201 | Next i
202 | j = 1 ' layout mode data
203 | For i = 2 - typ To typ - 2
204 | If typ = 7 And i = 0 Then i = i + 1 ' skip reference grid
205 | If enc(b) And j Then .AddShape(msoShapeRectangle, ctr - i, ctr - typ, 1, 1).Name = Application.Caller.Address ' top
206 | If enc(b + 1) And j Then .AddShape(msoShapeRectangle, ctr + typ, ctr - i, 1, 1).Name = Application.Caller.Address ' right
207 | If enc(b + 2) And j Then .AddShape(msoShapeRectangle, ctr + i, ctr + typ, 1, 1).Name = Application.Caller.Address ' bottom
208 | If enc(b + 3) And j Then .AddShape(msoShapeRectangle, ctr - typ, ctr + i, 1, 1).Name = Application.Caller.Address ' left
209 | j = j + j
210 | Next i
211 | m = .Count - m
212 | ReDim shps(m) As Integer ' group all shapes
213 | For i = .Count To 1 Step -1
214 | If .Range(i).Name = Application.Caller.Address Then
215 | shps(m) = i: m = m - 1
216 | If m < 0 Then Exit For
217 | End If
218 | Next i
219 | With .Range(shps).Group
220 | .Fill.ForeColor.RGB = fColor ' format barcode shape
221 | .line.ForeColor.RGB = bColor
222 | .line.Weight = line
223 | x = Application.Caller.MergeArea.Width
224 | y = Application.Caller.MergeArea.Height
225 | If x > y Then x = y
226 | .Width = x * (2 * ctr + 1) / (2 * ctr + 3) ' fit symbol in excel cell
227 | .Height = .Width
228 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
229 | .Top = Application.Caller.Top + (Application.Caller.MergeArea.Height - .Height) / 2
230 | .Name = Application.Caller.Address ' link shape to data
231 | .Title = text
232 | .AlternativeText = "Aztec " & IIf(typ = 5, "compact", "full") & " barcode, security " & security & "%, layers " & layers & ", " & (2 * ctr + 1) & "x" & (2 * ctr + 1) & " cells"
233 | .LockAspectRatio = True
234 | .Placement = xlMove
235 | End With
236 | End With
237 | failed:
238 | If Err.Number Then Aztec = "ERROR Aztec: " & Err.Description
239 | End Function
240 |
241 | ' get character encoding mode of ch
242 | Private Function modeOf(ByVal ch As Integer) As Integer
243 | Dim i As Integer, k As Variant
244 | If ch = 32 Then modeOf = md * 32: Exit Function ' space
245 | k = Array(0, 14, 65, 26, 32, 52, 32, 48, 69, 47, 58, 82, 57, 64, 59, 64, 91, -63, 96, 123, -63)
246 | For i = 0 To UBound(k) Step 3 ' check range
247 | If ch > k(i) And ch < k(i + 1) Then Exit For
248 | Next i
249 | If i <= UBound(k) Then modeOf = ch + k(i + 2): Exit Function ' ch in range
250 | i = InStr("@\^_'|~¦[]{}", Chr(ch))
251 | modeOf = IIf(i = 0, -1, IIf(i < 9, 20 + 64, 27 + 96 - 8) + i - 1) ' binary/mixed/punct
252 | End Function
253 |
254 | ' add value to data stream
255 | Private Sub push(ByVal val As Long, Optional ByVal bits As Integer = 0)
256 | val = val * 2 ^ b
257 | If bits = 0 Then bits = IIf(md = 4, 4, 5)
258 | eb = eb + bits
259 | enc(el) = enc(el) + val \ 2 ^ eb ' add data
260 | Do While eb >= b ' word full ?
261 | If typ = 0 And (enc(el) < 2 Or enc(el) + 3 > 2 ^ b) Then ' bit stuffing
262 | enc(el) = enc(el) Xor ((enc(el) + 3) \ 2 And 1) ' add complementary bit
263 | eb = eb + 1
264 | End If
265 | eb = eb - b: el = el + 1
266 | enc(el) = (val \ 2 ^ eb) And ((2 ^ b) - 1)
267 | Loop
268 | End Sub
269 |
270 | ' compute Reed Solomon error detection and correction
271 | Private Sub addCheck(ByVal ec As Integer, ByVal s As Integer, ByVal p As Integer)
272 | Dim i As Integer, j As Integer, x As Integer
273 | ReDim rc(ec + 2) As Integer, lg(s + 1) As Integer, ex(s) As Integer
274 | j = 1
275 | For i = 0 To s - 1 ' compute log/exp table of Galois field
276 | ex(i) = j: lg(j) = i
277 | j = j + j: If (j > s) Then j = j Xor p ' GF polynomial
278 | Next i
279 | rc(ec + 1) = 0
280 | For i = 0 To ec ' compute RS generator polynomial
281 | rc(ec - i) = 1
282 | For j = ec - i + 1 To ec
283 | rc(j) = rc(j + 1) Xor ex((lg(rc(j)) + i) Mod s)
284 | Next j
285 | enc(el + i) = 0
286 | Next i
287 | For i = 0 To el - 1 ' compute RS checkwords
288 | x = enc(el) Xor enc(i)
289 | For j = 1 To ec
290 | enc(el + j - 1) = enc(el + j) Xor IIf(x, ex((lg(rc(j)) + lg(x)) Mod s), 0)
291 | Next j
292 | Next i
293 | End Sub
294 |
295 | ' move one cell
296 | Private Sub move(x As Long, y As Long, ByVal dx As Integer, ByVal dy As Integer)
297 | Do
298 | x = x + dx
299 | Loop While typ = 7 And (x And 15) = 0 ' skip reference grid
300 | Do
301 | y = y + dy
302 | Loop While typ = 7 And (y And 15) = 0
303 | End Sub
304 |
--------------------------------------------------------------------------------
/VBComponents/modQRcode.bas:
--------------------------------------------------------------------------------
1 | Attribute VB_Name = "modQRcode"
2 | Option Explicit
3 | Dim mat() As Byte ' matrix of QR
4 |
5 | ' QR Code 2005 bar code symbol creation according ISO/IEC 18004:2006
6 | ' param text to encode
7 | ' param level optional: quality level LMQH
8 | ' param version optional: minimum version size (-3:M1, -2:M2, .. 1, .. 40)
9 | ' creates QR and micro QR bar code symbol as shape in Excel cell.
10 | ' Kanji mode needs the custom property 'kanji' of the Application.Caller sheet to convert from unicode to kanji
11 | ' the string contains the 6879 chars of Kanji followed by the 6879 equivalent unicode chars
12 | Public Function QRCode(text As String, Optional level As String, Optional version As Integer = 1) As String
13 | Attribute QRCode.VB_Description = "Draw QR code"
14 | Attribute QRCode.VB_ProcData.VB_Invoke_Func = " \n18"
15 | On Error GoTo failed
16 | If Not TypeOf Application.Caller Is Range Then Err.Raise 513, "QR code", "Call only from sheet"
17 | Dim mode As Byte, lev As Byte, s As Long, a As Long, blk As Long, ec As Long
18 | Dim i As Long, j As Long, k As Long, l As Long, c As Long, b As Long, txt As String
19 | Dim w As Long, x As Long, y As Long, v As Double, el As Long, eb As Long
20 | Dim shp As Shape, m As Long, p As Variant, ecw As Variant, ecb As Variant
21 | Dim k1 As String, k2 As String, fColor As Long, bColor As Long, line As Long
22 | Const alpha = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:"
23 |
24 | fColor = vbBlack: bColor = vbBlack: line = xlHairline ' redraw graphic ?
25 | For Each shp In Application.Caller.Parent.Shapes
26 | If shp.Name = Application.Caller.Address Then
27 | If shp.Title = text Then Exit Function ' same as prev ?
28 | fColor = shp.Fill.ForeColor.RGB ' remember format
29 | bColor = shp.line.ForeColor.RGB
30 | line = shp.line.Weight
31 | shp.Delete
32 | End If
33 | Next shp
34 | For Each ecw In ActiveWorkbook.Worksheets
35 | For Each p In ecw.CustomProperties ' look for kanji conversion string
36 | If p.Name = "kanji" Then If Len(p.Value) > 10000 Then k1 = p.Value
37 | Next p
38 | Next ecw
39 | lev = (InStr("LMQHlmqh0123", level) - 1) And 3
40 | For i = 1 To Len(text) ' compute mode
41 | c = AscW(Mid(text, i, 1))
42 | If c < 48 Or c > 57 Then
43 | If mode = 0 Then mode = 1 ' alphanumeric mode
44 | If InStr(alpha, ChrW(c)) = 0 Then
45 | If mode = 1 Then mode = 2 ' binary or kanji ?
46 | If c < 32 Or c > 126 Then
47 | If InStr(Len(k1) / 2 + 1, k1, ChrW(c)) = 0 Then mode = 2: Exit For ' binary
48 | mode = 3 ' kanji
49 | End If
50 | End If
51 | End If
52 | Next i
53 | txt = IIf(mode = 2, utf16to8(text), text) ' for reader conformity
54 | l = Len(txt)
55 | w = Int(l * Array(10 / 3, 11 / 2, 8, 13)(mode) + 0.5) ' 3 digits in 10 bits, 2 chars in 11 bits, 1 byte, 13 bits/byte
56 | p = Array(Array(10, 12, 14), Array(9, 11, 13), Array(8, 16, 16), Array(8, 10, 12))(mode) ' # of bits of count indicator
57 | ' error correction words L,M,Q,H and blocks L,M,Q,H for all version sizes (99=N/A)
58 | ecw = Array(Array(2, 5, 6, 8, 7, 10, 15, 20, 26, 18, 20, 24, 30, 18, 20, 24, 26, 30, 22, 24, 28, 30, 28, 28, 28, 28, 30, 30, 26, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30), _
59 | Array(99, 6, 8, 10, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28), _
60 | Array(99, 99, 99, 14, 13, 22, 18, 26, 18, 24, 18, 22, 20, 24, 28, 26, 24, 20, 30, 24, 28, 28, 26, 30, 28, 30, 30, 30, 30, 28, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30), _
61 | Array(99, 99, 99, 99, 17, 28, 22, 16, 22, 28, 26, 26, 24, 28, 24, 28, 22, 24, 24, 30, 28, 28, 26, 28, 30, 24, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30))
62 | ecb = Array(Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 4, 4, 4, 4, 4, 6, 6, 6, 6, 7, 8, 8, 9, 9, 10, 12, 12, 12, 13, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 24, 25), _
63 | Array(1, 1, 1, 1, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49), _
64 | Array(1, 1, 1, 1, 1, 1, 2, 2, 4, 4, 6, 6, 8, 8, 8, 10, 12, 16, 12, 17, 16, 18, 21, 20, 23, 23, 25, 27, 29, 34, 34, 35, 38, 40, 43, 45, 48, 51, 53, 56, 59, 62, 65, 68), _
65 | Array(1, 1, 1, 1, 1, 1, 2, 4, 4, 4, 5, 6, 8, 8, 11, 11, 16, 16, 18, 16, 19, 21, 25, 25, 25, 34, 30, 32, 35, 37, 40, 42, 45, 48, 51, 54, 57, 60, 63, 66, 70, 74, 77, 81))
66 | version = IIf(version < mode - 3, mode - 3, version) - 1
67 | Do ' compute QR size
68 | version = version + 1
69 | If version + 3 > UBound(ecb(0)) Then Err.Raise 515, "QRCode", "Message too long"
70 | s = version * IIf(version < 1, 2, 4) + 17 ' symbol size
71 | j = ecb(lev)(version + 3) * ecw(lev)(version + 3) ' error correction
72 | a = IIf(version < 2, 0, version \ 7 + 2) ' # of align pattern
73 | el = (s - 1) * (s - 1) - (5 * a - 1) * (5 * a - 1) ' total bits - align - timing
74 | el = el - IIf(version < 1, 59, IIf(version < 2, 191, IIf(version < 7, 136, 172))) ' finder, version, format
75 | k = IIf(version < 1, version + (19 - 2 * mode) \ 3, p((version + 7) \ 17)) ' count indcator bits
76 | i = IIf(version < 1, version + (version And 1) * 4 + 3, 4) ' mode indicator bits, M1+M3: +4 bits
77 | Loop While (el And -8) - 8 * j < w + i + k
78 | For lev = lev To 2 ' increase security level if data still fits
79 | j = ecb(lev + 1)(version + 3) * ecw(lev + 1)(version + 3)
80 | If (el And -8) - 8 * j < w + i + k Then Exit For
81 | Next lev
82 | blk = ecb(lev)(version + 3) ' # of error correction blocks
83 | ec = ecw(lev)(version + 3) ' # of error correction bytes
84 | el = el \ 8 - ec * blk ' data capacity
85 | w = el \ blk ' # of words in group 1
86 | b = blk + w * blk - el ' # of blocks in group 1
87 |
88 | ReDim enc(el + ec * blk) As Byte, mat(s - 1, s - 1) As Byte
89 | c = 0 ' encode head indicator bits
90 | If version > 0 Then v = 2 ^ mode: eb = 4 Else v = mode: eb = version + 3 ' mode indicator
91 | eb = eb + k: v = v * 2 ^ k + l ' character count indicator
92 | For i = 1 To l ' encode data
93 | Select Case mode
94 | Case 0: ' numeric
95 | v = v * IIf(i + 1 < l, 1024, IIf(i < l, 128, 16)) + val(Mid(txt, i, 3))
96 | eb = eb + IIf(i + 1 < l, 10, 4 + 3 * (l - i)): i = i + 2
97 | Case 1: ' alphanumeric
98 | j = InStr(alpha, Mid(txt, i, 1)) - 1
99 | If i < l Then j = 45 * j + InStr(alpha, Mid(txt, i + 1, 1)) - 1
100 | v = v * IIf(i < l, 2048, 64) + j
101 | eb = eb + IIf(i < l, 11, 6): i = i + 1
102 | Case 2: ' binary
103 | v = v * 256 + Asc(Mid(txt, i, 1))
104 | eb = eb + 8
105 | Case 3: ' Kanji
106 | j = InStr(Len(k1) / 2 + 1, k1, Mid(txt, i, 1)) - Len(k1) / 2
107 | j = (AscW(Mid(k1, j, 1)) And &H3FFF) - 320 ' unicode to shift JIS X 2008
108 | v = v * 8192 + (j \ 256) * 192 + (j And 255) ' to 13 bit kanji
109 | eb = eb + 13
110 | End Select
111 | For eb = eb To 8 Step -8 ' add data to bit stream
112 | j = 2 ^ (eb - 8): enc(c) = v \ j
113 | v = v - enc(c) * j: c = c + 1
114 | Next eb
115 | Next i
116 | If el > c Then i = IIf(version > 0, 4, version + 6): v = v * 2 ^ i: eb = eb + i ' terminator
117 | enc(c) = (v * 256) \ 2 ^ eb: c = c + 1: enc(c) = ((v * 65536) \ 2 ^ eb) And 255
118 | If eb > 8 And el >= c Then c = c + 1 ' bit padding
119 | If (version And -3) = -3 And el = c Then enc(c) = enc(c) \ 16 ' M1,M3: shift high bits to low nibble
120 | i = 236
121 | For c = c To el - 1 ' byte padding
122 | enc(c) = IIf((version And -3) = -3 And c = el - 1, 0, i)
123 | i = i Xor 236 Xor 17
124 | Next c
125 |
126 | ReDim rs(ec + 1) As Integer ' compute Reed Solomon error detection and correction
127 | Dim lg(256) As Integer, ex(255) As Integer ' log/exp table
128 | j = 1
129 | For i = 0 To 254
130 | ex(i) = j: lg(j) = i ' compute log/exp table of Galois field
131 | j = j + j: If j > 255 Then j = j Xor 285 ' GF polynomial a^8+a^4+a^3+a^2+1 = 100011101b = 285
132 | Next i
133 | rs(0) = 1 ' compute RS generator polynomial
134 | For i = 0 To ec - 1
135 | rs(i + 1) = 0
136 | For j = i + 1 To 1 Step -1
137 | rs(j) = rs(j) Xor ex((lg(rs(j - 1)) + i) Mod 255)
138 | Next j
139 | Next i
140 | eb = el: k = 0
141 | For c = 1 To blk ' compute RS correction data for each block
142 | For i = IIf(c <= b, 1, 0) To w
143 | x = enc(eb) Xor enc(k)
144 | For j = 1 To ec
145 | enc(eb + j - 1) = enc(eb + j) Xor IIf(x, ex((lg(rs(j)) + lg(x)) Mod 255), 0)
146 | Next j
147 | k = k + 1
148 | Next i
149 | eb = eb + ec
150 | Next c
151 |
152 | ' fill QR matrix
153 | For i = 8 To s - 1 ' timing pattern
154 | mat(i, IIf(version < 1, 0, 6)) = i And 1 Xor 3
155 | mat(IIf(version < 1, 0, 6), i) = i And 1 Xor 3
156 | Next i
157 | If version > 6 Then ' reserve version area
158 | For i = 0 To 17
159 | mat(i \ 3, s - 11 + i Mod 3) = 2
160 | mat(s - 11 + i Mod 3, i \ 3) = 2
161 | Next i
162 | End If
163 | If a < 2 Then a = IIf(version < 1, 1, 2)
164 | For x = 1 To a ' layout finder/align pattern
165 | For y = 1 To a
166 | If x = 1 And y = 1 Then ' finder upper left
167 | i = 0: j = 0
168 | p = Array(383, 321, 349, 349, 349, 321, 383, 256, 511)
169 | ElseIf x = 1 And y = a Then ' finder lower left
170 | i = 0: j = s - 8
171 | p = Array(256, 383, 321, 349, 349, 349, 321, 383)
172 | ElseIf x = a And y = 1 Then ' finder upper right
173 | i = s - 8: j = 0
174 | p = Array(254, 130, 186, 186, 186, 130, 254, 0, 255)
175 | Else ' alignment grid
176 | c = 2 * Int(2 * (version + 1) / (1 - a)) ' pattern spacing
177 | i = IIf(x = 1, 4, s - 9 + c * (a - x))
178 | j = IIf(y = 1, 4, s - 9 + c * (a - y))
179 | p = Array(31, 17, 21, 17, 31) ' alignment pattern
180 | End If
181 | If version <> 1 Or x + y < 4 Then ' no align pattern for version 1
182 | For c = 0 To UBound(p) ' set fixed pattern, reserve space
183 | m = p(c): k = 0
184 | Do
185 | mat(i + k, j + c) = (m And 1) Or 2
186 | m = m \ 2: k = k + 1
187 | Loop While 2 ^ k <= p(0)
188 | Next c
189 | End If
190 | Next y
191 | Next x
192 | x = s: y = s - 1 ' layout codewords
193 | For i = 0 To eb - 1
194 | c = 0: k = 0: j = w + 1 ' interleave data
195 | If i >= el Then
196 | c = el: k = el: j = ec ' interleave checkwords
197 | ElseIf i + blk - b >= el Then
198 | c = -b: k = c ' interleave group 2 last bytes
199 | ElseIf (i Mod blk) >= b Then
200 | c = -b ' interleave group 2
201 | Else
202 | j = j - 1 ' interleave group 1
203 | End If
204 | c = enc(c + ((i - k) Mod blk) * j + (i - k) \ blk) ' interleave data
205 | For j = IIf((-3 And version) = -3 And i = el - 1, 3, 7) To 0 Step -1 ' M1,M3: 4 bit
206 | k = IIf(version > 0 And x < 6, 1, 0) ' skip vertical timing pattern
207 | Do ' advance x,y
208 | x = x - 1
209 | If 1 And (x + 1) Xor k Then
210 | If s - x - k And 2 Then
211 | If y > 0 Then y = y - 1: x = x + 2 ' up, top turn
212 | Else
213 | If y < s - 1 Then y = y + 1: x = x + 2 ' down, bottom turn
214 | End If
215 | End If
216 | Loop While mat(x, y) And 2 ' skip reserved area
217 | If c And 2 ^ j Then mat(x, y) = 1
218 | Next j
219 | Next i
220 |
221 | m = 0: p = 1000000 ' data masking
222 | For k = 0 To IIf(version < 1, 3, 7)
223 | If version < 1 Then ' penalty micro QR
224 | x = 1: y = 1
225 | For i = 1 To s - 1
226 | x = x - getPattern(i, s - 1, k, version)
227 | y = y - getPattern(s - 1, i, k, version)
228 | Next i
229 | j = IIf(x > y, 16 * x + y, x + 16 * y)
230 | Else ' penalty QR
231 | l = 0: k2 = "": j = 0
232 | For y = 0 To s - 1 ' horizontal
233 | c = 0: i = 0: k1 = "0000"
234 | For x = 0 To s - 1
235 | w = getPattern(x, y, k, version)
236 | l = l + w: k1 = k1 & w ' rule 4: count darks
237 | If c = w Then ' same as prev
238 | i = i + 1
239 | If x And Mid(k2, x + 4, 2) = c & c Then j = j + 3 ' rule 2: block 2x2
240 | Else
241 | If i > 5 Then j = j + i - 2 ' rule 1: >5 adjacent
242 | c = 1 - c: i = 1
243 | End If
244 | Next x
245 | If i > 5 Then j = j + i - 2 ' rule 1: >5 adjacent
246 | i = 0
247 | Do ' rule 3: like finder pattern
248 | i = InStr(i + 4, k1, "1011101")
249 | If i < 1 Then Exit Do
250 | If Mid(k1, i - 4, 4) = "0000" Or Mid(k1 & "0000", i + 7, 4) = "0000" Then j = j + 40
251 | Loop
252 | k2 = k1 ' rule 2: remember last line
253 | Next y
254 | For x = 0 To s - 1 ' vertical
255 | c = 0: i = 0: k1 = "0000"
256 | For y = 0 To s - 1
257 | w = getPattern(x, y, k, version)
258 | k1 = k1 & w ' vertical to string
259 | If c = w Then ' same as prev
260 | i = i + 1
261 | Else
262 | If i > 5 Then j = j + i - 2 ' rule 1: >5 adjacent
263 | c = 1 - c: i = 1
264 | End If
265 | Next y
266 | If i > 5 Then j = j + i - 2 ' rule 1: >5 adjacent
267 | i = 0
268 | Do ' rule 3: like finder pattern
269 | i = InStr(i + 4, k1, "1011101")
270 | If i < 1 Then Exit Do
271 | If Mid(k1, i - 4, 4) = "0000" Or Mid(k1 & "0000", i + 7, 4) = "0000" Then j = j + 40
272 | Loop
273 | Next x
274 | j = j + Int(Abs(10 - 20 * l / (s * s))) * 10 ' rule 4: darks
275 | End If
276 | If j < p Then p = j: m = k ' take mask of lower penalty
277 | Next k
278 | ' add format information, code level and mask
279 | j = IIf(version = -3, m, IIf(version < 1, (2 * version + lev + 5) * 4 + m, ((5 - lev) And 3) * 8 + m))
280 | j = j * 1024: k = j
281 | For i = 4 To 0 Step -1 ' BCH error correction: 5 data, 10 error bits
282 | If j >= 1024 * 2 ^ i Then j = j Xor 1335 * 2 ^ i
283 | Next i ' generator polynom: x^10+x^8+x^5+x^4+x^2+x+1 = 10100110111b = 1335
284 | k = k Xor j Xor IIf(version < 1, 17477, 21522) ' XOR masking
285 | For j = 0 To 14 ' layout format information
286 | If version < 1 Then
287 | mat(IIf(j < 8, 8, 15 - j), IIf(j < 8, j + 1, 8)) = k And 1 Xor 2 ' micro QR
288 | Else
289 | mat(IIf(j < 8, s - j - 1, IIf(j = 8, 7, 14 - j)), 8) = k And 1 Xor 2 ' QR horizontal
290 | mat(8, IIf(j < 6, j, IIf(j < 8, j + 1, s + j - 15))) = k And 1 Xor 2 ' vertical
291 | End If
292 | k = k \ 2
293 | Next j
294 | If version > 6 Then ' add version information
295 | k = version * 4096&
296 | For i = 5 To 0 Step -1 ' BCH error correction: 6 data, 12 error bits
297 | If k >= 4096 * 2 ^ i Then k = k Xor 7973 * 2 ^ i
298 | Next i ' generator polynom: x^12+x^11+x^10+x^9+x^8+x^5+x^2+1 = 1111100100101b = 7973
299 | k = k Xor (version * 4096&)
300 | For j = 0 To 17 ' layout version information
301 | mat(j \ 3, s + j Mod 3 - 11) = k And 1 Xor 2
302 | mat(s + j Mod 3 - 11, j \ 3) = k And 1 Xor 2
303 | k = k \ 2
304 | Next j
305 | End If
306 | With Application.Caller.Parent.Shapes
307 | k = .Count + 1 ' layout QR code
308 | For y = 0 To s - 1
309 | For x = 0 To s - 1
310 | If getPattern(x, y, m, version) Then ' apply mask
311 | .AddShape(msoShapeRectangle, x, y, 1, 1).Name = Application.Caller.Address
312 | End If
313 | Next x
314 | Next y
315 | k = .Count - k
316 | ReDim shps(k) As Integer ' group all shapes
317 | For i = .Count To 1 Step -1
318 | If .Range(i).Name = Application.Caller.Address Then
319 | shps(k) = i: k = k - 1
320 | If k < 0 Then Exit For
321 | End If
322 | Next i
323 |
324 | With .Range(shps).Group
325 | .Fill.ForeColor.RGB = fColor ' format barcode shape
326 | .line.ForeColor.RGB = bColor
327 | .line.Weight = line
328 | x = Application.Caller.MergeArea.Width
329 | y = Application.Caller.MergeArea.Height
330 | If x > y Then x = y
331 | .Width = x * s / (s + 2) ' fit symbol in excel cell
332 | .Height = .Width
333 | .Left = Application.Caller.Left + (Application.Caller.MergeArea.Width - .Width) / 2
334 | .Top = Application.Caller.Top + (Application.Caller.MergeArea.Height - .Height) / 2
335 | .Name = Application.Caller.Address ' link shape to data
336 | .Title = text
337 | .AlternativeText = "QuickResponse barcode, level " & Mid("LMQH", lev + 1, 1) & ", version " & IIf(version < 1, "M" & (version + 4), version) & ", mode " & Array("digit", "alpha", "binary", "kanji")(mode) & ", " & s & "x" & s & " cells"
338 | .LockAspectRatio = True
339 | .Placement = xlMove
340 | End With
341 | End With
342 | failed:
343 | If Err.Number Then QRCode = "ERROR QRCode: " & Err.Description
344 | End Function
345 |
346 | ' get QR pattern mask
347 | Private Function getPattern(ByVal x As Long, ByVal y As Long, ByVal m As Integer, ByVal version As Integer) As Integer
348 | Dim i As Integer, j As Long
349 | If version < 1 Then m = Array(1, 4, 6, 7)(m) ' mask pattern of micro QR
350 | i = mat(x, y)
351 | If i < 2 Then
352 | Select Case m
353 | Case 0: j = (x + y) And 1
354 | Case 1: j = y And 1
355 | Case 2: j = x Mod 3
356 | Case 3: j = (x + y) Mod 3
357 | Case 4: j = (x \ 3 + y \ 2) And 1
358 | Case 5: j = ((x * y) And 1) + (x * y) Mod 3
359 | Case 6: j = (x * y + (x * y) Mod 3) And 1
360 | Case 7: j = (x + y + (x * y) Mod 3) And 1
361 | End Select
362 | If j = 0 Then i = i Xor 1 ' invert only data according mask
363 | End If
364 | getPattern = i And 1
365 | End Function
366 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------