Preferences: Display Bitmaps as Anti-aliased Images sets image smoothing in every view

The canvas smoothed placed and embedded bitmaps in every view but Pixel
Preview, with no way to turn that off. File Handling now has Display
Bitmaps as Anti-aliased Images (`smoothBitmaps`), on by default so
nothing changes until it is turned off. Off, images drawn larger than
their pixels show each pixel as a hard-edged square. Display Bitmaps as
Anti-aliased Images in Pixel Preview (`antiAliasedBitmaps`) still
governs Pixel Preview, and an image marked pixelated is never smoothed.

Part of #10712.
This commit is contained in:
dotCooCoo
2026-12-03 10:44:33 -08:00
parent 3055e36ad5
commit ddf48b4d73
8 changed files with 51 additions and 8 deletions
+1
View File
@@ -401,6 +401,7 @@ pub const PREF_SPECS: &[PrefSpec] = &[
p!("recentFilesCount", "File Handling", "Files", "Number of Recent Files to Display", int(0, 30)),
p!("lowResProxyEps", "File Handling", "Files", "Use Low Resolution Proxy for Linked EPS", bool),
p!("pdfImportEmbeddedFonts", "File Handling", "Files", "Use fonts embedded in imported PDFs", bool),
p!("smoothBitmaps", "File Handling", "Files", "Display Bitmaps as Anti-aliased Images", bool),
p!("antiAliasedBitmaps", "File Handling", "Files", "Display Bitmaps as Anti-aliased Images in Pixel Preview", bool),
p!(
"updateLinks",
+6
View File
@@ -304,6 +304,11 @@ pub struct Prefs {
/// fallback font with the missing-font warning (#4568).
pub pdf_import_embedded_fonts: bool,
pub anti_aliased_bitmaps: bool,
/// File Handling › Display Bitmaps as Anti-aliased Images: placed and embedded bitmaps drawn
/// larger than their pixels are smoothed in every view but Pixel Preview (on by default); off,
/// each of their pixels shows as a hard-edged square (#10712). Pixel Preview follows
/// `anti_aliased_bitmaps`.
pub smooth_bitmaps: bool,
pub update_links: String,
/// PDF Text: what the text of a PDF, `.ai` or `.ait` file opened or placed from the app
/// becomes when the open or place does not say (`text`: editable type in the file's fonts;
@@ -694,6 +699,7 @@ impl Default for Prefs {
low_res_proxy_eps: false,
pdf_import_embedded_fonts: true,
anti_aliased_bitmaps: false,
smooth_bitmaps: true,
update_links: s("askWhenModified"),
pdf_text_as: s("text"),
copy_as_svg: true,
+2 -2
View File
@@ -19,7 +19,7 @@ use serde_json::json;
use vectorcraft_geom::{Affine, Point};
use super::BodyKind;
use super::raster::{backdrop, cache_key, frame_options, frame_ppp, frame_view, pixel_region, placed_key, plugin_key, snapped_rect};
use super::raster::{backdrop, cache_key, frame_options, frame_ppp, frame_view, pixel_region, placed_key, plugin_key, smooth_images, snapped_rect};
use crate::doc_windows::Win;
use crate::state::View;
use crate::{CacheKey, VectorcraftApp};
@@ -152,7 +152,7 @@ impl PaneSource {
let ppp = frame_ppp(space.size(), ppp, max_side);
let side = |l: f32| ((l * ppp).round().max(1.0) as u32).min(u32::from(u16::MAX));
let (pw, ph) = (side(space.width()), side(space.height()));
let smooth_images = pixel.is_none() || app.session.prefs.anti_aliased_bitmaps;
let smooth_images = smooth_images(&app.session.prefs, pixel.is_some());
let plugins = plugin_key(&mut app.canvas.plugin_keys, &app.session, st);
let placed = placed_key(&mut app.canvas.placed_keys, &app.session, st);
let mut cache = cache_key(app, ctx, st, env.tokens.tokens(), cv, (pw, ph, ppp), (pixel, smooth_images, plugins, placed));
+9 -3
View File
@@ -325,6 +325,14 @@ pub(super) fn snapped_rect(min: egui::Pos2, size: egui::Vec2, device_ppp: f32) -
egui::Rect::from_min_size(pos2(snap(min.x), snap(min.y)), size)
}
/// Whether a view smooths the bitmaps it draws larger than their pixels. While Pixel Preview draws
/// its own raster (a document pixel larger than a screen pixel) it follows File Handling › Display Bitmaps as Anti-aliased Images in Pixel Preview, and in every
/// other view File Handling › Display Bitmaps as Anti-aliased Images. Off, each image pixel shows as
/// a hard-edged square. An image marked pixelated is never smoothed (the renderer checks it).
pub(super) fn smooth_images(prefs: &vectorcraft_engine::Prefs, pixel_preview: bool) -> bool {
if pixel_preview { prefs.anti_aliased_bitmaps } else { prefs.smooth_bitmaps }
}
/// Pixel Preview: the whole document pixels (x0, y0, x1, y1) under the canvas, rotated view
/// included. None when the view is degenerate, or when a side of the region is more than
/// `max_side` pixels, the largest texture side the display supports.
@@ -365,9 +373,7 @@ pub(super) fn picture(app: &mut VectorcraftApp, ui: &mut Ui, space: &CanvasSpace
// View › Pixel Preview: the art as it rasterizes, one pixel per point, while a document pixel
// is bigger than a screen pixel (below that the screen render already shows it).
let pixel = (app.ui.view.pixel_preview && view.zoom * device_ppp as f64 > 1.0).then(|| pixel_region(&view, max_side)).flatten();
// File Handling › Display Bitmaps as Anti-aliased Images in Pixel Preview: off, images show
// their pixels as they rasterize, hard-edged.
let smooth_images = pixel.is_none() || app.session.prefs.anti_aliased_bitmaps;
let smooth_images = smooth_images(&app.session.prefs, pixel.is_some());
let plugins = plugin_key(&mut app.canvas.plugin_keys, &app.session, st);
let placed = placed_key(&mut app.canvas.placed_keys, &app.session, st);
let key = cache_key(app, ui.ctx(), st, env.tokens.tokens(), &view, (w, h, ppp), (pixel, smooth_images, plugins, placed));
+26
View File
@@ -3169,6 +3169,32 @@ fn pixel_preview_smooths_bitmaps_only_when_asked() {
assert!(smooth(&mut app), "Pixel Preview, on");
}
/// File Handling › Display Bitmaps as Anti-aliased Images (#10712): on by default, the canvas
/// smooths images out of Pixel Preview as it always has; off, it draws them with each pixel taking
/// its nearest image pixel. Pixel Preview keeps following its own preference.
#[test]
fn every_view_smooths_bitmaps_unless_turned_off() {
let mut app = VectorcraftApp::new(Session::new(), Default::default());
app.session.execute("file.new", &json!({"width": 400, "height": 300})).unwrap();
app.canvas.worker_started = true; // render on this thread
let ctx = crate::testing::ui_context();
let smooth = |app: &mut VectorcraftApp| {
let (_, mut delta) = frame_output(app, &ctx);
delta.clear();
app.canvas.key.as_ref().map(|k| k.smooth_images).unwrap()
};
assert!(smooth(&mut app), "on by default");
app.run("prefs.set", json!({"key": "smoothBitmaps", "value": false})).unwrap();
assert!(!smooth(&mut app), "off: nearest sampling in Preview");
app.run("prefs.set", json!({"key": "antiAliasedBitmaps", "value": true})).unwrap();
app.ui.view.pixel_preview = true;
app.view_mut().unwrap().zoom = 8.0;
assert!(smooth(&mut app), "Pixel Preview follows its own preference");
app.ui.view.pixel_preview = false;
app.run("prefs.set", json!({"key": "smoothBitmaps", "value": true})).unwrap();
assert!(smooth(&mut app), "on again");
}
/// Appearance of Black › On Screen (#394): Display All Blacks Accurately (the default) shows
/// pure CMYK black through the CMYK profile, a dark grey; Display All Blacks as Rich Black
/// shows it as RGB black. A rich black shows the same either way.
@@ -343,9 +343,10 @@ pub(crate) const DESCRIPTIONS: &[(&str, &str)] = &[
"When a document opens, a linked EPS image that shows its saved preview keeps it instead of reading the EPS file again; changed files still follow Update Links.",
),
("pdfImportEmbeddedFonts", "Uses a PDF's embedded glyphs for imported text when its font is missing; off, it uses the fallback font."),
("smoothBitmaps", "Outside Pixel Preview, images are drawn smoothed; off, their pixels show with hard edges."),
(
"antiAliasedBitmaps",
"In Pixel Preview, images are drawn smoothed; off, their pixels show with hard edges. Outside Pixel Preview, images are always smoothed.",
"In Pixel Preview, images are drawn smoothed; off, their pixels show with hard edges. Outside Pixel Preview, the setting above applies.",
),
(
"updateLinks",
+3
View File
@@ -10759,6 +10759,9 @@ Printing / Exporting, `accurate` by default) does the same for RGB raster export
Print as Bitmap: `rich` draws pure CMYK black as RGB black in the pixels; CMYK ink exports and the document's
colours stay as they are. `antiAliasedBitmaps` (off by default;
desktop app): in View › Pixel Preview, on softens placed and embedded bitmaps; off, their pixels stay hard-edged.
`smoothBitmaps` (Display Bitmaps as Anti-aliased Images, on by default): the same choice for the canvas in every
view other than Pixel Preview at a zoom where a document pixel is larger than a screen pixel; off, placed and embedded bitmaps drawn larger than their pixels show each pixel as a
hard-edged square. An image marked pixelated is never softened.
`pdfTextAs` (Preferences › File Handling › PDF Text, `text` by default; `text` or `outlines`): what the text of a PDF
opened or placed embedded from the app becomes when the open or place gives no `textAs` (see `document.open`).
`disableAutoAddDelete` (off by default): on, the Pen no longer adds or deletes an anchor when a click lands on a
File diff suppressed because one or more lines are too long