Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
127fe96
feat(functions): interpolate Order 3 sampled functions with a cubic s…
michaelstonis Nov 13, 2026
8afcdd6
Merge #236 Order 3 sampled functions
michaelstonis Nov 13, 2026
18bdf21
refactor(annotations): subtypes read their own entries through shared…
michaelstonis Nov 13, 2026
0163bf4
feat(security): read unencrypted wrapper documents and open their enc…
michaelstonis Nov 13, 2026
7a3324d
Merge #253 Annotation subtypes own their entries (expand)
michaelstonis Nov 13, 2026
d021a90
Merge #234 Unencrypted wrapper documents: reading
michaelstonis Nov 13, 2026
4122212
refactor(api): async entry points mirror their synchronous overloads …
michaelstonis Nov 13, 2026
9abc8d0
Merge #250 Async entry points mirror their synchronous overloads
michaelstonis Nov 13, 2026
5d7fd69
refactor(annotations): delete the retired subtype readers from PdfAnn…
michaelstonis Nov 13, 2026
2867253
Merge #254 Annotation subtypes own their entries (contract)
michaelstonis Nov 13, 2026
4927e2d
perf(cos): keep cross-reference entries compact and copy large stream…
michaelstonis Nov 13, 2026
2a51ac8
refactor(filters): split the DCT decoder by responsibility (#252)
michaelstonis Nov 13, 2026
0c319b3
Merge branch 'sweep/7a' into 252-split-dct-decoder
michaelstonis Nov 13, 2026
8a7d342
refactor(files): read associated files through their owners (#249)
michaelstonis Nov 13, 2026
95eeab0
Merge branch 'sweep/7a' into 237-bounded-memory-large-files
michaelstonis Nov 13, 2026
e359200
Merge #249 Associated files are read through their owners
michaelstonis Nov 13, 2026
a5811a8
feat(rendering): render the same bytes on every platform (#233)
michaelstonis Nov 13, 2026
455597a
Merge branch 'sweep/7a' into 233-bit-identical-rendering
michaelstonis Nov 13, 2026
8f4e78f
feat(security): write unencrypted wrapper documents around an encrypt…
michaelstonis Nov 13, 2026
d2c873b
Merge #235 Unencrypted wrapper documents: writing
michaelstonis Nov 13, 2026
196d0b8
Merge #233 Software rendering is bit-identical on every platform
michaelstonis Nov 13, 2026
98ebb9c
refactor(diagnostics): give diagnostic codes a public, typed catalog …
michaelstonis Nov 13, 2026
37d8f60
Merge branch 'sweep/7a' into 252-split-dct-decoder
michaelstonis Nov 13, 2026
23f80c0
perf(cos): record the allocation baseline of compact cross-reference …
michaelstonis Nov 13, 2026
84e9938
test(hosting): guard that every option and diagnostic reaches the hos…
michaelstonis Nov 13, 2026
b4fe712
Merge branch 'sweep/7a' into 239-hosted-options-guard
michaelstonis Nov 13, 2026
59d5603
merge sweep/7a into 242-public-diagnostic-catalog (#242)
michaelstonis Nov 13, 2026
e7bbfa5
Merge #242 Diagnostic codes get a public, typed catalog (expand)
michaelstonis Nov 13, 2026
9749ff4
test(hosting): sample a valid cryptographic filter version in the opt…
michaelstonis Nov 13, 2026
31d7d20
test(files): read the wrapper's associated files through the document…
michaelstonis Nov 13, 2026
2469057
Merge #239 Every option and diagnostic reaches the hosted engine
michaelstonis Nov 13, 2026
552e7ca
Merge #252 The DCT decoder is split by responsibility
michaelstonis Nov 13, 2026
d22f137
docs(bench): note the cross-reference and save timings of compact ent…
michaelstonis Nov 13, 2026
88861be
refactor(diagnostics): font, CharString, CFF, Type 1, Type 3, CMap an…
michaelstonis Nov 13, 2026
7634f93
refactor(diagnostics): move file structure, object, security and cata…
michaelstonis Nov 13, 2026
75b7f18
Merge #245 Diagnostic codes migrate: fonts, CMaps and text
michaelstonis Nov 13, 2026
39d9e32
Merge #243 Diagnostic codes migrate: file structure, objects, securit…
michaelstonis Nov 13, 2026
a2fc1cc
Merge branch 'sweep/7a' into 237-bounded-memory-large-files
michaelstonis Nov 13, 2026
f4a080a
refactor(diagnostics): keep one set of typed DiagnosticSink overloads…
michaelstonis Nov 13, 2026
0323e6c
fix(parsing): record a diagnostic for the remaining silent file-struc…
michaelstonis Nov 13, 2026
76802b7
Merge branch 'sweep/7a' into 238-silent-structure-repairs
michaelstonis Nov 13, 2026
8651fff
refactor(diagnostics): extension-point contexts report typed codes (#…
michaelstonis Nov 13, 2026
b7db18f
merge: take sweep/7a's DiagnosticSink and restore the 7.5.2 conforman…
michaelstonis Nov 13, 2026
0d28d9b
Merge #237 Multi-gigabyte files keep memory bounded on open and save
michaelstonis Nov 13, 2026
c0d8aff
fix(parsing): keep table entries beyond Size in lenient mode (#238)
michaelstonis Nov 13, 2026
8a59ecf
test(files): leave the unencrypted wrapper out of the encrypted-file …
michaelstonis Nov 13, 2026
2fce68b
Merge branch 'sweep/7a' into 238-silent-structure-repairs
michaelstonis Nov 13, 2026
01f809d
refactor(diagnostics): migrate content, color and document-model repo…
michaelstonis Nov 13, 2026
4278e3c
Merge #246 Diagnostic codes migrate: content, color and the document …
michaelstonis Nov 13, 2026
c4254c1
refactor(diagnostics): report filter, codec and image codes from the …
michaelstonis Nov 13, 2026
869d3b4
merge: sweep/7a into 244-diagnostic-codes-filters-images (#244)
michaelstonis Nov 13, 2026
d2116d3
test(diagnostics): the internal catalog may be empty once every area …
michaelstonis Nov 13, 2026
8aa088d
test(corpus): re-triage the real-world snapshots and gate allowlists …
michaelstonis Nov 13, 2026
5015791
Merge #244 Diagnostic codes migrate: filters and images
michaelstonis Nov 13, 2026
d04bfb6
Merge branch 'sweep/7a' into 238-silent-structure-repairs
michaelstonis Nov 13, 2026
b3a6a0e
merge: sweep/7a into 248-extension-point-typed-codes (#248)
michaelstonis Nov 13, 2026
c3cc5a8
Merge #238 Remaining silent file-structure repairs record diagnostics
michaelstonis Nov 13, 2026
8466f6f
refactor(diagnostics): retire the internal diagnostic catalog and gua…
michaelstonis Nov 13, 2026
ee66755
Merge branch 'sweep/7a' into 247-retire-internal-catalog
michaelstonis Nov 13, 2026
dff4960
refactor(images): one geometry value, enums for SMaskInData and the A…
michaelstonis Nov 13, 2026
4f5c76c
Merge sweep/7a into 251-image-api-tidy
michaelstonis Nov 13, 2026
2368152
merge: sweep/7a (#244, #246) into 248-extension-point-typed-codes (#248)
michaelstonis Nov 13, 2026
950159e
Merge #248 Extension-point contexts report typed codes
michaelstonis Nov 13, 2026
7b4c263
test(diagnostics): let the catalog guard allow owner-prefixed third-p…
michaelstonis Nov 13, 2026
2120111
Merge #251 Image API tidy before the freeze
michaelstonis Nov 13, 2026
eb9ddd2
Merge #247 The internal diagnostic catalog is retired (contract)
michaelstonis Nov 13, 2026
032b717
feat(conformance): check clause citations against the XML documentati…
michaelstonis Nov 13, 2026
0c4fc13
Merge #240 Clause citations are checked, not trusted
michaelstonis Nov 13, 2026
8f27588
docs(conformance): close every conformance row for v1 (#241)
michaelstonis Nov 13, 2026
3b51678
Merge #241 Conformance map closure for v1
michaelstonis Nov 13, 2026
70f9276
test(structure): accept one more real-world structure tree recovered …
michaelstonis Nov 13, 2026
a628892
fix(ci): allow 2 ulps for cbrt against the platform library and keep …
michaelstonis Nov 13, 2026
7214b4f
test(numerics): check cbrt exactly instead of against the platform li…
michaelstonis Nov 14, 2026
f19d315
chore(bench): re-record the allocation baseline from the CI runner af…
michaelstonis Nov 14, 2026
1aff73c
perf(numerics): table-driven deterministic pow and single-kernel degr…
michaelstonis Nov 14, 2026
a3521a5
perf(rendering): compute the arc step once per stroke and skip the an…
michaelstonis Nov 14, 2026
e987b49
chore(bench): re-record FirstPaint allocation after stroker arc-step …
michaelstonis Nov 14, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
53 changes: 49 additions & 4 deletions .claude/skills/adding-a-filter/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,20 @@ public sealed class FilterContext
public PdfReadingMode ReadingMode { get; init; } // Strict => Report throws
public long MaxDecodedLength { get; init; } // check header-declared sizes against this before allocating
public IReadOnlyList<Diagnostic> Diagnostics { get; }// what was reported through this context
public void Report(string code, DiagnosticSeverity severity, string message); // lenient: record; strict: throw DiagnosticException
public void Report(DiagnosticCode code, DiagnosticSeverity severity, string message); // lenient: record; strict: throw DiagnosticException
public CosObject Resolve(CosObject? value); // indirect references of the document (CosNull outside one)
public ReadOnlyMemory<byte> DecodeStream(CosStream stream); // another stream through the same pipeline (JBIG2Globals)
}

// Codes (namespace Broadside.Diagnostics, #242/#248): Broadside's are static properties of the catalog classes
// (FilterDiagnostics.FilterDataTruncated, DctDiagnostics..., names never contain a dot). A third-party filter makes its own once,
// in a static property, with an owner prefix; the reserved owner "Broadside" (any case, as the first segment) throws:
public static DiagnosticCode DiagnosticCode.Create(string owner, string name, DiagnosticSeverity defaultSeverity, string? clause = null);
// DiagnosticCode.Create("Contoso", "TileSkipped", DiagnosticSeverity.Warning) -> Name "Contoso.TileSkipped", Owner "Contoso", Area None

// Registration, per engine (no static registry):
new PdfOptions().UseFilter(IStreamFilter filter); // replaces the default of filter.Name or adds a name; later wins
new PdfOptions().WithMaxDecodedStreamLength(long); // decompression-bomb limit, default PdfOptions.DefaultMaxDecodedStreamLength (1 GiB)
new PdfOptions().WithMaxDecodedLength(long); // decompression-bomb limit, default PdfOptions.DefaultMaxDecodedLength (1 GiB)

// Consumption:
ReadOnlyMemory<byte> PdfDocument.DecodeStream(CosStream stream);
Expand All @@ -61,9 +67,48 @@ What the pipeline (internal `StreamDecoder`, one per document) does so a filter
- buffers between stages in pooled memory, truncates at `MaxDecodedLength` with `StreamDecodedLengthExceeded`, stops the chain at an unregistered name with `FilterUnsupported` and returns the data decoded so far;
- converts any exception a filter throws (other than a strict-mode `DiagnosticException`) into `FilterFailed`, keeping what it wrote.

Rules for an implementation: keep no state between calls (one instance serves every thread of every document of the engine); write through `IBufferWriter<byte>` in chunks (internal `FilterOutput` ref struct does this for the defaults); report each kind of deviation once per call with the codes in `Parsing/DiagnosticCodes.cs` ("Stream filters" group: `FilterDataInvalid`, `FilterDataTruncated`, ...); in lenient mode write what can be decoded and return.
Rules for an implementation: keep no state between calls (one instance serves every thread of every document of the engine); write through `IBufferWriter<byte>` in chunks (internal `FilterOutput` ref struct does this for the defaults); report each kind of deviation once per call with the codes of the public catalog: `FilterDiagnostics` (`src/Broadside/Diagnostics/FilterDiagnostics.cs`: `FilterDataInvalid`, `FilterDataTruncated`, ...), and for a codec its own class (`DctDiagnostics`, `CcittDiagnostics`, `Jbig2Diagnostics`, `JpxDiagnostics`, `ImageDiagnostics`); a new code is added only there (property with docs, default severity and clause, plus an entry in the class's `Codes` list; the architecture test `DiagnosticCatalogArchitectureTests` fails if a code is declared anywhere else); in lenient mode write what can be decoded and return.

Image codecs (Phase 2B): read the image entries from `StreamDictionary`, resolve auxiliary streams with `Resolve` and decode them with `DecodeStream`, size-check against `MaxDecodedLength` before allocating, and write the §8.9.3 sample layout so a codec behaves like any filter in a chain. Codec metadata (DCT transform, JPX components and color, alpha) is #60's optional image facet: a second interface the four codecs implement in addition to `IStreamFilter`, used when the codec is last in the chain. Its contract after the image API tidy (#251):

```csharp
namespace Broadside.Images;
public readonly record struct ImageGeometry(int Width, int Height, int Components, int BitsPerComponent)
{
public ImageGeometry AtReduction(int reduction); // ceil(W / 2^n) x ceil(H / 2^n), components and depth unchanged
}
public enum PdfSoftMaskInData { None = 0, Alpha = 1, PremultipliedAlpha = 2 } // the dictionary's SMaskInData
public enum AdobeColorTransform : byte { Unknown = 0, YCbCr = 1, YCCK = 2 } // a JPEG APP14 marker's transform code

namespace Broadside.Filters;
public interface IImageFilter : IStreamFilter // register with UseFilter, like any filter
{
bool TryReadHeader(ReadOnlySpan<byte> encoded, ImageFilterContext context, out ImageHeader header);
DecodedImage? DecodeImage(ReadOnlyMemory<byte> encoded, ImageFilterContext context);
}

public readonly record struct ImageHeader(ImageGeometry Geometry) // what the codestream declares
{
public bool HasAlpha { get; init; }
public int MaxReduction { get; init; } // 0: always full resolution; 3: decodes at 1/2, 1/4, 1/8 too
public ImageColorModel ColorModel { get; init; }
public ReadOnlyMemory<byte> IccProfile { get; init; }
}

public sealed class ImageFilterContext
{
public FilterContext Filter { get; } // Parameters, StreamDictionary, Report, Resolve
public ImageGeometry Geometry { get; init; } // the dictionary's Width, Height, BitsPerComponent, and its ColorSpace's component count; 0 where absent
public bool IsImageMask { get; init; } // ImageMask true: one component, one bit
public PdfSoftMaskInData SoftMaskInData { get; init; }// None: the codec may skip the opacity channel
public int Reduction { get; init; } // power of two asked for; deliver less and say so in DecodedImageBuilder.Reduction
public long MaxPixels { get; init; }
public long MaxDecodedLength { get; init; } // the same name and limit as FilterContext.MaxDecodedLength and PdfOptions.MaxDecodedLength
public bool TryCreateImage(ImageGeometry geometry, out DecodedImageBuilder? image); // checks both limits before renting memory
}
```

Image codecs (Phase 2B): read the image entries from `StreamDictionary`, resolve auxiliary streams with `Resolve` and decode them with `DecodeStream`, size-check against `MaxDecodedLength` before allocating, and write the §8.9.3 sample layout so a codec behaves like any filter in a chain. Codec metadata (DCT transform, JPX components and colour, alpha) is #60's optional image facet: a second interface the four codecs implement in addition to `IStreamFilter`, used when the codec is last in the chain.
A third-party image codec is exercised in `tests/Broadside.Tests/Images/ThirdPartyImageFilterTests.cs`; it compiles against exactly this surface.

Encoding (#142) is a separate contract, so decode-only filters need not change:

Expand Down
12 changes: 10 additions & 2 deletions .claude/skills/adding-a-font-program-parser/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,17 @@ public sealed class FontProgramContext // public ctor = stand-al
int MaxCompositeDepth { get; init; } // 16; int MaxGlyphPoints { get; init; } // 65,536
int MaxCharStringOperators { get; init; } // 100,000 per glyph, subrs and seac components included (#51)
IReadOnlyList<Diagnostic> Diagnostics { get; } // first of each code
void Report(string code, DiagnosticSeverity severity, string message); // throws in strict mode (not for Information)
void Report(DiagnosticCode code, DiagnosticSeverity severity, string message); // throws in strict mode (not for Information)
}

// Codes (Broadside.Diagnostics, #248): a built-in parser passes a catalog property (FontDiagnostics.FontGlyphInvalid,
// CffDiagnostics.FontCffIndexTruncated, ...). A third-party parser makes its own once, in a static property, with an owner
// prefix that cannot collide with Broadside's dot-free names; the owner "Broadside" (any case, first segment) is rejected:
public static DiagnosticCode DiagnosticCode.Create(string owner, string name, DiagnosticSeverity defaultSeverity, string? clause = null);
// DiagnosticCode.Create("Contoso.Fonts", "HintsDropped", DiagnosticSeverity.Information) -> "Contoso.Fonts.HintsDropped"
// Inside a document the diagnostic lands on PdfDocument.Diagnostics against the font file stream; Kind is the code (Owner set).
// The same typed Report is on SecurityHandlerContext (ISecurityHandler) and on the internal CMapContext.

public abstract class FontProgram // immutable, shared across threads; lookups never throw
{
protected FontProgram();
Expand Down Expand Up @@ -83,7 +91,7 @@ Registration and use:
- Glyph selection belongs to the PDF font: `PdfTrueTypeFont.GetGlyphId(byte)` implements §9.6.5.4 (`TrueTypeGlyphSelector`). #51/#52 supply a simple font's built-in encoding through `PdfSimpleFont.GetProgramEncoding()` (internal virtual, #49) and add the lookups their format has as new virtual members of `FontProgram` (built-in encoding, CID to GID, FDSelect): adding a virtual member with a "not available" default does not break other parsers.
- The sfnt container (`Fonts/TrueType/SfntFile`: table directory, TTC face selection, "name") is internal and meant to be shared with the OpenType-CFF parser (#51); "cmap" (`CmapSubtable`) and "post" (`PostTable`) readers likewise.
- Simple Type 1 fonts select glyphs through `PdfType1Font.GetGlyphId(byte)` (§9.6.5.2): the encoding's glyph name (whose base is `FontProgram.BuiltInEncoding` for an embedded font, through #49's `GetProgramEncoding`) looked up with `FontProgram.TryGetGlyphId`. A Type 1 or CFF program implements `BuiltInEncoding`, `TryGetGlyphId` and `GetGlyphName`. The Type 1 interpreter (`Fonts/Type1/Type1CharStringInterpreter`, #52) and the Type 2 one (`Fonts/Cff/Type2CharStringInterpreter`, #51) keep their own decoders but share `src/Broadside/Fonts/CharStrings/`: `CharStringLimits` (48 operands, 10 subroutine levels), the per-glyph budget `FontProgramContext.MaxCharStringOperators`, and `CharStringReporter` (shared FontCharstring* codes with the glyph id, once per kind per program in lenient mode; Error when the glyph is dropped, Warning for a repair). Type 2 also uses `CharStringPath`, `CharStringStack` and `StandardEncodingNames`. A later interpreter reuses these instead of its own limits and codes.
- Diagnostic codes (`Parsing/DiagnosticCodes.Fonts.cs`): `FontProgramUnsupported`, `FontProgramFormatMismatch`, `FontProgramInvalid`, `FontProgramTruncated`, `FontTableInvalid`, `FontGlyphInvalid`, `FontCmapInvalid`, `FontGlyphMappingFallback`. Glyph-level problems are reported when the glyph is asked for, so strict mode throws from `GetOutline`.
- Diagnostic codes live in the public catalog, `FontDiagnostics` (`src/Broadside/Diagnostics/FontDiagnostics.cs`; charstring codes in `CharStringDiagnostics`, CFF in `CffDiagnostics`, Type 1 in `Type1Diagnostics`): `FontProgramUnsupported`, `FontProgramFormatMismatch`, `FontProgramInvalid`, `FontProgramTruncated`, `FontTableInvalid`, `FontGlyphInvalid`, `FontCmapInvalid`, `FontGlyphMappingFallback`. Glyph-level problems are reported when the glyph is asked for, so strict mode throws from `GetOutline`. A new code is added only to the public catalog class of its area (property with docs, default severity and clause, plus an entry in the class's `Codes` list); the architecture test `DiagnosticCatalogArchitectureTests` fails if a code is declared anywhere else.
- Hot path: `GetOutline` into a reused `GlyphOutline` allocates nothing once warm (pooled point buffers, stack-allocated ancestor stack): prove it with an allocation test and `<Format>Benchmarks.Outlines` (`Allocated` = `-`).

### Responsibilities
Expand Down
Loading
Loading