diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c377c1d..d9a8fecf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1012,6 +1012,42 @@ 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.** 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 independent second reading found, what veraPDF does, which one this library follows, and whether a 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..3b08c7a3 100644 --- a/src/VellumPdf.Layout/Core/TextStyle.cs +++ b/src/VellumPdf.Layout/Core/TextStyle.cs @@ -32,25 +32,30 @@ 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 + /// message names the element the style is attached to and the size itself. + /// public double FontSize { get; init; } = 12; /// /// 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 e41669b7..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; @@ -102,6 +114,35 @@ 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 + /// 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. + /// + /// + /// 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 /// @@ -308,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) @@ -321,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); @@ -338,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. @@ -357,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 8cb968ee..3c5e4841 100644 --- a/src/VellumPdf.Layout/Elements/Heading.cs +++ b/src/VellumPdf.Layout/Elements/Heading.cs @@ -18,6 +18,19 @@ 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. 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. + /// 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 205d2184..8ba32ddd 100644 --- a/src/VellumPdf.Layout/Elements/LayoutImage.cs +++ b/src/VellumPdf.Layout/Elements/LayoutImage.cs @@ -28,7 +28,19 @@ 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. + /// 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. + /// public double? Width { get; init; } // null = fit to available width /// @@ -43,7 +55,15 @@ 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. + /// 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. + /// 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..c9a11752 100644 --- a/src/VellumPdf.Layout/Elements/LineSeparator.cs +++ b/src/VellumPdf.Layout/Elements/LineSeparator.cs @@ -9,6 +9,20 @@ namespace VellumPdf.Layout.Elements; public sealed class LineSeparator { /// Stroke width of the rule in points. + /// + /// 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. + /// 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..6d447d5a 100644 --- a/src/VellumPdf.Layout/Elements/ListElement.cs +++ b/src/VellumPdf.Layout/Elements/ListElement.cs @@ -36,6 +36,18 @@ public sealed class ListElement public IReadOnlyList Items => _items; /// Points of indent for each list level. + /// + /// 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; /// 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..088c7362 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 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; /// 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..3416051e 100644 --- a/src/VellumPdf.Layout/Elements/PieChart.cs +++ b/src/VellumPdf.Layout/Elements/PieChart.cs @@ -26,6 +26,21 @@ 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. 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 , + /// 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; } = []; /// @@ -33,6 +48,18 @@ 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 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 , + /// 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. @@ -45,9 +72,28 @@ 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 + /// 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 , + /// 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. + /// + /// 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; /// @@ -55,6 +101,17 @@ 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 + /// 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 , + /// 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 7bec4997..1d89929c 100644 --- a/src/VellumPdf.Layout/Elements/RunningBand.cs +++ b/src/VellumPdf.Layout/Elements/RunningBand.cs @@ -13,18 +13,68 @@ 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. 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; } /// The text style of the band. public TextStyle Style { get; } /// Horizontal alignment of the band text. + /// + /// 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; } /// /// 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. 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 d2d58a8b..ec0beeed 100644 --- a/src/VellumPdf.Layout/Elements/Table/Cell.cs +++ b/src/VellumPdf.Layout/Elements/Table/Cell.cs @@ -20,7 +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. The cell then + /// ends at the table's right edge rather than beyond it. /// + /// + /// 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; /// @@ -30,17 +36,45 @@ 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. 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. public TextStyle? Style { get; init; } /// Inner padding between the cell border and its content. + /// + /// 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. + /// 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..50f582b8 100644 --- a/src/VellumPdf.Layout/Elements/Table/TableElement.cs +++ b/src/VellumPdf.Layout/Elements/Table/TableElement.cs @@ -22,6 +22,19 @@ public sealed class TableElement public TextStyle? DefaultCellStyle { get; init; } /// Width of the table border lines, in points. + /// + /// 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. + /// public double BorderWidth { get; init; } = 0.5; /// Color of the table border lines.