Merge pull request #8635 from storytold/fix/ase-cap

color: an .ase library over the cap gets VectorCraft's own, translated message again
This commit is contained in:
BFlat
2026-11-19 08:00:13 +07:00
committed by GitHub
2 changed files with 16 additions and 3 deletions
+15 -1
View File
@@ -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())
+1 -2
View File
@@ -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() {