Compare commits

..
Author SHA1 Message Date
Dylan M. Taylor aac8bf08f5 ci: notify artcraft-services on release state changes 2026-11-26 21:56:44 -05:00
FredApps 74591abae8 Merge pull request #2155 from gmrmad1/fix/1683-hanging-indent-tab-stop
text: a hanging indent is the first tab stop (#1683)
2026-11-26 14:52:01 +01:00
FredApps a0f0ad5772 Compare a tab stop past the line's edge with the hanging indent at the edge
A stop past the right edge takes effect at the edge, so tab_advance now clamps
the explicit candidate before deciding whether it beats the hanging indent.
With x=0, hang=80, right edge 60 and a right stop at 700, the tab now advances
to 40 (right-aligned at the edge) instead of 80. Answers CodeRabbit's review.
2026-11-26 20:42:45 +07:00
FredApps cd468b5b57 Merge branch 'main' into fix/1683-hanging-indent-tab-stop 2026-11-26 14:10:19 +01:00
FredApps 1a0c12eb75 Merge pull request #2032 from storytold/autocraft/fix-2029-line-chart-legend-key-is-a-fil
Fix line chart legend key is a filled square instead of the series line
2026-11-26 14:10:03 +01:00
FredApps 8158ee3370 Merge branch 'main' into autocraft/fix-2029-line-chart-legend-key-is-a-fil 2026-11-26 13:55:31 +01:00
FredApps 6613ae8686 Merge pull request #2031 from storytold/autocraft/fix-2028-chart-legend-ignores-per-point
Fix chart legend ignores per-point colours (c:dPt) on pie charts
2026-11-26 13:55:16 +01:00
FredApps 65a32bc3ef Merge main into fix/1683-hanging-indent-tab-stop
Conflicts in crates/text/src/breaking.rs and layout.rs: #2154 (just merged) gave tab_advance and line_advances a right-edge argument, and this PR gave them the hanging-indent stop. Both arguments are kept (hang, then right/avail), with both doc paragraphs, and main's new tab tests pass None for hang. cargo test -p deckcraft-text and cargo fmt --check pass locally.
2026-11-26 19:53:47 +07:00
FredApps 373263da58 Merge branch 'main' into autocraft/fix-2028-chart-legend-ignores-per-point 2026-11-26 13:41:42 +01:00
FredApps 9a6d851daf Merge pull request #2154 from gmrmad1/fix/1659-audio-icon-hidden
show: an audio icon with Hide During Show stays hidden while it plays (#1659)
2026-11-26 13:39:22 +01:00
FredApps f4d2f5f3e3 Merge branch 'main' into fix/1659-audio-icon-hidden 2026-11-26 13:29:16 +01:00
FredApps 4f5607f764 Merge pull request #2141 from gmrmad1/fix/1663-right-tab-stop-at-margin
text: a tab stop past the right margin sits at it (#1663)
2026-11-26 13:28:59 +01:00
FredApps dbd7c66e05 Merge branch 'main' into fix/1663-right-tab-stop-at-margin 2026-11-26 13:18:53 +01:00
Madhav Agarwal fc253bdb29 review: limit the hanging-indent tab stop to LTR first lines (coderabbit/rtl scope and later-line stop) 2026-11-16 18:12:23 +05:30
Madhav Agarwal 1add4c138b review: clamp a tab stop to the line's absolute right edge (coderabbit/relative-width clamp) 2026-11-16 18:09:48 +05:30
Madhav Agarwal 87af318469 text: a hanging indent is the first tab stop (#1683) 2026-11-15 21:43:04 +05:30
Madhav Agarwal edb303d966 show: an audio icon with Hide During Show stays hidden while it plays (#1659) 2026-11-15 21:12:58 +05:30
Madhav Agarwal 5a6add630e text: a tab stop past the right margin sits at it (#1663) 2026-11-15 14:37:52 +05:30
autocraft-bot[bot] ca819f1477 Apply review fixes
- crates/render/src/chart.rs
2026-11-11 14:33:36 +00:00
autocraft-bot[bot] 0175c6c21d Fix line chart legend key is a filled square instead of the series line
Fixes #2029.

- crates/render/src/chart.rs
- crates/model/src/chart.rs
- crates/render/tests/autocraft_regression_2029.rs
2026-11-11 13:47:52 +00:00
autocraft-bot[bot] 6df9331b52 Fix chart legend ignores per-point colours (c:dPt) on pie charts
Fixes #2028.

- crates/render/src/chart.rs
- crates/render/tests/autocraft_regression_2028.rs
2026-11-11 13:47:42 +00:00
17 changed files with 364 additions and 38 deletions
+9 -9
View File
@@ -5,21 +5,21 @@ version: 'v0.0.3'
workflows:
'.github/workflows/ci.yml':
- 'actions/checkout@v7.0.1'
- 'step-security/harden-runner@v2.23.0'
- 'step-security/harden-runner@v2.22.4'
'.github/workflows/freebsd.yml': []
'.github/workflows/house-rules.yml': []
'.github/workflows/lockfile.yml':
- 'actions/checkout@v7.0.1'
- 'step-security/harden-runner@v2.23.0'
'.github/workflows/nightly-macos.yml':
- 'actions/checkout@v7.0.1'
- 'step-security/harden-runner@v2.23.0'
- 'step-security/harden-runner@v2.22.4'
'.github/workflows/nightly-sign.yml': []
'.github/workflows/nightly.yml': []
'.github/workflows/nightly-macos.yml':
- 'actions/checkout@v7.0.1'
- 'step-security/harden-runner@v2.22.4'
'.github/workflows/nix.yml': []
'.github/workflows/packaging-lint.yml':
- 'actions/checkout@v7.0.1'
- 'step-security/harden-runner@v2.23.0'
- 'step-security/harden-runner@v2.22.4'
'.github/workflows/release.yml': []
'.github/workflows/sonarcloud.yml': []
'.github/workflows/windows-arm64.yml': []
@@ -29,8 +29,8 @@ dependencies:
commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
owner_id: 44036562
repo_id: 197814629
'step-security/harden-runner@v2.23.0':
ref: 'v2.23.0'
commit: 'sha1-aebdcf6156ab6691adf63218240e476564a1ed4c'
'step-security/harden-runner@v2.22.4':
ref: 'v2.22.4'
commit: 'sha1-1d88384fd173af6ecb012dfd0264a306b711241a'
owner_id: 88700172
repo_id: 422287306
+1 -1
View File
@@ -27,7 +27,7 @@ jobs:
CRAFT_FONTS_REF: 37827adc41fd165f9a9234ac40f94dbad353aa69
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.23.0
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- name: Check out craft-fonts
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
timeout-minutes: 10
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.23.0
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7.0.1
+1 -1
View File
@@ -36,7 +36,7 @@ jobs:
RUST_BACKTRACE: 1
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.23.0
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7.0.1
+1 -1
View File
@@ -34,7 +34,7 @@ jobs:
checks: read
attestations: write
id-token: write
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@4ec2a14646b538253fd5ebe109bf463a3d31b061
uses: storytold/craft-common-actions/.github/workflows/nightly-release.yml@be00e5ccd18b68e950c8a08532f2230e7c3d0cba
with:
tooling-revision: be00e5ccd18b68e950c8a08532f2230e7c3d0cba
app-name: deckcraft
+1 -1
View File
@@ -22,7 +22,7 @@ jobs:
actions: read
attestations: write
id-token: write
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@4ec2a14646b538253fd5ebe109bf463a3d31b061
uses: storytold/craft-common-actions/.github/workflows/nightly-unsigned.yml@be00e5ccd18b68e950c8a08532f2230e7c3d0cba
with:
tooling-revision: be00e5ccd18b68e950c8a08532f2230e7c3d0cba
app-name: deckcraft
+19
View File
@@ -0,0 +1,19 @@
name: Notify Services on Release Change
on:
release:
types:
- published
- unpublished
- created
- edited
- deleted
- prereleased
- released
permissions: {}
jobs:
notify:
uses: storytold/craft-common-actions/.github/workflows/notify-services.yml@main
secrets: inherit
+2 -2
View File
@@ -28,7 +28,7 @@ jobs:
runs-on: windows-latest
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.23.0
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7.0.1
@@ -58,7 +58,7 @@ jobs:
contents: read
steps:
- name: Harden runner
uses: step-security/harden-runner@v2.23.0
uses: step-security/harden-runner@v2.22.4
with:
egress-policy: audit
- uses: actions/checkout@v7.0.1
+10
View File
@@ -254,6 +254,16 @@ pub struct MediaClip {
pub height: u32,
}
impl MediaClip {
/// Whether the clip's frame (an audio icon, or a video's poster) stays out of the
/// show picture. `playing` is true while the voice exists and has not ended.
/// Audio with "Hide During Show" set stays hidden even while it plays; video with
/// "Hide While Not Playing" set shows its frame while it plays.
pub fn hidden_during_show(&self, playing: bool) -> bool {
self.hide_while_not_playing && (!self.video || !playing)
}
}
/// One ink stroke (Draw tab): points in slide coordinates with pressure (`0..=1`,
/// where `1` is [`InkStroke::width`]).
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
+19 -3
View File
@@ -1,7 +1,7 @@
use super::{
ColorRef, Fill, LayoutType, Paragraph, PhType, Placeholder, Presentation, Run, RunProps, SchemeSlot, Shape, ShapeId, ShapeKind, ShapeStyle,
Slide, Table, TextBody, Theme, Xfrm, defaults, ink_pressure_is_legacy, ink_sample_width, parent_of, resolve, sibling_list_mut, style, text,
theme, walk,
ColorRef, Fill, LayoutType, MediaClip, Paragraph, PhType, Placeholder, Presentation, Run, RunProps, SchemeSlot, Shape, ShapeId, ShapeKind,
ShapeStyle, Slide, Table, TextBody, Theme, Xfrm, defaults, ink_pressure_is_legacy, ink_sample_width, parent_of, resolve, sibling_list_mut, style,
text, theme, walk,
};
use crate::resolve::Ctx;
@@ -339,3 +339,19 @@ fn colour_alpha_follows_alpha_mod_and_off() {
let both = base().with(ColorTransform::Alpha(40000)).with(ColorTransform::AlphaMod(50000));
assert!((both.alpha() - 0.2).abs() < 1e-9, "{}", both.alpha());
}
#[test]
fn hide_during_show_keeps_audio_hidden_while_playing() {
let clip = |video: bool, hide_while_not_playing: bool| MediaClip { video, hide_while_not_playing, ..Default::default() };
// Audio with the flag set stays hidden both idle and playing (#1659).
assert!(clip(false, true).hidden_during_show(false), "audio, flagged, idle");
assert!(clip(false, true).hidden_during_show(true), "audio, flagged, playing");
// Video with the flag set hides only while not playing.
assert!(clip(true, true).hidden_during_show(false), "video, flagged, idle");
assert!(!clip(true, true).hidden_during_show(true), "video, flagged, playing");
// Without the flag nothing is hidden.
assert!(!clip(false, false).hidden_during_show(false), "audio, unflagged, idle");
assert!(!clip(false, false).hidden_during_show(true), "audio, unflagged, playing");
assert!(!clip(true, false).hidden_during_show(false), "video, unflagged, idle");
assert!(!clip(true, false).hidden_during_show(true), "video, unflagged, playing");
}
+33 -8
View File
@@ -49,6 +49,8 @@ enum Paint {
Pattern(String, Rgba, Rgba),
/// `a:noFill`: only the outline, if any, shows.
Nothing,
/// A line series' legend key: its colour and width, and whether it carries a marker.
Line(Rgba, f64, bool),
}
/// The paint of fill `f` as a bar or legend key draws it; the palette's `fallback` when the file
@@ -72,6 +74,20 @@ fn fill_with(ctx: &mut RenderContext, p: &Paint, r: Rect, m: Affine) {
}
Paint::Pattern(name, fg, bg) => crate::pattern::fill(ctx, name, *fg, *bg, 1.0, &r.to_path(0.1), m),
Paint::Nothing => {}
Paint::Line(c, width, marker) => {
// A short stretch of the series' line through the key's middle, with the marker on it.
let mid = (r.y0 + r.y1) / 2.0;
let mut p = BezPath::new();
p.move_to((r.x0, mid));
p.line_to((r.x1, mid));
ctx.set_transform(m);
ctx.set_paint(color(*c, 1.0));
ctx.set_stroke(kurbo::Stroke::new(width.min(r.height() * 0.4)));
ctx.stroke_path(&p);
if *marker {
ctx.fill_path(&kurbo::Circle::new(((r.x0 + r.x1) / 2.0, mid), r.height() * 0.3).to_path(0.1));
}
}
}
}
@@ -97,6 +113,13 @@ fn bar_paint(ctx: &Ctx, c: &Chart, si: usize, pi: usize, s: &deckcraft_model::ch
paint_of(ctx, s.fill.as_ref(), series_color(ctx, c, si))
}
/// Colour of pie slice `i`: its `<c:dPt>` solid fill, else the palette's. Slices and legend keys share it.
fn pie_slice_color(ctx: &Ctx, c: &Chart, s: Option<&deckcraft_model::chart::Series>, i: usize) -> Rgba {
s.and_then(|s| s.point_fills.iter().find(|(k, _)| *k == i))
.and_then(|(_, f)| if let Fill::Solid { color: cc } = f { Some(ctx.color(cc, None)) } else { None })
.unwrap_or_else(|| series_color(ctx, c, i))
}
fn polyline(pts: &[Point]) -> BezPath {
let mut p = BezPath::new();
for (k, q) in pts.iter().enumerate() {
@@ -613,7 +636,7 @@ fn build_legend_items(rctx: &Ctx, c: &Chart, pie: bool, waterfall: bool) -> Vec<
// A map draws its own colour scale.
vec![]
} else if pie {
c.categories.iter().enumerate().map(|(i, n)| (n.clone(), Paint::Color(series_color(rctx, c, i)), None)).collect()
c.categories.iter().enumerate().map(|(i, n)| (n.clone(), Paint::Color(pie_slice_color(rctx, c, c.series.first(), i)), None)).collect()
} else {
c.series
.iter()
@@ -621,7 +644,14 @@ fn build_legend_items(rctx: &Ctx, c: &Chart, pie: bool, waterfall: bool) -> Vec<
.map(|(i, s)| {
let k = c.series_kind(s);
let line = !k.is_bar_like() && !matches!(k, ChartType::Area | ChartType::StackedArea | ChartType::FilledRadar);
if line {
if matches!(k, ChartType::Line | ChartType::LineMarkers | ChartType::StackedLine | ChartType::Radar) {
let lw = s.line.as_ref().and_then(|l| l.width).filter(|w| w.is_finite() && *w > 0.0).unwrap_or(2.25).clamp(0.25, 20.0);
(
s.name.clone(),
Paint::Line(series_line(rctx, c, i, s), lw, k == ChartType::LineMarkers || (k == ChartType::Radar && s.marker.is_some())),
None,
)
} else if line {
(s.name.clone(), Paint::Color(series_line(rctx, c, i, s)), None)
} else if k.is_bar_like() {
let paint = if c.vary_colors && c.series.len() == 1 && s.fill.is_none() {
@@ -1179,12 +1209,7 @@ fn draw_pie(ctx: &mut RenderContext, rctx: &Ctx, c: &Chart, m: Affine, area: Rec
p.extend(arc.append_iter(0.1));
p.close_path();
ctx.set_transform(m);
let col = s
.point_fills
.iter()
.find(|(k, _)| *k == i)
.and_then(|(_, f)| if let Fill::Solid { color: cc } = f { Some(rctx.color(cc, None)) } else { None })
.unwrap_or_else(|| series_color(rctx, c, i));
let col = pie_slice_color(rctx, c, Some(s), i);
ctx.set_paint(color(col, 1.0));
ctx.fill_path(&p);
ctx.set_paint(color(Rgba::WHITE, 1.0));
@@ -0,0 +1,20 @@
use deckcraft_color::Rgba;
use deckcraft_model::chart::ChartType;
use deckcraft_model::style::{ColorRef, Fill};
use deckcraft_model::{Chart, Presentation, Shape, ShapeId, ShapeKind, Xfrm};
use deckcraft_render::{RenderOpts, render_slide};
#[test]
fn pie_legend_keys_take_the_point_colours() {
let mut c = Chart::sample(ChartType::Pie);
c.title = None;
c.legend = Some("r".into());
c.series[0].point_fills = vec![(0, Fill::solid(ColorRef::rgb(Rgba::rgb(255, 0, 255))))];
let sh = Shape { id: ShapeId(2028), xfrm: Some(Xfrm::new(0.0, 0.0, 960.0, 540.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() };
let mut p = Presentation::default();
std::sync::Arc::make_mut(&mut p.slides[0]).shapes = vec![sh];
let img = render_slide(&p, 0, &RenderOpts { scale: 1.0, ..Default::default() });
// The pie stays well left of x = 850; only the legend column lies beyond it.
let key = (850..img.width).flat_map(|x| (0..img.height).map(move |y| (x, y))).filter(|(x, y)| img.pixel(*x, *y)[..3] == [255, 0, 255]).count();
assert!(key > 20, "the legend key of the overridden slice is drawn in its colour: {key} px");
}
@@ -0,0 +1,53 @@
use deckcraft_model::chart::ChartType;
use deckcraft_model::style::Line;
use deckcraft_model::{Chart, ColorRef, Presentation, Rgba, Shape, ShapeId, ShapeKind, Xfrm};
use deckcraft_render::{RenderOpts, render_slide};
/// Rows and columns of the pixels matching `want` in the legend's key column, right of the plot.
fn key_extent(kind: ChartType, want: &dyn Fn([u8; 4]) -> bool) -> (usize, usize) {
let mut c = Chart::sample(kind);
c.title = None;
c.legend = Some("r".into());
c.series.truncate(2);
for (s, (name, rgb)) in c.series.iter_mut().zip([("A", Rgba::rgb(255, 0, 0)), ("B", Rgba::rgb(0, 0, 255))]) {
s.name = name.into();
s.line = Some(Line::solid(ColorRef::rgb(rgb), 3.0));
}
let sh = Shape { id: ShapeId(1), xfrm: Some(Xfrm::new(0.0, 0.0, 960.0, 540.0)), kind: ShapeKind::Chart(Box::new(c)), ..Default::default() };
let mut p = Presentation::default();
std::sync::Arc::make_mut(&mut p.slides[0]).shapes = vec![sh];
let img = render_slide(&p, 0, &RenderOpts { scale: 1.0, ..Default::default() });
let hits: Vec<(u32, u32)> =
(870..img.width).flat_map(|x| (0..img.height).map(move |y| (x, y))).filter(|(x, y)| want(img.pixel(*x, *y))).collect();
let rows = hits.iter().map(|h| h.1).collect::<std::collections::BTreeSet<_>>().len();
let cols = hits.iter().map(|h| h.0).collect::<std::collections::BTreeSet<_>>().len();
(rows, cols)
}
fn red(p: [u8; 4]) -> bool {
p[0] > 200 && p[1] < 60 && p[2] < 60
}
fn blue(p: [u8; 4]) -> bool {
p[0] < 60 && p[1] < 60 && p[2] > 200
}
#[test]
fn line_chart_legend_key_is_a_stretch_of_the_line() {
// A 3 pt line key is a few pixels tall; a filled square key is over ten.
for want in [&red as &dyn Fn([u8; 4]) -> bool, &blue] {
let (rows, cols) = key_extent(ChartType::Line, want);
assert!((2..=5).contains(&rows), "line key is {rows} rows tall");
assert!(cols >= 8, "line key is {cols} columns wide");
}
}
#[test]
fn line_with_markers_legend_key_has_a_marker_on_the_line() {
// The marker is wider than the line but smaller than a filled square.
for want in [&red as &dyn Fn([u8; 4]) -> bool, &blue] {
let (rows, cols) = key_extent(ChartType::LineMarkers, want);
assert!((6..=10).contains(&rows), "marker key is {rows} rows tall");
assert!(cols >= 8, "marker key is {cols} columns wide");
}
}
+66 -6
View File
@@ -150,10 +150,13 @@ pub(crate) struct BreakParams<'a> {
pub(crate) default_tab: f64,
pub(crate) x0_first: f64,
pub(crate) x0_rest: f64,
/// Absolute position of the hanging-indent implicit stop (`marL`), when the first
/// line starts left of the margin. [`tab_advance`] treats it as a left stop.
pub(crate) hang: Option<f64>,
}
pub(crate) fn break_lines(p: &ParaShaped, params: &BreakParams) -> Vec<RawLine> {
let BreakParams { first_w, rest_w, wrap, tab_stops, default_tab, x0_first, x0_rest } = *params;
let BreakParams { first_w, rest_w, wrap, tab_stops, default_tab, x0_first, x0_rest, hang: hang_stop } = *params;
let text: String = p.cells.iter().map(|c| c.ch).collect();
let (allowed, _) = break_opportunities(&text, p.props.latin_line_break.unwrap_or(false));
let hang = p.props.hanging_punct.unwrap_or(false);
@@ -179,7 +182,8 @@ pub(crate) fn break_lines(p: &ParaShaped, params: &BreakParams) -> Vec<RawLine>
break;
}
let adv = if c == '\t' {
tab_advance(x0 + x, tab_stops, default_tab, tab_segment(&p.cells, i))
// The implicit stop is for the first line only: later lines start at the margin.
tab_advance(x0 + x, tab_stops, default_tab, tab_segment(&p.cells, i), if lines.is_empty() { hang_stop } else { None }, x0 + avail)
} else {
p.cells.get(i).map(|c| c.adv).unwrap_or(0.0)
};
@@ -305,11 +309,40 @@ pub(crate) fn tab_segment(cells: &[Cell], i: usize) -> (f64, f64) {
/// Advance of a tab at `x` (from the start edge) to the next stop, placing the text after it
/// (`seg`: its width, and its width before the decimal point) as the stop aligns it but never
/// moving back, as PowerPoint does; past the last stop, to the next default stop.
pub(crate) fn tab_advance(x: f64, stops: &[Tab], default_tab: f64, seg: (f64, f64)) -> f64 {
/// `hang` is the hanging-indent implicit stop (`marL`): the first tab on a first line that
/// starts left of the margin goes there instead, as PowerPoint does. The nearer of the
/// implicit and the regular stops wins; an explicit stop within 0.5 pt of it keeps its
/// own alignment.
///
/// `right` is the line's right edge in the same coordinate space as `x` (the text area's left
/// edge plus the line's start offset and width): a stop set past that edge acts as one at the
/// edge, as PowerPoint treats it (a right-aligned stop there ends the text at the margin).
pub(crate) fn tab_advance(x: f64, stops: &[Tab], default_tab: f64, seg: (f64, f64), hang: Option<f64>, right: f64) -> f64 {
// `stops` is in position order (`tabs_of`): the next stop is the first past x.
// A NaN `x` (a NaN spacing upstream) skips the lookup and takes the finite default-stop path.
if !x.is_nan()
&& let Some(h) = hang
&& h.is_finite()
&& x < h - 0.5
{
let explicit = stops.get(stops.partition_point(|s| s.pos <= x + 0.5));
let d = if default_tab > 1.0 { default_tab } else { 72.0 };
let default_next = ((x / d).floor() + 1.0) * d;
let explicit_wins = match explicit {
// Compared where the stop takes effect: one past the line's edge ends there (below).
Some(s) => {
let pos = if right.is_finite() && right > 0.0 { s.pos.min(right) } else { s.pos };
pos < h - 0.5 || (pos - h).abs() <= 0.5
}
None => h >= default_next - 0.5,
};
if !explicit_wins {
return (h - x).max(1.0);
}
}
if let Some(s) = stops.get(stops.partition_point(|s| s.pos <= x + 0.5)).filter(|_| !x.is_nan()) {
let to = s.pos - x;
let pos = if right.is_finite() && right > 0.0 { s.pos.min(right) } else { s.pos };
let to = (pos - x).max(0.0);
return match s.align {
TabAlign::Left => to,
TabAlign::Right => (to - seg.0).max(0.0),
@@ -329,7 +362,34 @@ mod tab_tests {
#[test]
fn a_nan_position_takes_the_finite_default_stop() {
let stops = [Tab { pos: 100.0, align: TabAlign::Left }];
assert!(tab_advance(f64::NAN, &stops, 72.0, (0.0, 0.0)).is_finite());
assert_eq!(tab_advance(10.0, &stops, 72.0, (0.0, 0.0)), 90.0);
assert!(tab_advance(f64::NAN, &stops, 72.0, (0.0, 0.0), None, 600.0).is_finite());
assert_eq!(tab_advance(10.0, &stops, 72.0, (0.0, 0.0), None, 600.0), 90.0);
}
#[test]
fn a_stop_past_the_edge_is_compared_with_the_hang_at_the_edge() {
// The 700 pt stop takes effect at the 60 pt edge, which comes before the 80 pt hang: it
// wins, and right-aligned text after it ends at the edge (60 - 20), not at the hang.
let stops = [Tab { pos: 700.0, align: TabAlign::Right }];
assert_eq!(tab_advance(0.0, &stops, 72.0, (20.0, 20.0), Some(80.0), 60.0), 40.0);
}
#[test]
fn a_stop_past_the_line_ends_at_its_edge() {
let stops = [Tab { pos: 700.0, align: TabAlign::Right }];
// Right-aligned text after the tab ends at the line's right edge, not 700.
assert_eq!(tab_advance(0.0, &stops, 72.0, (100.0, 100.0), None, 600.0), 500.0);
// A stop inside the line keeps its own position.
assert_eq!(tab_advance(0.0, &stops, 72.0, (100.0, 100.0), None, 800.0), 600.0);
}
#[test]
fn an_offset_line_clamps_to_its_absolute_right_edge() {
// The stop and the edge are absolute coordinates: a 100 pt start offset does not move the
// edge in to 500 pt, so an inside stop at 550 stays there and one past 600 ends at 600.
let inside = [Tab { pos: 550.0, align: TabAlign::Right }];
assert_eq!(tab_advance(100.0, &inside, 72.0, (100.0, 100.0), None, 600.0), 350.0);
let past = [Tab { pos: 700.0, align: TabAlign::Right }];
assert_eq!(tab_advance(100.0, &past, 72.0, (100.0, 100.0), None, 600.0), 400.0);
}
}
+15 -4
View File
@@ -233,6 +233,7 @@ struct ParaEnv<'a> {
first_x: f64,
rest_x: f64,
tabs: &'a [Tab],
hang: Option<f64>,
}
impl ParaEnv<'_> {
@@ -312,6 +313,12 @@ fn place_paragraph(p: &ParaShaped, pi: usize, g: &BoxGeom, spacing: (f64, bool),
let first_x = first_line_start(p.bullet.is_some(), margin, indent, bullet_w);
let rest_x = margin;
let tabs = tabs_of(props);
// A hanging first line (marL > 0, indent < 0) treats the indent position (marL) as an
// implicit tab stop for its first tab; later lines already start there, so the stop
// only ever applies ahead of the first line's start.
// LTR only: the implicit stop is measured from the left margin, and RTL tab handling is
// out of this change's scope (its stops are not mirrored here yet).
let hang = (!p.rtl && margin - first_x > 0.5 && margin.is_finite()).then_some(margin);
let first_w = (g.col_w - first_x - mr).max(1.0);
let rest_w = (g.col_w - rest_x - mr).max(1.0);
let raw = break_lines(
@@ -324,13 +331,14 @@ fn place_paragraph(p: &ParaShaped, pi: usize, g: &BoxGeom, spacing: (f64, bool),
default_tab: props.default_tab.unwrap_or(72.0),
x0_first: first_x,
x0_rest: rest_x,
hang,
},
);
// The first paragraph's space before counts only when the body says so.
let before = if pi == 0 && !first_last { 0.0 } else { spacing_pts(props.space_before, p.lead_size) };
flow.y += before.max(0.0) + flow.prev_after;
let first_line_idx = flow.lines.len();
let env = ParaEnv { p, g, reduce, margin, indent, mr, bullet_w, first_x, rest_x, tabs: &tabs };
let env = ParaEnv { p, g, reduce, margin, indent, mr, bullet_w, first_x, rest_x, tabs: &tabs, hang };
for (li, rl) in raw.iter().enumerate() {
let is_last = li + 1 == raw.len();
let placed = place_line(&env, pi, rl, li, is_last, flow);
@@ -376,7 +384,10 @@ fn line_extent(p: &ParaShaped, rl: &RawLine) -> (f64, f64, f64) {
}
/// Logical advance of each cell on the line (tabs measure from the start edge) and their sum.
fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64) -> (Vec<f64>, f64) {
/// `hang` is the implicit first-line stop, or `None` on later lines: they already start at the
/// margin, and negative character spacing can dip `x` below it, which would wrongly re-trigger
/// the stop.
fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64, hang: Option<f64>, avail: f64) -> (Vec<f64>, f64) {
let p = env.p;
let line_cells = p.cells.get(rl.start..rl.end).unwrap_or(&[]);
let n = rl.end.saturating_sub(rl.start);
@@ -388,7 +399,7 @@ fn line_advances(env: &ParaEnv, rl: &RawLine, is_last: bool, x0: f64) -> (Vec<f6
let a = if shy_end && k + 1 == n {
p.faces.get(c.face).zip(p.styles.get(c.style)).map(|(f, st)| measure_str(f, st.size, "-").0).unwrap_or(0.0)
} else if c.ch == '\t' {
tab_advance(x0 + x, env.tabs, p.props.default_tab.unwrap_or(72.0), tab_segment(&p.cells, rl.start + k))
tab_advance(x0 + x, env.tabs, p.props.default_tab.unwrap_or(72.0), tab_segment(&p.cells, rl.start + k), hang, x0 + avail)
} else {
c.adv
};
@@ -520,7 +531,7 @@ fn place_line(env: &ParaEnv, pi: usize, rl: &RawLine, li: usize, is_last: bool,
let avail = (g.col_w - x0 - env.mr).max(0.0);
let n = rl.end.saturating_sub(rl.start);
let line_cells = p.cells.get(rl.start..rl.end).unwrap_or(&[]);
let (mut adv, width) = line_advances(env, rl, is_last, x0);
let (mut adv, width) = line_advances(env, rl, is_last, x0, if li == 0 { env.hang } else { None }, avail);
let align = props.align.unwrap_or(Align::Left);
let slack = (avail - width).max(0.0);
let stretch = !is_last && g.wrap && slack > 0.0;
+112
View File
@@ -1419,6 +1419,54 @@ fn tab_stops_align_the_text_after_them() {
assert!((l.lines[0].edges[4].0 - x0(&l) - 72.0).abs() < 0.01);
}
#[test]
fn a_right_tab_stop_past_the_margin_ends_the_text_at_the_margin() {
// #1663: a layout may set a right tab stop a little past the text area's right edge.
// PowerPoint treats it as one at the margin: the text after it stays on one line and ends
// at the right edge. DeckCraft started it too far right and wrapped the rest.
let l = tabbed("x\tCorrie Ten Boom", &[(700.0, "r")], 600.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
let right = l.inner.x0 + l.inner.width();
assert!((l.lines[0].extent.1 - right).abs() < 0.01, "ends at {:?}, margin {right}", l.lines[0].extent);
}
#[test]
fn an_indented_paragraph_clamps_a_tab_stop_to_its_absolute_right_edge() {
// #1663: the stop and the edge are measured from the text area's left edge, so an indented
// first line does not pull the edge in by its margin. A stop inside it keeps its position;
// one past it ends the text at the margin.
let (p, mut sh) = setup("x\tCorrie Ten Boom", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(100.0);
pp.indent = Some(0.0);
pp.default_tab = Some(72.0);
pp.tabs = Some(vec![deckcraft_model::text::TabStop { pos: 550.0, align: "r".to_string() }]);
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
assert!((l.lines[0].extent.1 - l.inner.x0 - 550.0).abs() < 0.01, "inside stop at {:?}", l.lines[0].extent);
let (p, mut sh) = setup("x\tCorrie Ten Boom", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(100.0);
pp.indent = Some(0.0);
pp.default_tab = Some(72.0);
pp.tabs = Some(vec![deckcraft_model::text::TabStop { pos: 700.0, align: "r".to_string() }]);
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 1, "{:?}", l.lines.iter().map(|x| (x.start, x.end, x.extent)).collect::<Vec<_>>());
let right = l.inner.x0 + l.inner.width();
assert!((l.lines[0].extent.1 - right).abs() < 0.01, "ends at {:?}, margin {right}", l.lines[0].extent);
}
#[test]
fn many_tabs_over_many_stops_lay_out_by_position() {
// 20,000 stops given out of order, and 2,000 tabs: each tab finds the next stop by position.
@@ -1439,6 +1487,70 @@ fn a_tab_past_the_end_moves_to_the_next_line() {
assert!((l.lines[1].edges[1].0 - l.inner.x0 - 72.0).abs() < 0.01);
}
/// One paragraph `text` with a hanging indent (`marL`/`indent`), no bullet or explicit stops.
fn hanging_tabbed(text: &str, margin: f64, indent: f64, w: f64) -> TextLayout {
let (p, mut sh) = setup(text, w, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(margin);
pp.indent = Some(indent);
pp.default_tab = Some(72.0);
pp.tabs = None;
lay(&p, &sh, w, 300.0)
}
#[test]
fn hanging_indent_is_the_first_tab_stop() {
// PowerPoint: with a 0.375 in (27 pt) hanging indent, the first tab on the first line goes
// to marL; later tabs go to the normal default stops.
let l = hanging_tabbed("a\tb\tc", 27.0, -27.0, 600.0);
assert_eq!(l.lines.len(), 1);
let x0 = l.inner.x0;
assert!((l.lines[0].edges[2].0 - x0 - 27.0).abs() < 0.5, "the char after the first tab starts at marL: {:?}", l.lines[0].edges);
assert!((l.lines[0].edges[4].0 - x0 - 72.0).abs() < 0.5, "the char after the second tab starts at the default stop: {:?}", l.lines[0].edges);
// A third tab lands on the next default stop.
let l = hanging_tabbed("a\tb\tc\td", 27.0, -27.0, 600.0);
assert!((l.lines[0].edges[6].0 - l.inner.x0 - 144.0).abs() < 0.5, "{:?}", l.lines[0].edges);
}
#[test]
fn a_tab_on_a_wrapped_line_keeps_the_default_stop() {
// The implicit stop only applies ahead of the first line's start: a tab on the second
// line uses the normal default stop from the box grid (72 pt here), not marL + 27.
let l = hanging_tabbed("AAAA\u{b}\tB", 27.0, -27.0, 600.0);
assert_eq!(l.lines.len(), 2, "{:?}", l.lines.iter().map(|x| (x.start, x.end)).collect::<Vec<_>>());
let x = l.lines[1].edges[1].0 - l.inner.x0;
assert!((x - 72.0).abs() < 0.5, "the wrapped line's tab uses the default stop, got {x}");
assert!((x - 54.0).abs() > 5.0, "and not marL + 27");
}
#[test]
fn a_tab_after_negative_spacing_on_a_later_line_keeps_the_default_stop() {
// #1683 follow-up: the implicit stop is a first-line stop only. Negative character spacing
// can put a later line's cursor left of the margin; its tab must still take the default stop.
let (p, mut sh) = setup("A\u{b}X\tY", 600.0, 300.0);
let para = &mut sh.text.as_mut().unwrap().paragraphs[0];
for r in &mut para.runs {
r.props.size = Some(18.0);
r.props.spacing = Some(-20.0);
}
let pp = &mut para.props;
pp.bullet = Some(Bullet::None);
pp.margin_left = Some(27.0);
pp.indent = Some(-27.0);
pp.default_tab = Some(72.0);
pp.tabs = None;
let l = lay(&p, &sh, 600.0, 300.0);
assert_eq!(l.lines.len(), 2, "{:?}", l.lines.iter().map(|x| (x.start, x.end)).collect::<Vec<_>>());
let x = l.lines[1].edges[2].0 - l.inner.x0;
assert!((x - 72.0).abs() < 0.5, "the later line's tab uses the default stop, got {x}");
assert!((x - 27.0).abs() > 5.0, "and not the first line's margin stop");
}
/// Underline decorations of "ab cd" underlined `u` at 40 pt.
fn underline_decos(u: &str) -> (TextLayout, Vec<Deco>) {
let (p, mut sh) = setup("ab cd", 2000.0, 300.0);
+1 -1
View File
@@ -369,7 +369,7 @@ fn begin_slide(app: &mut SlideApp, show: &Show, f: &Fr, size: (u32, u32)) -> Sl
let media = crate::media::slide_media(doc, idx);
let hidden: Vec<ShapeId> = media
.iter()
.filter(|(id, _, clip)| clip.hide_while_not_playing && !app.media.status(*id).is_some_and(|s| s.state != deckcraft_media::PlayState::Ended))
.filter(|(id, _, clip)| clip.hidden_during_show(app.media.status(*id).is_some_and(|s| s.state != deckcraft_media::PlayState::Ended)))
.map(|m| m.0)
.collect();
let gifs = app.media.gifs(doc_uid, doc, idx, now, &app.session.gif_paused);