Skip to content

Code128 issue, codes starting with 99 will have that stripped from finished barcode #251

@rejjen

Description

@rejjen

When generating Code128 barcode for code "999999" for example

The resulting svg will not include the first pair of nines.

Below are snippets for testing, which may or may not be optimal for illustrating the problem.

tests/test_builds.py

def test_code128_builds() -> None:
    gen_000000 = get_barcode("code128", "000000")
    code_000000 = gen_000000.build()
    gen_999999 = get_barcode("code128", "999999")
    code_999999 = gen_999999.build()

    assert len(code_000000[0]) == len(code_999999[0])

tests/test_init.py, to generate a svg

def test_generate_99999() -> None:
    with open(os.path.join(TESTPATH, "generate_999999.svg"), "wb") as f:
        barcode.generate("code128", "999999", output=f, writer=SVGWriter())

This is as far as I can tell behavior that is related to charset C for Code128, and may possibly be intentional.
But it feels very random.

Looks like this where this stripping happens.
https://github.com/WhyNotHugo/python-barcode/blob/85acbda24151d5ce155b3299077a87b25fcd2cc2/barcode/codex.py#L269C5-L272C23

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions