mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 12:38:18 +00:00
color: an .ase library over the cap gets VectorCraft's own, translated message again
#8627 left the check to craft-cms, whose wording isn't in the catalogs, and main's test of the message failed.
This commit is contained in:
@@ -114,6 +114,10 @@ fn swatches_from_cms(list: Vec<PaletteSwatch>) -> Vec<Swatch> {
|
||||
list.into_iter().map(|w| Swatch { name: w.name, paint: Paint::solid(color_from_cms(w.color)), global: w.global, spot: w.spot }).collect()
|
||||
}
|
||||
|
||||
/// The most colors and groups one swatch exchange file holds, read or written (craft-cms reads
|
||||
/// as many).
|
||||
const ASE_MAX_ENTRIES: usize = 100_000;
|
||||
|
||||
fn to_cms_palette(lib: &SwatchLibrary) -> Palette {
|
||||
Palette {
|
||||
name: lib.name.clone(),
|
||||
@@ -148,7 +152,17 @@ pub fn write(lib: &SwatchLibrary, format: PaletteFormat) -> Result<Vec<u8>, Stri
|
||||
serde_json::to_string_pretty(&file).unwrap_or_default()
|
||||
}
|
||||
PaletteFormat::Gpl => return cms_palette::write_palette(&to_cms_palette(lib), cms_palette::PaletteFormat::Gpl),
|
||||
PaletteFormat::Ase => return cms_palette::write_palette(&to_cms_palette(lib), cms_palette::PaletteFormat::Ase),
|
||||
PaletteFormat::Ase => {
|
||||
let p = to_cms_palette(lib);
|
||||
// Counted here, so the message is VectorCraft's own and its translations apply.
|
||||
let entries = p.swatches.len() + p.groups.iter().map(|g| 1 + g.swatches.len()).sum::<usize>();
|
||||
if entries > ASE_MAX_ENTRIES {
|
||||
return Err(format!(
|
||||
"VectorCraft reads at most {ASE_MAX_ENTRIES} colors and groups from a swatch exchange file, and this library has {entries}"
|
||||
));
|
||||
}
|
||||
return cms_palette::write_palette(&p, cms_palette::PaletteFormat::Ase);
|
||||
}
|
||||
PaletteFormat::Css => write_css(lib, keep),
|
||||
};
|
||||
Ok(text.into_bytes())
|
||||
|
||||
@@ -2,12 +2,11 @@ use super::*;
|
||||
use crate::{Gradient, GradientPaint, GradientStop};
|
||||
use proptest::prelude::*;
|
||||
|
||||
// The swatch exchange file's signature, block types and entry cap, which craft-cms keeps private.
|
||||
// The swatch exchange file's signature and block types, which craft-cms keeps private.
|
||||
const ASE_SIGNATURE: &[u8] = b"ASEF";
|
||||
const ASE_GROUP_START: u16 = 0xC001;
|
||||
const ASE_GROUP_END: u16 = 0xC002;
|
||||
const ASE_COLOR: u16 = 0x0001;
|
||||
const ASE_MAX_ENTRIES: usize = 100_000;
|
||||
|
||||
#[test]
|
||||
fn gpl_blank_name_keeps_fallback() {
|
||||
|
||||
Reference in New Issue
Block a user