diff --git a/crates/engine/src/cmd/webexport.rs b/crates/engine/src/cmd/webexport.rs index 897cd87c55..498982a7f9 100644 --- a/crates/engine/src/cmd/webexport.rs +++ b/crates/engine/src/cmd/webexport.rs @@ -32,7 +32,7 @@ pub fn specs() -> Vec { "Save for Web", [], None, - "{path?, preset?: a webExport.presets name (its settings, then these keys), format?: gif (default)|jpg|png8|png24, reduction?: perceptual|selective (default)|adaptive|web|blackWhite|gray (gif/png8, as the next five), colors?: 128 (2–256), dither?: none|diffusion (default)|pattern|noise, ditherAmount?: 100, webSnap?: 0 (0–100 %: colours that close to a web-safe one become it), lossy?: 0 (0–100, gif), colorTable?: {locked?: [\"#rrggbb\"…] (kept when reducing), transparent?: [\"#rrggbb\"…] (become transparent), webShift?: [\"#rrggbb\"…] (become web-safe), sort?: none|hue|luminance|popularity, deleted?: [\"#rrggbb\"…] (taken out of the table: their pixels take the nearest color left, and at least one color stays), customPalette?: [\"#rrggbb\"…] (a fixed palette used instead of the reduction's, at most `colors` entries; a new reduction without colorTable clears it and deleted)} (colours as the preview's colors[].source; #rrggbbaa and #rgba are refused here and in matte), transparency?: true (gif/png8/png24), matte?: white (default)|black|none|\"#rrggbb\" (what edges blend into; jpg and opaque png24: the background), interlaced?: false (gif/png8/png24), quality?: 60 (jpg: 0–100), progressive?: false (jpg), optimized?: true (jpg), embedProfile?: false (jpg: sRGB profile), width?: px | height?: px | percent?: 100 (the image size, proportional; width wins over height, height over percent), antiAlias?: none|art (default)|type, clipToArtboard?: true (the artboard; false: the art and the slices), artboard?: 0 (0-based), convertToSrgb?: true (PNG files say they are sRGB), metadata?: none|copyright (default)|contact|all (File Info written as PNG text, a GIF or JPEG comment), slices?: all (default)|selected|none (one image per slice: images/.), output?: images (default)|html (an HTML page placing the image or slices, .html)} → {path, files: [path…], bytes (total), width, height, warnings: [] or [a note that an image couldn't be decoded and is missing from the image]}; no path → {files: [{name, dataBase64}], bytes, width, height, warnings} (names such as page.html, images/page_01.gif). A single image without HTML is written at path itself", + "{path?, preset?: a webExport.presets name (its settings, then these keys), format?: gif (default)|jpg|png8|png24, reduction?: perceptual|selective (default)|adaptive|web|blackWhite|gray (gif/png8, as the next five), colors?: 128 (2–256), dither?: none|diffusion (default)|pattern|noise, ditherAmount?: 100, webSnap?: 0 (0–100 %: colours that close to a web-safe one become it), lossy?: 0 (0–100, gif), colorTable?: {locked?: [\"#rrggbb\"…] (kept when reducing), transparent?: [\"#rrggbb\"…] (become transparent), webShift?: [\"#rrggbb\"…] (become web-safe), sort?: none|hue|luminance|popularity, deleted?: [\"#rrggbb\"…] (taken out of the table: their pixels take the nearest color left, and at least one color stays), customPalette?: [\"#rrggbb\"…] (a fixed palette used instead of the reduction's, at most `colors` entries, its transparent colors taking one slot together; a new reduction without colorTable clears it and deleted), shifted?: {\"#source\": \"#rrggbb\"…} (each source color is written as the color given, wherever it is in the image; kept when reducing as a locked color is, before the locked ones, while one palette slot is left for the reduction; at most 256; a source the table does not hold shifts nothing; a color shifted to itself is removed; a shifted color is not web-shifted, and a transparent one stays transparent; GIF lossy moves no pixel into or out of a shifted color)} (colours as the preview's colors[].source; #rrggbbaa and #rgba are refused here and in matte), transparency?: true (gif/png8/png24), matte?: white (default)|black|none|\"#rrggbb\" (what edges blend into; jpg and opaque png24: the background), interlaced?: false (gif/png8/png24), quality?: 60 (jpg: 0–100), progressive?: false (jpg), optimized?: true (jpg), embedProfile?: false (jpg: sRGB profile), width?: px | height?: px | percent?: 100 (the image size, proportional; width wins over height, height over percent), antiAlias?: none|art (default)|type, clipToArtboard?: true (the artboard; false: the art and the slices), artboard?: 0 (0-based), convertToSrgb?: true (PNG files say they are sRGB), metadata?: none|copyright (default)|contact|all (File Info written as PNG text, a GIF or JPEG comment), slices?: all (default)|selected|none (one image per slice: images/.), output?: images (default)|html (an HTML page placing the image or slices, .html)} → {path, files: [path…], bytes (total), width, height, warnings: [] or [a note that an image couldn't be decoded and is missing from the image]}; no path → {files: [{name, dataBase64}], bytes, width, height, warnings} (names such as page.html, images/page_01.gif). A single image without HTML is written at path itself", has_doc, export ), @@ -41,7 +41,7 @@ pub fn specs() -> Vec { "Save for Web Preview", [], None, - "{…the settings of document.exportForWeb (preset?, format?…), slice?: n (1-based, from slice.list; default the whole image), kbps?: 56.6 (connection speed for the download time), image?: false (also the optimised file as dataBase64)} what Save writes for the whole image (or one slice) → {format, width, height, bytes (exactly the file's size), seconds (to download at kbps), kbps, colors?: [{color: \"#rrggbb\", source: \"#rrggbb\" (the colour the reduction made, as colorTable lists it), transparent, locked, webShifted, webSafe}] (gif/png8: the colour table in file order), mappedToTransparent?: [\"#rrggbb\"…], slices: images an export writes, warnings (as document.exportForWeb's), dataBase64?}", + "{…the settings of document.exportForWeb (preset?, format?…), slice?: n (1-based, from slice.list; default the whole image), kbps?: 56.6 (connection speed for the download time), image?: false (also the optimised file as dataBase64)} what Save writes for the whole image (or one slice) → {format, width, height, bytes (exactly the file's size), seconds (to download at kbps), kbps, colors?: [{color: \"#rrggbb\", source: \"#rrggbb\" (the colour the reduction made, as colorTable lists it), transparent, locked, webShifted, shifted (by colorTable.shifted; also locked), webSafe}] (gif/png8: the colour table in file order), mappedToTransparent?: [\"#rrggbb\"…], slices: images an export writes, warnings (as document.exportForWeb's), dataBase64?}", has_doc, preview ), @@ -331,8 +331,14 @@ pub struct ColorTable { /// A fixed palette (a Custom table) used instead of the reduction's own: the colors of the /// table when the first color was deleted. Empty: the reduction makes the palette. pub custom_palette: Vec, + /// Colors shifted by hand: each source color (`#rrggbb`) and the color it is written as. A + /// shifted color is locked, and a source the table does not hold shifts nothing. + pub shifted: std::collections::BTreeMap, } +/// A color shifted by hand: (source, color written). +type Shift = ([u8; 3], [u8; 3]); + /// The most colours a colour table list holds. const MAX_TABLE: usize = 256; @@ -352,6 +358,21 @@ impl ColorTable { list.iter().map(|h| Self::rgb(h).ok_or_else(|| format!("colorTable.{what}: `{h}` is not a colour such as \"#ff8800\""))).collect() } + /// The colors shifted by hand as (source, color written). An error names a value that is not a + /// color such as `#ff8800`, two keys that name one color, or more than 256 entries. + fn shifts(&self) -> std::result::Result, String> { + // One entry past the limit is enough for `colors` to refuse a longer map. + let (keys, values): (Vec, Vec) = self.shifted.iter().take(MAX_TABLE + 1).map(|(k, v)| (k.clone(), v.clone())).unzip(); + let sources = Self::colors(&keys, "shifted")?; + let to = Self::colors(&values, "shifted")?; + for (i, (s, k)) in sources.iter().zip(&keys).enumerate() { + if sources[..i].contains(s) { + return Err(format!("colorTable.shifted: `{k}` names a color another key names")); + } + } + Ok(sources.into_iter().zip(to).collect()) + } + /// `h` as RGB; `None` when it is not a color such as `#ff8800`. fn rgb(h: &str) -> Option<[u8; 3]> { vectorcraft_color::Color::from_hex(h).filter(|_| !super::hex_with_alpha(h)).map(|c| { @@ -487,13 +508,18 @@ impl WebSettings { { ColorTable::colors(list, what)?; } - // A deleted color is no longer locked, transparent or web-shifted. + // A deleted color is no longer locked, transparent, web-shifted or shifted. let deleted = ColorTable::colors(&table.deleted, "deleted")?; if !deleted.is_empty() { for list in [&mut table.locked, &mut table.transparent, &mut table.web_shift] { list.retain(|h| ColorTable::rgb(h).is_none_or(|c| !deleted.contains(&c))); } } + // Shifts are kept as `#rrggbb` in lowercase; a color shifted to itself is not shifted, and + // a color shifted by hand is not web-shifted. + let shifts: Vec = table.shifts()?.into_iter().filter(|(s, to)| s != to && !deleted.contains(s)).collect(); + table.web_shift.retain(|h| ColorTable::rgb(h).is_none_or(|c| !shifts.iter().any(|(s, _)| *s == c))); + table.shifted = shifts.into_iter().map(|(s, to)| (hex(s), hex(to))).collect(); Ok(self) } @@ -640,6 +666,8 @@ pub struct TableColor { pub transparent: bool, pub locked: bool, pub web_shifted: bool, + /// Shifted by hand (`colorTable.shifted`): written as `color` instead of `source`. + pub shifted: bool, } /// An optimised image file. @@ -759,6 +787,11 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 let locked = ColorTable::colors(&table.locked, "locked")?; let to_clear = ColorTable::colors(&table.transparent, "transparent")?; let shift = ColorTable::colors(&table.web_shift, "webShift")?; + let by_hand = table.shifts()?; + let shifted_to = |src: &[u8; 3]| by_hand.iter().find(|(s, _)| s == src).map(|(_, to)| *to); + // A color shifted by hand is kept when the colors are reduced, as a locked one is, and takes + // one of the slots kept for them before the locked colors do. + let kept: Vec<[u8; 3]> = by_hand.iter().map(|(s, _)| *s).chain(locked.iter().copied()).collect(); let o = PaletteOptions { colors: s.colors, reduction: s.reduction, @@ -767,7 +800,7 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 transparency: s.transparency, matte, }; - let mut ix = reduced(rgba, w, h, s, &o, &locked)?; + let mut ix = reduced(rgba, w, h, s, &o, &kept)?; // Map to transparent works on the colours the reduction made. let before = ix.palette.clone(); let clear = ix.transparent.map(usize::from); @@ -781,11 +814,11 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 *slot = *c; } } - // Web snap, then the colours shifted by hand (locked colours stay as they are). + // Web shift and web snap (locked colors and colors shifted by hand stay as they are). let clear = ix.transparent.map(usize::from); for (i, c) in ix.palette.iter_mut().enumerate() { let src = sources.get(i).copied().unwrap_or(*c); - if Some(i) == clear || locked.contains(&src) { + if Some(i) == clear || shifted_to(&src).is_some() || locked.contains(&src) { continue; } if shift.contains(&src) { @@ -794,8 +827,19 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 *c = snapped; } } + // Lossy compares the pixels with the colors written for them, and moves no pixel into or out of + // a color shifted by hand. if s.format == WebFormat::Gif { - web::lossy(&mut ix, rgba, s.lossy); + let fixed: Vec = sources.iter().enumerate().filter(|(_, c)| shifted_to(c).is_some()).filter_map(|(i, _)| u8::try_from(i).ok()).collect(); + web::lossy(&mut ix, rgba, s.lossy, &fixed); + } + // The colors shifted by hand. + for (i, c) in ix.palette.iter_mut().enumerate() { + if Some(i) != clear + && let Some(to) = sources.get(i).and_then(shifted_to) + { + *c = to; + } } let order = web::sort(&mut ix, table.sort); let sources: Vec<[u8; 3]> = order.iter().map(|&i| sources.get(i).copied().unwrap_or_default()).collect(); @@ -804,12 +848,17 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 .iter() .zip(&sources) .enumerate() - .map(|(i, (c, src))| TableColor { - color: *c, - source: *src, - transparent: ix.transparent == u8::try_from(i).ok(), - locked: locked.contains(src), - web_shifted: shift.contains(src), + .map(|(i, (c, src))| { + let transparent = ix.transparent == u8::try_from(i).ok(); + let shifted = !transparent && shifted_to(src).is_some(); + TableColor { + color: *c, + source: *src, + transparent, + locked: locked.contains(src) || shifted, + web_shifted: shift.contains(src) && !shifted, + shifted, + } }) .collect(); Ok(PaletteImage { ix, colors, mapped }) @@ -818,7 +867,8 @@ fn palette_image(rgba: &[u8], w: u32, h: u32, s: &WebSettings, matte: Option<[u8 /// The pixels reduced to the palette `s` gives: the reduction's own (`locked` kept), or the /// color table's fixed one, without the deleted colors. The pixels of a deleted color take the /// nearest color left, with `o`'s dither. A deletion has to leave a color that is not mapped to -/// transparent. +/// transparent. A fixed palette keeps its colors mapped to transparent, which take one slot of +/// `colors` together, and its first opaque colors that fit in the rest. fn reduced(rgba: &[u8], w: u32, h: u32, s: &WebSettings, o: &PaletteOptions, locked: &[[u8; 3]]) -> std::result::Result { let table = &s.color_table; let deleted = ColorTable::colors(&table.deleted, "deleted")?; @@ -847,11 +897,70 @@ fn reduced(rgba: &[u8], w: u32, h: u32, s: &WebSettings, o: &PaletteOptions, loc left.push(c); } } - left.truncate(usize::from(s.colors.clamp(2, 256)) - usize::from(has_clear)); if left.is_empty() || (removed && !opaque_left(&left)) { return Err(KEEP_ONE.into()); } - Ok(quantize::quantize_to(rgba, w, h, o, &left)) + // The colors mapped to transparent all become the one transparent entry, so together they take + // one slot, and the opaque colors fill the rest in palette order. When no pixel takes one of + // them and no pixel is transparent, that slot goes to the next opaque color instead. + let kept = fixed_palette(&left, &to_clear, s.colors, has_clear, true); + let mut ix = quantize::quantize_to(rgba, w, h, o, &kept); + clear_dropped(&mut ix, rgba, o, &kept, &left, &to_clear); + if !has_clear && !ix.palette.iter().any(|c| to_clear.contains(c)) && left.iter().any(|c| to_clear.contains(c)) { + return Ok(quantize::quantize_to(rgba, w, h, o, &fixed_palette(&left, &to_clear, s.colors, has_clear, false))); + } + Ok(ix) +} + +/// The entries of the fixed palette `left` that fit in `colors`. With `clear`, the colors in +/// `to_clear` are kept and take one slot together; without it they are left out. The list holds +/// at most 256 entries, less one when `has_clear` (the transparent pixels' entry). +fn fixed_palette(left: &[[u8; 3]], to_clear: &[[u8; 3]], colors: u16, has_clear: bool, clear: bool) -> Vec<[u8; 3]> { + let any_clear = clear && left.iter().any(|c| to_clear.contains(c)); + let total = 256 - usize::from(has_clear); + let mut room = (usize::from(colors.clamp(2, 256)) - usize::from(has_clear || any_clear)).min(total - usize::from(any_clear)); + let opaque = left.iter().filter(|c| !to_clear.contains(c)).count().min(room); + let mut clear_room = if clear { total - opaque } else { 0 }; + left.iter() + .copied() + .filter(|c| { + let slots = if to_clear.contains(c) { &mut clear_room } else { &mut room }; + let keep = *slots > 0; + *slots = slots.saturating_sub(1); + keep + }) + .collect() +} + +/// Makes transparent the pixels of `ix` whose nearest color is a color of `left` mapped to +/// transparent (`to_clear`) that does not fit in the fixed palette `kept`. Such a pixel takes the +/// transparent entry, or an entry mapped to transparent, which Map to Transparent clears later. +fn clear_dropped(ix: &mut Indexed, rgba: &[u8], o: &PaletteOptions, kept: &[[u8; 3]], left: &[[u8; 3]], to_clear: &[[u8; 3]]) { + let dropped: Vec<[u8; 3]> = left.iter().filter(|c| to_clear.contains(c) && !kept.contains(c)).copied().collect(); + if dropped.is_empty() { + return; + } + let all: Vec<[u8; 3]> = kept.iter().chain(&dropped).copied().collect(); + let near = quantize::nearest_entries(rgba, o, &all); + if !near.iter().any(|n| n.is_some_and(|n| n >= kept.len())) { + return; + } + let entry = match ix.transparent.or_else(|| ix.palette.iter().position(|c| to_clear.contains(c)).and_then(|i| u8::try_from(i).ok())) { + Some(i) => i, + None => { + // A kept color mapped to transparent that no pixel took; at most 255 entries are used then. + let (Some(c), Ok(i)) = (kept.iter().find(|c| to_clear.contains(c)), u8::try_from(ix.palette.len())) else { + return; + }; + ix.palette.push(*c); + i + } + }; + for (v, n) in ix.indices.iter_mut().zip(&near) { + if n.is_some_and(|n| n >= kept.len()) { + *v = entry; + } + } } /// An optimised image as straight RGBA → `(pixels, width, height)` (the dialog's preview). @@ -1116,7 +1225,7 @@ fn preview(s: &mut Session, p: &Value) -> Result { .map(|c| { json!({ "color": hex(c.color), "source": hex(c.source), "transparent": c.transparent, "locked": c.locked, - "webShifted": c.web_shifted, "webSafe": quantize::web_safe(c.color) == c.color, + "webShifted": c.web_shifted, "shifted": c.shifted, "webSafe": quantize::web_safe(c.color) == c.color, }) }) .collect(); diff --git a/crates/engine/src/tests/webexport.rs b/crates/engine/src/tests/webexport.rs index 21ae0796d3..fe3deecbef 100644 --- a/crates/engine/src/tests/webexport.rs +++ b/crates/engine/src/tests/webexport.rs @@ -539,6 +539,196 @@ fn colour_table_delete_maps_pixels_to_the_nearest_color_left() { assert_eq!(sources(&preview(&mut s, json!({"preset": "No near red"}))), ["#0000ff", "#ff0000"]); } +/// The colors of a fixed palette mapped to transparent take one slot of Colors together with the +/// transparent pixels, so the opaque colors after them still fit: their pixels stay opaque, and the +/// pixels of the colors mapped to transparent become transparent. +#[test] +fn colour_table_fixed_palette_keeps_an_opaque_color() { + // 40×10: red, a near red and blue, and 10 px with nothing (transparent). + let mut s = session(40.0, 10.0); + rect(&mut s, [0.0, 0.0, 10.0, 10.0], "#ff0000"); + rect(&mut s, [10.0, 0.0, 10.0, 10.0], "#ee1100"); + rect(&mut s, [20.0, 0.0, 10.0, 10.0], "#0000ff"); + for table in [ + json!({"customPalette": ["#ff0000", "#ee1100", "#0000ff"], "deleted": ["#ee1100"], "transparent": ["#ff0000"]}), + json!({"customPalette": ["#ff0000", "#0000ff"], "transparent": ["#ff0000"]}), + ] { + let p = json!({"format": "png8", "dither": "none", "colors": 2, "colorTable": table}); + let v = run(&mut s, "document.exportForWeb.preview", p.clone()); + let opaque: Vec<&Value> = v["colors"].as_array().unwrap().iter().filter(|c| c["transparent"] == false).map(|c| &c["source"]).collect(); + assert_eq!((opaque, v["colors"].as_array().unwrap().len()), (vec![&json!("#0000ff")], 2), "{p}"); + let img = pixels(&one(&mut s, p.clone())); + let alpha = |x: u32| img.get_pixel(x, 5).0[3]; + assert_eq!((alpha(5), alpha(15), img.get_pixel(25, 5).0, alpha(35)), (0, 0, [0, 0, 255, 255], 0), "{p}"); + } + // A color mapped to transparent that no pixel takes leaves its slot to an opaque color. + let mut u = session(20.0, 10.0); + rect(&mut u, [0.0, 0.0, 10.0, 10.0], "#0000ff"); + rect(&mut u, [10.0, 0.0, 10.0, 10.0], "#00ff00"); + let p = json!({"format": "png8", "dither": "none", "colors": 2, "colorTable": {"customPalette": ["#0000ff", "#00ff00", "#ff0000"], "transparent": ["#ff0000"]}}); + let img = pixels(&one(&mut u, p)); + assert_eq!((img.get_pixel(5, 5).0, img.get_pixel(15, 5).0), ([0, 0, 255, 255], [0, 255, 0, 255])); + // At 256 colors a color mapped to transparent after 255 opaque ones still keeps an entry. + let full: Vec = + std::iter::once("#0000ff".to_string()).chain((1..255).map(|i| format!("#00{i:02x}00"))).chain(["#ff0000".to_string()]).collect(); + let p = json!({"format": "png8", "dither": "none", "colors": 256, "colorTable": {"customPalette": full, "transparent": ["#ff0000"]}}); + let img = pixels(&one(&mut s, p)); + assert_eq!((img.get_pixel(5, 5).0[3], img.get_pixel(25, 5).0, img.get_pixel(35, 5).0[3]), (0, [0, 0, 255, 255], 0)); + // With one opaque color and 255 mapped to transparent, the last of those does not fit, and its + // pixels still become transparent rather than taking the opaque color nearest them. + let mut d = session(30.0, 10.0); + rect(&mut d, [0.0, 0.0, 10.0, 10.0], "#0000ff"); + rect(&mut d, [10.0, 0.0, 10.0, 10.0], "#0000ee"); + let clear: Vec = (1..255).map(|i| format!("#00{i:02x}00")).chain(["#0000ee".to_string()]).collect(); + let palette: Vec = std::iter::once("#0000ff".to_string()).chain(clear.iter().cloned()).collect(); + let p = json!({"format": "png8", "dither": "none", "colors": 256, "colorTable": {"customPalette": palette, "transparent": clear}}); + let img = pixels(&one(&mut d, p)); + assert_eq!((img.get_pixel(5, 5).0, img.get_pixel(15, 5).0[3], img.get_pixel(25, 5).0[3]), ([0, 0, 255, 255], 0, 0)); + // Without transparent pixels the colors mapped to transparent still take one slot together. + let mut t = session(30.0, 10.0); + rect(&mut t, [0.0, 0.0, 10.0, 10.0], "#ff0000"); + rect(&mut t, [10.0, 0.0, 10.0, 10.0], "#ee1100"); + rect(&mut t, [20.0, 0.0, 10.0, 10.0], "#0000ff"); + let p = json!({"format": "png8", "dither": "none", "colors": 2, "colorTable": { + "customPalette": ["#ff0000", "#ee1100", "#0000ff", "#00ff00"], "transparent": ["#ff0000", "#ee1100"], + }}); + let v = run(&mut t, "document.exportForWeb.preview", p.clone()); + assert_eq!(v["colors"].as_array().unwrap().len(), 2, "{v}"); + let img = pixels(&one(&mut t, p)); + assert_eq!((img.get_pixel(5, 5).0[3], img.get_pixel(15, 5).0[3], img.get_pixel(25, 5).0), (0, 0, [0, 0, 255, 255])); +} + +/// A color shifted by hand (`colorTable.shifted`) is written as the color picked wherever it is in +/// the image, the other colors stay, the table shows it as shifted and locked, and the preview is +/// the file. +#[test] +fn colour_table_shift_writes_the_picked_color_wherever_the_source_is() { + let mut s = session(30.0, 10.0); + rect(&mut s, [0.0, 0.0, 10.0, 10.0], "#ff0000"); + rect(&mut s, [10.0, 0.0, 10.0, 10.0], "#0000ff"); + rect(&mut s, [20.0, 0.0, 10.0, 10.0], "#00ff00"); + let preview = |s: &mut Session, p: Value| run(s, "document.exportForWeb.preview", p); + let entry = |v: &Value, source: &str| v["colors"].as_array().unwrap().iter().find(|c| c["source"] == source).cloned().unwrap_or(Value::Null); + for format in ["gif", "png8"] { + let p = json!({"format": format, "dither": "none", "colorTable": {"shifted": {"#0000FF": "#FF8800"}}}); + let v = preview(&mut s, p.clone()); + let c = entry(&v, "#0000ff"); + assert_eq!( + (c["color"].as_str(), c["shifted"].as_bool(), c["locked"].as_bool(), c["webShifted"].as_bool()), + (Some("#ff8800"), Some(true), Some(true), Some(false)), + "{format}: {v}" + ); + assert_eq!((entry(&v, "#ff0000")["shifted"].as_bool(), entry(&v, "#ff0000")["color"].as_str()), (Some(false), Some("#ff0000"))); + let file = one(&mut s, p); + assert_eq!(v["bytes"].as_u64(), Some(file.len() as u64), "{format}: the preview is the file"); + let img = pixels(&file); + assert_eq!( + (img.get_pixel(5, 5).0, img.get_pixel(12, 2).0, img.get_pixel(18, 8).0, img.get_pixel(25, 5).0), + ([255, 0, 0, 255], [255, 136, 0, 255], [255, 136, 0, 255], [0, 255, 0, 255]), + "{format}" + ); + assert_eq!(distinct(&img), 3, "{format}"); + } + // A shifted color is kept when the colors are reduced, as a locked one is. + let two = preview(&mut s, json!({"colors": 2, "dither": "none", "colorTable": {"shifted": {"#00ff00": "#123456"}}})); + assert_eq!(entry(&two, "#00ff00")["color"], "#123456", "{two}"); + // With one slot to keep, the shifted color takes it before a locked one. + let p = json!({"colors": 2, "dither": "none", "colorTable": {"locked": ["#ff0000"], "shifted": {"#0000ff": "#123456"}}}); + let first = preview(&mut s, p); + assert_eq!(entry(&first, "#0000ff")["color"], "#123456", "{first}"); + // A source the table does not hold shifts nothing, and the shift stays with the settings. + let base = preview(&mut s, json!({"dither": "none"})); + let absent = preview(&mut s, json!({"dither": "none", "colorTable": {"shifted": {"#123456": "#000000"}}})); + assert_eq!(absent["colors"], base["colors"]); + // Two colors may be shifted to one color and keep their own sources. + let same = preview(&mut s, json!({"dither": "none", "colorTable": {"shifted": {"#ff0000": "#123456", "#0000ff": "#123456"}}})); + assert_eq!((entry(&same, "#ff0000")["color"].as_str(), entry(&same, "#0000ff")["color"].as_str()), (Some("#123456"), Some("#123456"))); + assert_eq!(entry(&same, "#00ff00")["shifted"], false); + // A shift by hand wins over web shift, web snap and a lock; transparency wins over it. + let p = + json!({"dither": "none", "webSnap": 100, "colorTable": {"shifted": {"#0000ff": "#fe0101"}, "webShift": ["#0000ff"], "locked": ["#0000ff"]}}); + let c = entry(&preview(&mut s, p), "#0000ff"); + assert_eq!((c["color"].as_str(), c["webShifted"].as_bool(), c["locked"].as_bool()), (Some("#fe0101"), Some(false), Some(true))); + let clear = json!({"dither": "none", "colorTable": {"shifted": {"#0000ff": "#fe0101"}, "transparent": ["#0000ff"]}}); + let v = preview(&mut s, clear.clone()); + assert!(v["colors"].as_array().unwrap().iter().all(|c| c["shifted"] == false), "{v}"); + assert_eq!(pixels(&one(&mut s, clear)).get_pixel(15, 5).0[3], 0); + // The settings keep the shifts in lowercase, drop a color shifted to itself, a deleted one and + // the web shift of a color shifted by hand. + let table = json!({"shifted": {"#0000FF": "#FE0101", "#FF0000": "#ff0000", "#00ff00": "#000000"}, "webShift": ["#0000ff", "#00ff00"], "deleted": ["#00ff00"]}); + let r = run(&mut s, "webExport.settings", json!({ "colorTable": table })); + let t = &r["settings"]["colorTable"]; + assert_eq!((&t["shifted"], &t["webShift"]), (&json!({"#0000ff": "#fe0101"}), &json!([]))); + // Another reduction keeps the shifts; a saved preset keeps them. + let r = run(&mut s, "webExport.settings", json!({"reduction": "adaptive"})); + assert_eq!(r["settings"]["colorTable"]["shifted"], json!({"#0000ff": "#fe0101"})); + run(&mut s, "webExport.presets.save", json!({"name": "Blue to red", "dither": "none", "colorTable": {"shifted": {"#0000ff": "#fe0101"}}})); + assert_eq!(entry(&preview(&mut s, json!({"preset": "Blue to red"})), "#0000ff")["color"], "#fe0101"); + // Bad shifts are refused and change nothing. + let many: serde_json::Map = (0..257).map(|i| (format!("#{i:06x}"), json!("#000000"))).collect(); + for bad in [ + json!({"nope": "#000000"}), + json!({"#ff0000": "nope"}), + json!({"#ff0000": "#ff000080"}), + json!({"#ff000080": "#000000"}), + json!({"#ff0000": "#000000", "#FF0000": "#ffffff"}), + json!({"#f00": "#000000", "#ff0000": "#ffffff"}), + Value::Object(many), + ] { + let p = json!({"colorTable": {"shifted": bad}}); + assert!(s.execute("document.exportForWeb", &p).is_err(), "{p}"); + assert!(s.execute("document.exportForWeb.preview", &p).is_err(), "{p}"); + assert!(s.execute("webExport.settings", &p).is_err(), "{p}"); + } + assert_eq!(run(&mut s, "webExport.settings", json!({}))["settings"]["colorTable"]["shifted"], json!({"#0000ff": "#fe0101"})); + // Settings saved before shifts existed still read. + let old: cmd::webexport::WebSettings = serde_json::from_value(json!({"colorTable": {"locked": ["#ff0000"]}})).unwrap(); + assert!(old.color_table.shifted.is_empty()); +} + +/// Lossy GIF compression leaves the pixels of a color shifted by hand alone, so a color shifted near +/// another one does not take in that color's pixels. +#[test] +fn lossy_does_not_spread_a_shifted_color_into_another() { + let mut s = session(30.0, 10.0); + rect(&mut s, [0.0, 0.0, 10.0, 10.0], "#0000ff"); + rect(&mut s, [10.0, 0.0, 20.0, 10.0], "#c80000"); + let p = json!({"format": "gif", "dither": "none", "lossy": 100, "colorTable": {"shifted": {"#0000ff": "#be0000"}}}); + let img = pixels(&one(&mut s, p)); + assert_eq!((img.get_pixel(5, 5).0, img.get_pixel(20, 5).0, img.get_pixel(29, 5).0), ([190, 0, 0, 255], [200, 0, 0, 255], [200, 0, 0, 255])); +} + +/// Lossy GIF compression moves no pixel into or out of a color shifted by hand: the colors next to +/// a shifted one keep their own pixels, and the shifted color keeps all of its pixels. +#[test] +fn lossy_moves_no_pixel_into_or_out_of_a_shifted_color() { + let mut s = session(30.0, 10.0); + rect(&mut s, [0.0, 0.0, 10.0, 10.0], "#1414e6"); + rect(&mut s, [10.0, 0.0, 20.0, 10.0], "#0000ff"); + rect(&mut s, [20.0, 0.0, 30.0, 10.0], "#1414e6"); + let p = json!({"format": "gif", "dither": "none", "lossy": 100, "colorTable": {"shifted": {"#0000ff": "#ff0000"}}}); + let img = pixels(&one(&mut s, p)); + let near_blue = [20, 20, 230, 255]; + for x in 0..30 { + let want = if (10..20).contains(&x) { [255, 0, 0, 255] } else { near_blue }; + assert_eq!(img.get_pixel(x, 5).0, want, "x = {x}"); + } +} + +/// Lossy GIF compression compares the pixels with the colors web snap writes, so a pixel does not +/// take a color that snaps far from it. +#[test] +fn lossy_compares_pixels_with_the_snapped_colors() { + let mut s = session(20.0, 10.0); + rect(&mut s, [0.0, 0.0, 10.0, 10.0], "#1a1a1a"); + rect(&mut s, [10.0, 0.0, 20.0, 10.0], "#000000"); + let img = pixels(&one(&mut s, json!({"format": "gif", "dither": "none", "webSnap": 100, "lossy": 50}))); + for x in 0..20 { + let want = if x < 10 { [51, 51, 51, 255] } else { [0, 0, 0, 255] }; + assert_eq!(img.get_pixel(x, 5).0, want, "x = {x}"); + } +} + #[test] fn presets_and_remembered_settings() { let mut s = two_colours(); diff --git a/crates/render/src/encode/quantize.rs b/crates/render/src/encode/quantize.rs index dc459d4331..fff66aa142 100644 --- a/crates/render/src/encode/quantize.rs +++ b/crates/render/src/encode/quantize.rs @@ -203,6 +203,21 @@ pub fn quantize_to(rgba: &[u8], width: u32, height: u32, o: &PaletteOptions, pal finish(px, &colors, width, height, &palette, o, o.dither) } +/// For each pixel of `rgba`, the entry of `palette` nearest its color, as [`quantize_to`] measures +/// it (the matte, transparency and `o.reduction`'s distance weights) without dither; `None` for a +/// pixel that becomes transparent, and for every pixel when `palette` is empty. +pub fn nearest_entries(rgba: &[u8], o: &PaletteOptions, palette: &[[u8; 3]]) -> Vec> { + let px = rgba.as_chunks::<4>().0; + let colors = opaque_colors(px, o, false); + let pal: Vec<[f32; 3]> = palette.iter().map(|c| c.map(f32::from)).collect(); + let index = PaletteIndex::new(&pal, o.reduction.weights()); + colors + .iter() + .zip(px) + .map(|(c, p)| if pal.is_empty() || (o.transparency && p[3] < 128) { None } else { Some(index.nearest(c.map(f32::from))) }) + .collect() +} + /// The color of each pixel when opaque: blended over the matte, and gray when `gray`. fn opaque_colors(px: &[[u8; 4]], o: &PaletteOptions, gray: bool) -> Vec<[u8; 3]> { let matte = o.matte.unwrap_or([255; 3]); diff --git a/crates/render/src/encode/tests_web.rs b/crates/render/src/encode/tests_web.rs index 10063a5da4..7eb480a414 100644 --- a/crates/render/src/encode/tests_web.rs +++ b/crates/render/src/encode/tests_web.rs @@ -80,14 +80,19 @@ fn lossy_makes_runs_and_smaller_gifs() { let px = image(96, 64, |x, y| [(x * 2 + y) as u8, (y * 3) as u8, ((x * y) % 255) as u8]); let ix = quantize(&px, 96, 64, &PaletteOptions { colors: 64, dither: Dither::Diffusion, ..Default::default() }); let mut lossy_ix = ix.clone(); - lossy(&mut lossy_ix, &px, 80); + lossy(&mut lossy_ix, &px, 80, &[]); let runs = |ix: &Indexed| ix.indices.windows(2).filter(|w| w[0] != w[1]).count(); assert!(runs(&lossy_ix) < runs(&ix)); let size = |ix: &Indexed| gif::encode(ix, false).unwrap().len(); assert!(size(&lossy_ix) < size(&ix), "{} vs {}", size(&lossy_ix), size(&ix)); let mut none = ix.clone(); - lossy(&mut none, &px, 0); + lossy(&mut none, &px, 0, &[]); assert_eq!(none, ix); + // A fixed entry keeps its pixels and takes no others. + let fixed: Vec = (0..ix.palette.len()).filter_map(|i| u8::try_from(i).ok()).collect(); + let mut kept = ix.clone(); + lossy(&mut kept, &px, 100, &fixed); + assert_eq!(kept, ix); } #[test] diff --git a/crates/render/src/encode/web.rs b/crates/render/src/encode/web.rs index 2a26a336d1..3d572cf9ce 100644 --- a/crates/render/src/encode/web.rs +++ b/crates/render/src/encode/web.rs @@ -83,19 +83,24 @@ pub fn to_transparent(ix: &mut Indexed, mapped: impl Fn(usize) -> bool) -> Vec().0; for (row, src) in ix.indices.chunks_mut(w).zip(px.chunks(w)) { for x in 1..row.len() { let (prev, cur) = (row[x - 1], row[x]); - if prev == cur || ix.transparent.is_some_and(|t| t == prev || t == cur) { + if prev == cur || held[usize::from(prev)] || held[usize::from(cur)] { continue; } let (Some(c), Some(p)) = (src.get(x), ix.palette.get(prev as usize)) else { continue }; diff --git a/crates/ui-egui/src/dialogs.rs b/crates/ui-egui/src/dialogs.rs index b96f5a7af0..da5b93a7bb 100644 --- a/crates/ui-egui/src/dialogs.rs +++ b/crates/ui-egui/src/dialogs.rs @@ -547,8 +547,9 @@ fn hidden_controls(d: &Dialog) -> &'static [&'static str] { } // The selected rows and Randomize's seed. Some(DialogKind::Recolor) => &["__seed", "__sel"], - // The view, zoom, download speed, selected color table entries and the preset name being typed. - Some(DialogKind::SaveForWeb) => &["__color", "__colors", "__kbps", "__presetName", "__view", "__zoom"], + // The view, zoom, download speed, selected color table entries, the color table entry whose + // Color Picker opens and the preset name being typed. + Some(DialogKind::SaveForWeb) => &["__color", "__colors", "__editColor", "__kbps", "__presetName", "__view", "__zoom"], // The link that keeps width and height in proportion. Some(DialogKind::Shape | DialogKind::TransformEach) => &["__constrain"], // The attention filter, the Keys section, the search text and the key being recorded. diff --git a/crates/ui-egui/src/dialogs/save_for_web.rs b/crates/ui-egui/src/dialogs/save_for_web.rs index c412bc2dcb..6ff967f95a 100644 --- a/crates/ui-egui/src/dialogs/save_for_web.rs +++ b/crates/ui-egui/src/dialogs/save_for_web.rs @@ -2,8 +2,9 @@ //! as the web image Save writes, beside the original (Original, Optimized, 2-Up and 4-Up views, //! each with its file size and download time), and the settings: format (GIF, JPEG, PNG-8, //! PNG-24), colour reduction, colours, dither, transparency and matte, interlacing, web snap, -//! lossy, JPEG quality, the colour table (lock, map to transparent, web shift, sort, Delete Color -//! and Restore Generated Table), image size and anti-aliasing, Clip to Artboard, sRGB, metadata, +//! lossy, JPEG quality, the colour table (lock, map to transparent, web shift, sort, Delete Color, +//! Restore Generated Table, a double-click that shifts a color to one picked in the Color Picker, +//! and Unshift All Colors), image size and anti-aliasing, Clip to Artboard, sRGB, metadata, //! slices and HTML output, and presets. //! //! Fields are the `document.exportForWeb` settings (`webExport.settings` gives them; set one with @@ -11,7 +12,8 @@ //! `optimized`, `2up`, `4up`), `__zoom` (`fit` or a percentage), `__kbps` (connection speed), //! `__color` (the colour table's selected colour, by source: the one Lock, Transparent and Web //! Shift edit, and where a Shift-click range starts), `__colors` (every selected color, by source, -//! which Delete Color deletes; when it is empty, `__color` alone), `__presetName` (shown while saving a +//! which Delete Color deletes; when it is empty, `__color` alone), `__editColor` (a source color: +//! the Color Picker opens on it, as a double-click on its swatch opens it), `__presetName` (shown while saving a //! preset) and `__hasSlices`. Optimize to File Size… (`__optimizeOpen: true`) shows `__optimizeK` (the desired size in K), //! `__optimizeStart` (`current`, `auto`) and with slices `__optimizeUse` (`allSlices`, //! `eachSlice`, `currentSlice`); `__optimizeGo: true` runs `webExport.optimizeToFileSize` and @@ -535,6 +537,7 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { { app.status(e); } + take_shift(d); let settings = settings_of(app, d); let mut browser = false; // In a window too narrow for both, the panes are narrower, so the settings beside them and the @@ -565,6 +568,12 @@ fn body(app: &mut VectorcraftApp, ui: &mut egui::Ui, d: &mut Dialog) -> bool { if browser && let Err(e) = app.run("file.saveForWeb.browser", params(d)) { app.status(e); } + // A double-clicked swatch (or an agent's `__editColor`) opens the Color Picker last, over the + // dialog as it now is. + if let Some(source) = d.fields.remove("__editColor").and_then(|v| v.as_str().map(String::from)) { + let start = d.fields.remove("__editStart").and_then(|v| v.as_str().map(String::from)).unwrap_or_else(|| source.clone()); + edit_color(d, &source, &start); + } false } @@ -1088,7 +1097,9 @@ fn matte_row(ui: &mut egui::Ui, d: &mut Dialog) { /// ones with a square, web-safe ones with a diamond, transparent ones over the grid), the buttons /// that edit the selected colour, Delete Color and the table's menu, plus the sort order. A click /// selects one color, a Shift-click the colors from the anchor, and a Ctrl-click -/// (Command-click on macOS) adds or removes one. Returns an error for a deletion that would leave +/// (Command-click on macOS) adds or removes one; a double-click on an opaque color asks for the +/// Color Picker (`__editColor`), and a color shifted by hand shows its source color at the upper +/// left and its new color at the lower right. Returns an error for a deletion that would leave /// no color. fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Result<(), String> { let t = Tokens::get(ui.ctx()); @@ -1117,15 +1128,20 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re .colors .iter() .map(|c| (*c, false)) - .chain(shot.mapped.iter().map(|c| (TableColor { color: *c, source: *c, transparent: true, locked: false, web_shifted: false }, true))) + .chain( + shot.mapped + .iter() + .map(|c| (TableColor { color: *c, source: *c, transparent: true, locked: false, web_shifted: false, shifted: false }, true)), + ) .collect(); const CELL: f32 = 15.0; let per_row = ((SIDE_W - 8.0) / (CELL + 2.0)).floor().max(1.0) as usize; let lines = rows.len().div_ceil(per_row).max(1); - let (area, resp) = ui.allocate_exact_size(egui::vec2(SIDE_W - 8.0, lines as f32 * (CELL + 2.0)), egui::Sense::click()); + let (area, _) = ui.allocate_exact_size(egui::vec2(SIDE_W - 8.0, lines as f32 * (CELL + 2.0)), egui::Sense::hover()); // The colors that can be selected, in table order (for Shift-click ranges). let order: Vec = rows.iter().filter(|(c, mapped)| !c.transparent || *mapped).map(|(c, _)| hex(c.source)).collect(); let mut clicked = None; + let mut edit = None; let p = ui.painter(); for (i, (c, mapped)) in rows.iter().enumerate() { let r = egui::Rect::from_min_size( @@ -1144,6 +1160,15 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re } } else { p.rect_filled(r, 0.0, fill); + if c.shifted { + // Shifted by hand: the source color at the upper left, the new one at the lower right. + let [red, g, b] = c.source; + p.add(egui::Shape::convex_polygon( + vec![r.left_top(), r.right_top(), r.left_bottom()], + egui::Color32::from_rgb(red, g, b), + egui::Stroke::NONE, + )); + } } let mark = if c.color.iter().map(|v| u32::from(*v)).sum::() > 380 { egui::Color32::BLACK } else { egui::Color32::WHITE }; if c.locked { @@ -1161,18 +1186,37 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re let pickable = !c.transparent || *mapped; let ringed = pickable && picked.iter().any(|h| h.eq_ignore_ascii_case(&hex(c.source))); p.rect_stroke(r, 0.0, egui::Stroke::new(if ringed { 2.0 } else { 1.0 }, if ringed { t.accent } else { t.border }), egui::StrokeKind::Outside); - if pickable && resp.clicked() && resp.interact_pointer_pos().is_some_and(|pos| r.contains(pos)) { + if !pickable { + continue; + } + let resp = ui.interact(r, swatch_id(&hex(c.source)), egui::Sense::click()); + if resp.clicked() { clicked = Some(hex(c.source)); } + // A double-click edits an opaque color: the picker opens on the color as shown, or on the + // source color for a color already shifted by hand. + if resp.double_clicked() && !c.transparent { + edit = Some((hex(c.source), hex(if c.shifted { c.source } else { c.color }))); + } } if let Some(c) = clicked { let m = ui.input(|i| i.modifiers); pick(d, &order, &c, m.shift, m.command); } + if let Some((source, start)) = edit { + d.fields.insert("__editColor".into(), json!(source)); + d.fields.insert("__editStart".into(), json!(start)); + } + let shifted = |c: &str| table.shifted.keys().any(|k| k.eq_ignore_ascii_case(c)); + // The colors the table shows, by source: Lock, Transparent, Web Shift and Delete Color act only + // on these. + let palette: Vec = + shot.colors.iter().filter(|c| !c.transparent).map(|c| hex(c.source)).chain(shot.mapped.iter().map(|c| hex(*c))).collect(); + let shown = palette.iter().any(|p| p.eq_ignore_ascii_case(&selected)); ui.add_space(4.0); let on = |list: &[String]| list.iter().any(|h| h.eq_ignore_ascii_case(&selected)); ui.horizontal(|ui| { - ui.add_enabled_ui(!selected.is_empty(), |ui| { + ui.add_enabled_ui(shown, |ui| { for (list, on_label, off_label) in [ ("transparent", tl!("Restore"), tl!("Transparent")), ("webShift", tl!("Unshift"), tl!("Web Shift")), @@ -1183,21 +1227,30 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re "webShift" => &table.web_shift, _ => &table.locked, }; - let is_on = on(current); - if widgets::flat_button(ui, if is_on { on_label } else { off_label }, 88.0).clicked() { + // A color shifted by hand stays locked until it is unshifted. + let fixed = list == "locked" && shifted(&selected); + let is_on = on(current) || fixed; + let label = if is_on { on_label } else { off_label }; + if ui.add_enabled(!fixed, |ui: &mut egui::Ui| widgets::flat_button(ui, label, 88.0)).clicked() { toggle(d, list, &selected, !is_on); + // Web Shift replaces a shift by hand. + if list == "webShift" && !is_on { + unshift(d, &selected); + } } } }); }); - // Delete Color (the button and the table's menu) and Restore Generated Table. - let (mut delete, mut restore) = (false, false); + // Delete Color (the button and the table's menu) and Restore Generated Table. Delete Color + // takes only selected colors the table shows (`palette`, by source). + let deletable = !selected_in(d, &palette).is_empty(); + let (mut delete, mut restore, mut unshift_all) = (false, false, false); ui.horizontal(|ui| { - delete |= widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Color"), false, !picked.is_empty(), 24.0).clicked(); + delete |= widgets::icon_button_enabled(ui, "trash-2", tl!("Delete Color"), false, deletable, 24.0).clicked(); let menu = widgets::icon_button(ui, "menu", tl!("Color Table"), false, 24.0); let open = menu.clicked(); let _ = widgets::popover(&menu, open, |ui| { - if widgets::menu_item(ui, tl!("Delete Color"), !picked.is_empty(), false) { + if widgets::menu_item(ui, tl!("Delete Color"), deletable, false) { delete = true; ui.close(); } @@ -1205,6 +1258,10 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re restore = true; ui.close(); } + if widgets::menu_item(ui, tl!("Unshift All Colors"), !table.shifted.is_empty() || !table.web_shift.is_empty(), false) { + unshift_all = true; + ui.close(); + } }); }); let sort = table.sort; @@ -1219,14 +1276,20 @@ fn color_table(ui: &mut egui::Ui, d: &mut Dialog, s: Option<&WebSettings>) -> Re if restore { restore_table(d); } + if unshift_all { + unshift_all_colors(d); + } if delete { - let palette: Vec = - shot.colors.iter().filter(|c| !c.transparent).map(|c| hex(c.source)).chain(shot.mapped.iter().map(|c| hex(*c))).collect(); delete_colors(d, &palette)?; } Ok(()) } +/// The selected colors (by source) that `palette`, the colors the table shows, holds. +pub(super) fn selected_in(d: &Dialog, palette: &[String]) -> Vec { + selection(d).into_iter().filter(|c| palette.iter().any(|p| p.eq_ignore_ascii_case(c))).collect() +} + /// The colour table's selected colors, by source: `__colors`, else `__color`. pub(super) fn selection(d: &Dialog) -> Vec { let many: Vec = @@ -1276,11 +1339,14 @@ pub(super) fn pick(d: &mut Dialog, order: &[String], color: &str, shift: bool, c /// Delete Color: the selected colors join the color table's `deleted` list and leave its other /// lists. The first deletion fixes the palette (`customPalette`) to `palette`, the table's colors /// (by source) with the deleted ones, so the colors left do not change. A deletion that leaves no -/// color, or only colors mapped to transparent, is refused with nothing changed. The selection is -/// cleared. +/// color, or only colors mapped to transparent, is refused with nothing changed. Only selected +/// colors that `palette` holds are deleted; when it holds none of them, the table is left as it is +/// and the selection is cleared. The selection is cleared after a deletion too. pub(super) fn delete_colors(d: &mut Dialog, palette: &[String]) -> Result<(), String> { - let picked = selection(d); + let picked = selected_in(d, palette); if picked.is_empty() { + d.fields.remove("__colors"); + d.fields.remove("__color"); return Ok(()); } let list = |d: &Dialog, key: &str| -> Vec { @@ -1316,6 +1382,9 @@ pub(super) fn delete_colors(d: &mut Dialog, palette: &[String]) -> Result<(), St } } } + for c in &picked { + unshift(d, c); + } set_table(d, "customPalette", json!(custom)); set_table(d, "deleted", json!(deleted)); d.fields.remove("__colors"); @@ -1330,6 +1399,71 @@ pub(super) fn restore_table(d: &mut Dialog) { set_table(d, "customPalette", json!([])); } +/// The id of the color table's swatch for the source color `source` (`#rrggbb`). +pub(super) fn swatch_id(source: &str) -> egui::Id { + egui::Id::unique(("sfw-swatch", source.to_ascii_lowercase())) +} + +/// The field of the Color Picker's OK over Save for Web: the color the edited swatch shifts to. +const SHIFT_TO: &str = "__shiftTo"; + +/// The Color Picker over the dialog for the color table's source color `source`, on `start`; its +/// OK shifts the color ([`shift_color`]) and its Cancel leaves the table as it was. Nothing opens +/// when either is not a color. +pub(super) fn edit_color(d: &mut Dialog, source: &str, start: &str) { + let (Some(_), Some(c)) = (vectorcraft_color::Color::from_hex(source), vectorcraft_color::Color::from_hex(start)) else { return }; + d.fields.insert("__shiftSource".into(), json!(source)); + *d = super::color_picker::over_effect(d, SHIFT_TO, c); +} + +/// Back from the Color Picker: its OK's color shifts the color it was opened for. +fn take_shift(d: &mut Dialog) { + let source = d.fields.remove("__shiftSource"); + if let (Some(to), Some(source)) = (d.fields.remove(SHIFT_TO), source) + && let (Some(to), Some(source)) = (to.as_str(), source.as_str()) + { + shift_color(d, source, to); + } +} + +/// Shift the source color `source` to `to` (`colorTable.shifted`), wherever it is in the image; it +/// is no longer web-shifted. Picking the source color itself takes the shift away. The color +/// becomes the selection. Nothing changes when either is not a color. +pub(super) fn shift_color(d: &mut Dialog, source: &str, to: &str) { + let hex = |h: &str| vectorcraft_color::Color::from_hex(h).map(|c| c.to_hex()); + let (Some(source), Some(to)) = (hex(source), hex(to)) else { return }; + unshift(d, &source); + if to != source { + let mut map = shifts(d); + map.insert(source.clone(), json!(to)); + set_table(d, "shifted", Value::Object(map)); + } + toggle(d, "webShift", &source, false); + d.fields.insert("__colors".into(), json!([source])); + d.fields.insert("__color".into(), json!(source)); +} + +/// The `colorTable.shifted` field. +fn shifts(d: &Dialog) -> Map { + d.fields.get("colorTable").and_then(|t| t.get("shifted")).and_then(Value::as_object).cloned().unwrap_or_default() +} + +/// Take the shift by hand of the source color `source` away. +pub(super) fn unshift(d: &mut Dialog, source: &str) { + let mut map = shifts(d); + let before = map.len(); + map.retain(|k, _| !k.eq_ignore_ascii_case(source)); + if map.len() != before { + set_table(d, "shifted", Value::Object(map)); + } +} + +/// Unshift All Colors: no color is shifted by hand or web-shifted. +pub(super) fn unshift_all_colors(d: &mut Dialog) { + set_table(d, "shifted", json!({})); + set_table(d, "webShift", json!([])); +} + /// Add `color` to the colour table's `list`, or take it out. pub(super) fn toggle(d: &mut Dialog, list: &str, color: &str, add: bool) { let mut v: Vec = d.fields.get("colorTable").and_then(|t| t.get(list)).and_then(Value::as_array).cloned().unwrap_or_default(); diff --git a/crates/ui-egui/src/dialogs/tests_save_for_web.rs b/crates/ui-egui/src/dialogs/tests_save_for_web.rs index e27f4b766c..a965977b14 100644 --- a/crates/ui-egui/src/dialogs/tests_save_for_web.rs +++ b/crates/ui-egui/src/dialogs/tests_save_for_web.rs @@ -783,6 +783,177 @@ fn colour_table_selection_and_delete_color() { assert_eq!((&d.fields["colorTable"]["deleted"], &d.fields["colorTable"]["customPalette"]), (&json!([]), &json!([]))); } +/// Delete Color takes only selected colors the table shows: a selection the table no longer holds +/// (after a change of reduction or color count, or set through `ui.dialog.set`) deletes nothing, +/// fixes no palette and is cleared, and a selection partly in the table deletes only what it shows. +#[test] +fn delete_color_skips_selected_colors_the_table_does_not_show() { + let mut d = Dialog::new(save_for_web::KIND, json!({})); + let shown: Vec = ["#000000", "#111111"].map(String::from).to_vec(); + let table = |d: &Dialog, key: &str| d.fields.get("colorTable").and_then(|t| t.get(key)).cloned(); + d.fields.insert("__colors".into(), json!(["#ABCDEF"])); + d.fields.insert("__color".into(), json!("#abcdef")); + assert!(save_for_web::selected_in(&d, &shown).is_empty()); + save_for_web::delete_colors(&mut d, &shown).unwrap(); + assert_eq!((table(&d, "customPalette"), table(&d, "deleted")), (None, None)); + assert!(!d.fields.contains_key("__colors") && !d.fields.contains_key("__color")); + d.fields.insert("__colors".into(), json!(["#abcdef", "#111111"])); + assert_eq!(save_for_web::selected_in(&d, &shown), ["#111111"]); + save_for_web::delete_colors(&mut d, &shown).unwrap(); + assert_eq!((table(&d, "customPalette"), table(&d, "deleted")), (Some(json!(shown)), Some(json!(["#111111"])))); +} + +/// A shift by hand replaces a web shift and selects the color; a shift to the color itself takes it +/// away; Unshift All Colors clears both kinds; Delete Color takes a deleted color's shift away. +#[test] +fn colour_table_shift_unshift_and_unshift_all() { + let mut d = Dialog::new(save_for_web::KIND, json!({})); + save_for_web::toggle(&mut d, "webShift", "#123456", true); + save_for_web::shift_color(&mut d, "#123456", "#FF8800"); + assert_eq!(d.fields["colorTable"], json!({"webShift": [], "shifted": {"#123456": "#ff8800"}})); + assert_eq!(save_for_web::selection(&d), ["#123456"]); + // Not a color: nothing changes. + let before = d.fields.clone(); + save_for_web::shift_color(&mut d, "nope", "#000000"); + save_for_web::shift_color(&mut d, "#123456", "nope"); + assert_eq!(d.fields, before); + save_for_web::shift_color(&mut d, "#ABCDEF", "#00ff00"); + save_for_web::shift_color(&mut d, "#123456", "#123456"); + assert_eq!(d.fields["colorTable"]["shifted"], json!({"#abcdef": "#00ff00"})); + save_for_web::toggle(&mut d, "webShift", "#222222", true); + save_for_web::unshift_all_colors(&mut d); + assert_eq!((&d.fields["colorTable"]["shifted"], &d.fields["colorTable"]["webShift"]), (&json!({}), &json!([]))); + let order: Vec = ["#000000", "#222222"].map(String::from).to_vec(); + save_for_web::shift_color(&mut d, "#222222", "#ffffff"); + save_for_web::delete_colors(&mut d, &order).unwrap(); + assert_eq!((&d.fields["colorTable"]["shifted"], &d.fields["colorTable"]["deleted"]), (&json!({}), &json!(["#222222"]))); +} + +/// One frame of `app` in `ctx`, 50 ms after the last. +fn tick(app: &mut VectorcraftApp, ctx: &egui::Context, events: Vec) { + let time = ctx.input(|i| i.time) + 0.05; + let screen_rect = Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1400.0, 1000.0))); + let mut out = ctx.run_ui(egui::RawInput { screen_rect, events, time: Some(time), ..Default::default() }, |ui| show(app, ui.ctx())); + out.textures_delta.clear(); +} + +/// Double-click the color table's swatch of the source color `source`. +fn double_click_swatch(app: &mut VectorcraftApp, ctx: &egui::Context, source: &str) { + for _ in 0..3 { + tick(app, ctx, vec![]); + } + let pos = ctx.read_response(save_for_web::swatch_id(source)).unwrap_or_else(|| panic!("no swatch for {source}")).rect.center(); + let button = |pressed| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers: egui::Modifiers::NONE }; + tick(app, ctx, vec![egui::Event::PointerMoved(pos), button(true)]); + tick(app, ctx, vec![button(false)]); + tick(app, ctx, vec![button(true)]); + tick(app, ctx, vec![button(false)]); + tick(app, ctx, vec![]); +} + +/// The color the open Color Picker shows. +fn picker_color(app: &VectorcraftApp) -> Option { + let d = app.ui.dialog.as_ref()?; + assert_eq!(d.kind, "colorPicker", "the Color Picker is open"); + d.fields.get("color").and_then(vectorcraft_engine::cmd::color_value).map(|c| c.to_hex()) +} + +/// A double-click on a swatch opens the Color Picker on its color. Cancel changes nothing; OK +/// shifts the color in the table and the saved file. A double-click on a shifted swatch opens the +/// picker on the source color, and Web Shift replaces the shift by hand. +#[test] +fn double_clicking_a_swatch_shifts_its_color() { + let dir = vectorcraft_testkit::temp_dir("sfw-shift-color"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + for (k, v) in [("format", json!("gif")), ("antiAlias", json!("none")), ("dither", json!("none"))] { + set(&mut app, k, v); + } + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let shifted = |app: &VectorcraftApp| app.ui.dialog.as_ref().map(|d| d.fields["colorTable"]["shifted"].clone()); + double_click_swatch(&mut app, &ctx, "#0000ff"); + assert_eq!(picker_color(&app).as_deref(), Some("#0000ff")); + crate::dialogs::cancel(&mut app); + tick(&mut app, &ctx, vec![]); + assert_eq!((kind(&app), shifted(&app)), (Some(save_for_web::KIND), Some(json!({}))), "Cancel shifts nothing"); + double_click_swatch(&mut app, &ctx, "#0000ff"); + set(&mut app, "color", json!("#00ff00")); + confirm(&mut app).unwrap(); + tick(&mut app, &ctx, vec![]); + assert_eq!((kind(&app), shifted(&app)), (Some(save_for_web::KIND), Some(json!({"#0000ff": "#00ff00"}))), "OK shifts the color"); + // The shifted swatch opens on its source color. + double_click_swatch(&mut app, &ctx, "#0000ff"); + assert_eq!(picker_color(&app).as_deref(), Some("#0000ff")); + crate::dialogs::cancel(&mut app); + // Web Shift replaces the shift by hand. + click_text(&mut app, "Web Shift"); + let t = app.ui.dialog.as_ref().unwrap().fields["colorTable"].clone(); + assert_eq!((&t["shifted"], &t["webShift"]), (&json!({}), &json!(["#0000ff"]))); + // Shifted again, the color reaches the saved file and is remembered. + double_click_swatch(&mut app, &ctx, "#0000ff"); + set(&mut app, "color", json!("#00ff00")); + confirm(&mut app).unwrap(); + tick(&mut app, &ctx, vec![]); + let r = confirm(&mut app).unwrap(); + let image = image::open(r["path"].as_str().unwrap()).unwrap().to_rgba8(); + assert_eq!((image.get_pixel(50, 20).0, image.get_pixel(20, 14).0), ([0, 255, 0, 255], [204, 51, 0, 255])); + let remembered = app.session.last_web_settings().color_table; + assert_eq!((remembered.shifted.get("#0000ff").map(String::as_str), remembered.web_shift.len()), (Some("#00ff00"), 0)); +} + +/// `ui.dialog.set` accepts `__editColor`, and the next frame opens the Color Picker on that color, +/// whose OK shifts it. +#[test] +fn dialog_set_edit_color_opens_the_color_picker() { + let dir = vectorcraft_testkit::temp_dir("sfw-edit-color-set"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + set(&mut app, "format", json!("gif")); + let ctx = egui::Context::default(); + crate::theme::install_fonts(&ctx); + let (req, _) = crate::control::ControlRequest::new("ui.dialog.set", json!({"field": "__editColor", "value": "#0000ff"})); + let crate::control::Outcome::Done(r) = crate::control::handle(&mut app, &ctx, &req) else { panic!("not done") }; + assert_eq!(r["ok"], true, "{r}"); + tick(&mut app, &ctx, vec![]); + assert_eq!(picker_color(&app).as_deref(), Some("#0000ff")); + set(&mut app, "color", json!("#00ff00")); + confirm(&mut app).unwrap(); + tick(&mut app, &ctx, vec![]); + let shifted = app.ui.dialog.as_ref().map(|d| d.fields["colorTable"]["shifted"].clone()); + assert_eq!((kind(&app), shifted), (Some(save_for_web::KIND), Some(json!({"#0000ff": "#00ff00"})))); +} + +/// Lock, Transparent and Web Shift are off while the selected color (`__color`) is one the table +/// no longer shows, so a click adds it to no list; with a color the table shows, Lock locks it. +#[test] +fn table_buttons_skip_a_selected_color_the_table_does_not_show() { + let dir = vectorcraft_testkit::temp_dir("sfw-stale-anchor"); + let (mut app, _) = app(&dir, false); + app.run("shape.rectangle", json!({"x": 40, "y": 0, "width": 20, "height": 40})).unwrap(); + app.run("paint.setFill", json!({"color": "#0000ff"})).unwrap(); + app.run("file.saveForWeb", json!({})).unwrap(); + for (k, v) in [("format", json!("gif")), ("antiAlias", json!("none")), ("dither", json!("none"))] { + set(&mut app, k, v); + } + let table = |app: &VectorcraftApp| app.ui.dialog.as_ref().and_then(|d| d.fields.get("colorTable").cloned()).unwrap_or_default(); + let has = |app: &VectorcraftApp, list: &str, c: &str| table(app)[list].as_array().is_some_and(|l| l.iter().any(|v| v == c)); + set(&mut app, "__color", json!("#abcdef")); + for label in ["Lock", "Transparent", "Web Shift"] { + click_text(&mut app, label); + } + for list in ["locked", "transparent", "webShift"] { + assert!(!has(&app, list, "#abcdef"), "{list}: {}", table(&app)); + } + set(&mut app, "__color", json!("#0000ff")); + click_text(&mut app, "Lock"); + assert!(has(&app, "locked", "#0000ff"), "{}", table(&app)); +} + /// Click the dialog's text `label` with the pointer (frames a quarter second apart). fn click_text(app: &mut VectorcraftApp, label: &str) { let ctx = egui::Context::default(); diff --git a/crates/ui-egui/src/i18n/bg.tsv b/crates/ui-egui/src/i18n/bg.tsv index 10eafe36cb..74ebdf956d 100644 --- a/crates/ui-egui/src/i18n/bg.tsv +++ b/crates/ui-egui/src/i18n/bg.tsv @@ -793,6 +793,7 @@ font-technology Variable Променливи Delete Brush Изтриване на четка Delete Color Изтриване на цвят Restore Generated Table Възстановяване на генерираната таблица + Unshift All Colors Преместване назад на всички цветове Delete Character Style Изтриване на стил за знаци Delete Empty Artboards Изтриване на празни работни области Delete Freeform Point Изтриване на свободна точка @@ -4683,6 +4684,7 @@ axis Both И двете @msg choose a location for the package изберете местоположение за пакета @msg clipboard is empty клипбордът е празен @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: поне един цвят трябва да остане в цветовата таблица +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` назовава цвят, който друг ключ също назовава @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` не е цвят като "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: най-много {MAX_TABLE} цвята @msg command `{0}` is not available right now: {1} команда `{0}` не е налична в момента: {1} diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index da1196a6e3..26043b3b50 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -3488,6 +3488,7 @@ theme Appearance Izgled Delete Brush Izbriši četkicu Delete Color Izbriši boju Restore Generated Table Vrati generisanu tabelu + Unshift All Colors Poništi pomak svih boja Delete Symbol Izbriši simbol Delete the selected symbol? Izbrisati odabrani simbol? Delete the selected symbols? Izbrisati odabrane simbole? @@ -5091,6 +5092,7 @@ imageTrace Outline Obris @msg choose a location for the package odaberite lokaciju za paket @msg clipboard is empty međuspremnik je prazan @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: barem jedna boja mora ostati u tabeli boja +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` imenuje boju koju imenuje i drugi ključ @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` nije boja poput "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: najviše {MAX_TABLE} boja @msg command `{0}` is not available right now: {1} naredba `{0}` trenutno nije dostupna: {1} diff --git a/crates/ui-egui/src/i18n/ca.tsv b/crates/ui-egui/src/i18n/ca.tsv index eef5ef3344..cc55fc4bbd 100644 --- a/crates/ui-egui/src/i18n/ca.tsv +++ b/crates/ui-egui/src/i18n/ca.tsv @@ -1156,6 +1156,7 @@ antiAlias Sharp Nítid Delete Brush Suprimeix el pinzell Delete Color Suprimeix el color Restore Generated Table Restaura la taula generada + Unshift All Colors Desfés el desplaçament de tots els colors Delete Character Style Suprimeix l’estil de caràcter Delete Data Set Suprimeix el conjunt de dades Delete Data Sets Suprimeix els conjunts de dades @@ -5865,6 +5866,7 @@ digits Malayalam Malaiàlam @msg clipboard is empty el porta-retalls és buit @msg closing needs three anchors el tancament necessita tres punts d’ancoratge @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: almenys un color ha de quedar a la taula de colors +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` indica un color que també indica una altra clau @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` no és un color com "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: com a màxim {MAX_TABLE} colors @msg column docks a set as a dock column, with no anchor or icon column acobla un conjunt com a columna d’acoblament, sense àncora ni icona diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index c336b5ef18..df557f4800 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -3588,6 +3588,7 @@ theme Appearance Motiv Delete Brush Odstranit štětec Delete Color Odstranit barvu Restore Generated Table Obnovit vygenerovanou tabulku + Unshift All Colors Zrušit posun všech barev Delete Symbol Odstranit symbol Delete the selected symbol? Odstranit vybraný symbol? Delete the selected symbols? Odstranit vybrané symboly? @@ -5386,6 +5387,7 @@ liquify-list-end {0}, {1} {0} a {1} @msg choose a location for the package zvolte umístění balíčku @msg clipboard is empty schránka je prázdná @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: v tabulce barev musí zůstat alespoň jedna barva +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` označuje barvu, kterou označuje i jiný klíč @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` není barva jako "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: nejvýše {MAX_TABLE} barev @msg command `{0}` is not available right now: {1} příkaz `{0}` nyní není k dispozici: {1} diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index 20bc20156e..ea04982046 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -6044,6 +6044,7 @@ theme Appearance Udseende Delete Brush Slet pensel Delete Color Slet farve Restore Generated Table Gendan genereret tabel + Unshift All Colors Fjern skift af alle farver Delete Symbol Slet symbol Delete the selected symbol? Vil du slette det markerede symbol? Delete the selected symbols? Vil du slette de markerede symboler? @@ -7580,6 +7581,7 @@ imageTrace Outline Kontur @msg choose a location for the package vælg en placering til pakken @msg clipboard is empty udklipsholderen er tom @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: mindst én farve skal blive i farvetabellen +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` angiver en farve, som en anden nøgle også angiver @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` er ikke en farve som "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: højst {MAX_TABLE} farver @msg command `{0}` is not available right now: {1} kommandoen `{0}` er ikke tilgængelig lige nu: {1} diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 1abde3d052..c1622570f2 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -800,6 +800,7 @@ font-technology Variable Variabel Delete Brush Pinsel löschen Delete Color Farbe löschen Restore Generated Table Generierte Tabelle wiederherstellen + Unshift All Colors Verschiebung aller Farben aufheben Delete Character Style Zeichenformat löschen Delete Empty Artboards Leere Zeichenflächen löschen Delete Freeform Point Freiformpunkt löschen @@ -4981,6 +4982,7 @@ liquify-list-end {0}, {1} {0} und {1} @msg choose a location for the package wählen Sie einen Speicherort für das Paket @msg clipboard is empty die Zwischenablage ist leer @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: Mindestens eine Farbe muss in der Farbtabelle bleiben +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` bezeichnet eine Farbe, die auch ein anderer Schlüssel bezeichnet @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` ist keine Farbe wie "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: höchstens {MAX_TABLE} Farben @msg command `{0}` is not available right now: {1} der Befehl `{0}` ist derzeit nicht verfügbar: {1} diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index ca1a95f158..1cee65998f 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -778,6 +778,7 @@ font-technology Variable Μεταβλητές Delete Brush Διαγραφή πινέλου Delete Color Διαγραφή χρώματος Restore Generated Table Επαναφορά του παραγόμενου πίνακα + Unshift All Colors Αναίρεση μετατόπισης όλων των χρωμάτων Delete Character Style Διαγραφή στυλ χαρακτήρων Delete Empty Artboards Διαγραφή κενών πινάκων σχεδίασης Delete Freeform Point Διαγραφή ελεύθερου σημείου @@ -5043,6 +5044,7 @@ digits Malayalam Μαλαγιάλαμ @msg choose a location for the package επιλέξτε τοποθεσία συσκευασίας @msg clipboard is empty το πρόχειρο είναι κενό @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: τουλάχιστον ένα χρώμα πρέπει να παραμείνει στον πίνακα χρωμάτων +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: το `{k}` ορίζει ένα χρώμα που ορίζει και άλλο κλειδί @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: το `{h}` δεν είναι έγκυρο χρώμα, όπως το "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: επιτρέπονται το πολύ {MAX_TABLE} χρώματα @msg command `{0}` is not available right now: {1} η εντολή `{0}` δεν είναι διαθέσιμη αυτήν τη στιγμή: {1} diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 34e40d457c..69b743eae6 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -819,6 +819,7 @@ font-technology Variable Variables Delete Brush Eliminar pincel Delete Color Eliminar color Restore Generated Table Restaurar tabla generada + Unshift All Colors Deshacer cambio de todos los colores Delete Character Style Eliminar estilo de carácter Delete Empty Artboards Eliminar mesas de trabajo vacías Delete Freeform Point Eliminar punto libre @@ -5093,6 +5094,7 @@ liquify-list-end {0}, {1} {0}, {1} @msg choose a location for the package elige una ubicación para el paquete @msg clipboard is empty el portapapeles está vacío @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: al menos un color debe quedar en la tabla de colores +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` indica un color que también indica otra clave @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` no es un color como "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: como máximo {MAX_TABLE} colores @msg command `{0}` is not available right now: {1} el comando `{0}` no está disponible ahora: {1} diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index eb5f98ad4b..6a23e44159 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -3530,6 +3530,7 @@ theme Appearance Ulkoasu Delete Brush Poista sivellin Delete Color Poista väri Restore Generated Table Palauta luotu taulukko + Unshift All Colors Peru kaikkien värien siirto Delete Symbol Poista symboli Delete the selected symbol? Poistetaanko valittu symboli? Delete the selected symbols? Poistetaanko valitut symbolit? @@ -5309,6 +5310,7 @@ liquify-list-end {0}, {1} {0} ja {1} @msg choose a location for the package valitse paketin sijainti @msg clipboard is empty leikepöytä on tyhjä @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: väritaulukkoon on jäätävä vähintään yksi väri +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` nimeää värin, jonka myös toinen avain nimeää @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` ei ole väri, kuten "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: enintään {MAX_TABLE} väriä @msg command `{0}` is not available right now: {1} komento `{0}` ei ole nyt käytettävissä: {1} diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index c8fd5c0f58..d03ba004cf 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -821,6 +821,7 @@ font-technology Variable Variables Delete Brush Supprimer la forme Delete Color Supprimer la couleur Restore Generated Table Restaurer la table générée + Unshift All Colors Annuler le décalage de toutes les couleurs Delete Character Style Supprimer le style de caractère Delete Empty Artboards Supprimer les plans de travail vides Delete Freeform Point Supprimer le point libre @@ -5052,6 +5053,7 @@ liquify-list-end {0}, {1} {0} et {1} @msg choose a location for the package choisissez un emplacement pour l’assemblage @msg clipboard is empty le presse-papiers est vide @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: au moins une couleur doit rester dans la table des couleurs +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` désigne une couleur qu’une autre clé désigne aussi @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what} : `{h}` n’est pas une couleur comme "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what} : {MAX_TABLE} couleurs au maximum @msg command `{0}` is not available right now: {1} la commande `{0}` n’est pas disponible pour le moment : {1} diff --git a/crates/ui-egui/src/i18n/gu.tsv b/crates/ui-egui/src/i18n/gu.tsv index 59de9d1fcc..8996edb7c3 100644 --- a/crates/ui-egui/src/i18n/gu.tsv +++ b/crates/ui-egui/src/i18n/gu.tsv @@ -924,6 +924,7 @@ Delete Brush બ્રશ કાઢી નાખો Delete Color રંગ કાઢી નાખો Restore Generated Table જનરેટ થયેલું ટેબલ પુનઃસ્થાપિત કરો + Unshift All Colors બધા રંગોનું શિફ્ટ રદ કરો Delete Character Style અક્ષર સ્ટાઇલ કાઢી નાખો Delete Data Set ડેટા સેટ કાઢી નાખો Delete Data Sets ડેટા સેટ્સ કાઢી નાખો diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index 04388ab5d3..2529add00e 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -1319,6 +1319,7 @@ antiAlias Sharp शार्प Delete Brush ब्रश हटाएँ Delete Color रंग हटाएँ Restore Generated Table जनरेट की गई तालिका पुनर्स्थापित करें + Unshift All Colors सभी रंग अनशिफ़्ट करें Delete Character Style कैरेक्टर स्टाइल हटाएँ Delete Data Set डेटा सेट हटाएँ Delete Data Sets डेटा सेट्स हटाएँ @@ -6982,6 +6983,7 @@ antiAlias Sharp शार्प @msg colorMode must be rgb or cmyk, not `{m}` colorMode को rgb या cmyk होना चाहिए, `{m}` नहीं @msg colorModel must be {own} (the document's mode), grayscale or bitmap colorModel को {own} (डॉक्यूमेंट का मोड), grayscale या bitmap होना चाहिए @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: रंग तालिका में कम से कम एक रंग रहना चाहिए +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` वही रंग बताता है जो कोई दूसरी कुंजी भी बताती है @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}`, "#ff8800" जैसा रंग नहीं है @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: अधिकतम {MAX_TABLE} रंग @msg colour groups can't go into colour groups रंग समूह रंग समूहों में नहीं जा सकते हैं diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index 60a5a63001..558a1fff03 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -1048,6 +1048,7 @@ font-technology Variable Változó Delete Brush Ecset törlése Delete Color Szín törlése Restore Generated Table Előállított tábla visszaállítása + Unshift All Colors Az összes szín eltolásának visszavonása Delete Character Style Karakterstílus törlése Delete Data Set Adatkészlet törlése Delete Empty Artboards Üres rajztáblák törlése @@ -5456,6 +5457,7 @@ imageTrace Outline Körvonal @msg clipboard is empty a vágólap üres @msg closing needs three anchors a lezáráshoz három horgonypont kell @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: legalább egy színnek a színtáblában kell maradnia +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: a(z) `{k}` olyan színt nevez meg, amelyet egy másik kulcs is megnevez @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` nem szín (például "#ff8800") @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: legfeljebb {MAX_TABLE} szín @msg column must be true or a number from 1 a column értéke true vagy 1-től kezdődő szám lehet diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index 28c924d09a..187140987e 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -3262,6 +3262,7 @@ theme Appearance Tampilan Delete Brush Hapus kuas Delete Color Hapus warna Restore Generated Table Pulihkan tabel yang dibuat + Unshift All Colors Batalkan pergeseran semua warna Delete Symbol Hapus simbol Delete the selected symbol? Hapus simbol yang dipilih? Delete the selected symbols? Hapus simbol yang dipilih? @@ -4793,6 +4794,7 @@ imageTrace Outline Kontur @msg choose a location for the package pilih lokasi untuk paket @msg clipboard is empty papan klip kosong @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: setidaknya satu warna harus tetap ada di tabel warna +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` menyebut warna yang juga disebut kunci lain @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` bukan warna seperti "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: maksimal {MAX_TABLE} warna @msg command `{0}` is not available right now: {1} perintah `{0}` tidak tersedia saat ini: {1} diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index ed7360a240..aa76d297c2 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -821,6 +821,7 @@ font-technology Variable Variabili Delete Brush Elimina pennello Delete Color Elimina colore Restore Generated Table Ripristina tabella generata + Unshift All Colors Annulla spostamento di tutti i colori Delete Character Style Elimina stile carattere Delete Empty Artboards Elimina tavole da disegno vuote Delete Freeform Point Elimina punto libero @@ -5119,6 +5120,7 @@ liquify-list-end {0}, {1} {0} e {1} @msg choose a location for the package scegli una posizione per il pacchetto @msg clipboard is empty gli appunti sono vuoti @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: almeno un colore deve restare nella tabella colori +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` indica un colore indicato anche da un’altra chiave @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` non è un colore come "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: al massimo {MAX_TABLE} colori @msg command `{0}` is not available right now: {1} il comando `{0}` non è disponibile in questo momento: {1} diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index de5f87e7e3..5ba02970c4 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -1522,6 +1522,7 @@ antiAlias Sharp シャープ Delete Brush ブラシを削除 Delete Color カラーを削除 Restore Generated Table 生成されたテーブルを復元 + Unshift All Colors すべてのカラーのシフトを戻す Delete Character Style 文字スタイルを削除 Delete Empty Artboards 空のアートボードを削除 Delete Freeform Point フリーフォームポイントを削除 @@ -5082,6 +5083,7 @@ variable-list-end {0}, {1} {0}、{1} @msg paste unavailable 貼り付けを使用できません @msg Save for Web: the image is empty Web 用に保存: 画像が空です @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: カラーテーブルには少なくとも 1 つのカラーを残す必要があります +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` は別のキーと同じカラーを指しています @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` は「#ff8800」のような形式のカラーではありません @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: 指定できるカラーは {MAX_TABLE} 色までです @msg no artboard {i} (0-based; the document has {_1}) アートボード {i} はありません (番号は 0 始まり、このドキュメントには {_1} 個あります) diff --git a/crates/ui-egui/src/i18n/ka.tsv b/crates/ui-egui/src/i18n/ka.tsv index 639a6fe65b..6ca7ed646e 100644 --- a/crates/ui-egui/src/i18n/ka.tsv +++ b/crates/ui-egui/src/i18n/ka.tsv @@ -5356,6 +5356,7 @@ theme Appearance იერსახე Delete Brush ფუნჯის წაშლა Delete Color ფერის წაშლა Restore Generated Table გენერირებული ცხრილის აღდგენა + Unshift All Colors ყველა ფერის წანაცვლების მოხსნა Delete Symbol სიმბოლოს წაშლა Delete the selected symbol? წაიშალოს მონიშნული სიმბოლო? Delete the selected symbols? წაიშალოს მონიშნული სიმბოლოები? @@ -6860,6 +6861,7 @@ font-technology Variable ცვლადი @msg choose a location for the package აირჩიეთ შეფუთვის მდებარეობა @msg clipboard is empty გაცვლის ბუფერი ცარიელია @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: ფერების ცხრილში ერთი ფერი მაინც უნდა დარჩეს +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` ასახელებს ფერს, რომელსაც სხვა გასაღებიც ასახელებს @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` ფერი არ არის, მაგალითად "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: არაუმეტეს {MAX_TABLE} ფერი @msg command `{0}` is not available right now: {1} ბრძანება `{0}` ახლა ხელმისაწვდომი არ არის: {1} diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 206d9ac57b..365f5a082c 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -1512,6 +1512,7 @@ antiAlias Sharp 날카롭게 Delete Brush 브러시 삭제 Delete Color 색상 삭제 Restore Generated Table 생성된 표 복원 + Unshift All Colors 모든 색상 이동 취소 Delete Character Style 문자 스타일 삭제 Delete Empty Artboards 빈 아트보드 삭제 Delete Freeform Point 자유 형태 포인트 삭제 @@ -5011,6 +5012,7 @@ variable-list-end {0}, {1} {0} 및 {1} @msg paste unavailable 붙여넣을 수 없습니다 @msg Save for Web: the image is empty 웹용으로 저장: 이미지가 비어 있습니다 @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: 색상 표에 색상이 하나 이상 남아 있어야 합니다 +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}`이(가) 다른 키와 같은 색상을 가리킵니다 @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}`은(는) "#ff8800" 같은 색상이 아닙니다 @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: 색상은 최대 {MAX_TABLE}개입니다 @msg no artboard {i} (0-based; the document has {_1}) 아트보드 {i}이(가) 없습니다(0부터 시작, 문서의 아트보드 수: {_1}) diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index f5ab592480..19a692b735 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -3917,6 +3917,7 @@ theme Appearance Vormgeving Delete Brush Penseel verwijderen Delete Color Kleur verwijderen Restore Generated Table Gegenereerde tabel herstellen + Unshift All Colors Verschuiving van alle kleuren ongedaan maken Delete Symbol Symbool verwijderen Delete the selected symbol? Het geselecteerde symbool verwijderen? Delete the selected symbols? De geselecteerde symbolen verwijderen? @@ -5454,6 +5455,7 @@ imageTrace Outline Contour @msg choose a location for the package kies een locatie voor het pakket @msg clipboard is empty het klembord is leeg @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: er moet ten minste één kleur in de kleurentabel blijven +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` noemt een kleur die ook een andere sleutel noemt @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` is geen kleur zoals "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: maximaal {MAX_TABLE} kleuren @msg command `{0}` is not available right now: {1} opdracht `{0}` is nu niet beschikbaar: {1} diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index 34284e10cc..5073adcdc5 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -3467,6 +3467,7 @@ theme Appearance Wygląd Delete Brush Usuń pędzel Delete Color Usuń kolor Restore Generated Table Przywróć wygenerowaną tablicę + Unshift All Colors Cofnij przesunięcie wszystkich kolorów Delete Symbol Usuń symbol Delete the selected symbol? Usunąć zaznaczony symbol? Delete the selected symbols? Usunąć zaznaczone symbole? @@ -5203,6 +5204,7 @@ liquify-list-end {0}, {1} {0} i {1} @msg choose a location for the package wybierz lokalizację pakietu @msg clipboard is empty schowek jest pusty @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: w tablicy kolorów musi zostać co najmniej jeden kolor +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` wskazuje kolor, który wskazuje też inny klucz @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` nie jest kolorem w rodzaju "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: maksymalnie {MAX_TABLE} kolorów @msg command `{0}` is not available right now: {1} polecenie `{0}` jest teraz niedostępne: {1} diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 0b6f03834f..a8f4d06505 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -733,6 +733,7 @@ antiAlias Sharp Nítido Delete Brush Excluir Pincel Delete Color Excluir Cor Restore Generated Table Restaurar Tabela Gerada + Unshift All Colors Desfazer Mudança de Todas as Cores Delete Character Style Excluir Estilo de Caractere Delete Empty Artboards Excluir Mesas de Trabalho Vazias Delete Freeform Point Excluir Ponto Livre @@ -4350,6 +4351,7 @@ axis Both Ambos @msg choose a location for the package escolha um local para o pacote @msg clipboard is empty a área de transferência está vazia @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: pelo menos uma cor deve permanecer na tabela de cores +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` indica uma cor que outra chave também indica @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` não é uma cor como "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: no máximo {MAX_TABLE} cores @msg command `{0}` is not available right now: {1} o comando `{0}` não está disponível agora: {1} diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 706e2a889c..8bcf7e4d21 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -817,6 +817,7 @@ font-technology Variable Вариативные Delete Brush Удалить кисть Delete Color Удалить цвет Restore Generated Table Восстановить созданную таблицу + Unshift All Colors Отменить сдвиг всех цветов Delete Character Style Удалить стиль символа Delete Empty Artboards Удалить пустые монтажные области Delete Freeform Point Удалить произвольную точку @@ -5114,6 +5115,7 @@ liquify-list-end {0}, {1} {0} и {1} @msg choose a location for the package выберите расположение для пакета @msg clipboard is empty буфер обмена пуст @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: в цветовой таблице должен остаться хотя бы один цвет +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` обозначает цвет, который обозначает и другой ключ @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` не является цветом, например "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: не более {MAX_TABLE} цветов @msg command `{0}` is not available right now: {1} команда `{0}` сейчас недоступна: {1} diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index 97f11b2f08..eb3152f9ff 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -807,6 +807,7 @@ font-technology Variable Variabla Delete Brush Radera pensel Delete Color Radera färg Restore Generated Table Återställ genererad tabell + Unshift All Colors Ta bort förskjutning av alla färger Delete Character Style Radera teckenstil Delete Empty Artboards Radera tomma ritytor Delete Freeform Point Radera fri punkt @@ -4983,6 +4984,7 @@ liquify-list-end {0}, {1} {0} och {1} @msg choose a location for the package välj en plats för paketet @msg clipboard is empty urklippet är tomt @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: minst en färg måste finnas kvar i färgtabellen +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` anger en färg som även en annan nyckel anger @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` är inte en färg som "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: högst {MAX_TABLE} färger @msg command `{0}` is not available right now: {1} kommandot `{0}` är inte tillgängligt just nu: {1} diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index c8c5e00630..70a6ce66dc 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -798,6 +798,7 @@ font-technology Variable Değişken Delete Brush Fırçayı Sil Delete Color Rengi Sil Restore Generated Table Oluşturulan Tabloyu Geri Yükle + Unshift All Colors Tüm Renklerin Kaydırmasını Kaldır Delete Character Style Karakter Stilini Sil Delete Empty Artboards Boş Çalışma Yüzeylerini Sil Delete Freeform Point Serbest Biçim Noktasını Sil @@ -4800,6 +4801,7 @@ liquify-list-end {0}, {1} {0} ve {1} @msg choose a location for the package paket için bir yer seçin @msg clipboard is empty pano boş @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: renk tablosunda en az bir renk kalmalı +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` başka bir anahtarın da belirttiği bir rengi belirtiyor @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}`, "#ff8800" gibi bir renk değil @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: en fazla {MAX_TABLE} renginde @msg command `{0}` is not available right now: {1} `{0}` komutu şu anda kullanılamıyor: {1} diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index 8830aacd8f..af4340137b 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -815,6 +815,7 @@ font-technology Variable Варіативні Delete Brush Видалити пензель Delete Color Видалити колір Restore Generated Table Відновити створену таблицю + Unshift All Colors Скасувати зсув усіх кольорів Delete Character Style Видалити стиль символу Delete Empty Artboards Видалити порожні монтажні області Delete Freeform Point Видалити довільну точку @@ -5103,6 +5104,7 @@ liquify-list-end {0}, {1} {0} і {1} @msg choose a location for the package виберіть розташування для пакета @msg clipboard is empty буфер обміну порожній @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: у колірній таблиці має залишитися принаймні один колір +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` позначає колір, який позначає й інший ключ @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` не є кольором, наприклад "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: не більше {MAX_TABLE} кольорів @msg command `{0}` is not available right now: {1} команда `{0}` зараз недоступна: {1} diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index 0fc276acd5..c0efcbc2db 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -945,6 +945,7 @@ font-technology Variable Biến thiên Delete Brush Xóa cọ Delete Color Xóa màu Restore Generated Table Khôi phục bảng đã tạo + Unshift All Colors Bỏ dịch chuyển tất cả màu Delete Character Style Xóa kiểu ký tự Delete Data Set Xóa tập dữ liệu Delete Design Xóa thiết kế @@ -5124,6 +5125,7 @@ theme Appearance Giao diện @msg clipboard is empty khay nhớ tạm trống @msg closing needs three anchors đóng đường dẫn cần ba điểm neo @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted: phải giữ lại ít nhất một màu trong bảng màu +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted: `{k}` chỉ một màu mà khóa khác cũng chỉ @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}: `{h}` không phải là màu như "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}: tối đa {MAX_TABLE} màu @msg column must be true or a number from 1 column phải là true hoặc số từ 1 diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index cabb5e2866..c5b307c1d2 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -763,6 +763,7 @@ antiAlias Sharp 锐利 Delete Brush 删除画笔 Delete Color 删除颜色 Restore Generated Table 恢复生成的颜色表 + Unshift All Colors 取消偏移所有颜色 Delete Character Style 删除字符样式 Delete Empty Artboards 删除空白画板 Delete Freeform Point 删除自由点 @@ -4771,6 +4772,7 @@ imageTrace Outline 轮廓 @msg paste unavailable 无法粘贴 @msg Save for Web: the image is empty 存储为 Web 所用格式:图像为空 @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted:颜色表中至少要保留一种颜色 +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted:`{k}` 与另一个键指的是同一种颜色 @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}:`{h}` 不是颜色,例如 "#ff8800" @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}:最多 {MAX_TABLE} 种颜色 @msg no artboard {i} (0-based; the document has {_1}) 没有画板 {i} (从 0 开始计数;文档有 {_1} 个) diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index 2a9fb3e68b..aeaa0e9802 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -783,6 +783,7 @@ font-technology Variable 可變 Delete Brush 刪除筆刷 Delete Color 刪除顏色 Restore Generated Table 還原產生的色彩表 + Unshift All Colors 取消位移所有顏色 Delete Character Style 刪除字元樣式 Delete Empty Artboards 刪除空白工作區域 Delete Freeform Point 刪除任意形狀錨點 @@ -2235,6 +2236,7 @@ file-filter Templates 範本 @msg paste unavailable 無法貼上 @msg Save for Web: the image is empty 儲存為網頁用:影像是空的 @msg colorTable.deleted: at least one color has to stay in the color table colorTable.deleted:色彩表中至少要保留一種顏色 +@msg colorTable.shifted: `{k}` names a color another key names colorTable.shifted:`{k}` 與另一個鍵指的是同一種顏色 @msg colorTable.{what}: `{h}` is not a colour such as "#ff8800" colorTable.{what}:`{h}` 不是像 "#ff8800" 這樣的顏色 @msg colorTable.{what}: at most {MAX_TABLE} colours colorTable.{what}:最多 {MAX_TABLE} 種顏色 @msg no artboard {i} (0-based; the document has {_1}) 沒有工作區域 {i} (從 0 起算;文件有 {_1} 個) diff --git a/docs/mcp.md b/docs/mcp.md index 9bb4128d4c..e1c7773827 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -9586,7 +9586,7 @@ File → Export → Save for Web (Legacy) writes optimised web images: `document …}` renders the artboard (`clipToArtboard`, the default; `artboard` picks one) or the visible art and the slices, at `width`, `height` or `percent`, and encodes it with the format's settings: for GIF and PNG-8 `reduction`, `colors`, `dither`, `ditherAmount`, `transparency`, `matte`, `interlaced`, `webSnap`, `lossy` (GIF) and `colorTable {locked, -transparent, webShift, sort, deleted, customPalette}`; for JPEG `quality`, `progressive`, `optimized`, `embedProfile` and `matte`; for PNG-24 +transparent, webShift, sort, deleted, customPalette, shifted}`; for JPEG `quality`, `progressive`, `optimized`, `embedProfile` and `matte`; for PNG-24 `transparency`, `matte` and `interlaced`. `metadata` (none, copyright, contact, all) writes File Info as PNG text or a GIF/JPEG comment; `convertToSrgb` marks PNGs as sRGB. `` is the name of `path` without its extension, or without `path` the document's title with the characters Windows does not allow in a file name as `-` and a `-` after @@ -9599,7 +9599,7 @@ couldn't be decoded and is missing from the image; the files are written all the `document.exportForWeb.preview` returns what Save writes for the same settings without writing it: `bytes` (the exact file size), `seconds` to download at `kbps` (default 56.6), the size, and for palette formats the colour table -(`colors: [{color, source, transparent, locked, webShifted, webSafe}]`). The colour table's lists name colours by +(`colors: [{color, source, transparent, locked, webShifted, shifted, webSafe}]`). The colour table's lists name colours by `source` (the colour the reduction made), so a colour keeps its edits when it is web-shifted or snapped. `slice: n` previews one slice; `image: true` adds the file; `warnings` holds the export's warnings. @@ -9609,15 +9609,38 @@ file agree. A deleted color also leaves `locked`, `transparent` and `webShift`. ignored. Deleting every opaque color is an error, and the settings, preview and files do not change; the transparent entry of transparent pixels cannot be deleted. `colorTable.customPalette: ["#rrggbb"…]` is a fixed palette (a Custom table) used instead of the reduction's own, at most `colors` entries with the transparent one included, so a color it -lacks is not made again; the dialog's Delete Color sets it to the table's colors on the first deletion. Both lists hold +lacks is not made again. Its colors in `transparent` all become the transparent entry and take one of the `colors` +slots together (when no pixel is transparent and no pixel takes one of them, that slot goes to its next color); its +other colors fill the remaining slots in order. The dialog's Delete Color sets it to the table's colors on the first deletion. Both lists hold at most 256 colors, and `#rrggbbaa` is refused. A `reduction` change without `colorTable` in the same params clears both lists. JPEG and PNG-24 have no color table and do not read them. Presets and `webExport.settings` keep them. In the dialog a click selects one color, Shift-click selects the colors between it and the last one clicked, and Ctrl-click (Command-click on macOS) adds or removes one (`__colors` holds the selection, `__color` the last one -clicked). The trash button and Delete Color in the table's menu delete the selection in one edit, Restore Generated +clicked). The trash button and Delete Color in the table's menu delete the selected colors the table shows in one edit, +and are off when it shows none of them (a selected color can leave the table when the reduction or the color count +changes). The Lock, Transparent and Web Shift buttons act on the last color clicked, and are off when the table no longer +shows it. Restore Generated Table in that menu clears `deleted` and `customPalette`, and the table reads Custom while either is set. Choosing another reduction in the dialog also clears them. +Shifting a color is `colorTable.shifted: {"#source": "#rrggbb"…}`, by `source`: every pixel of that color is +written as the color given, in the preview and the file. The color is kept when the colors are reduced, as a +locked one is: the shifted and locked colors take the palette's slots first, shifted ones before locked ones, and at +least one slot is left for the reduction, so with `colors: 2` and transparent pixels none is kept and a color left out +shifts nothing. As with a locked color, a kept source stays in the palette when the art no longer has it, and the +pixels nearest to it are written in the new color. The preview marks it `shifted` and `locked`. A shift by hand wins over `webShift`, `webSnap` and +`locked`; a color mapped to transparent stays transparent. GIF `lossy` moves no pixel into or out of a shifted color. +Two colors may be shifted to the same color. A source the +table does not hold shifts nothing, and the shift stays with the settings for when it comes back; another reduction +keeps it. The settings store the map in lowercase, drop a color shifted to itself or deleted, and drop the `webShift` +of a color shifted by hand. More than 256 entries, a key or value that is not a color such as `#ff8800` (`#rrggbbaa` +included), and two keys that name one color are errors. Presets and `webExport.settings` keep the map. In the dialog a double-click on an +opaque swatch opens the Color Picker on the color shown (on the source color for a color already shifted; an agent +sets `__editColor: "#source"`). Its OK shifts the color (picking the source color takes the shift away), and Cancel +leaves the table as it was. A shifted swatch shows the source color at its upper left and the new color at its lower +right, with the lock mark, and Lock stays on until the color is unshifted. Web Shift replaces a shift by hand, and +Unshift All Colors in the table's menu clears `shifted` and `webShift`. Only Web Colors in the picker starts off. + ```json {"name":"run_command","arguments":{"command":"document.exportForWeb.preview","params":{"format":"png8","colorTable":{"deleted":["#ff0000"],"customPalette":["#0000ff","#00ff00","#ff0000"]}}}} ``` diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md index df6473423c..db84035050 100644 --- a/docs/target-app-parity.md +++ b/docs/target-app-parity.md @@ -924,6 +924,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur - Save for Web: Optimize to File Size… opens rows for a desired file size in K, Start With (Current Settings, Auto Select GIF/JPEG) and, with slices, Use (Total of All Slices, Each Slice, Current Slice); OK takes the settings whose files fit and shows the size found, or says that no setting tried fits ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf#page=395)). The search lowers JPEG quality or palette colors (GIF then lossy) and encodes at most 32 trial settings; Auto Select chooses GIF for transparent art or art of at most 256 colors and JPEG otherwise. The slices share one setting, so every Use choice changes all of them (`webExport.optimizeToFileSize`). Scores and estimates are unchanged. - Save for Web: while Alt (Option on macOS) is held, the dialog's Cancel button reads Reset, which puts the remembered settings back on the document's active artboard and leaves the dialog open (`ui.dialogReset`). - Save for Web: the color table's trash button and Delete Color in its menu remove the selected GIF or PNG-8 colors, and their pixels take the nearest color left in the palette ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs4/illustrator_cs4_help.pdf#page=404)). Click selects one color, Shift-click a range and Ctrl-click (Command-click on macOS) adds or removes one ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=398)). After the first deletion the table is a fixed Custom palette, so deleted colors stay out when the preview updates. These rules are VectorCraft's own: a deleted color is no longer locked, transparent or web-shifted; deleting every opaque color is refused; Restore Generated Table in the menu, or another reduction, goes back to the generated palette; presets and the remembered settings keep the edit (`colorTable.deleted`, `colorTable.customPalette`). Fixed palettes can also use all 256 entries when nothing is transparent. Scores and estimates are unchanged. + - Save for Web: double-clicking a GIF or PNG-8 color-table swatch opens the Color Picker, and its OK changes that color to the one picked everywhere it appears in the image. The swatch then shows the original color in its upper-left half and the new one in its lower-right half, with the lock mark, and the color stays through a lower color count. Double-clicking a changed swatch opens the picker on the original color, and OK on it changes the color back; Unshift All Colors in the table's menu undoes every change, web shifts included ([the help page](https://help.adobe.com/archive/en_US/illustrator/cs3/illustrator_cs3_help.pdf#page=398)). These rules are VectorCraft's own: Cancel changes nothing; a changed color wins over Web Shift, Web Snap and Lock, and pressing Web Shift replaces it; a color mapped to transparent stays transparent; two colors may change to the same color; a changed color takes a kept palette slot before a locked one, and one slot always stays for the reduction; the change is kept by source color when the reduction changes and applies only while that source is in the table; presets and the remembered settings keep it; the picker opens with Only Web Colors off (`colorTable.shifted`). GIF lossy compression moves no pixel into or out of a changed color. Scores and estimates are unchanged. - Export for Screens, Save for Web (slice images, and files named after the document's title) and the Libraries panel name files with the characters Windows does not allow written as `-` and with a `-` after a Windows device name such as `CON`, on every platform (`document.exportForScreens`, `document.exportForWeb`, `library.create`). - Variables (data merge): text, visibility and image variables bound to objects (an object may carry several), dataset rows applied in one undo step (`variable.*`, `dataset.*`) from a Variables panel and Window › Variables, with dialogs to define, bind and edit, Make Text/Visibility/Image Dynamic, Capture/Update Data Set, CSV import/export (`dataset.import` / `dataset.export`), and a row in italics when an edit leaves the art not matching it; an image dataset value is a file path and apply keeps the object's bounds; bindings let go of deleted art and locked art is left alone except by visibility values; every command, like the rest, is drivable over MCP and the CLI. - Export for Screens numbers distinct row files whose names collide, compared without case, as `-2`, `-3`… instead of leaving them out; identical rows still write one file. It puts row folders that differ only in case into one folder (`document.exportForScreens`).