Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ from lpdf import L, NoAttr, DocumentAttr, LayoutAttr, ColumnAttr, RowAttr, TextA

engine = L.engine()

doc = L.document(DocumentAttr(size='letter'), [
doc = L.document(DocumentAttr(size='Letter'), [
L.section(NoAttr, [
L.layout(LayoutAttr(margin='48pt'), [
L.column(ColumnAttr(gap='24pt'), [
Expand Down
24 changes: 12 additions & 12 deletions src/lpdf/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@
class PageSize(StrEnum):
"""The named values of the `size` attribute of a document or a section. A width and a height, such as 100pt 200pt, is a string."""

A0 = "a0"
A1 = "a1"
A2 = "a2"
A3 = "a3"
A4 = "a4"
A5 = "a5"
A6 = "a6"
B4 = "b4"
B5 = "b5"
LETTER = "letter"
LEGAL = "legal"
TABLOID = "tabloid"
A0 = "A0"
A1 = "A1"
A2 = "A2"
A3 = "A3"
A4 = "A4"
A5 = "A5"
A6 = "A6"
B4 = "B4"
B5 = "B5"
LETTER = "Letter"
LEGAL = "Legal"
TABLOID = "Tabloid"


class Orientation(StrEnum):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cross_industry_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'<value name="nummer" path="rsm:ExchangedDocument/ram:ID"/></cross-industry-invoice-map>')
RECHNUNG_TEMPLATE = (
'<lpdf version="1"><assets><font name="body" src="../assets/fonts/SourceSans3-Regular.otf"/></assets>'
'<document size="a4" font="body"><section><layout margin="48pt">'
'<document size="A4" font="body"><section><layout margin="48pt">'
'<text data-value="rechnung:nummer">0000</text>'
'</layout></section></document></lpdf>'
)
Expand Down Expand Up @@ -101,7 +101,7 @@ def document_in_code(invoice_data: dict):
L.text(muted, ["VAT in"]), L.text(muted, [totals["taxCurrency"]]), L.text(muted, [totals["vatInTaxCurrency"]]),
])] if "vatInTaxCurrency" in totals else []
return L.document(DocumentAttr(
size="a4", font="body",
size="A4", font="body",
assets=DocumentAssets(fonts=[FontAttr(name="body", src="../assets/fonts/SourceSans3-Regular.otf")]),
meta=DocumentMeta(title="Invoice", author="Northwind Paper SAS", lang="en"),
), [
Expand Down
2 changes: 1 addition & 1 deletion tests/test_engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_render_xml_auto_loads_image_src(self, invoke, tmp_path):
invoke.return_value = _engine_response()
img_file = tmp_path / "logo.png"
img_file.write_bytes(b"\x89PNG")
xml = f'<lpdf><assets><image name="logo" src="{img_file}"/></assets><document size="a4"><pages><page/></pages></document></lpdf>'
xml = f'<lpdf><assets><image name="logo" src="{img_file}"/></assets><document size="A4"><pages><page/></pages></document></lpdf>'
engine = PdfEngine().set_license_key("key")
engine.render(xml)
payload = _extract_payload(invoke)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ def test_divider():

def test_section():
layout = L.layout(NoAttr, [L.text(NoAttr, ["Hello"])])
section = L.section(SectionAttr(size="a4", background="#ffffff"), [layout])
section = L.section(SectionAttr(size="A4", background="#ffffff"), [layout])
d = section.to_dict()
assert d["type"] == "section"
assert d["attrs"] == {"size": "a4", "background": "#ffffff"}
assert d["attrs"] == {"size": "A4", "background": "#ffffff"}
assert len(d["nodes"]) == 1


Expand Down Expand Up @@ -113,13 +113,13 @@ def test_document_includes_version():
def test_document_with_meta_and_tokens():
doc = L.document(
DocumentAttr(
size="a4",
size="A4",
meta=DocumentMeta(title="Test", author="Me"),
tokens=DocumentTokens(colors={"primary": "#000"}),
),
)
d = doc.to_dict()
assert d["attrs"]["size"] == "a4"
assert d["attrs"]["size"] == "A4"
assert d["attrs"]["meta"] == {"title": "Test", "author": "Me"}
assert d["attrs"]["tokens"] == {"colors": {"primary": "#000"}}

Expand Down
12 changes: 6 additions & 6 deletions tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def test_a_required_attribute_cannot_be_left_out():
@pytest.mark.parametrize("build", [
pytest.param(lambda: ImgAttr("logo", "40pt"), id="ImgAttr"), # type: ignore[call-arg]
pytest.param(lambda: TextAttr("12pt"), id="TextAttr"), # type: ignore[call-arg]
pytest.param(lambda: SectionAttr("a4"), id="SectionAttr"), # type: ignore[call-arg]
pytest.param(lambda: DocumentAttr("letter"), id="DocumentAttr"), # type: ignore[call-arg]
pytest.param(lambda: SectionAttr("A4"), id="SectionAttr"), # type: ignore[call-arg]
pytest.param(lambda: DocumentAttr("Letter"), id="DocumentAttr"), # type: ignore[call-arg]
pytest.param(lambda: DocumentMeta("Report"), id="DocumentMeta"), # type: ignore[call-arg]
pytest.param(lambda: DocumentOutput("aes-256"), id="DocumentOutput"), # type: ignore[call-arg]
pytest.param(lambda: DocumentTokens({"primary": "#336699"}), id="DocumentTokens"), # type: ignore[call-arg]
Expand Down Expand Up @@ -225,7 +225,7 @@ def test_a_transform_is_a_string_a_layer_accepts():
# ── Rendering ──────────────────────────────────────────────────────────────────

def _built_document():
return L.document(DocumentAttr(size="a4"), [
return L.document(DocumentAttr(size="A4"), [
L.section(NoAttr, [
L.layout(NoAttr, [
L.column(ColumnAttr(gap="12pt"), [
Expand Down Expand Up @@ -368,7 +368,7 @@ def build(columns=None):
def test_a_bulk_table_renders_from_data_as_the_table_without_bulk_and_one_built_with_l_which_has_no_data_is_rejected():
def xml(bulk):
return (
'<lpdf version="1"><document size="a4"><section><layout margin="36pt">'
'<lpdf version="1"><document size="A4"><section><layout margin="36pt">'
f'<table cols="1fr 2fr"{bulk}><thead><td><text bold="true">Date</text></td><td><text bold="true">Amount</text></td></thead>'
'<tr data-source="entries"><td><text data-value="date">-</text></td><td><text data-value="amount">-</text></td></tr></table>'
'<region pin="bottom"><text align="right">Page {page} of {pages}</text></region></layout></section></document></lpdf>'
Expand Down Expand Up @@ -902,7 +902,7 @@ def test_the_constants_of_the_closed_enumerations_are_the_words_the_schema_reads
assert [
PageSize.A0, PageSize.A1, PageSize.A2, PageSize.A3, PageSize.A4, PageSize.A5, PageSize.A6,
PageSize.B4, PageSize.B5, PageSize.LETTER, PageSize.LEGAL, PageSize.TABLOID,
] == ["a0", "a1", "a2", "a3", "a4", "a5", "a6", "b4", "b5", "letter", "legal", "tabloid"]
] == ["A0", "A1", "A2", "A3", "A4", "A5", "A6", "B4", "B5", "Letter", "Legal", "Tabloid"]
assert [TextAlign.LEFT, TextAlign.CENTER, TextAlign.RIGHT, TextAlign.JUSTIFY] == ["left", "center", "right", "justify"]
assert [Paginate.NO, Paginate.BREAK_BEFORE, Paginate.BREAK_AFTER, Paginate.KEEP_NEXT] == ["no", "break-before", "break-after", "keep-next"]
assert Anchor.TOP_LEFT == "top-left"
Expand All @@ -923,7 +923,7 @@ def test_a_document_built_with_the_constants_renders_as_the_xml_with_their_words
L.barcode(BarcodeAttr(type=BarcodeType.QR, data="x", ec=QrEcLevel.H, height="40pt")),
])]),
])
xml = '<lpdf version="1"><document size="a4" orientation="landscape"><section><layout><text align="center" paginate="keep-next">x</text><barcode type="qr" data="x" ec="H" height="40pt"/></layout></section></document></lpdf>'
xml = '<lpdf version="1"><document size="A4" orientation="landscape"><section><layout><text align="center" paginate="keep-next">x</text><barcode type="qr" data="x" ec="H" height="40pt"/></layout></section></document></lpdf>'
assert _render(xml) == _render(built)


Expand Down