Merge upstream/main into feat/style-pr-change-2697

This commit is contained in:
vangel76
2026-11-08 18:22:02 +01:00
26 changed files with 985 additions and 60 deletions
+9 -1
View File
File diff suppressed because one or more lines are too long
+16 -16
View File
@@ -299,25 +299,24 @@ fn uses_x11(setting: wordcraft_ui_egui::DisplayServer, env: impl Fn(&str) -> Opt
}
fn save_prefs(app: &WordApp) {
if let Err(e) = try_save_prefs(app) {
log::warn!("preferences: {e}");
}
}
/// Saves the preferences and says why when it could not. `Ok(false)`: nothing was written
/// because preferences are switched off or there is no settings folder.
fn try_save_prefs(app: &WordApp) -> Result<bool, String> {
if !prefs_enabled() {
return;
return Ok(false);
}
if let Some(p) = prefs_path() {
if let Some(dir) = p.parent()
&& let Err(e) = std::fs::create_dir_all(dir)
{
log::warn!("preferences: cannot create {}: {e}", dir.display());
return;
}
match serde_json::to_vec_pretty(&app.prefs()) {
Ok(bytes) => {
if let Err(e) = write_prefs(&p, &bytes) {
log::warn!("preferences: cannot save {}: {e}", p.display());
}
}
Err(e) => log::warn!("preferences: cannot serialize: {e}"),
}
let Some(p) = prefs_path() else { return Ok(false) };
if let Some(dir) = p.parent() {
std::fs::create_dir_all(dir).map_err(|e| format!("cannot create {}: {e}", dir.display()))?;
}
let bytes = serde_json::to_vec_pretty(&app.prefs()).map_err(|e| format!("cannot serialize: {e}"))?;
write_prefs(&p, &bytes).map_err(|e| format!("cannot save {}: {e}", p.display()))?;
Ok(true)
}
/// Writes `bytes` to a sibling temporary file and renames it over `path`, so a failed or
@@ -352,6 +351,7 @@ fn services(file_dialog: file_dialogs::Hook, ctx: &egui::Context) -> Services {
set_clipboard_rich: Some(Box::new(clipboard::set_rich)),
clipboard_rtf: Some(Box::new(clipboard::rtf)),
clipboard_formats: Some(Box::new(clipboard::formats)),
save_prefs: Some(Box::new(try_save_prefs)),
..Default::default()
}
}
+11 -3
View File
@@ -7,7 +7,9 @@ use std::sync::{Arc, Mutex, RwLock};
use kurbo::BezPath;
use skrifa::instance::{Location, LocationRef, Size};
use skrifa::outline::{DrawSettings, Engine, Hinting, HintingInstance, HintingOptions, OutlinePen, Target};
use skrifa::outline::{
DrawSettings, Engine, GlyphStyles, Hinting, HintingInstance, HintingOptions, OutlineGlyphFormat, OutlinePen, SmoothMode, Target,
};
use skrifa::raw::FileRef;
use skrifa::string::StringId;
use skrifa::{GlyphId, MetadataProvider};
@@ -15,8 +17,6 @@ use skrifa::{GlyphId, MetadataProvider};
pub(crate) mod user;
pub use user::{FONT_FILE_EXTS, FontFormat, Installed, MAX_FONT_FILE_BYTES, UserFont, UserFontError, decode_font_file, is_font_file_name, sniff};
static GLOBAL: std::sync::OnceLock<FontDb> = std::sync::OnceLock::new();
mod catalog;
mod face;
mod fallback;
@@ -41,10 +41,16 @@ use names::{MAX_NAME_CHARS, file_face_names, font_faces, mini_font, name};
#[cfg(test)]
pub(crate) use names::{last_resort_face, legacy_family};
static GLOBAL: std::sync::OnceLock<FontDb> = std::sync::OnceLock::new();
/// Process-wide font database.
pub struct FontDb {
faces: RwLock<Vec<Arc<FontFace>>>,
outlines: Mutex<HashMap<(u32, u32), Arc<BezPath>>>,
/// Screen-hinted outlines per (face, glyph, ppem bits); `None` where the face can't be hinted.
hinted: Mutex<HashMap<(u32, u32, u32), Option<Arc<BezPath>>>>,
/// Light hinting instances per (face, ppem bits); `None` where the face can't be hinted.
hinters: Mutex<HashMap<(u32, u32), Option<Arc<HintingInstance>>>>,
/// Fallback faces found per (character, excluded face), valid while the face count is the
/// one stored (faces are only ever added). Layout asks once per uncovered character, and the
/// search sorts every loaded face, so without this text in a script the requested font lacks
@@ -110,6 +116,8 @@ impl FontDb {
Self {
faces: RwLock::new(faces),
outlines: Mutex::new(HashMap::new()),
hinted: Mutex::new(HashMap::new()),
hinters: Mutex::new(HashMap::new()),
fallbacks: RwLock::new(FallbackCache::default()),
run_fallbacks: RwLock::new(RunFallbackCache::default()),
#[cfg(not(target_arch = "wasm32"))]
+47 -4
View File
@@ -1,7 +1,7 @@
use super::names::{LocalName, east_asian_font};
use super::{
Arc, AtomicU32, BezPath, DrawSettings, Engine, GlyphId, Hinting, HintingInstance, HintingOptions, Location, LocationRef, MetadataProvider,
Ordering, OutlinePen, RwLock, Size, Target,
Arc, AtomicU32, BezPath, DrawSettings, Engine, GlyphId, GlyphStyles, Hinting, HintingInstance, HintingOptions, Location, LocationRef,
MetadataProvider, Ordering, OutlineGlyphFormat, OutlinePen, RwLock, Size, SmoothMode, Target,
};
/// The family used when a requested family is unknown (the UI sans).
@@ -77,6 +77,8 @@ pub struct FontFace {
pub(super) bmp: std::sync::OnceLock<Box<[u64]>>,
// Some legacy CJK fonts assemble their contours with TrueType instructions.
pub(super) outline_hinter: std::sync::OnceLock<Option<HintingInstance>>,
/// The autohinter's analysis of the font for screen hinting, made once for every size.
pub(super) glyph_styles: std::sync::OnceLock<GlyphStyles>,
/// Hinted draws so far, those that ran too long, and whether that turned hinting off
/// ([`FontFace::count_hinted`]).
#[cfg_attr(target_arch = "wasm32", allow(dead_code))]
@@ -288,6 +290,42 @@ impl FontFace {
})
.as_ref()
}
/// Glyph `gid`'s outline hinted for screen text at `ppem` device pixels per em, in device
/// pixels, y-down (flipped), or `None` when the face can't be hinted. The hinting is light,
/// as FreeType's `hintslight`: horizontal edges (baseline, x-height, cap height) move onto
/// whole pixels, nothing moves sideways, so advances and layout stay as they are.
pub(super) fn hinted_glyph_outline(&self, gid: u32, hinter: &HintingInstance) -> Option<BezPath> {
let f = self.skrifa()?;
let g = f.outline_glyphs().get(GlyphId::new(gid))?;
let mut pen = FlipPen { path: BezPath::new(), room: usize::MAX, over: false, hinted: true };
g.draw(DrawSettings::hinted(hinter, false), &mut pen).map_err(|e| log::warn!("Cannot hint glyph {gid} in {:?}: {e}", self.family)).ok()?;
Some(pen.path)
}
/// A light hinting instance for `ppem` device pixels per em, with the engine FreeType's light
/// hinting picks: the autohinter for TrueType outlines (their own instructions are ignored;
/// measured against Firefox on Linux, the autohinter matches its rows of pixels and the
/// TrueType instructions don't), the font's own hints for PostScript (CFF) outlines, and for
/// fonts whose glyphs need their instructions to be assembled at all their instructions with
/// the monochrome target, as skrifa requires for them.
pub(super) fn screen_hinter(&self, ppem: f32) -> Option<HintingInstance> {
let f = self.skrifa()?;
let outlines = f.outline_glyphs();
let light = Target::Smooth { mode: SmoothMode::Light, symmetric_rendering: true, preserve_linear_metrics: true };
let (engine, target) = if outlines.require_interpreter() {
// FreeType's "tricky" fonts (old CJK fonts that assemble glyphs with their
// instructions): skrifa asks for the interpreter with the monochrome target, under
// which the instructions may move points sideways, or glyphs come apart.
(Engine::Interpreter, Target::Mono)
} else if outlines.format() == Some(OutlineGlyphFormat::Glyf) {
(Engine::Auto(Some(self.glyph_styles.get_or_init(|| GlyphStyles::new(&outlines)).clone())), light)
} else {
(Engine::Interpreter, light)
};
HintingInstance::new(&outlines, Size::new(ppem), self.location(), HintingOptions { engine, target })
.map_err(|e| log::warn!("Cannot hint {:?} at {ppem} px: {e}", self.family))
.ok()
}
/// Is `family` this face's typographic, legacy, full or PostScript name?
pub fn named(&self, family: &str) -> bool {
self.family.eq_ignore_ascii_case(family)
@@ -358,13 +396,18 @@ impl FontFace {
pub(super) static NEXT_ID: AtomicU32 = AtomicU32::new(1);
pub(super) const OUTLINE_CACHE_MAX: usize = 50_000;
/// Hinting instances kept (one per face and text size on screen).
pub(super) const HINTER_CACHE_MAX: usize = 256;
/// Sizes hinted, in device pixels per em: below, text is too small to read anyway; above, the
/// half-pixel hinting moves is invisible (and each size would cost a cache entry).
pub(super) const HINT_PPEM: std::ops::RangeInclusive<f32> = 4.0..=96.0;
/// Collects an outline flipped to y-down, keeping at most `room` path elements (`over` once it
/// had to drop one).
pub(super) struct FlipPen {
pub(super) path: BezPath,
room: usize,
over: bool,
pub(super) room: usize,
pub(super) over: bool,
/// Drawn with the face's TrueType interpreter.
pub(super) hinted: bool,
}
+38 -1
View File
@@ -1,4 +1,4 @@
use super::face::{FALLBACK_FAMILY, FontBytes, FontFace, OUTLINE_CACHE_MAX};
use super::face::{FALLBACK_FAMILY, FontBytes, FontFace, HINT_PPEM, HINTER_CACHE_MAX, OUTLINE_CACHE_MAX};
#[cfg(not(target_arch = "wasm32"))]
use super::fallback_data::read_fallback_file;
#[cfg(not(target_arch = "wasm32"))]
@@ -227,4 +227,41 @@ impl FontDb {
cache.insert(key, p.clone());
p
}
/// Glyph outline hinted for the screen at `ppem` device pixels per em ([`HINT_PPEM`]), in
/// device pixels, y-down, for drawing at a baseline on a whole pixel; cached per (face, glyph,
/// size). `None` for sizes out of range and faces that can't be hinted: draw [`Self::outline`].
pub fn hinted_outline(&self, face: &FontFace, gid: u32, ppem: f32) -> Option<Arc<BezPath>> {
if !HINT_PPEM.contains(&ppem) {
return None;
}
let key = (face.id, gid, ppem.to_bits());
if let Some(p) = self.hinted.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&key) {
return p.clone();
}
let hinter = {
let hkey = (face.id, ppem.to_bits());
let known = self.hinters.lock().unwrap_or_else(std::sync::PoisonError::into_inner).get(&hkey).cloned();
match known {
Some(h) => h,
None => {
// Built outside the lock: running a font's hinting programs takes a while.
let h = face.screen_hinter(ppem).map(Arc::new);
let mut cache = self.hinters.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
if cache.len() >= HINTER_CACHE_MAX {
cache.clear();
}
cache.insert(hkey, h.clone());
h
}
}
};
let p = hinter.and_then(|h| face.hinted_glyph_outline(gid, &h)).map(Arc::new);
let mut cache = self.hinted.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
if cache.len() >= OUTLINE_CACHE_MAX {
cache.clear();
}
cache.insert(key, p.clone());
p
}
}
+1
View File
@@ -394,6 +394,7 @@ pub(super) fn make_face(
index,
bmp: std::sync::OnceLock::new(),
outline_hinter: std::sync::OnceLock::new(),
glyph_styles: std::sync::OnceLock::new(),
hint_draws: Default::default(),
hint_slow: Default::default(),
hinting_off: Default::default(),
+62
View File
@@ -38,6 +38,7 @@ fn kai_contours_include_complete_character_body() {
}
}
use super::face::FlipPen;
use super::*;
#[test]
@@ -92,6 +93,67 @@ fn run_fallback_is_cached_per_char_set() {
assert!(db.run_fallbacks.read().unwrap().map.is_empty());
}
#[test]
fn screen_hinting_puts_horizontal_edges_on_whole_pixels_and_moves_nothing_sideways() {
let db = FontDb::global();
let face = db.face(FALLBACK_FAMILY, "Regular");
let x = face.glyph_for('x');
// 11 pt at 100 % zoom on a 145 % desktop: a fractional size, as on most screens.
let ppem = 11.0 * 96.0 / 72.0 * 1.45;
let hinted = db.hinted_outline(&face, x, ppem).expect("Source Sans 3 can be hinted");
let plain = db.outline(&face, x);
let k = f64::from(ppem) / face.upem;
let (h, u) = (kurbo::Shape::bounding_box(&*hinted), kurbo::Shape::bounding_box(&*plain));
// The x-height (the top, y-down) and the baseline sit on the pixel grid…
assert!((h.y0 - h.y0.round()).abs() < 0.02, "x-height at {}", h.y0);
assert!((h.y1 - h.y1.round()).abs() < 0.02, "baseline at {}", h.y1);
assert!((u.y0 * k - (u.y0 * k).round()).abs() > 0.02, "the unhinted x-height is off the grid: {}", u.y0 * k);
// …and the sides stay where the font puts them, so advances and line breaks don't change.
assert!((h.x0 - u.x0 * k).abs() < 0.01 && (h.x1 - u.x1 * k).abs() < 0.01, "{h:?} vs {:?}", u.scale_from_origin(k));
// Cached per size.
assert!(Arc::ptr_eq(&hinted, &db.hinted_outline(&face, x, ppem).expect("cached")));
}
#[test]
fn screen_hinting_uses_the_autohinter_even_for_fonts_with_their_own_instructions() {
// FreeType's light hinting (`hintslight`, Firefox on Linux) runs its autohinter on
// TrueType outlines and ignores their instructions: measured against Firefox, the
// instructions drew Arial's rows elsewhere and heavier.
let db = FontDb::global();
let face = db.face(FALLBACK_FAMILY, "Regular");
let font = face.skrifa().unwrap();
let outlines = font.outline_glyphs();
assert!(outlines.prefer_interpreter(), "Source Sans 3 carries TrueType instructions (ttfautohint)");
let ppem = 11.0 * 96.0 / 72.0 * 1.45;
let target = Target::Smooth { mode: SmoothMode::Light, symmetric_rendering: true, preserve_linear_metrics: true };
let drawn = |engine: Engine, gid: u32| {
let h = HintingInstance::new(&outlines, Size::new(ppem), face.location(), HintingOptions { engine, target }).unwrap();
let mut pen = FlipPen { path: BezPath::new(), room: usize::MAX, over: false, hinted: true };
outlines.get(GlyphId::new(gid)).unwrap().draw(DrawSettings::hinted(&h, false), &mut pen).unwrap();
pen.path
};
let mut differs = false;
for c in "Every Thursday".chars().filter(|c| !c.is_whitespace()) {
let gid = face.glyph_for(c);
let ours = db.hinted_outline(&face, gid, ppem).unwrap();
assert_eq!(*ours, drawn(Engine::Auto(None), gid), "{c}: the autohinter's outline");
differs |= *ours != drawn(Engine::Interpreter, gid);
}
assert!(differs, "the font's own instructions would draw it differently");
}
#[test]
fn screen_hinting_refuses_hostile_sizes() {
let db = FontDb::global();
let face = db.face(FALLBACK_FAMILY, "Regular");
let x = face.glyph_for('x');
for ppem in [f32::NAN, f32::INFINITY, f32::NEG_INFINITY, -12.0, 0.0, 1.0, 3.99, 96.01, 1e9] {
assert!(db.hinted_outline(&face, x, ppem).is_none(), "{ppem}");
}
// A glyph id past the font's glyphs has no outline to hint.
assert!(db.hinted_outline(&face, u32::MAX, 20.0).is_none_or(|o| o.elements().is_empty()));
}
/// The issue's run (#1549): Thai letters and digits, Latin letters, digits and the baht sign.
const THAI_RUN: &str = "[D] น้ำ ค่ำ ปั้น ฝั่ง ปู่ ๑๒๓๔๕๖๗๘๙๐ ฿1,250.50";
+34
View File
@@ -2,6 +2,7 @@
#[allow(unused_imports)]
use std::path::{Path, PathBuf};
use crate::fontdb::face::FlipPen;
use crate::fontdb::*;
const FAMILY: &str = "Sysfont Sans3";
@@ -420,6 +421,39 @@ fn a_family_partly_loaded_by_a_character_fallback_is_loaded_whole_for_a_run() {
assert_eq!(db.read_faces().iter().filter(|f| f.family == "Sysfont Famly").count(), 3);
}
#[test]
fn screen_hinting_runs_a_tricky_fonts_instructions_with_the_monochrome_target() {
// FreeType's "tricky" fonts (old CJK fonts listed by name, such as DynaLab's "cpop") assemble
// their glyphs with their instructions; skrifa requires the interpreter with `Target::Mono`
// for them. A bundled font renamed into the list stands in for one.
let dir = font_dir("tricky");
std::fs::write(dir.join("Tricky.ttf"), renamed_to("SourceSans3-Regular.ttf", "Sysfont cpop1")).unwrap();
let db = FontDb::with_font_dirs(vec![dir]);
let face = db.face("Sysfont cpop1", "Regular");
assert_eq!(face.family, "Sysfont cpop1");
let font = face.skrifa().unwrap();
let outlines = font.outline_glyphs();
assert!(outlines.require_interpreter(), "the name makes it tricky");
let ppem = 11.0 * 96.0 / 72.0 * 1.45;
let drawn = |target: Target, gid: u32| {
let h = HintingInstance::new(&outlines, Size::new(ppem), face.location(), HintingOptions { engine: Engine::Interpreter, target }).unwrap();
let mut pen = FlipPen { path: BezPath::new(), room: usize::MAX, over: false, hinted: true };
outlines.get(GlyphId::new(gid)).unwrap().draw(DrawSettings::hinted(&h, false), &mut pen).unwrap();
pen.path
};
// The target decides whether the instructions may move points sideways (the light target's
// backward compatibility forbids it): this font's instructions only move points vertically,
// so the target itself is checked, and the outlines drawn with it.
assert!(matches!(face.screen_hinter(ppem).unwrap().target(), Target::Mono));
for c in "Every Thursday".chars().filter(|c| !c.is_whitespace()) {
let gid = face.glyph_for(c);
assert_eq!(*db.hinted_outline(&face, gid, ppem).unwrap(), drawn(Target::Mono, gid), "{c}: the monochrome target");
}
// Any other font keeps the light target.
let plain = db.face(FALLBACK_FAMILY, "Regular");
assert!(matches!(plain.screen_hinter(ppem).unwrap().target(), Target::Smooth { mode: SmoothMode::Light, preserve_linear_metrics: true, .. }));
}
#[test]
fn coverage_ranges_hold_exactly_the_mapped_characters() {
let data = renamed("SourceSans3-Regular.ttf");
+1
View File
@@ -35,6 +35,7 @@ fn lay_in(math: &Math, lin: &str, display: bool, avail: f32, mp: &MathProps) ->
#[test]
fn eq_array_rows_without_ampersand_are_centred() {
crate::test_fonts();
// Word centres a row with no `&` in the array (#2617: a case row "a, n odd" above
// "|a|, &n even"), whether or not the other rows have one.
use wordcraft_doc::math::*;
+2
View File
@@ -1940,6 +1940,7 @@ fn lists_get_labels_and_indent() {
#[test]
fn a_none_format_label_shows_its_text_and_tabs_to_the_indent() {
crate::test_fonts();
// #4985: Word draws a "none" level's literal text ("RESPONSE:"), and an empty one still tabs
// the text to a hanging indent, as a numbered item's. An empty label already at the left indent
// takes no tab (Word's Chapter 1 list: Heading 2 starts at the margin, not at 0.5").
@@ -7845,6 +7846,7 @@ fn graphic_text_in_a_degenerate_rectangle_is_not_drawn() {
#[test]
fn chart_text_the_font_lacks_is_drawn_in_a_fallback_face() {
crate::test_fonts();
// #4720: a Chinese legend in a chart drawn in the body font (which has no Chinese) showed boxes.
use wordcraft_doc::graphic::{Graphic, GraphicItem, GraphicKind, TextAlign};
use wordcraft_doc::props::Rgb;
+2
View File
@@ -107,6 +107,7 @@ fn character_styles_and_paragraph_numbers() {
/// has no number to list.
#[test]
fn full_context_keeps_the_parent_of_a_none_level_heading() {
crate::test_fonts();
let mut d = doc(CHAPTERS, &[r#"STYLEREF "Heading 2" \w"#, r#"STYLEREF "Heading 2" \r"#]);
let num = Arc::make_mut(&mut d.numbering).add_list(ListKind::Numbered);
if let Some(n) = Arc::make_mut(&mut d.numbering).nums.iter_mut().find(|n| n.id == num) {
@@ -123,6 +124,7 @@ fn full_context_keeps_the_parent_of_a_none_level_heading() {
/// empty label of its own adds no part in full context: `3`, not `3.`.
#[test]
fn a_none_level_heading_s_number_has_no_text_and_no_trailing_period() {
crate::test_fonts();
let numbered = |text: &str, codes: &[&str]| {
let mut d = doc(CHAPTERS, codes);
let num = Arc::make_mut(&mut d.numbering).add_list(ListKind::Numbered);
+41 -1
View File
@@ -163,6 +163,11 @@ pub struct RenderOptions {
/// Thicken glyphs slightly the way macOS draws text on screen ("font smoothing"), so pages
/// look like they do in other Mac apps. For on-screen rasters only: exports stay exact.
pub text_darkening: bool,
/// Hint text for the screen the way FreeType's `hintslight` does on Linux desktops: glyph
/// baselines sit on whole pixels and their horizontal edges (x-height, cap height) are moved
/// onto the pixel grid, so text looks as crisp as in other apps there. Nothing moves
/// sideways, so lines break as without it. For on-screen rasters only: exports stay exact.
pub hinting: bool,
/// Dark page (View › Switch Modes): every colour but pictures has its lightness inverted, so
/// white paper turns black and black text white while hues stay the same. Screen only.
pub dark: bool,
@@ -265,6 +270,7 @@ impl Default for RenderOptions {
paper: Rgb::WHITE,
mark_color: Rgb(0x2B, 0x57, 0x9A),
text_darkening: false,
hinting: false,
dark: false,
dark_paper: DARK_PAPER,
read_paper: None,
@@ -491,6 +497,13 @@ fn draw_watermark(ctx: &mut RenderContext, view: Affine, page: &Page, wm: &wordc
}
}
/// Does `view` map page points to device pixels without rotation, skew or mirroring, scaling both
/// axes alike? Only then do hinted outlines (made on the pixel grid) line up with the screen.
fn is_upright(view: Affine) -> bool {
let [a, b, c, d, e, f] = view.as_coeffs();
[a, b, c, d, e, f].iter().all(|v| v.is_finite()) && b == 0.0 && c == 0.0 && a > 0.0 && (a - d).abs() <= a * 1e-6
}
/// How far, in device pixels, macOS-style font smoothing pushes each side of a glyph outline out
/// at `ppem` device pixels per em. Values from Pathfinder (MIT/Apache-2.0), which measured them
/// against macOS: 1.21% of the pixel size horizontally and 1.25 times that vertically, each
@@ -729,13 +742,19 @@ fn draw_glyphs(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
let darken_px = if opts.text_darkening && *alpha >= 1.0 { stem_darkening(*size as f64 * px_per_pt) } else { 0.0 };
let darken = if darken_px > 0.0 && k * px_per_pt > 0.0 { 2.0 * darken_px / (k * px_per_pt) } else { 0.0 };
let outline_stroke = if *synth_bold { face.upem * 0.03 } else { 0.0 } + darken;
let join = if darken > 0.0 { kurbo::Join::Round } else { kurbo::Join::Miter };
if outline_stroke > 0.0 {
let join = if darken > 0.0 { kurbo::Join::Round } else { kurbo::Join::Miter };
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(join));
}
// Emoji and other colour glyphs (#1269) are drawn from the font's colour data.
let colour = face.has_color_glyphs();
let ppem = *size as f64 * px_per_pt;
// Hinted outlines are in device pixels: only for an upright, unmirrored, evenly scaled
// view (not rotated text boxes), where the pixel grid lines up with the glyphs.
let hint_ppem = (opts.hinting && !colour && is_upright(view)).then_some(ppem as f32);
// The outline strokes in device pixels, for the hinted outlines.
let stroke_px = outline_stroke * k * px_per_pt;
let mut hinted_stroke = false;
for (gid, x, y) in glyphs {
let (gx, gy) = (*x as f64, *y as f64);
// Written so a NaN position is skipped too.
@@ -749,6 +768,23 @@ fn draw_glyphs(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
ctx.set_paint(color(opts.ink(*c), *alpha));
continue;
}
if let Some(o) = hint_ppem.and_then(|p| db.hinted_outline(face, *gid, p)) {
if o.elements().is_empty() {
continue;
}
// The baseline on a whole pixel, as the hinting assumes.
let at = view * kurbo::Point::new(gx, gy);
ctx.set_transform(Affine::translate((at.x, at.y.round())) * skew);
ctx.fill_path(&o);
if outline_stroke > 0.0 {
if !hinted_stroke {
ctx.set_stroke(kurbo::Stroke::new(stroke_px).with_join(join));
hinted_stroke = true;
}
ctx.stroke_path(&o);
}
continue;
}
let o = db.outline(face, *gid);
if o.elements().is_empty() {
continue;
@@ -756,6 +792,10 @@ fn draw_glyphs(ctx: &mut RenderContext, fr: &Frame, it: &Draw) {
ctx.set_transform(view * Affine::translate((gx, gy)) * skew * Affine::scale(k));
ctx.fill_path(&o);
if outline_stroke > 0.0 {
if hinted_stroke {
ctx.set_stroke(kurbo::Stroke::new(outline_stroke).with_join(join));
hinted_stroke = false;
}
ctx.stroke_path(&o);
}
}
+61
View File
@@ -290,6 +290,67 @@ fn text_darkening_adds_ink_on_screen_only() {
assert!(!RenderOptions::default().text_darkening);
}
/// Inked pixels that are only partly covered (grey): an edge between two pixel rows.
fn grey(img: &Rendered) -> usize {
img.pixels.as_chunks::<4>().0.iter().filter(|p| (40..215).contains(&p[0])).count()
}
/// The first and last pixel columns with any ink.
fn ink_columns(img: &Rendered) -> (usize, usize) {
let w = img.width as usize;
let inked: Vec<usize> = img.pixels.as_chunks::<4>().0.iter().enumerate().filter(|(_, p)| p[0] < 250).map(|(i, _)| i % w.max(1)).collect();
(inked.iter().copied().min().unwrap_or(0), inked.iter().copied().max().unwrap_or(0))
}
#[test]
fn hinting_sharpens_screen_text_without_making_it_bolder_or_moving_it() {
let mut d =
Document::from_text("Every Thursday evening the old print shop fills with people who make things. Painters set up by the north windows.");
// A bundled face at a fixed size, so the pixel thresholds below do not follow the machine's
// default-font substitution.
let styles = std::sync::Arc::make_mut(&mut d.styles);
styles.default_chr.font = Some("Source Sans 3".into());
styles.default_chr.size = Some(12.0);
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
// 100 % zoom on a 145 % desktop: glyph edges land between pixels.
let scale = 96.0 / 72.0 * 1.45;
let plain = render_page(&d, &l.pages[0], scale, &RenderOptions::default());
let hinted = render_page(&d, &l.pages[0], scale, &RenderOptions { hinting: true, ..Default::default() });
// Fewer grey pixels: the baseline, x-height and cap height fill whole pixel rows. Only
// horizontal edges snap (the vertical stems stay put), so on the bundled face the drop is
// 4 to 5 %: asked for at least 3 %.
let (g0, g1) = (grey(&plain), grey(&hinted));
assert!((g1 as f64) < g0 as f64 * 0.97, "grey pixels: plain {g0}, hinted {g1}");
// The same weight, as FreeType's light hinting draws it: no darker than a few percent.
let (a, b) = (ink(&plain), ink(&hinted));
assert!(b as f64 > a as f64 * 0.95 && (b as f64) < a as f64 * 1.12, "ink: plain {a}, hinted {b}");
// Nothing moves sideways: the text starts and ends in the same pixel columns.
let ((l0, r0), (l1, r1)) = (ink_columns(&plain), ink_columns(&hinted));
assert!(l0.abs_diff(l1) <= 1 && r0.abs_diff(r1) <= 1, "plain {l0}..{r0}, hinted {l1}..{r1}");
// Off by default: exports and thumbnails are untouched.
assert!(!RenderOptions::default().hinting);
}
#[test]
fn rotated_or_mirrored_views_are_not_hinted() {
let d = Document::from_text("Rotated text stays as the font draws it.");
let l = layout(&d, &mut LayoutCache::new(), &LayoutOptions::default());
let hint = RenderOptions { hinting: true, ..Default::default() };
for view in [
Affine::translate((300.0, -50.0)) * Affine::rotate(0.3) * Affine::scale(1.9),
Affine::translate((600.0, 0.0)) * Affine::scale_non_uniform(-1.9, 1.9),
Affine::scale_non_uniform(1.9, 2.4),
] {
let plain = render_region(&d, &l.pages[0], 600, 300, view, &RenderOptions::default());
let hinted = render_region(&d, &l.pages[0], 600, 300, view, &hint);
assert!(ink(&plain) > 0, "{view:?}");
assert_eq!(plain.pixels, hinted.pixels, "{view:?}");
}
assert!(is_upright(Affine::translate((3.5, 7.25)) * Affine::scale(1.93)));
assert!(!is_upright(Affine::scale(f64::NAN)));
assert!(!is_upright(Affine::scale(0.0)));
}
#[test]
fn page_picture_is_painted_behind_the_text() {
let mut png = Vec::new();
+4 -1
View File
@@ -9,6 +9,8 @@
//! background work such as a Zotero session). The window is 1440×900 pt at 2× and opens the sample
//! document unless the first line is `{"empty": true}`; `{"empty": true, "startScreen": true}`
//! starts the way the desktop app does with nothing to open (File › Home, #766). A line
//! `{"width": w}`, `{"height": h}` or `{"ppp": s}` sets the window size in points or its pixels
//! per point (e.g. 1.45 for a 145 % desktop, to see text as it is drawn there).
//! `{"demoPacks": true}` lists a few sample Language packs (installs only record themselves), and
//! (with `{"network": true}` on a line, downloading is already on) `{"demoPacks": "store"}` uses a real font store, as the desktop app does, in a new temporary
//! folder rather than the person's, or in `"storeDir"` given on the same line (with
@@ -57,8 +59,9 @@ fn main() {
}
let w = lines.iter().find_map(|l| l.get("width").and_then(|v| v.as_f64())).unwrap_or(1440.0) as f32;
let h = lines.iter().find_map(|l| l.get("height").and_then(|v| v.as_f64())).unwrap_or(900.0) as f32;
let ppp = lines.iter().find_map(|l| l.get("ppp").and_then(|v| v.as_f64())).map(|p| p.clamp(0.5, 4.0)).unwrap_or(2.0) as f32;
let mut harness =
egui_kittest::Harness::builder().with_size(egui::vec2(w, h)).with_pixels_per_point(2.0).with_max_steps(1_000_000).wgpu().build_ui_state(
egui_kittest::Harness::builder().with_size(egui::vec2(w, h)).with_pixels_per_point(ppp).with_max_steps(1_000_000).wgpu().build_ui_state(
|ui, app: &mut WordApp| {
if !READY.load(std::sync::atomic::Ordering::Relaxed) {
return;
+50
View File
@@ -397,6 +397,9 @@ impl WordApp {
for req in std::mem::take(&mut self.session.ui_requests) {
self.handle_request(&req);
}
// The open document goes to the front of the recent list after every command. The recent
// commands (`ui.recentRemove`, `ui.recentClear`) return from `ui_command` before this
// runs, so taking a document off the list is never undone by the re-add (#2716).
if let Some(p) = self.session.path.as_ref().map(|p| p.to_string_lossy().to_string())
&& self.ui.recent.first() != Some(&p)
{
@@ -800,6 +803,38 @@ impl WordApp {
}
json!({"startScreen": self.ui.start_screen})
}
"ui.recentRemove" => {
// Backstage ▸ Home/Open ▸ Recent: take one document off the list (Word's context
// menu Remove). The path must be an entry that is on the list (#2716).
let Some(path) = p.get("path").and_then(Value::as_str) else {
return Some(Err("`path` must name a document on the recent list".into()));
};
let before = self.ui.recent.len();
self.ui.recent.retain(|r| r != path);
if self.ui.recent.len() == before {
return Some(Err(format!("`{path}` is not on the recent list")));
}
let saved = self.save_prefs_now();
if !matches!(saved, Some(Err(_))) {
let name = std::path::Path::new(path).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or(path.to_string());
self.status(i18n::fmt(tl!("Removed {name} from the recent list"), &[("name", &name)]));
}
let mut r = json!({"removed": 1, "recent": self.ui.recent});
add_saved(&mut r, saved);
r
}
"ui.recentClear" => {
// Clear the whole list, as Word's registry clear does for recent documents (#2716).
let removed = self.ui.recent.len();
self.ui.recent.clear();
let saved = self.save_prefs_now();
if !matches!(saved, Some(Err(_))) {
self.status(i18n::fmt(tl!("Removed {count} documents from the recent list"), &[("count", &removed.to_string())]));
}
let mut r = json!({"removed": removed, "recent": self.ui.recent});
add_saved(&mut r, saved);
r
}
"ui.displayServer" => {
// File › Options › Advanced › Linux display server (#2184): `value` `auto`,
// `wayland` or `x11`; no value reads it. The desktop app reads it at the next launch.
@@ -1022,6 +1057,19 @@ fn input_dialog_other(id: &str, params: &Value) -> Option<&'static str> {
}
}
/// The result fields of a command that saves the preferences at once: `saved` is true when the
/// write worked, false with `saveError` when it failed (the change still holds for this run) and
/// null when the host has no preferences hook or wrote nothing.
fn add_saved(r: &mut Value, saved: Option<Result<(), String>>) {
r["saved"] = match &saved {
None => Value::Null,
Some(res) => json!(res.is_ok()),
};
if let Some(Err(e)) = saved {
r["saveError"] = json!(e);
}
}
/// Commands that work while no document is open (#1129): opening or creating one, closing the
/// window, Help, adding fonts (a font file dropped on the empty window), and the settings (File ›
/// Options, the view and interface preferences it sets, AutoCorrect Options, Customize Ribbon and
@@ -1071,6 +1119,8 @@ pub(crate) fn works_without_document(id: &str) -> bool {
| "ui.discord"
| "ui.caretAnimation"
| "ui.startScreen"
| "ui.recentRemove"
| "ui.recentClear"
| "ui.displayServer"
| "ui.statusCount"
| "ui.checkForUpdates"
+19
View File
@@ -5,6 +5,8 @@ use super::{
zotero,
};
use crate::i18n;
impl WordApp {
/// A file that wouldn't open (#1103): log it, and say on the status bar which file and why,
/// whatever handed it over (the command line, a macOS open event, a drop). Returns the message.
@@ -19,6 +21,23 @@ impl WordApp {
self.status_msg = Some((s.into(), now_ms()));
}
/// Write the current preferences out through the host's hook, if it has one (#2716). The
/// desktop app saves them at exit; a change that should survive a crash, like taking a
/// document off the recent list, needs a save at the moment of the change. `None`: the host
/// has no hook or wrote nothing; `Some(Err)`: the write failed, and the status line says so.
pub(super) fn save_prefs_now(&mut self) -> Option<Result<(), String>> {
let save = self.services.save_prefs.as_ref()?;
match save(self) {
Ok(true) => Some(Ok(())),
// The host wrote nothing (preferences switched off): same as having no hook.
Ok(false) => None,
Err(e) => {
self.status(i18n::fmt(tl!("Could not save the preferences: {error}"), &[("error", &e)]));
Some(Err(e))
}
}
}
/// Document title for the title bar (and the suggested file name). An untitled document is
/// named in the interface language, as `Document1` is in English.
pub fn title_stem(&self) -> String {
+51 -1
View File
@@ -592,6 +592,28 @@ fn personal_error_id() -> egui::Id {
egui::Id::unique("backstage_personal_error")
}
/// How the × of a recent row is drawn (#2716): not at all while nothing is hovered, dimmed while
/// the row is, and with the stronger fill only when the pointer is on the × itself.
#[derive(Debug, PartialEq, Eq)]
enum RemoveCue {
Hidden,
Dim,
Strong,
}
fn remove_cue(row_active: bool, x_active: bool) -> RemoveCue {
if x_active {
RemoveCue::Strong
} else if row_active {
RemoveCue::Dim
} else {
RemoveCue::Hidden
}
}
/// Width of the × that sits at the trailing end of a recent row (#2716).
const REMOVE_W: f32 = 28.0;
/// Draws the Recent documents list, distinguishes duplicate names by path for screen readers, and
/// stores an open failure in this page's temporary state.
fn open_list(app: &mut WordApp, ui: &mut Ui) {
@@ -610,7 +632,10 @@ fn open_list(app: &mut WordApp, ui: &mut Ui) {
let file_name = |p: &str| std::path::Path::new(p).file_name().map(|n| n.to_string_lossy().to_string()).unwrap_or(p.to_string());
let names = shown.iter().map(|p| file_name(p)).collect::<Vec<_>>();
for (p, name) in shown.iter().zip(&names) {
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width().min(700.0), 40.0), Sense::click());
// #2716: each row carries its own Remove, as Word's context menu does. The × is a button
// of its own at the trailing end, so it never opens the document; clicking the rest of the
// row opens it as before.
let (r, resp) = ui.allocate_exact_size(vec2(ui.available_width().min(700.0) - REMOVE_W, 40.0), Sense::click());
// The row shows a name and a path that may not fit: the path in full is its tooltip.
let resp = resp.on_hover_text(crate::i18n::isolate_path(p));
// Two documents with the same file name are told apart by their path, as on screen.
@@ -632,10 +657,35 @@ fn open_list(app: &mut WordApp, ui: &mut Ui) {
let side = crate::rtl::lead_center(rtl);
ui.painter().text(pos2(crate::rtl::lead_x(rtl, r, 40.0), r.min.y + 13.0), side, crate::i18n::isolate(name), medium(13.0), t.text);
ui.painter().text(pos2(crate::rtl::lead_x(rtl, r, 40.0), r.min.y + 29.0), side, crate::i18n::isolate_path(p), regular(11.0), t.text_dim);
let xr = Rect::from_min_max(pos2(r.max.x + 2.0, r.min.y + 4.0), pos2(r.max.x + REMOVE_W, r.max.y - 4.0));
// Right-to-left: the × sits on the left, past the row's trailing edge.
let xr = if rtl { xr.translate(vec2(-(r.width() + REMOVE_W + 2.0), 0.0)) } else { xr };
let xresp = ui.interact(xr, ui.scope_id().with(("recent-remove", &p)), Sense::click());
xresp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, ui.is_enabled(), tl!("Remove from list")));
// The × shows (dimmed) as soon as the row or the × is hovered or focused, so the Remove can
// be found; only the × itself gets the stronger fill and full-strength glyph.
match remove_cue(resp.hovered() || resp.has_focus(), xresp.hovered() || xresp.has_focus()) {
RemoveCue::Hidden => {}
RemoveCue::Dim => {
ui.painter().text(xr.center(), egui::Align2::CENTER_CENTER, "×", medium(15.0), t.text_dim);
}
RemoveCue::Strong => {
ui.painter().rect_filled(xr, 4.0, t.hover);
ui.painter().text(xr.center(), egui::Align2::CENTER_CENTER, "×", medium(15.0), t.text);
}
}
if resp.clicked() {
let failed = open_recent(app, p).err();
ui.ctx().data_mut(|d| d.insert_temp(open_error_id(), failed.unwrap_or_default()));
}
if xresp.clicked() {
let _ = app.run("ui.recentRemove", json!({"path": p}));
}
}
if app.ui.recent.iter().take(app.ui.recent_shown()).next().is_some()
&& ui.add(egui::Button::new(egui::RichText::new(tl!("Clear all")).font(medium(13.0)))).clicked()
{
let _ = app.run("ui.recentClear", json!({}));
}
}
+50
View File
@@ -517,6 +517,56 @@ fn an_unusable_saved_folder_falls_back_to_the_apps_own() {
let _ = std::fs::remove_dir_all(&own);
}
/// #2716: the × of a recent row is a cue, not a secret: dimmed when only the row is hovered,
/// stronger on the × itself, absent when neither is.
#[test]
fn recent_remove_cross_shows_when_the_row_is_hovered() {
use super::{RemoveCue, remove_cue};
assert_eq!(remove_cue(false, false), RemoveCue::Hidden);
assert_eq!(remove_cue(true, false), RemoveCue::Dim, "row hovered shows the glyph");
assert_eq!(remove_cue(false, true), RemoveCue::Strong);
assert_eq!(remove_cue(true, true), RemoveCue::Strong);
}
/// #2716: each recent row has its own Remove (× at the right end, so it opens nothing), and
/// Clear all takes the whole list away; the list is empty afterwards.
#[test]
fn recent_rows_can_be_removed_one_by_one_or_all_at_once() {
use egui::accesskit::Role;
let mut a = WordApp::new(wordcraft_engine::Session::new(wordcraft_doc::Document::new()), Services::default());
a.ui.recent = vec!["/tmp/alpha.docx".into(), "/tmp/beta.docx".into()];
a.run("ui.backstage", json!({"value": true, "page": "home"})).unwrap();
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(1440.0, 900.0)).build_ui_state(
|ui, app: &mut WordApp| {
let ctx = ui.ctx().clone();
app.logic(&ctx);
app.ui(ui);
},
a,
);
h.run_steps(4);
let row = |h: &egui_kittest::Harness<WordApp>, name: &str| h.query_all_by_role_and_label(Role::Button, name).next().map(|n| n.rect());
assert!(row(&h, "alpha.docx").is_some() && row(&h, "beta.docx").is_some(), "both rows show");
// The × inside alpha's row, not beta's: click it and only alpha goes.
let remove_in = |h: &mut egui_kittest::Harness<WordApp>, name: &str| {
let r = row(h, name).expect(name);
h.query_all_by_role_and_label(Role::Button, "Remove from list")
.find(|n| n.rect().min.y >= r.min.y && n.rect().min.y < r.max.y)
.expect("row has its Remove")
.click();
};
remove_in(&mut h, "alpha.docx");
h.run_steps(4);
assert_eq!(h.state().ui.recent, ["/tmp/beta.docx".to_string()], "the row's own Remove takes its row");
assert!(h.state().ui.backstage, "the × does not open the Backstage away");
assert!(row(&h, "alpha.docx").is_none() && row(&h, "beta.docx").is_some());
h.get_by_label("Clear all").click();
h.run_steps(4);
assert!(h.state().ui.recent.is_empty(), "Clear all empties the list");
assert!(h.query_by_label("Documents you open will show up here.").is_some());
assert!(row(&h, "beta.docx").is_none(), "and Clear all goes with it");
}
/// Home and New are different pages (#141): Home has the short template row, the link to New
/// and Recent; New has every template and no Recent list.
#[test]
+107 -14
View File
@@ -64,8 +64,8 @@ use navigation::{scrollbar_page_tip, viewed_page};
use pages::{DRAWING_GRID_MAX_LINES, DRAWING_GRID_MIN_PX};
pub(crate) use pages::{PageKeys, dark_page, page_doc, page_screen_scale, preview_sel, screen_render_options};
use pages::{
drawing_grid, drawing_grid_step, gridline_cells, page_image, page_key, page_render_options, shown_layout, texel_aligned_rect, view_key,
visible_tiles,
drawing_grid, drawing_grid_step, gridline_cells, page_image, page_key, page_render_options, page_shows, shown_layout, texel_aligned_rect,
view_key, visible_tiles,
};
pub(crate) use reading::turn_read_page;
#[cfg(test)]
@@ -111,7 +111,10 @@ fn canvas_scroll_thumb(visuals: &mut egui::Visuals, t: &Tokens) {
}
pub struct CanvasState {
textures: HashMap<usize, (u64, TextureHandle)>,
/// Page rasters: (key, what the page showed, texture). The key ([`page_key`]) includes the
/// raster scale; what the page showed ([`page_shows`]) doesn't, so a zoom can tell whether
/// a raster may stand in for the page at another size.
textures: HashMap<usize, (u64, u64, TextureHandle)>,
/// Visible full-resolution tiles of pages too tall for one GPU texture.
tiles: HashMap<(usize, usize), (u64, TextureHandle)>,
/// Page content fingerprints of the current layout, for the texture cache (#811).
@@ -168,6 +171,10 @@ pub struct CanvasState {
pub viewed_page: Option<usize>,
/// Effective scale (screen points per document point).
pub scale: f32,
/// Whether this frame's pages were drawn hinted ([`hint_pages`]).
pub(crate) pages_hinted: bool,
/// Page rasters rendered so far (whole pages, not tiles), for tests.
pub(crate) rasters: u64,
pub canvas_rect: Option<Rect>,
pub focused: bool,
/// The page's widget id and the pass that last drew it, so a click elsewhere can hand the
@@ -402,6 +409,8 @@ impl Default for CanvasState {
scrollbar_page: None,
viewed_page: None,
scale: PX_PER_PT,
pages_hinted: screen_render_options().hinting,
rasters: 0,
canvas_rect: None,
focused: false,
widget_id: None,
@@ -526,6 +535,10 @@ struct CanvasView {
vruler: Option<Rect>,
paper: Color32,
animate: bool,
/// A pointer zoom is moving the scale over several frames ([`pointer_zoom`]).
zooming: bool,
/// Whether this frame draws the pages hinted ([`hint_pages`]).
hinted: bool,
opts: egui::InputOptions,
geo: Geometry,
dim_body: bool,
@@ -580,9 +593,16 @@ fn prepare_view(app: &mut WordApp, ui: &Ui, full: Rect, layout: &DocLayout) -> C
if read_mode {
app.canvas.scroll_max = (geo.size - area.size()).max(egui::Vec2::ZERO);
}
if (geo.scale - app.canvas.scale).abs() > 1e-6 {
let rescaled = (geo.scale - app.canvas.scale).abs() > 1e-6;
if rescaled {
ui.ctx().request_repaint();
}
// Does the zoom move over several frames? An eased wheel notch or a pinch does; with animation
// effects off a wheel step lands finished in its own frame (and is drawn so at once).
let gliding = animate || ui.input(|i| i.multi_touch().is_some() || i.events.iter().any(|e| matches!(e, egui::Event::Zoom(_))));
let zooming = pointer_zoom(zoom_delta, rescaled, gliding);
let hinted = hint_pages(zoom_delta, rescaled, gliding);
app.canvas.pages_hinted = hinted;
// A zoom moves the scroll offset without anyone scrolling: not passed on to a partner window.
let rescaled = (geo.scale - app.canvas.scale).abs() > 1e-4;
app.canvas.scale = geo.scale;
@@ -612,7 +632,7 @@ fn prepare_view(app: &mut WordApp, ui: &Ui, full: Rect, layout: &DocLayout) -> C
{
app.session.page_hint = c.page;
}
CanvasView { area, hruler, vruler, paper, animate, opts, geo, dim_body, grid_story, caret, rescaled }
CanvasView { area, hruler, vruler, paper, animate, zooming, hinted, opts, geo, dim_body, grid_story, caret, rescaled }
}
fn update_caret_scroll(app: &mut WordApp, view: &CanvasView) -> Option<Rect> {
@@ -912,6 +932,10 @@ struct PagePaint<'a> {
paper: Color32,
hidden: Option<(usize, Pos)>,
view: u64,
/// The view without the hinting, which a stretched raster may differ in (see `stretched`).
shown_view: u64,
zooming: bool,
hinted: bool,
content_origin: Pos2,
ppp: f32,
max_tex: f32,
@@ -924,6 +948,39 @@ struct PagePaintOutput {
rendered: usize,
}
/// Are pages drawn hinted this frame (as [`screen_render_options`] says)? Not while a pointer
/// zoom moving over several frames ([`pointer_zoom`]) changes the scale: each such frame is a new
/// size shown for a moment, and hinting every one would cost each page about 1.5 ms more and fill
/// the hint caches with sizes nobody rests on, pushing out the one the zoom ends at. The first
/// frame at rest draws the page hinted (the hinting is in the page's key). A zoom that leaves the
/// scale as it is (at 10 % or 500 %, or over the ribbon) keeps the pages hinted, and other scale
/// changes (the Zoom dialog or slider, a fit zoom following the window, a wheel step with
/// animation effects off) are drawn hinted at once.
fn hint_pages(zoom_delta: f32, rescaled: bool, gliding: bool) -> bool {
screen_render_options().hinting && !pointer_zoom(zoom_delta, rescaled, gliding)
}
/// Is a pointer zoom (Ctrl/⌘+wheel, a pinch: `zoom_delta` other than 1) changing the scale this
/// frame (`rescaled`) on its way over several frames (`gliding`: easing in, or following the
/// fingers)? Its frames are in-between sizes, each shown for a moment. A wheel step with
/// animation effects off lands finished in its frame: not in between.
fn pointer_zoom(zoom_delta: f32, rescaled: bool, gliding: bool) -> bool {
let gesture = zoom_delta.is_nan() || (zoom_delta - 1.0).abs() > 1e-3;
gesture && rescaled && gliding
}
/// A page raster is stretched at most this much (either way) during a pointer zoom before it is
/// rendered again at the zoom's current size.
const STRETCH_MAX: f32 = 1.5;
/// Can a page raster `tex_w` pixels wide, of a page `page_w` points wide, stand in for one at
/// `scale_px` pixels per point while a zoom goes on ([`STRETCH_MAX`])?
fn stretch_fits(tex_w: usize, page_w: f32, scale_px: f32) -> bool {
let had = tex_w as f32 / page_w.max(1.0);
let ratio = scale_px / had;
ratio.is_finite() && (1.0 / STRETCH_MAX..=STRETCH_MAX).contains(&ratio)
}
fn draw_page_gridlines(app: &WordApp, painter: &egui::Painter, t: &Tokens, page: &Page, visual_sr: Rect, page_scale: f32) {
// View › Gridlines: the drawing grid over the text area (Print Layout, on screen only).
if app.session.view.gridlines && app.session.view.mode == wordcraft_layout::ViewMode::Print && !app.session.view.read_mode {
@@ -956,7 +1013,25 @@ fn draw_page_gridlines(app: &WordApp, painter: &egui::Painter, t: &Tokens, page:
}
fn paint_pages(pass: PagePaint<'_>) -> PagePaintOutput {
let PagePaint { app, ui, layout, geo, t, painter, dim_body, paper, hidden, view, content_origin, ppp, max_tex, grid_story } = pass;
let PagePaint {
app,
ui,
layout,
geo,
t,
painter,
dim_body,
paper,
hidden,
view,
shown_view,
zooming,
hinted,
content_origin,
ppp,
max_tex,
grid_story,
} = pass;
let mut visible_tile_keys = HashSet::new();
let mut rendered = 0;
let mut rects = Vec::with_capacity(geo.rects.len());
@@ -977,36 +1052,48 @@ fn paint_pages(pass: PagePaint<'_>) -> PagePaintOutput {
let cached = !tiled && app.canvas.textures.contains_key(&i);
let key =
if visible || cached { page_key(app, layout, i, view, scale_px) ^ if tiled { (tile_height_px as u64) << 32 } else { 0 } } else { 0 };
let mut fresh = cached && app.canvas.textures.get(&i).is_some_and(|(k, _)| *k == key);
let mut fresh = cached && app.canvas.textures.get(&i).is_some_and(|(k, _, _)| *k == key);
// The page a drag took an object off: render it this frame whatever the budget, or the
// raster with the object still on it shows for a frame.
let forced = hidden.as_ref().is_some_and(|(page, _)| *page == i);
// Render before placing the page: a page re-rendered in this frame (a zoom step, an
// edit) then sits on the pixel grid in this frame too, rather than a frame later.
if visible && !tiled && !fresh && (forced || rendered < 2 || !app.canvas.textures.contains_key(&i) && rendered < 4) {
// During a pointer zoom the page's last raster is stretched to the new size instead of
// rendered at each in-between size (each shown for a frame, a few ms a page on a 4K
// screen): it is rendered once the zoom stops, or before stretching softens it too much.
// Only a raster of what the page shows now: a zoom that reflows the pages (Read Mode's
// text size, Web Layout's width) renders them anew.
let shows = if visible || cached { page_shows(app, layout, i, shown_view) } else { 0 };
let stretched = zooming
&& !forced
&& app.canvas.textures.get(&i).is_some_and(|(_, showed, tex)| *showed == shows && stretch_fits(tex.size()[0], page.w, scale_px));
if visible && !tiled && !fresh && !stretched && (forced || rendered < 2 || !app.canvas.textures.contains_key(&i) && rendered < 4) {
let mut opts = page_render_options(app, dim_body);
opts.hinting &= hinted;
// Only on the page it is on: the `Pos` can't match an object of another page.
opts.display.hide_object = hidden.as_ref().filter(|(page, _)| *page == i).map(|(_, p)| p.clone());
let img = wordcraft_render::render_page(page_doc(app), page, scale_px, &opts);
let ci = page_image(&img);
match app.canvas.textures.get_mut(&i) {
Some((k, tex)) => {
Some((k, showed, tex)) => {
tex.set(ci, egui::TextureOptions::LINEAR);
*k = key;
*showed = shows;
}
None => {
let tex = ui.ctx().load_texture(format!("page{i}"), ci, egui::TextureOptions::LINEAR);
app.canvas.textures.insert(i, (key, tex));
app.canvas.textures.insert(i, (key, shows, tex));
}
}
rendered += 1;
app.canvas.rasters += 1;
fresh = true;
} else if visible && !tiled && !fresh {
ui.ctx().request_repaint();
}
let current_scale = geo.scale * ppp;
let visual_sr = if fresh && (scale_px - current_scale).abs() <= 0.0001_f32.max(current_scale.abs() * 0.0001) {
app.canvas.textures.get(&i).map_or(sr, |(_, tex)| texel_aligned_rect(sr, tex.size_vec2(), ppp))
app.canvas.textures.get(&i).map_or(sr, |(_, _, tex)| texel_aligned_rect(sr, tex.size_vec2(), ppp))
} else {
sr
};
@@ -1038,6 +1125,7 @@ fn paint_pages(pass: PagePaint<'_>) -> PagePaintOutput {
let fresh = app.canvas.tiles.get(&id).is_some_and(|(k, _)| *k == key);
if !fresh && rendered < 4 {
let mut opts = page_render_options(app, dim_body);
opts.hinting &= hinted;
// Only on the page it is on: the `Pos` can't match an object of another page.
opts.display.hide_object = hidden.as_ref().filter(|(page, _)| *page == i).map(|(_, p)| p.clone());
// The tiny subtraction avoids a 1px overshoot from round-tripping f32
@@ -1072,7 +1160,7 @@ fn paint_pages(pass: PagePaint<'_>) -> PagePaintOutput {
painter.image(tex.id(), rect, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
}
}
} else if let Some((_, tex)) = app.canvas.textures.get(&i) {
} else if let Some((_, _, tex)) = app.canvas.textures.get(&i) {
painter.image(tex.id(), visual_sr, Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)), Color32::WHITE);
}
let page_scale = page_screen_scale(visual_sr, page, geo.scale);
@@ -1446,7 +1534,7 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
let scroll_target = if hold_scroll_for_preview(app) { None } else { update_caret_scroll(app, &view) };
let motion = scroll_motion(app, ui, full, &view);
let (scroll_area, scroll_base) = configure_scroll_area(app, ui, &view, motion);
let CanvasView { area, hruler, vruler, paper, geo, dim_body, grid_story, caret, rescaled, .. } = view;
let CanvasView { area, hruler, vruler, paper, zooming, hinted, geo, dim_body, grid_story, caret, rescaled, .. } = view;
let mut origin = area.min;
let mut ui_area = ui.new_child(egui::UiBuilder::new().max_rect(area));
// The bars are drawn with `ui_area`'s style; what the pages draw gets the inherited one back.
@@ -1468,7 +1556,9 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
let max_tex = ui.ctx().input(|i| i.max_texture_side).min(wordcraft_render::MAX_SIDE as usize).max(1) as f32;
let content_origin = ui.min_rect().min;
let hidden = app.canvas.dragged_off_page();
let page_view = view_key(app, dim_body, hidden.as_ref().map(|(_, p)| p));
let page_view = view_key(app, dim_body, hidden.as_ref().map(|(_, p)| p), hinted);
// The view without the hinting, which a stretched raster may differ in (see `stretched`).
let shown_view = view_key(app, dim_body, hidden.as_ref().map(|(_, p)| p), true);
let t0 = crate::now_ms();
let PagePaintOutput { rects, visible_tile_keys, rendered } = paint_pages(PagePaint {
app,
@@ -1481,6 +1571,9 @@ pub fn show(app: &mut WordApp, ui: &mut Ui) {
paper,
hidden,
view: page_view,
shown_view,
zooming,
hinted,
content_origin,
ppp,
max_tex,
+21 -4
View File
@@ -4,8 +4,10 @@ use super::{DocLayout, Hash, Hasher, Page, Placed, Pos, Pos2, Rect, StoryRef, Wo
/// marks and markup, dark mode, the page colour and watermark, header/body dimming, the media,
/// and (while a drag lasts) the object left out of the page.
/// Taken once per frame.
pub(super) fn view_key(app: &WordApp, dim_body: bool, hidden: Option<&Pos>) -> u64 {
pub(super) fn view_key(app: &WordApp, dim_body: bool, hidden: Option<&Pos>, hinted: bool) -> u64 {
let mut h = std::collections::hash_map::DefaultHasher::new();
// A page drawn unhinted mid-zoom must not pass for the hinted page (see [`hint_pages`]).
hinted.hash(&mut h);
let v = &app.session.view;
(v.marks, app.session.prefs.marks, v.show_markup, v.dark_mode, wordcraft_render::DARK_PAPER, v.hide_ink, v.draw.replay).hash(&mut h);
(v.read_mode, v.read_page_color, app.session.prefs.paper_color).hash(&mut h);
@@ -82,6 +84,14 @@ impl PageKeys {
}
}
/// What page `i` shows, whatever its size: its content and the view (`view_key` with the
/// hinting fixed). A raster that showed this may be stretched to stand in for the page.
pub(super) fn page_shows(app: &mut WordApp, layout: &std::sync::Arc<DocLayout>, i: usize, view: u64) -> u64 {
let mut h = std::collections::hash_map::DefaultHasher::new();
(view, app.canvas.page_keys.content(layout, i)).hash(&mut h);
h.finish()
}
/// The texture cache key of page `i`: its content, the view, and the raster scale.
pub(super) fn page_key(app: &mut WordApp, layout: &std::sync::Arc<DocLayout>, i: usize, view: u64, scale_px: f32) -> u64 {
let mut h = std::collections::hash_map::DefaultHasher::new();
@@ -263,8 +273,15 @@ pub(super) fn page_render_options(app: &WordApp, dim_body: bool) -> wordcraft_re
opts
}
/// Render options for page rasters shown on screen: on macOS, text is darkened the way the system
/// draws it, so a page looks as it does in other Mac apps (exports never are).
/// Render options for page rasters shown on screen, so a page looks as text does in the
/// platform's other apps (exports never change): on macOS, text is darkened the way the system
/// draws it; on Linux and the BSDs it is hinted lightly, as FreeType's `hintslight` draws it
/// there (not darkened: hinted text already has FreeType's weight, and darkening made it
/// look semi-bold).
pub(crate) fn screen_render_options() -> wordcraft_render::RenderOptions {
wordcraft_render::RenderOptions { text_darkening: cfg!(target_os = "macos"), ..Default::default() }
wordcraft_render::RenderOptions {
text_darkening: cfg!(target_os = "macos"),
hinting: cfg!(all(unix, not(target_os = "macos"))),
..Default::default()
}
}
+43 -10
View File
@@ -345,7 +345,7 @@ fn caret_contrasts_with_what_lies_under_it() {
let at = |a: &mut WordApp, off: usize| {
let layout = a.session.layout();
let c = layout.caret_on(&Pos::body(0, off), 0).unwrap();
let view = view_key(a, false, None);
let view = view_key(a, false, None, true);
caret_color_at(a, &layout, c.page, c.x, c.top + c.height / 2.0, view, false)
};
assert_eq!(at(&mut a, 2), Color32::BLACK, "white paper");
@@ -372,19 +372,19 @@ fn read_mode_page_color_sets_the_reading_paper() {
a.run("design.pageColor", json!({"color": "#102040"})).unwrap();
let paper = |a: &WordApp| page_render_options(a, false).paper_of(&a.session.doc);
assert_eq!(paper(&a), Rgb(0x10, 0x20, 0x40), "Print Layout shows the page color");
let print_key = view_key(&a, false, None);
let print_key = view_key(&a, false, None, true);
a.run("view.readMode", json!({})).unwrap();
assert_eq!(paper(&a), Rgb::WHITE, "None: white, the page color ignored");
let none_key = view_key(&a, false, None);
let none_key = view_key(&a, false, None, true);
a.run("view.readPageColor", json!({"value": "sepia"})).unwrap();
assert_eq!(paper(&a), wordcraft_render::SEPIA_PAPER);
assert!(!page_render_options(&a, false).dark, "Sepia keeps the text's colors");
let sepia_key = view_key(&a, false, None);
let sepia_key = view_key(&a, false, None, true);
a.run("view.readPageColor", json!({"value": "inverse"})).unwrap();
assert!(page_render_options(&a, false).dark);
let d = wordcraft_render::DARK_PAPER;
assert_eq!(paper(&a), Rgb(d, d, d));
let inverse_key = view_key(&a, false, None);
let inverse_key = view_key(&a, false, None, true);
let keys = [print_key, none_key, sepia_key, inverse_key];
for (i, k) in keys.iter().enumerate() {
assert!(!keys[..i].contains(k), "each paper has its own view key");
@@ -4930,9 +4930,42 @@ fn the_view_key_changes_when_a_drag_takes_an_object_off_the_page() {
let doc = wordcraft_doc::Document::from_text("Hello WordCraft");
let app = WordApp::new(wordcraft_engine::Session::new(doc), Default::default());
let object = Pos::body(0, 5);
let hidden = view_key(&app, false, Some(&object));
assert_ne!(hidden, view_key(&app, false, None), "the page without the dragged object is rendered again");
assert_eq!(hidden, view_key(&app, false, Some(&object)), "the same drag keeps the key: no re-render every frame");
let hidden = view_key(&app, false, Some(&object), true);
assert_ne!(hidden, view_key(&app, false, None, true), "the page without the dragged object is rendered again");
assert_eq!(hidden, view_key(&app, false, Some(&object), true), "the same drag keeps the key: no re-render every frame");
}
/// A zoom easing in (or a pinch) shows a new size every frame for a moment: those pages are
/// drawn unhinted, so they fill no hint caches with sizes nobody rests on. The first frame
/// without zooming draws the page hinted again, even at the size the last zoom frame drew.
#[test]
fn pages_are_hinted_again_once_a_zoom_stops() {
let platform = screen_render_options().hinting;
assert_eq!(hint_pages(1.0, false, true), platform, "at rest, as the platform draws text");
for zoom in [1.1, 0.9, 1.002, 0.998, f32::NAN, f32::INFINITY, 0.0] {
assert!(!hint_pages(zoom, true, true), "{zoom}: the scale changes under a gliding pointer zoom");
assert_eq!(hint_pages(zoom, false, true), platform, "{zoom}: at 10 % or 500 %, or over the ribbon: nothing changes");
assert_eq!(hint_pages(zoom, true, false), platform, "{zoom}: a wheel step with animation effects off lands finished");
}
assert_eq!(hint_pages(1.0, true, true), platform, "the Zoom dialog or slider, a fit zoom: hinted at once");
// The hinting is part of the page's key: the last zoom frame's raster is replaced.
let doc = wordcraft_doc::Document::from_text("Hello WordCraft");
let app = WordApp::new(wordcraft_engine::Session::new(doc), Default::default());
assert_ne!(view_key(&app, false, None, true), view_key(&app, false, None, false));
}
/// While a zoom goes on, a page raster stands in for one up to half again larger or smaller.
#[test]
fn a_raster_is_stretched_at_most_half_again_during_a_zoom() {
// A 612 pt page rendered 816 px wide (100 % at 1x): 1.333 px per point.
assert!(stretch_fits(816, 612.0, 816.0 / 612.0));
assert!(stretch_fits(816, 612.0, 1.9), "zoomed in 43 %");
assert!(!stretch_fits(816, 612.0, 2.1), "zoomed in 58 %: rendered again");
assert!(stretch_fits(816, 612.0, 0.95), "zoomed out to 71 %");
assert!(!stretch_fits(816, 612.0, 0.85), "zoomed out to 64 %: rendered again");
for hostile in [(0, 612.0, 1.0), (816, 0.0, 1.0), (816, 612.0, f32::NAN), (816, 612.0, f32::INFINITY), (816, f32::NAN, 1.0)] {
assert!(!stretch_fits(hostile.0, hostile.1, hostile.2), "{hostile:?}");
}
}
#[test]
@@ -4942,10 +4975,10 @@ fn screen_paper_color_changes_raster_and_cache_without_changing_export_paper() {
let layout = app.session.layout();
let page = &layout.pages[0];
let print_before = wordcraft_render::render_page(&app.session.doc, page, 0.1, &Default::default());
let mut keys = vec![view_key(&app, false, None)];
let mut keys = vec![view_key(&app, false, None, true)];
for (value, expected) in [("green", Rgb(0xCC, 0xE8, 0xCF)), ("cream", Rgb(0xFA, 0xF0, 0xDC)), ("gray", Rgb(0xE8, 0xEA, 0xED))] {
app.run("view.paperColor", json!({"value":value})).unwrap();
let key = view_key(&app, false, None);
let key = view_key(&app, false, None, true);
assert!(!keys.contains(&key), "each preset invalidates page and tile caches");
keys.push(key);
let opts = page_render_options(&app, false);
+8 -1
View File
@@ -1,5 +1,5 @@
use super::state::DefaultApp;
use super::{FileDialogAnswer, FileDialogRequest, async_saves, paste_picture, printing};
use super::{FileDialogAnswer, FileDialogRequest, WordApp, async_saves, paste_picture, printing};
/// Platform services injected by the host (file dialogs, file I/O).
#[derive(Default)]
@@ -92,6 +92,13 @@ pub struct Services {
/// `xdg-mime`. `None` (web, macOS) hides the button; macOS shows how to do it in Finder
/// instead. An error means nothing changed.
pub make_default_app: Option<Box<dyn Fn() -> Result<DefaultApp, String>>>,
/// Desktop: write the app's current preferences out now, not only at exit (#2716): a
/// document taken off the recent list should survive the app being killed before a normal
/// close. `Ok(true)`: written; `Ok(false)`: nothing written because the host keeps no
/// preferences (switched off, no settings folder); an error is the reason the write failed.
/// The recent commands report these as `saved` true / null / false. `None` (web, tests) keeps
/// the change to this run and reports `saved: null`.
pub save_prefs: Option<Box<dyn Fn(&WordApp) -> Result<bool, String>>>,
/// Desktop: the app's own user templates folder (`Templates` in the settings folder, #2852),
/// used while File › Options names none. File › New lists personal templates from it and Save
/// as Word Template starts in it. `None` (web) hides personal templates.
+244
View File
@@ -1742,6 +1742,145 @@ fn wheel_notches_land_at_once_with_animation_effects_off() {
assert!(first > 0.0 && first < notch, "a notch eases in again: {first}");
}
/// A Ctrl+wheel notch eases in over several frames, each a new size: those pages are drawn
/// unhinted (they show for a moment, and hinting each size would fill the hint caches), and
/// the first frame after the zoom stops draws them hinted, as the platform draws text.
#[test]
fn an_easing_zoom_draws_unhinted_pages_until_it_stops() {
let ctx = egui::Context::default();
let system = std::rc::Rc::new(std::cell::Cell::new(Some(true)));
let mut a = app_with_system_animations(&system);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 800.0));
let mut t = 0.0;
let mut frame = |a: &mut WordApp, events: Vec<egui::Event>| {
t += 1.0 / 60.0;
let input = egui::RawInput { events, time: Some(t), screen_rect: Some(screen), ..Default::default() };
ctx.run_ui(input, |ui| {
a.logic(ui.ctx());
a.ui(ui);
})
.drop_without_applying_deltas();
};
for _ in 0..3 {
frame(&mut a, Vec::new());
}
let platform = crate::canvas::screen_render_options().hinting;
assert_eq!(a.canvas.pages_hinted, platform, "at rest");
let over_page = a.canvas.canvas_rect.unwrap().center();
frame(&mut a, vec![egui::Event::PointerMoved(over_page)]);
let wheel = egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Line,
source: egui::MouseWheelSource::Unknown,
delta: egui::vec2(0.0, 1.0),
phase: egui::TouchPhase::Move,
modifiers: egui::Modifiers::COMMAND,
};
let before = a.canvas.scale;
frame(&mut a, vec![wheel]);
// The wheel's own frame already starts the zoom, unhinted.
assert_ne!(a.canvas.scale, before, "the zoom starts in the wheel's frame");
assert!(!platform || !a.canvas.pages_hinted, "the wheel's frame is unhinted");
let (mut eased, mut unhinted) = (0, 0);
let mut last = a.canvas.scale;
for _ in 0..60 {
frame(&mut a, Vec::new());
if a.canvas.scale != last {
eased += 1;
unhinted += usize::from(!a.canvas.pages_hinted);
last = a.canvas.scale;
} else {
break;
}
}
assert!(a.canvas.scale > before && eased >= 2, "the notch eased in over frames: {eased}");
if platform {
assert_eq!(unhinted, eased, "every in-between size unhinted");
}
// The frame after the zoom stops: hinted again, at the size it ended on.
frame(&mut a, Vec::new());
assert_eq!(a.canvas.scale, last);
assert_eq!(a.canvas.pages_hinted, platform, "hinted once the zoom stops");
}
/// A pointer zoom stretches the pages' last rasters rather than rendering each in-between
/// size: a notch (22 %) renders nothing until it stops, then the page once; a long zoom renders
/// again only when a raster would be stretched past half again its size. A zoom that isn't a
/// gesture (View › Zoom) renders at once.
#[test]
fn a_pointer_zoom_stretches_pages_until_it_stops() {
let ctx = egui::Context::default();
let system = std::rc::Rc::new(std::cell::Cell::new(Some(true)));
let mut a = app_with_system_animations(&system);
let screen = egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1280.0, 800.0));
let mut t = 0.0;
let mut frame = |a: &mut WordApp, events: Vec<egui::Event>| {
t += 1.0 / 60.0;
// A GPU's texture size, as on desktops: at egui's 2048 default the zoomed page would
// be drawn in tiles (for very long Web Layout pages), which this isn't about.
let input = egui::RawInput { events, time: Some(t), screen_rect: Some(screen), max_texture_side: Some(8192), ..Default::default() };
ctx.run_ui(input, |ui| {
a.logic(ui.ctx());
a.ui(ui);
})
.drop_without_applying_deltas();
};
for _ in 0..3 {
frame(&mut a, Vec::new());
}
let over_page = a.canvas.canvas_rect.unwrap().center();
frame(&mut a, vec![egui::Event::PointerMoved(over_page)]);
let wheel = || egui::Event::MouseWheel {
unit: egui::MouseWheelUnit::Line,
source: egui::MouseWheelSource::Unknown,
delta: egui::vec2(0.0, 1.0),
phase: egui::TouchPhase::Move,
modifiers: egui::Modifiers::COMMAND,
};
// Frames until the zoom stops; returns (frames with a new scale, rasters rendered in them,
// rasters rendered in the frame it stopped).
let ease = |a: &mut WordApp, frame: &mut dyn FnMut(&mut WordApp, Vec<egui::Event>), notches: &[usize]| {
let before = a.canvas.rasters;
let (mut moving, mut last, mut f) = (0, a.canvas.scale, 0);
loop {
let ahead = a.canvas.rasters;
frame(a, if notches.contains(&f) { vec![wheel()] } else { Vec::new() });
f += 1;
if a.canvas.scale == last && f > notches.iter().max().copied().unwrap_or(0) {
return (moving, ahead - before, a.canvas.rasters - ahead);
}
moving += usize::from(a.canvas.scale != last);
last = a.canvas.scale;
assert!(f < 120, "the zoom stops");
}
};
let start = a.canvas.scale;
let (moving, while_moving, at_rest) = ease(&mut a, &mut frame, &[0]);
assert!(moving >= 3 && a.canvas.scale / start > 1.2, "a notch eases in: {moving} frames");
assert_eq!((while_moving, at_rest), (0, 1), "no raster while it moves ({moving} frames), one the frame it stops");
// A long zoom (three notches, about 1.8x): rendered again only every half again.
let start = a.canvas.scale;
let (moving, while_moving, at_rest) = ease(&mut a, &mut frame, &[0, 3, 6]);
let rasters = while_moving + at_rest;
assert!(a.canvas.scale / start > 1.7, "{}", a.canvas.scale / start);
assert!((2..=3).contains(&rasters) && rasters < moving as u64, "{rasters} rasters over {moving} frames");
// View › Zoom isn't a gesture: the page is rendered at the new size in that frame.
let before = a.canvas.rasters;
a.run("view.zoom", json!({"value": 100.0})).unwrap();
frame(&mut a, Vec::new());
assert_eq!(a.canvas.rasters, before + 1);
// Read Mode: the wheel changes the text size and the pages reflow, so a raster of the old
// text must not stand in for them: they are rendered as they change.
a.run("view.readMode", json!({})).unwrap();
for _ in 0..10 {
frame(&mut a, Vec::new());
}
let over_page = a.canvas.canvas_rect.unwrap().center();
frame(&mut a, vec![egui::Event::PointerMoved(over_page)]);
let (moving, while_moving, _) = ease(&mut a, &mut frame, &[0]);
assert!(moving >= 3, "the text size eases in: {moving} frames");
assert!(while_moving >= 2, "reflowed pages rendered while it moves: {while_moving} over {moving} frames");
}
/// With animation effects off a zoom step is finished in its own frame: Ctrl+wheel zooms the
/// notch's whole step at once, the page is already placed and drawn as it will stay, and the
/// status bar's zoom readout follows in the very next frame. Turns that arrive in small pieces
@@ -1784,6 +1923,7 @@ fn zoom_steps_land_finished_with_animation_effects_off() {
frame(&mut a, vec![ctrl_wheel(1.0)]);
let (scale, pages) = (a.canvas.scale, a.canvas.page_rects.clone());
assert!((scale / before - notch_zoom).abs() < 1e-3, "the whole notch in its frame: {before} -> {scale}");
assert_eq!(a.canvas.pages_hinted, crate::canvas::screen_render_options().hinting, "drawn as it stays: hinted where text is");
for _ in 0..30 {
frame(&mut a, Vec::new());
assert_eq!(a.canvas.scale, scale, "nothing is left to ease in");
@@ -7915,3 +8055,107 @@ fn focus_hides_the_ribbon_and_escape_brings_it_back() {
h.step();
assert!(h.state().session.view.read_mode && shown(&h, "Focus"), "Immersive Reader keeps the status bar");
}
/// Issue #2716: taking documents off the recent list is final — the open document must not be
/// pushed back by the after-command re-add — and the change goes to the settings at once, so
/// it survives the app being killed. Junk params return errors, never panics.
#[test]
fn recent_list_edits_are_final_and_persist() {
let saved = std::rc::Rc::new(std::cell::Cell::new(0u32));
let saved_hook = saved.clone();
let mut a = app();
a.services.save_prefs = Some(Box::new(move |app: &WordApp| {
saved_hook.set(saved_hook.get() + 1);
let _ = serde_json::to_string(&app.prefs()).unwrap();
Ok(true)
}));
a.ui.recent = vec!["/tmp/alpha.docx".into(), "/tmp/beta.docx".into()];
// The open document is on the list, at the back.
a.session.path = Some(std::path::PathBuf::from("/tmp/beta.docx"));
// Removing the open document sticks: `after_command` must not re-add it.
let r = a.run("ui.recentRemove", json!({"path": "/tmp/beta.docx"})).unwrap();
assert_eq!(r["removed"], 1);
assert_eq!(r["recent"], json!(["/tmp/alpha.docx"]));
assert_eq!(r["saved"], true);
assert_eq!(a.ui.recent, ["/tmp/alpha.docx".to_string()], "the open document stays off the list");
assert_eq!(saved.get(), 1, "the change is written out at once");
// Removing an entry that isn't there is an error, not a silent success, and saves nothing.
assert!(a.run("ui.recentRemove", json!({"path": "/tmp/gamma.docx"})).is_err());
assert_eq!(saved.get(), 1, "a rejected command writes nothing");
// Hostile params: missing path, junk types.
for junk in [json!({}), json!({"path": 7}), json!({"path": null}), json!({"path": ["x"]})] {
assert!(a.run("ui.recentRemove", junk).is_err());
}
assert_eq!(a.ui.recent, ["/tmp/alpha.docx".to_string()], "junk params change nothing");
// A normal command re-adds the open document, as before.
a.run("text.insert", json!({"text": "x"})).unwrap();
assert_eq!(a.ui.recent.first(), Some(&"/tmp/beta.docx".to_string()));
// Clearing empties the list (the re-added open document is back, so both entries go) and
// keeps it empty through the next command.
let r = a.run("ui.recentClear", json!({})).unwrap();
assert_eq!(r["removed"], 2);
assert!(a.ui.recent.is_empty());
assert_eq!(saved.get(), 2, "the clear is written out at once");
a.run("text.insert", json!({"text": "y"})).unwrap();
assert_eq!(a.ui.recent.first(), Some(&"/tmp/beta.docx".to_string()), "the open document comes back after clearing");
// Clearing an empty list reports zero removed and is not an error.
a.ui.recent.clear();
assert_eq!(a.run("ui.recentClear", json!({})).unwrap()["removed"], 0);
// The list lives in the prefs, so a restart keeps the removal.
a.ui.recent = vec!["/tmp/alpha.docx".into(), "/tmp/beta.docx".into()];
a.run("ui.recentRemove", json!({"path": "/tmp/alpha.docx"})).unwrap();
let saved_prefs = serde_json::to_string(&a.prefs()).unwrap();
assert!(saved_prefs.contains(r#""recent":["/tmp/beta.docx"]"#), "{saved_prefs}");
let mut b = app();
b.apply_prefs(serde_json::from_str(&saved_prefs).unwrap());
assert_eq!(b.ui.recent, ["/tmp/beta.docx".to_string()]);
}
/// Issue #2716: when the immediate preferences write fails, both recent commands say so (result
/// and status line) instead of reporting plain success; the removal still holds for this run.
/// A host with no hook, or one that wrote nothing, reports `saved: null`.
#[test]
fn recent_list_edits_report_a_failed_preferences_save() {
let mut a = app();
a.services.save_prefs = Some(Box::new(|_: &WordApp| Err::<bool, _>("disk full".to_string())));
a.ui.recent = vec!["/tmp/alpha.docx".into(), "/tmp/beta.docx".into()];
let r = a.run("ui.recentRemove", json!({"path": "/tmp/alpha.docx"})).unwrap();
assert_eq!((&r["saved"], &r["saveError"]), (&json!(false), &json!("disk full")), "{r}");
assert_eq!(r["recent"], json!(["/tmp/beta.docx"]));
assert_eq!(a.ui.recent, ["/tmp/beta.docx".to_string()], "the removal holds for this run");
let status = a.status_msg.as_ref().map(|(m, _)| m.clone()).unwrap_or_default();
assert!(status.contains("disk full") && !status.starts_with("Removed"), "{status}");
let r = a.run("ui.recentClear", json!({})).unwrap();
assert_eq!((&r["saved"], &r["saveError"]), (&json!(false), &json!("disk full")), "{r}");
assert_eq!(r["removed"], 1);
assert!(a.ui.recent.is_empty());
// No hook, or a hook that wrote nothing (preferences switched off): `saved` is null.
for hook in [None, Some(Box::new(|_: &WordApp| Ok(false)) as Box<dyn Fn(&WordApp) -> Result<bool, String>>)] {
a.services.save_prefs = hook;
a.ui.recent = vec!["/tmp/alpha.docx".into()];
let r = a.run("ui.recentClear", json!({})).unwrap();
assert!(r["saved"].is_null() && r.get("saveError").is_none(), "{r}");
assert!(a.status_msg.as_ref().is_some_and(|(m, _)| m.starts_with("Removed")), "{:?}", a.status_msg);
}
}
/// Issue #2716: taking documents off the list needs no open document — the Start screen shows
/// the recent list, and its buttons must work from there.
#[test]
fn recent_list_edits_work_without_a_document() {
let mut a = app();
a.ui.recent = vec!["/tmp/alpha.docx".into()];
assert!(!a.session.dirty && a.session.path.is_none());
assert!(works_without_document("ui.recentRemove") && works_without_document("ui.recentClear"));
assert_eq!(a.run("ui.recentRemove", json!({"path": "/tmp/alpha.docx"})).unwrap()["removed"], 1);
assert_eq!(a.run("ui.recentClear", json!({})).unwrap()["removed"], 0);
}
+56
View File
@@ -850,9 +850,20 @@ pub fn apply_animations(ctx: &egui::Context, on: bool) {
});
}
/// Coverage exponent for light-on-dark interface text on Linux and the BSDs (see [`visuals`]).
const DARK_TEXT_GAMMA: f32 = 0.8;
/// egui's visuals for one of our palettes.
fn visuals(t: &Tokens) -> Visuals {
let mut v = if t.dark { Visuals::dark() } else { Visuals::light() };
// Light text on a dark background, on Linux and the BSDs: egui's dark default thickens every
// glyph edge, about a fifth more ink than FreeType gives it in Firefox and the other apps
// there, so the interface looked semi-bold. Plain coverage (Firefox's weight) left the thin
// light strokes on the darkest strips (the tab row) looking soft; a light boost, about 7 %
// more ink, was chosen side by side on a 145 % desktop.
if t.dark && cfg!(all(unix, not(target_os = "macos"))) {
v.text_options.color_transfer_function = egui::epaint::FontColorTransferFunction::Gamma(DARK_TEXT_GAMMA);
}
v.panel_fill = t.ribbon;
v.window_fill = t.menu;
v.extreme_bg_color = t.input;
@@ -894,6 +905,51 @@ pub fn c32(c: wordcraft_doc::Rgb) -> Color32 {
mod tests {
use std::collections::BTreeSet;
/// Ink of a line of interface text at 1.45x (a 145 % desktop) in `appearance`, drawn in the
/// palette's text colour extremes (black on white, white on black) so the two compare.
#[cfg(all(unix, not(target_os = "macos")))]
fn interface_text_ink(appearance: super::Appearance) -> u64 {
let dark = matches!(appearance, super::Appearance::Dark);
let (fg, bg) = if dark { (egui::Color32::WHITE, egui::Color32::BLACK) } else { (egui::Color32::BLACK, egui::Color32::WHITE) };
let mut h = egui_kittest::Harness::builder().with_size(egui::vec2(560.0, 40.0)).with_pixels_per_point(1.45).wgpu().build_ui_state(
move |ui, set: &mut bool| {
if !*set {
super::apply(ui.ctx(), appearance);
ui.ctx().set_fonts(super::font_definitions(false, false));
*set = true;
}
egui::Frame::new().fill(bg).inner_margin(8.0).show(ui, |ui| {
ui.label(egui::RichText::new("Every Thursday evening the old print shop").font(egui::FontId::proportional(12.5)).color(fg));
});
},
false,
);
h.run();
let img = h.render().unwrap();
// Ink: how far each pixel, laid over the background (the window outside the frame is
// transparent), is from the background.
let back = u64::from(bg.r());
img.pixels()
.map(|p| {
let (v, a) = (u64::from(p.0[0]), u64::from(p.0[3]));
let shown = (v * a + back * (255 - a)) / 255;
shown.abs_diff(back)
})
.sum()
}
#[test]
#[cfg(all(unix, not(target_os = "macos")))]
fn dark_interface_text_is_only_a_little_heavier_than_light_interface_text() {
// egui's dark default added about a fifth more ink than FreeType gives the same text in
// Firefox on Linux (semi-bold); plain coverage, Firefox's weight, looked soft on the dark
// tab row. The light boost chosen side by side adds about 7 %.
let (light, dark) = (interface_text_ink(super::Appearance::Light), interface_text_ink(super::Appearance::Dark));
assert!(light > 0);
let ratio = dark as f64 / light as f64;
assert!((1.03..1.12).contains(&ratio), "light {light}, dark {dark}: {ratio:.3}");
}
/// WCAG contrast ratio between two opaque colours.
pub(super) fn contrast(a: egui::Color32, b: egui::Color32) -> f32 {
let lum = |c: egui::Color32| {
+1 -2
View File
@@ -82,8 +82,7 @@ let apps move windows, so there Arrange All and Side by Side only resize.
| Method | Params | Result |
|---|---|---|
| `engine.execute` | `command`, `params`, `doc?` | the command's result (any id from `engine.commands`, including UI commands `ui.tab`, `ui.dialog` (`{"name": dialog, "part"?: table style part}`; `part` opens New / Modify Table Style (`newTableStyle` / `modifyTableStyle`) on that part: `wholeTable`, `headerRow`, `firstColumn`, `bandedRows`, `nwCell`… as `table.modifyStyle` names them), `ui.backstage`, `ui.zotero.*` (see `docs/zotero.md`), `ui.language` (`{"value": "auto"\|"en"\|"zh-hans"\|"zh-hant"\|"ja"\|"pt-br"\|"es"\|"uk"\|"sr"\|"sr-latn"\|"et"\|"tr"\|"ru"\|"pl"\|"de"\|"it"\|"cs"\|"hu"\|"fr"}`), `ui.theme` (`{"value": "system"\|"light"\|"dark"}`; `system` follows the OS appearance, light when it reports none), `ui.interfaceSize` (`{"value": "auto"}` or `{"percent": 50–300}`, clamped; no value reads it; `auto` keeps the system display scale, a percentage is absolute, so 100 is one screen pixel per point (#822); the result's `percent` is the size drawn at and `auto` whether it follows the system; document zoom stays `view.zoom`), `ui.animations` (`{"value": "system"\|"on"\|"off"}`; no value reads it; `system` follows the system's animation setting, which the desktop app reads on Windows, macOS, Linux and the BSDs and the web app from `prefers-reduced-motion`, and means on where the system doesn't say; the result's `enabled` is what the setting comes to and `system` what the system reports, `null` when it doesn't say), `ui.fileBrowser` (desktop: `{"purpose": "document"\|"picture"\|"recipients"\|"save"}` opens WordCraft's own file browser, for when the system file dialog doesn't show up, #576), `ui.saveAsTemplate` (File › Save As › Save as Word Template: the Save dialog for a `.dotx`, starting in the user templates folder; the result's `dir` is that folder, `null` on the web, #2852), `ui.caretAnimation` (`{"value": true\|false}`; no value reads it; off, the caret jumps and blinks on and off instead of gliding and fading), `ui.startScreen` (`{"value": true\|false}`; no value reads it; on, the default, the desktop and web apps start on File › Home when launched with nothing to open, #766), `ui.displayServer` (`{"value": "auto"\|"wayland"\|"x11"}`; no value reads it; File › Options › Advanced › Linux display server, which the desktop app reads on Linux and the BSDs at its next launch; `WORDCRAFT_WAYLAND` overrides it, #2184), `ui.alignmentGuides` (`{"value": true\|false}`; no value reads it; on, the default, moving a picture or shape snaps it to the page, the margins and other objects, with guide lines while dragging; Alt moves freely), `ui.quickAccessToolbar` (`{"value": true\|false}`; no value toggles it; false takes the Quick Access Toolbar out of the title bar, as its menu's Hide Quick Access Toolbar does, and true brings it back, #1945), `ui.focusRibbon` (`{"value": true\|false}`; no value toggles it; in Focus, true drops the ribbon down over the page, as the bar's ⋯ does, and false puts it away, as a click on the page does; outside Focus it stays put away, #1678), `ui.contextMenu` (opens the page's context menu below the caret, as Shift+F10 does), `ui.paneDock` (`{"pane": "navigation"\|"clipboard"\|"styles"\|"styleInspector"\|"accessibility"\|"altText"\|"formatShape"\|"restrictEditing"\|"comments"\|"smartArtText", "dock"?: "left"\|"right"\|"float", "before"?: pane\|null}`; no `dock` reads it; docks or floats a task pane as its menu does, kept between runs; Styles is `view.stylesPaneDock`, #1756; `before` puts the pane directly before that pane in the order, outside it on their edge, as a drop over a docked pane's outer third does, and `null` after every pane; the order is kept between runs)…) |
| `engine.execute` | `command`, `params`, `doc?` | the command's result (any id from `engine.commands`, including UI commands `ui.tab`, `ui.dialog` (`{"name": dialog, "part"?: table style part}`; `part` opens New / Modify Table Style (`newTableStyle` / `modifyTableStyle`) on that part: `wholeTable`, `headerRow`, `firstColumn`, `bandedRows`, `nwCell`… as `table.modifyStyle` names them), `ui.backstage`, `ui.zotero.*` (see `docs/zotero.md`), `ui.language` (`{"value": "auto"\|"en"\|"zh-hans"\|"zh-hant"\|"ja"\|"pt-br"\|"es"\|"uk"\|"sr"\|"sr-latn"\|"et"\|"tr"\|"ru"\|"pl"\|"de"\|"it"\|"cs"\|"hu"\|"fr"}`), `ui.theme` (`{"value": "system"\|"light"\|"dark"}`; `system` follows the OS appearance, light when it reports none), `ui.interfaceSize` (`{"value": "auto"}` or `{"percent": 50–300}`, clamped; no value reads it; `auto` keeps the system display scale, a percentage is absolute, so 100 is one screen pixel per point (#822); the result's `percent` is the size drawn at and `auto` whether it follows the system; document zoom stays `view.zoom`), `ui.animations` (`{"value": "system"\|"on"\|"off"}`; no value reads it; `system` follows the system's animation setting, which the desktop app reads on Windows, macOS, Linux and the BSDs and the web app from `prefers-reduced-motion`, and means on where the system doesn't say; the result's `enabled` is what the setting comes to and `system` what the system reports, `null` when it doesn't say), `ui.fileBrowser` (desktop: `{"purpose": "document"\|"picture"\|"recipients"\|"save"}` opens WordCraft's own file browser, for when the system file dialog doesn't show up, #576), `ui.saveAsTemplate` (File › Save As › Save as Word Template: the Save dialog for a `.dotx`, starting in the user templates folder; the result's `dir` is that folder, `null` on the web, #2852), `ui.caretAnimation` (`{"value": true\|false}`; no value reads it; off, the caret jumps and blinks on and off instead of gliding and fading), `ui.startScreen` (`{"value": true\|false}`; no value reads it; on, the default, the desktop and web apps start on File › Home when launched with nothing to open, #766), `ui.alignmentGuides` (`{"value": true\|false}`; no value reads it; on, the default, moving a picture or shape snaps it to the page, the margins and other objects, with guide lines while dragging; Alt moves freely), `ui.quickAccessToolbar` (`{"value": true\|false}`; no value toggles it; false takes the Quick Access Toolbar out of the title bar, as its menu's Hide Quick Access Toolbar does, and true brings it back, #1945), `ui.statusCount` (`{"value": "words"\|"characters"\|"charactersNoSpaces"}`; no value reads it; what the status bar's count shows — words (the default), characters with spaces, or characters without spaces — kept between runs, #2797), `ui.focusRibbon` (`{"value": true\|false}`; no value toggles it; in Focus, true drops the ribbon down over the page, as the bar's ⋯ does, and false puts it away, as a click on the page does; outside Focus it stays put away, #1678), `ui.contextMenu` (opens the page's context menu below the caret, as Shift+F10 does), `ui.paneDock` (`{"pane": "navigation"\|"clipboard"\|"styles"\|"styleInspector"\|"accessibility"\|"altText"\|"formatShape"\|"restrictEditing"\|"comments"\|"smartArtText", "dock"?: "left"\|"right"\|"float", "before"?: pane\|null}`; no `dock` reads it; docks or floats a task pane as its menu does, kept between runs; Styles is `view.stylesPaneDock`, #1756; `before` puts the pane directly before that pane in the order, outside it on their edge, as a drop over a docked pane's outer third does, and `null` after every pane; the order is kept between runs)…) |
| `engine.execute` | `command`, `params`, `doc?` | the command's result (any id from `engine.commands`, including UI commands `ui.tab`, `ui.dialog` (`{"name": dialog, "part"?: table style part}`; `part` opens New / Modify Table Style (`newTableStyle` / `modifyTableStyle`) on that part: `wholeTable`, `headerRow`, `firstColumn`, `bandedRows`, `nwCell`… as `table.modifyStyle` names them), `ui.backstage`, `ui.zotero.*` (see `docs/zotero.md`), `ui.language` (`{"value": "auto"\|"en"\|"zh-hans"\|"zh-hant"\|"ja"\|"pt-br"\|"es"\|"uk"\|"sr"\|"sr-latn"\|"et"\|"tr"\|"ru"\|"pl"\|"de"\|"it"\|"cs"\|"hu"\|"fr"}`), `ui.theme` (`{"value": "system"\|"light"\|"dark"}`; `system` follows the OS appearance, light when it reports none), `ui.interfaceSize` (`{"value": "auto"}` or `{"percent": 50–300}`, clamped; no value reads it; `auto` keeps the system display scale, a percentage is absolute, so 100 is one screen pixel per point (#822); the result's `percent` is the size drawn at and `auto` whether it follows the system; document zoom stays `view.zoom`), `ui.animations` (`{"value": "system"\|"on"\|"off"}`; no value reads it; `system` follows the system's animation setting, which the desktop app reads on Windows, macOS, Linux and the BSDs and the web app from `prefers-reduced-motion`, and means on where the system doesn't say; the result's `enabled` is what the setting comes to and `system` what the system reports, `null` when it doesn't say), `ui.fileBrowser` (desktop: `{"purpose": "document"\|"picture"\|"recipients"\|"save"}` opens WordCraft's own file browser, for when the system file dialog doesn't show up, #576), `ui.saveAsTemplate` (File › Save As › Save as Word Template: the Save dialog for a `.dotx`, starting in the user templates folder; the result's `dir` is that folder, `null` on the web, #2852), `ui.caretAnimation` (`{"value": true\|false}`; no value reads it; off, the caret jumps and blinks on and off instead of gliding and fading), `ui.startScreen` (`{"value": true\|false}`; no value reads it; on, the default, the desktop and web apps start on File › Home when launched with nothing to open, #766), `ui.alignmentGuides` (`{"value": true\|false}`; no value reads it; on, the default, moving a picture or shape snaps it to the page, the margins and other objects, with guide lines while dragging; Alt moves freely), `ui.quickAccessToolbar` (`{"value": true\|false}`; no value toggles it; false takes the Quick Access Toolbar out of the title bar, as its menu's Hide Quick Access Toolbar does, and true brings it back, #1945), `ui.displayServer` (`{"value": "auto"\|"wayland"\|"x11"}`; no value reads it; File › Options › Advanced › Linux display server, which the desktop app reads on Linux and the BSDs at its next launch; `WORDCRAFT_WAYLAND` overrides it, #2184), `ui.statusCount` (`{"value": "words"\|"characters"\|"charactersNoSpaces"}`; no value reads it; what the status bar's count shows — words (the default), characters with spaces, or characters without spaces — kept between runs, #2797), `ui.recentRemove` (`{"path": entry}` takes that document off the recent list — `path` must be an entry on the list; on the desktop the new list is saved right away: the result's `saved` is true then, false with `saveError` when the write failed (the removal still holds for this run) and null where the host keeps no preferences (the web app, or preferences switched off), #2716), `ui.recentClear` (`{}` clears the whole list; the result reports `removed`, the new `recent` and `saved` as above), `ui.focusRibbon` (`{"value": true\|false}`; no value toggles it; in Focus, true drops the ribbon down over the page, as the bar's ⋯ does, and false puts it away, as a click on the page does; outside Focus it stays put away, #1678), `ui.contextMenu` (opens the page's context menu below the caret, as Shift+F10 does), `ui.paneDock` (`{"pane": "navigation"\|"clipboard"\|"styles"\|"styleInspector"\|"accessibility"\|"altText"\|"formatShape"\|"restrictEditing"\|"comments"\|"smartArtText", "dock"?: "left"\|"right"\|"float", "before"?: pane\|null}`; no `dock` reads it; docks or floats a task pane as its menu does, kept between runs; Styles is `view.stylesPaneDock`, #1756; `before` puts the pane directly before that pane in the order, outside it on their edge, as a drop over a docked pane's outer third does, and `null` after every pane; the order is kept between runs)…) |
| `engine.commands` | — | every command: id, label, location, shortcut, params, enabled |
| `document.inspect` | `text?`, `doc?` | blocks (text, style, runs, lists, tables), parts, sections, selection, pages |
| `ui.inspect` | — | UI state, view, dialog, window size, page rects on screen, caret, comment balloons (`balloons`: id + screen rect; `balloon`: the selected one), perf; `windows`: the other windows as the drawn window sees them (`available`, `others`, `sideBySide`, `syncScroll`); `document`: the active document's id; `documents`: the open documents (`id`, `title`, `path`, `dirty`, `active`) |
+6 -1
View File
File diff suppressed because one or more lines are too long