mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-16 20:19:40 +00:00
Type: each frame of a thread keeps its own anti-aliasing method
text.setFormat {antiAlias} and the Character panel set the method of the
targeted type objects only. Threading frames, reflowing a thread and
opening a file no longer give every frame of a thread the first frame's
method.
This commit is contained in:
@@ -76,8 +76,8 @@ pub struct TextObject {
|
||||
/// Off for new type and for documents from before it, and saved only when on.
|
||||
#[serde(default, rename = "opticalMarginAlignment", skip_serializing_if = "crate::skip::is_default")]
|
||||
pub optical_margin: bool,
|
||||
/// Character panel › Anti-aliasing Method: how the type's edges are drawn as pixels. Every
|
||||
/// frame of a thread has the same method. Sharp for new type and for documents from before it,
|
||||
/// Character panel › Anti-aliasing Method: how the type's edges are drawn as pixels. Each
|
||||
/// frame of a thread keeps its own method. Sharp for new type and for documents from before it,
|
||||
/// and saved only when it is another method.
|
||||
#[serde(default, rename = "antiAlias", skip_serializing_if = "crate::skip::is_default")]
|
||||
pub anti_alias: TypeAntiAlias,
|
||||
|
||||
@@ -366,8 +366,6 @@ pub fn load_with(name: &str, bytes: &[u8], opts: &LoadOptions) -> Result<Loaded>
|
||||
if !doc.text_threads.is_empty() && !restored {
|
||||
crate::cmd::threads::reflow(&Document::new(1.0, 1.0), &mut doc);
|
||||
} else if !doc.text_threads.is_empty() {
|
||||
// Each frame also takes its thread's first frame's anti-aliasing method, as `reflow` gives it.
|
||||
crate::cmd::threads::share_anti_alias(&mut doc);
|
||||
crate::cmd::threads::share_optical_margin(&mut doc);
|
||||
// A frame whose first paragraph continues from the frame before draws it without the
|
||||
// paragraph's first-line indent and list marker.
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -181,45 +181,12 @@ pub(crate) fn reflow(before: &Document, doc: &mut Document) {
|
||||
}
|
||||
}
|
||||
if live.len() >= 2 {
|
||||
if let Some(a) = anti_alias(before, doc, &live) {
|
||||
give_anti_alias(doc, &live, a);
|
||||
}
|
||||
kept.push(live);
|
||||
}
|
||||
}
|
||||
doc.text_threads = kept;
|
||||
}
|
||||
|
||||
/// The anti-aliasing method that every frame of a thread with the frames `live` takes: that of the
|
||||
/// first frame whose method changed between `before` and `doc`, else the first frame's.
|
||||
fn anti_alias(before: &Document, doc: &Document, live: &[NodeId]) -> Option<vectorcraft_doc::text::TypeAntiAlias> {
|
||||
let now = |id: &NodeId| text_of(doc, *id).map(|t| t.anti_alias);
|
||||
let changed = live.iter().find(|id| text_of(before, **id).is_some_and(|t| Some(t.anti_alias) != now(id)));
|
||||
changed.or(live.first()).and_then(now)
|
||||
}
|
||||
|
||||
/// Give each of the frames `live` that has another anti-aliasing method the method `a`.
|
||||
fn give_anti_alias(doc: &mut Document, live: &[NodeId], a: vectorcraft_doc::text::TypeAntiAlias) {
|
||||
for id in live {
|
||||
if text_of(doc, *id).is_some_and(|t| t.anti_alias != a)
|
||||
&& let Some(NodeKind::Text(t)) = doc.node_mut(*id).map(|n| &mut n.kind)
|
||||
{
|
||||
t.anti_alias = a;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Give every frame of each thread the first frame's anti-aliasing method, without re-flowing the
|
||||
/// story: for a document restored from a file as it was saved.
|
||||
pub(crate) fn share_anti_alias(doc: &mut Document) {
|
||||
for thread in doc.text_threads.clone() {
|
||||
let live: Vec<NodeId> = thread.into_iter().filter(|id| text_of(doc, *id).is_some()).collect();
|
||||
if let Some(a) = anti_alias(doc, doc, &live) {
|
||||
give_anti_alias(doc, &live, a);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Type that is not a frame of a thread is a story of its own: its numbered list paragraphs count
|
||||
/// from 1. Each such type object with another [`TextObject::list_count`] (a copy of a frame, a
|
||||
/// frame taken out of its thread, a frame converted to point type, which [`reflow`] takes out of
|
||||
|
||||
@@ -985,12 +985,11 @@ fn a_thread_takes_its_first_frames_optical_margin_alignment() {
|
||||
assert_eq!([a, b, c].map(|id| optical(&s, id).0), [true; 3]);
|
||||
}
|
||||
|
||||
/// The anti-aliasing method (`text.setFormat {antiAlias}`) belongs to the whole thread and is
|
||||
/// saved only when not Sharp: set in one frame, with or without a range, it is set in every
|
||||
/// frame in one undo step, a frame threaded on takes the thread's method, and a file whose
|
||||
/// frames of one thread differ opens with the first frame's method in all of them.
|
||||
/// The anti-aliasing method (`text.setFormat {antiAlias}`) belongs to each frame and is saved
|
||||
/// only when not Sharp. A range sets its frame in one undo step. Threading and opening preserve
|
||||
/// different methods on the frames of a thread.
|
||||
#[test]
|
||||
fn the_anti_aliasing_method_is_set_for_every_frame_of_a_thread() {
|
||||
fn the_anti_aliasing_method_is_set_for_each_frame_of_a_thread() {
|
||||
use vectorcraft_doc::text::TypeAntiAlias::{self, Crisp, None as Hard, Sharp, Strong};
|
||||
let method = |s: &Session, id: u64| text_of(&s.doc().unwrap().doc, NodeId(id)).map(|t| t.anti_alias);
|
||||
let saved = |s: &Session, id: u64| serde_json::to_value(text_of(&s.doc().unwrap().doc, NodeId(id)).unwrap()).unwrap().get("antiAlias").cloned();
|
||||
@@ -1001,18 +1000,30 @@ fn the_anti_aliasing_method_is_set_for_every_frame_of_a_thread() {
|
||||
let err = s.execute("text.setFormat", &json!({"antiAlias": "smooth"})).unwrap_err().to_string();
|
||||
assert!(err.contains("`antiAlias` must be"), "{err}");
|
||||
s.execute("text.setFormat", &json!({"antiAlias": "crisp"})).unwrap();
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Crisp), Some(Crisp)), "the first frame takes it too");
|
||||
assert_eq!(saved(&s, a), Some(json!("crisp")));
|
||||
// A range of characters sets the whole thread as well.
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Sharp), Some(Crisp)), "only the selected frame takes it");
|
||||
assert_eq!(saved(&s, b), Some(json!("crisp")));
|
||||
// A range of characters sets its whole frame.
|
||||
s.execute("text.setFormat", &json!({"ids": [a], "start": 0, "end": 1, "antiAlias": "none"})).unwrap();
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Hard), Some(Hard)));
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Hard), Some(Crisp)));
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Crisp), Some(Crisp)), "one undo step");
|
||||
// A frame threaded on from the last one takes the thread's method.
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(Sharp), Some(Crisp)), "one undo step");
|
||||
// A new frame does not change the methods of the existing frames.
|
||||
s.execute("text.setFormat", &json!({"ids": [b], "antiAlias": "strong"})).unwrap();
|
||||
let c = new_id(s.execute("text.thread.add", &json!({"from": b, "at": [400, 10]})).unwrap());
|
||||
assert_eq!([a, b, c].map(|id| method(&s, id)), [Some(Strong); 3]);
|
||||
assert_eq!([a, b, c].map(|id| method(&s, id)), [Some(Sharp), Some(Strong), Some(Strong)]);
|
||||
s.execute("edit.undo", &json!({})).unwrap();
|
||||
// Threading existing frames with different methods preserves both.
|
||||
let (mut joined, first_id, second_id) = quoted_thread();
|
||||
joined.execute("text.thread.remove", &json!({})).unwrap();
|
||||
joined.execute("text.setFormat", &json!({"ids": [first_id], "antiAlias": "crisp"})).unwrap();
|
||||
joined.execute("text.setFormat", &json!({"ids": [second_id], "antiAlias": "strong"})).unwrap();
|
||||
joined.execute("select.set", &json!({"ids": [first_id, second_id]})).unwrap();
|
||||
joined.execute("text.thread.create", &json!({})).unwrap();
|
||||
assert_eq!((method(&joined, first_id), method(&joined, second_id)), (Some(Crisp), Some(Strong)));
|
||||
joined.execute("text.editRange", &json!({"id": first_id, "start": 0, "end": 0, "insert": "New "})).unwrap();
|
||||
assert_eq!((method(&joined, first_id), method(&joined, second_id)), (Some(Crisp), Some(Strong)), "reflow keeps both methods");
|
||||
joined.execute("text.thread.remove", &json!({})).unwrap();
|
||||
assert_eq!((method(&joined, first_id), method(&joined, second_id)), (Some(Crisp), Some(Strong)), "unthreading keeps both methods");
|
||||
let first: [TypeAntiAlias; 2] = [Crisp, Hard];
|
||||
for (one, name) in [(first, "old.vectorcraft"), ([Hard, Crisp], "old.vectorcraft"), (first, "old.eps"), ([Hard, Crisp], "old.eps")] {
|
||||
for (id, m) in [(a, one[0]), (b, one[1])] {
|
||||
@@ -1029,7 +1040,7 @@ fn the_anti_aliasing_method_is_set_for_every_frame_of_a_thread() {
|
||||
let r = s.execute("document.open", &json!({"name": name, "dataBase64": vectorcraft_format::base64_encode(&bytes)})).unwrap();
|
||||
assert_eq!(r["restored"], name.ends_with(".eps"), "{r}");
|
||||
assert_eq!(threads(&s), [[a, b]], "{name}");
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(one[0]), Some(one[0])), "{name}, first frame {:?}", one[0]);
|
||||
assert_eq!((method(&s, a), method(&s, b)), (Some(one[0]), Some(one[1])), "{name}, frame methods");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -723,9 +723,8 @@ fn shared_anti_alias(app: &VectorcraftApp) -> Option<TypeAntiAlias> {
|
||||
acc.value()
|
||||
}
|
||||
|
||||
/// Set the anti-aliasing method `m` of the type objects the panel acts on, and of every frame of
|
||||
/// their threads (`text.setFormat {antiAlias}`): the one the Type tool edits, whatever part of its
|
||||
/// text is selected, else the selected type.
|
||||
/// Set the anti-aliasing method `m` of the frame the Type tool edits, whatever part of its text
|
||||
/// is selected, else the selected type objects (`text.setFormat {antiAlias}`).
|
||||
fn set_anti_alias(app: &mut VectorcraftApp, m: TypeAntiAlias) {
|
||||
let mut p = json!({"antiAlias": m.id()});
|
||||
if let Some((id, _, _)) = text_editing(app) {
|
||||
|
||||
@@ -428,6 +428,7 @@ fn the_anti_aliasing_method_dropdown_shows_and_sets_the_types_method() {
|
||||
assert!(text_editing(&app).is_some());
|
||||
set_anti_alias(&mut app, TypeAntiAlias::Strong);
|
||||
assert_eq!(method(&app, a), TypeAntiAlias::Strong);
|
||||
assert_eq!(method(&app, b), TypeAntiAlias::Sharp, "the other selected type is unchanged while editing");
|
||||
assert_eq!(shared_anti_alias(&app), Some(TypeAntiAlias::Strong));
|
||||
// Reset Panel sets Sharp, with the characters' attributes, in one undo step.
|
||||
range_style(&mut app, json!({"tracking": 50}));
|
||||
|
||||
+4
-4
@@ -4875,10 +4875,10 @@ characters take the new ones. One undo step.
|
||||
`text.setFormat {antiAlias: "none"|"sharp"|"crisp"|"strong"}` (the selected type, or `ids`) sets the Character panel's
|
||||
Anti-aliasing Method, which decides how the edges of the characters are drawn as pixels: on the canvas, in raster exports
|
||||
(Export As PNG, JPEG and the other raster formats, Export for Screens, Save for Web) and when Object › Rasterize or
|
||||
Effect › Rasterize draws the type. The method belongs to the whole type object and to every frame of its thread: a
|
||||
`start`/`end` range sets the whole object, threading frames gives the thread its first frame's method, and a file
|
||||
whose frames of one thread differ opens with the first frame's method in all of them. VectorCraft defines what each
|
||||
method does, on the pixels of the picture being drawn (the canvas at its zoom, an export at its resolution):
|
||||
Effect › Rasterize draws the type. The method belongs to the whole type object, and each frame of a thread keeps its
|
||||
own method: a `start`/`end` range sets the whole frame, and threading frames or opening a file keeps each frame's
|
||||
method. VectorCraft defines what each method does, on the pixels of the picture being drawn (the canvas at its zoom,
|
||||
an export at its resolution):
|
||||
|
||||
- `sharp`, the default, draws each edge pixel with the share of it the type covers, as before.
|
||||
- `none` draws hard edges: a pixel takes the type's color where the type covers at least half of it, and nothing
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user