Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor 35d043fe70 docs: prefer shared craft-libs implementations 2026-11-16 06:27:34 -05:00
9 changed files with 41 additions and 50 deletions
-3
View File
@@ -18,7 +18,4 @@ jobs:
sonarcloud:
# Tracked at @main so org-wide CI improvements propagate without PR churn.
uses: storytold/craft-common-actions/.github/workflows/sonarcloud.yml@main
with:
# Same craft-fonts commit as ci.yml: the UI glyph tests need its CJK and Arabic fonts.
fonts-ref: b076417b5880bd4154bd22f00695b1d28c6bea83
secrets: inherit
+4
View File
@@ -138,3 +138,7 @@ Progress docs: `ROADMAP.md` (stage, headline numbers, progress log), `docs/targe
- Some workflow files here still run their own jobs. Don't add to them. Moving a job into craft-common-actions is its own task, never part of another PR, and the job stays here until a shared workflow runs it.
New workspace crates include `workspace = true` under `[lints]` in `Cargo.toml`. Production crate roots declare the crate-level lint attributes before modules; crate-level `//!` documentation may precede them.
## Shared-library reuse
Before implementing file formats, codecs, protocols or reusable UI components, check [storytold/craft-libs](https://github.com/storytold/craft-libs) and relevant open PRs; reuse or extend shared APIs instead of duplicating app-local implementations. Keep app-specific policy and adapters local, preserve behavior and format fidelity, security and resource limits, repository layering and regression tests, and document any shared-API gap rather than silently reducing functionality.
Generated
+1 -11
View File
@@ -1248,7 +1248,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa
dependencies = [
"brotli-decompressor 6.3.1",
"chrono",
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=41fb227542efb8a7748caa1c659f271d8605303c)",
"craft-tiff",
"quick-xml 0.41.0",
"serde",
]
@@ -1401,15 +1401,6 @@ dependencies = [
"thiserror 2.0.21",
]
[[package]]
name = "craft-tiff"
version = "0.1.0"
source = "git+https://github.com/storytold/craft-libs?rev=6ef2c053dfa758a9e292ff6ce4398bcd84aab1a1#6ef2c053dfa758a9e292ff6ce4398bcd84aab1a1"
dependencies = [
"serde",
"thiserror 2.0.21",
]
[[package]]
name = "craft-ui"
version = "0.1.0"
@@ -7416,7 +7407,6 @@ name = "wordcraft-geom"
version = "0.18.1"
dependencies = [
"craft-image-codecs",
"craft-tiff 0.1.0 (git+https://github.com/storytold/craft-libs?rev=6ef2c053dfa758a9e292ff6ce4398bcd84aab1a1)",
"image",
"serde",
]
-3
View File
@@ -68,7 +68,6 @@ brotli-decompressor = "5"
vello_cpu = "0.2"
image = { version = "0.25", default-features = false }
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "41fb227542efb8a7748caa1c659f271d8605303c", version = "=0.1.0" }
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "6ef2c053dfa758a9e292ff6ce4398bcd84aab1a1", version = "=0.1.0" }
craft-pdf = { git = "https://github.com/storytold/craft-libs", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", version = "=0.1.0", default-features = false, features = ["write"] }
# craft-update: app-specific pretend versions apply to startup and manual checks.
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] }
@@ -123,8 +122,6 @@ arboard = { version = "3.7", default-features = false, features = ["wayland-data
[workspace.lints.rust]
unsafe_code = "forbid"
# cargo llvm-cov sets `--cfg coverage`; timing tests skip themselves under its instrumentation.
unexpected_cfgs = { level = "warn", check-cfg = ["cfg(coverage)"] }
[workspace.lints.clippy]
cognitive_complexity = "deny"
+1 -2
View File
@@ -10,10 +10,9 @@ workspace = true
[features]
# Picture decoding within a memory budget (`picture`), for the crates that decode pictures.
image = ["dep:image", "dep:craft-image-codecs", "dep:craft-tiff"]
image = ["dep:image", "dep:craft-image-codecs"]
[dependencies]
craft-image-codecs = { workspace = true, optional = true }
craft-tiff = { workspace = true, optional = true }
image = { workspace = true, optional = true }
serde = { workspace = true }
+30 -1
View File
@@ -539,7 +539,36 @@ fn worst_coefficients(bytes: &[u8]) -> u64 {
/// tag is missing. None when the header can't be read, or when the tag appears more than once:
/// the decoder keeps the last copy, so a harmless first one must not hide a JPEG one after it.
fn tiff_compression(bytes: &[u8]) -> Option<u16> {
craft_tiff::probe::first_image_compression(bytes)
let le = match bytes.get(..4)? {
b"II*\0" => true,
b"MM\0*" => false,
_ => return None,
};
let u16_at = |at: usize| -> Option<u16> {
let b = [*bytes.get(at)?, *bytes.get(at.checked_add(1)?)?];
Some(if le { u16::from_le_bytes(b) } else { u16::from_be_bytes(b) })
};
let u32_at = |at: usize| -> Option<u32> {
let b: [u8; 4] = bytes.get(at..at.checked_add(4)?)?.try_into().ok()?;
Some(if le { u32::from_le_bytes(b) } else { u32::from_be_bytes(b) })
};
let ifd = usize::try_from(u32_at(4)?).ok()?;
let mut found = None;
for i in 0..usize::from(u16_at(ifd)?) {
let entry = ifd.checked_add(2)?.checked_add(i.checked_mul(12)?)?;
if u16_at(entry)? != 259 {
continue;
}
if found.is_some() || u32_at(entry.checked_add(4)?)? != 1 {
return None;
}
found = Some(match u16_at(entry.checked_add(2)?)? {
3 => u16_at(entry.checked_add(8)?)?,
4 => u16::try_from(u32_at(entry.checked_add(8)?)?).ok()?,
_ => return None,
});
}
Some(found.unwrap_or(1))
}
/// A DIB with a V4 or V5 header in the layout the decoder reads. A 32-bit one whose alpha mask
+5 -11
View File
@@ -718,18 +718,12 @@ pub(crate) fn place_objects(ctx: &mut Ctx, req: &ObjectPlacement) -> (Vec<Placed
// (#4250). Inline objects go with their own line.
let first = l0 == 0;
let late = at.late.filter(|l| !l.placed.is_empty());
// A later piece looks only at its own lines and those holding the anchors of the late floats
// it draws, in order: walking every line of the paragraph for each piece made a paragraph of
// many pages quadratic (#6757).
let (piece, mut late_lines) =
if first { (0..pl.lines.len(), Vec::new()) } else { (l0..l1.min(pl.lines.len()), late.map(LateFloats::lines_here).unwrap_or_default()) };
late_lines.retain(|li| !piece.contains(li));
late_lines.sort_unstable();
late_lines.dedup();
let (before, after) = late_lines.split_at(late_lines.partition_point(|li| *li < piece.start));
for li in before.iter().copied().chain(piece).chain(after.iter().copied()) {
crate::work::steps(1);
let late_lines = late.map(LateFloats::lines_here).unwrap_or_default();
for li in 0..pl.lines.len() {
let in_piece = (l0..l1).contains(&li);
if !in_piece && !first && !late_lines.contains(&li) {
continue;
}
let Some(line) = pl.lines.get(li) else { continue };
for k in line.c0..line.c1 {
let Some(c) = pl.clusters.get(k) else { continue };
-3
View File
@@ -914,7 +914,6 @@ fn long_word_beside_a_float(n: usize) -> Document {
/// A word with no break opportunity in it: measuring the word for every line it takes scanned
/// the whole paragraph each time, so the layout was quadratic in the word's length.
#[test]
#[cfg_attr(coverage, ignore = "coverage instrumentation skews the time ratio")]
fn a_long_unbreakable_word_lays_out_in_linear_time() {
let (t1, tk, ratio) = layout_time_ratio(long_word_beside_a_float, 50_000, &LayoutOptions::default());
eprintln!("t(n) {t1:.4} s, t(8n) {tk:.4} s, ratio {ratio:.1}");
@@ -1135,7 +1134,6 @@ fn long_word_with_alternating_advances_beside_a_float(n: usize) -> Document {
/// A word whose advances alternate in sign lays out in linear time: the measurement that asks
/// whether it would fit the full line must not walk the word again for every line it takes.
#[test]
#[cfg_attr(coverage, ignore = "coverage instrumentation skews the time ratio")]
fn a_word_with_alternating_advances_lays_out_in_linear_time() {
let (t1, tk, ratio) = layout_time_ratio(long_word_with_alternating_advances_beside_a_float, 50_000, &LayoutOptions::default());
eprintln!("t(n) {t1:.4} s, t(8n) {tk:.4} s, ratio {ratio:.1}");
@@ -7841,7 +7839,6 @@ fn a_no_break_space_before_a_slash_still_holds() {
}
#[test]
#[cfg_attr(coverage, ignore = "coverage instrumentation skews the time ratio")]
fn unequal_formats_lay_out_in_linear_time() {
crate::test_fonts();
// Runs whose formats never compare equal (NaN spacing from a hostile file) each get a style;
-16
View File
@@ -223,22 +223,6 @@ fn selecting_a_long_endnote_takes_linear_time() {
assert_linear_steps("endnote selection", 20, laid, |(d, l, (a, b))| drop(std::hint::black_box(l.selection_rects(d, a, b, 0))));
}
/// One paragraph of `n` lines (a line break after each word), so it runs over many pages.
fn many_lines(n: usize) -> Document {
let mut d = Document::from_text("");
d.body = vec![wordcraft_doc::para_block(Paragraph::with_text(&"x\n".repeat(n), CharProps::default()))];
d
}
/// The piece of a long paragraph on each page looked through every line of the paragraph for the
/// pictures and shapes to draw with it (#6757).
#[test]
fn a_paragraph_over_many_pages_lays_out_in_linear_time() {
let pages = lay(&many_lines(SCALE * 400), &LayoutOptions::default()).pages.len();
assert!(pages > 40, "the paragraph runs over many pages: {pages}");
assert_layout_linear("a paragraph over many pages", 400, many_lines, &LayoutOptions::default());
}
/// A table of `n` rows of 60 cells, each row exactly half a point high, so every cell clips its
/// (empty) paragraph and the whole table fits on the first page.
fn clipped_table(n: usize) -> Document {