mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-26 04:58:07 +00:00
App red round 7 g2: fixes and wiring from the g2 fixer
This commit is contained in:
@@ -75,7 +75,15 @@ fn a_software_renderer_is_shown_to_the_user() {
|
||||
});
|
||||
h.run_steps(2);
|
||||
let cards = craft::ui::runtime::toast::cards(&h.ctx, &craft::ui::runtime::env::WindowKey::main());
|
||||
cards.iter().map(|card| card.toast.message.as_str().to_owned()).collect()
|
||||
// A posted notice's text is the card's title; a message and bullet lines follow it.
|
||||
cards
|
||||
.iter()
|
||||
.map(|card| {
|
||||
let toast = &card.toast;
|
||||
let parts = toast.title.iter().chain(std::iter::once(&toast.message)).chain(&toast.lines);
|
||||
parts.map(|part| part.as_str()).filter(|text| !text.is_empty()).collect::<Vec<_>>().join("\n")
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
// Issue #519: WARP or llvmpipe is announced in the app, not just in pdfcraft.log.
|
||||
let mut app = crate::startup::test_app();
|
||||
|
||||
@@ -940,7 +940,7 @@ fn page_parts_of(
|
||||
// The comment a press under the pointer would take, hit within the theme's reach and with its markers at the
|
||||
// icon size, both as the tools on the canvas read them.
|
||||
let env = Env::of(ui);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation, body.view);
|
||||
let pointer = ui.input(|i| i.pointer.hover_pos()).map(|p| craft::behavior::kurbo::Point::new(p.x.into(), p.y.into()));
|
||||
let (tolerance, icon_side) = (map.doc_len(env.hit_reach()), map.doc_len(env.tokens.size.icon.md));
|
||||
parts.extend(comments::parts(cx.info, &map, cx.prefs, cx.tool, pointer, &session.comments.tool, tolerance, icon_side));
|
||||
@@ -1201,14 +1201,14 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
session.all_text = false;
|
||||
}
|
||||
let button_held = ui.input(|i| i.pointer.any_down());
|
||||
let tool_cx = PageToolCx { pages: body.pages, viewport: body.rect, button_held, ..cx.tools };
|
||||
let tool_cx = PageToolCx { pages: body.pages, viewport: body.rect, view: body.view, button_held, ..cx.tools };
|
||||
let mut bench = page_tools::ToolBench::default();
|
||||
let mut fill = None;
|
||||
let mut tool = page_tool(cx.chosen, tool_cx, &mut *session, &mut bench, &mut fill, &pass.press);
|
||||
let reply = ToolHost::new().momentary(momentary).run(ui, pass, &mut tool);
|
||||
let mut finish = tool.finish();
|
||||
// The comment gestures the run finished: each committed one is an engine edit, one undo step per drag.
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation, body.view);
|
||||
let now = ui.input(|i| i.time);
|
||||
if let Some(edit) = comments::take_edits(&mut session.comments, &map, cx.info, cx.prefs, now) {
|
||||
session.pending_edit = Some(edit);
|
||||
@@ -1284,7 +1284,7 @@ fn page_body(ui: &mut egui::Ui, body: &PageBody<'_>, session: &mut PageSession,
|
||||
// The comment under the pointer is hit as the page's parts hit it: within the theme's reach, with its markers
|
||||
// at the icon size. The redaction hover is the user's setting, passed as a data colour (L-90).
|
||||
let env = Env::of(ui);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation);
|
||||
let map = comments::PageMap::new(cx.info, body.pages, cx.rotation, body.view);
|
||||
let pick = (map.doc_len(env.hit_reach()), map.doc_len(env.tokens.size.icon.md));
|
||||
let pointer = ui.input(|i| i.pointer.hover_pos().filter(|_| !i.pointer.any_down()));
|
||||
let hover = comments::Hover { pointer, redact: cx.redact_hover, pick, allowed: cx.allowed };
|
||||
@@ -1521,6 +1521,7 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
|
||||
sizes: &page_sizes[..],
|
||||
rotation: state.rotation,
|
||||
viewport: Rect::NOTHING,
|
||||
view: CanvasView::new(Rect::NOTHING, craft::behavior::kurbo::Point::ORIGIN, 1.0),
|
||||
button_held: false,
|
||||
text_style: &app.text_style,
|
||||
allowed,
|
||||
@@ -1587,6 +1588,9 @@ pub fn document_area_at(app: &mut PdfCraftApp, index: usize, rect: Rect, ui: &mu
|
||||
if let Some(canvas) = &body_out.view {
|
||||
out.adopt(&mut view.view, canvas);
|
||||
}
|
||||
if out.scrolled {
|
||||
view.end_find_following();
|
||||
}
|
||||
if out.toggle_white_space {
|
||||
view.view.hide_white_space = !view.view.hide_white_space;
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ pub(crate) struct PageToolCx<'a> {
|
||||
pub(crate) rotation: u16,
|
||||
/// The page body's rect this pass, filled from the body each run as `pages` is.
|
||||
pub(crate) viewport: egui::Rect,
|
||||
/// The canvas view the pages are shown in this pass, filled from the body each run as `pages` is.
|
||||
pub(crate) view: craft::behavior::CanvasView,
|
||||
/// A pointer button is down this pass, filled from the body each run as `pages` is: a key waits for it to come
|
||||
/// up where the press held would then name another item.
|
||||
pub(crate) button_held: bool,
|
||||
@@ -288,7 +290,7 @@ pub(crate) fn page_tool<'a>(
|
||||
let size = move |page: usize| sizes.get(page).copied().unwrap_or_default();
|
||||
*xforms = cx.pages.iter().map(|placed| (placed.page, PageXform::of(placed, cx.rotation, size(placed.page)))).collect();
|
||||
let xforms: &'a [(usize, PageXform)] = xforms;
|
||||
let map: &'a comments::PageMap<'a> = map_slot.insert(comments::PageMap::new(cx.info, cx.pages, cx.rotation));
|
||||
let map: &'a comments::PageMap<'a> = map_slot.insert(comments::PageMap::new(cx.info, cx.pages, cx.rotation, cx.view));
|
||||
let selects_text = tool_selects_text(tool, cx.preparing);
|
||||
let arm = match tool {
|
||||
// Prepare a form under the Select tool: the selection rectangle and the moves of fields are Prepare's.
|
||||
@@ -314,7 +316,7 @@ pub(crate) fn page_tool<'a>(
|
||||
_ => {
|
||||
let snap = caret_snap(tool, &cx, &session.texts, session.comments.tool.page);
|
||||
let view = &mut session.comments;
|
||||
let map = comments::PageMap::new(cx.info, cx.pages, cx.rotation);
|
||||
let map = comments::PageMap::new(cx.info, cx.pages, cx.rotation, cx.view);
|
||||
let annotate = CommentsTool::new(&mut view.tool, &mut view.paste, map, &mut view.tool_done, &mut view.tool_pressed)
|
||||
.settings(tool, cx.comment_prefs, cx.allowed, cx.doc.comments_hidden())
|
||||
.outcome(&mut session.pending_edit, &mut view.notice);
|
||||
|
||||
@@ -11,7 +11,7 @@ use pdfcraft_render::{PageInfo, RenderPool, RenderRequest, Tile};
|
||||
|
||||
use super::PageXform;
|
||||
use crate::QuickTool;
|
||||
use crate::comments::{CommentView, PageCx, id_of, key_of};
|
||||
use crate::comments::{CommentView, PageCx, PageMap, id_of, key_of};
|
||||
|
||||
/// The longest side, in pixels, a stamp's own layer is rendered at.
|
||||
const MAX_STAMP_SIDE: f32 = 2048.0;
|
||||
@@ -277,7 +277,7 @@ impl SignatureDrag {
|
||||
|
||||
/// The comment being dragged, drawn from its layers under `tool`, the quick tool the page sees: only Select and the
|
||||
/// Fill & Sign tools move comments.
|
||||
pub fn paint(&self, draw: &Draw<'_>, cx: &PageCx<'_>, tool: QuickTool, cv: &CommentView, pending: Option<&Edit>) {
|
||||
pub fn paint(&self, draw: &Draw<'_>, cx: &PageCx<'_>, map: &PageMap<'_>, tool: QuickTool, cv: &CommentView, pending: Option<&Edit>) {
|
||||
let (Some((_, page, index)), Some(layers)) = (self.key, &self.layers) else { return };
|
||||
if page != cx.page || !matches!(tool, QuickTool::Select | QuickTool::Fill(_)) || cx.hidden {
|
||||
return;
|
||||
@@ -294,7 +294,7 @@ impl SignatureDrag {
|
||||
{
|
||||
return;
|
||||
}
|
||||
let rect = cx.adjusted_rect(a, in_flight, pending);
|
||||
let rect = cx.adjusted_rect(map, a, in_flight, pending);
|
||||
draw.clipped(cx.xf.rect, |draw| {
|
||||
paint_quad(draw, page_corners(cx.xf), background.id);
|
||||
match &layers.front {
|
||||
@@ -369,7 +369,7 @@ impl SignatureDrag {
|
||||
}
|
||||
|
||||
/// The comment being moved, drawn where it goes (as far as its frame has gone).
|
||||
pub fn paint_move(&self, draw: &Draw<'_>, cx: &PageCx<'_>, cv: &CommentView, pending: Option<&Edit>) {
|
||||
pub fn paint_move(&self, draw: &Draw<'_>, cx: &PageCx<'_>, map: &PageMap<'_>, cv: &CommentView, pending: Option<&Edit>) {
|
||||
let Some(((_, page, index), m)) = &self.moving else { return };
|
||||
if *page != cx.page || cx.hidden {
|
||||
return;
|
||||
@@ -377,7 +377,7 @@ impl SignatureDrag {
|
||||
let Some(a) = cx.get(*index) else { return };
|
||||
// As far as its frame has gone from where the move started (once applied, its box is
|
||||
// already where it went).
|
||||
let rect = cx.adjusted_rect(a, cv.tool.in_flight(), pending);
|
||||
let rect = cx.adjusted_rect(map, a, cv.tool.in_flight(), pending);
|
||||
let from = cx.xf.user_rect(cx.info, *page, m.layer.from);
|
||||
draw.clipped(cx.xf.rect, |draw| m.layer.paint(draw, cx, *page, from.translate(rect.min - from.min)));
|
||||
}
|
||||
|
||||
@@ -119,6 +119,12 @@ impl PdfCraftApp {
|
||||
self.unpin_tool(&tool);
|
||||
}
|
||||
}
|
||||
// A row that opens Preferences on one of its pages (the theme button's Appearance settings…).
|
||||
"app.preferences" if fired.command.params.get("tab").is_some() => {
|
||||
if let Some(page) = fired.command.params.get("tab").and_then(serde_json::Value::as_str) {
|
||||
self.open_preferences_at(page);
|
||||
}
|
||||
}
|
||||
"app.theme" => self.toggle_theme(ctx),
|
||||
"tools.expand" => self.expand_all_tools(ctx),
|
||||
"tools.collapse" => self.all_tools_full = false,
|
||||
|
||||
@@ -25,9 +25,10 @@ fn field_colour(c: pdfcraft_engine::Rgb) -> FieldValue {
|
||||
FieldValue::Color(c.map(|v| v as f32))
|
||||
}
|
||||
|
||||
/// A dialog field's colour as the comment's.
|
||||
/// A dialog field's colour as the comment's. Each channel is the decimal the `f32` shows (its shortest form), not
|
||||
/// its binary widening: a colour the dialog opened with or was given (0.18) comes back as itself, not 0.18000000715.
|
||||
fn rgb(c: [f32; 3]) -> pdfcraft_engine::Rgb {
|
||||
c.map(f64::from)
|
||||
c.map(|v| v.to_string().parse().unwrap_or(f64::from(v)))
|
||||
}
|
||||
|
||||
/// Where the Comment Properties dialog stands: the id the dialog host returned for it, and what it
|
||||
|
||||
@@ -172,6 +172,14 @@ impl PdfCraftApp {
|
||||
}
|
||||
}
|
||||
|
||||
/// Opens Preferences, or leaves the open window as it is, showing the page `page` (the id its `PageSpec` has).
|
||||
pub(crate) fn open_preferences_at(&mut self, page: &str) {
|
||||
self.open_preferences();
|
||||
if let Some(session) = self.preferences.as_mut() {
|
||||
session.state.selected = page.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// Shows the Preferences window for this pass while it is open, and closes it when answered.
|
||||
pub(crate) fn show_preferences(&mut self, ui: &mut Ui) {
|
||||
let Some(mut session) = self.preferences.take() else {
|
||||
|
||||
@@ -135,8 +135,9 @@ impl StackDialog for WordCountDialog {
|
||||
(tl!("Characters without spaces"), report.total.characters_without_spaces),
|
||||
(tl!("Pages counted"), report.pages.len()),
|
||||
] {
|
||||
Field::new(label.to_string()).show(ui, |ui, _| {
|
||||
Text::new(value.to_string()).show(ui);
|
||||
let value = value.to_string();
|
||||
Field::new(label.to_string()).value(value.clone()).show(ui, |ui, _| {
|
||||
Text::new(value.clone()).show(ui);
|
||||
});
|
||||
}
|
||||
if report.pages_without_text > 0 {
|
||||
@@ -217,13 +218,9 @@ mod tests {
|
||||
PdfCraftApp::with_host(Arc::new(host), services)
|
||||
}
|
||||
|
||||
/// The figure in the Words row of the open dialog: the value beside the row's label.
|
||||
/// The figure in the Words row of the open dialog: the value its readout field reports.
|
||||
fn words_shown(h: &Harness<'_, PdfCraftApp>) -> String {
|
||||
let row = h.get_by_label("Words").parent().expect("the Words label sits in its row");
|
||||
row.children_recursive()
|
||||
.filter_map(|n| n.accesskit_node().label().map(|l| l.to_string()))
|
||||
.find(|l| l.chars().all(|c| c.is_ascii_digit()))
|
||||
.expect("the row shows a figure")
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Group, "Words").value().expect("the Words row reports a figure")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -1,18 +1,19 @@
|
||||
//! The one place that maps the engine's annotations and `Edit`s to the framework's `Annotation` and `AnnotationEdit`
|
||||
//! and back. The framework's page units here are the page as shown: its `/Rotate` and the view's quarter turn both
|
||||
//! applied, in points, top-left origin. [`PageMap`] carries the view's turn.
|
||||
//! and back. The framework's annotation tool and overlay work in the canvas's document space (`CanvasView::to_doc`
|
||||
//! of a screen point), where every placed page sits at its place in the layout; [`PageMap`] maps a page's user space
|
||||
//! to it and back, through the page as shown (its `/Rotate` and the view's quarter turn both applied).
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
use chrono::NaiveDate;
|
||||
use craft::behavior::kurbo::{Point, Rect, Vec2};
|
||||
use craft::behavior::{Cursor, CursorIcon};
|
||||
use craft::behavior::{CanvasView, Cursor, CursorIcon};
|
||||
use craft::pages::ui::PlacedPage;
|
||||
use craft::review::annotate::{marker_rect, pick_at};
|
||||
use craft::review::ui::AnnotateTool;
|
||||
use craft::review::{Annotation as Marked, AnnotationEdit, AnnotationId, AnnotationKind, HandleRule, Placement, ThreadId};
|
||||
|
||||
use super::geometry::{CARET_SIZE, clamp_to, frame, is_callout, on_text, reshapable, resizable};
|
||||
use super::geometry::{CARET_SIZE, frame, is_callout, on_text, reshapable, resizable};
|
||||
use super::popups::has_popup;
|
||||
use super::state::{CommentView, Composer, ComposerKind, PageCx};
|
||||
use super::{
|
||||
@@ -45,8 +46,8 @@ pub(crate) fn thread_key(thread: ThreadId) -> (usize, usize) {
|
||||
key_of(AnnotationId(thread.0))
|
||||
}
|
||||
|
||||
/// The pages on screen this pass with the document's page geometry: the maps between a page's user space, its
|
||||
/// displayed space (the framework's page units) and the screen.
|
||||
/// The pages on screen this pass with the document's page geometry and the canvas view that shows them: the maps
|
||||
/// between a page's user space, the canvas's document space (the framework's annotation units) and the screen.
|
||||
pub(crate) struct PageMap<'a> {
|
||||
/// The pages placed on screen.
|
||||
pub pages: &'a [PlacedPage],
|
||||
@@ -54,12 +55,14 @@ pub(crate) struct PageMap<'a> {
|
||||
pub info: &'a DocInfo,
|
||||
/// The view's quarter turn in degrees, which the placed pages show but `PageInfo`'s own transform does not.
|
||||
pub rotation: u16,
|
||||
/// The canvas view the pages are shown in this pass.
|
||||
pub view: CanvasView,
|
||||
}
|
||||
|
||||
impl<'a> PageMap<'a> {
|
||||
/// A map over `pages` of the document `info`, shown turned by `rotation` degrees.
|
||||
pub(crate) fn new(info: &'a DocInfo, pages: &'a [PlacedPage], rotation: u16) -> Self {
|
||||
Self { pages, info, rotation }
|
||||
/// A map over `pages` of the document `info`, shown turned by `rotation` degrees in the canvas `view`.
|
||||
pub(crate) fn new(info: &'a DocInfo, pages: &'a [PlacedPage], rotation: u16, view: CanvasView) -> Self {
|
||||
Self { pages, info, rotation, view }
|
||||
}
|
||||
|
||||
fn placed(&self, page: usize) -> Option<&PlacedPage> {
|
||||
@@ -70,67 +73,132 @@ impl<'a> PageMap<'a> {
|
||||
self.info.pages.get(page).is_some() && self.placed(page).is_some()
|
||||
}
|
||||
|
||||
/// A user-space point of `page` in the page's displayed units.
|
||||
/// The map between `page`'s displayed units and document space, when the page is placed.
|
||||
pub(crate) fn frame(&self, page: usize) -> Option<PageFrame> {
|
||||
let placed = self.placed(page)?;
|
||||
Some(PageFrame { origin: Point::new(f64::from(placed.rect.min.x), f64::from(placed.rect.min.y)), scale: placed.scale, view: self.view })
|
||||
}
|
||||
|
||||
/// A user-space point of `page` in the canvas's document space. A page not placed this pass has no place there:
|
||||
/// its displayed point stands in.
|
||||
pub(crate) fn to_doc(&self, page: usize, user: [f64; 2]) -> Point {
|
||||
match self.info.pages.get(page) {
|
||||
let shown = match self.info.pages.get(page) {
|
||||
Some(p) => turned_point(p, self.rotation, [user[0] as f32, user[1] as f32]),
|
||||
None => Point::new(user[0], user[1]),
|
||||
};
|
||||
match self.frame(page) {
|
||||
Some(frame) => frame.doc(shown),
|
||||
None => shown,
|
||||
}
|
||||
}
|
||||
|
||||
/// A displayed point of `page` in the page's user space.
|
||||
/// A document point in the user space of `page`.
|
||||
pub(crate) fn to_user(&self, page: usize, at: Point) -> [f64; 2] {
|
||||
let shown = match self.frame(page) {
|
||||
Some(frame) => frame.shown(at),
|
||||
None => at,
|
||||
};
|
||||
match self.info.pages.get(page) {
|
||||
Some(p) => unturned_point(p, self.rotation, at),
|
||||
None => [at.x, at.y],
|
||||
Some(p) => unturned_point(p, self.rotation, shown),
|
||||
None => [shown.x, shown.y],
|
||||
}
|
||||
}
|
||||
|
||||
/// A user-space rectangle of `page` as the document rectangle that bounds it.
|
||||
fn doc_rect(&self, page: usize, r: [f32; 4]) -> Rect {
|
||||
let corners = [[r[0], r[1]], [r[2], r[1]], [r[2], r[3]], [r[0], r[3]]].map(|[x, y]| self.to_doc(page, [f64::from(x), f64::from(y)]));
|
||||
bounds(&corners).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// A document rectangle as the user-space rectangle of `page` that bounds it.
|
||||
fn user_rect(&self, page: usize, r: Rect) -> [f32; 4] {
|
||||
let corners = [(r.x0, r.y0), (r.x1, r.y0), (r.x1, r.y1), (r.x0, r.y1)].map(|(x, y)| self.to_user(page, Point::new(x, y)));
|
||||
let fold = |f: fn(f64, f64) -> f64, i: usize, seed: f64| corners.iter().fold(seed, |m, c| f(m, c[i])) as f32;
|
||||
[fold(f64::min, 0, f64::MAX), fold(f64::min, 1, f64::MAX), fold(f64::max, 0, f64::MIN), fold(f64::max, 1, f64::MIN)]
|
||||
}
|
||||
|
||||
/// A document offset as the user-space offset it makes on `page`.
|
||||
fn user_delta(&self, page: usize, d: Vec2) -> (f64, f64) {
|
||||
let (o, p) = (self.to_user(page, Point::ZERO), self.to_user(page, Point::ZERO + d));
|
||||
(p[0] - o[0], p[1] - o[1])
|
||||
}
|
||||
|
||||
/// A document length as the user-space length it makes on `page`.
|
||||
fn user_len(&self, page: usize, len: f64) -> f64 {
|
||||
let (dx, dy) = self.user_delta(page, Vec2::new(len, 0.0));
|
||||
dx.hypot(dy)
|
||||
}
|
||||
|
||||
/// A document length as a length in the displayed units of `page`.
|
||||
pub(crate) fn shown_len(&self, page: usize, len: f64) -> f64 {
|
||||
self.frame(page).map_or(len, |frame| frame.shown_len(len))
|
||||
}
|
||||
|
||||
/// The whole of `page` in document space.
|
||||
fn page_rect(&self, page: usize) -> Option<Rect> {
|
||||
let placed = self.placed(page)?;
|
||||
let r = placed.rect;
|
||||
bounds(&[r.left_top(), r.right_top(), r.right_bottom(), r.left_bottom()].map(|p| self.view.to_doc(p)))
|
||||
}
|
||||
|
||||
/// The placed page under the screen point `screen`.
|
||||
// PLAN: the sheet's `page_at(Point)` takes a screen point: a displayed point alone cannot say which page.
|
||||
// PLAN: the sheet's `page_at(Point)` takes a screen point: a document point alone cannot say which page.
|
||||
pub(crate) fn page_at(&self, screen: Point) -> Option<usize> {
|
||||
let at = egui::pos2(screen.x as f32, screen.y as f32);
|
||||
self.pages.iter().find(|p| p.rect.contains(at)).map(|p| p.page)
|
||||
}
|
||||
|
||||
/// The displayed point of `page` under the screen point `screen`.
|
||||
/// The document point under the screen point `screen`, where `page` is placed.
|
||||
pub(crate) fn to_page(&self, page: usize, screen: Point) -> Option<Point> {
|
||||
Some(self.placed(page)?.to_page(egui::pos2(screen.x as f32, screen.y as f32)))
|
||||
self.placed(page)?;
|
||||
Some(self.view.to_doc(egui::pos2(screen.x as f32, screen.y as f32)))
|
||||
}
|
||||
|
||||
/// The screen position of the displayed point `at` of `page`.
|
||||
/// The screen position of the document point `at`, where `page` is placed.
|
||||
pub(crate) fn to_screen(&self, page: usize, at: Point) -> Option<egui::Pos2> {
|
||||
Some(self.placed(page)?.to_screen(at))
|
||||
self.placed(page)?;
|
||||
Some(self.view.to_screen(at))
|
||||
}
|
||||
|
||||
/// A length of `screen` points as page units. Every page is shown at one zoom, so the first placed page's scale
|
||||
/// serves.
|
||||
// PLAN: the sheet's `doc_len(screen)` has no page: the pages share one scale.
|
||||
/// A length of `screen` points in document units.
|
||||
pub(crate) fn doc_len(&self, screen: f32) -> f64 {
|
||||
let scale = self.pages.first().map_or(1.0, |p| p.scale);
|
||||
if scale.is_finite() && scale > 0.0 { f64::from(screen) / scale } else { f64::from(screen) }
|
||||
self.view.doc_len(screen)
|
||||
}
|
||||
}
|
||||
|
||||
/// `PageInfo` has one entry per page; this names the "is there such a page" question for [`PageMap::shows`].
|
||||
trait HasPage {
|
||||
fn contains_key_page(&self, page: usize) -> bool;
|
||||
/// One placed page's map between its displayed units (the page as shown, top-left origin) and the canvas's document
|
||||
/// space, owned, for what outlives the pass's borrows (the caret snap).
|
||||
#[derive(Clone, Copy)]
|
||||
pub(crate) struct PageFrame {
|
||||
/// The page's top-left corner on screen.
|
||||
origin: Point,
|
||||
/// Screen points per displayed unit.
|
||||
scale: f64,
|
||||
view: CanvasView,
|
||||
}
|
||||
|
||||
impl HasPage for Vec<PageInfo> {
|
||||
fn contains_key_page(&self, page: usize) -> bool {
|
||||
page < self.len()
|
||||
impl PageFrame {
|
||||
/// The document point of the displayed point `shown`. In f64 through the view's own affine, so a point that goes
|
||||
/// there and back comes back where it was.
|
||||
pub(crate) fn doc(&self, shown: Point) -> Point {
|
||||
self.view.affine().inverse() * (self.origin + shown.to_vec2() * self.scale)
|
||||
}
|
||||
}
|
||||
|
||||
fn view_point(page: &PageInfo, user: [f32; 2]) -> Point {
|
||||
let v = page.user_to_view(user[0], user[1]);
|
||||
Point::new(f64::from(v[0]), f64::from(v[1]))
|
||||
}
|
||||
/// The displayed point at the document point `at`.
|
||||
pub(crate) fn shown(&self, at: Point) -> Point {
|
||||
let on_screen = self.view.affine() * at;
|
||||
Point::ORIGIN + (on_screen - self.origin) / self.scale
|
||||
}
|
||||
|
||||
fn user_point(page: &PageInfo, at: Point) -> [f64; 2] {
|
||||
let u = page.view_to_user(at.x as f32, at.y as f32);
|
||||
[f64::from(u[0]), f64::from(u[1])]
|
||||
/// A document length in displayed units.
|
||||
pub(crate) fn shown_len(&self, len: f64) -> f64 {
|
||||
if self.scale > 0.0 { len * self.view.zoom / self.scale } else { len }
|
||||
}
|
||||
|
||||
/// A displayed length in document units.
|
||||
pub(crate) fn doc_len(&self, len: f64) -> f64 {
|
||||
if self.view.zoom > 0.0 { len * self.scale / self.view.zoom } else { len }
|
||||
}
|
||||
}
|
||||
|
||||
/// A user-space point as the displayed point of a page the view turns clockwise by `rotation` degrees.
|
||||
@@ -160,31 +228,6 @@ fn unturned_point(page: &PageInfo, rotation: u16, at: Point) -> [f64; 2] {
|
||||
[f64::from(u[0]), f64::from(u[1])]
|
||||
}
|
||||
|
||||
/// A user-space rectangle as the displayed rectangle that bounds it.
|
||||
fn view_rect(page: &PageInfo, r: [f32; 4]) -> Rect {
|
||||
let (a, b) = (view_point(page, [r[0], r[1]]), view_point(page, [r[2], r[3]]));
|
||||
Rect::new(a.x.min(b.x), a.y.min(b.y), a.x.max(b.x), a.y.max(b.y))
|
||||
}
|
||||
|
||||
/// A displayed rectangle as the user-space rectangle that bounds it.
|
||||
fn user_rect(page: &PageInfo, r: Rect) -> [f32; 4] {
|
||||
let corners = [(r.x0, r.y0), (r.x1, r.y0), (r.x1, r.y1), (r.x0, r.y1)].map(|(x, y)| page.view_to_user(x as f32, y as f32));
|
||||
let fold = |f: fn(f32, f32) -> f32, i: usize, seed: f32| corners.iter().fold(seed, |m, c| f(m, c[i]));
|
||||
[fold(f32::min, 0, f32::MAX), fold(f32::min, 1, f32::MAX), fold(f32::max, 0, f32::MIN), fold(f32::max, 1, f32::MIN)]
|
||||
}
|
||||
|
||||
/// A displayed offset as the user-space offset it makes.
|
||||
fn user_delta(page: &PageInfo, d: Vec2) -> (f64, f64) {
|
||||
let (o, p) = (page.view_to_user(0.0, 0.0), page.view_to_user(d.x as f32, d.y as f32));
|
||||
(f64::from(p[0]) - f64::from(o[0]), f64::from(p[1]) - f64::from(o[1]))
|
||||
}
|
||||
|
||||
/// A displayed length as the user-space length it makes.
|
||||
fn user_len(page: &PageInfo, len: f64) -> f64 {
|
||||
let (dx, dy) = user_delta(page, Vec2::new(len, 0.0));
|
||||
dx.hypot(dy)
|
||||
}
|
||||
|
||||
fn bounds(points: &[Point]) -> Option<Rect> {
|
||||
let first = points.first()?;
|
||||
let seed = Rect::new(first.x, first.y, first.x, first.y);
|
||||
@@ -206,25 +249,28 @@ pub(crate) fn rgb8(c: [f32; 3]) -> [u8; 3] {
|
||||
c.map(|v| (v.clamp(0.0, 1.0) * 255.0).round() as u8)
|
||||
}
|
||||
|
||||
/// The framework's annotation for `a`, with `members` (its group's subordinates) joined to its shape.
|
||||
/// The framework's annotation for `a`, in `map`'s document space, with `members` (its group's subordinates) joined
|
||||
/// to its shape.
|
||||
// PLAN: `DocInfo` carries no ink strokes, opacity or line width, and the image signatures' aspect lives in the view's
|
||||
// signature drag: `strokes` is empty, opacity 1 and width 1, and `aspect` is only a drawn signature's box.
|
||||
pub(super) fn marked(info: &DocInfo, a: &Annotation, members: &[&Annotation], allowed: bool) -> Option<Marked> {
|
||||
pub(super) fn marked(map: &PageMap<'_>, a: &Annotation, members: &[&Annotation], allowed: bool) -> Option<Marked> {
|
||||
let info = map.info;
|
||||
let page = info.pages.get(a.page)?;
|
||||
let kind = kind_of(&info.annotations, a);
|
||||
let rotation = page.rotation;
|
||||
let mut rect = view_rect(page, frame(a, rotation));
|
||||
let mut rect = map.doc_rect(a.page, frame(a, rotation));
|
||||
for m in members {
|
||||
rect = rect.union(view_rect(page, m.shown_rect(rotation)));
|
||||
rect = rect.union(map.doc_rect(a.page, m.shown_rect(rotation)));
|
||||
}
|
||||
let doc = |p: [f32; 2]| map.to_doc(a.page, [f64::from(p[0]), f64::from(p[1])]);
|
||||
let points = if kind.is_pointwise() {
|
||||
a.points.iter().map(|q| view_point(page, *q)).collect()
|
||||
a.points.iter().map(|q| doc(*q)).collect()
|
||||
} else if kind.is_markup() {
|
||||
std::iter::once(a)
|
||||
.chain(members.iter().copied())
|
||||
.flat_map(|m| m.quads.iter())
|
||||
.flat_map(|q| [[q[0], q[1]], [q[2], q[3]], [q[4], q[5]], [q[6], q[7]]])
|
||||
.map(|p| view_point(page, p))
|
||||
.map(doc)
|
||||
.collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
@@ -281,23 +327,17 @@ pub(crate) fn annotations(info: &DocInfo, map: &PageMap<'_>, tool: QuickTool, al
|
||||
all.iter()
|
||||
.enumerate()
|
||||
.filter(|(_, a)| a.is_comment() && a.subtype != "Popup" && map.shows(a.page) && pick(a))
|
||||
.filter_map(|(i, a)| marked(info, a, members.get(&i).map_or(&[][..], Vec::as_slice), allowed))
|
||||
.filter_map(|(i, a)| marked(map, a, members.get(&i).map_or(&[][..], Vec::as_slice), allowed))
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn marker_boxes(info: &DocInfo, anns: &[Marked], icon_side: f64) -> Vec<(AnnotationId, Rect)> {
|
||||
anns.iter()
|
||||
.filter_map(|a| {
|
||||
let p = info.pages.get(a.page)?;
|
||||
let page = Rect::new(0.0, 0.0, f64::from(p.width), f64::from(p.height));
|
||||
marker_rect(a, page, icon_side).map(|r| (a.id, r))
|
||||
})
|
||||
.collect()
|
||||
fn marker_boxes(map: &PageMap<'_>, anns: &[Marked], icon_side: f64) -> Vec<(AnnotationId, Rect)> {
|
||||
anns.iter().filter_map(|a| marker_rect(a, map.page_rect(a.page)?, icon_side).map(|r| (a.id, r))).collect()
|
||||
}
|
||||
|
||||
/// The markers of commented text markup, in displayed units, an `icon_side` square.
|
||||
/// The markers of commented text markup, in document units, an `icon_side` square.
|
||||
pub(crate) fn markers(info: &DocInfo, map: &PageMap<'_>, icon_side: f64) -> Vec<(AnnotationId, Rect)> {
|
||||
marker_boxes(info, &annotations(info, map, QuickTool::Select, true), icon_side)
|
||||
marker_boxes(map, &annotations(info, map, QuickTool::Select, true), icon_side)
|
||||
}
|
||||
|
||||
/// Whether `tool` shows tips at all: not with Fill & Sign, whose placement stays clear, and not while drawing
|
||||
@@ -358,7 +398,7 @@ pub(crate) fn parts(
|
||||
let _ = at;
|
||||
let Some(at) = map.to_page(page, screen) else { return Vec::new() };
|
||||
let anns: Vec<Marked> = annotations(info, map, tool, true).into_iter().filter(|a| a.page == page).collect();
|
||||
let markers = marker_boxes(info, &anns, icon_side);
|
||||
let markers = marker_boxes(map, &anns, icon_side);
|
||||
let Some(id) = pick_at(&anns, at, tolerance, icon_side, &markers) else { return Vec::new() };
|
||||
let Some(found) = anns.iter().find(|a| a.id == id) else { return Vec::new() };
|
||||
// A markup's lines, or its box when it has none (a highlight with no /QuadPoints is picked by its box too).
|
||||
@@ -402,12 +442,12 @@ fn targets(edit: &AnnotationEdit, id: AnnotationId) -> bool {
|
||||
|
||||
/// Where the in-flight `edit` leaves `a`, as a user-space rectangle, when it is `a`'s: what the live image, the
|
||||
/// handles and the released edit all draw.
|
||||
pub(super) fn edited_user_rect(info: &DocInfo, a: &Annotation, edit: &AnnotationEdit) -> Option<[f32; 4]> {
|
||||
let own = marked(info, a, &[], true)?;
|
||||
pub(super) fn edited_user_rect(map: &PageMap<'_>, a: &Annotation, edit: &AnnotationEdit) -> Option<[f32; 4]> {
|
||||
let own = marked(map, a, &[], true)?;
|
||||
if !targets(edit, own.id) {
|
||||
return None;
|
||||
}
|
||||
Some(user_rect(info.pages.get(a.page)?, own.edited(edit)?.rect))
|
||||
Some(map.user_rect(a.page, own.edited(edit)?.rect))
|
||||
}
|
||||
|
||||
/// The engine edit for one framework edit. A gesture that changes nothing (a click with no drag) gives none.
|
||||
@@ -419,7 +459,7 @@ pub(crate) fn edit(e: AnnotationEdit, map: &PageMap<'_>, view: &mut CommentView,
|
||||
AnnotationEdit::Resize { id, rect } => {
|
||||
let (page, index) = key_of(id);
|
||||
engine(info, page, index).filter(|a| resizable(a))?;
|
||||
let r = user_rect(info.pages.get(page)?, rect).map(f64::from);
|
||||
let r = map.user_rect(page, rect).map(f64::from);
|
||||
Some(Edit::ResizeAnnotation { page, index, rect: r })
|
||||
}
|
||||
AnnotationEdit::Reshape { id, points } => {
|
||||
@@ -482,9 +522,8 @@ fn moved(ids: &[AnnotationId], delta: Vec2, map: &PageMap<'_>, info: &DocInfo) -
|
||||
// moved with its comment.
|
||||
let a = engine(info, page, index).filter(|a| !a.is_reply() && !on_text(a) && !a.locked)?;
|
||||
let p = info.pages.get(page)?;
|
||||
// The delta is in the page as shown, the view's turn included: the map takes it back to user space.
|
||||
let (from, to) = (map.to_user(page, Point::ZERO), map.to_user(page, Point::ZERO + delta));
|
||||
let (dx, dy) = (to[0] - from[0], to[1] - from[1]);
|
||||
// The delta is in document space: the map takes it back to user space, the view's turn included.
|
||||
let (dx, dy) = map.user_delta(page, delta);
|
||||
if !(dx.is_finite() && dy.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
@@ -536,9 +575,11 @@ fn erased(ids: &[AnnotationId], path: &[Point], radius: f64, map: &PageMap<'_>,
|
||||
hits.dedup();
|
||||
let edits: Vec<Edit> = hits
|
||||
.into_iter()
|
||||
.filter_map(|(page, index)| {
|
||||
let p = info.pages.get(page)?;
|
||||
Some(Edit::EraseInk { page, index, path: path.iter().map(|q| map.to_user(page, *q)).collect(), radius: user_len(p, radius) })
|
||||
.map(|(page, index)| Edit::EraseInk {
|
||||
page,
|
||||
index,
|
||||
path: path.iter().map(|q| map.to_user(page, *q)).collect(),
|
||||
radius: map.user_len(page, radius),
|
||||
})
|
||||
.collect();
|
||||
(!edits.is_empty()).then(|| Edit::Batch { label: "Erase".into(), edits })
|
||||
@@ -546,12 +587,8 @@ fn erased(ids: &[AnnotationId], path: &[Point], radius: f64, map: &PageMap<'_>,
|
||||
|
||||
fn create(a: &Marked, map: &PageMap<'_>, prefs: &CommentPrefs) -> Option<Edit> {
|
||||
let tool = CommentTool::from_kind(a.kind)?;
|
||||
let page = map.info.pages.get(a.page)?;
|
||||
let bounds = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(page.width, page.height));
|
||||
let user = |p: Point| {
|
||||
let c = clamp_to(bounds, egui::pos2(p.x as f32, p.y as f32));
|
||||
map.to_user(a.page, Point::new(f64::from(c.x), f64::from(c.y)))
|
||||
};
|
||||
let page = map.page_rect(a.page)?;
|
||||
let user = |p: Point| map.to_user(a.page, Point::new(p.x.clamp(page.x0, page.x1), p.y.clamp(page.y0, page.y1)));
|
||||
let pts: Vec<[f64; 2]> = a.points.iter().map(|p| user(*p)).collect();
|
||||
let strokes = || -> Vec<Vec<[f64; 2]>> { a.strokes.iter().map(|s| s.iter().map(|p| user(*p)).collect()).collect() };
|
||||
let boxed = || {
|
||||
@@ -594,12 +631,12 @@ fn place(p: &Placement, map: &PageMap<'_>, view: &mut CommentView) {
|
||||
let at = map.to_user(p.page, p.at);
|
||||
let kind = match p.kind {
|
||||
AnnotationKind::Note => ComposerKind::Note,
|
||||
AnnotationKind::TextBox => ComposerKind::TextBox { size: p.size.map(|s| [s.x, s.y]) },
|
||||
AnnotationKind::TextBox => ComposerKind::TextBox { size: p.size.map(|s| [map.shown_len(p.page, s.x), map.shown_len(p.page, s.y)]) },
|
||||
AnnotationKind::Callout => {
|
||||
let Some(from) = p.from else { return };
|
||||
ComposerKind::Callout { point: map.to_user(p.page, from) }
|
||||
}
|
||||
AnnotationKind::Caret => ComposerKind::Caret { size: p.size.map_or(CARET_SIZE, |s| s.y) },
|
||||
AnnotationKind::Caret => ComposerKind::Caret { size: p.size.map_or(CARET_SIZE, |s| map.shown_len(p.page, s.y)) },
|
||||
AnnotationKind::Attach => {
|
||||
view.attach_at = Some((p.page, at));
|
||||
view.select(None);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::{Annotation, DocInfo, PageInfo, PageText, Pos2, Rect, pos2};
|
||||
use super::{Annotation, DocInfo, PageInfo, PageText};
|
||||
|
||||
pub(super) fn is_markup(subtype: &str) -> bool {
|
||||
matches!(subtype, "Highlight" | "Underline" | "StrikeOut" | "Squiggly")
|
||||
@@ -41,10 +41,6 @@ pub(super) fn frame(a: &Annotation, rotation: u16) -> [f32; 4] {
|
||||
a.text_box.unwrap_or_else(|| a.shown_rect(rotation))
|
||||
}
|
||||
|
||||
pub(super) fn clamp_to(r: Rect, p: Pos2) -> Pos2 {
|
||||
pos2(p.x.clamp(r.left(), r.right()), p.y.clamp(r.top(), r.bottom()))
|
||||
}
|
||||
|
||||
/// The side of the caret's box, in user space units, away from text.
|
||||
pub(super) const CARET_SIZE: f64 = 8.0;
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ pub(crate) struct Hover {
|
||||
pub pointer: Option<Pos2>,
|
||||
/// The user's Redaction Tool Properties fill and opacity.
|
||||
pub redact: ([f64; 3], f64),
|
||||
/// The page-unit `(tolerance, icon side)` of the hit test.
|
||||
/// The document-unit `(tolerance, icon side)` of the hit test.
|
||||
pub pick: (f64, f64),
|
||||
/// The document allows commenting.
|
||||
pub allowed: bool,
|
||||
@@ -43,7 +43,7 @@ pub(crate) fn show(
|
||||
tool: QuickTool,
|
||||
hover: Hover,
|
||||
) {
|
||||
let map = PageMap::new(info, body.pages, rotation);
|
||||
let map = PageMap::new(info, body.pages, rotation, body.view);
|
||||
let all = bridge::annotations(info, &map, QuickTool::Select, hover.allowed);
|
||||
let reached = bridge::annotations(info, &map, tool, hover.allowed);
|
||||
let markers = bridge::markers(info, &map, hover.pick.1);
|
||||
@@ -68,7 +68,7 @@ pub(crate) fn show(
|
||||
}
|
||||
overlay.show(ui);
|
||||
let Some(at) = hover.pointer.filter(|p| idle && page.rect.contains(*p)) else { continue };
|
||||
let at = page.to_page(at);
|
||||
let at = body.view.to_doc(at);
|
||||
let (tolerance, icon_side) = hover.pick;
|
||||
let under = pick_at(&on_page, at, tolerance, icon_side, &markers).and_then(|id| on_page.iter().find(|a| a.id == id));
|
||||
if let Some(a) = under
|
||||
|
||||
@@ -3,7 +3,7 @@ use std::collections::HashMap;
|
||||
use craft::review::AnnotationEdit;
|
||||
use craft::review::ui::{AnnotateTool, CommentsPanelState, NoteDrafts};
|
||||
|
||||
use super::bridge;
|
||||
use super::bridge::{self, PageMap};
|
||||
use super::geometry::{frame, is_markup};
|
||||
use super::tool::PastePlacement;
|
||||
use super::{Annotation, CommentPrefs, CommentTool, DocInfo, Edit, PageXform, Pos2, Rect};
|
||||
@@ -608,8 +608,8 @@ impl PageCx<'_> {
|
||||
|
||||
/// The same geometry drives the live image, its handles, and the edit on release: `pending` is
|
||||
/// the edit just released and not yet applied, `in_flight` the tool's edit while the pointer
|
||||
/// is down.
|
||||
pub(crate) fn adjusted_rect(&self, a: &Annotation, in_flight: Option<AnnotationEdit>, pending: Option<&Edit>) -> Rect {
|
||||
/// is down, in `map`'s document space.
|
||||
pub(crate) fn adjusted_rect(&self, map: &PageMap<'_>, a: &Annotation, in_flight: Option<AnnotationEdit>, pending: Option<&Edit>) -> Rect {
|
||||
if let Some(Edit::ResizeAnnotation { page, index, rect }) = pending
|
||||
&& (*page, *index) == (self.page, a.index)
|
||||
{
|
||||
@@ -621,7 +621,7 @@ impl PageCx<'_> {
|
||||
let f = frame(a, self.rotation());
|
||||
return self.xf.user_rect(self.info, self.page, [f[0] + *dx as f32, f[1] + *dy as f32, f[2] + *dx as f32, f[3] + *dy as f32]);
|
||||
}
|
||||
match in_flight.and_then(|edit| bridge::edited_user_rect(self.info, a, &edit)) {
|
||||
match in_flight.and_then(|edit| bridge::edited_user_rect(map, a, &edit)) {
|
||||
Some(r) => self.xf.user_rect(self.info, self.page, r),
|
||||
None => self.frame_rect(a),
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ fn placed_page(xf: &PageXform, zoom: f64) -> PlacedPage {
|
||||
PlacedPage::new(0, xf.rect, zoom, (0.0, xf.rect.height()), TextureState::Missing)
|
||||
}
|
||||
|
||||
/// The page map the app feeds `bridge` for `placed` pages shown turned `rotation` degrees.
|
||||
/// The page map the app feeds `bridge` for `placed` pages shown turned `rotation` degrees, in a canvas view whose
|
||||
/// document space is neither the screen nor the page's units, as the page view's is not.
|
||||
fn page_map<'a>(placed: &'a [PlacedPage], info: &'a DocInfo, rotation: u16) -> PageMap<'a> {
|
||||
PageMap::new(info, placed, rotation)
|
||||
let view = craft::behavior::CanvasView::new(Rect::from_min_size(Pos2::ZERO, vec2(800.0, 800.0)), Point::new(250.0, 300.0), 0.75);
|
||||
PageMap::new(info, placed, rotation, view)
|
||||
}
|
||||
|
||||
/// A rectangle in page units of `page` on screen, through the page map, for comparing a marker with the page's
|
||||
@@ -560,7 +562,8 @@ fn the_hover_outline_goes_round_what_a_press_would_take() {
|
||||
let over = Point::new(100.0, 100.0);
|
||||
let annotations = bridge::annotations(&info, &map, QuickTool::Select, true);
|
||||
let markers = bridge::markers(&info, &map, side);
|
||||
assert_eq!(pick_at(&annotations, over, tolerance, side, &markers), Some(bridge::id_of(0, 0)), "the highlight a press there selects");
|
||||
let at = map.to_page(0, over).expect("the page is placed");
|
||||
assert_eq!(pick_at(&annotations, at, tolerance, side, &markers), Some(bridge::id_of(0, 0)), "the highlight a press there selects");
|
||||
// PLAN: the outline shape itself is the overlay's `HoverOutline` (pdf-comments-w8); a request to w8 for an `overlay` helper
|
||||
// the test can compare against the part's annotation. The part registered at the pointer is asserted here.
|
||||
let parts =
|
||||
|
||||
@@ -201,10 +201,12 @@ impl CanvasTool for CommentsTool<'_> {
|
||||
draw.eraser_radius = eraser_radius(eraser_width);
|
||||
// The options are builders over the owned tool: rebuilt from the tool taken out, its gesture kept.
|
||||
let mut built = std::mem::take(self.annotate).select_options(select).draw_options(draw);
|
||||
// The snap reads the page's displayed units; the tool asks in document space.
|
||||
if self.quick == QuickTool::Comment(CommentTool::Caret)
|
||||
&& let Some(snap) = self.caret.take()
|
||||
&& let Some(frame) = self.map.frame(page)
|
||||
{
|
||||
built = built.caret_snap(snap);
|
||||
built = built.caret_snap(move |at| snap(frame.shown(at)).map(|(tip, side)| (frame.doc(tip), frame.doc_len(side))));
|
||||
}
|
||||
*self.annotate = built;
|
||||
self.annotate.each_pass(cx);
|
||||
|
||||
@@ -175,7 +175,8 @@ fn sidebar_comment_centres_the_annotation_at_high_zoom() {
|
||||
app.views[0].session.comments.clear_selection();
|
||||
app.set_option(&egui::Context::default(), "page", "1").unwrap();
|
||||
});
|
||||
h.get_by_label("Reveal this note").click();
|
||||
// The panel names a card by its author, text and date.
|
||||
h.get_by_label_contains("Reveal this note").click();
|
||||
h.run_steps(8);
|
||||
assert_eq!(h.state().views[0].session.comments.selection(), vec![(1, 0)], "the sidebar card was selected");
|
||||
let a = &comments(&h)[0];
|
||||
@@ -1622,9 +1623,10 @@ fn search_finds_a_comment_by_the_status_set_on_one_of_its_replies() {
|
||||
app.views[0].session.comments.panel.search_open = true;
|
||||
});
|
||||
h.run_steps(2);
|
||||
h.get_by_label("Plain root");
|
||||
h.get_by_label("Ordinary reply");
|
||||
assert_eq!(h.query_all_by_label("Other root").count(), 0, "the other comment has no such status");
|
||||
// The panel names a card or reply row by its author, text and date.
|
||||
h.get_by_label_contains("Plain root");
|
||||
h.get_by_label_contains("Ordinary reply");
|
||||
assert_eq!(h.query_all_by_label_contains("Other root").count(), 0, "the other comment has no such status");
|
||||
assert_eq!(h.query_all_by_label("No comments match.").count(), 0);
|
||||
}
|
||||
|
||||
@@ -1645,10 +1647,11 @@ trailer << /Root 1 0 R >>
|
||||
#[test]
|
||||
fn replies_follow_irt_references_when_names_repeat_on_every_page() {
|
||||
let h = harness_with_bytes(PER_PAGE_NAMES.to_vec(), |app| app.set_option(&egui::Context::default(), "panel", "comments").unwrap());
|
||||
let reply = h.get_by_label("Reply on page two");
|
||||
assert!(reply.rect().top() > h.get_by_label("Second page note").rect().top(), "the reply sits under page 2's comment");
|
||||
// The panel names a card or reply row by its author, text and date.
|
||||
let reply = h.get_by_label_contains("Reply on page two");
|
||||
assert!(reply.rect().top() > h.get_by_label_contains("Second page note").rect().top(), "the reply sits under page 2's comment");
|
||||
assert!(h.get_by_label("Page 2").rect().top() < reply.rect().top(), "not under page 1's comment, which shares the /NM");
|
||||
h.get_by_label("Answer on page two");
|
||||
h.get_by_label_contains("Answer on page two");
|
||||
// The header counts the two comments, not their replies (Acrobat says 2, not 4), and gives
|
||||
// the replies in small text under it.
|
||||
assert_eq!(h.query_all_by_label("4").count(), 0);
|
||||
@@ -1937,12 +1940,13 @@ fn the_panel_reveals_edits_and_reopens_a_late_thread_without_changing_its_replie
|
||||
app.set_option(&egui::Context::default(), "panel", "comments").unwrap();
|
||||
app.views[0].session.comments.panel.collapsed_pages = vec![0, 1];
|
||||
});
|
||||
assert_eq!(h.query_all_by_label("Late root").count(), 0);
|
||||
// The panel names a card or reply row by its author, text and date.
|
||||
assert_eq!(h.query_all_by_label_contains("Late root").count(), 0);
|
||||
h.state_mut().views[0].session.comments.select_only((1, 0));
|
||||
h.state_mut().views[0].session.comments.reveal = true;
|
||||
h.run_steps(4);
|
||||
h.get_by_label("Late root");
|
||||
h.get_by_label("Late thread reply");
|
||||
h.get_by_label_contains("Late root");
|
||||
h.get_by_label_contains("Late thread reply");
|
||||
assert_eq!(h.state().views[0].session.comments.panel.collapsed_pages, vec![0]);
|
||||
h.get_by_label("More").click();
|
||||
h.run_steps(2);
|
||||
@@ -3403,11 +3407,12 @@ trailer << /Root 1 0 R >>
|
||||
#[test]
|
||||
fn a_group_is_one_comment_in_the_panel_and_on_the_page() {
|
||||
let mut h = harness_with_bytes(GROUP_FIXTURE.to_vec(), |app| app.set_option(&egui::Context::default(), "panel", "comments").unwrap());
|
||||
h.get_by_label("Primary");
|
||||
h.get_by_label("Plain reply");
|
||||
h.get_by_label("Reply to the subordinate");
|
||||
assert_eq!(h.query_all_by_label("Subordinate").count(), 0, "the subordinate's own text is ignored");
|
||||
assert_eq!(h.query_all_by_label("Bob").count(), 0, "the subordinate's own author is ignored");
|
||||
// The panel names a card or reply row by its author, text and date.
|
||||
h.get_by_label_contains("Primary");
|
||||
h.get_by_label_contains("Plain reply");
|
||||
h.get_by_label_contains("Reply to the subordinate");
|
||||
assert_eq!(h.query_all_by_label_contains("Subordinate").count(), 0, "the subordinate's own text is ignored");
|
||||
assert_eq!(h.query_all_by_label_contains("Bob").count(), 0, "the subordinate's own author is ignored");
|
||||
let p = at(&h, 220.0, 150.0);
|
||||
click(&mut h, p);
|
||||
assert_eq!(h.state().views[0].session.comments.selection(), vec![(0, 0)], "clicking the Circle selects its group");
|
||||
@@ -3479,8 +3484,8 @@ fn choosing_the_groups_card_makes_delete_act_on_the_card_not_the_member_clicked(
|
||||
let mut h = harness_with_bytes(GROUP_FIXTURE.to_vec(), |app| app.set_option(&egui::Context::default(), "panel", "comments").unwrap());
|
||||
click_pt(&mut h, (220.0, 150.0));
|
||||
assert_eq!(h.state().views[0].session.comments.primary(), Some((0, 0)), "the Circle's click selects the group");
|
||||
// The selected card's header row, with its author.
|
||||
h.get_by_label("Alice").click();
|
||||
// The selected card, named by its author first.
|
||||
h.get_by(|n| n.role() == Role::TreeItem && n.label().is_some_and(|l| l.starts_with("Alice:"))).click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(h.state().views[0].session.comments.primary(), Some((0, 0)), "the card selects the same group");
|
||||
assert_eq!(h.state().views[0].session.comments.selection().len(), 1, "only the group's card");
|
||||
|
||||
@@ -31,7 +31,7 @@ fn compare_two_versions() {
|
||||
assert_eq!(crate::support::right(h.state()), Some(RightPanel::Compare));
|
||||
assert_eq!(crate::support::shown_notice(&h).as_deref(), Some("2 differences found"));
|
||||
h.get_by_label("2 Replaced");
|
||||
h.get_by_label("\"five\" → \"three\"").click();
|
||||
h.get_by_label_contains("\"five\" → \"three\"").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(h.state().compare.as_ref().unwrap().selected, Some(0));
|
||||
let id = h.state().active_ids().unwrap().1;
|
||||
@@ -151,11 +151,11 @@ fn compare_filters_hide_text_or_visual_changes() {
|
||||
let (text_old, visual_old) = kinds(&h, old_i);
|
||||
assert!(text_new > 0 && visual_new > 0, "the fixture has both kinds on the new file: {text_new} text, {visual_new} visual");
|
||||
assert!(text_old > 0 && visual_old > 0, "and on the old file: {text_old} text, {visual_old} visual");
|
||||
h.get_by_label("\"five\" → \"three\"");
|
||||
h.get_by_label_contains("\"five\" → \"three\"");
|
||||
|
||||
h.get_by_label("Text").click();
|
||||
h.run_steps(2);
|
||||
assert!(h.query_by_label("\"five\" → \"three\"").is_none(), "text changes leave the list");
|
||||
assert!(h.query_by_label_contains("\"five\" → \"three\"").is_none(), "text changes leave the list");
|
||||
assert_eq!(kinds(&h, new_i), (0, visual_new), "and the new file's shading");
|
||||
assert_eq!(kinds(&h, old_i), (0, visual_old), "and the old file's");
|
||||
|
||||
@@ -166,7 +166,7 @@ fn compare_filters_hide_text_or_visual_changes() {
|
||||
|
||||
h.get_by_label("Text").click();
|
||||
h.run_steps(2);
|
||||
h.get_by_label("\"five\" → \"three\"");
|
||||
h.get_by_label_contains("\"five\" → \"three\"");
|
||||
assert_eq!(kinds(&h, new_i), (text_new, 0), "text back, visual still hidden");
|
||||
assert_eq!(kinds(&h, old_i), (text_old, 0));
|
||||
}
|
||||
@@ -261,10 +261,18 @@ fn export_to_word_html_and_rtf() {
|
||||
for ext in ["docx", "pptx", "html", "rtf"] {
|
||||
// Each save is answered with the suggested name in the suggested folder.
|
||||
let files = std::sync::Arc::new(craft::host::ScriptedFiles::new().saving_suggested());
|
||||
let mut app = crate::control::app_with_files(files.clone());
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "e.pdf", None, doc.clone()).unwrap();
|
||||
assert!(app.execute(&egui::Context::default(), &format!("export.{ext}")));
|
||||
let (app_files, doc) = (files.clone(), doc.clone());
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).build_eframe(move |cc| {
|
||||
crate::support::install_runtime(&cc.egui_ctx);
|
||||
let mut app = crate::control::app_with_files(app_files);
|
||||
app.set_option(&egui::Context::default(), "language", "en").unwrap();
|
||||
app.open_bytes(&egui::Context::default(), "e.pdf", None, doc).unwrap();
|
||||
app
|
||||
});
|
||||
h.run_steps(4);
|
||||
assert!(h.execute(&format!("export.{ext}")));
|
||||
// The picker's answer is taken on a later frame.
|
||||
h.run_steps(3);
|
||||
let request = files.requests().pop().expect("the export asked where to save");
|
||||
let path = request.directory.or(request.default_directory).unwrap_or_default().join(request.file_name.expect("a suggested name"));
|
||||
let bytes = files.file(&path).unwrap_or_else(|| panic!("{ext} was written"));
|
||||
|
||||
@@ -158,7 +158,7 @@ fn the_layers_panel_shows_the_order_tree() {
|
||||
h.get_by_role_and_label(Role::TreeItem, "Colours").click();
|
||||
h.run_steps(2);
|
||||
assert_eq!(shown(&h), layers(true, false));
|
||||
h.get_by_label("Red").click();
|
||||
h.get_by_role_and_label(Role::TreeItem, "Red").click();
|
||||
h.run_steps(3);
|
||||
assert_eq!(shown(&h), layers(false, false));
|
||||
|
||||
|
||||
@@ -31,15 +31,16 @@ fn held() -> (Arc<ManualJobs>, Harness<'static, PdfCraftApp>) {
|
||||
|
||||
#[test]
|
||||
fn a_second_run_is_refused_while_one_is_going() {
|
||||
let (jobs, mut h) = held();
|
||||
let (_jobs, mut h) = held();
|
||||
assert!(h.execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(h.state().optimize_run.is_some(), "the first run is going");
|
||||
// The queue holds the pages' own jobs too, so the run is told by the app's record of it, not by counting jobs.
|
||||
let first = Arc::clone(&h.state().optimize_run.as_ref().expect("the first run is going").progress);
|
||||
assert!(h.execute("optimize.reduce"));
|
||||
h.run_steps(2);
|
||||
assert!(support::shown_notice(&h).is_some(), "the second run is refused with a notice");
|
||||
assert!(jobs.run_next(), "the first run's job is kept");
|
||||
assert!(!jobs.run_next(), "and no second job was queued");
|
||||
let kept = h.state().optimize_run.as_ref().is_some_and(|run| Arc::ptr_eq(&run.progress, &first));
|
||||
assert!(kept, "the first run is kept, and no second one started");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -8,7 +8,7 @@ use crate::support::AppHarness as _;
|
||||
use craft::host::{ManualJobs, ScriptedFiles};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use pdfcraft_ui_egui::PdfCraftApp;
|
||||
use pdfcraft_ui_egui::{PdfCraftApp, RightPanel};
|
||||
|
||||
/// A one-page PDF.
|
||||
const PAGE: &[u8] = b"%PDF-1.7
|
||||
@@ -122,10 +122,9 @@ fn panel_shown(h: &Harness<'static, PdfCraftApp>, label: &str) -> bool {
|
||||
h.query_by_label(label).is_some()
|
||||
}
|
||||
|
||||
/// Run the panel command `id`.
|
||||
fn panel_command(h: &mut Harness<'static, PdfCraftApp>, id: &str) {
|
||||
// PLAN: the right-panel command ids are assumed (pdf-chrome-w13).
|
||||
assert!(h.execute(id), "{id}");
|
||||
/// The reader picks the right panel `panel`, or closes it with `None`.
|
||||
fn choose_panel(h: &mut Harness<'static, PdfCraftApp>, panel: Option<RightPanel>) {
|
||||
h.state_mut().choose_right_panel(panel);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
@@ -160,11 +159,11 @@ fn a_portfolio_opens_its_initial_document_and_shows_its_files_with_the_panel_clo
|
||||
select(&mut h, 0);
|
||||
assert!(panel_shown(&h, "Attachments"));
|
||||
// The reader can still close the list on the portfolio's tab.
|
||||
panel_command(&mut h, "panel.right.close");
|
||||
choose_panel(&mut h, None);
|
||||
assert!(!panel_shown(&h, "Attachments"));
|
||||
// A panel the reader had open comes back once they leave the portfolio's tab.
|
||||
select(&mut h, 1);
|
||||
panel_command(&mut h, "panel.right.bookmarks");
|
||||
choose_panel(&mut h, Some(RightPanel::Bookmarks));
|
||||
select(&mut h, 0);
|
||||
assert!(panel_shown(&h, "Attachments"));
|
||||
select(&mut h, 1);
|
||||
@@ -269,7 +268,7 @@ fn a_panel_picked_in_read_mode_stays_when_the_tab_changes() {
|
||||
select(&mut h, 0);
|
||||
assert!(h.execute("view.read_mode"));
|
||||
h.run_steps(2);
|
||||
panel_command(&mut h, "panel.right.attachments");
|
||||
choose_panel(&mut h, Some(RightPanel::Attachments));
|
||||
select(&mut h, 1);
|
||||
assert!(panel_shown(&h, "Attachments"));
|
||||
}
|
||||
|
||||
@@ -110,6 +110,8 @@ fn crashed_session(dir: &Path, bytes: Vec<u8>, password: Option<&str>, path: Opt
|
||||
let ctx_h = h.ctx.clone();
|
||||
h.state_mut().open_bytes(&ctx_h, "work.pdf", path.map(str::to_string), bytes).unwrap();
|
||||
if let Some(pw) = password {
|
||||
// The open is queued: the prompt comes when the worker finds the document locked.
|
||||
settle(&mut h, &rig, "the password prompt", |app| app.password_prompt.is_some());
|
||||
h.submit_password(Some(pw.to_string()));
|
||||
}
|
||||
settle(&mut h, &rig, "the document opening", |app| app.views.len() == 1);
|
||||
@@ -354,7 +356,8 @@ fn a_cancelled_recovery_password_does_not_attach_to_the_next_unlocked_document()
|
||||
|
||||
let app = h.state_mut();
|
||||
app.open_bytes(&egui::Context::default(), "B.pdf", Some("/docs/B.pdf".into()), encrypted(fixture(1), "pw-b")).unwrap();
|
||||
app.submit_password(&egui::Context::default(), Some("pw-b".into()));
|
||||
settle(&mut h, &rig, "B's password prompt", |app| app.password_prompt.is_some());
|
||||
h.submit_password(Some("pw-b".into()));
|
||||
settle(&mut h, &rig, "unlocked B", |app| app.views.len() == 1);
|
||||
let app = h.state();
|
||||
let b = app.session.get(app.views[0].id).unwrap();
|
||||
|
||||
@@ -69,7 +69,8 @@ fn assert_theme(h: &mut Harness<'static, PdfCraftApp>, c: &ControlClient, prefer
|
||||
|
||||
/// A click on the title bar's theme button cycles Light, Dark, System.
|
||||
fn click_toolbar(h: &mut Harness<'static, PdfCraftApp>, label: &str) {
|
||||
h.get_by_label(&format!("Display theme: {label}")).click();
|
||||
// The button, not the tip that shows while the pointer is still over it from the last click.
|
||||
h.get_by_role_and_label(egui::accesskit::Role::Button, &format!("Display theme: {label}")).click();
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user