3895 Commits
Author SHA1 Message Date
William Dunn 56c3c833bb file-formats: let the codec decide whether JXL reads (#2278)
Every workspace gate with `--all-features` has been failing since #2135 taught
craft-image-codecs to read JPEG XL behind a `jxl` feature. The capability test
asserted that JXL read is `Unsupported`, full stop. With that codec feature on,
`capabilities()` forwards the codec's own answer of `Available`. The assertion
then fails.

This crate cannot read that feature through `cfg!`. The feature belongs to a
dependency. A workspace build turns it on without this crate selecting
anything. An equality against either value is therefore wrong in some build.

The test now asks the codec the same question the code asks it. It compares
the two answers. A build whose codec reads JXL must report `Available`. One whose codec
does not must report `Unsupported`. The mapping has to exist either way. A missing
codec therefore fails an assertion of its own. The comparison is never quietly
skipped. Without `raster-codecs` there is no codec to ask. The answer is
`Unsupported`.

Verified at 1.100.0 on Linux. `cargo test -p craft-file-formats -p craft-image-codecs --all-features --locked` runs the case that was failing and passes. The same test passes with `-p craft-file-formats --all-features` and with `--no-default-features`. clippy with `--all-targets --all-features -D warnings` is clean. `cargo fmt --check` is clean. Making `capabilities()` ignore the codec's read flag fails the test. That is what the comparison is for. The HEIF and deep-EXR failures in that package need the pinned corpus. My checkout has not fetched it.
2026-11-19 00:43:07 -05:00
el-jandDylan M. Taylor 56847b14ad craft-captions: MP4 timed text sample codec (mov_text / tx3g) (#1781)
* craft-captions: MP4 timed text sample codec (mov_text / tx3g)

Add 3GPP TS 26.245 timed text subtitle sample decoding and encoding,
modifier box parsing (styl, hlit, hclr, krok, dlay, href, tbox, blnk, wrap),
markup conversion and tx3g sample entry configuration under feature
mov-text. Closes #1555.

* craft-captions: address reviews on mov_text formatting, twrp, and timescales.

---------

Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
2026-11-19 00:11:54 -05:00
Diego Chagas 401bf426a6 jxl: charge failed brob inflations, refuse large windows, walk boxes without a span list (#2275)
Follow-up to the brob budget:
- an over-cap or broken stream now charges the bytes it produced to the shared budget, so
  a file of many such streams cannot inflate the whole budget once per box;
- a Brotli header that declares a large window is refused before decoding (the decoder reserves
  its ring buffer up front, outside the output cap);
- boxes are walked one at a time instead of collected into a Vec of spans before the brob check.
image-codecs: document that JPEG XL ignores keep_orientation.
2026-11-19 00:11:50 -05:00
0a022b61f7 craft-sheet: built-in number formats 37 to 40 are the codes Excel reports (#2020) (#2291)
Excel 16 (en-US) reports #,##0_);(#,##0), #,##0_);[Red](#,##0),
#,##0.00_);(#,##0.00) and #,##0.00_);[Red](#,##0.00) for ids 37 to 40,
not the ECMA-376 Part 1 18.8.30 text the table held. It writes neither a
numFmt nor a FORMAT record for these ids, so the table is the only source
of their codes when a file Excel saved is read, as .xlsx or as .xls.

Co-authored-by: kiwi4boy <kiwi4boy@gmail.com>
Co-authored-by: Dylan M. Taylor <dylan@dylanmtaylor.com>
2026-11-18 23:55:20 -05:00
.CooCoo 7aaa2f8010 craft-media: mpegts::mux writes MPEG-2 transport streams frame by frame to any io::Write (#1998)
* craft-media: mpegts::mux writes MPEG-2 transport streams frame by frame to any io::Write

The mpegts feature gains a transport stream writer (ITU-T H.222.0 |
ISO/IEC 13818-1) next to the demuxer:

- PAT and PMT with the CRC-32 the demuxer checks (ts::crc32_mpeg), at
  the start, every psi_interval, directly before video keyframes, and
  after replace_writer and discontinuity; a PMT longer than one packet
  spans packets.
- One PES packet per frame for H.264, HEVC, MPEG-1, MPEG-2 and MPEG-4
  Part 2 video, AV1 (Carriage of AV1 in MPEG-2 TS), AAC (ADTS, or raw
  frames given an ADTS header), Opus (Opus transport draft V0.1.3,
  including explicit channel mappings and trims), AC-3, E-AC-3 and MPEG
  audio, with PTS and DTS modulo 2^33.
- The PCR on a stream's PID or its own, at most pcr_interval apart
  (100 ms at most), PCR-only packets in gaps, advance() for idle live
  outputs, continuity counters, random access and discontinuity
  indicators.
- Packets go out in batches of batch_packets (7 by default) built in
  fixed buffers; replace_writer returns per-segment facts.
- Frames are checked before anything is written; video frames are
  limited to MAX_UNIT_BYTES so the demuxer reads every one back.

Tests read every codec back with the demuxer (bytes, PTS, DTS, keyframes,
PCR range, no continuity or CRC warnings), check the PES header bits and
the refusals, and fuzz programs, timelines, idle gaps and output swaps.

* craft-media: mpegts::mux leaves out zero-ended AV1 padding and refuses 960-sample AAC configs

An AV1 padding OBU that ends with a zero byte, an empty one included, is
now left out like a temporal delimiter instead of failing the whole
temporal unit. Decoders ignore padding, and the trailing zero would
otherwise form a forbidden sequence with the next start code.

Codec::aac_from_asc refuses an AudioSpecificConfig with frameLengthFlag 1:
an ADTS header has no field for 960-sample frames, so decoders would read
the stream as 1024-sample frames.

* craft-media: the transport stream packet checker refuses a PCR flag in an adaptation field shorter than seven bytes

* craft-media: README states the multistream layout for 3 to 8 channel Opus

An Opus { channels } access unit is one Opus packet for 1 or 2 channels.
For 3 to 8 channels it holds the mapping family 1 streams in the order
of table 4-3 of the Opus transport draft, every stream but the last
self-delimited (RFC 6716 Appendix B). The README now says so, matching
the Codec::Opus doc comment.
2026-11-18 23:26:00 -05:00
Aleksander HelgakerandClaude Opus 5.5 2e6f11eabb craft-video: TrackDecoder for H.264, HEVC, VP9, AV1 and MPEG-2 (#1231) (#2022)
* craft-video: TrackDecoder, codec-agnostic decoding for H.264, HEVC, VP9, AV1 and MPEG-2 (#1231)

Add `craft_video::TrackDecoder`, the counterpart of craft-audio's: built
from a track's `CodecParams`, it takes packets in decode order with
their timestamps and returns `VideoFrame`s in display order, with
`flush` and `reset`. Each codec is behind its decoder feature.

Configuration: an `avcC` / `hvcC` record, Annex B parameter sets (AVI
with global headers) or nothing (MPEG-TS) for H.264 and HEVC; the
`av1C` config OBUs for AV1; a sequence header for MPEG-2. Picture data
in the configuration is refused (or, for MPEG-2, dropped by the
decoder's reset). `reset` keeps the configuration: H.264 applies it
again, HEVC and AV1 build a new decoder from it.

A call that fails keeps the frames it finished for the next call.

Add `VideoError` (Unsupported, Malformed, Frame), into which each
decoder's error converts. `av1::decode::bits` becomes `pub(crate)` for
its LEB128 reader.

Tests: unit tests for codec selection, configuration checks, hostile
configuration and kept frames; `tests/track` decodes ffmpeg-made MP4,
MPEG-TS and AVI files and compares with ffmpeg's decode, then decodes
again after a reset and from a later key packet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* craft-video: TrackDecoder review fixes (#1231)

- MPEG-2: configuration is checked before it is decoded. Every start
  code must be a sequence header, extension, user data or GOP header;
  a picture after a valid sequence header was decoded and then dropped
  by a reset, so construction succeeded. It is now Malformed.
- The decode and flush docs and the README say what each codec keeps
  after its own decoding error: H.264 keeps finished pictures, HEVC
  only its newest 32 while calls keep failing, VP9 those of earlier
  packets, MPEG-2 unless the packet made too many, and AV1 drops those
  of the failing decode or flush. Frames that fail to convert are
  still kept for the next call.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-18 23:25:56 -05:00
Dylan M. Taylor 4ce34ca37e Add bounded borrowed certificate inspection views (#2325)
Keep wire evidence separate from existing verification and trust APIs. Inspection semantics acknowledge Afloat’s original Craft Anything raw-field and non-minimal-length contributions.
2026-11-18 23:23:21 -05:00
cbf6840b10 Add craft-ppt-binary: DeckCraft's PowerPoint 97-2003 reader on craft-cfb and craft-pptx (#2316)
* ppt-binary: open PowerPoint 97-2003 .ppt/.pot/.pps files

New crate deckcraft-ppt (L3), written from the public [MS-CFB], [MS-PPT]
and [MS-ODRAW] Open Specifications: a compound-file reader (ported from
FilmCraft's clean-room reader), the edit chain and persist directory, and
the OfficeArt drawings. Main masters become masters (colours, fonts, text
styles, background, decorations), title masters become layouts; slides
keep their shapes (presets, freeforms, groups, rotation, flips), fills,
lines, shadows, pictures (PNG, JPEG, DIB, TIFF, EMF, WMF), text with the
master styles resolved into it, fields, notes and hidden flags.

Import only: an opened .ppt has no save path, so Save asks for a new
name. A .pps from the system starts the slide show. File dialogs, drag
and drop, the web shell and the macOS, Windows and Linux file
associations offer the three extensions. Tests build .ppt files from
records and sweep hostile input.

From storytold/deckcraft@0aef89cb1a (storytold/deckcraft#1137).

* ppt-binary: address review: budget picture decoding, read each persist directory once, macOS .pot/.pps types

- Pictures decode lazily, when a shape first uses them, each at most once and all
  within a shared 4 GiB budget: many store entries pointing at one deflated blob
  can no longer ask for unbounded memory.
- A persist directory named by many edits is read once.
- Info.plist declares com.microsoft.powerpoint.pot and .pps alongside .ppt.

From storytold/deckcraft@9e575ccecc (storytold/deckcraft#1137).

* ppt-binary: address review: check the picture budget before copying bitmap data

From storytold/deckcraft@470a429392 (storytold/deckcraft#1137).

* ppt-binary: build against current main

- convert.rs: set `flip: None` on imported gradients. `Gradient` gained the field in
  ad97533a; None is what an unflipped gradient was before.
- tests.rs: split `imports_a_presentation` into one check per section (title, picture,
  group, text box, master) for the workspace `cognitive_complexity` lint (6ddd2fb8).
  The assertions are unchanged.
- Cargo.lock: deckcraft-ppt takes the workspace version, 0.15.0.

From storytold/deckcraft@a0ececefeb (storytold/deckcraft#1137).

* ppt-binary: keep the picture budget on 32-bit targets

`MAX_TOTAL` was `4 << 30` as a `usize`. On wasm32 that is 2^32, which wraps to 0
without any error, so the web build's picture budget was zero and every .ppt
picture was dropped. Use the address space as the limit there. A compile-time
assertion that the budget holds at least one picture keeps it from happening
again on any target: the CI wasm step (`cargo check`) now fails if it does.

From storytold/deckcraft@4fd930ce1a (storytold/deckcraft#1137).

* ppt-binary: read past the character fields PowerPoint 2002 and later add

A TextCFException can end with pp10runid (mask bit 20), newEAFontRef (24),
csFontRef (25) and pp11ext (26), after `position`. read_cf stopped at
`position`, so in a StyleTextPropAtom the next run's count and mask were read
from the leftover bytes, and every later run got garbage formatting or the
walk ended. Master text styles go through the same reader. The fields are
read past and not used. The test has a run carrying all four followed by a
bold 18 pt run, which now reads as written.

From storytold/deckcraft@773af639c9 (storytold/deckcraft#1137).

* ppt-binary: convert each listed object once and index notes pages

Nothing stopped a slide list from naming one persist object many times, and
each listing converted its whole drawing again: a 100k-shape slide listed
180k times fits in about 10 MB and makes 1.8e10 shapes. An object is now
listed once across the slide, master and notes lists (PowerPoint never lists
one twice), and a repeat is logged and skipped. Notes pages are looked up
through a map built once, instead of a scan per slide (slides x notes). The
first matching page still wins.

From storytold/deckcraft@b3aa0983bd (storytold/deckcraft#1137).

* ppt-binary: find formatting runs by binary search

paragraphs() found the run at a position (rposition) and the next run start
(find) by scanning the run starts for every run, break and field, so text
cost grew with chars x runs. The starts are a running sum and never
decrease, so both lookups are now partition_point. Measured in a debug
build, 640k one-character runs (about 6 MB of file): 75 s before, about 2 s
after. The test uses a 20 s bound, like render's pathgrad budget test.

From storytold/deckcraft@b70b022362 (storytold/deckcraft#1137).

* ppt-binary: cap decoded pictures at the .pptx package total

The picture budget was 4 GiB, so a few MB of small deflated metafiles, each
inflating to 64 MiB, could make the import hold 4 GiB. A .pptx package may
inflate to 2 GiB in total (deckcraft-pptx opc MAX_TOTAL), and pictures are
the only part of a .ppt this crate inflates, so use the same 2 GiB. That also
fits a 32-bit usize, which replaces the wasm32 special case. This is a limit
change, so there is no new test: the budget test
(the_store_decodes_lazily_within_a_budget) and the compile-time check that
the budget holds a picture still cover it.

From storytold/deckcraft@a9cefff8b8 (storytold/deckcraft#1137).

* ppt-binary: fall back to the first main master the same way every time

A slide naming a master that doesn't exist fell back to the lowest index in
the masters HashMap. A title master is stored with its main master's index,
so the two tied and the HashMap's random order picked one: the same file got
the "Title Master" layout on some opens and the main master's on others. The
fallback now considers main masters only. The test opens such a deck 30
times; before the fix it took the title master's layout within those opens.

From storytold/deckcraft@60942d5950 (storytold/deckcraft#1137).

* ppt-binary: try the edit scan before calling a file too old

Any Current User token other than the plain or encrypted one, including none
at all from a truncated record, returned TooOld at once. A PowerPoint 97 file
with a damaged Current User stream was reported as "made by PowerPoint 95 or
earlier", and the UserEditAtom scan meant for a missing stream never ran.
[MS-PPT] allows only those two tokens, so an unknown one can't tell a damaged
file from an older format. The scan now runs, and TooOld is returned only when
it finds no edit record behind an unknown token.

From storytold/deckcraft@3869c3dc51 (storytold/deckcraft#1137).

* ppt-binary: read persist directories within one stream's worth of words

dirs_seen only skips a directory named at the same offset again. Directories
nested inside one another, each named by its own UserEditAtom, were each read
to the end of the stream: MAX_EDITS x the stream. In a debug build, 4095 such
edits over a 64 MiB stream took about 48 s. All directories now share a budget
of stream.len() / 4 words. Real directories are separate records inside the
stream, so they always fit. The hostile case stops in milliseconds and is
reported as damaged.

From storytold/deckcraft@5799048d88 (storytold/deckcraft#1137).

* ppt-binary: check two additions on input-derived sizes

- cfb.rs: the mini sector end `at + MINI_SECTOR_SIZE` was unchecked. On a
  32-bit target (wasm32), a sector number near 0x03FF_FFFF puts `at` at the
  top of usize, so the add panics in a debug build and wraps in release.
- text.rs: the style-run total `chars.len() as u32 + 1` truncated and could
  overflow past u32::MAX characters. It now saturates.

Neither case can be reached in a native test (one needs a 32-bit target, the
other more than 4 GiB of text), so there is no new test. The `+ 1`s in
convert.rs paragraphs() that the review also named are bounded by the text
length and can't overflow, so they are unchanged.

From storytold/deckcraft@b58c354246 (storytold/deckcraft#1137).

* ppt-binary: a sector chain that revisits a sector is an error

read_chain stopped at the stream's size, so a FAT loop shorter than the stream returned the
looped sectors again as the stream's bytes. It now tracks visited sectors and fails on a revisit,
and reserves the stream's size (capped at the file length) up front.

a_looping_chain_stops expected the repeated bytes; it now expects the error (eliets2's review).

From storytold/deckcraft@2b0940bff5 (storytold/deckcraft#1137).

* ppt-binary: slide shapes inherit from their own master's shapes

Master shape properties were remembered by shape id alone, so a later master (a title master,
or a second main master) that reused a shape id replaced the first master's entry, and slides
inherited fill and line from the wrong master. They are now keyed by master slide id and shape id,
and a shape's hspMaster is looked up in its slide's master, then a title master's main master.
Notes pages have no imported master, so they inherit nothing.

PowerPoint gives shapes file-unique ids, so this takes a damaged or generated file (eliets2's
review).

From storytold/deckcraft@7ad2f5152b (storytold/deckcraft#1137).

* ppt-binary: drop the unused fBackground field

RawShape.background was set from the FSP flag but never read: the background shape is the
drawing container's own shape (OfficeArtDgContainer.shape, [MS-ODRAW] 2.2.13), which drawing()
already takes. The comment there now says so (eliets2's review).

From storytold/deckcraft@afd57f47e0 (storytold/deckcraft#1137).

* ppt-binary: shadowed text keeps its shadow

TextCFException's shadow bit was read and merged but never reached the run. A shadowed run now
gets a shadow in the colour scheme's shadow colour, at the distance and direction of the app's own
Text Shadow command, with no blur (the record has none). Emboss has no counterpart in the model,
so its field is gone and the loss is listed in the docs (eliets2's review).

From storytold/deckcraft@ab5cf618e1 (storytold/deckcraft#1137).

* ppt-binary: the .pps show-on-open test opens a real 97-2003 file

a_ppsx_from_the_system_starts_the_show saved a .pptx under the name "Old talk.pps", so it went
through the PPTX path and never reached the legacy importer. crates/ppt/tests/fixtures/old-talk.pps
is a one-slide .pps built from records by the ppt tests (rebuilt with DECKCRAFT_WRITE_PPT_FIXTURE=1,
checked on every run), attributed CC0 like the other generated fixtures, and the UI test opens it
(eliets2's review).

From storytold/deckcraft@f511a2a66b (storytold/deckcraft#1137).

* ppt-binary: test mini streams, 4096-byte sectors and the DIFAT chain

The compound-file test builder only made version-3 files with 512-byte sectors, no mini stream
and every FAT sector in the header, so read_mini_chain, 4096-byte sectors and the DIFAT chain never
ran. build_with takes the sector shift and the mini stream cutoff, and lists FAT sectors past the
header's 109 in DIFAT sectors; build is build_with(streams, 9, 0), so existing tests see the same
layout. Three tests read streams back through each path (eliets2's review).

From storytold/deckcraft@212788b693 (storytold/deckcraft#1137).

* ppt-binary: test every picture kind, two-UID blips and blips inside the FBSE

The blip tests covered PNG, deflated WMF and DIB only. New tests decode JPEG (RGB and CMYK), TIFF
and PNG with one and two UIDs, an uncompressed EMF with each UID count, a metafile over the budget
(compressed or not), and a blip held inside its FBSE rather than in the Pictures stream. All
passed as written (eliets2's review).

From storytold/deckcraft@fe8023b9c2 (storytold/deckcraft#1137).

* ppt-binary: placeholder text held only in the slide list is imported

A shape's client text box may hold just an OutlineTextRefAtom, with no TextHeaderAtom ([MS-PPT]
OfficeArtClientTextbox): the text lives in the slide list, and that is the usual form for slide
placeholders. read_block returned None without a header, so text_block never reached its
outline fallback and the placeholder came in empty. A block with a reference and no header is
now returned for the caller to follow.

placeholder_text_can_come_from_the_slide_list covers the reference alone (it failed before this
change) and a header with a reference; the test document builder can put outline blocks in the
slide list (streams_with_outline). Found writing the test eliets2's review asked for.

From storytold/deckcraft@bf8ec603f3 (storytold/deckcraft#1137).

* ppt-binary: test newer edits and the two other encryption signs

doc::read had tests for one edit and the Current User token only. a_later_edit_replaces_a_slide
adds an edit whose persist directory gives the slide a new object; the newer slide is imported and
the master from the older directory is kept. encryption_is_found_in_the_edit_and_the_persist_directory
covers an edit record long enough for encryptSessionPersistIdRef and a CryptSession object named
by a later edit. Both passed as written (eliets2's review).

From storytold/deckcraft@f0b8525cc6 (storytold/deckcraft#1137).

* ppt-binary: test title masters and slides that follow nothing

No test made a slide of a title master or a slide with the follow-master flags off. The new test
checks that a title master becomes a "Title Master" layout with its own background and shapes
and without the master's shapes, that its slide uses that layout and follows its background, and
that a slide with all three flags off keeps its own background and colour scheme and hides the
master's shapes. It passed as written (eliets2's review).

From storytold/deckcraft@a41bf545e7 (storytold/deckcraft#1137).

* ppt-binary: merge boolean properties flag by flag

A boolean property word holds sixteen flags, each with its own fUse bit.
Props::inherit and add_table kept the whole word from the most specific
set, so a placeholder or text box that set only fNoFillHitTest lost the
inherited "not filled" and "no line" and was drawn with a fill and an
outline. Merge those words per flag instead (storytold/deckcraft#1137 review, issue 1).

From storytold/deckcraft@79ae833152 (storytold/deckcraft#1137).

* ppt-binary: recover a broken edit chain and report lost slides

An edit whose previous-edit offset points back at itself (or anywhere
that isn't an edit) cut the older edits off, and with them the persist
directories holding the slides: such a file opened as an empty deck
with no warning. When the chain doesn't end at offset 0, read every
edit's persist directory in the stream, newest first, filling only what
the chain left unset.

Slides the slide list names but whose objects are still missing are now
returned by deckcraft_ppt::import_checked and reported like a damaged
.pptx: lostSlides, a "(Repaired)" copy and the CLI warning
(storytold/deckcraft#1137 review, issue 3).

From storytold/deckcraft@135674101f (storytold/deckcraft#1137).

* ppt-binary: picture frames, inline picture fills, gradients, footers, numbering

The remaining differences from LibreOffice in the storytold/deckcraft#1137 stress test:

- Picture frames (and OLE frames) that say nothing about fill or line
  start with neither, as placeholders and text boxes do, instead of the
  drawing defaults' fill.
- A pib or fillBlip held in the property's own complex bytes (fBid) is
  decoded within the picture budget: table cells with a picture fill
  showed a plain colour.
- Shaded fills put the back colour at fillFocus ([MS-ODRAW]), and the
  linear angle follows how LibreOffice writes and reads it (0 degrees
  from the top): the linear gradient was reversed, the radial inside out.
- HeadersFooters (the slide's, else the document's) add the date,
  footer and slide number placeholders; the master's footer placement,
  alignment, size and colour reach every layout.
- Numbering from the document's ___PPT9 tag (OutlineTextProps9, pp9rt
  in the runs' fontStyle) turns bulleted paragraphs into numbered ones.
- Wingdings diamonds draw as a diamond, not a dot.

From storytold/deckcraft@24437bd075 (storytold/deckcraft#1137).

* ppt-binary: read CString records up to their first NUL

Header/footer text and the ___PPT9 tag name were decoded from the whole
CString body. A writer that ends the string with a NUL would put the NUL
into the footer text and make the tag name fail to match, losing the
numbering. Stop at the first NUL, as the font names already do.

From storytold/deckcraft@110e1420fd (storytold/deckcraft#1137).

* ppt-binary: on craft-cfb and craft-pptx (the move from DeckCraft)

What the move from storytold/deckcraft#1137 changes; the commits before this one are that
PR's crates/ppt as it is on its branch, without its manifest.

- craft-cfb replaces the crate's own compound-file reader (cfb.rs, 552 lines). Streams are
  read capped at the file's length, as before. Its six tests (looping chains, mini streams,
  version 4 sectors, the DIFAT) are covered by craft-cfb's own. The byte helpers move to
  record.rs. Test files are written by craft-cfb's writer.
- deckcraft-model, deckcraft-color and deckcraft-geom become craft-pptx and craft-drawingml,
  the same types (storytold/deckcraft#2179, storytold/deckcraft#2180 and #792's plan). A gradient now states its
  shape and rotate-with-shape explicitly, as craft-drawingml's are optional.
- DeckCraft's default master (defaults::build_master and blank_presentation) becomes the
  caller's craft_pptx::Defaults: import(bytes, &defaults), as craft_pptx::import takes. The
  file's masters take the default master's layouts and placeholders, then the file's theme,
  placeholder boxes and styles. The tests use a default master with title, body and footer
  placeholders and the seven layouts .ppt layout types map to; a new test reads with
  craft_pptx::Plain.
- The two tests that drive DeckCraft's engine (open and save, lost slides in the app) stay in
  DeckCraft.
- The fixture's rebuild variable is CRAFT_WRITE_PPT_FIXTURE; old-talk.pps is unchanged and
  gets its ATTRIBUTION row. Bare #1137 references in comments name storytold/deckcraft#1137.
- README, crate README (doctested) and the workspace entry.

* ppt-binary: bound text, strings, paths and repeated work from hostile files

Tab stops keep the first 64 entries while still reading past the rest, string properties stop
at 4096 units, and a freeform path uses at most 8192 vertices, since each of these is copied
into every paragraph or inheriting shape. An outline block in the slide list is the text of
one shape only; a second reference keeps the shape's own text.

The fallback master and each master's layout per type are found once before the slides are
converted, a shape's primary property tables are collected without inserting at the front,
and a compressed metafile that fails to inflate is charged to the picture budget.

* ppt-binary: review fixes for footers, rulers, title masters, paths and numbering

A slide's own headers and footers record (instance 0) now wins over the document's, and a
text box that points at an outline block keeps the margins and indents of its own ruler. A
slide list entry whose object is not a slide is reported as lost.

Title masters place their layout's placeholders from their own placeholder boxes, adding any
the title layout lacks, and copy only placeholders from an earlier title layout. Slides that
don't name a title master no longer pick its layout.

Freeform paths skip the points of escape segments, and without segments follow shapePath
(closed lines by default, open lines or curves). DIB colour tables are sized by bit depth and
refused when they run past the bitmap. Numbering schemes 0x10 to 0x28 map to their DrawingML
names, master style levels go to the level they name, and a broken edit chain reads the newest
edits rather than the oldest.

The nested persist directory test now checks the file is reported damaged, the footer test
fails when a layout has no slide number, and the README says tables come in as groups of
shapes.

* ppt-binary: second review round: failed pictures, title layouts, notes, arcs and property tables

Inflating a compressed metafile is now charged its compressed bytes as well as its output, and
is refused when those bytes alone pass the remaining budget, so many entries pointing at one
stream that inflates to nothing can't each read it again for free.

A title master's layout starts only from the defaults' own title layout, not one made for an
earlier title master. A notes page shared by two slide records with the same slide id goes to
the first only. After elliptical quadrants or a quadratic Bezier escape a path goes on from
their last point; after an arc or angle ellipse, whose end isn't one of its vertices, the path
stops rather than draw from the wrong place. A property set keeps at most 1024 distinct
properties, so copying the drawing defaults into each shape costs a bounded amount.

* ppt-binary: take each main master's title-layout base once; test outline notes

A title master's layout starts from the placeholders of the defaults' title layout. They are now
taken once, when the main master is made, instead of rebuilding the set of title-master layouts
and rescanning the master's layouts for every title master, which was quadratic in title masters.

A notes page whose body text is in the notes list's outline block also goes to one slide only.

---------

Co-authored-by: Oliwier Kulczycki <oleknuso282@gmail.com>
Co-authored-by: kiwi4boy <kiwi4boy@gmail.com>
2026-11-18 23:23:02 -05:00
.CooCoo c39072d321 image-codecs: keep PrefixDetector tests within the prefix contract (#2277)
PrefixDetector::detect requires each call's bytes to start with the
previous call's bytes. Two integration tests passed a buffer that broke
that rule, so a detector that rechecks the SOI before resuming would
have failed them while still honoring the contract.

The tests now pass longer prefixes of one file and compare each answer
with detect_prefix on the same bytes. The check that a walk resumes at
the marker it stopped at stays in the jpegls unit tests, and a new unit
test checks that a walk that found a non-JPEG-LS frame header stays at
that marker.
2026-11-18 23:20:49 -05:00
mtlcl410 d2a7d88d2e hayro-postscript: a \ddd escape above \377 keeps its low eight bits (#2321) (#2324)
A literal string's octal escape was converted with `u8::from_str_radix`,
which fails above 0o377, so the byte was dropped. Read one to three octal
digits into a u16 (at most 0o777) and push the low byte, as ISO 32000-2
7.3.4.2 and the PostScript Language Reference (third edition, 3.2.2)
specify: "high-order overflow shall be ignored". Escapes up to `\377`
decode as before.

Record the patch in SOURCE.json and vendor/README.craft-reader.md.

Fixes #2321
2026-11-18 23:20:45 -05:00
.CooCoo 4e0c880f58 craft-csv: delimiter detection samples 65,536 characters, not 64 KiB (#2326)
sniff_delimiter read the first 64 KiB of the text. A first field of
three-byte characters longer than about 21,800 characters filled that
sample before its delimiter, so a semicolon or tab file opened as
comma-separated. The sample is now the first 65,536 characters, the
amount detection read before it moved into craft-csv.

The new test fails without the change: a first field of 65,535
three-byte characters followed by a semicolon is detected as comma.
2026-11-18 23:20:42 -05:00
aiongg 36ca4574e4 Merge pull request #2318 from aiongg/ci-tier1
Workspace CI: own cache entries per gate call, stripped test binaries, no examples in the test build
2026-11-18 22:21:51 -05:00
Dylan M. Taylor c350c5eedd Merge pull request #2078 from texjer/craft-develop-inpaint
craft-develop: the crate, with inpaint from LightCraft (#587)
2026-11-18 21:37:58 -05:00
aiongg e701f54d0a workspace: own cache entries for the WASM and 1.95 calls, stripped test binaries, no examples in the test build
Needs craft-common-actions gate.yml with the cache-name and dev-strip inputs.
2026-11-19 02:22:51 +00:00
FredApps 13ca2272a9 Merge pull request #2307 from FredApps/fix/786-psd-hue-level-writers
psd: share raw hue and levels block writers
2026-11-19 08:44:35 +07:00
texjer bf11227dae Merge main into craft-develop-inpaint: the crate now also holds spline, curve and lut 2026-11-18 20:41:04 -05:00
William Dunn 4141fe7a9f craft-gpu: provider-neutral GPU job traits and the wgpu backend (#663)
* craft-gpu: add the GPU job traits and the shared providers.

This carries over crates/gpu, crates/gpu-wgpu, crates/gpu-null, and crates/gpu-providers from the cut-down #160 branch, with minimal workspace wiring.

None of these crates names a vendor or any app. craft-gpu defines GpuJob and ProviderRegistry. craft-gpu-null is an in-memory context for tests. craft-gpu-providers holds the shared craft.* WGSL providers. craft-gpu-wgpu is the wgpu backend, native and WebGPU.

* craft-gpu: real device wiring, device loss and async readback (RFC-0022)

Addresses skylartaylor's review gate on #663 at 138f7b2. RFC-0022 has merged
since that review. This follows its acceptance requirements.

WgpuContext now requests a real device. DeviceCaps comes from that device,
reflecting the limits and features actually enabled on it. Buffers are real
wgpu::Buffer values when a device exists. The no-adapter case still degrades
to the same staging behavior as craft-gpu-null. The RFC defines that case
explicitly as the no-adapter path. Device loss is registered via
set_device_lost_callback. It surfaces as GpuFault::DeviceLost. It never
surfaces as a panic. The recovery is stated on GpuContext's trait docs.

GpuContext::read_buffer is no longer a required method. The primitives are
request_read and poll_reads. That mirrors craft-worker-host's own
HostMessage::GpuJobs to WorkerMessage::GpuBatchDone split one level down.
read_buffer stays as a default blocking convenience. It resolves immediately
on the null and staging paths. Native wgpu blocks on
Device::poll(wait_indefinitely). On wasm32 it returns GpuFault::Operation,
since a blocking wait there would freeze the one thread map_async's own
callback needs to run on.

crates/gpu-wgpu/src/tests.rs adds a real-backend suite, gated on
adapter-probe plus non-wasm32. It runs upload, readback and device-loss
tests against a real WgpuContext. It also runs three craft-gpu-providers
CPU-stand-in providers against that same real WgpuContext. It skips with a clear message when no adapter is present.
Verified against lavapipe with mesa-vulkan-drivers, using
--features adapter-probe,native-vulkan: every test passes. That run first
caught a real wgpu panic on buffer lengths that are not a multiple of 4,
COPY_BUFFER_ALIGNMENT. The fix pads real buffers transparently. Every caller
still sees exact, unpadded bytes.

docs/gpu-backends.md and docs/gpu-providers.md are updated to match,
including named consumers (the runtime slice first, then EffectCraft and
FilmCraft) and a device-ownership note for when egui's wgpu renderer is also
running.

* craft-gpu: buffer-size guards, empty-buffer parity, read_buffer keeps other completions

Answers the six findings in CodeRabbit review 5852678306 on PR #663.

upload_buffer on the device path refuses a padded size past the device's
max_buffer_size with GpuFault::InvalidJob before creating the buffer.
request_read guards its staging copy the same way. An oversized request
used to reach wgpu as a validation error on the device's error scope.

Empty buffers are accepted everywhere, matching craft-gpu-null and the
documented staging parity. The device path resolves an empty readback
immediately (wgpu refuses an empty map range). The blanket InvalidJob on
empty upload bytes is gone.

read_buffer no longer eats completions that belong to another
outstanding request. The wgpu override re-queues them for the next
poll_reads. The null context gains an override that takes only its own
completion. The trait's default-body contract is documented: with the
default body, do not interleave read_buffer with an outstanding
request_read.

ReadbackProvider validates the storage-binding cap directly. The old
chunk_buffer call allocated a Vec of slices only to drop it.

parse_u32 and params_contain refuse an empty prefix or needle.
windows(0) panics and the crate's rule is never to crash.

The manifest guard test now also rejects *-engine dependency lines, per
docs/gpu-providers.md.

* craft-gpu: per-job batch results, wasm staging reads resolve

Two findings CodeRabbit raised against the carried copy on PR 662, fixed here where the crates live. dispatch_batch now answers per job in input order. The old first-failure abort discarded outcomes earlier providers had already produced, leaving the caller nothing to reply with and no way to name the jobs worth retrying. A job fed by a failed predecessor fails honestly on its own bad handles. On wasm32 read_buffer now serves the staging backing, whose reads resolve synchronously. The backing on that target is always staging today. The refusal remains for a read that did not resolve synchronously, guarding the future wasm device backing where blocking would hang the tab.

* Add free_buffer and device_status to GpuContext.

Two CodeRabbit findings against crates/gpu-wgpu, both answered at the
trait level since craft-gpu-null has the exact same gap.

free_buffer (lib.rs:313). Every upload_buffer call added an entry to a
backend's buffer table. So did every output buffer a provider's job
created. Nothing ever removed one. Repeated jobs retained memory for
the whole lifetime of a context. The new required method releases a
buffer's resources. A freed handle behaves as invalid afterward, the
same fault an unknown handle already produces.

device_status (lib.rs:401). poll_reads can only attach a device-lost
fault to a read it has something to attach it to. A caller whose event
loop only polls, with nothing pending when loss happens, could never
observe it. The new method, default Ok(()), covers that gap directly;
a backend with no concept of device loss needs no override.

MemContext in this crate's own tests gets the same free_buffer shape as
craft-gpu-null, to keep it compiling under the new required method.

* Implement free_buffer for NullContext.

buffers moves from Vec<Vec<u8>> to Vec<Option<Vec<u8>>>. A handle is a
stable index. Freeing a slot replaces it with None. Removing it
instead would shift every later handle's index out from under its
caller. buffer_len and request_read now reject a freed index the same
way they already reject one that never existed.

Two new tests. One frees a handle and checks another's index and bytes
stay untouched. One frees a handle twice, and a handle that never
existed, and confirms both are a harmless no-op.

* Fix the no-device caps fallback, capture allocation failures, free buffers.

Four CodeRabbit findings against this crate.

The no-device fallback in WgpuContext::new called probe_caps() again
on request_device failure (lib.rs:228). A second, successful adapter
query would then report the adapter's advertised limits as if they
came from a granted device, for a context that holds none. It now
falls back to the plain, fixed caps probe_caps's own doc comment
already promises for that case.

Allocation failures during buffer creation used to reach wgpu's
default uncaptured-error handler (lib.rs:299). That handler panics.
The size check already in place only catches a request past the
device's advertised maximum. It says nothing about whether the device
can actually allocate that many bytes right now. An error scope around
both the output-buffer and the read-staging-buffer creation converts a
failure into a GpuFault instead.

free_buffer for WgpuContext (lib.rs:313) matches the Option-wrapped
shape just added to craft-gpu-null. Both backings, staging and real
device, release a buffer's resources and make the handle behave as
invalid afterward, without shifting any other handle's index.

device_status for WgpuContext (lib.rs:401) reports device loss through
the trait method just added to GpuContext. A caller that only polls
can now observe loss even with nothing pending.

New tests cover the fixed fallback value and a regression check that
the new allocation error scope does not misfire on an ordinary
allocation. They also cover free_buffer on both the staging and the
real-device path. One more covers device_status observing a destroyed
device with nothing outstanding. A genuine out-of-memory condition is not reliably
reproducible in CI; the allocation-failure test is the honest half of
that fix this can run.

* Fix the error-scope API call and run cargo fmt.

wgpu 30.0.1's Device has no pop_error_scope method. push_error_scope
returns an ErrorScopeGuard. pop() lives on that guard. Keep the guard
from push_error_scope and call pop() on it.

Also drops an unneeded mut on a test binding that never mutates its
context. Also runs cargo fmt on the lines the Option-wrapped buffer
changes touched.

* Drop a needless return clippy flagged in the adapter-probe lane.

The fallback branch in WgpuContext::new is the function's own tail
expression once the real-device branch above it has already returned
early. The explicit return on it was redundant.

* Run cargo fmt on the no-device fallback branch.

* Pop the OOM scope before the call that would misuse a failed buffer.

upload_buffer popped its scope only after write_buffer. request_read
popped its scope only after the copy and its submission. A buffer that
failed to create is invalid. Using an invalid buffer raises a VALIDATION
error that an OutOfMemory-only scope never catches. The default
uncaptured-error handler still panicked on a failed create even with the
scope in place. Pop right after create_buffer in both paths and return
before the buffer is used again, with a separate scope around the later
write or copy.

write_buffer only queues its copy into wgpu's PendingWrites. An upload
with no following submission kept the destination and staging buffers
alive inside wgpu-core until some other submit happened. upload_buffer now
flushes with an empty queue.submit right after its own write_buffer call.
A free_buffer right after an upload can now actually release the
allocation.

* Run cargo fmt on the new ordering test.

* craft-gpu-wgpu: correct the crate docs on wasm32 read_buffer

The staging backing serves wasm32 reads synchronously since the staging-reads fix. Only a read that did not complete synchronously faults. The crate-level summary still described the old unconditional fault.

* craft-gpu: sync the docs with the implemented readback behavior

Review asked for three corrections. The backends doc, the providers doc and the trait docs now state that both bundled backends override read_buffer's default body and that wasm32 serves the staging read, with a fault only for a read that did not resolve synchronously. The runtime follow-up paragraph now records that #662 consumed it. The software Vulkan container run is described as local testing. Hosted CI coverage and the pilot consumers' browser and hardware validation remain their own requirements. Em dashes swept from both docs per the house writing rules.

* has_device: say the answer once, in this file's own shape

Clippy 1.100.0 refuses the old body under `needless_bool`. The `if` returned a
bool literal with a bare `false` after it. The cfg attribute sat on the `if`
itself. The whole statement therefore vanished without the adapter-probe
feature.

Two cfg blocks replace it, one per configuration. `probe_caps` in the same
file already has that shape. `Backing::Device` exists only under that feature.
The clippy suggestion on its own would not compile.

The plain clippy leg never saw this. The line compiles only with adapter-probe
on. The all-features leg catches it, as does any workspace build that unifies
the feature in.
2026-11-18 19:05:00 -06:00
FredApps 9da45ec561 Merge pull request #2313 from FredApps/fix/full-validation-shell-oracle-778
ci: align full-validation oracle with Bash conditions
2026-11-19 07:57:03 +07:00
FredApps 1eb0815488 ci: align full gate oracle with Bash condition syntax 2026-11-19 01:15:24 +01:00
Dylan M. Taylor e787321728 feat(jpeg): add reduced-size DCT-scaled decoding (#2296)
* feat(jpeg): add reduced-size DCT-scaled decoding

* Fix cargo fmt and clippy warnings in craft-jpeg

* fix(jpeg): use as_chunks instead of chunks_exact(3) in test
2026-11-18 18:59:59 -05:00
Dylan M. Taylor d7b8dba7b2 craft-plotter: add HP-GL/2 plot and write modules (#2295)
* craft-plotter: add HP-GL/2 plot and write modules

* Make clip::Region and nest::{bounds, outer} pub for clippy
2026-11-18 18:59:55 -05:00
FredApps fa4741d0bb psd: share raw hue and levels block writers 2026-11-19 00:59:54 +01:00
Dylan M. Taylor 3475d9a543 feat(ipp): extract craft-ipp from photocraft-ipp (#2292)
* feat(ipp): extract craft-ipp from photocraft-ipp

* chore(ipp): fix cargo fmt
2026-11-18 18:59:51 -05:00
Dylan M. Taylor 07d5165036 hayro-postscript: add Scanner::parse_object_or_skip (#2287) 2026-11-18 18:59:47 -05:00
Dylan M. Taylor 8008ad3608 chore(doc-binary): mark spec-mandated MD4 BLIP UID as NOSONAR (#2305) 2026-11-18 18:52:05 -05:00
Dylan M. Taylor 00577e538f chore(ci): use [[ ]] in shell scripts (SonarCloud S7688) (#2304) 2026-11-18 18:50:50 -05:00
Dylan M. Taylor 0e6af4121b docs: add CodeRabbit badge to README (#2303) 2026-11-18 18:49:25 -05:00
Dylan M. Taylor b625263e07 feat(cms): add GPL/CSS/ASE/ACB palette I/O (#2297)
* feat(cms): add GPL/CSS/ASE/ACB palette I/O

* chore(cms): fix fmt and clippy
2026-11-18 18:45:56 -05:00
FredApps 027416ac9f Merge pull request #2272 from FredApps/fix/786-psd-fixed-writers
psd: share raw brightness and exposure block writers
2026-11-19 06:44:50 +07:00
8aa61a478a feat(jpeg): add finer_than_first header check (#2302)
Port samhyun’s progressive JPEG sampling guard from storytold/figcraft#1491,
source commit 9aac391e045c3c5894c1112e537d8ea2da382521.

Shared API and existing frame-walker adaptation by Dylan M. Taylor.
Code and base are identical to storytold/craft-libs#2294 at
7f868f0a109aa1c301b79b9aa2c06626689fcd55; this replacement corrects attribution.

Co-authored-by: samhyun <rnflal31@gmail.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-11-18 18:40:24 -05:00
Dylan M. Taylor 6e7e752947 fix: resolve clippy nonminimal_bool and unexpected_cfgs on main (#2300) 2026-11-18 18:12:07 -05:00
Dylan M. Taylor ce7cefa554 fix: update JXL capability test and format craft-exr (#2298) 2026-11-18 17:58:04 -05:00
Dylan M. Taylor 3b8e426a26 feat(exr): add f32/f16 RGBA writer, compression modes, and chromaticities (#2281) 2026-11-18 17:20:52 -05:00
Dylan M. Taylor 010702ee9b chore: sync Cargo.lock with workspace (#2279) 2026-11-18 16:37:32 -05:00
Dylan M. Taylorandtexjer 6c034902b2 craft-develop: extract spline, curve, and lut modules from LightCraft (#587) (#2274)
Co-authored-by: texjer <texjer@gmail.com>
2026-11-18 16:30:48 -05:00
FredApps bba249ecbf Merge pull request #2270 from FredApps/fix/786-psd-tagged-descriptor-prefix
psd: add bounded recovering descriptor-block prefixes
2026-11-19 04:28:10 +07:00
texjer ad126d48f9 Merge branch 'craft-develop-inpaint' of https://github.com/texjer/craft-libs into craft-develop-inpaint
# Conflicts:
#	Cargo.lock
2026-11-18 16:13:52 -05:00
Dylan M. Taylor 816f745c02 Merge pull request #2023 from el-j/feat/video-mjpeg-frame
craft-video: Motion JPEG frames convert to VideoFrame (#1231)
2026-11-18 16:11:50 -05:00
texjer bf655268d7 craft-develop: a cancelled inpaint with an impossible patch radius is still cancelled 2026-11-18 16:09:33 -05:00
texjer 440235aadf Merge remote-tracking branch 'origin/main' into craft-develop-inpaint
# Conflicts:
#	Cargo.lock
2026-11-18 16:08:29 -05:00
.CooCoo b130ac1fa4 image-codecs: find the JPEG-LS frame header past 64 segments, and add detect_prefix (#2178)
* image-codecs: find the JPEG-LS frame header past 64 segments, and add detect_prefix

detect walked at most 64 marker segments looking for the SOF55 frame
header, so a JPEG-LS file with more segments before its frame header,
such as an ICC profile split over 255 APP2 segments, was reported as
JPEG. The walk now runs until it reaches a frame or scan header or the
end of the bytes. Each step moves forward at least one byte, so the walk
takes at most one step per byte.

detect also reported JPEG for a buffer that ended before the frame
header, which is what a caller that reads only the start of a file
passes. The new detect_prefix returns Detection::NeedBytes(n) in that
case, with the length the next step reads, and otherwise the answer
detect gives. The doc comment on detect now says that it needs the bytes
up to the frame header.

* image-codecs: walk each JPEG marker segment once when detecting in steps

detect_prefix walks the marker segments from the SOI on every call, so a
caller that reads exactly the length each Detection::NeedBytes asks for
walks the earlier segments again on each call. Over a file with many
small segments before its frame header, the total walk grows with the
square of the segment count.

The new PrefixDetector keeps the offset of the marker where its last
walk stopped and starts the next walk there. Its detect gives the same
answer and asks for the same lengths as detect_prefix, and
detect_prefix now runs a single step of a new PrefixDetector.

* image-codecs: read past a JPEG-LS restart interval segment and stop at FF 00

The JPEG-LS frame walk treated a DRI segment before the SOF55 frame header
as the end of the walk, so a file with one was detected and decoded as
JPEG. DRI now takes the length-prefixed path. The decoder accepts a 2-, 3-
or 4-byte interval of 0, reports a nonzero interval as unsupported, and
rejects other segment sizes as malformed.

`FF 00` after the SOI is a stuffed zero, not a marker, so the walk now ends
there instead of asking for a length field.

A PrefixDetector whose walk stopped at another frame header answers JPEG
for bytes that start with `FF D8 FF`, without walking from the SOI again.

* image-codecs: apply the JPEG-LS restart interval in effect at each scan

A later DRI with an interval of 0 turns restarts off again, and an
interval of at least the frame height puts a non-interleaved scan in
one interval with no restart marker. Both decode again. A nonzero
interval shorter than the frame height is still unsupported.

* image-codecs: reject a restart marker after a JPEG-LS scan of one interval

A restart marker comes only between two restart intervals. When the
interval in effect is at least the frame height, the scan is one
interval, so a restart marker after it, with or without fill bytes
before it, is now an error instead of being skipped.

Adds a test that a PrefixDetector starts each call at the marker where
its previous walk stopped.
2026-11-18 15:52:55 -05:00
.CooCoo 37724ad48d craft-image-codecs: lossy WebP encoding no longer copies the luma plane for every macroblock (#1975)
The VP8 encoder cloned the whole luma reconstruction before each
macroblock's B_PRED trial and restored it when a whole-block mode won,
so encoding P pixels copied about P^2/256 bytes. The trial writes only
the current macroblock, and the whole-block path writes every pixel of
that macroblock again without reading the trial's values, so the copy
and the restore are removed.

The output is byte-identical: a new test pins the SHA-256 of ten
encoded files (1x1 to 640x480, sizes that are not multiples of 16,
qualities 10 to 95) taken before the change, and decodes each with
image-webp. An ignored test prints encode times for 512 to 4096
squares; in release on one machine, 4096x4096 took 162.9 s before and
1.36 s after.
2026-11-18 15:51:10 -05:00
Kevin Joseph 041bafa259 craft-docx: keep a table style's w:tblInd on read and save (#2196)
* craft-docx: keep a table style's w:tblInd on read and save

A table style's own indent was dropped on read, so it was gone on save.
pandoc's Table style sets it to 0, and Word for Mac places a table whose
style chain sets no indent about 5.4 pt further right than one set to 0.

craft-wordmodel gains TableStyleParts::indent, merged through basedOn.
The reader takes a dxa indent (nil is 0; pct and auto set none) and the
writer emits it in schema order, 0 included.

Part of storytold/wordcraft#5767.

* craft-docx: a table style's w:tblInd without w:w is 0

CT_TblWidth's w:w defaults to 0, so the style resets a based-on style's
indent instead of inheriting it. The test helper now fails when a saved
style is missing rather than matching an empty string.

* craft-docx: the tblInd override test checks the base sets an indent

Without it the test would pass if the reader dropped the base style's
indent, since there would be nothing to override.
2026-11-18 15:35:42 -05:00
Kevin Joseph 0c3793eadd craft-docx: theme font slots survive a save (#2197)
* craft-docx: theme font slots survive a save

w:rFonts' w:eastAsiaTheme and w:cstheme slots are kept on read and written
back. Word picks the East Asian and complex-script fonts through them, so
dropping them changed which font Word used for East Asian punctuation and
its line breaks. The Latin slots (w:asciiTheme, w:hAnsiTheme) are kept when
the run's font came from them and written back only while they still name
that font in the document's theme, so a font chosen later is not hidden.

craft-wordmodel: a one-byte ThemeFont and CharProps font_ascii_theme,
font_hansi_theme, font_ea_theme and font_cs_theme. Overlaying a named font
without its slot clears the slot; minus keeps a slot whose font stays.

Ported from storytold/wordcraft#5772.

* craft-docx: keep the theme's East Asian and script fonts; exact slot replacement

The saved theme wrote empty a:ea and a:cs faces and no per-script fonts, so
a kept w:eastAsiaTheme or w:cstheme slot named no font in Word. The reader
now keeps the theme's ea, cs and a:font script entries (THEME_FONTS) and
the writer puts them back.

craft-wordmodel: a named font replaces both Latin slots with its own, so a
patch with one slot no longer leaves the other stale. minus keeps a font
equal to the base's when its slots differ, so a font that clears the
base's slots still clears them when overlaid. latin_slot compares the
theme face without cloning it.

* craft-docx: theme fonts keep faces and scripts apart; limit only usable scripts

THEME_FONTS lines now say whether they hold a default face (a:ea, a:cs) or a
per-script font, so an a:font script="cs" is no longer written back as the
a:cs face. The 256-entry limit applies to usable per-script fonts only, so
empty default faces no longer push the last one out.

A test pins down Latin slots that name different faces: the model has one
Latin font, so only the slot that still names it is written.

* craft-docx: a long theme script id never pushes out one font resolution uses

The kept per-script fonts count script ids of 8 characters or fewer (the
ones font resolution takes) and longer ones (language tags such as
zh-Hant-TW) apart, 256 each, so a long one can't use up the place of a
mapping resolution keeps.

* craft-docx: THEME_FONTS names both per-script caps
2026-11-18 15:35:36 -05:00
Kevin JosephandNghiathan13 6242f65262 craft-docx: a table border without w:sz is width 0, and ODT and RTF keep it (#2203)
* craft-docx: a DOCX border without w:sz is an eighth of a point

* craft-docx: a table border without w:sz is width 0, and ODT and RTF keep it

A table, cell or table-style border without w:sz gives the same output in
Word as w:sz="0" and takes no room; read as half a point, rows below a
pandoc table's header rule moved down half a point. PropCtx::table_borders
now reads it as 0, as PropCtx::borders does since #1488.

ODT and RTF have no border that is drawn and takes no room, so a drawn
width-0 cell side is written at Border::THINNEST instead of being dropped.
Where two ODT cells share an edge, a line with a width wins over a width-0
one, whichever cell states it.

Table half of storytold/wordcraft#5764.

---------

Co-authored-by: Nghiathan13 <201675788+Nghiathan13@users.noreply.github.com>
2026-11-18 15:35:29 -05:00
ARCandARC 1846851756 fix(docx): a VML shape whose v:stroke is off or fully transparent has no outline (#2226)
The VML reader took a shape's outline from its stroked and strokecolor
attributes only, so a v:stroke child with on="f" or opacity="0" was
ignored and the shape got a black 0.75 pt outline. Google Docs writes
its horizontal rules this way (a 0.05 pt v:rect with a transparent
stroke): Word shows nothing, and after a save every rule became a
visible line.

Each stroke property (on, color, opacity, endcap) now resolves as Word
does: the shape's own v:stroke, then the shape's attribute (stroked,
strokecolor), then the same two on its shapetype. A fully transparent
line is kept as a shape without an outline, and freeforms take the
resolved opacity, inherited ones included. Opacity is read in all three
forms a file can use (0, 0% and 65536ths such as 0f).

Moved from storytold/wordcraft#3829, where it was reviewed, now that
the DOCX reader lives here.

Co-authored-by: ARC <261443955+arc-uri-el@users.noreply.github.com>
2026-11-18 15:35:22 -05:00
ARCandARC da69193a2f fix(docx): write and read a turned object's effect extent as Word does (#2227)
From 45° up to 135° and from 225° up to 315°, Word measures the room a
turned object's rotated bounds take against its frame with width and
height exchanged, so a quarter turn records no effect extent. craft-docx
measured it against the unturned frame, so saving a picture turned 90°
wrote half the difference between its sides as negative top and bottom
extents, which Word draws as a crop, and the text after it moves up.
Reading had the same mismatch the other way: a picture Word turned 60°
gained phantom effects room above and below.

Float::effect_spin_pad gives the overhang in Word's measure, choosing the
frame from the angle as it is saved (60000ths of a degree), so an angle
such as 44.999996° is measured as the 45° it is written as. The docx
reader and both writers use it; a bare turn (Float::is_bare_turn) still
records none, and layout keeps spin_pad and line_pad.

The test reads and saves a 254 x 337 pt picture with the extents Word
for Microsoft 365 (build 16.0.20527) writes at 60° and 90° and on both
sides of each boundary (44/45, 134/135, 224/225, 314/315), and reads the
saved file back. Two existing tests asserted the old values and now use
Word's.

Moved from storytold/wordcraft#3828, where it was reviewed, now that the
DOCX reader and writer live here.

Co-authored-by: ARC <261443955+arc-uri-el@users.noreply.github.com>
2026-11-18 15:35:16 -05:00
.CooCoo 95cd2c0eb7 Add craft-color-transform: RGB spaces, white balance, OkLab, tone curves and PQ tone mapping (#1995)
* Add craft-color-transform: RGB spaces, white balance, OkLab, tone curves and PQ tone mapping

craft-color-transform builds on craft-color. It holds RGB spaces from
primaries and a white point with Bradford adaptation, white balance by
correlated color temperature and tint, OkLab and OkLCh for any RGB space,
monotone tone curves and 1D lookup tables, and the BT.2408-8 Annex 5 EETF
with a maxRGB tone map. The per-pixel functions take f32 and do not
allocate, and the crate builds for wasm32-unknown-unknown.

Moved from StudioCraft's craft-color-transform
(blamejs/StudioCraft crates/craft-color-transform). The README names the
LightCraft and FilmCraft modules parts of it started from.

* Color transform: compose, interpolate and invert at extreme values

Lut1::compose samples the densest grid of at most MAX_LUT entries that holds both tables' points, so a short inner table, or one that crosses an outer peak between its own points, keeps the outer table's points to within one grid step. Lut1::eval weights the two entries in f64, so entries as far apart as -f32::MAX and f32::MAX no longer give NaN or infinity. MonotoneCurve::new compares the tangent pair's length with 3|d|, so a subnormal secant next to a normal one no longer gives a NaN tangent. Mat3::inverse divides the matrix by its largest entry before taking the determinant, so diag(1e110) and diag(1e-200) invert. OkLab::for_space falls back to XYZ_TO_LMS when a matrix has no inverse or an entry beyond f32.

* Color transform: build the matrix arithmetic on craft_cms::math

craft_cms::math gains the two hardened functions the color transforms
need, and craft-color-transform calls them instead of carrying its own
copies.

- math::inverse divides the matrix by its largest entry before taking
  the determinant, so a matrix whose own determinant overflows or
  underflows still inverts, and it returns None for NaN, infinite or
  all-zero input and for an inverse beyond f64. math::invert keeps its
  absolute 1e-12 floor, which profile construction uses to validate ICC
  matrices.
- math::bradford_checked returns None when a white's cone response is
  not finite or not above 0, or the ratios overflow. math::bradford
  still divides without the check.
- math::BRADFORD is public.
- Mat3::mul, apply, determinant and inverse, Xy::to_xyz, BRADFORD and
  bradford_xyz call craft_cms::math.
- oklab::lms_matrices gives OkLab::for_space's matrices in f64.

* Color transform: keep the EETF's black lift rising for a high target black

The BT.2408 Annex 5 lift minLum * (1 - E2)^4 has a slope of 1 - 4 minLum
at E2 = 0, so a target black above a quarter of the normalized range
made the output fall near black, and it raised the peak well above the
target peak.

The lift is now minLum * (1 - E2 / r)^k with r = max(T, min(1, 2 -
4 minLum)) and k = min(4, r / minLum), where T is the top of the output
(the smaller of maxLum and 1). It equals the Annex's lift up to minLum
0.25, keeps the output rising, changes continuously with the target
black, and from minLum 0.5 reaches 0 at the top of the output. A target
black above the source peak reads as the source peak.

* Color transform: state the composition bound for the fallback grid
2026-11-18 15:35:09 -05:00
Tex Jernigan db9e24391a craft-develop-model and craft-geom: develop settings and crs: import, from LightCraft (#1132)
* craft-geom and craft-develop-model: develop settings and crs: import, from LightCraft

craft-develop-model is lightcraft-develop (settings, controls, presets,
segmentation masks, process versions) plus the crs: import from
lightcraft-engine (crs.rs, crs_masks.rs). craft-geom is lightcraft-geom,
which the model and the coming develop pipeline both need. Step 3 of #587.

* craft-develop-model, craft-geom: review fixes to copy, presets, section reset and crs: import

Copy and presets: to_json_for_merge states every setting the stored JSON
leaves out at its default, so copying a group turns HDR, the camera's local
tone and Lens Blur's optional settings off on the target, and a preset at an
amount starts from them. A preset at no amount adds no mask, and its Lens
Blur focus mask follows its mask to the id the photo gives it.

Reset and range: reset_section resets the sliders of point colours and red
eyes, Upright with its guides, and the two Optics switches. Settings from
outside the app keep the list sliders in range. is_unedited counts a chosen
white balance as an edit.

crs: import: a brush dab that is not a finite number is dropped instead of
failing the whole packet, brush runs that differ in MaskInverted stay two
components, RetouchInfo is read only without RetouchAreas, and an XMP preset
keeps its masks. SegMask::from_logits does not overflow on an absurd side.

craft-geom: Homography::from_quads solves a mapping that sends the origin
to infinity, by solving again about the middle of the source quad.

Docs: the links to LightCraft's light-v3.md and grain.md point at that
repository, and xmp-interop.md says when the older fields are read. The
README lists what now differs from LightCraft.

* craft-develop-model, craft-geom: second round of review fixes to crs: import, mask grids, crop and quads

A range mask with a number that is not one failed the whole merge; a straight legacy ToneCurve and a
photo's switched-off masks or spots were left unsaid, so the photo kept what it had; a mask grid of a
side past the limit was cut to 32 bits; a crop restored under a new angle could reach outside the
photo; a quad mapping onto a collapsed quad solved to a matrix that does not map it.
2026-11-18 15:35:02 -05:00
mmazzieriandMauro Mazzieri 5bd7eb9e88 craft-rtf: read text boxes and drawing shapes from \shpinst (#2059)
Ported from storytold/wordcraft#6242 (issue storytold/wordcraft#6212), written before the RTF reader
moved here. Rectangles, ellipses, triangles, diamonds, block arrows and text boxes are read from
the shape's properties (position, size, wrap, fill, line, text); the \defshp picture Word writes
after a shape it read, also inside \shppict, is not imported as a second copy.

Co-authored-by: Mauro Mazzieri <mauro.mazzieri@talete.net>
2026-11-18 15:31:52 -05:00