mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-10-25 02:07:09 -06:00
Merge pull request #2994 from Higgs32584/warn-svg-artboard-loss
Save: warn when SVG keeps only one of several artboards
This commit is contained in:
@@ -549,7 +549,10 @@ impl SaveJob {
|
||||
let one = self.encode_one(&artboard_doc(&self.doc, b))?;
|
||||
enc.files.extend(one.files.into_iter().map(|(_, bytes)| (Some(b), bytes)));
|
||||
}
|
||||
enc.warnings.splice(0..0, fidelity_warning(self.plan.format));
|
||||
// Lost artboards first: the status bar shows only the first warning.
|
||||
let f = self.plan.format;
|
||||
let lost = if is_svg(f) { super::svg::lost_artboards_warning(&self.doc, &self.params, f.label) } else { None };
|
||||
enc.warnings.splice(0..0, lost.into_iter().chain(fidelity_warning(f)));
|
||||
Ok(enc)
|
||||
}
|
||||
|
||||
|
||||
@@ -120,7 +120,9 @@ pub fn options_map(p: &Value) -> Result<Map<String, Value>, String> {
|
||||
match o.get("svg") {
|
||||
None | Some(Value::Null) => {}
|
||||
Some(Value::Object(svg)) => m.extend(svg.clone()),
|
||||
Some(_) => return Err("`svg` must be an object of SVG options (see document.formats)".into()),
|
||||
Some(_) => {
|
||||
return Err("`svg` must be an object of SVG options (see document.formats)".into());
|
||||
}
|
||||
}
|
||||
Ok(m)
|
||||
}
|
||||
@@ -147,6 +149,17 @@ fn plan(doc: &Document, p: &Value) -> Result<(ExportOptions, Vec<Option<usize>>,
|
||||
Ok((opts, named.unwrap_or_else(|| vec![0]).into_iter().map(Some).collect(), chosen))
|
||||
}
|
||||
|
||||
/// What a save of `doc` as SVG (format `label`) with options `p` loses of several artboards: the
|
||||
/// file is one artboard and reopens as one, unless it carries the native document (Preserve
|
||||
/// Editing Capabilities).
|
||||
pub(super) fn lost_artboards_warning(doc: &Document, p: &Value, label: &str) -> Option<String> {
|
||||
let n = doc.artboards.len();
|
||||
let preserved = plan(doc, p).is_ok_and(|(opts, ..)| opts.preserve_editing);
|
||||
(n > 1 && !preserved).then(|| {
|
||||
format!("{label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all.")
|
||||
})
|
||||
}
|
||||
|
||||
/// Encode `doc` as SVG (or gzipped, SVGZ): one file per chosen artboard, with the images they
|
||||
/// link to and the writer's warnings.
|
||||
pub(super) fn encode(doc: &Document, p: &Value, compressed: bool) -> Result<Encoded, String> {
|
||||
|
||||
@@ -145,6 +145,23 @@ fn preserve_editing_reopens_the_native_document() {
|
||||
assert_eq!(s.doc().unwrap().doc.artboards.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn saving_several_artboards_as_plain_svg_warns_they_are_lost() {
|
||||
let artboards = |r: &Value| r["warnings"].as_array().unwrap().iter().filter(|w| w.as_str().unwrap().contains("artboards")).count();
|
||||
let mut s = session(3);
|
||||
let r = s.execute("document.save", &json!({"format": "svg"})).unwrap();
|
||||
assert_eq!(artboards(&r), 1, "{r}");
|
||||
// First: the status bar shows only the first warning.
|
||||
assert!(r["warnings"][0].as_str().unwrap().contains("1 of the document's 3 artboards"), "{r}");
|
||||
assert_eq!(artboards(&s.execute("file.saveAs", &json!({"format": "svgz"})).unwrap()), 1);
|
||||
// Preserve Editing keeps them all (they reopen); a single artboard loses none.
|
||||
for p in [json!({"format": "svg", "preserveEditing": true}), json!({"format": "svg", "svg": {"preserveEditing": true}})] {
|
||||
let r = s.execute("document.save", &p).unwrap();
|
||||
assert_eq!(artboards(&r), 0, "{p}: {r}");
|
||||
}
|
||||
assert_eq!(artboards(&session(1).execute("document.save", &json!({"format": "svg"})).unwrap()), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn save_writes_svg_and_remembers_its_options() {
|
||||
let mut s = session(1);
|
||||
|
||||
@@ -5190,3 +5190,4 @@ theme Appearance Външен вид
|
||||
# Select by Color (select.color)
|
||||
Select by Color Избиране по цвят
|
||||
Move Anchor Point Преместване на опорна точка
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} запазва 1 от {n} работни области на документа: файлът се отваря отново с един. Включете „Запазване на възможностите за редактиране“, за да запазите всички.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5228,3 +5228,4 @@ mark-style Japanese Japonské
|
||||
# Select by Color (select.color)
|
||||
Select by Color Vybrat podle barvy
|
||||
Move Anchor Point Přesunout kotevní bod
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} zachová 1 z {n} pracovních ploch dokumentu: soubor se znovu otevře s jedním. Zapněte Zachovat možnosti úprav, aby zůstala všechna.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4808,3 +4808,4 @@ effect Soft Weich
|
||||
# Select by Color (select.color)
|
||||
Select by Color Nach Farbe auswählen
|
||||
Move Anchor Point Ankerpunkt verschieben
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} behält 1 der {n} Zeichenflächen des Dokuments: Die Datei wird mit einer wieder geöffnet. Aktivieren Sie „Bearbeitungsfunktionen beibehalten“, um alle zu behalten.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5180,3 +5180,4 @@ effect Points Σημεία
|
||||
# Select by Color (select.color)
|
||||
Select by Color Επιλογή βάσει χρώματος
|
||||
Move Anchor Point Μετακίνηση σημείου αγκύρωσης
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. Το {label} διατηρεί 1 από τους {n} πίνακες σχεδίασης του εγγράφου: το αρχείο ανοίγει ξανά με μία. Ενεργοποιήστε τη Διατήρηση δυνατοτήτων επεξεργασίας για να τους κρατήσετε όλους.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2016 and column 19.
|
@@ -5170,3 +5170,4 @@ mark-style Japanese Japonesas
|
||||
# Select by Color (select.color)
|
||||
Select by Color Seleccionar por color
|
||||
Move Anchor Point Mover punto de ancla
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} conserva 1 de las {n} mesas de trabajo del documento: el archivo se vuelve a abrir con una. Active Conservar capacidades de edición para conservarlas todas.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5259,3 +5259,4 @@ swatch Bright Violet Kirkas violetti
|
||||
Save and Close Tallenna ja sulje
|
||||
Play: Toista:
|
||||
Move Anchor Point Siirrä ankkuripistettä
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} säilyttää asiakirjan {n} piirtoalustasta 1: tiedosto avautuu uudelleen yhdellä. Ota Säilytä muokkausominaisuudet käyttöön, jotta kaikki säilyvät.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5227,3 +5227,4 @@ theme Appearance Apparence
|
||||
# Select by Color (select.color)
|
||||
Select by Color Sélectionner par couleur
|
||||
Move Anchor Point Déplacer le point d’ancrage
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} conserve 1 des {n} plans de travail du document : le fichier se rouvre avec un seul. Activez Conserver les fonctions d’édition pour les conserver tous.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5214,3 +5214,4 @@ imageTrace Outline Körvonal
|
||||
# Select by Color (select.color)
|
||||
Select by Color Kijelölés szín szerint
|
||||
Move Anchor Point Horgonypont áthelyezése
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. A(z) {label} a dokumentum {n} rajztáblájából 1-et tart meg: a fájl eggyel nyílik meg újra. Kapcsolja be a Szerkeszthetőség megtartása beállítást, hogy mind megmaradjon.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4842,3 +4842,4 @@ lighting Light Luce
|
||||
# Select by Color (select.color)
|
||||
Select by Color Seleziona per colore
|
||||
Move Anchor Point Sposta punto di ancoraggio
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} mantiene 1 delle {n} tavole da disegno del documento: il file si riapre con una sola. Attiva Mantieni possibilità di modifica per mantenerle tutte.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4882,3 +4882,4 @@ lighting Light ライト
|
||||
# Select by Color (select.color)
|
||||
Select by Color カラーで選択
|
||||
Move Anchor Point アンカーポイントを移動
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} ではドキュメントの {n} 個のアートボードのうち 1 個だけが保持され、ファイルは 1 個で開き直されます。すべて保持するには「編集機能を保持」をオンにしてください。
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5135,3 +5135,4 @@ imageTrace Outline კონტური
|
||||
@msg thumbnail: no page {n} (the file has 1) thumbnail: გვერდი {n} არ არსებობს (ფაილს 1 გვერდი აქვს)
|
||||
Move Anchor Point საყრდენი წერტილის გადაადგილება
|
||||
Alt key toggles to Smooth Tool Alt კლავიში ჩართავს გაგლუვების ხელსაწყოს
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} ინახავს დოკუმენტის {n} სამუშაო დაფიდან 1-ს: ფაილი ხელახლა ერთით გაიხსნება. ყველას შესანარჩუნებლად ჩართეთ „რედაქტირების შესაძლებლობების შენარჩუნება“.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4805,3 +4805,4 @@ lighting Light 광원
|
||||
# Select by Color (select.color)
|
||||
Select by Color 색상별 선택
|
||||
Move Anchor Point 앵커 포인트 이동
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label}은(는) 문서의 아트보드 {n}개 중 1개만 유지하며 파일은 아트보드 하나로 다시 열립니다. 모두 유지하려면 편집 기능 보존을 켜십시오.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5080,3 +5080,4 @@ mark-style Japanese Japońskie
|
||||
# Select by Color (select.color)
|
||||
Select by Color Zaznacz według koloru
|
||||
Move Anchor Point Przesuń punkt kontrolny
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} zachowuje 1 z {n} obszarów kompozycji dokumentu: plik otworzy się ponownie z jednym. Włącz Zachowaj możliwości edycji, aby zachować wszystkie.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5145,3 +5145,4 @@ mark-style Japanese Japonesas
|
||||
# Select by Color (select.color)
|
||||
Select by Color Selecionar por Cor
|
||||
Move Anchor Point Mover Ponto de Ancoragem
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} mantém 1 das {n} mesas de trabalho do documento: o arquivo reabre com uma. Ative Preservar Capacidades de Edição para manter todas.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
@@ -4838,3 +4838,4 @@ lighting Light Свет
|
||||
# Select by Color (select.color)
|
||||
Select by Color Выделить по цвету
|
||||
Move Anchor Point Переместить опорную точку
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} сохраняет 1 из {n} монтажных областей документа: файл откроется снова с одной. Включите «Сохранять возможности редактирования», чтобы сохранить все.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -5184,3 +5184,4 @@ theme Appearance Utseende
|
||||
# Select by Color (select.color)
|
||||
Select by Color Markera efter färg
|
||||
Move Anchor Point Flytta ankarpunkt
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} behåller 1 av dokumentets {n} ritytor: filen öppnas igen med en. Slå på Bevara redigeringsmöjligheter för att behålla alla.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 5 and column 25.
|
@@ -4822,3 +4822,4 @@ lighting Light Світло
|
||||
# Select by Color (select.color)
|
||||
Select by Color Виділити за кольором
|
||||
Move Anchor Point Перемістити опорну точку
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} зберігає 1 з {n} монтажних областей документа: файл відкриється знову з однією. Увімкніть «Зберігати можливості редагування», щоб зберегти всі.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 725 and column 40.
|
@@ -4822,3 +4822,4 @@ theme Appearance Giao diện
|
||||
# Select by Color (select.color)
|
||||
Select by Color Chọn theo màu
|
||||
Move Anchor Point Di chuyển điểm neo
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} chỉ giữ 1 trong {n} bảng vẽ của tài liệu: tệp sẽ mở lại với một bảng vẽ. Bật Bảo lưu khả năng chỉnh sửa để giữ tất cả.
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 3959 and column 10.
|
@@ -5065,3 +5065,4 @@ lighting Light 光源
|
||||
# Select by Color (select.color)
|
||||
Select by Color 按颜色选择
|
||||
Move Anchor Point 移动锚点
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} 只保留文档 {n} 个画板中的 1 个:文件重新打开时只有一个。打开“保留编辑功能”可全部保留。
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 2 and column 73.
|
@@ -4860,3 +4860,4 @@ lighting Light 光源
|
||||
@msg invalid object id {value}: expected a non-negative integer 無效的物件 id {value}:應為非負整數
|
||||
@msg no such object id {value} 沒有 id 為 {value} 的物件
|
||||
Move Anchor Point 移動錨點
|
||||
@msg {label} keeps 1 of the document's {n} artboards: the file reopens with one. Turn on Preserve Editing Capabilities to keep them all. {label} 只保留文件 {n} 個工作區域中的 1 個:檔案重新開啟時只有一個。開啟「保留編輯功能」可全部保留。
|
||||
|
||||
|
Can't render this file because it contains an unexpected character in line 6 and column 47.
|
Reference in New Issue
Block a user