From 81413ff1dae20358b54342fb41886352d9329d49 Mon Sep 17 00:00:00 2001 From: Tim81 Date: Sat, 12 Sep 2026 11:41:18 +0200 Subject: [PATCH 1/3] docs(layout): say what each public member refuses, and what not to pass 2.3.2 is the release that created these boundaries and documented almost none of them. Layout has 340 public members and one file carrying any tag. That matters more than the count suggests, because the refusals are raised from Save rather than from the property the caller set: assign a non-finite font size and the exception arrives from a call you never made, while the member you did set says nothing. Twenty-one members now carry the pattern TextStyle.FontSize already used. A bold sentence names what is refused, which call throws it and why. A following paragraph begins "Do not pass" for input accepted today, says what it does now, and says a later major will reject it. Covered: the table cell's two spans and its padding, the table border width, the image width and height, the separator line width, the pie chart's slices, diameter, start angle, stroke width and alignment, the heading level, the list indent and nesting depth, the running band's template, height and alignment, and the document margins. Three sentences I wrote did not survive checking them against the code, and are in as measured rather than as assumed: The pie chart does not skip a zero-width stroke. It strokes on StrokeColor being set, not on StrokeWidth being non-zero, so a zero width still emits 0 w and asks the device for its thinnest line. A table's grid cannot be suppressed at all. BorderColor is not nullable and every cell is stroked unconditionally, so the nearest thing to a gridless table is a border colour matching the page. A non-finite document margin is refused only when it is positive infinity. NaN and negative infinity slip past the margin check, because a comparison against them is false, and surface as "an element is too tall to fit" and as the page-continuation cap. Measured one value at a time, because all three take different branches. Both wrong-cause messages are the defect #481 corrected for other inputs; filed as #502 rather than fixed here, since routing margins through LayoutValidation changes behaviour. The rule itself goes into CLAUDE.md, so a public member's boundary is written in the same commit as the member instead of swept up at a release. Refs #502 --- CHANGELOG.md | 27 +++++++++++++ src/VellumPdf.Layout/Document.cs | 21 ++++++++++ src/VellumPdf.Layout/Elements/Heading.cs | 11 +++++ src/VellumPdf.Layout/Elements/LayoutImage.cs | 31 ++++++++++++++ .../Elements/LineSeparator.cs | 10 +++++ src/VellumPdf.Layout/Elements/ListElement.cs | 8 ++++ src/VellumPdf.Layout/Elements/ListItem.cs | 9 +++++ src/VellumPdf.Layout/Elements/PieChart.cs | 40 +++++++++++++++++++ src/VellumPdf.Layout/Elements/RunningBand.cs | 29 ++++++++++++++ src/VellumPdf.Layout/Elements/Table/Cell.cs | 32 +++++++++++++++ .../Elements/Table/TableElement.cs | 9 +++++ 11 files changed, 227 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c377c1d..f140f7f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1012,6 +1012,33 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Documentation +- **The public members that refuse input now say so, and say what not to pass.** 2.3.2 is the + release that created these boundaries, and they were documented almost nowhere: Layout has 340 + public members and, before this, one file carrying any `` tag. The refusals are + raised from `Save` rather than from the property the caller set, so a programmer who assigns a + bad value gets an exception from a call they never made while the member they did set says + nothing about it. + + Twenty-one members now carry the pattern already used on the text style's font size: a bold + sentence naming what is refused, which call throws it and why, then a separate paragraph + beginning "Do not pass" for input that is accepted today, what it does now, and that a later + major will reject it. That covers the table cell's spans and padding, the table's border width, + the image's width and height, the separator's line width, the pie chart's slices, diameter, + start angle, stroke width and alignment, the heading level, the list indent and nesting depth, + the running band's template, height and alignment, and the document margins. + + Writing them turned up three claims of mine that the code did not support, each corrected + against the code rather than shipped: the pie chart does not skip a zero-width stroke, it + strokes on the stroke colour being set and emits `0 w`; a table's grid cannot be suppressed at + all, since the border colour is not nullable and every cell is stroked unconditionally; and a + non-finite document margin is refused only when it is positive infinity. `NaN` and negative + infinity slip past the margin check, because a comparison against them is false, and surface as + a message about an element being too tall or about the page-continuation cap. That is the same + wrong-cause defect #481 corrected elsewhere and is filed as #502. + + The rule is written into the contributor guidance rather than left to a release: a public + member's boundary is documented in the same commit as the member. + - **Where the conformance rules knowingly disagree with veraPDF is written down (#418, #419).** `docs/conformance-divergences.md` records each case with what the standard requires, what an independent second reading found, what veraPDF does, which one this library follows, and whether a diff --git a/src/VellumPdf.Layout/Document.cs b/src/VellumPdf.Layout/Document.cs index e41669b7..6ad5b28e 100644 --- a/src/VellumPdf.Layout/Document.cs +++ b/src/VellumPdf.Layout/Document.cs @@ -102,6 +102,27 @@ public bool UseObjectStreams } /// Page margins applied to the content area. Defaults to 72 points (1 inch) on all sides. + /// + /// Margins that meet or exceed the page are refused. Saving throws + /// naming which axis and both figures, because the content + /// box would have no positive size and no element could be placed in it. The header and + /// footer count toward this: their heights come off the same box, so margins that fit on + /// their own can still leave nothing once a running band is set. + /// Do not pass a negative inset. It is not refused: the document saves, and the + /// content is placed outside the page's own boundaries where a reader clips it. Measured on a + /// one-paragraph document with every inset at -72, the file is written with no invalid token + /// in it, so nothing downstream reports the loss either. A later major version will reject + /// it. + /// Do not pass a non-finite inset. None of the three is refused by a message + /// naming the margin, and each fails differently, so none of them can be caught the way a + /// caller would expect. Measured on the same document: positive infinity does reach the + /// margin check and throws naming it; NaN slips past + /// the check, because a comparison against it is false, and surfaces as an + /// saying an element is too tall to fit, which is + /// not what happened; negative infinity slips past for the same reason and surfaces as the + /// page-continuation cap instead. Both wrong-cause messages are the defect #481 corrected + /// elsewhere, still outstanding here. + /// public EdgeInsets Margins { get; set; } = new EdgeInsets(72); // 1 inch /// diff --git a/src/VellumPdf.Layout/Elements/Heading.cs b/src/VellumPdf.Layout/Elements/Heading.cs index 8cb968ee..adddd7d7 100644 --- a/src/VellumPdf.Layout/Elements/Heading.cs +++ b/src/VellumPdf.Layout/Elements/Heading.cs @@ -18,6 +18,17 @@ public sealed class Heading public TextStyle Style { get; } /// Outline nesting level: 0 = top-level, 1 = sub-heading, etc. + /// + /// Zero-based: level 0 is tagged H1, level 4 is H5, and every level at or + /// above 5 is tagged H6, because that is the deepest heading type PDF defines. + /// Do not pass a negative level. It is not refused, and it does not clamp the + /// way a reader would expect: the mapping's catch-all sends it to H6, the deepest + /// type, where a caller means the shallowest. The raw value also reaches the outline + /// builder, so the bookmark tree nests on it. A later major version will reject it. + /// Do not rely on a very large level for depth. Everything from 5 upward is the + /// same H6 tag, so assistive technology cannot tell level 5 from level 500, while the + /// outline still nests on the number given. + /// public int Level { get; init; } /// diff --git a/src/VellumPdf.Layout/Elements/LayoutImage.cs b/src/VellumPdf.Layout/Elements/LayoutImage.cs index 205d2184..517f1fc0 100644 --- a/src/VellumPdf.Layout/Elements/LayoutImage.cs +++ b/src/VellumPdf.Layout/Elements/LayoutImage.cs @@ -29,6 +29,25 @@ public sealed class LayoutImage /// horizontally, which is a side effect of the transformation matrix rather than a supported /// way to flip an image. A later major version will reject it. /// + /// + /// null fits the image to the width available, which is the usual case. + /// + /// Zero is refused, and so is anything under 5e-6 in magnitude. + /// throws + /// naming the width. The check is on the magnitude + /// rather than on equality with zero because the canvas writes coordinates to five decimals, + /// so a width of 4e-6 is written as the token 0 and the image's transformation matrix + /// has no inverse either way. Measured at the boundary: 5e-6 writes 0.00001, 4.9e-6 + /// writes 0. + /// A non-finite width is refused by the same exception, because the number + /// would reach the content stream as a token no reader can parse. + /// Do not pass a negative width. It is not refused and it is not an error in + /// the format: it writes a valid matrix that mirrors the image horizontally, which #472 left + /// in place deliberately. Use it only if that is what is wanted; a later major version will + /// require it to be stated some other way. + /// A width wider than the content box is clamped to the box, so the image drawn is + /// narrower than the number set here and nothing reports the difference. + /// public double? Width { get; init; } // null = fit to available width /// @@ -44,6 +63,18 @@ public sealed class LayoutImage /// numbers. Do not pass a negative height; it is not refused today and flips the image /// vertically as a side effect. /// + /// + /// null derives the height from and the image's own aspect ratio, + /// which is the usual case. + /// + /// Zero, anything under 5e-6 in magnitude, and any non-finite value are refused, for + /// the reasons given on : a zero written into the transformation matrix + /// leaves it with no inverse, and a non-finite value is not a PDF number. + /// Do not pass a negative height unless a vertical mirror is what is wanted. + /// It is accepted and writes a valid matrix that flips the image. + /// Setting both this and overrides the aspect ratio rather than + /// fitting inside the pair, so the image is distorted if they disagree with it. + /// public double? Height { get; init; } // null = maintain aspect ratio /// Horizontal alignment of the image within the available width. diff --git a/src/VellumPdf.Layout/Elements/LineSeparator.cs b/src/VellumPdf.Layout/Elements/LineSeparator.cs index 2f43c711..c6797fab 100644 --- a/src/VellumPdf.Layout/Elements/LineSeparator.cs +++ b/src/VellumPdf.Layout/Elements/LineSeparator.cs @@ -9,6 +9,16 @@ namespace VellumPdf.Layout.Elements; public sealed class LineSeparator { /// Stroke width of the rule in points. + /// + /// A non-finite width is refused. + /// throws naming the width, because the number would + /// reach the content stream as a token no reader can parse. + /// Do not use zero to hide the rule. Zero is accepted and is not a no-op: it + /// asks the device for the thinnest line it can draw, which is one pixel at any zoom and so + /// grows heavier as the page is scaled down. To omit the rule, omit the element. + /// Do not pass a negative width. It is not refused today and its effect is the + /// renderer's, not the format's. A later major version will reject it. + /// public double LineWidth { get; init; } = 1; /// Stroke color of the rule. diff --git a/src/VellumPdf.Layout/Elements/ListElement.cs b/src/VellumPdf.Layout/Elements/ListElement.cs index 5ac63b62..c9881220 100644 --- a/src/VellumPdf.Layout/Elements/ListElement.cs +++ b/src/VellumPdf.Layout/Elements/ListElement.cs @@ -36,6 +36,14 @@ public sealed class ListElement public IReadOnlyList Items => _items; /// Points of indent for each list level. + /// + /// Do not set an indent at or beyond the content width. It is not refused. The marker + /// is drawn and the item text is discarded, so the list renders as a column of bullets with + /// no content, and nothing reports the loss (#476). + /// Do not assume the marker fits the indent. A marker wider than the indent + /// overprints the item text rather than pushing it along; roman numerals reach that at 38 + /// items with the default of 20 points. + /// public double Indent { get; init; } = 20; /// Outer margins applied around the whole list block. diff --git a/src/VellumPdf.Layout/Elements/ListItem.cs b/src/VellumPdf.Layout/Elements/ListItem.cs index 5773b1fd..8f0e9ae4 100644 --- a/src/VellumPdf.Layout/Elements/ListItem.cs +++ b/src/VellumPdf.Layout/Elements/ListItem.cs @@ -25,6 +25,15 @@ public sealed class ListItem public string? Language { get; init; } /// The nested child items, or null if this item has no children. + /// + /// One level of nesting, and only one. A child's own + /// is read by nothing: a grandchild is not measured, not drawn, and + /// not reported. Its text is simply absent from the document. Scope of that claim: the + /// renderer reads item.Children and takes each child's style, marker and content, and + /// never reads child.Children. + /// So do not build a tree deeper than two levels and expect the whole of it to + /// appear. Flatten it, or compose separate lists, until arbitrary nesting lands (#479). + /// public IReadOnlyList? Children => _children; /// Creates a list item with the given text and optional style. diff --git a/src/VellumPdf.Layout/Elements/PieChart.cs b/src/VellumPdf.Layout/Elements/PieChart.cs index 75bd3866..a04e4cd7 100644 --- a/src/VellumPdf.Layout/Elements/PieChart.cs +++ b/src/VellumPdf.Layout/Elements/PieChart.cs @@ -26,6 +26,18 @@ namespace VellumPdf.Layout.Elements; public sealed class PieChart { /// The slices, drawn in order. The sum of their values must be positive. + /// + /// An empty list is refused, and so is a list whose values sum to zero or less. + /// Laying the chart out throws with + /// ParamName of Slices: there is no angle to give any slice, so there is + /// nothing to draw rather than something small. + /// A slice value that is negative or not finite is refused by the same + /// exception, because a negative sweep would paint over its neighbours and a non-finite one + /// has no angle at all. + /// Do not rely on a zero value being visible. A zero is accepted and + /// contributes no angle, so the slice is absent from the chart while remaining in this list; + /// nothing reports that it was dropped. + /// public IReadOnlyList Slices { get; init; } = []; /// @@ -33,6 +45,13 @@ public sealed class PieChart /// layout time, the chart is placed at that width instead, so this is an upper bound on the /// drawn size rather than a guaranteed one. /// + /// + /// Zero, a negative value and a non-finite value are all refused. Laying the chart + /// out throws naming Diameter. + /// Do not size this against the page. A diameter wider than the content box is + /// accepted and clamped to the area the layout pass was handed, so the chart drawn is + /// smaller than the number set here and nothing reports the difference. + /// public double Diameter { get; init; } = 200; /// Margins around the chart. Defaults to 6 points on all sides. @@ -45,9 +64,24 @@ public sealed class PieChart public ColorRgb? StrokeColor { get; init; } /// Width of the separator stroke in points. Defaults to 0.5. + /// + /// A negative width and a non-finite width are both refused. Laying the chart out + /// throws naming StrokeWidth. + /// Do not use zero to remove the separators. Zero is accepted, but the stroke + /// is skipped on being unset, not on this being zero, so a zero + /// width with a stroke colour still strokes: it emits 0 w, which asks the device for + /// the thinnest line it can draw, and that grows heavier as the page is scaled down. Leave + /// unset instead. + /// public double StrokeWidth { get; init; } = 0.5; /// Horizontal placement of the chart within the content area. Defaults to centre. + /// + /// Do not pass . It is not refused and it is + /// not honoured: it falls through to left alignment. This is worse here than elsewhere + /// because the default is , so asking for justify + /// silently loses the centring the chart had. + /// public HorizontalAlignment Alignment { get; init; } = HorizontalAlignment.Center; /// @@ -55,6 +89,12 @@ public sealed class PieChart /// from the +X axis in PDF space (Y-up). The default π/2 starts at the top /// (12 o'clock). /// + /// + /// A non-finite angle is refused. Laying the chart out throws + /// naming StartAngle. + /// Radians, not degrees, and no range is imposed: a value outside 0 to 2π is accepted + /// and wraps, so there is no need to normalise one. The default of π/2 starts at the top. + /// public double StartAngle { get; init; } = Math.PI / 2; /// diff --git a/src/VellumPdf.Layout/Elements/RunningBand.cs b/src/VellumPdf.Layout/Elements/RunningBand.cs index 7bec4997..db41518d 100644 --- a/src/VellumPdf.Layout/Elements/RunningBand.cs +++ b/src/VellumPdf.Layout/Elements/RunningBand.cs @@ -13,18 +13,47 @@ namespace VellumPdf.Layout.Elements; public sealed class RunningBand { /// Text template — may contain {page} and/or {pages}. + /// + /// A template too wide for the content box is truncated, not refused. Before #365 it + /// was drawn off the page at a negative coordinate with every glyph still written into the + /// content stream, so the header or footer was invisible in every reader while its bytes + /// were still paid for. It is now cut to fit, and the cut is reported through + /// Document.BandTruncations and DocumentRenderer.BandTruncations. + /// The cut bounds the advance width, not the ink: side bearings and italic overhang + /// can still paint a little past it, because nothing in this package sets a clip path. + /// Do not rely on truncation for a template whose glyphs measure zero. Control + /// characters, the five undefined WinAnsi codes, and both symbolic standard-14 faces all + /// measure zero width, so any length of them "fits" and is drawn in full. + /// One report per band per render, naming the page that lost the most rather than the + /// first page cut, because a {page} or {pages} token lengthens the resolved + /// text as the number gains digits. + /// public string Template { get; } /// The text style of the band. public TextStyle Style { get; } /// Horizontal alignment of the band text. + /// + /// Do not pass . It is not refused and not + /// honoured: it falls through to left alignment. A single-line band has nothing to justify + /// against, so there is no meaning to give it. + /// public HorizontalAlignment Alignment { get; } /// /// Reserved height in points. Defaults to Style.EffectiveLeading + 4. /// Caller may override for tighter/looser bands. /// + /// + /// This reserves space; it does not scale the text. The band's own + /// decides how large the glyphs are, so a height smaller + /// than the text needs lets the band overlap the content rather than shrinking it. + /// Do not pass zero, a negative value or a non-finite value. None is refused. + /// The height comes off the page's content box, so zero or a negative one gives the band no + /// room while still drawing it, and a non-finite one propagates into the content area + /// calculation. A later major version will reject all three. + /// public double? Height { get; init; } /// Creates a running band from a text template, with optional style and alignment (defaults to centered). diff --git a/src/VellumPdf.Layout/Elements/Table/Cell.cs b/src/VellumPdf.Layout/Elements/Table/Cell.cs index d2d58a8b..fab92ddf 100644 --- a/src/VellumPdf.Layout/Elements/Table/Cell.cs +++ b/src/VellumPdf.Layout/Elements/Table/Cell.cs @@ -21,6 +21,17 @@ public sealed class Cell /// throws naming the row and cell, because a span of /// zero can leave the grid with no columns at all and nothing to draw into. /// + /// + /// A span below one is refused. throws + /// naming the row and the cell. A cell has to cover + /// at least the column it sits in, and before this it either raised a message about the + /// element being too tall to fit, which it was not, or drew the rest of the table normally + /// while never reaching this cell at all (#481). + /// A span wider than the columns left in the row is accepted and clamped to them, so + /// the cell ends at the table's right edge rather than past it. + /// Do not use this to set the table's width. The column count comes from the + /// widest row, counting spans, so a span on any row can widen the whole table. + /// public int ColSpan { get; init; } = 1; /// @@ -35,12 +46,33 @@ public sealed class Cell /// later major version will reject it, so do not write code that depends on the current /// behaviour. /// + /// + /// Do not pass a span below one. Unlike it is not refused: zero + /// and negative values both behave as one. That is deliberate for now, because refusing them + /// would turn documents that render today into exceptions, and a later major version will + /// reject them instead. + /// A span reaching past the rows the page can draw is reduced to the rows actually + /// drawn, and the /RowSpan attribute written into the tagged structure follows the + /// reduced figure rather than the one set here, so a reader is never told about rows that + /// are not on the page (#493). + /// public int RowSpan { get; init; } = 1; /// Text style for the cell content; falls back to the table default when null. public TextStyle? Style { get; init; } /// Inner padding between the cell border and its content. + /// + /// A non-finite inset is refused. + /// throws naming the row and the cell, because the + /// number would reach the content stream as a token no reader can parse. + /// Do not pass a negative inset. It is not refused, and it does not clip: the + /// cell's text is placed outside the cell, over its neighbour or past the table edge. A + /// later major version will reject it. + /// Do not pass padding wider than the column. It is not refused either. The + /// content box collapses and the text is measured against a width at or below zero, which + /// produces a cell of markers and no content. + /// public EdgeInsets Padding { get; init; } = new EdgeInsets(4, 6, 4, 6); /// Optional background fill color for the cell. diff --git a/src/VellumPdf.Layout/Elements/Table/TableElement.cs b/src/VellumPdf.Layout/Elements/Table/TableElement.cs index bc1f9573..0230aca8 100644 --- a/src/VellumPdf.Layout/Elements/Table/TableElement.cs +++ b/src/VellumPdf.Layout/Elements/Table/TableElement.cs @@ -22,6 +22,15 @@ public sealed class TableElement public TextStyle? DefaultCellStyle { get; init; } /// Width of the table border lines, in points. + /// + /// A non-finite width is refused. + /// throws naming the table. + /// Do not use zero to hide the borders. Zero is accepted and asks the device + /// for its thinnest line rather than for nothing, so the grid is still drawn and grows + /// heavier as the page is scaled down. There is at present no way to draw a table without a + /// grid: every cell is stroked unconditionally, and is not + /// nullable, so the nearest available approximation is a border colour matching the page. + /// public double BorderWidth { get; init; } = 0.5; /// Color of the table border lines. From dd07aa2f14065ab245e1676cfdf339a499c5996d Mon Sep 17 00:00:00 2001 From: Tim81 Date: Sat, 12 Sep 2026 12:45:39 +0200 Subject: [PATCH 2/3] docs(layout): correct eight documentation claims the code refutes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A review round read every new sentence against the code. Eight were wrong, and three of those in ways a caller would have acted on. A positive-infinity image width is not refused. #472's over-wide clamp resolves it to the content box before validation sees it, so it renders as a full-width image. The property's pre-existing remarks said exactly that, correctly, and the block added last round contradicted them two lines below. That contradiction was invisible because four members ended up with two elements each. Two on one member compiles without a warning and renderers show one of the two, so which sentence a reader gets depends on their tool. The pre-existing blocks on all four were already right, so the added ones are gone and only what was genuinely missing is spliced into the originals. A marker wider than the list indent does not overprint the item text. The gutter is widened to the marker's own width, per item, which is the fix this same branch describes in its own changelog. The threshold figure was wrong too: the first roman marker to exceed a 20-point indent at the default style is item 17, not 38. Padding wider than its column does not produce "a cell of markers and no content", and a table cell has no markers at all. The inner width is clamped to one point on both the measure and the draw path, so the text wraps to one glyph per line and every line is placed at the left padding's offset. Measured with 400 points of padding in a 260-point column on a 300-point page: ten glyphs, ten lines, all at x = 420, off the page. A non-finite running-band height is refused, not accepted. All three values throw and no file is written, by three different exceptions, none of which names the band height. H6 is this library's deepest heading tag, not the format's. ISO 32000-2 Table 366 defines Hn for any unsigned integer from one upward, and NOTE 2 says outright that H7 may be used for a seventh-level heading. Two counts were wrong: the generated documentation has 340 entries of which 42 are types, so 298 members, not 340; and the sweep covers nineteen members, not twenty-one, since the two it was modelled on were already done. Finally, the rule itself was in the wrong file. CLAUDE.md is untracked and excluded, so it appears in no clone and in no diff, and CONTRIBUTING.md — which that file itself calls the human-facing guide — said nothing. The rule now lives there, including the two things this round learned: measure each non-finite value separately, and check the member does not already carry a block. The rule asks for an tag wherever a call can throw, and none of the nineteen had one. Thirteen members now do, up from one. Refs #502 --- CHANGELOG.md | 61 +++++++++++-------- CONTRIBUTING.md | 27 ++++++++ src/VellumPdf.Layout/Core/TextStyle.cs | 4 ++ src/VellumPdf.Layout/Document.cs | 6 ++ src/VellumPdf.Layout/Elements/Heading.cs | 4 +- src/VellumPdf.Layout/Elements/LayoutImage.cs | 45 +++++--------- .../Elements/LineSeparator.cs | 3 + src/VellumPdf.Layout/Elements/ListElement.cs | 9 ++- src/VellumPdf.Layout/Elements/PieChart.cs | 16 +++++ src/VellumPdf.Layout/Elements/RunningBand.cs | 14 +++-- src/VellumPdf.Layout/Elements/Table/Cell.cs | 37 +++++------ .../Elements/Table/TableElement.cs | 3 + 12 files changed, 144 insertions(+), 85 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f140f7f6..d9a8fecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1012,32 +1012,41 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Documentation -- **The public members that refuse input now say so, and say what not to pass.** 2.3.2 is the - release that created these boundaries, and they were documented almost nowhere: Layout has 340 - public members and, before this, one file carrying any `` tag. The refusals are - raised from `Save` rather than from the property the caller set, so a programmer who assigns a - bad value gets an exception from a call they never made while the member they did set says - nothing about it. - - Twenty-one members now carry the pattern already used on the text style's font size: a bold - sentence naming what is refused, which call throws it and why, then a separate paragraph - beginning "Do not pass" for input that is accepted today, what it does now, and that a later - major will reject it. That covers the table cell's spans and padding, the table's border width, - the image's width and height, the separator's line width, the pie chart's slices, diameter, - start angle, stroke width and alignment, the heading level, the list indent and nesting depth, - the running band's template, height and alignment, and the document margins. - - Writing them turned up three claims of mine that the code did not support, each corrected - against the code rather than shipped: the pie chart does not skip a zero-width stroke, it - strokes on the stroke colour being set and emits `0 w`; a table's grid cannot be suppressed at - all, since the border colour is not nullable and every cell is stroked unconditionally; and a - non-finite document margin is refused only when it is positive infinity. `NaN` and negative - infinity slip past the margin check, because a comparison against them is false, and surface as - a message about an element being too tall or about the page-continuation cap. That is the same - wrong-cause defect #481 corrected elsewhere and is filed as #502. - - The rule is written into the contributor guidance rather than left to a release: a public - member's boundary is documented in the same commit as the member. +- **The public members that refuse input now say so, and say what not to pass.** These + boundaries were created by the fixes already listed above and documented almost nowhere: of + Layout's 298 documented public members, exactly one carried an `` tag. That matters + because of where the refusals fire. They are raised from `Save`, not from the property the + caller set, so a programmer who assigns a bad value gets an exception from a call they never + made while the member they did set says nothing about it. + + Nineteen members gain a boundary paragraph and thirteen now carry an `` tag, up from + one. The pattern is the one on the text style's font size: a bold sentence naming what is + refused, which call throws it and why, then a paragraph beginning "Do not pass" for input that + is accepted today, what it does now, and which major version will reject it. Covered: the table + cell's spans and padding, the table border width, the image width and height, the separator line + width, the pie chart's slices, diameter, start angle, stroke width and alignment, the heading + level, the list indent and nesting depth, the running band's template, height and alignment, and + the document margins. + + Writing them turned up eight statements of mine the code did not support. The pie chart does not + skip a zero-width stroke: it strokes on the stroke colour being set, and emits `0 w`. A table's + grid cannot be suppressed at all, since the border colour is not nullable and every cell is + stroked unconditionally. A non-finite document margin is refused only when it is positive + infinity; `NaN` and negative infinity slip past the check, because a comparison against them is + false, and surface as a message about an element being too tall or about the page-continuation + cap, which is the wrong-cause defect #481 corrected elsewhere, filed as #502. A positive-infinity + image width is likewise not refused but clamped to the content box. A marker wider than the list + indent does not overprint the item text, because the gutter is widened per item; the first roman + marker to exceed the default indent is item 17, not 38. Padding wider than its column does not + collapse the cell to nothing: the inner width is clamped to one point, so the text wraps to one + glyph per line and every line lands outside the page. A non-finite band height is refused, by + three different exceptions, none of which names the band height. And `H6` is this library's + deepest heading tag, not the format's: ISO 32000-2 Table 366 defines `Hn` for any integer from + one upward and its NOTE 2 names `H7` explicitly. + + The rule is written into `CONTRIBUTING.md`, which ships, rather than only into the agent + guidance, which is untracked and reaches no clone: a public member's boundary is documented in + the same commit as the member. - **Where the conformance rules knowingly disagree with veraPDF is written down (#418, #419).** `docs/conformance-divergences.md` records each case with what the standard requires, what an diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index be683269..ba424f8b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -252,6 +252,33 @@ otherwise. Use the IDE code-fix (`RS0016` / `RS0017`) or edit the file manually. Do not add symbols to `PublicAPI.Shipped.txt` — that file is updated only at release time. +## Public XML documentation states the boundary + +Every public member documents where its boundary is and what a caller must not do, not only what +it is. Write it in the same commit as the member. + +The shape, copied from `TextStyle.FontSize` in `src/VellumPdf.Layout/Core/TextStyle.cs`: + +- `` says what the member is. +- An `` tag for every type a call can raise — **including when the throw lands in a + later call rather than this one**, which in the layout engine usually means `Document.Save`. + List each type separately; `NotSupportedException` does not derive from `InvalidDataException`, + and a caller who catches one and not the other has a crash waiting. +- `` opens with a bold sentence naming what is **refused**, which call throws it, and the + reason. Not just the fact. +- A following `` beginning "**Do not pass ...**" for input that is accepted today but should + not be relied on: what it does now, and which major version will reject it. + +Two rules about the writing itself, both learned the hard way: + +- **Measure each non-finite value separately.** `NaN`, positive infinity and negative infinity + take different branches, and a sentence about "a non-finite value" that was measured on one of + them is usually wrong about the other two. A positive-infinity image width, for instance, is + clamped and accepted, while `NaN` is refused. +- **Check the member does not already have a `` block.** Two `` elements on one + member compile without a warning, and renderers show one of the two, so a contradiction between + them is invisible until a reader hits it. + ## Branch and PR etiquette - **Target `main`.** All pull requests should be opened against the `main` diff --git a/src/VellumPdf.Layout/Core/TextStyle.cs b/src/VellumPdf.Layout/Core/TextStyle.cs index ee73ff42..00c3af64 100644 --- a/src/VellumPdf.Layout/Core/TextStyle.cs +++ b/src/VellumPdf.Layout/Core/TextStyle.cs @@ -40,6 +40,10 @@ public Standard14 Font /// zero shows nothing and a negative size inverts the glyphs. A later major version will reject /// both. /// + /// + /// Raised from a save rather than from this property, when the size is not finite. The + /// message names the element the style is attached to and the size itself. + /// public double FontSize { get; init; } = 12; /// diff --git a/src/VellumPdf.Layout/Document.cs b/src/VellumPdf.Layout/Document.cs index 6ad5b28e..cb9bcdfd 100644 --- a/src/VellumPdf.Layout/Document.cs +++ b/src/VellumPdf.Layout/Document.cs @@ -123,6 +123,12 @@ public bool UseObjectStreams /// page-continuation cap instead. Both wrong-cause messages are the defect #481 corrected /// elsewhere, still outstanding here. /// + /// + /// Raised from a save rather than from this property, when the margins on either axis meet + /// or exceed the page, or when they leave the content area no positive size once the header + /// and footer are taken off. Positive infinity reaches this check; NaN and negative + /// infinity do not, and surface as the unrelated messages described above. + /// public EdgeInsets Margins { get; set; } = new EdgeInsets(72); // 1 inch /// diff --git a/src/VellumPdf.Layout/Elements/Heading.cs b/src/VellumPdf.Layout/Elements/Heading.cs index adddd7d7..e58d61c0 100644 --- a/src/VellumPdf.Layout/Elements/Heading.cs +++ b/src/VellumPdf.Layout/Elements/Heading.cs @@ -20,7 +20,9 @@ public sealed class Heading /// Outline nesting level: 0 = top-level, 1 = sub-heading, etc. /// /// Zero-based: level 0 is tagged H1, level 4 is H5, and every level at or - /// above 5 is tagged H6, because that is the deepest heading type PDF defines. + /// above 5 is tagged H6. That ceiling is this library's, not the format's: ISO 32000-2 + /// Table 366 defines Hn for any unsigned integer from 1 upward, and its NOTE 2 says + /// outright that H7 may be used for a seventh-level heading. /// Do not pass a negative level. It is not refused, and it does not clamp the /// way a reader would expect: the mapping's catch-all sends it to H6, the deepest /// type, where a caller means the shallowest. The raw value also reaches the outline diff --git a/src/VellumPdf.Layout/Elements/LayoutImage.cs b/src/VellumPdf.Layout/Elements/LayoutImage.cs index 517f1fc0..2f1adbd2 100644 --- a/src/VellumPdf.Layout/Elements/LayoutImage.cs +++ b/src/VellumPdf.Layout/Elements/LayoutImage.cs @@ -28,26 +28,16 @@ public sealed class LayoutImage /// Do not pass a negative width. It is not refused today and mirrors the image /// horizontally, which is a side effect of the transformation matrix rather than a supported /// way to flip an image. A later major version will reject it. + /// The zero check is on the written token, not the value. + /// PdfCanvas formats coordinates to five decimals, so anything under 5e-6 in magnitude + /// is written as 0 and the matrix is singular whatever the value held. Measured at the + /// boundary: 5e-6 writes 0.00001, 4.9e-6 writes 0. At that boundary the message + /// names the height, not the width, because the height is derived from the width and + /// collapses first. /// - /// - /// null fits the image to the width available, which is the usual case. - /// - /// Zero is refused, and so is anything under 5e-6 in magnitude. - /// throws - /// naming the width. The check is on the magnitude - /// rather than on equality with zero because the canvas writes coordinates to five decimals, - /// so a width of 4e-6 is written as the token 0 and the image's transformation matrix - /// has no inverse either way. Measured at the boundary: 5e-6 writes 0.00001, 4.9e-6 - /// writes 0. - /// A non-finite width is refused by the same exception, because the number - /// would reach the content stream as a token no reader can parse. - /// Do not pass a negative width. It is not refused and it is not an error in - /// the format: it writes a valid matrix that mirrors the image horizontally, which #472 left - /// in place deliberately. Use it only if that is what is wanted; a later major version will - /// require it to be stated some other way. - /// A width wider than the content box is clamped to the box, so the image drawn is - /// narrower than the number set here and nothing reports the difference. - /// + /// + /// Raised from rather than from this property, for zero, for a magnitude under 5e-6, and for NaN or negative infinity. Positive infinity is clamped to the content box instead and does not throw. + /// public double? Width { get; init; } // null = fit to available width /// @@ -62,19 +52,14 @@ public sealed class LayoutImage /// : the emitted transformation matrix is either singular or not made of PDF /// numbers. Do not pass a negative height; it is not refused today and flips the image /// vertically as a side effect. - /// - /// - /// null derives the height from and the image's own aspect ratio, - /// which is the usual case. - /// - /// Zero, anything under 5e-6 in magnitude, and any non-finite value are refused, for - /// the reasons given on : a zero written into the transformation matrix - /// leaves it with no inverse, and a non-finite value is not a PDF number. - /// Do not pass a negative height unless a vertical mirror is what is wanted. - /// It is accepted and writes a valid matrix that flips the image. + /// Anything under 5e-6 in magnitude is refused too, for the reason given on + /// : the canvas writes it as the token 0. /// Setting both this and overrides the aspect ratio rather than - /// fitting inside the pair, so the image is distorted if they disagree with it. + /// fitting inside the pair, so the image is distorted if the two disagree with it. /// + /// + /// Raised from rather than from this property, for zero, for a magnitude under 5e-6, and for any non-finite value. + /// public double? Height { get; init; } // null = maintain aspect ratio /// Horizontal alignment of the image within the available width. diff --git a/src/VellumPdf.Layout/Elements/LineSeparator.cs b/src/VellumPdf.Layout/Elements/LineSeparator.cs index c6797fab..631a46aa 100644 --- a/src/VellumPdf.Layout/Elements/LineSeparator.cs +++ b/src/VellumPdf.Layout/Elements/LineSeparator.cs @@ -19,6 +19,9 @@ public sealed class LineSeparator /// Do not pass a negative width. It is not refused today and its effect is the /// renderer's, not the format's. A later major version will reject it. /// + /// + /// Raised from rather than from this property, when the width is not finite. The message names the separator. + /// public double LineWidth { get; init; } = 1; /// Stroke color of the rule. diff --git a/src/VellumPdf.Layout/Elements/ListElement.cs b/src/VellumPdf.Layout/Elements/ListElement.cs index c9881220..96abf477 100644 --- a/src/VellumPdf.Layout/Elements/ListElement.cs +++ b/src/VellumPdf.Layout/Elements/ListElement.cs @@ -40,9 +40,12 @@ public sealed class ListElement /// Do not set an indent at or beyond the content width. It is not refused. The marker /// is drawn and the item text is discarded, so the list renders as a column of bullets with /// no content, and nothing reports the loss (#476). - /// Do not assume the marker fits the indent. A marker wider than the indent - /// overprints the item text rather than pushing it along; roman numerals reach that at 38 - /// items with the default of 20 points. + /// A marker wider than the indent does not overprint the item text: the + /// gutter is widened to the marker's own width, per item. With roman numerals at the default + /// style the first marker to exceed a 20-point indent is item 17, and from there each item's + /// text starts further right than its neighbours'. The one case that still overprints is the + /// narrow fallback, where widening the gutter would leave less room than the longest word in + /// the item, and the gutter reverts to the indent. /// public double Indent { get; init; } = 20; diff --git a/src/VellumPdf.Layout/Elements/PieChart.cs b/src/VellumPdf.Layout/Elements/PieChart.cs index a04e4cd7..6b4cc090 100644 --- a/src/VellumPdf.Layout/Elements/PieChart.cs +++ b/src/VellumPdf.Layout/Elements/PieChart.cs @@ -38,6 +38,10 @@ public sealed class PieChart /// contributes no angle, so the slice is absent from the chart while remaining in this list; /// nothing reports that it was dropped. /// + /// + /// Raised while the chart is laid out, which happens inside , + /// when the list is empty, when a value is negative or not finite, or when the values sum to zero or less. ParamName is this property's name. + /// public IReadOnlyList Slices { get; init; } = []; /// @@ -52,6 +56,10 @@ public sealed class PieChart /// accepted and clamped to the area the layout pass was handed, so the chart drawn is /// smaller than the number set here and nothing reports the difference. /// + /// + /// Raised while the chart is laid out, which happens inside , + /// when the diameter is zero, negative or not finite. ParamName is this property's name. + /// public double Diameter { get; init; } = 200; /// Margins around the chart. Defaults to 6 points on all sides. @@ -73,6 +81,10 @@ public sealed class PieChart /// the thinnest line it can draw, and that grows heavier as the page is scaled down. Leave /// unset instead. /// + /// + /// Raised while the chart is laid out, which happens inside , + /// when the width is negative or not finite. ParamName is this property's name. + /// public double StrokeWidth { get; init; } = 0.5; /// Horizontal placement of the chart within the content area. Defaults to centre. @@ -95,6 +107,10 @@ public sealed class PieChart /// Radians, not degrees, and no range is imposed: a value outside 0 to 2π is accepted /// and wraps, so there is no need to normalise one. The default of π/2 starts at the top. /// + /// + /// Raised while the chart is laid out, which happens inside , + /// when the angle is not finite. ParamName is this property's name. + /// public double StartAngle { get; init; } = Math.PI / 2; /// diff --git a/src/VellumPdf.Layout/Elements/RunningBand.cs b/src/VellumPdf.Layout/Elements/RunningBand.cs index db41518d..ba4bc354 100644 --- a/src/VellumPdf.Layout/Elements/RunningBand.cs +++ b/src/VellumPdf.Layout/Elements/RunningBand.cs @@ -49,10 +49,16 @@ public sealed class RunningBand /// This reserves space; it does not scale the text. The band's own /// decides how large the glyphs are, so a height smaller /// than the text needs lets the band overlap the content rather than shrinking it. - /// Do not pass zero, a negative value or a non-finite value. None is refused. - /// The height comes off the page's content box, so zero or a negative one gives the band no - /// room while still drawing it, and a non-finite one propagates into the content area - /// calculation. A later major version will reject all three. + /// Zero and a negative value are not refused, and neither is useful: the + /// height comes off the page's content box, so both give the band no room while it is still + /// drawn, over the content. A later major version will reject them. + /// A non-finite value is refused, but by none of the messages you would expect. + /// All three throw from and none names the band + /// height. Measured, one value at a time: positive infinity gives + /// about the content area having no positive size; NaN + /// gives about an element being too tall to fit; + /// negative infinity gives the page-continuation cap. No file is written in any of the + /// three. /// public double? Height { get; init; } diff --git a/src/VellumPdf.Layout/Elements/Table/Cell.cs b/src/VellumPdf.Layout/Elements/Table/Cell.cs index fab92ddf..33214a2a 100644 --- a/src/VellumPdf.Layout/Elements/Table/Cell.cs +++ b/src/VellumPdf.Layout/Elements/Table/Cell.cs @@ -20,18 +20,13 @@ public sealed class Cell /// Zero or negative is refused. /// throws naming the row and cell, because a span of /// zero can leave the grid with no columns at all and nothing to draw into. + /// A span reaching past the columns left in its row is clamped to them, so the cell + /// ends at the table's right edge rather than beyond it. /// - /// - /// A span below one is refused. throws - /// naming the row and the cell. A cell has to cover - /// at least the column it sits in, and before this it either raised a message about the - /// element being too tall to fit, which it was not, or drew the rest of the table normally - /// while never reaching this cell at all (#481). - /// A span wider than the columns left in the row is accepted and clamped to them, so - /// the cell ends at the table's right edge rather than past it. - /// Do not use this to set the table's width. The column count comes from the - /// widest row, counting spans, so a span on any row can widen the whole table. - /// + /// + /// Raised from rather than from this property, when the + /// span is below one. The message names the row and the cell. + /// public int ColSpan { get; init; } = 1; /// @@ -45,13 +40,7 @@ public sealed class Cell /// as 1, which is an accident of how the draw loop tests the span rather than a guarantee. A /// later major version will reject it, so do not write code that depends on the current /// behaviour. - /// - /// - /// Do not pass a span below one. Unlike it is not refused: zero - /// and negative values both behave as one. That is deliberate for now, because refusing them - /// would turn documents that render today into exceptions, and a later major version will - /// reject them instead. - /// A span reaching past the rows the page can draw is reduced to the rows actually + /// A span reaching past the rows this page draws is reduced to the rows actually /// drawn, and the /RowSpan attribute written into the tagged structure follows the /// reduced figure rather than the one set here, so a reader is never told about rows that /// are not on the page (#493). @@ -69,10 +58,16 @@ public sealed class Cell /// Do not pass a negative inset. It is not refused, and it does not clip: the /// cell's text is placed outside the cell, over its neighbour or past the table edge. A /// later major version will reject it. - /// Do not pass padding wider than the column. It is not refused either. The - /// content box collapses and the text is measured against a width at or below zero, which - /// produces a cell of markers and no content. + /// Do not pass padding wider than the column. It is not refused, and what + /// happens is worse than a collapsed cell: the inner width is clamped to one point, so the + /// text wraps to one glyph per line and every line is placed at the left padding's own + /// offset, which is outside the column and usually outside the page. Measured with 400 points + /// of horizontal padding in a 260-point column on a 300-point page: ten glyphs, ten lines, + /// every one at x = 420. Nothing is dropped and nothing reports it. /// + /// + /// Raised from rather than from this property, when any inset is not finite. The message names the row and the cell. + /// public EdgeInsets Padding { get; init; } = new EdgeInsets(4, 6, 4, 6); /// Optional background fill color for the cell. diff --git a/src/VellumPdf.Layout/Elements/Table/TableElement.cs b/src/VellumPdf.Layout/Elements/Table/TableElement.cs index 0230aca8..5851a47b 100644 --- a/src/VellumPdf.Layout/Elements/Table/TableElement.cs +++ b/src/VellumPdf.Layout/Elements/Table/TableElement.cs @@ -31,6 +31,9 @@ public sealed class TableElement /// grid: every cell is stroked unconditionally, and is not /// nullable, so the nearest available approximation is a border colour matching the page. /// + /// + /// Raised from rather than from this property, when the width is not finite. The message names the table. + /// public double BorderWidth { get; init; } = 0.5; /// Color of the table border lines. From 616357005016158d6e58f0d2b125adb04a59a176 Mon Sep 17 00:00:00 2001 From: Tim81 Date: Sat, 12 Sep 2026 13:50:37 +0200 Subject: [PATCH 3/3] docs(layout): write the boundaries in the reference's voice, and fix three more Two things in one pass, both requested. The avoid-ai-writing audit over the 2,489 words of documentation added here found no vocabulary or hedging problems, and two structural ones. Thirty-two bold tags, nearly all of them a bold clause opening a paragraph that the next sentence then repeats, which is the inline-header pattern; and sixteen instances of a bold label terminated with a period where a person writes a colon or no label at all. The voice now follows the Swiss Ephemeris programmer's reference. Bold marks one operative word, a negation or an obligation, rather than a clause. A trap is marked "Attention:" and a fact about history "NOTE:", which is what the reference uses instead of emphasis. The reader is addressed directly, as someone with a job to do, which is how that document talks about anything a caller has to handle itself. Constraints come first in one short sentence, with the reason following as its own. Measured over the added prose: bold per thousand words 13 to 7, "Do not" labels 16 to 2, direct address 1 to 32, median sentence 14 words to 11. Not imitated: the reference's comma before "that", which is its author's German habit and in a .NET public API would read as a typo. Three claims corrected, each measured rather than reasoned about. The 5e-6 boundary names the width, not the height. ValidateImageExtent checks the width first, so a width under the boundary is always what the message names, whatever the source aspect ratio. The height is named only above the boundary, where a legal but small width collapses a non-square image's derived height. The last round had this backwards. The cell-padding figures disagreed with each other. EdgeInsets.Horizontal is Left plus Right, so "400 points of horizontal padding" puts the text at x = 220, not the 420 the same sentence reported. It is Left alone that decides where a line starts, and the figures now say which is which. A non-finite band height is refused by two exception types across three messages, not three types, and the NaN one does name the band height, as "NaNpt of running bands". Worse, "no file is written" is true of the content and false of the file: the string overloads open the target before the layout runs, so a failure leaves a zero-byte file where a 1,535-byte document was. Measured, and filed as #508. Also the three exception tags the sweep's own rule required and did not have, on RunningBand.Height, Cell.RowSpan and Document.Margins, the last of which listed ArgumentException while its own remarks described two InvalidOperationException routes past it. And the four save overloads and PageSize, which every caller touches and which had one-line summaries and no boundary at all: single use, the empty-document refusal, and the destructive truncation. Refs #508, #509, #510 --- src/VellumPdf.Layout/Core/TextStyle.cs | 25 ++-- src/VellumPdf.Layout/Document.cs | 120 +++++++++++++++--- src/VellumPdf.Layout/Elements/Heading.cs | 14 +- src/VellumPdf.Layout/Elements/LayoutImage.cs | 24 ++-- .../Elements/LineSeparator.cs | 17 +-- src/VellumPdf.Layout/Elements/ListElement.cs | 19 +-- src/VellumPdf.Layout/Elements/ListItem.cs | 14 +- src/VellumPdf.Layout/Elements/PieChart.cs | 61 ++++----- src/VellumPdf.Layout/Elements/RunningBand.cs | 71 +++++++---- src/VellumPdf.Layout/Elements/Table/Cell.cs | 47 ++++--- .../Elements/Table/TableElement.cs | 15 ++- 11 files changed, 268 insertions(+), 159 deletions(-) diff --git a/src/VellumPdf.Layout/Core/TextStyle.cs b/src/VellumPdf.Layout/Core/TextStyle.cs index 00c3af64..3b08c7a3 100644 --- a/src/VellumPdf.Layout/Core/TextStyle.cs +++ b/src/VellumPdf.Layout/Core/TextStyle.cs @@ -32,13 +32,14 @@ public Standard14 Font /// The font size in points. Defaults to 12. Must be a finite number. /// /// - /// A non-finite size is refused. throws - /// naming the size, because every height derived from - /// it is also non-finite and nothing can be measured or placed. - /// Do not pass zero or a negative size. Neither is refused today: both reach the - /// content stream as a font operator a reader accepts, so a document is produced, but a size of - /// zero shows nothing and a negative size inverts the glyphs. A later major version will reject - /// both. + /// A non-finite size is refused. throws + /// and names the size. Every height in a layout is + /// derived from the font size, so a non-finite size leaves nothing that can be measured or + /// placed. + /// Attention: a size of zero or less is not refused. It reaches the content + /// stream as a font operator that readers accept, so you still get a document. At zero the + /// text is invisible. Below zero the glyphs are inverted. If you do not want either, check the + /// value before you set it. A later major version will reject both. /// /// /// Raised from a save rather than from this property, when the size is not finite. The @@ -50,11 +51,11 @@ public Standard14 Font /// The line leading in points; 0 (the default) means auto, which is the font size times 1.2. /// /// - /// Any value at or below zero selects the automatic leading, so there is no way to ask for - /// lines that overlap exactly. - /// Do not pass a non-finite value. It is not refused today and does not reach the - /// content stream, so the page is emitted with the text placed as though the leading were - /// automatic. A later major version will reject it. + /// Any value at or below zero selects the automatic leading. There is therefore no way to + /// ask for lines that overlap exactly. + /// Attention: a non-finite value is not refused, and it does not reach the + /// content stream either. The page is emitted with the text placed as though you had asked + /// for automatic leading. A later major version will reject it. /// public double Leading { get; init; } = 0; // 0 = auto (font-size * 1.2) diff --git a/src/VellumPdf.Layout/Document.cs b/src/VellumPdf.Layout/Document.cs index cb9bcdfd..41452743 100644 --- a/src/VellumPdf.Layout/Document.cs +++ b/src/VellumPdf.Layout/Document.cs @@ -50,6 +50,18 @@ public sealed class Document : IDisposable public PdfDocumentInfo Info => _pdf.Info; /// The default page size used for newly created pages. + /// + /// Validated at save, not here. A width or height that is not a positive finite number is + /// refused with naming the axis and the value, and + /// a page narrower or shorter than is refused with + /// . + /// Attention: changing this after adding elements does not re-lay out what you already + /// added. The layout runs once, at the save, against whatever size is set then. + /// + /// + /// Raised from a save rather than from this property, when the width or height is zero, + /// negative or not finite. + /// public PdfRectangle PageSize { get => _pdf.DefaultPageSize; @@ -103,31 +115,33 @@ public bool UseObjectStreams /// Page margins applied to the content area. Defaults to 72 points (1 inch) on all sides. /// - /// Margins that meet or exceed the page are refused. Saving throws - /// naming which axis and both figures, because the content - /// box would have no positive size and no element could be placed in it. The header and - /// footer count toward this: their heights come off the same box, so margins that fit on - /// their own can still leave nothing once a running band is set. - /// Do not pass a negative inset. It is not refused: the document saves, and the - /// content is placed outside the page's own boundaries where a reader clips it. Measured on a - /// one-paragraph document with every inset at -72, the file is written with no invalid token - /// in it, so nothing downstream reports the loss either. A later major version will reject - /// it. - /// Do not pass a non-finite inset. None of the three is refused by a message - /// naming the margin, and each fails differently, so none of them can be caught the way a - /// caller would expect. Measured on the same document: positive infinity does reach the - /// margin check and throws naming it; NaN slips past - /// the check, because a comparison against it is false, and surfaces as an - /// saying an element is too tall to fit, which is - /// not what happened; negative infinity slips past for the same reason and surfaces as the - /// page-continuation cap instead. Both wrong-cause messages are the defect #481 corrected - /// elsewhere, still outstanding here. + /// Margins that meet or exceed the page are refused. Saving throws + /// and names the axis and both figures. The content box would + /// otherwise have no positive size, and no element could be placed in it. + /// The header and footer count toward this. Their heights come off the same box, so + /// margins that fit on their own can still leave nothing once you set a running band. + /// Attention: a negative inset is not refused. The document saves and the content is + /// placed outside the page's boundaries, where a reader clips it. On a one-paragraph document + /// with every inset at -72, the file is written with no invalid token in it, so nothing + /// downstream reports the loss either. A later major version will reject it. + /// A non-finite inset is refused in only one of its three forms, and each form fails + /// differently, so you cannot catch them together. Positive infinity reaches the margin check + /// and throws naming the margin. NaN slips past the + /// check, because a comparison against it is false, and surfaces as + /// saying an element is too tall to fit, which is not + /// what happened. Negative infinity slips past for the same reason and surfaces as the + /// page-continuation cap. Both wrong-cause messages are the defect #481 corrected elsewhere, + /// still outstanding here (#502). /// /// /// Raised from a save rather than from this property, when the margins on either axis meet /// or exceed the page, or when they leave the content area no positive size once the header - /// and footer are taken off. Positive infinity reaches this check; NaN and negative - /// infinity do not, and surface as the unrelated messages described above. + /// and footer are taken off. Positive infinity reaches this check. + /// + /// + /// Raised from a save when an inset is NaN or negative infinity. Neither reaches the + /// check above, so each surfaces as one of the unrelated messages described in the remarks. + /// Catching alone will not catch them. /// public EdgeInsets Margins { get; set; } = new EdgeInsets(72); // 1 inch @@ -335,6 +349,30 @@ private void CollectDiagnostics(DocumentRenderer renderer) } /// Runs the layout pass and writes the resulting PDF to the given stream. + /// + /// A document is single-use. The layout runs here, not when you add an element, so most of + /// what can go wrong goes wrong at this call rather than at the one that set the bad value. + /// Attention: calling this twice throws. The second call reports that the document has + /// already been written and tells you to create a new one. Nothing is appended and nothing is + /// overwritten, but you cannot use one to write two files. + /// A document with no pages throws as well. Add at least one element before you + /// save. + /// + /// + /// The document has already been written, or has no pages, or an element's input cannot be + /// laid out. The boundary documentation on the individual properties says which inputs those + /// are. + /// + /// + /// The margins, header and footer together leave the content area no positive size. + /// + /// + /// has a width or height that is not a positive finite number. + /// + /// + /// was set and was called. The two + /// cannot be combined. + /// public void Save(Stream destination) { var renderer = new DocumentRenderer(_pdf, _pdf.DefaultPageSize, Margins) @@ -348,6 +386,14 @@ public void Save(Stream destination) } /// Runs the layout pass and writes the resulting PDF to a file at the given path. + /// + /// Everything on applies, and one thing more. + /// Attention: the file is opened before the layout runs, so a failure destroys whatever + /// the path held. Measured: a path holding a 1,535-byte document, saved again from a document + /// whose layout then fails, is left existing and zero bytes long. If the target matters, + /// write to a temporary path and move it into place yourself, or save to a stream you control + /// (#508). + /// public void Save(string path) { using var fs = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None); @@ -365,6 +411,30 @@ public void Save(string path) /// final write, but does not abort layout or serialisation already in progress. /// /// + /// + /// A document is single-use. The layout runs here, not when you add an element, so most of + /// what can go wrong goes wrong at this call rather than at the one that set the bad value. + /// Attention: calling this twice throws. The second call reports that the document has + /// already been written and tells you to create a new one. Nothing is appended and nothing is + /// overwritten, but you cannot use one to write two files. + /// A document with no pages throws as well. Add at least one element before you + /// save. + /// + /// + /// The document has already been written, or has no pages, or an element's input cannot be + /// laid out. The boundary documentation on the individual properties says which inputs those + /// are. + /// + /// + /// The margins, header and footer together leave the content area no positive size. + /// + /// + /// has a width or height that is not a positive finite number. + /// + /// + /// was set and was called. The two + /// cannot be combined. + /// // RS0026 flags multiple overloads with optional parameters as a future-ambiguity risk; // Stream and string share no implicit conversion, so overload resolution can never be // ambiguous between these two. @@ -384,6 +454,14 @@ public async Task SaveAsync(Stream destination, CancellationToken cancellationTo } /// Asynchronously runs the layout pass and writes the resulting PDF to a file at the given path. + /// + /// Everything on applies, and one thing more. + /// Attention: the file is opened before the layout runs, so a failure destroys whatever + /// the path held. Measured: a path holding a 1,535-byte document, saved again from a document + /// whose layout then fails, is left existing and zero bytes long. If the target matters, + /// write to a temporary path and move it into place yourself, or save to a stream you control + /// (#508). + /// #pragma warning disable RS0026 public async Task SaveAsync(string path, CancellationToken cancellationToken = default) #pragma warning restore RS0026 diff --git a/src/VellumPdf.Layout/Elements/Heading.cs b/src/VellumPdf.Layout/Elements/Heading.cs index e58d61c0..3c5e4841 100644 --- a/src/VellumPdf.Layout/Elements/Heading.cs +++ b/src/VellumPdf.Layout/Elements/Heading.cs @@ -23,13 +23,13 @@ public sealed class Heading /// above 5 is tagged H6. That ceiling is this library's, not the format's: ISO 32000-2 /// Table 366 defines Hn for any unsigned integer from 1 upward, and its NOTE 2 says /// outright that H7 may be used for a seventh-level heading. - /// Do not pass a negative level. It is not refused, and it does not clamp the - /// way a reader would expect: the mapping's catch-all sends it to H6, the deepest - /// type, where a caller means the shallowest. The raw value also reaches the outline - /// builder, so the bookmark tree nests on it. A later major version will reject it. - /// Do not rely on a very large level for depth. Everything from 5 upward is the - /// same H6 tag, so assistive technology cannot tell level 5 from level 500, while the - /// outline still nests on the number given. + /// Attention: a negative level is not refused, and it does not clamp the way + /// you would expect. The mapping's catch-all sends it to H6, the deepest tag, where + /// you almost certainly meant the shallowest. The raw value also reaches the outline builder, + /// so your bookmark tree nests on it. A later major version will reject it. + /// Every level from 5 upward is the same H6 tag. Assistive technology therefore + /// cannot tell level 5 from level 500, while the outline still nests on the number you gave. + /// Do not use a large level to express depth. /// public int Level { get; init; } diff --git a/src/VellumPdf.Layout/Elements/LayoutImage.cs b/src/VellumPdf.Layout/Elements/LayoutImage.cs index 2f1adbd2..8ba32ddd 100644 --- a/src/VellumPdf.Layout/Elements/LayoutImage.cs +++ b/src/VellumPdf.Layout/Elements/LayoutImage.cs @@ -28,12 +28,15 @@ public sealed class LayoutImage /// Do not pass a negative width. It is not refused today and mirrors the image /// horizontally, which is a side effect of the transformation matrix rather than a supported /// way to flip an image. A later major version will reject it. - /// The zero check is on the written token, not the value. - /// PdfCanvas formats coordinates to five decimals, so anything under 5e-6 in magnitude - /// is written as 0 and the matrix is singular whatever the value held. Measured at the - /// boundary: 5e-6 writes 0.00001, 4.9e-6 writes 0. At that boundary the message - /// names the height, not the width, because the height is derived from the width and - /// collapses first. + /// NOTE: the check is on the token written, not on the value held. PdfCanvas + /// formats coordinates to five decimals, so any magnitude below 5e-6 is written as 0 + /// and the matrix is singular whatever you passed. At the boundary, 5e-6 writes + /// 0.00001 and 4.9e-6 writes 0. + /// The width is validated before the height, so a width under the boundary is always + /// what the message names, whatever the source image's aspect ratio. Above the boundary it is + /// the other way round: a width that is legal but small collapses the derived height of a + /// non-square image, and then the height is named. A width of 5e-6 on a 100 by 1 source + /// reports a height of 0.0000001. /// /// /// Raised from rather than from this property, for zero, for a magnitude under 5e-6, and for NaN or negative infinity. Positive infinity is clamped to the content box instead and does not throw. @@ -52,10 +55,11 @@ public sealed class LayoutImage /// : the emitted transformation matrix is either singular or not made of PDF /// numbers. Do not pass a negative height; it is not refused today and flips the image /// vertically as a side effect. - /// Anything under 5e-6 in magnitude is refused too, for the reason given on - /// : the canvas writes it as the token 0. - /// Setting both this and overrides the aspect ratio rather than - /// fitting inside the pair, so the image is distorted if the two disagree with it. + /// Any magnitude below 5e-6 is refused too. The canvas writes it as the token + /// 0, as described on . + /// Attention: setting both this and overrides the aspect ratio. The + /// image is not fitted inside the pair, so it is distorted whenever the two disagree with its + /// own proportions. If you want it fitted, set one and leave the other null. /// /// /// Raised from rather than from this property, for zero, for a magnitude under 5e-6, and for any non-finite value. diff --git a/src/VellumPdf.Layout/Elements/LineSeparator.cs b/src/VellumPdf.Layout/Elements/LineSeparator.cs index 631a46aa..c9a11752 100644 --- a/src/VellumPdf.Layout/Elements/LineSeparator.cs +++ b/src/VellumPdf.Layout/Elements/LineSeparator.cs @@ -10,14 +10,15 @@ public sealed class LineSeparator { /// Stroke width of the rule in points. /// - /// A non-finite width is refused. - /// throws naming the width, because the number would - /// reach the content stream as a token no reader can parse. - /// Do not use zero to hide the rule. Zero is accepted and is not a no-op: it - /// asks the device for the thinnest line it can draw, which is one pixel at any zoom and so - /// grows heavier as the page is scaled down. To omit the rule, omit the element. - /// Do not pass a negative width. It is not refused today and its effect is the - /// renderer's, not the format's. A later major version will reject it. + /// A non-finite width is refused. throws + /// and names the width. The number would otherwise + /// reach the content stream as a token that no reader can parse. + /// Attention: zero does not hide the rule. ISO 32000-2, 8.4.3.2 defines a line + /// width of zero as the thinnest line the device can render, one pixel wide. That is one pixel + /// at any zoom, so the rule grows heavier as the page is scaled down. If you want no rule, + /// leave the element out. + /// A negative width is not refused. What it draws is the renderer's business rather + /// than the format's, so do not rely on it. A later major version will reject it. /// /// /// Raised from rather than from this property, when the width is not finite. The message names the separator. diff --git a/src/VellumPdf.Layout/Elements/ListElement.cs b/src/VellumPdf.Layout/Elements/ListElement.cs index 96abf477..6d447d5a 100644 --- a/src/VellumPdf.Layout/Elements/ListElement.cs +++ b/src/VellumPdf.Layout/Elements/ListElement.cs @@ -37,15 +37,16 @@ public sealed class ListElement /// Points of indent for each list level. /// - /// Do not set an indent at or beyond the content width. It is not refused. The marker - /// is drawn and the item text is discarded, so the list renders as a column of bullets with - /// no content, and nothing reports the loss (#476). - /// A marker wider than the indent does not overprint the item text: the - /// gutter is widened to the marker's own width, per item. With roman numerals at the default - /// style the first marker to exceed a 20-point indent is item 17, and from there each item's - /// text starts further right than its neighbours'. The one case that still overprints is the - /// narrow fallback, where widening the gutter would leave less room than the longest word in - /// the item, and the gutter reverts to the indent. + /// Attention: an indent at or beyond the content width is not refused. The marker + /// is drawn and the item text is discarded. The list then renders as a column of bullets with + /// no content, and nothing reports the loss (#476). Keep the indent well below the content + /// width. + /// A marker wider than the indent does not overprint the item text. The gutter is + /// widened to the marker's own width, per item. With roman numerals at the default style the + /// first marker to exceed a 20-point indent is item 17; from there each item's text starts + /// further right than its neighbours'. One case still overprints: where widening the gutter + /// would leave less room than the item's longest word, the gutter reverts to the + /// indent. /// public double Indent { get; init; } = 20; diff --git a/src/VellumPdf.Layout/Elements/ListItem.cs b/src/VellumPdf.Layout/Elements/ListItem.cs index 8f0e9ae4..088c7362 100644 --- a/src/VellumPdf.Layout/Elements/ListItem.cs +++ b/src/VellumPdf.Layout/Elements/ListItem.cs @@ -26,13 +26,13 @@ public sealed class ListItem /// The nested child items, or null if this item has no children. /// - /// One level of nesting, and only one. A child's own - /// is read by nothing: a grandchild is not measured, not drawn, and - /// not reported. Its text is simply absent from the document. Scope of that claim: the - /// renderer reads item.Children and takes each child's style, marker and content, and - /// never reads child.Children. - /// So do not build a tree deeper than two levels and expect the whole of it to - /// appear. Flatten it, or compose separate lists, until arbitrary nesting lands (#479). + /// One level of nesting is supported, and only one. A child's own + /// is read by nothing. A grandchild is not measured, not drawn and not reported, and + /// its text is simply absent from the document. The scope of that claim: the renderer reads + /// item.Children and takes each child's style, marker and content, and never reads + /// child.Children. + /// Be aware that you have to handle this yourself. If you build a tree deeper than two + /// levels, flatten it or compose separate lists, until arbitrary nesting lands (#479). /// public IReadOnlyList? Children => _children; diff --git a/src/VellumPdf.Layout/Elements/PieChart.cs b/src/VellumPdf.Layout/Elements/PieChart.cs index 6b4cc090..3416051e 100644 --- a/src/VellumPdf.Layout/Elements/PieChart.cs +++ b/src/VellumPdf.Layout/Elements/PieChart.cs @@ -27,16 +27,15 @@ public sealed class PieChart { /// The slices, drawn in order. The sum of their values must be positive. /// - /// An empty list is refused, and so is a list whose values sum to zero or less. - /// Laying the chart out throws with - /// ParamName of Slices: there is no angle to give any slice, so there is - /// nothing to draw rather than something small. - /// A slice value that is negative or not finite is refused by the same - /// exception, because a negative sweep would paint over its neighbours and a non-finite one - /// has no angle at all. - /// Do not rely on a zero value being visible. A zero is accepted and - /// contributes no angle, so the slice is absent from the chart while remaining in this list; - /// nothing reports that it was dropped. + /// An empty list is refused. So is a list whose values sum to zero or less. Laying the + /// chart out throws with ParamName of Slices. + /// In both cases there is no angle to give any slice, so the result would be nothing rather + /// than something small. + /// A negative or non-finite slice value is refused by the same exception. A negative + /// sweep would paint over its neighbours, and a non-finite one has no angle at all. + /// Attention: a value of zero is accepted and contributes no angle. The slice stays in + /// this list and is absent from the chart, and nothing reports that it was dropped. If a zero + /// slice should be visible in your chart, give it a small positive value. /// /// /// Raised while the chart is laid out, which happens inside , @@ -50,11 +49,12 @@ public sealed class PieChart /// drawn size rather than a guaranteed one. /// /// - /// Zero, a negative value and a non-finite value are all refused. Laying the chart - /// out throws naming Diameter. - /// Do not size this against the page. A diameter wider than the content box is - /// accepted and clamped to the area the layout pass was handed, so the chart drawn is - /// smaller than the number set here and nothing reports the difference. + /// Zero, a negative value and a non-finite value are all refused. Laying the chart out + /// throws and names Diameter. + /// Attention: a diameter wider than the content box is accepted and clamped to the area + /// the layout pass was handed. The chart drawn is then smaller than the number you set, and + /// nothing reports the difference. Do not size a chart against the page; size it against the + /// space you have given it. /// /// /// Raised while the chart is laid out, which happens inside , @@ -73,13 +73,13 @@ public sealed class PieChart /// Width of the separator stroke in points. Defaults to 0.5. /// - /// A negative width and a non-finite width are both refused. Laying the chart out - /// throws naming StrokeWidth. - /// Do not use zero to remove the separators. Zero is accepted, but the stroke - /// is skipped on being unset, not on this being zero, so a zero - /// width with a stroke colour still strokes: it emits 0 w, which asks the device for - /// the thinnest line it can draw, and that grows heavier as the page is scaled down. Leave - /// unset instead. + /// A negative width and a non-finite width are both refused. Laying the chart out throws + /// and names StrokeWidth. + /// Attention: zero does not remove the separators. Whether a stroke happens at + /// all is decided by , not by this width. With a stroke colour set + /// and a width of zero, the renderer emits 0 w and still strokes, which asks the device + /// for its thinnest line. If you want no separators, leave + /// unset. /// /// /// Raised while the chart is laid out, which happens inside , @@ -89,10 +89,10 @@ public sealed class PieChart /// Horizontal placement of the chart within the content area. Defaults to centre. /// - /// Do not pass . It is not refused and it is - /// not honoured: it falls through to left alignment. This is worse here than elsewhere - /// because the default is , so asking for justify - /// silently loses the centring the chart had. + /// Attention: is neither refused nor + /// honoured. It falls through to left alignment. That costs more here than elsewhere, because + /// the default is : asking for justify loses the + /// centring you already had, and nothing reports it. /// public HorizontalAlignment Alignment { get; init; } = HorizontalAlignment.Center; @@ -102,10 +102,11 @@ public sealed class PieChart /// (12 o'clock). /// /// - /// A non-finite angle is refused. Laying the chart out throws - /// naming StartAngle. - /// Radians, not degrees, and no range is imposed: a value outside 0 to 2π is accepted - /// and wraps, so there is no need to normalise one. The default of π/2 starts at the top. + /// A non-finite angle is refused. Laying the chart out throws + /// and names StartAngle. + /// The unit is radians, not degrees. No range is imposed: a value outside 0 to 2π is + /// accepted and wraps, so you do not have to normalise one yourself. The default of π/2 + /// starts the first slice at the top. /// /// /// Raised while the chart is laid out, which happens inside , diff --git a/src/VellumPdf.Layout/Elements/RunningBand.cs b/src/VellumPdf.Layout/Elements/RunningBand.cs index ba4bc354..1d89929c 100644 --- a/src/VellumPdf.Layout/Elements/RunningBand.cs +++ b/src/VellumPdf.Layout/Elements/RunningBand.cs @@ -14,19 +14,21 @@ public sealed class RunningBand { /// Text template — may contain {page} and/or {pages}. /// - /// A template too wide for the content box is truncated, not refused. Before #365 it - /// was drawn off the page at a negative coordinate with every glyph still written into the - /// content stream, so the header or footer was invisible in every reader while its bytes - /// were still paid for. It is now cut to fit, and the cut is reported through - /// Document.BandTruncations and DocumentRenderer.BandTruncations. - /// The cut bounds the advance width, not the ink: side bearings and italic overhang - /// can still paint a little past it, because nothing in this package sets a clip path. - /// Do not rely on truncation for a template whose glyphs measure zero. Control - /// characters, the five undefined WinAnsi codes, and both symbolic standard-14 faces all - /// measure zero width, so any length of them "fits" and is drawn in full. - /// One report per band per render, naming the page that lost the most rather than the - /// first page cut, because a {page} or {pages} token lengthens the resolved - /// text as the number gains digits. + /// A template too wide for the content box is truncated, not refused. The cut is reported + /// through Document.BandTruncations and DocumentRenderer.BandTruncations, so + /// read one of those if you need to know it happened. + /// NOTE: before #365 an overlong template was drawn off the page at a negative + /// coordinate, with every glyph still written into the content stream. The header or footer + /// was then invisible in every reader while you paid for its bytes. + /// The cut bounds the advance width, not the ink. Side bearings and italic + /// overhang can still paint a little past it. Nothing in this package sets a clip path. + /// Attention: truncation does nothing for a template whose glyphs measure zero. Control + /// characters, the five undefined WinAnsi codes and both symbolic standard-14 faces all + /// measure zero width, so any length of them fits and is drawn in full. + /// You get one report per band per render, naming the page that lost the most rather + /// than the first page cut. A {page} or {pages} token lengthens the resolved + /// text as the number gains digits, so the worst page is the one that tells you how much + /// shorter the template has to be. /// public string Template { get; } @@ -35,8 +37,8 @@ public sealed class RunningBand /// Horizontal alignment of the band text. /// - /// Do not pass . It is not refused and not - /// honoured: it falls through to left alignment. A single-line band has nothing to justify + /// Attention: is neither refused nor + /// honoured. It falls through to left alignment. A single-line band has nothing to justify /// against, so there is no meaning to give it. /// public HorizontalAlignment Alignment { get; } @@ -46,20 +48,33 @@ public sealed class RunningBand /// Caller may override for tighter/looser bands. /// /// - /// This reserves space; it does not scale the text. The band's own - /// decides how large the glyphs are, so a height smaller - /// than the text needs lets the band overlap the content rather than shrinking it. - /// Zero and a negative value are not refused, and neither is useful: the - /// height comes off the page's content box, so both give the band no room while it is still - /// drawn, over the content. A later major version will reject them. - /// A non-finite value is refused, but by none of the messages you would expect. - /// All three throw from and none names the band - /// height. Measured, one value at a time: positive infinity gives - /// about the content area having no positive size; NaN - /// gives about an element being too tall to fit; - /// negative infinity gives the page-continuation cap. No file is written in any of the - /// three. + /// This reserves space. It does not scale the text: the band's own + /// decides how large the glyphs are. A height smaller than + /// the text needs therefore lets the band overlap the content rather than shrinking it. + /// Attention: zero and negative values are not refused, and neither is useful. The + /// height comes off the page's content box, so both leave the band no room while it is still + /// drawn, over your content. A later major version will reject them. + /// A non-finite value is refused, by two exception types across three messages. Each + /// was measured on its own, because the three values take different routes. Positive infinity + /// gives about the content area having no positive size, and + /// names the margins as the parameter. NaN gives + /// about an element being too tall to fit; that one + /// does report the height, as NaNpt of running bands. Negative infinity gives + /// about the page-continuation cap, which names + /// nothing about the band. + /// Attention: no valid document is produced in any of the three, and if you saved to a + /// path you have lost what was there. The string overloads of + /// open the file before the layout runs, so a failure + /// leaves a zero-byte file in place of whatever the path held (#508). /// + /// + /// Raised from a save rather than from this property, when the height is positive infinity: + /// the content area is then left with no positive size. + /// + /// + /// Raised from a save, when the height is NaN or negative infinity. The two give + /// different messages, described above. + /// public double? Height { get; init; } /// Creates a running band from a text template, with optional style and alignment (defaults to centered). diff --git a/src/VellumPdf.Layout/Elements/Table/Cell.cs b/src/VellumPdf.Layout/Elements/Table/Cell.cs index 33214a2a..ec0beeed 100644 --- a/src/VellumPdf.Layout/Elements/Table/Cell.cs +++ b/src/VellumPdf.Layout/Elements/Table/Cell.cs @@ -20,7 +20,7 @@ public sealed class Cell /// Zero or negative is refused. /// throws naming the row and cell, because a span of /// zero can leave the grid with no columns at all and nothing to draw into. - /// A span reaching past the columns left in its row is clamped to them, so the cell + /// A span reaching past the columns left in its row is clamped to them. The cell then /// ends at the table's right edge rather than beyond it. /// /// @@ -36,15 +36,19 @@ public sealed class Cell /// A spanning cell is drawn once, at its own row, across the combined height of the rows it /// covers, and those rows skip the columns it occupies. A page break is never placed inside a /// spanning group; a group too tall for one page raises rather than splitting. - /// Do not pass zero or a negative value. It is not currently refused and behaves - /// as 1, which is an accident of how the draw loop tests the span rather than a guarantee. A - /// later major version will reject it, so do not write code that depends on the current - /// behaviour. + /// Attention: zero and negative values are not refused. Both behave as 1. + /// That is an accident of how the draw loop tests the span, not a guarantee, so do not write + /// code that depends on it. A later major version will reject them. /// A span reaching past the rows this page draws is reduced to the rows actually - /// drawn, and the /RowSpan attribute written into the tagged structure follows the - /// reduced figure rather than the one set here, so a reader is never told about rows that - /// are not on the page (#493). + /// drawn. The /RowSpan attribute written into the tagged structure follows the reduced + /// figure, not the one you set, so a reader is never told about rows that are not on the page + /// (#493). /// + /// + /// Raised from a save rather than from this property, when a spanning group is taller than + /// one page. A page break is never placed inside such a group, so it raises instead of + /// splitting. + /// public int RowSpan { get; init; } = 1; /// Text style for the cell content; falls back to the table default when null. @@ -52,18 +56,21 @@ public sealed class Cell /// Inner padding between the cell border and its content. /// - /// A non-finite inset is refused. - /// throws naming the row and the cell, because the - /// number would reach the content stream as a token no reader can parse. - /// Do not pass a negative inset. It is not refused, and it does not clip: the - /// cell's text is placed outside the cell, over its neighbour or past the table edge. A - /// later major version will reject it. - /// Do not pass padding wider than the column. It is not refused, and what - /// happens is worse than a collapsed cell: the inner width is clamped to one point, so the - /// text wraps to one glyph per line and every line is placed at the left padding's own - /// offset, which is outside the column and usually outside the page. Measured with 400 points - /// of horizontal padding in a 260-point column on a 300-point page: ten glyphs, ten lines, - /// every one at x = 420. Nothing is dropped and nothing reports it. + /// A non-finite inset is refused. throws + /// and names the row and the cell. The number would + /// otherwise reach the content stream as a token that no reader can parse. + /// Attention: a negative inset is not refused, and nothing clips the result. The cell's + /// text is placed outside the cell, over its neighbour or past the table's edge. You have to + /// keep the insets positive yourself. A later major version will reject them. + /// Padding wider than the column is not refused either, and the result is worse than a + /// collapsed cell. The inner width is clamped to one point, so the text wraps to one glyph per + /// line, and every line is placed at Left's own offset, outside the column and usually + /// outside the page. Measured with Left at 400 in a 260-point column on a 300-point + /// page: ten glyphs on ten lines, every one at x = 420. Nothing is dropped and nothing + /// reports it. + /// NOTE: is Left plus Right, so an + /// insets value of 400 across both sides puts the text at x = 220 rather than 420. It is + /// Left alone that decides where a line starts. /// /// /// Raised from rather than from this property, when any inset is not finite. The message names the row and the cell. diff --git a/src/VellumPdf.Layout/Elements/Table/TableElement.cs b/src/VellumPdf.Layout/Elements/Table/TableElement.cs index 5851a47b..50f582b8 100644 --- a/src/VellumPdf.Layout/Elements/Table/TableElement.cs +++ b/src/VellumPdf.Layout/Elements/Table/TableElement.cs @@ -23,13 +23,14 @@ public sealed class TableElement /// Width of the table border lines, in points. /// - /// A non-finite width is refused. - /// throws naming the table. - /// Do not use zero to hide the borders. Zero is accepted and asks the device - /// for its thinnest line rather than for nothing, so the grid is still drawn and grows - /// heavier as the page is scaled down. There is at present no way to draw a table without a - /// grid: every cell is stroked unconditionally, and is not - /// nullable, so the nearest available approximation is a border colour matching the page. + /// A non-finite width is refused. throws + /// and names the table. + /// Attention: zero does not hide the borders. It asks the device for its + /// thinnest line, so the grid is still drawn, and it grows heavier as the page is scaled + /// down. + /// There is at present no way to draw a table without a grid. Every cell is + /// stroked unconditionally and is not nullable. If you need a + /// gridless table, the nearest you can get is a border colour matching the page. /// /// /// Raised from rather than from this property, when the width is not finite. The message names the table.