diff --git a/crates/pages/src/ui/view.rs b/crates/pages/src/ui/view.rs index bf510c36fc..583f51e102 100644 --- a/crates/pages/src/ui/view.rs +++ b/crates/pages/src/ui/view.rs @@ -477,6 +477,7 @@ pub struct PageView<'a> { reach: f32, go_to_place: GoToPlace, fill_screen: bool, + floating_scrollbars: bool, } /// How far from the view, in view heights above and below it (and one view width either side), the page view keeps a @@ -507,6 +508,7 @@ impl<'a> PageView<'a> { reach: PICTURE_REACH, go_to_place: GoToPlace::AfterRowAbove, fill_screen: false, + floating_scrollbars: false, } } @@ -527,6 +529,13 @@ impl<'a> PageView<'a> { self } + /// Use the theme's floating scroll indicators over the page edges. + #[must_use] + pub fn floating_scrollbars(mut self) -> Self { + self.floating_scrollbars = true; + self + } + /// The colour round the pages: the theme's by default; production's full screen view is black. #[must_use] pub fn pasteboard(mut self, colour: PasteboardColor) -> Self { @@ -695,6 +704,7 @@ impl<'a> PageView<'a> { reach, go_to_place, fill_screen, + floating_scrollbars, } = self; let mut spacing = PageMetrics::new().show_at(ui, Rect::from_min_size(rect.min, Vec2::ZERO)).spacing; // Filling the screen, the pages keep no margin above or below and no gutter beside them, and draw no border. @@ -751,8 +761,20 @@ impl<'a> PageView<'a> { let mut held = Held::new(Bind::bound(state)); let mut seen: Option = None; let mut canvas_body = |ui: &mut Ui, cx: &mut BodyCx<'_>| { - let inputs = - Inputs { source, describer, build: &build, rect, given, paper, navigation, border, keep, reach, strips: strips_clip.map(|_| full) }; + let inputs = Inputs { + source, + describer, + build: &build, + rect, + given, + paper, + navigation, + border, + keep, + reach, + floating_scrollbars, + strips: strips_clip.map(|_| full), + }; let (mut next, pending) = run_pass(ui, cx, &mut held, &inputs, |ui, page| before(ui, page, session))?; let pass = tool_pass(&cx.env); if let Some(clip) = strips_clip { @@ -816,6 +838,7 @@ struct Inputs<'a> { keep: &'a [usize], /// `PageView::picture_reach`. reach: f32, + floating_scrollbars: bool, /// With `PageView::rulers`, the view's whole rect, strips included; the canvas shows inside the strips. strips: Option, } @@ -985,7 +1008,7 @@ fn run_pass( inputs: &Inputs<'_>, mut before: impl FnMut(&mut Ui, &PageBody<'_>) -> Option, ) -> Option<(Seen, Pending)> { - let Inputs { source, describer, build, rect, given, paper, navigation, border, keep, reach, strips: _ } = *inputs; + let Inputs { source, describer, build, rect, given, paper, navigation, border, keep, reach, floating_scrollbars, strips: _ } = *inputs; let mut state = held.read(cx)?; let started = state.clone(); state.normalise(); @@ -1003,8 +1026,9 @@ fn run_pass( // A display, continuous, cover, fit or rotation other than the layout placed last keeps the current page in // view. Writing a field to the value it has changes nothing, and the first pass has no layout to differ from. let previous = mem.layout.take(); - if state.go_to.is_none() && previous.as_ref().is_some_and(|(key, _)| key.display_differs(&state)) { - state.go_to = Some(GoTo::Top { page: state.current, fraction: 0.0 }); + let reposition = state.go_to.is_none() && previous.as_ref().is_some_and(|(key, _)| key.display_differs(&state)); + if reposition { + state.go_to(state.current); } // The layout the canvas was given its view for: what this pass draws, whatever the pass makes of the state. let drawn = build.of(&state); @@ -1027,6 +1051,11 @@ fn run_pass( state.offset = offset; } } + // Switching fit or display also places the current page at the top. Use that same + // destination for this paint, before the normal go-to processing commits it. + if reposition && let Some(top) = state.go_to { + state.offset = go_to_offset(top, &geo, state.continuous, state.offset, (vw, vh), &build.spacing, build.go_to_place); + } state.zoom = geo.scale / SCREEN_POINTS_PER_POINT; // The canvas folded the wheel, a pinch and the view commands into the view it settled on: a different zoom is the @@ -1065,13 +1094,15 @@ fn run_pass( } } let mut scrolled = wheel.is_some_and(|wheel| !zooming && wheel.scroll != Vec2::ZERO); - // A zoom that does not ease draws the layout it made in its own pass, through the view of the anchored offset: the - // pages reflow and the point under the pointer stays in the pass the zoom happens, and the next pass, given that - // view, moves nothing. (Drawing the layout the pass started with, scaled, put the reflow and the spacing that does - // not scale one pass late.) An ease draws the layout it started from, scaled, until it lands. - let (drawn, drawn_frame, mut shown) = if zooming && !space.easing() { + // Wheel zooms and external scale changes both compute an anchored offset above. Paint + // through it immediately so the new page size and its placement change in the same frame. + // An animated canvas keeps drawing its easing view until it lands. + let anchored = state.offset != started.offset; + let (drawn, drawn_frame, mut shown) = if (zooming || anchored) && !space.easing() { let frame = Frame::of(&geo); - let mut view = frame.view(rect, state.offset, geo.scale / SCREEN_POINTS_PER_POINT); + let (xs, ys) = (offset_range(geo.doc.x0, geo.doc.x1, vw), geo.y_range(vh)); + let offset = (want.0.clamp(xs.0, xs.1), want.1.clamp(ys.0, ys.1)); + let mut view = frame.view(rect, offset, geo.scale / SCREEN_POINTS_PER_POINT); // As the canvas places a given view: in its own rect (inside the rulers), about the same centre. view.rect = target.rect; let view = if shown == target { view } else { pixel_aligned(view, ui.ctx().pixels_per_point()) }; @@ -1199,6 +1230,7 @@ fn run_pass( Label::from(words.page_of.fill(&[("page", label.as_str()), ("count", total.as_str())])) }; let bars = if count > 0 { bars.tip(&tip) } else { bars }; + let bars = if floating_scrollbars { bars.floating() } else { bars }; // Pages that fit the view's width can't scroll sideways, so there is no horizontal bar. The layout drawn // decides, as the bars measure it. let (x_lo, x_hi) = offset_range(drawn.doc.x0, drawn.doc.x1, vw); diff --git a/crates/pages/tests/it/views.rs b/crates/pages/tests/it/views.rs index bc77a2420a..ca2ac06782 100644 --- a/crates/pages/tests/it/views.rs +++ b/crates/pages/tests/it/views.rs @@ -125,6 +125,51 @@ fn the_horizontal_bar_shows_only_when_the_pages_are_wider_than_the_view() { assert!(has_horizontal_bar(3.0), "pages wider than the view scroll sideways"); } +#[trial] +fn floating_page_scrollbars_use_narrower_tracks_and_keep_the_same_page_layout() { + let measure = |floating: bool| { + let pages = DemoPages::new(4); + let mut state = state_with(|s| { + s.fit = Fit::None; + s.zoom = 2.0; + }); + let page = Rc::new(RefCell::new(egui::Rect::NOTHING)); + let drawn = Rc::clone(&page); + let mut fixture = Fixture::new(move |ui| { + let view = PageView::new("Pages", &pages, &mut state, PAPER); + let shown = if floating { view.floating_scrollbars() } else { view }.show(ui, |_, _| {}); + *drawn.borrow_mut() = shown.pages[0].rect; + }); + fixture.room(vec2(900.0, 600.0)).idle(3); + let horizontal = horizontal_bar(&fixture).expect("wide pages scroll sideways"); + let vertical = fixture + .by_role(Role::SCROLL_BAR) + .into_iter() + .map(|node| node.rect) + .find(|rect| rect.height() > rect.width()) + .expect("long documents scroll vertically"); + let initial = *page.borrow(); + if floating { + // Hover the thumb at the start of each track, then drag from inside its hover area. + for (grab, delta) in [ + (pos2(horizontal.left() + 4.0, horizontal.center().y), vec2(35.0, 0.0)), + (pos2(vertical.center().x, vertical.top() + 4.0), vec2(0.0, 35.0)), + ] { + fixture.frame(vec![craft_ui::testing::pointer::moved(grab)]); + let before = page.borrow().min; + fixture.drag_hold_at(grab, delta).release_at(grab + delta).idle(2); + let moved = before - page.borrow().min; + assert!(moved.dot(delta) > 1.0, "the thumb drag must scroll its own axis: {delta:?} -> {moved:?}"); + } + } + (horizontal.height(), vertical.width(), initial) + }; + let (float_h, float_v, float_page) = measure(true); + let (dock_h, dock_v, dock_page) = measure(false); + assert!(float_h < dock_h && float_v < dock_v); + assert_eq!(float_page, dock_page); +} + /// The horizontal scroll bar the fixture shows, if any. fn horizontal_bar(fixture: &Fixture) -> Option { fixture.by_role(Role::SCROLL_BAR).iter().map(|bar| bar.rect).find(|rect| rect.width() > rect.height()) @@ -489,6 +534,29 @@ fn assert_centre_kept(out: &Out, before: (usize, kurbo::Point), what: &str) { ); } +/// A zoom entered in a toolbar draws the page in its final position immediately. A pass at +/// the new scale with the old offset makes the page jump sideways and vertically on the next frame. +#[trial] +fn a_written_zoom_draws_the_anchored_page_on_its_first_frame() { + let mut view = rig( + 5, + state_with(|s| { + s.fit = Fit::None; + s.zoom = 1.0; + }), + ); + for (fit, zoom) in [(Fit::None, 2.0), (Fit::None, 1.0), (Fit::Width, 1.0), (Fit::None, 2.0)] { + view.state.borrow_mut().fit = fit; + view.state.borrow_mut().zoom = zoom; + view.fixture.idle(1); + let first = view.out.borrow().pages[0].rect; + view.fixture.idle(2); + let settled = view.out.borrow().pages[0].rect; + assert!((first.min - settled.min).length() < 1.0, "at {zoom}: first {first:?}, settled {settled:?}"); + assert!((first.size() - settled.size()).length() < 1.0); + } +} + /// A written zoom keeps the point at the centre; a new room (a panel opened beside the view) refits and keeps the /// current page's top where it was, as production did. #[trial] diff --git a/crates/pdf/tests/upstream_raster.rs b/crates/pdf/tests/upstream_raster.rs index 3adae408c5..7f05c247a0 100644 --- a/crates/pdf/tests/upstream_raster.rs +++ b/crates/pdf/tests/upstream_raster.rs @@ -19,6 +19,37 @@ fn render(bytes: &[u8]) -> Pixels { Pixels { width: raster.width, height: raster.height, rgba: raster.bytes().to_vec() } } +/// An axial shading fills a pattern cell even when the page is rendered smaller than the cell +/// or the caller requests just a tile. The upper and lower corners show opposite gradient ends. +#[cfg_attr(not(target_arch = "wasm32"), test)] +#[cfg_attr(target_arch = "wasm32", wasm_bindgen_test::wasm_bindgen_test)] +fn shading_covers_pattern_cell_at_each_viewport_scale() { + let content = "/Pattern cs /P scn 5 6 150 108 re f"; + let bytes = format!( + "%PDF-1.7\n1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj\n\ + 2 0 obj << /Type /Pages /Kids [3 0 R] /Count 1 >> endobj\n\ + 3 0 obj << /Type /Page /Parent 2 0 R /MediaBox [0 0 160 120] /Contents 4 0 R /Resources << /Pattern << /P 5 0 R >> >> >> endobj\n\ + 4 0 obj << /Length {} >> stream\n{content}\nendstream endobj\n\ + 5 0 obj << /Type /Pattern /PatternType 1 /PaintType 1 /TilingType 1 /BBox [0 0 200 144] /XStep 200 /YStep 144\n\ + /Matrix [.75 0 0 -.75 5 114] /Resources << /Shading << /S << /ShadingType 2 /ColorSpace /DeviceRGB /Coords [0 0 0 144]\n\ + /Function << /FunctionType 2 /Domain [0 1] /C0 [1 0 0] /C1 [0 0 1] /N 1 >> /Extend [true true] >> >> >> /Length 5 >>\n\ + stream\n/S sh\nendstream endobj\ntrailer << /Root 1 0 R >>\n%%EOF", + content.len() + ); + let pdf = open_slice(bytes.as_bytes(), None).unwrap(); + for (scale, size, offset) in [(0.5, [80, 60], [0.0, 0.0]), (1.5, [180, 150], [30.0, 15.0])] { + let opts = Options { scale: [scale; 2], size: Some(size), offset, background: [255; 4], ..Default::default() }; + let image = raster::render(&pdf.pages()[0], &RenderCache::new(), &Default::default(), &opts).unwrap(); + for x in [size[0] / 10, size[0] * 9 / 10] { + for (y, upper) in [(size[1] / 10, true), (size[1] * 9 / 10, false)] { + let i = ((y * image.width + x) * 4) as usize; + let rgb = &image.bytes()[i..i + 3]; + assert!(rgb[1] < 8 && if upper { rgb[0] > rgb[2] } else { rgb[2] > rgb[0] }, "{scale} ({x}, {y}): {rgb:?}"); + } + } + } +} + // These frozen RGB8 values were computed outside the renderer in f64 from the // CIE Lab inverse, the full XYZ adaptation matrix B^-1 diag(B*D65 / B*white) B, // and the standard sRGB matrix/transfer function. No production helper is used. diff --git a/crates/pptx/src/lib.rs b/crates/pptx/src/lib.rs index d206caaa94..5f868eadde 100644 --- a/crates/pptx/src/lib.rs +++ b/crates/pptx/src/lib.rs @@ -1083,6 +1083,8 @@ pub struct Presentation { pub next_id: u32, /// Embedded fonts. The face bytes live in [`Self::media`]. pub embedded_fonts: Vec, + /// Whether the next save should keep only the characters used by embedded fonts. + pub save_subset_fonts: bool, /// Table styles defined in the file (`ppt/tableStyles.xml`). #[serde(skip_serializing_if = "Vec::is_empty")] pub table_styles: Vec, @@ -1131,6 +1133,7 @@ impl Default for Presentation { first_slide_number: 1, next_id: 0, embedded_fonts: vec![], + save_subset_fonts: false, table_styles: vec![], tags: vec![], kept_parts: vec![], diff --git a/crates/pptx/src/read.rs b/crates/pptx/src/read.rs index 588ba1357b..b3fd815c06 100644 --- a/crates/pptx/src/read.rs +++ b/crates/pptx/src/read.rs @@ -575,6 +575,7 @@ fn read_presentation_settings(imp: &mut Imp, p: &mut Presentation, pres_part: &P p.notes_size = Size::new(sane_len(w, 540.0), sane_len(h, 720.0)); } p.first_slide_number = pres_el.attr_local("firstSlideNum").and_then(value::to_u32_lossy).unwrap_or(1).min(9999); + p.save_subset_fonts = pres_el.attr_local("saveSubsetFonts").and_then(value::to_bool).unwrap_or(false); if let Some(dts) = pres_el.child(Local("defaultTextStyle")) { p.default_text_style = dml::list_style(&mut Src(imp, pres_part), dts); } diff --git a/crates/pptx/src/write.rs b/crates/pptx/src/write.rs index 30c0b83df2..2b0d8825d3 100644 --- a/crates/pptx/src/write.rs +++ b/crates/pptx/src/write.rs @@ -1153,7 +1153,11 @@ fn presentation_xml(x: &mut Exp, o: &mut Out, masters: &[(u64, String)], notes: let p = x.p; let mut w = Writer::document(); let first = (p.first_slide_number != 1).then_some(p.first_slide_number.min(9999)); - root_open(&mut w, "p:presentation", A::new().a("saveSubsetFonts", 1).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first)); + root_open( + &mut w, + "p:presentation", + A::new().t("saveSubsetFonts", p.save_subset_fonts).t("embedTrueTypeFonts", !fonts.is_empty()).o("firstSlideNum", first), + ); w.open("p:sldMasterIdLst", &[]); for (id, rid) in masters { w.tag("p:sldMasterId").attr("id", id).attr("r:id", rid).empty(); diff --git a/crates/pptx/tests/it/write.rs b/crates/pptx/tests/it/write.rs index 46db7041de..5a7e13859c 100644 --- a/crates/pptx/tests/it/write.rs +++ b/crates/pptx/tests/it/write.rs @@ -100,6 +100,25 @@ fn a_deck_without_masters_gets_the_callers() { assert_eq!(q.slides[0].layout, q.masters[0].layouts[0].id); } +#[test] +fn subset_font_setting_is_not_invented_and_survives_when_present() { + let bytes = craft_pptx::export(&deck(), &Plain).unwrap(); + assert!(!part(&bytes, "ppt/presentation.xml").contains("saveSubsetFonts"), "a new deck must not opt into font subsetting"); + let with_subset = common::rewrite( + &bytes, + |name, data| { + if name != "ppt/presentation.xml" { + return Some(data.to_vec()); + } + let xml = String::from_utf8(data.to_vec()).unwrap(); + Some(xml.replace(" { /// horizontal bar or corner is shown. #[prop(flag)] vertical_only: bool, + /// Use floating indicators with a narrow thumb at rest. Document chrome takes precedence. + #[prop(flag)] + #[style_key] + floating: bool, /// Wider bars with inset thumbs, step arrows and a corner for a document window. #[prop(flag)] #[style_key] @@ -431,6 +435,7 @@ impl<'a> CanvasScrollbars<'a> { overscroll: false, vertical_only: false, document_chrome: false, + floating: false, tip: None, held: None, } @@ -510,9 +515,12 @@ impl Component for CanvasScrollbars<'_> { type Output = CanvasScrollbarsOutput; fn style(cx: &StyleCx<'_>, key: CanvasScrollbarsStyleKey) -> ScrollbarsStyle { - let mut look = cx.scroll_bar_of(ScrollBarKind::Docked); + let kind = if key.floating && !key.document_chrome { ScrollBarKind::Floating } else { ScrollBarKind::Docked }; + let mut look = cx.scroll_bar_of(kind); let (thickness, margin) = bar_size(cx.tokens, key.document_chrome); - look.thickness = thickness; + if kind == ScrollBarKind::Docked { + look.thickness = thickness; + } let document = key.document_chrome.then(|| { let color = &cx.tokens.color; look.track = Stateful::new(cx.color(color.surface.sunken)); diff --git a/crates/ui-panels/src/docking/group.rs b/crates/ui-panels/src/docking/group.rs index 67c842b256..856f5444e8 100644 --- a/crates/ui-panels/src/docking/group.rs +++ b/crates/ui-panels/src/docking/group.rs @@ -398,7 +398,6 @@ pub struct DockGroup<'a, P: Clone + Hash + Send + Sync + 'static> { tab_look: PanelTabLook, /// The header shows the shown panel's title (with its count) and a close button in place of the tab strip, as a /// single titled panel does: the panels are shown from a rail, not by tabs. - #[prop(flag)] titled: bool, /// The tab row takes key focus in this pass: [`take_focus`](DockGroup::take_focus). take_focus: bool, @@ -478,6 +477,16 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< .label(title) } + /// Shows the active panel title with the standard panel inset, aligned with the body beneath it. + #[must_use] + pub fn titled(mut self) -> Self { + self.titled = true; + if let Some(header) = self.props.header.as_mut() { + header.inset = crate::contract::Pad::Regular; + } + self + } + /// The shown panel's footer: the closure fills a footer bar pinned under the body, across the group, that stays in /// view while the body scrolls. A minimized group shows none. #[must_use] @@ -499,7 +508,9 @@ impl<'a, P: Clone + Hash + Send + Sync + PartialEq + Debug + 'static> DockGroup< /// lie on a strip of `surface.canvas`, the others on the window's background. #[must_use] pub fn tab_look(mut self, look: PanelTabLook) -> Self { - self.props = self.props.header(HeaderRegion::new().fill(strip_surface(look))); + if let Some(header) = self.props.header.as_mut() { + *header = header.fill(strip_surface(look)); + } self.tab_look = look; self } diff --git a/crates/ui-panels/src/rails/tool/trials.rs b/crates/ui-panels/src/rails/tool/trials.rs index 655a7aa898..fe9db51389 100644 --- a/crates/ui-panels/src/rails/tool/trials.rs +++ b/crates/ui-panels/src/rails/tool/trials.rs @@ -404,6 +404,7 @@ struct Seen { footer_runs: usize, selected: Vec, edit_toolbar: Option, + edit_clicks: usize, } /// A rail with the Edit Toolbar button, a footer and a tool held in `Seen::current`. @@ -420,12 +421,21 @@ fn memo_rail() -> (Fixture, Rc>) { }); let mut seen = shared.borrow_mut(); seen.selected.extend(out.select); + seen.edit_clicks += usize::from(out.edit_toolbar.as_ref().is_some_and(crate::contract::clicked)); seen.edit_toolbar = out.edit_toolbar.map(|response| response.rect); }); fixture.room(Vec2::new(200.0, 600.0)).settle(); (fixture, seen) } +#[trial] +fn the_rail_reports_an_edit_button_activation_once() { + let (mut fixture, seen) = memo_rail(); + let button = fixture.by_label("Edit Toolbar").expect("the edit button is present"); + fixture.access(crate::testing::focus::AccessActionKind::Click, &button).settle(); + assert_eq!(seen.borrow().edit_clicks, 1); +} + /// How the slot grid took part in the last frame: (ran, replayed). fn grid_runs(fixture: &Fixture) -> (usize, usize) { let runs = last_frame_memo_runs(fixture.ctx()); diff --git a/crates/ui-panels/tests/it/dock_group.rs b/crates/ui-panels/tests/it/dock_group.rs index 906f6ef7ae..0513efb92f 100644 --- a/crates/ui-panels/tests/it/dock_group.rs +++ b/crates/ui-panels/tests/it/dock_group.rs @@ -110,7 +110,12 @@ fn a_titled_group_shows_the_panel_title_and_a_close_button_instead_of_tabs() { } }); fixture.settle(); - assert!(fixture.by_label("Accessibility Checker").is_some(), "the title shows whole"); + let title = fixture + .by_role(craft_ui::contract::Role::LABEL) + .into_iter() + .find(|node| fixture.tree().name_of(node.node) == Some("Accessibility Checker")) + .expect("the title shows whole"); + assert!(title.rect.left() > 10.0, "the title clears the panel edge"); assert!(fixture.by_label("Pages").is_none(), "no tab for the other panel"); let Some(close) = fixture.by_label("Close Accessibility Checker") else { panic!("a close button shows") }; fixture.click(&close).settle(); diff --git a/crates/ui-widgets/src/tabs/tab.rs b/crates/ui-widgets/src/tabs/tab.rs index 4cf2abe35f..49fd42dd03 100644 --- a/crates/ui-widgets/src/tabs/tab.rs +++ b/crates/ui-widgets/src/tabs/tab.rs @@ -199,6 +199,10 @@ pub struct Tab<'a> { #[style_key] #[prop] role: TabRole, + /// The text-tab label role when the strip shares a row with another control, such as a menu bar. + #[style_key] + #[prop] + text_role: Option, /// Large Tabs: the strip's taller form with the body type; text tabs take the strong body type and stand further apart. #[style_key] #[prop(flag)] @@ -246,6 +250,7 @@ impl<'a> Tab<'a> { common: Common::new(), kind: TabKind::Document, role: TabRole::default(), + text_role: None, large: false, panel_look: PanelTabLook::Plain, detail: None, @@ -394,10 +399,9 @@ impl Component for Tab<'_> { // semibold document tab's title is in the tab-title role: the condensed face where the app embeds it. let role = if ribbon { TypeRole::BodyStrong - } else if text_only && key.large { - // Large text tabs (a dialog's categories): the strong body type, about 13 points. - TypeRole::BodyStrong - } else if text_only || key.large { + } else if text_only { + key.text_role.unwrap_or(if key.large { TypeRole::BodyStrong } else { TypeRole::Body }) + } else if key.large { TypeRole::Body } else if strong { TypeRole::TabTitle diff --git a/crates/ui-widgets/src/text/number/rule.rs b/crates/ui-widgets/src/text/number/rule.rs index 8dcd9badb9..42141f3af9 100644 --- a/crates/ui-widgets/src/text/number/rule.rs +++ b/crates/ui-widgets/src/text/number/rule.rs @@ -282,17 +282,3 @@ impl Codec for Ruled { Cow::Owned(self.samples(current).max_by_key(|text| text.chars().count()).unwrap_or_default()) } } - -#[cfg(test)] -mod tests { - use super::truncate_to; - - #[test] - fn truncation_cuts_toward_zero_and_keeps_values_at_the_precision() { - for (value, decimals, want) in - [(2.5, 0, 2.0), (-2.5, 0, -2.0), (1.159, 2, 1.15), (1.15, 2, 1.15), (-1.15, 2, -1.15), (0.29, 2, 0.29), (1.2345678919, 9, 1.234567891)] - { - assert_eq!(truncate_to(value, decimals), want, "{value} at {decimals} decimals"); - } - } -} diff --git a/crates/ui-widgets/tests/it/text/number.rs b/crates/ui-widgets/tests/it/text/number.rs index cadff1fc89..d1e5381b48 100644 --- a/crates/ui-widgets/tests/it/text/number.rs +++ b/crates/ui-widgets/tests/it/text/number.rs @@ -210,6 +210,24 @@ fn a_localised_decimal_types_in() { assert_eq!(typed(Some(host), None, "12,5"), Some(12.5)); } +/// A field that truncates typed values cuts them toward zero to its committed decimals, and keeps a value already at +/// that precision. +#[trial] +fn a_truncating_field_cuts_a_typed_value_toward_zero_and_keeps_one_at_the_precision() { + for (text, decimals, want) in [ + ("2.5", 0, 2.0), + ("-2.5", 0, -2.0), + ("1.159", 2, 1.15), + ("1.15", 2, 1.15), + ("-1.15", 2, -1.15), + ("0.29", 2, 0.29), + ("1.2345678919", 9, 1.234567891), + ] { + let committed = typed_with(Some(region_host("en")), text, |field| field.truncate_typed().commit_decimals(decimals)); + assert_eq!(committed, Some(want), "{text} at {decimals} decimals"); + } +} + /// A whole-only field over 1 to 100 under `host`'s locale, with `text` typed over 50 and committed with Tab: the value /// kept and the range alert the commit reported. fn whole_typed(host: Option>, text: &str) -> (Option, Option) { diff --git a/crates/window/src/desktop/work_area.rs b/crates/window/src/desktop/work_area.rs index 79d5e41bb1..18aafe9af6 100644 --- a/crates/window/src/desktop/work_area.rs +++ b/crates/window/src/desktop/work_area.rs @@ -149,6 +149,20 @@ mod tests { } } + #[test] + fn a_menu_keeps_its_client_anchor_on_an_offset_portrait_monitor() { + let laptop = Monitor::new(craft_behavior::MonitorKey::new("laptop", [1920, 1080]), [0, 0], [1920, 1080], 1.0); + let portrait = Monitor::new(craft_behavior::MonitorKey::new("portrait", [1080, 1920]), [1920, -240], [1080, 1920], 1.5) + .with_work_px([1920, -240], [1080, 1872]); + let monitors = [laptop, portrait]; + for scale in [1.0, 1.5] { + let content = Rect::from_min_size(pos2(0.0, 0.0), vec2(1040.0, 1100.0) / scale); + let inner = content.translate(vec2(1920., -240.) / scale); + assert_eq!(visible_part_on_monitors(content, inner, scale, &monitors), Some(content)); + assert!(visible_part(content, Some(vec2(1080., 1920.) / scale), Some(inner), Normal).left() > 0.); + } + } + #[test] fn maximized_unknown_or_nonsense_input_keeps_the_window() { let (content, inner) = window(0.0, 0.0, 1440.0, 900.0); diff --git a/vendor/hayro-interpret/src/pattern.rs b/vendor/hayro-interpret/src/pattern.rs index 1dceae2dd3..9c336c0c17 100644 --- a/vendor/hayro-interpret/src/pattern.rs +++ b/vendor/hayro-interpret/src/pattern.rs @@ -165,7 +165,6 @@ pub struct TilingPattern<'a> { cache_key: u128, /// PdfCraft patch (78): see [`Self::instance`]. instance: u64, - ctx_bbox: Rect, /// The bbox of the tiling pattern. pub bbox: Rect, /// The step in the x direction. @@ -242,7 +241,6 @@ impl<'a> TilingPattern<'a> { .unwrap_or_default(); let state = ctx.get().clone(); - let ctx_bbox = ctx.bbox(); let fill_cs = state .graphics_state @@ -274,7 +272,6 @@ impl<'a> TilingPattern<'a> { x_step, y_step, matrix, - ctx_bbox, is_color, stream, stroke_paint, @@ -320,8 +317,9 @@ impl<'a> TilingPattern<'a> { let mut context = Context::new_with( state.ctm, - // TODO: bbox? - (initial_transform * self.ctx_bbox.to_path(0.1)).bounding_box(), + // Shadings cover the cell's device bounds. The caller may be a differently + // scaled page, or a page tile with a different origin. + initial_transform.transform_rect_bbox(self.bbox), &self.cache, self.xref, self.settings.clone(),