()
| 4 | |
| 5 | |
| 6 | def test_barcode(): |
| 7 | path = os.path.normpath(f'{__file__}/../../tests/test_barcode_out.pdf') |
| 8 | |
| 9 | url = 'http://artifex.com' |
| 10 | text_in = '012345678901' |
| 11 | text_out = '123456789012' |
| 12 | # Create empty document and add a qrcode image. |
| 13 | with pymupdf.Document() as document: |
| 14 | page = document.new_page() |
| 15 | |
| 16 | pixmap = pymupdf.mupdf.fz_new_barcode_pixmap( |
| 17 | pymupdf.mupdf.FZ_BARCODE_QRCODE, |
| 18 | url, |
| 19 | 512, |
| 20 | 4, # ec_level |
| 21 | 0, # quiet |
| 22 | 1, # hrt |
| 23 | ) |
| 24 | pixmap = pymupdf.Pixmap('raw', pixmap) |
| 25 | page.insert_image( |
| 26 | (0, 0, 100, 100), |
| 27 | pixmap=pixmap, |
| 28 | ) |
| 29 | pixmap = pymupdf.mupdf.fz_new_barcode_pixmap( |
| 30 | pymupdf.mupdf.FZ_BARCODE_EAN13, |
| 31 | text_in, |
| 32 | 512, |
| 33 | 4, # ec_level |
| 34 | 0, # quiet |
| 35 | 1, # hrt |
| 36 | ) |
| 37 | pixmap = pymupdf.Pixmap('raw', pixmap) |
| 38 | page.insert_image( |
| 39 | (0, 200, 100, 300), |
| 40 | pixmap=pixmap, |
| 41 | ) |
| 42 | |
| 43 | document.save(path) |
| 44 | |
| 45 | with pymupdf.open(path) as document: |
| 46 | page = document[0] |
| 47 | for i, ii in enumerate(page.get_images()): |
| 48 | xref = ii[0] |
| 49 | pixmap = pymupdf.Pixmap(document, xref) |
| 50 | hrt, barcode_type = pymupdf.mupdf.fz_decode_barcode_from_pixmap2( |
| 51 | pixmap.this, |
| 52 | 0, # rotate. |
| 53 | ) |
| 54 | print(f'{hrt=}') |
| 55 | if i == 0: |
| 56 | assert hrt == url |
| 57 | elif i == 1: |
| 58 | assert hrt == text_out |
| 59 | else: |
| 60 | assert 0 |
nothing calls this directly
no test coverage detected
searching dependent graphs…