diff --git a/barcode/__init__.py b/barcode/__init__.py index 78b38a7..0c2592d 100755 --- a/barcode/__init__.py +++ b/barcode/__init__.py @@ -12,7 +12,7 @@ """ from barcode.errors import BarcodeNotFoundError -from barcode.codex import Code39, PZN, Code128 +from barcode.codex import Code39, PZN, Code128, Gs1_128 from barcode.ean import EAN8, EAN13, EAN14, JAN from barcode.isxn import ISBN10, ISBN13, ISSN from barcode.upc import UPCA @@ -43,6 +43,7 @@ pzn=PZN, code128=Code128, itf=ITF, + gs1_128=Gs1_128, ) PROVIDED_BARCODES = list(__BARCODE_MAP) diff --git a/barcode/codex.py b/barcode/codex.py index 30d290f..c747175 100755 --- a/barcode/codex.py +++ b/barcode/codex.py @@ -258,5 +258,25 @@ def render(self, writer_options=None, text=None): return Barcode.render(self, options, text) +class Gs1_128(Code128): + """ + following the norm, a gs1-128 barcode is a subset of code 128 barcode, + it can be generated by prepending the code with the FNC1 character + https://en.wikipedia.org/wiki/GS1-128 + https://www.gs1-128.info/ + """ + + name = 'GS1-128' + + FNC1_CHAR = '\xf1' + + def __init__(self, code, writer=None): + code = self.FNC1_CHAR + code + super(Gs1_128, self).__init__(code, writer) + + def get_fullcode(self): + return super(Gs1_128, self).get_fullcode()[1:] + + # For pre 0.8 compatibility PZN = PZN7 diff --git a/test.py b/test.py index 8a9d523..a906558 100755 --- a/test.py +++ b/test.py @@ -149,6 +149,10 @@ def test_isbn13(self): isbn = get_barcode('isbn13', '978376926085') self.assertEqual('9783769260854', isbn.get_fullcode()) + def test_gs1_128(self): + gs1_128 = get_barcode('gs1_128', '00376401856400470087') + self.assertEqual('00376401856400470087', gs1_128.get_fullcode()) + if __name__ == '__main__': test()