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 src/main/java/io/lpdf/L.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* import java.util.List;
* import static io.lpdf.L.NoAttr;
*
* var doc = L.document(new DocumentAttr().size("a4"), List.of(
* var doc = L.document(new DocumentAttr().size("A4"), List.of(
* L.section(NoAttr, List.of(
* L.layout(new LayoutAttr().margin("40pt"), List.of(
* L.text(new TextAttr().font("Helvetica-Bold"), List.of("Hello"))
Expand Down
24 changes: 12 additions & 12 deletions src/main/java/io/lpdf/PageSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ public final class PageSize {
private PageSize() {
}

public static final String A0 = "a0";
public static final String A1 = "a1";
public static final String A2 = "a2";
public static final String A3 = "a3";
public static final String A4 = "a4";
public static final String A5 = "a5";
public static final String A6 = "a6";
public static final String B4 = "b4";
public static final String B5 = "b5";
public static final String LETTER = "letter";
public static final String LEGAL = "legal";
public static final String TABLOID = "tabloid";
public static final String A0 = "A0";
public static final String A1 = "A1";
public static final String A2 = "A2";
public static final String A3 = "A3";
public static final String A4 = "A4";
public static final String A5 = "A5";
public static final String A6 = "A6";
public static final String B4 = "B4";
public static final String B5 = "B5";
public static final String LETTER = "Letter";
public static final String LEGAL = "Legal";
public static final String TABLOID = "Tabloid";
}
2 changes: 1 addition & 1 deletion src/test/java/com/example/SketchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class SketchTest {
@Test
void the_invoice_of_the_design_compiles_and_renders() {
var doc = L.document(new DocumentAttr().size("a4"), List.of(
var doc = L.document(new DocumentAttr().size("A4"), List.of(
L.section(NoAttr, List.of(
L.layout(new LayoutAttr().margin("40pt"), List.of(
L.column(new ColumnAttr().gap("m"), List.of(
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/lpdf/CrossIndustryInvoiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class CrossIndustryInvoiceTest {
private static final String RECHNUNG_MAP = "<cross-industry-invoice-map prefix=\"rechnung\">"
+ "<value name=\"nummer\" path=\"rsm:ExchangedDocument/ram:ID\"/></cross-industry-invoice-map>";
private static final String 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\">"
+ "</assets><document size=\"A4\" font=\"body\"><section><layout margin=\"48pt\">"
+ "<text data-value=\"rechnung:nummer\">0000</text></layout></section></document></lpdf>";

private static byte[] bytes(Path path) {
Expand Down Expand Up @@ -168,7 +168,7 @@ private static PdfDocument documentInCode(Map<String, Object> invoiceData) {
sums.add(L.row(new RowAttr().gap("xs"), List.of(
L.text(total, List.of("Total")), L.text(total, List.of(totals.get("gross"))), L.text(total, List.of(totals.get("currency"))))));

return L.document(new DocumentAttr().size("a4").font("body")
return L.document(new DocumentAttr().size("A4").font("body")
.assets(new DocumentAssets().fonts(List.of(new FontAttr().name("body").src("../assets/fonts/SourceSans3-Regular.otf"))))
.meta(new DocumentMeta().title("Invoice").author("Northwind Paper SAS").lang("en")),
List.of(L.section(NoAttr, List.of(L.layout(new LayoutAttr().margin("48pt"), List.of(
Expand Down
8 changes: 4 additions & 4 deletions src/test/java/io/lpdf/KitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ void the_attributes_are_under_their_schema_names_and_types() {
assertEquals("graph", L.section(new SectionAttr().ruling("graph"), List.of()).attrs().get("ruling"));
assertEquals("l", L.text(new TextAttr().lineHeight("l"), List.of("A token")).attrs().get("line-height"));
assertEquals(1.5, L.text(new TextAttr().lineHeight(1.5), List.of("A factor")).attrs().get("line-height"));
assertEquals(Map.of("size", "a4", "orientation", "landscape"),
L.document(new DocumentAttr().size("a4").orientation("landscape"), List.of()).attrs());
assertEquals(Map.of("size", "A4", "orientation", "landscape"),
L.document(new DocumentAttr().size("A4").orientation("landscape"), List.of()).attrs());
assertEquals(Map.of("margin", "20pt 30pt"), L.layout(new LayoutAttr().margin("20pt 30pt"), List.of()).attrs());
assertEquals(Map.of("col-width", "120pt", "cols", 3), L.grid(new GridAttr().colWidth("120pt").cols(3), List.of()).attrs());
}
Expand All @@ -109,10 +109,10 @@ void a_container_is_a_node_of_its_element() {
void a_section_holds_its_layout_and_its_layers() {
var layout = L.layout(NoAttr, List.of(L.column(NoAttr, List.of())));
var layer = L.layer(NoAttr, List.of(L.rect(new RectAttr().width("10pt").height("10pt"))));
var section = L.section(new SectionAttr().size("a4"), List.of(layer, layout));
var section = L.section(new SectionAttr().size("A4"), List.of(layer, layout));

assertEquals("section", section.type());
assertEquals("a4", section.attrs().get("size"));
assertEquals("A4", section.attrs().get("size"));
assertEquals(List.of(layer, layout), section.nodes());
}

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/io/lpdf/SchemaTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void a_value_that_starts_with_a_digit_takes_the_last_word_of_its_enumerations_na

@Test
void the_constants_of_the_closed_enumerations_are_the_words_the_schema_reads() {
assertEquals(List.of("a0", "a1", "a2", "a3", "a4", "a5", "a6", "b4", "b5", "letter", "legal", "tabloid"),
assertEquals(List.of("A0", "A1", "A2", "A3", "A4", "A5", "A6", "B4", "B5", "Letter", "Legal", "Tabloid"),
List.of(PageSize.A0, PageSize.A1, PageSize.A2, PageSize.A3, PageSize.A4, PageSize.A5, PageSize.A6,
PageSize.B4, PageSize.B5, PageSize.LETTER, PageSize.LEGAL, PageSize.TABLOID));
assertEquals(List.of("left", "center", "right", "justify"),
Expand All @@ -164,7 +164,7 @@ void a_document_built_with_the_constants_renders_as_the_xml_with_their_words() {
L.section(NoAttr, List.of(L.layout(NoAttr, List.of(
L.text(new TextAttr().align(TextAlign.CENTER).paginate(Paginate.KEEP_NEXT), List.of("x")),
L.barcode(new BarcodeAttr().type(BarcodeType.QR).data("x").ec(QrEcLevel.H).height("40pt"))))))));
var 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>";
var 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>";
assertEquals(render(xml), render(built));
}

Expand Down Expand Up @@ -237,8 +237,8 @@ private static boolean has(Class<?> type, String setter) {

@Test
void a_layer_shape_is_drawn() {
var empty = L.document(new DocumentAttr().size("a4"), List.of(L.section(NoAttr, List.of(L.layer(NoAttr, List.of())))));
var drawn = L.document(new DocumentAttr().size("a4"), List.of(L.section(NoAttr, List.of(L.layer(NoAttr, List.of(
var empty = L.document(new DocumentAttr().size("A4"), List.of(L.section(NoAttr, List.of(L.layer(NoAttr, List.of())))));
var drawn = L.document(new DocumentAttr().size("A4"), List.of(L.section(NoAttr, List.of(L.layer(NoAttr, List.of(
L.rect(new RectAttr().x("50pt").y("50pt").width("200pt").height("100pt").fill("#ff0000"))))))));

assertNotEquals(render(empty), render(drawn));
Expand Down Expand Up @@ -273,7 +273,7 @@ void a_section_with_two_layouts_is_rejected() {

@Test
void a_text_at_a_circle_and_the_margin_of_the_layout_are_written_as_their_xml() {
Function<String, PdfDocument> circleAt = x -> L.document(new DocumentAttr().size("a4"), List.of(L.section(NoAttr,
Function<String, PdfDocument> circleAt = x -> L.document(new DocumentAttr().size("A4"), List.of(L.section(NoAttr,
List.of(L.layer(NoAttr, List.of(L.circle(new CircleAttr().x(x).y("20pt").r("10pt").fill("#ff0000"))))))));
var textAt = L.toXml(L.document(NoAttr, List.of(L.section(NoAttr, List.of(L.layer(NoAttr, List.of(
L.textAt(new TextAtAttr().x("10pt").y("20pt").maxLines(2).width("80pt"), List.of("Page {page} of {pages}")))))))));
Expand All @@ -299,7 +299,7 @@ void a_text_that_captures_and_one_that_shows_a_capture_are_written_under_the_sch

@Test
void a_built_document_renders_the_same_as_its_xml() {
var built = L.document(new DocumentAttr().size("a4"), List.of(L.section(NoAttr, List.of(
var built = L.document(new DocumentAttr().size("A4"), List.of(L.section(NoAttr, List.of(
L.layout(NoAttr, List.of(L.column(new ColumnAttr().gap("12pt"), List.of(
L.text(new TextAttr().align("right").bold(true), List.of("Title")),
L.text(NoAttr, List.of("Body ", L.span(new SpanAttr().bold(true), List.of("bold")), " text")),
Expand Down Expand Up @@ -425,7 +425,7 @@ record Entries(List<Entry> entries) {

@Test
void a_bulk_table_renders_from_data_as_the_table_without_bulk_and_one_built_with_l_which_has_no_data_is_rejected() {
Function<String, String> xml = bulk -> "<lpdf version=\"1\"><document size=\"a4\"><section><layout margin=\"36pt\">"
Function<String, String> xml = bulk -> "<lpdf version=\"1\"><document size=\"A4\"><section><layout margin=\"36pt\">"
+ "<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 "
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/io/lpdf/TextContentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void attributes_are_read_when_the_builder_is_called() {

@Test
void a_text_of_strings_and_a_span_renders_as_a_tree_and_as_its_xml() {
var doc = L.document(new DocumentAttr().size("a4"), List.of(
var doc = L.document(new DocumentAttr().size("A4"), List.of(
L.section(NoAttr, List.of(
L.layout(NoAttr, List.of(
L.text(new TextAttr().fontSize("14pt"),
Expand Down