mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-26 20:46:22 +01:00
Fix #9051: Display Print Size shows 100% at the display's physical size
With Preferences › General › Display Print Size at 100% Zoom on, 100% took 96 screen points to an inch on every display, so a ruler held to the screen measured more or less than the document said on any display of another density. The desktop app now measures the density of the display that shows the main window from the physical size the system reports (CGDisplayScreenSize on macOS, the monitor's raw DPI on Windows, the RandR output's millimeters on X11, the wl_output geometry on Wayland), and measures it again when the window moves to another display, where every document window keeps its zoom percentage so the art keeps its physical size. Actual Size, the zoom field, the zoom stops and the tab titles count 100% from that density. Where the system reports no size, or a size no display has (zero, an aspect ratio given as the size, or axes that disagree), an inch stays 96 points, as on the web. Zoom stepping takes the density from the app instead of a process-wide flag, and the last zoom stop in each direction stays in the zoom range.
This commit is contained in:
1 parent
88f5ece15b
commit
050ddcb567
25 files changed
+464
-71
No files matched your search
@@ -65,8 +65,9 @@ pollster = "1"
|
||||
# which src/host_services.rs uses to read the path PhotoCraft registers under App Paths.
|
||||
# Win32_Devices_Display has `QueryDisplayConfig`, Win32_UI_ColorSystem the display's ICC profile and
|
||||
# Win32_System_LibraryLoader `GetProcAddress`, which src/display_profile.rs uses to read the
|
||||
# display's color profile for the canvas.
|
||||
windows = { version = "0.62", features = ["Win32_Devices_Display", "Win32_Foundation", "Win32_Graphics_DirectWrite", "Win32_Graphics_Gdi", "Win32_System_LibraryLoader", "Win32_System_Registry", "Win32_System_Threading", "Win32_UI_ColorSystem", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Input_Pointer", "Win32_UI_WindowsAndMessaging"] }
|
||||
# display's color profile for the canvas. Win32_UI_HiDpi has `GetDpiForMonitor`, which
|
||||
# src/windows_display_size.rs uses to read a monitor's raw density for Display Print Size.
|
||||
windows = { version = "0.62", features = ["Win32_Devices_Display", "Win32_Foundation", "Win32_Graphics_DirectWrite", "Win32_Graphics_Gdi", "Win32_System_LibraryLoader", "Win32_System_Registry", "Win32_System_Threading", "Win32_UI_ColorSystem", "Win32_UI_HiDpi", "Win32_UI_Input_KeyboardAndMouse", "Win32_UI_Input_Pointer", "Win32_UI_WindowsAndMessaging"] }
|
||||
# The renderer's worker count follows those cores (src/windows_cores.rs).
|
||||
vectorcraft-render = { workspace = true }
|
||||
|
||||
@@ -90,7 +91,8 @@ objc2-core-text = { version = "0.3", default-features = false, features = ["std"
|
||||
# The windows' Metal layers and the sRGB color space they are tagged with (src/mac_color_space.rs).
|
||||
# Zlib OR Apache-2.0 OR MIT, already in the build through wgpu with these features.
|
||||
objc2-quartz-core = { version = "0.3", default-features = false, features = ["std", "objc2-core-foundation", "objc2-core-graphics", "CALayer", "CAMetalLayer"] }
|
||||
objc2-core-graphics = { version = "0.3", default-features = false, features = ["std", "CGColorSpace"] }
|
||||
# CGDisplayScreenSize gives a display's physical size for Display Print Size (src/screen_density.rs).
|
||||
objc2-core-graphics = { version = "0.3", default-features = false, features = ["std", "CGColorSpace", "CGDirectDisplay", "CGDisplayConfiguration"] }
|
||||
# Waits for the answer of a file dialog shown as a sheet (src/main.rs, #867). MIT OR Apache-2.0,
|
||||
# already in the build through eframe.
|
||||
pollster = "1"
|
||||
|
||||
@@ -208,6 +208,11 @@ impl App {
|
||||
}
|
||||
if let Some(w) = &self.winit_window {
|
||||
self.display_profile.tick(w, now, self.app.session.prefs.monitor_profile_display, &self.app.display_profile, ctx);
|
||||
if let Some(read) = self.screen_density.tick(w, now)
|
||||
&& self.app.set_screen_ppi(read)
|
||||
{
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
self.app.tick(ctx);
|
||||
if self.pending_maximize {
|
||||
|
||||
@@ -67,6 +67,7 @@ mod presentation;
|
||||
mod printing;
|
||||
#[cfg(not(any(target_os = "macos", windows)))]
|
||||
mod quit_windows;
|
||||
mod screen_density;
|
||||
#[cfg(not(target_os = "macos"))]
|
||||
mod single_instance;
|
||||
#[cfg(windows)]
|
||||
@@ -77,6 +78,8 @@ mod window_frame;
|
||||
mod windows_alt_codes;
|
||||
#[cfg(windows)]
|
||||
mod windows_cores;
|
||||
#[cfg(windows)]
|
||||
mod windows_display_size;
|
||||
mod windows_screen_color;
|
||||
mod windows_stylus;
|
||||
mod xwayland;
|
||||
@@ -140,6 +143,9 @@ struct App {
|
||||
monitors_listed: Option<(f64, f32)>,
|
||||
/// Reads the profile of the display that shows the main window, for the canvas.
|
||||
display_profile: display_profile::Reader,
|
||||
/// Measures the density of the display that shows the main window, for Display Print Size at
|
||||
/// 100% Zoom.
|
||||
screen_density: screen_density::Tracker,
|
||||
/// When this frame's input hook started, for the hang report's frame times (`hang_watch`).
|
||||
frame_start: Option<std::time::Instant>,
|
||||
/// The shortest time between the starts of two frames, while the window presents without vsync
|
||||
@@ -712,6 +718,7 @@ fn main() -> std::process::ExitCode {
|
||||
held_files,
|
||||
monitors_listed: None,
|
||||
display_profile: Default::default(),
|
||||
screen_density: Default::default(),
|
||||
frame_start: None,
|
||||
min_frame,
|
||||
last_frame_began: None,
|
||||
|
||||
@@ -0,0 +1,252 @@
|
||||
//! The density of the display that shows most of the main window, in the window's points per
|
||||
//! inch, for Preferences › General › Display Print Size at 100% Zoom (`Services::screen_ppi`):
|
||||
//! the display's size in points divided by the physical size the system reports for it.
|
||||
//!
|
||||
//! - macOS: `CGDisplayScreenSize`.
|
||||
//! - Windows: `GetDpiForMonitor`'s raw density (`windows_display_size`).
|
||||
//! - X11, XWayland included: the RandR output's width and height in millimeters.
|
||||
//! - Wayland: the physical width and height of the compositor's `wl_output` for the display.
|
||||
//!
|
||||
//! A display that reports no size, or a size no display has, gives `None`, and an inch then takes
|
||||
//! 96 points. The window's display is looked up once a second while the app draws, and read when
|
||||
//! it changes.
|
||||
|
||||
use winit::dpi::{PhysicalPosition, PhysicalSize};
|
||||
use winit::monitor::MonitorHandle;
|
||||
|
||||
/// Seconds between two checks of which display shows the window.
|
||||
const LOOK_EVERY: f64 = 1.0;
|
||||
|
||||
/// Millimeters in an inch.
|
||||
const MM_PER_INCH: f64 = 25.4;
|
||||
|
||||
/// How far the horizontal and vertical densities of one display may differ, as a fraction of the
|
||||
/// larger: square pixels on a display that reports its true size give two densities this close.
|
||||
const AXES_AGREE: f64 = 0.1;
|
||||
|
||||
/// What identifies the display and the window's scale on it between two looks.
|
||||
type Shown = (Option<String>, PhysicalPosition<i32>, PhysicalSize<u32>, u64);
|
||||
|
||||
/// Keeps the density current from the main window's frames.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct Tracker {
|
||||
/// When the window's display was last looked up.
|
||||
looked: Option<f64>,
|
||||
/// The display read last, with the window's scale factor then.
|
||||
shown: Option<Shown>,
|
||||
}
|
||||
|
||||
impl Tracker {
|
||||
/// Looks up the window's display when a look is due at `now` (seconds), and returns its
|
||||
/// density (`None` inside for a display that reports no size) when the display or the
|
||||
/// window's scale changed since the last reading.
|
||||
pub(crate) fn tick(&mut self, window: &winit::window::Window, now: f64) -> Option<Option<f64>> {
|
||||
if self.looked.is_some_and(|at| (at..at + LOOK_EVERY).contains(&now)) {
|
||||
return None;
|
||||
}
|
||||
self.looked = Some(now);
|
||||
let monitor = window.current_monitor();
|
||||
let scale = window.scale_factor();
|
||||
let shown = monitor.as_ref().map(|m| (m.name(), m.position(), m.size(), scale.to_bits()));
|
||||
if shown == self.shown {
|
||||
return None;
|
||||
}
|
||||
self.shown = shown;
|
||||
let read = monitor.and_then(|m| points_per_inch(m.size(), scale, physical_mm(window, &m)?));
|
||||
match read {
|
||||
Some(p) => log::info!("the window's display has {p:.1} points to an inch"),
|
||||
None => log::info!("the window's display reports no physical size; an inch is 96 points"),
|
||||
}
|
||||
Some(read)
|
||||
}
|
||||
}
|
||||
|
||||
/// The density, in points per inch, of a display `size` physical pixels wide and high, with the
|
||||
/// window drawn at `scale` pixels to a point, that the system says is `mm` millimeters wide and
|
||||
/// high. `None` for a size that is no display's: zero or less, an aspect ratio given in place of
|
||||
/// the size (16 × 9, 160 × 90 and the like), axes whose densities disagree in either orientation,
|
||||
/// or a density outside [`vectorcraft_ui_egui::state::SCREEN_PPI_RANGE`]. A display turned a
|
||||
/// quarter turn may report the size of its panel upright, so the axes are also tried swapped.
|
||||
pub(crate) fn points_per_inch(size: PhysicalSize<u32>, scale: f64, mm: [f64; 2]) -> Option<f64> {
|
||||
if !(scale.is_finite() && scale > 0.0) || mm.iter().any(|v| !(v.is_finite() && *v > 0.0)) || aspect_as_size(mm) {
|
||||
return None;
|
||||
}
|
||||
let points = [f64::from(size.width) / scale, f64::from(size.height) / scale];
|
||||
let density = |[w, h]: [f64; 2]| [points[0] / (w / MM_PER_INCH), points[1] / (h / MM_PER_INCH)];
|
||||
let agree = |[x, y]: [f64; 2]| (x - y).abs() <= AXES_AGREE * x.max(y);
|
||||
let [x, y] = [density(mm), density([mm[1], mm[0]])].into_iter().find(|d| agree(*d))?;
|
||||
let ppi = (x + y) / 2.0;
|
||||
vectorcraft_ui_egui::state::SCREEN_PPI_RANGE.contains(&ppi).then_some(ppi)
|
||||
}
|
||||
|
||||
/// Whether `mm` is an aspect ratio that a display's EDID gave in place of its size: 16:9, 16:10
|
||||
/// or 4:3, in centimeters or tenths of them.
|
||||
fn aspect_as_size(mm: [f64; 2]) -> bool {
|
||||
const RATIOS: [[f64; 2]; 3] = [[16.0, 9.0], [16.0, 10.0], [4.0, 3.0]];
|
||||
let sorted = if mm[0] >= mm[1] { mm } else { [mm[1], mm[0]] };
|
||||
RATIOS.iter().any(|r| [1.0, 10.0].iter().any(|k| sorted == [r[0] * k, r[1] * k]))
|
||||
}
|
||||
|
||||
/// The physical width and height, in millimeters, the system reports for `monitor`.
|
||||
#[cfg(target_os = "macos")]
|
||||
fn physical_mm(_: &winit::window::Window, monitor: &MonitorHandle) -> Option<[f64; 2]> {
|
||||
use winit::platform::macos::MonitorHandleExtMacOS as _;
|
||||
let size = objc2_core_graphics::CGDisplayScreenSize(monitor.native_id());
|
||||
Some([size.width, size.height])
|
||||
}
|
||||
|
||||
#[cfg(windows)]
|
||||
fn physical_mm(_: &winit::window::Window, monitor: &MonitorHandle) -> Option<[f64; 2]> {
|
||||
use winit::platform::windows::MonitorHandleExtWindows as _;
|
||||
let [x, y] = crate::windows_display_size::raw_dpi(monitor.hmonitor())?;
|
||||
let size = monitor.size();
|
||||
Some([f64::from(size.width) / x * MM_PER_INCH, f64::from(size.height) / y * MM_PER_INCH])
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
fn physical_mm(window: &winit::window::Window, monitor: &MonitorHandle) -> Option<[f64; 2]> {
|
||||
use winit::raw_window_handle::{HasWindowHandle as _, RawWindowHandle};
|
||||
let wayland = window.window_handle().ok().is_some_and(|h| matches!(h.as_raw(), RawWindowHandle::Wayland(_)));
|
||||
let read = if wayland { wayland::physical_mm(monitor.name().as_deref()) } else { x11::physical_mm(monitor) };
|
||||
read.unwrap_or_else(|e| {
|
||||
log::debug!("couldn't read the display's physical size: {e}");
|
||||
None
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(any(target_os = "macos", windows, target_os = "linux")))]
|
||||
fn physical_mm(_: &winit::window::Window, _: &MonitorHandle) -> Option<[f64; 2]> {
|
||||
None
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod x11 {
|
||||
use winit::monitor::MonitorHandle;
|
||||
use winit::platform::x11::MonitorHandleExtX11 as _;
|
||||
use x11rb::CURRENT_TIME;
|
||||
use x11rb::protocol::randr;
|
||||
|
||||
/// The millimeters RandR reports for the first output of the CRTC that shows `monitor`.
|
||||
pub(super) fn physical_mm(monitor: &MonitorHandle) -> Result<Option<[f64; 2]>, String> {
|
||||
let (conn, _) = x11rb::connect(None).map_err(|e| format!("couldn't connect to the X11 display: {e}"))?;
|
||||
let ask = |e: x11rb::errors::ConnectionError| format!("couldn't ask the X11 display: {e}");
|
||||
let crtc = randr::get_crtc_info(&conn, monitor.native_id(), CURRENT_TIME)
|
||||
.map_err(ask)?
|
||||
.reply()
|
||||
.map_err(|e| format!("the X11 display has no such CRTC: {e}"))?;
|
||||
let Some(output) = crtc.outputs.first() else { return Ok(None) };
|
||||
let info = randr::get_output_info(&conn, *output, CURRENT_TIME)
|
||||
.map_err(ask)?
|
||||
.reply()
|
||||
.map_err(|e| format!("the X11 display has no such output: {e}"))?;
|
||||
Ok(Some([f64::from(info.mm_width), f64::from(info.mm_height)]))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
mod wayland {
|
||||
use wayland_client::globals::{GlobalListContents, registry_queue_init};
|
||||
use wayland_client::protocol::wl_output::{self, WlOutput};
|
||||
use wayland_client::protocol::wl_registry::{self, WlRegistry};
|
||||
use wayland_client::{Connection, Dispatch, QueueHandle};
|
||||
|
||||
/// The physical size the compositor gives for the output named `name`, asked on a connection
|
||||
/// of its own; with no name, or a compositor that names no outputs, the only output's.
|
||||
pub(super) fn physical_mm(name: Option<&str>) -> Result<Option<[f64; 2]>, String> {
|
||||
let conn = Connection::connect_to_env().map_err(|e| format!("no Wayland compositor: {e}"))?;
|
||||
let (globals, mut queue) = registry_queue_init::<Outputs>(&conn).map_err(|e| e.to_string())?;
|
||||
let qh = queue.handle();
|
||||
let mut state = Outputs::default();
|
||||
for global in globals.contents().clone_list().into_iter().filter(|g| g.interface == "wl_output") {
|
||||
// Version 4 names the output; older ones give its size only.
|
||||
let output: WlOutput = globals.registry().bind(global.name, global.version.min(4), &qh, state.outputs.len());
|
||||
state.outputs.push((output, Output::default()));
|
||||
}
|
||||
// The compositor sends each output's geometry, name and `done` in reply to the bind.
|
||||
queue.roundtrip(&mut state).map_err(|e| e.to_string())?;
|
||||
let found: Vec<&Output> = state.outputs.iter().map(|(_, o)| o).collect();
|
||||
let pick = match name {
|
||||
Some(name) if found.iter().any(|o| o.name.is_some()) => found.iter().find(|o| o.name.as_deref() == Some(name)),
|
||||
_ if found.len() == 1 => found.first(),
|
||||
_ => None,
|
||||
};
|
||||
Ok(pick.and_then(|o| o.mm))
|
||||
}
|
||||
|
||||
/// One output's name and physical size.
|
||||
#[derive(Default)]
|
||||
struct Output {
|
||||
name: Option<String>,
|
||||
mm: Option<[f64; 2]>,
|
||||
}
|
||||
|
||||
/// The outputs bound, each with what its events gave.
|
||||
#[derive(Default)]
|
||||
struct Outputs {
|
||||
outputs: Vec<(WlOutput, Output)>,
|
||||
}
|
||||
|
||||
impl Dispatch<WlRegistry, GlobalListContents> for Outputs {
|
||||
fn event(_: &mut Self, _: &WlRegistry, _: wl_registry::Event, _: &GlobalListContents, _: &Connection, _: &QueueHandle<Self>) {}
|
||||
}
|
||||
|
||||
impl Dispatch<WlOutput, usize> for Outputs {
|
||||
fn event(state: &mut Self, _: &WlOutput, event: wl_output::Event, index: &usize, _: &Connection, _: &QueueHandle<Self>) {
|
||||
let Some((_, output)) = state.outputs.get_mut(*index) else { return };
|
||||
match event {
|
||||
wl_output::Event::Geometry { physical_width, physical_height, .. } => {
|
||||
output.mm = Some([f64::from(physical_width), f64::from(physical_height)]);
|
||||
}
|
||||
wl_output::Event::Name { name } => output.name = Some(name),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// A 14-inch laptop panel at twice its points: 3024 × 1964 pixels, 302 × 196 mm, draws 127
|
||||
/// points to an inch, more than the 96 a fixed inch assumes.
|
||||
#[test]
|
||||
fn a_laptop_panel_has_more_points_to_an_inch_than_the_reference() {
|
||||
let ppi = points_per_inch(PhysicalSize::new(3024, 1964), 2.0, [302.0, 196.0]);
|
||||
assert!(ppi.is_some_and(|p| p > 96.0 && (p - 1512.0 / (302.0 / MM_PER_INCH)).abs() < 1.0), "{ppi:?}");
|
||||
}
|
||||
|
||||
/// The same display in a scaled mode (more points on the same glass) draws more points to an
|
||||
/// inch, and at a higher scale factor fewer: the density counts the window's points.
|
||||
#[test]
|
||||
fn the_density_counts_points_at_the_windows_scale() {
|
||||
let at = |w, h, scale| points_per_inch(PhysicalSize::new(w, h), scale, [527.0, 296.0]).unwrap_or(0.0);
|
||||
assert!(at(1920, 1080, 1.0) > 0.0);
|
||||
assert!(at(2560, 1440, 1.0) > at(1920, 1080, 1.0), "more pixels on the same glass");
|
||||
assert!(at(3840, 2160, 2.0) < at(3840, 2160, 1.5), "a larger scale factor makes each point larger");
|
||||
}
|
||||
|
||||
/// A display turned a quarter turn whose system reports its panel's size upright still
|
||||
/// measures; axes that disagree either way do not.
|
||||
#[test]
|
||||
fn a_turned_display_measures_and_disagreeing_axes_do_not() {
|
||||
let upright = points_per_inch(PhysicalSize::new(1920, 1080), 1.0, [527.0, 296.0]);
|
||||
let turned = points_per_inch(PhysicalSize::new(1080, 1920), 1.0, [527.0, 296.0]);
|
||||
assert!(upright.is_some() && turned.is_some());
|
||||
assert!((upright.unwrap_or(0.0) - turned.unwrap_or(1.0)).abs() < 1e-9);
|
||||
assert_eq!(points_per_inch(PhysicalSize::new(1920, 1080), 1.0, [527.0, 527.0]), None);
|
||||
}
|
||||
|
||||
/// Sizes no display has give no density: none, an aspect ratio in place of the size, and
|
||||
/// densities past the range a display can have.
|
||||
#[test]
|
||||
fn reports_that_are_no_displays_size_give_no_density() {
|
||||
let at = |mm| points_per_inch(PhysicalSize::new(1920, 1080), 1.0, mm);
|
||||
for mm in [[0.0, 0.0], [-1.0, 300.0], [f64::NAN, 300.0], [160.0, 90.0], [16.0, 9.0], [160.0, 100.0], [40.0, 30.0], [9.0, 16.0]] {
|
||||
assert_eq!(at(mm), None, "{mm:?}");
|
||||
}
|
||||
assert_eq!(points_per_inch(PhysicalSize::new(1920, 1080), 0.0, [527.0, 296.0]), None, "no scale");
|
||||
assert_eq!(points_per_inch(PhysicalSize::new(100, 56), 1.0, [5270.0, 2960.0]), None, "under the range");
|
||||
assert_eq!(points_per_inch(PhysicalSize::new(7680, 4320), 1.0, [53.0, 30.0]), None, "over it");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
//! Windows: a monitor's raw density, the pixels per inch of the screen itself as Windows reads it
|
||||
//! from the monitor, for Display Print Size at 100% Zoom (`crate::screen_density`).
|
||||
//!
|
||||
//! `GetDpiForMonitor` is a C API with no safe binding, hence the scoped `unsafe_code` allowance.
|
||||
#![allow(unsafe_code)]
|
||||
|
||||
use windows::Win32::Graphics::Gdi::HMONITOR;
|
||||
use windows::Win32::UI::HiDpi::{GetDpiForMonitor, MDT_RAW_DPI};
|
||||
|
||||
/// The horizontal and vertical pixels per inch of the monitor winit's handle `monitor` names, or
|
||||
/// `None` when Windows reports none for it.
|
||||
pub(crate) fn raw_dpi(monitor: isize) -> Option<[f64; 2]> {
|
||||
let (mut x, mut y) = (0u32, 0u32);
|
||||
// SAFETY: `monitor` is a handle winit got from Windows for a connected monitor; a handle that
|
||||
// has gone stale makes the call fail, which returns `None`. Both pointers point at live `u32`s
|
||||
// for the length of the call.
|
||||
unsafe { GetDpiForMonitor(HMONITOR(monitor as *mut core::ffi::c_void), MDT_RAW_DPI, &mut x, &mut y) }.ok()?;
|
||||
(x > 0 && y > 0).then(|| [f64::from(x), f64::from(y)])
|
||||
}
|
||||
@@ -484,7 +484,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"view.actualSize",
|
||||
"Actual Size",
|
||||
"Cmd+1",
|
||||
"{} 100%: with Display Print Size at 100% Zoom off, one document point per screen point; on, one document inch fills 96 screen points (an inch at the system's reference density, whatever the display scaling); the same at every UI Scaling",
|
||||
"{} 100%: with Display Print Size at 100% Zoom off, one document point per screen point; on, one document inch fills an inch of the display that shows the window, measured from the physical size the system reports for it, or 96 screen points where it reports none; the same at every UI Scaling",
|
||||
),
|
||||
("view.setZoom", "Set Zoom", "", "{zoom: percent, center?: [x,y]}"),
|
||||
(
|
||||
|
||||
@@ -586,7 +586,6 @@ impl VectorcraftApp {
|
||||
ctx.request_repaint();
|
||||
return;
|
||||
}
|
||||
crate::state::sync_zoom_stops_display_print_size(self.session.prefs.display_print_size);
|
||||
// Whether this pass draws the last step of an action playing at Step by Step.
|
||||
let step_held = crate::panels::actions::playback_held(self);
|
||||
let t0 = now_ms();
|
||||
|
||||
@@ -136,7 +136,6 @@ impl VectorcraftApp {
|
||||
|
||||
/// [`Self::run`] it, inside what asks for file dialogs.
|
||||
fn run_now(&mut self, id: &str, params: Value) -> Result<Value, String> {
|
||||
crate::state::sync_zoom_stops_display_print_size(self.session.prefs.display_print_size);
|
||||
self.run_count = self.run_count.wrapping_add(1);
|
||||
// In debug builds the app's own calls are held to the params descriptions too (#1442): a
|
||||
// panel passing a key its command doesn't read shows up in the tests. Saved steps aren't
|
||||
|
||||
@@ -104,6 +104,34 @@ impl VectorcraftApp {
|
||||
self.session.active().map_or(vectorcraft_geom::Point::ZERO, |d| d.doc.ruler_origin_for(artboard))
|
||||
}
|
||||
|
||||
/// The screen points an inch takes at 100% zoom with Display Print Size at 100% Zoom on, for
|
||||
/// the display that shows the window; `None` with it off ([`crate::state::print_ppi`]).
|
||||
pub(crate) fn print_ppi(&self) -> Option<f64> {
|
||||
crate::state::print_ppi(self.session.prefs.display_print_size, self.services.screen_ppi)
|
||||
}
|
||||
|
||||
/// Takes `ppi` as the measured density of the main window's display
|
||||
/// ([`crate::Services::screen_ppi`]). With Display Print Size at 100% Zoom on, every document
|
||||
/// window's view keeps its zoom percentage, so the art keeps its physical size on the new
|
||||
/// display. Returns whether the density changed.
|
||||
pub fn set_screen_ppi(&mut self, ppi: Option<f64>) -> bool {
|
||||
if self.services.screen_ppi == ppi {
|
||||
return false;
|
||||
}
|
||||
let before = self.print_ppi();
|
||||
self.services.screen_ppi = ppi;
|
||||
if let (Some(before), Some(after)) = (before, self.print_ppi())
|
||||
&& before != after
|
||||
{
|
||||
let k = after / before;
|
||||
for v in &mut self.views {
|
||||
v.zoom = (v.zoom * k).clamp(0.0313, 640.0);
|
||||
}
|
||||
self.canvas.windows.views.scale_zooms(k);
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
pub fn view_mut(&mut self) -> Option<&mut View> {
|
||||
self.sync_views();
|
||||
let i = self.session.active_index()?;
|
||||
|
||||
@@ -602,7 +602,7 @@ fn drag_released(app: &mut VectorcraftApp, ui: &Ui, f: &Pointing, d: Drag, p: Po
|
||||
});
|
||||
// Backtick as it was at the button-up: a key pressed or released later in the frame does not count.
|
||||
let backquote = backquote_at_release(ui, egui::PointerButton::Primary, f.backquote_before);
|
||||
let ui_zoom = app.canvas_ui_zoom;
|
||||
let (ui_zoom, print) = (app.canvas_ui_zoom, app.print_ppi());
|
||||
match d {
|
||||
Drag::ZoomBox { start } => {
|
||||
let start = zoom_marquee_start(ui, start, before, p);
|
||||
@@ -615,14 +615,14 @@ fn drag_released(app: &mut VectorcraftApp, ui: &Ui, f: &Pointing, d: Drag, p: Po
|
||||
let fill = (rect.width() / r.width()).min(rect.height() / r.height());
|
||||
vm.zoom = (xf.zoom * f64::from(ui_zoom) * f64::from(fill)).clamp(0.0313, 640.0);
|
||||
} else {
|
||||
zoom_about(vm, rect, p, crate::state::next_zoom(vm.zoom, !m.alt), ui_zoom);
|
||||
zoom_about(vm, rect, p, crate::state::next_zoom(vm.zoom, !m.alt, print), ui_zoom);
|
||||
}
|
||||
}
|
||||
}
|
||||
// A click (not held, not dragged) steps the zoom as with the marquee.
|
||||
Drag::ZoomScrub { held, moved: false, .. } if held <= HOLD_DELAY => {
|
||||
if let Some(vm) = app.view_mut() {
|
||||
zoom_about(vm, rect, p, crate::state::next_zoom(vm.zoom, !m.alt), ui_zoom);
|
||||
zoom_about(vm, rect, p, crate::state::next_zoom(vm.zoom, !m.alt, print), ui_zoom);
|
||||
}
|
||||
}
|
||||
Drag::ZoomScrub { .. } => {}
|
||||
|
||||
@@ -8550,6 +8550,41 @@ fn view_actual_size_follows_display_print_size() {
|
||||
assert!((app.view().unwrap().zoom - 96.0 / 72.0).abs() < 1e-12, "an inch is 96 screen points");
|
||||
}
|
||||
|
||||
/// #9051: with Display Print Size on, Actual Size shows a document inch in an inch of the display
|
||||
/// the window is on, from the density the host measured for it. When the window moves to a
|
||||
/// display of another density, every document window keeps its zoom percentage, so the art keeps
|
||||
/// its physical size there.
|
||||
#[test]
|
||||
fn view_actual_size_fills_an_inch_of_the_measured_display() {
|
||||
let mut app = VectorcraftApp::new(Session::new(), Default::default());
|
||||
app.session.execute("file.new", &json!({"width": 200, "height": 100})).unwrap();
|
||||
let rect = egui::Rect::from_min_size(Pos2::ZERO, vec2(460.0, 260.0));
|
||||
app.canvas_rect = Some(rect);
|
||||
app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": true})).unwrap();
|
||||
assert!(app.set_screen_ppi(Some(127.0)));
|
||||
let inch = |v: &View| {
|
||||
let xf = Xf::new(rect, v);
|
||||
f64::from(xf.to_screen(Point::new(72.0, 0.0)).x - xf.to_screen(Point::new(0.0, 0.0)).x)
|
||||
};
|
||||
app.run("view.actualSize", json!({})).unwrap();
|
||||
assert!((inch(app.view().unwrap()) - 127.0).abs() < 1e-3, "72 pt take the display's 127 points to an inch");
|
||||
app.run("window.newWindow", json!({})).unwrap();
|
||||
let stepped = app.run("view.zoomIn", json!({})).unwrap()["zoom"].as_f64().unwrap_or(0.0);
|
||||
assert!((stepped - 150.0).abs() < 1e-9, "the stops count from that 100%: {stepped}");
|
||||
assert!(app.set_screen_ppi(Some(91.0)), "the window moved to a sparser display");
|
||||
assert!(!app.set_screen_ppi(Some(91.0)), "the same reading changes nothing");
|
||||
let first = *crate::doc_windows::view(&app, (0, 1)).unwrap();
|
||||
assert!((inch(&first) - 91.0).abs() < 1e-3, "the other window's 100% still fills an inch");
|
||||
assert_eq!(crate::state::zoom_label(first.zoom, app.print_ppi()), "100%");
|
||||
assert_eq!(crate::state::zoom_label(app.view().unwrap().zoom, app.print_ppi()), "150%");
|
||||
app.session.execute("prefs.set", &json!({"key": "displayPrintSize", "value": false})).unwrap();
|
||||
let zoom = app.view().unwrap().zoom;
|
||||
assert!(app.set_screen_ppi(Some(127.0)));
|
||||
assert_eq!(app.view().unwrap().zoom, zoom, "off, a move leaves the zoom alone");
|
||||
app.run("view.actualSize", json!({})).unwrap();
|
||||
assert!((app.view().unwrap().zoom - 1.0).abs() < 1e-12, "and 100% stays one point per point");
|
||||
}
|
||||
|
||||
/// Fit Artboard in Window fits the artboard as a rotated view shows it: at 45° every corner is
|
||||
/// on the canvas and one is within the 30-point margin of an edge. At 0° the zoom is unchanged.
|
||||
#[test]
|
||||
@@ -8604,7 +8639,7 @@ fn animated_zoom_scrubs_and_holds_else_the_zoom_tool_zooms_to_an_area() {
|
||||
press(&mut app, vec2(-100.0, 0.0), 0);
|
||||
assert!((app.view().unwrap().zoom - z0).abs() < 1e-6, "and back to the left");
|
||||
press(&mut app, vec2(0.0, 0.0), 0);
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(z0, true), "a click steps");
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(z0, true, None), "a click steps");
|
||||
let z2 = app.view().unwrap().zoom;
|
||||
press(&mut app, vec2(0.0, 0.0), 40);
|
||||
assert!(app.view().unwrap().zoom > z2 * 1.2, "held, it zooms on");
|
||||
@@ -8959,9 +8994,9 @@ fn cmd_space_zooms_and_space_pans_whatever_the_tool() {
|
||||
let z0 = app.view().unwrap().zoom;
|
||||
drag(&mut app, Modifiers::COMMAND, at);
|
||||
let z1 = app.view().unwrap().zoom;
|
||||
assert_eq!(z1, crate::state::next_zoom(z0, true), "Cmd+Space click zooms in");
|
||||
assert_eq!(z1, crate::state::next_zoom(z0, true, None), "Cmd+Space click zooms in");
|
||||
drag(&mut app, Modifiers::COMMAND | Modifiers::ALT, at);
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(z1, false), "Cmd+Alt+Space click zooms out");
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(z1, false, None), "Cmd+Alt+Space click zooms out");
|
||||
assert_eq!(app.session.active().unwrap().doc.art_bounds(), None, "the Rectangle tool drew nothing");
|
||||
// Space alone pans, with the Zoom tool too.
|
||||
app.select_tool("zoom");
|
||||
@@ -9009,7 +9044,7 @@ fn space_types_a_space_while_editing_text_and_does_not_pan() {
|
||||
assert_eq!(shown(&mut app), CursorIcon::ZoomIn, "Cmd+Space shows the magnifier");
|
||||
typing_frame(&mut app, &ctx, vec![button(at, true, Modifiers::COMMAND)]);
|
||||
typing_frame(&mut app, &ctx, vec![button(at, false, Modifiers::COMMAND)]);
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(before.zoom, true), "Cmd+Space click zooms in");
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(before.zoom, true, None), "Cmd+Space click zooms in");
|
||||
typing_frame(&mut app, &ctx, vec![space(false, Modifiers::COMMAND), Event::ModifiersChanged(Modifiers::NONE)]);
|
||||
assert_eq!(plain(&app, id), "a ", "the text is as typed");
|
||||
}
|
||||
@@ -9119,7 +9154,7 @@ fn space_shift_drag_rotates_the_view_whatever_the_tool() {
|
||||
assert_eq!((panned.rotation, panned.zoom), (v.rotation, v.zoom));
|
||||
assert_ne!(panned.center, v.center, "Space pans");
|
||||
drag(&mut app, Modifiers::COMMAND | Modifiers::SHIFT, true, c, c);
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(v.zoom, true), "Cmd+Shift+Space click zooms in");
|
||||
assert_eq!(app.view().unwrap().zoom, crate::state::next_zoom(v.zoom, true, None), "Cmd+Shift+Space click zooms in");
|
||||
assert_eq!(app.view().unwrap().rotation, v.rotation);
|
||||
// The Rotate View tool's Shift still rounds to 15°.
|
||||
app.select_tool("rotateView");
|
||||
|
||||
@@ -31,7 +31,7 @@ pub fn fit(app: &mut VectorcraftApp, how: &str) {
|
||||
};
|
||||
let Some(target) = target else { return };
|
||||
let zoom = if how == "view.actualSize" {
|
||||
actual_size_zoom(app.session.prefs.display_print_size)
|
||||
actual_size_zoom(app.print_ppi())
|
||||
} else {
|
||||
fit_zoom(rect, target, app.view().map_or(0.0, |v| v.rotation), app.canvas_ui_zoom)
|
||||
};
|
||||
@@ -102,11 +102,12 @@ pub(crate) fn animated_zoom(p: &vectorcraft_engine::Prefs) -> bool {
|
||||
}
|
||||
|
||||
/// Zoom for View → Actual Size (`view.actualSize`). With Preferences › General › Display Print
|
||||
/// Size at 100% Zoom off, one document point is one screen point. On, one document inch (72 pt)
|
||||
/// fills an inch of the screen as the system counts it: 96 screen points, the reference density
|
||||
/// that display scaling is set against (a CSS inch), whatever the scale factor.
|
||||
pub(crate) fn actual_size_zoom(display_print_size: bool) -> f64 {
|
||||
if display_print_size { 96.0 / 72.0 } else { 1.0 }
|
||||
/// Size at 100% Zoom off (`print` `None`), one document point is one screen point. On, one
|
||||
/// document inch (72 pt) fills an inch of the display that shows the window: `print` screen
|
||||
/// points, its measured density, or 96 (a CSS inch) where the system reports no physical size
|
||||
/// ([`crate::state::print_ppi`]).
|
||||
pub(crate) fn actual_size_zoom(print: Option<f64>) -> f64 {
|
||||
crate::state::zoom_baseline(print)
|
||||
}
|
||||
|
||||
/// Zoom view `vm` of the canvas `rect` to `zoom` (clamped to the zoom range), keeping the document
|
||||
|
||||
@@ -10,7 +10,7 @@ pub fn status_bar(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
.show(ui, |ui| {
|
||||
ui.horizontal_centered(|ui| {
|
||||
let zoom = app.view().map(|v| v.zoom).unwrap_or(1.0);
|
||||
let print = app.session.prefs.display_print_size;
|
||||
let print = app.print_ppi();
|
||||
let shown = crate::state::zoom_display_percent(zoom, print);
|
||||
ui.name_inputs(tl!("Zoom"), |ui| {
|
||||
craft_ui::ComboBox::from_id_salt("zoom-combo")
|
||||
|
||||
@@ -2,21 +2,21 @@ use super::{Sense, Stroke, Tokens, Ui, VectorcraftApp, icons, json, theme, vec2,
|
||||
|
||||
/// [`view_tab_title`] for a document with one view.
|
||||
#[cfg(test)]
|
||||
pub(super) fn tab_title(d: &vectorcraft_engine::DocState, zoom: f64, outline: bool, display_print_size: bool) -> String {
|
||||
view_tab_title(d, None, zoom, outline, display_print_size)
|
||||
pub(super) fn tab_title(d: &vectorcraft_engine::DocState, zoom: f64, outline: bool, print: Option<f64>) -> String {
|
||||
view_tab_title(d, None, zoom, outline, print)
|
||||
}
|
||||
|
||||
/// A document tab's title: "Name* @ 66.67 % (RGB/Preview)", or while an opacity mask is edited
|
||||
/// "Name* @ 66.67 % (<Opacity Mask>/Opacity Mask)". For a view of a document with more than one
|
||||
/// view, the view's `number` follows the name: "Name:2* @ 66.67 % (RGB/Preview)".
|
||||
fn view_tab_title(d: &vectorcraft_engine::DocState, number: Option<u32>, zoom: f64, outline: bool, display_print_size: bool) -> String {
|
||||
fn view_tab_title(d: &vectorcraft_engine::DocState, number: Option<u32>, zoom: f64, outline: bool, print: Option<f64>) -> String {
|
||||
let mode = if d.doc.mask_edit.is_some() {
|
||||
format!("<{0}>/{0}", tl!("Opacity Mask"))
|
||||
} else {
|
||||
let color = if d.doc.color_mode == vectorcraft_doc::ColorMode::Cmyk { "CMYK" } else { "RGB" };
|
||||
format!("{color}/{}", if outline { tl!("Outline") } else { tl!("Preview") })
|
||||
};
|
||||
format!("{} @ {} ({mode})", view_tab_name(d, number), zoom_label(zoom, display_print_size).replace('%', " %"))
|
||||
format!("{} @ {} ({mode})", view_tab_name(d, number), zoom_label(zoom, print).replace('%', " %"))
|
||||
}
|
||||
|
||||
/// The start of [`view_tab_title`], which an inactive document tab shows alone (#8582): "Name*",
|
||||
@@ -31,7 +31,7 @@ fn view_tab_name(d: &vectorcraft_engine::DocState, number: Option<u32>) -> Strin
|
||||
fn window_tab_title(app: &VectorcraftApp, w: crate::doc_windows::Win, d: &vectorcraft_engine::DocState) -> String {
|
||||
let view = crate::doc_windows::view(app, w);
|
||||
let zoom = view.map_or(1.0, |v| v.zoom);
|
||||
view_tab_title(d, crate::doc_windows::label(app, w), zoom, view.is_some_and(|v| v.outline), app.session.prefs.display_print_size)
|
||||
view_tab_title(d, crate::doc_windows::label(app, w), zoom, view.is_some_and(|v| v.outline), app.print_ppi())
|
||||
}
|
||||
|
||||
/// The title of window `w`'s tab and floating window ([`crate::doc_windows`]).
|
||||
|
||||
@@ -1918,7 +1918,7 @@ fn the_tab_title_names_the_opacity_mask_while_it_is_edited() {
|
||||
let mut s = Session::new();
|
||||
s.execute("file.new", &json!({"width": 100, "height": 100})).unwrap();
|
||||
s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 50, "height": 50})).unwrap();
|
||||
let title = |s: &Session| super::tab_title(s.active().unwrap(), 1.0, false, false);
|
||||
let title = |s: &Session| super::tab_title(s.active().unwrap(), 1.0, false, None);
|
||||
assert!(title(&s).ends_with("(RGB/Preview)"), "{}", title(&s));
|
||||
s.execute("transparency.makeOpacityMask", &json!({})).unwrap();
|
||||
assert!(title(&s).ends_with("(<Opacity Mask>/Opacity Mask)"), "{}", title(&s));
|
||||
|
||||
@@ -974,7 +974,7 @@ fn ui_commands_refuse_params_of_the_wrong_type() {
|
||||
assert_eq!(after, before, "{id} {params}: nothing changes");
|
||||
}
|
||||
app.run("view.setZoom", json!({"zoom": null, "center": null})).unwrap();
|
||||
assert_eq!(app.view().map(|v| v.zoom), Some(crate::state::zoom_from_display_percent(100.0, app.session.prefs.display_print_size)));
|
||||
assert_eq!(app.view().map(|v| v.zoom), Some(crate::state::zoom_from_display_percent(100.0, app.print_ppi())));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -36,6 +36,15 @@ pub struct Views {
|
||||
shown: HashMap<u64, u32>,
|
||||
}
|
||||
|
||||
impl Views {
|
||||
/// Multiplies the zoom of every view kept here by `k`, within the zoom range.
|
||||
pub(crate) fn scale_zooms(&mut self, k: f64) {
|
||||
for o in &mut self.others {
|
||||
o.view.zoom = (o.view.zoom * k).clamp(0.0313, 640.0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn uid(app: &VectorcraftApp, i: usize) -> Option<u64> {
|
||||
app.session.documents().get(i).map(|d| d.uid)
|
||||
}
|
||||
|
||||
@@ -455,12 +455,12 @@ fn run_ui_part5(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
"view.snapToPoint" => flag(&mut app.ui.view.snap_to_point),
|
||||
"view.zoomIn" | "view.zoomOut" => {
|
||||
let up = id == "view.zoomIn";
|
||||
let print = app.session.prefs.display_print_size;
|
||||
let print = app.print_ppi();
|
||||
// Selection & Anchor Display › Zoom to Selection: the selection comes to the middle.
|
||||
let focus = if app.session.prefs.zoom_to_selection { app.selection_box().map(|b| b.center()) } else { None };
|
||||
match app.view_mut() {
|
||||
Some(v) => {
|
||||
v.zoom = next_zoom(v.zoom, up);
|
||||
v.zoom = next_zoom(v.zoom, up, print);
|
||||
if let Some(c) = focus {
|
||||
v.center = c;
|
||||
}
|
||||
@@ -470,7 +470,7 @@ fn run_ui_part5(app: &mut VectorcraftApp, id: &str, p: &Value) -> Option<Result<
|
||||
}
|
||||
}
|
||||
"view.setZoom" => {
|
||||
let print = app.session.prefs.display_print_size;
|
||||
let print = app.print_ppi();
|
||||
let (zoom, center) = match opt_number(p, "zoom").and_then(|z| Ok((z, opt_point(p, "center")?))) {
|
||||
Ok(given) => given,
|
||||
Err(e) => return Some(Err(e)),
|
||||
|
||||
@@ -485,7 +485,7 @@ pub const UI_COMMANDS: &[(&str, &str, &str, &str)] = &[
|
||||
"view.actualSize",
|
||||
"Actual Size",
|
||||
"Cmd+1",
|
||||
"{} 100%: with Display Print Size at 100% Zoom off, one document point per screen point; on, one document inch fills 96 screen points (an inch at the system's reference density, whatever the display scaling); the same at every UI Scaling",
|
||||
"{} 100%: with Display Print Size at 100% Zoom off, one document point per screen point; on, one document inch fills an inch of the display that shows the window, measured from the physical size the system reports for it, or 96 screen points where it reports none; the same at every UI Scaling",
|
||||
),
|
||||
("view.setZoom", "Set Zoom", "", "{zoom: percent, center?: [x,y]}"),
|
||||
(
|
||||
|
||||
@@ -179,7 +179,7 @@ pub fn show(app: &mut VectorcraftApp, ui: &mut Ui) {
|
||||
});
|
||||
if app.session.tool_id() == "zoom" {
|
||||
let zoom = app.view().map_or(1.0, |v| v.zoom);
|
||||
mono(ui, format!("{} {}", crate::i18n::colon(tl!("Zoom")), crate::state::zoom_label(zoom, app.session.prefs.display_print_size)));
|
||||
mono(ui, format!("{} {}", crate::i18n::colon(tl!("Zoom")), crate::state::zoom_label(zoom, app.print_ppi())));
|
||||
}
|
||||
if let Some(Readout::Brush { name: Some(name) }) = readout {
|
||||
mono(ui, name);
|
||||
@@ -315,7 +315,7 @@ mod tests {
|
||||
assert!(!texts(&mut app).iter().any(|t| t.starts_with("Zoom:")));
|
||||
app.session.select_tool("zoom", view()).unwrap();
|
||||
let zoom = app.view().map_or(1.0, |v| v.zoom);
|
||||
let want = format!("Zoom: {}", crate::state::zoom_label(zoom, app.session.prefs.display_print_size));
|
||||
let want = format!("Zoom: {}", crate::state::zoom_label(zoom, app.print_ppi()));
|
||||
assert!(texts(&mut app).contains(&want), "{want}: {:?}", texts(&mut app));
|
||||
}
|
||||
|
||||
@@ -331,7 +331,7 @@ mod tests {
|
||||
crate::i18n::set_current(crate::i18n::Lang::EN);
|
||||
assert_eq!(shear.right[1], format!("{}\u{a0}: -12.5°", crate::i18n::tr(fr, "Shear")));
|
||||
let zoom = app.view().map_or(1.0, |v| v.zoom);
|
||||
let want = format!("{}\u{a0}: {}", crate::i18n::tr(fr, "Zoom"), crate::state::zoom_label(zoom, app.session.prefs.display_print_size));
|
||||
let want = format!("{}\u{a0}: {}", crate::i18n::tr(fr, "Zoom"), crate::state::zoom_label(zoom, app.print_ppi()));
|
||||
assert!(shown_texts.contains(&want), "{want}: {shown_texts:?}");
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,10 @@ pub(crate) const DESCRIPTIONS: &[(&str, &str)] = &[
|
||||
"usePreviewBounds",
|
||||
"Measures objects with their strokes and shape-changing effects for size, position and alignment; shadows, glows and blurs are not measured.",
|
||||
),
|
||||
("displayPrintSize", "At 100% zoom, one inch of the document takes 96 screen points instead of 72."),
|
||||
(
|
||||
"displayPrintSize",
|
||||
"At 100% zoom, one inch of the document fills an inch of the display, or 96 screen points where the system reports no display size.",
|
||||
),
|
||||
("doubleClickToIsolate", "Double-clicking a group, path or image with the Selection tool opens it in isolation mode."),
|
||||
(
|
||||
"transformPatternTiles",
|
||||
|
||||
@@ -220,6 +220,12 @@ pub struct Services {
|
||||
/// reports for a window on that monitor. Empty on the web, and where the host cannot place a
|
||||
/// window by these points, which sends floating panels to the main window's monitor.
|
||||
pub dock_monitors: Vec<craft_ui::docking::Monitor>,
|
||||
/// The density of the display that shows most of the main window, in the window's points
|
||||
/// (before UI Scaling) per inch, from the physical size the system reports for that display.
|
||||
/// The desktop host keeps it current as the window moves between displays. With Display Print
|
||||
/// Size at 100% Zoom, 100% shows one document inch in this many points ([`crate::state::print_ppi`]).
|
||||
/// `None` on the web and where the system reports no size, and then an inch takes 96 points.
|
||||
pub screen_ppi: Option<f64>,
|
||||
/// The text Help › Copy Troubleshooting Info copies (desktop: the platform, the graphics
|
||||
/// processor, recent commands and frame times, and the hang reports of this session and the
|
||||
/// one before). Without it the command copies the version only ([`crate::troubleshooting`]).
|
||||
|
||||
+58
-33
@@ -107,15 +107,21 @@ pub const ROTATE_VIEW_ANGLES: [(&str, f64); 12] = [
|
||||
];
|
||||
|
||||
use super::ControlResponse;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::mpsc::Sender;
|
||||
|
||||
/// Zoom stop stepping reads this (set each UI frame and before commands) so canvas wheel zoom
|
||||
/// matches the status bar when Display Print Size at 100% Zoom is on.
|
||||
static ZOOM_STOPS_PRINT_SIZE: AtomicBool = AtomicBool::new(false);
|
||||
/// Screen points in an inch when the system reports no physical size for the display: the
|
||||
/// reference density that display scaling is set against (a CSS inch).
|
||||
pub const REFERENCE_PPI: f64 = 96.0;
|
||||
|
||||
pub fn sync_zoom_stops_display_print_size(v: bool) {
|
||||
ZOOM_STOPS_PRINT_SIZE.store(v, Ordering::Relaxed);
|
||||
/// The densities a measured display may have, in screen points per inch. A size outside them is
|
||||
/// a wrong report (a projector or television that gives its aspect ratio as its size, or none).
|
||||
pub const SCREEN_PPI_RANGE: std::ops::RangeInclusive<f64> = 30.0..=1000.0;
|
||||
|
||||
/// The screen points one inch takes at 100% zoom: `None` with Preferences › General › Display
|
||||
/// Print Size at 100% Zoom off, else the measured density of the display (`screen_ppi`,
|
||||
/// [`crate::Services::screen_ppi`]), or [`REFERENCE_PPI`] when the display has none.
|
||||
pub fn print_ppi(display_print_size: bool, screen_ppi: Option<f64>) -> Option<f64> {
|
||||
display_print_size.then(|| screen_ppi.filter(|p| SCREEN_PPI_RANGE.contains(p)).unwrap_or(REFERENCE_PPI))
|
||||
}
|
||||
|
||||
/// The preset zoom stops, in percent.
|
||||
@@ -125,36 +131,35 @@ pub const ZOOM_STOPS: [f64; 26] = [
|
||||
];
|
||||
|
||||
/// Document zoom at 100% in the status bar: one screen point per document point, or with
|
||||
/// Preferences › General › Display Print Size at 100% Zoom, one document inch in 96 screen points.
|
||||
pub fn zoom_baseline(display_print_size: bool) -> f64 {
|
||||
if display_print_size { 96.0 / 72.0 } else { 1.0 }
|
||||
/// Preferences › General › Display Print Size at 100% Zoom ([`print_ppi`] `Some`), one document
|
||||
/// inch (72 pt) in an inch of the screen, `print` screen points.
|
||||
pub fn zoom_baseline(print: Option<f64>) -> f64 {
|
||||
print.map_or(1.0, |ppi| ppi / 72.0)
|
||||
}
|
||||
|
||||
pub fn zoom_display_percent(z: f64, display_print_size: bool) -> f64 {
|
||||
z / zoom_baseline(display_print_size) * 100.0
|
||||
pub fn zoom_display_percent(z: f64, print: Option<f64>) -> f64 {
|
||||
z / zoom_baseline(print) * 100.0
|
||||
}
|
||||
|
||||
pub fn zoom_from_display_percent(pct: f64, display_print_size: bool) -> f64 {
|
||||
pct / 100.0 * zoom_baseline(display_print_size)
|
||||
pub fn zoom_from_display_percent(pct: f64, print: Option<f64>) -> f64 {
|
||||
pct / 100.0 * zoom_baseline(print)
|
||||
}
|
||||
|
||||
pub fn next_zoom(z: f64, up: bool) -> f64 {
|
||||
next_zoom_with_display(z, up, ZOOM_STOPS_PRINT_SIZE.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
pub fn next_zoom_with_display(z: f64, up: bool, display_print_size: bool) -> f64 {
|
||||
let pct = zoom_display_percent(z, display_print_size);
|
||||
/// The preset zoom stop after zoom `z` (`up`) or before it, counted in the percentages the zoom
|
||||
/// field shows with 100% at [`zoom_baseline`]`(print)`, kept in the zoom range.
|
||||
pub fn next_zoom(z: f64, up: bool, print: Option<f64>) -> f64 {
|
||||
let pct = zoom_display_percent(z, print);
|
||||
let stop = if up {
|
||||
ZOOM_STOPS.iter().find(|s| **s > pct + 0.01).copied().unwrap_or(64000.0)
|
||||
} else {
|
||||
ZOOM_STOPS.iter().rev().find(|s| **s < pct - 0.01).copied().unwrap_or(3.13)
|
||||
};
|
||||
zoom_from_display_percent(stop, display_print_size)
|
||||
zoom_from_display_percent(stop, print).clamp(0.0313, 640.0)
|
||||
}
|
||||
|
||||
/// Format for the tab/zoom field: up to 2 decimals, no trailing zeros.
|
||||
pub fn zoom_label(z: f64, display_print_size: bool) -> String {
|
||||
let s = format!("{:.2}", zoom_display_percent(z, display_print_size));
|
||||
pub fn zoom_label(z: f64, print: Option<f64>) -> String {
|
||||
let s = format!("{:.2}", zoom_display_percent(z, print));
|
||||
let s = s.trim_end_matches('0').trim_end_matches('.');
|
||||
format!("{s}%")
|
||||
}
|
||||
@@ -1590,22 +1595,42 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn zoom_steps() {
|
||||
assert_eq!(next_zoom_with_display(1.0, true, false), 1.5);
|
||||
assert!((next_zoom_with_display(1.0, false, false) - 0.6667).abs() < 1e-9);
|
||||
assert_eq!(next_zoom_with_display(640.0, true, false), 640.0);
|
||||
assert_eq!(zoom_label(0.6667, false), "66.67%");
|
||||
assert_eq!(zoom_label(1.0, false), "100%");
|
||||
assert_eq!(zoom_label(0.125, false), "12.5%");
|
||||
assert_eq!(next_zoom(1.0, true, None), 1.5);
|
||||
assert!((next_zoom(1.0, false, None) - 0.6667).abs() < 1e-9);
|
||||
assert_eq!(next_zoom(640.0, true, None), 640.0);
|
||||
assert_eq!(zoom_label(0.6667, None), "66.67%");
|
||||
assert_eq!(zoom_label(1.0, None), "100%");
|
||||
assert_eq!(zoom_label(0.125, None), "12.5%");
|
||||
}
|
||||
|
||||
/// storytold/vectorcraft#2719: 100% in the zoom field matches Actual Size when Display Print Size is on.
|
||||
#[test]
|
||||
fn zoom_percent_honors_display_print_size_baseline() {
|
||||
let b = zoom_baseline(true);
|
||||
assert!((zoom_from_display_percent(100.0, true) - b).abs() < 1e-12);
|
||||
assert_eq!(zoom_from_display_percent(100.0, false), 1.0);
|
||||
assert_eq!(zoom_label(b, true), "100%");
|
||||
assert_eq!(next_zoom_with_display(b, true, true), zoom_from_display_percent(150.0, true));
|
||||
let print = print_ppi(true, None);
|
||||
let b = zoom_baseline(print);
|
||||
assert!((zoom_from_display_percent(100.0, print) - b).abs() < 1e-12);
|
||||
assert_eq!(zoom_from_display_percent(100.0, None), 1.0);
|
||||
assert_eq!(zoom_label(b, print), "100%");
|
||||
assert_eq!(next_zoom(b, true, print), zoom_from_display_percent(150.0, print));
|
||||
}
|
||||
|
||||
/// #9051: with Display Print Size on, 100% follows the measured density of the display, so an
|
||||
/// inch of the document takes as many screen points as an inch of that display holds. A
|
||||
/// density outside the range a display can have counts as no measurement.
|
||||
#[test]
|
||||
fn print_size_follows_the_displays_measured_density() {
|
||||
assert_eq!(print_ppi(false, Some(127.0)), None, "the preference off ignores the display");
|
||||
let (dense, sparse) = (print_ppi(true, Some(127.0)), print_ppi(true, Some(91.0)));
|
||||
assert!(zoom_baseline(dense) > zoom_baseline(print_ppi(true, None)), "a denser display than the reference zooms 100% further in");
|
||||
assert!(zoom_baseline(sparse) < zoom_baseline(print_ppi(true, None)), "a sparser one zooms it out");
|
||||
assert!((zoom_baseline(dense) * 72.0 - 127.0).abs() < 1e-9, "an inch of the document fills an inch of the display");
|
||||
for wrong in [Some(0.0), Some(-5.0), Some(f64::NAN), Some(f64::INFINITY), Some(5000.0), None] {
|
||||
assert_eq!(print_ppi(true, wrong), print_ppi(true, None), "{wrong:?} is no measurement");
|
||||
}
|
||||
assert_eq!(zoom_label(zoom_from_display_percent(100.0, dense), dense), "100%");
|
||||
let thin = print_ppi(true, Some(40.0));
|
||||
assert!(next_zoom(0.04, false, thin) >= 0.0313, "the last stop down stays in the zoom range");
|
||||
assert!(next_zoom(600.0, true, print_ppi(true, Some(900.0))) <= 640.0, "and the last stop up");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
+4
-1
@@ -8288,7 +8288,10 @@ control channel's `ui.drag` scrubs), `showHomeScreen` (on by default: the Home s
|
||||
off, an empty window, and the Home button or `app.home` still shows the screen), `autoCollapseIconPanels` (off by
|
||||
default: on, a click away from a panel popped out of the icon column puts it away), `displayPrintSize` (off by
|
||||
default: View › Actual Size / `view.actualSize` is one document point per screen point; on, one document inch fills
|
||||
96 screen points, an inch at the system's reference density whatever the display scaling). `uiScaling` scales the
|
||||
an inch of the display that shows the main window, measured from the physical size macOS, Windows, X11 or the
|
||||
Wayland compositor reports for it and measured again when the window moves to another display, where every
|
||||
document window keeps its zoom percentage; where the system
|
||||
reports no size, as on the web, or a size no display has, an inch is 96 screen points). `uiScaling` scales the
|
||||
interface and not the art: a zoom shows the art at the same size at every UI Scaling. The tool shortcut
|
||||
preference `holdToolKeys` also needs the desktop app. It is on by default: a single-key tool shortcut held for 0.25 s
|
||||
or more, or held while its tool is used, chooses the tool until the key is let go and then returns to the tool active
|
||||
|
||||
@@ -1292,7 +1292,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- **Pen rubber band after a smooth anchor:** the preview segment to the pointer is the curve a click there adds, leaving the last anchor along its outgoing handle and arriving at the new corner anchor without a handle, so the segment keeps its shape when the anchor is placed, as [the help page](https://helpx.adobe.com/illustrator/desktop/draw-shapes-and-paths/draw-shapes/preview-paths-drawn.html) describes. Before, the preview was a different curve, and the segment changed shape at the click (#8296, in part; `pen::tests::rubber_band_is_the_segment_a_click_adds`); scores and estimates unchanged.
|
||||
- **Pen rubber band over an anchor a click ends on:** over the path's first anchor, the preview segment ends on that anchor, as the closing segment does; over an end of another open path, it ends on that end and arrives along the end's own handle, as the joining segment does. The preview picks these anchors at the pointer before snapping, as a press does. Before, the preview ended at the pointer and arrived without a handle, so the segment moved by up to the pick tolerance at the click, and changed shape when the other end was smooth (#8296, in part; the `pen_rubber_band` tests in `engine/tests/it`); scores and estimates unchanged.
|
||||
- The desktop app keeps the Color panel's Show Options or Hide Options between sessions, and `ui.colorPanel` sets its mode and options as its panel menu does.
|
||||
- Preferences that act (#394, in part): Show Tool Tips, Double Click To Isolate, Zoom with Mouse Wheel (the wheel zooms about the pointer, Shift-wheel scrolls up and down, Cmd/Ctrl-wheel sideways; Alt/Option-wheel and a trackpad pinch zoom about the pointer either way), Use Precise Cursors; Selection & Anchor Display › Tolerance (objects, anchors and handles), Object Selection by Path Only, Command Click to Select Objects Behind (cycling down the stack), Zoom to Selection, anchor Size, Highlight anchors on mouse over; Type › Number of Recent Fonts (up to 15); Guides & Grid › guide and grid Color and Style (lines or dots) and Grids In Back. Then Snap to Point (its distance, for moves, drawn points and reference points), Move Locked and Hidden Artwork with Artboard, Enable Rubber Band for the Pen and Curvature tools, Handles style, Show handles when multiple anchors are selected, Hide Corner Widget for angles greater than; General › Transform Pattern Tiles (the transforms' and dialogs' Transform Patterns, Align and Distribute, art moved or duplicated with an artboard, and objects moved whole with direct-selected anchors) and Select Same Tint %; Type › Size/Leading, Tracking and Baseline Shift increments (`type.step`, Cmd+Shift+. and Cmd+Shift+, for the size, the Type tool's Alt+arrows), Enable Missing Glyph Protection and Fill New Type Objects With Placeholder Text. Then Smart Guides › Color, Alignment Guides, Anchor/Path Labels, Measurement Labels, Transform Tools, Object Highlighting (with Smart Guides on) and Snapping Tolerance (4 px by default, for every smart guide snap), then Construction Guides and their Angles (#506: a drawn point near a line at one of those angles through the point it leaves from lands on it). Then Type › Type Object Selection by Path Only (type is picked on the baseline of any of its lines, area type's frame or the path of type on a path, no longer anywhere in its bounds; the Type tools and the Eyedropper still take a click among the characters). Then General › Anti-aliased Artwork (off, the canvas draws the art with hard edges). Then Guides & Grid › Show Pixel Grid (Above 600% Zoom), a line at every document pixel over the art in Pixel Preview, turning with a rotated view as the document grid now does too. Then General › Show The Home Screen When No Documents Are Open (off, closing the last document leaves an empty window; the Home button still opens the screen). Then Units › Numbers Without Units Are Points (on by default: a number typed with no unit into a field in picas is read in points, a typed unit still wins; dimmed unless a unit is Picas). Then User Interface › Auto-Collapse Iconic Panels (off by default: on, a click away from a panel popped out of the icon column puts it away). Then Performance › Animated Zoom (on, with GPU Performance, which it needs and which dims it when off: the Zoom tool dragged sideways zooms about the press, right in and left out, and held still zooms on, Alt out; off, a drag zooms to the area dragged across, now drawn as a marquee), User Interface › Large Tabs (taller document tabs) and Scale Cursor Proportional to UI (off, the tool cursors keep their size whatever the UI Scaling), and File Handling › Display Bitmaps as Anti-aliased Images in Pixel Preview (off by default: Pixel Preview draws images with each pixel taking its nearest image pixel). Type › Auto Size New Area Type works too (new area type gets Auto Size). They reach agents too (`prefs.set`, then `pointer_gesture` or `press_key`; `ui.wheel` on the control channel). Then Smart Guides › Spacing Guides (moves space the selection evenly with its row or column, see Drawing aids). Then Hyphenation › Exceptions (comma-separated words that never break, or break only at their hyphens; `prefs.set` and restore push them into the hyphenator, #394). Then Type › Show Font Names in English (off, font menus label a family by its native-language name when the font has one; documents still use the English family, #394). Then General › Display Print Size at 100% Zoom (off by default: View › Actual Size is one document point per screen point; on, one document inch fills 96 screen points, an inch at the reference density display scaling is set against; `view.actualSize` / `prefs.set`, #394). Then Guides & Grid › Gridline every and Subdivisions (changing either sets the grid of every open document; new and opened documents take that grid too, except a native file and the native document an SVG, PDF, `.ai` or EPS file carries, which open with the grid they were saved with; `file.new`, `document.open`, `file.newFromTemplate`, `file.revert`, #394). Then Appearance of Black › On Screen (Display All Blacks Accurately by default: pure CMYK black shows through the CMYK profile, a dark grey; Display All Blacks as Rich Black shows it on the canvas as RGB black, also in CMYK documents drawn by ink planes, while rich blacks, black tints and images show as before; `RendeLine truncated
|
||||
- Preferences that act (#394, in part): Show Tool Tips, Double Click To Isolate, Zoom with Mouse Wheel (the wheel zooms about the pointer, Shift-wheel scrolls up and down, Cmd/Ctrl-wheel sideways; Alt/Option-wheel and a trackpad pinch zoom about the pointer either way), Use Precise Cursors; Selection & Anchor Display › Tolerance (objects, anchors and handles), Object Selection by Path Only, Command Click to Select Objects Behind (cycling down the stack), Zoom to Selection, anchor Size, Highlight anchors on mouse over; Type › Number of Recent Fonts (up to 15); Guides & Grid › guide and grid Color and Style (lines or dots) and Grids In Back. Then Snap to Point (its distance, for moves, drawn points and reference points), Move Locked and Hidden Artwork with Artboard, Enable Rubber Band for the Pen and Curvature tools, Handles style, Show handles when multiple anchors are selected, Hide Corner Widget for angles greater than; General › Transform Pattern Tiles (the transforms' and dialogs' Transform Patterns, Align and Distribute, art moved or duplicated with an artboard, and objects moved whole with direct-selected anchors) and Select Same Tint %; Type › Size/Leading, Tracking and Baseline Shift increments (`type.step`, Cmd+Shift+. and Cmd+Shift+, for the size, the Type tool's Alt+arrows), Enable Missing Glyph Protection and Fill New Type Objects With Placeholder Text. Then Smart Guides › Color, Alignment Guides, Anchor/Path Labels, Measurement Labels, Transform Tools, Object Highlighting (with Smart Guides on) and Snapping Tolerance (4 px by default, for every smart guide snap), then Construction Guides and their Angles (#506: a drawn point near a line at one of those angles through the point it leaves from lands on it). Then Type › Type Object Selection by Path Only (type is picked on the baseline of any of its lines, area type's frame or the path of type on a path, no longer anywhere in its bounds; the Type tools and the Eyedropper still take a click among the characters). Then General › Anti-aliased Artwork (off, the canvas draws the art with hard edges). Then Guides & Grid › Show Pixel Grid (Above 600% Zoom), a line at every document pixel over the art in Pixel Preview, turning with a rotated view as the document grid now does too. Then General › Show The Home Screen When No Documents Are Open (off, closing the last document leaves an empty window; the Home button still opens the screen). Then Units › Numbers Without Units Are Points (on by default: a number typed with no unit into a field in picas is read in points, a typed unit still wins; dimmed unless a unit is Picas). Then User Interface › Auto-Collapse Iconic Panels (off by default: on, a click away from a panel popped out of the icon column puts it away). Then Performance › Animated Zoom (on, with GPU Performance, which it needs and which dims it when off: the Zoom tool dragged sideways zooms about the press, right in and left out, and held still zooms on, Alt out; off, a drag zooms to the area dragged across, now drawn as a marquee), User Interface › Large Tabs (taller document tabs) and Scale Cursor Proportional to UI (off, the tool cursors keep their size whatever the UI Scaling), and File Handling › Display Bitmaps as Anti-aliased Images in Pixel Preview (off by default: Pixel Preview draws images with each pixel taking its nearest image pixel). Type › Auto Size New Area Type works too (new area type gets Auto Size). They reach agents too (`prefs.set`, then `pointer_gesture` or `press_key`; `ui.wheel` on the control channel). Then Smart Guides › Spacing Guides (moves space the selection evenly with its row or column, see Drawing aids). Then Hyphenation › Exceptions (comma-separated words that never break, or break only at their hyphens; `prefs.set` and restore push them into the hyphenator, #394). Then Type › Show Font Names in English (off, font menus label a family by its native-language name when the font has one; documents still use the English family, #394). Then General › Display Print Size at 100% Zoom (off by default: View › Actual Size is one document point per screen point; on, one document inch fills an inch of the display that shows the main window, measured from the physical size the system reports for it, or 96 screen points where it reports none; `view.actualSize` / `prefs.set`, #394, #9051). Then Guides & Grid › Gridline every and Subdivisions (changing either sets the grid of every open document; new and opened documents take that grid too, except a native file and the native document an SVG, PDF, `.ai` or EPS file carries, which open with the grid they were saved with; `file.new`, `document.open`, `file.newFromTemplate`, `file.revert`, #394). Then Appearance of Black › On Screen (Display All Blacks Accurately by default: pure CMYK black shows through the CMYK profile, a dark grey; Display All Blacks as Rich Black shows it on the canvas as RGB black, also in CMYK documents drawn byLine truncated
|
||||
- Preferences › General › Scroll Sideways with Cmd/Ctrl + Wheel (on by default; dimmed while Zoom with Mouse Wheel is on): while Zoom with Mouse Wheel is off, Cmd/Ctrl with a mouse wheel's whole notches scrolls the canvas sideways instead of zooming. Alt + Cmd/Ctrl-wheel and a pinch on a Mac trackpad, on a touch screen or in the web build still zoom about the pointer, and once a trackpad gesture holds Alt, it zooms until it ends, also after Alt is let go. Under either wheel preference, Cmd/Ctrl with a touchpad zooms about the pointer.
|
||||
- Preferences › Type › Highlight Substituted Fonts (on by default) paints pink behind text drawn in a substitute for a missing font in every document, and turning it off removes that highlight everywhere (`prefs.set highlightSubstitutedFonts`); Document Setup keeps Highlight Substituted Glyphs ([help](https://helpx.adobe.com/illustrator/desktop/design-with-text/fonts-and-scripts/edit-text-without-replacing-missing-fonts.html)).
|
||||
- Preferences › User Interface › UI Scaling scales the interface ([help](https://helpx.adobe.com/illustrator/desktop/get-started/learn-the-basics/modify-workspaces.html)). VectorCraft's own rule is that it leaves the art's size alone: at a given zoom a document point covers the same device pixels at every UI Scaling, so View › Actual Size shows the art at the same size whatever the UI Scaling. A click, a pinch or wheel zoom about the pointer, a pan, the Zoom tool's marquee, Fit, tiled panes, Pixel Preview and the Navigator's view box use the same mapping. Evidence: `canvas::tests_ui_scaling`, `tiled_documents_fit_their_panes_at_every_ui_scaling`, `the_view_box_outlines_the_canvas_at_every_ui_scaling`. Scores unchanged.
|
||||
|
||||
Reference in new issue
Block a user