mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-28 21:39:10 +00:00
combo: #8197
# Conflicts: # docs/file-format-parity.md # docs/roadmap.md # docs/target-app-parity.md
This commit is contained in:
@@ -38,11 +38,13 @@ pub(crate) use blend::{MAX_BLEND_OBJECTS, MAX_KEYS as MAX_BLEND_KEYS, PLUGIN as
|
||||
pub(crate) use brush::{
|
||||
BrushesRead, MANAGER_NAME as BRUSH_MANAGER, brushes_kept, plugin_name as brush_plugin_name, read_brush_object, turn_over as turn_brush_art_over,
|
||||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) use envelope::DASH_CHECKS_MADE;
|
||||
pub(crate) use envelope::DRAWN as ENVELOPE_DRAWN;
|
||||
pub(crate) use envelope::MAX_CHECKED;
|
||||
pub(crate) use envelope::TYPE_DRAWN as ENVELOPE_TYPE_DRAWN;
|
||||
pub(crate) use envelope::{GridPoint as EnvelopeGridPoint, PLUGIN as DEFORM_PLUGIN, outline as envelope_outline, upright as envelope_upright};
|
||||
pub(crate) use envelope::{MAX_ANY as ENVELOPE_MAX_ANY, MAX_SOLID as ENVELOPE_MAX_SOLID};
|
||||
pub(crate) use envelope::{MAX_CHECKED, MAX_DASH_CHECKS};
|
||||
pub(crate) use envelope::{WARPED_TYPE_DRAWN, WarpedType};
|
||||
#[cfg(test)]
|
||||
pub(crate) use frames::TEXT_FRAME_SCANS;
|
||||
|
||||
@@ -59,6 +59,16 @@ pub(crate) fn drawn_note(typed: bool) -> &'static str {
|
||||
pub(super) const MAX_PENDING: usize = 64;
|
||||
/// The most envelopes and warped text objects one import draws to check; more keep their drawn art.
|
||||
pub(crate) const MAX_CHECKED: usize = 256;
|
||||
/// The most strokes with dashes aligned to corners one import draws to check against their drawn
|
||||
/// looks (apart from [`MAX_CHECKED`]); more keep their drawn looks.
|
||||
pub(crate) const MAX_DASH_CHECKS: usize = 256;
|
||||
|
||||
#[cfg(test)]
|
||||
thread_local! {
|
||||
/// How many strokes with dashes aligned to corners have been drawn on this thread to check them
|
||||
/// against their looks.
|
||||
pub(crate) static DASH_CHECKS_MADE: std::cell::Cell<u64> = const { std::cell::Cell::new(0) };
|
||||
}
|
||||
/// The most rows or columns of a mesh read (Make with Mesh's own limit).
|
||||
const MAX_GRID: u32 = 50;
|
||||
/// How far, in points over width and height together, a saved size may lie from the contents'
|
||||
|
||||
@@ -599,6 +599,13 @@ struct Reader<'a> {
|
||||
envelope_checks: usize,
|
||||
/// How far the live envelopes read so far draw from their drawn art ([`super::envelope::Spent`]).
|
||||
envelope_spent: super::envelope::Spent,
|
||||
/// How many more strokes with dashes aligned to corners this import may draw to check
|
||||
/// ([`super::MAX_DASH_CHECKS`]).
|
||||
dash_checks: usize,
|
||||
/// Whether this reader reads only what comes before the first layer (swatches, brushes, styles,
|
||||
/// symbols) for a file whose layers another reader reads: it makes no more checks once it
|
||||
/// reaches the layers, so it spends none of theirs.
|
||||
defs_only: bool,
|
||||
/// The text objects read with a Warp ([`super::envelope::WarpedType`]).
|
||||
warped_type: Vec<super::envelope::WarpedLook>,
|
||||
/// The envelopes of type read with their drawn art, settled once the type is laid out
|
||||
@@ -864,6 +871,8 @@ impl<'a> Reader<'a> {
|
||||
envelopes: Vec::new(),
|
||||
envelope_checks: super::envelope::MAX_CHECKED,
|
||||
envelope_spent: super::envelope::Spent::default(),
|
||||
dash_checks: super::MAX_DASH_CHECKS,
|
||||
defs_only: false,
|
||||
warped_type: Vec::new(),
|
||||
typed_envelopes: Vec::new(),
|
||||
envelopes_drawn: Vec::new(),
|
||||
|
||||
@@ -16,6 +16,9 @@ impl<'a> Reader<'a> {
|
||||
if matches!(kind, Kind::Layer(_)) {
|
||||
self.ensure_space();
|
||||
self.check_symbols();
|
||||
if self.defs_only {
|
||||
(self.envelope_checks, self.dash_checks) = (0, 0);
|
||||
}
|
||||
}
|
||||
let base = if matches!(kind, Kind::Obj(_)) { self.stack.len() } else { self.frames.last().map_or(0, |f| f.base) };
|
||||
self.frames.push(Frame {
|
||||
|
||||
@@ -837,11 +837,13 @@ impl<'a> Reader<'a> {
|
||||
}
|
||||
|
||||
/// Lend `sub`, a reader of a definition, what this import may still spend on laying out blends
|
||||
/// and checking envelopes ([`Reader::take_back_budgets`] takes back what is left).
|
||||
/// and checking envelopes and aligned dashes ([`Reader::take_back_budgets`] takes back what is
|
||||
/// left).
|
||||
fn lend_budgets(&mut self, sub: &mut Reader<'_>) {
|
||||
sub.blend_budget = self.blend_budget;
|
||||
sub.envelope_checks = self.envelope_checks;
|
||||
sub.envelope_spent = std::mem::take(&mut self.envelope_spent);
|
||||
sub.dash_checks = self.dash_checks;
|
||||
}
|
||||
|
||||
/// Take back from `sub` what [`Self::lend_budgets`] lent it, less what it spent.
|
||||
@@ -849,6 +851,7 @@ impl<'a> Reader<'a> {
|
||||
self.blend_budget = sub.blend_budget;
|
||||
self.envelope_checks = sub.envelope_checks;
|
||||
self.envelope_spent = std::mem::take(&mut sub.envelope_spent);
|
||||
self.dash_checks = sub.dash_checks;
|
||||
}
|
||||
|
||||
/// In a pattern's definition, the operands of its first operator start with its head,
|
||||
|
||||
@@ -336,6 +336,7 @@ fn repoint(n: &mut Node, renamed: &std::collections::BTreeMap<String, String>) {
|
||||
/// those the swatches take.
|
||||
pub fn palette(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) -> Option<PaletteSwatches> {
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
r.defs_only = true;
|
||||
// The palette, the gradients and the patterns it names come before the art, so an error in the
|
||||
// art leaves them read.
|
||||
let _ = r.run();
|
||||
@@ -396,6 +397,7 @@ pub fn brushes(data: &[u8], patterns: &[PatternDef], names: &mut obj::Names) ->
|
||||
// Brush objects are plug-in objects: data without one isn't read again.
|
||||
memchr::memmem::find(data, b"BeginPluginObject")?;
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
r.defs_only = true;
|
||||
// The brushes come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
let (mut lib, unread) = r.brush_library()?;
|
||||
@@ -449,6 +451,7 @@ pub fn graphic_styles(data: &[u8], large_canvas: bool, names: &mut obj::Names) -
|
||||
return (vec![], 1.0);
|
||||
}
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
r.defs_only = true;
|
||||
r.large_canvas = large_canvas.then_some(1.0);
|
||||
// The styles come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
@@ -482,6 +485,7 @@ pub struct Symbols {
|
||||
pub fn symbols(data: &[u8], names: &mut obj::Names) -> Option<Symbols> {
|
||||
crate::import::ai::find(data, b"BeginSymbol")?;
|
||||
let mut r = Reader::with_names(data, names.encoding);
|
||||
r.defs_only = true;
|
||||
// The symbols come before the art, so an error in the art leaves them read.
|
||||
let _ = r.run();
|
||||
r.check_symbols();
|
||||
@@ -536,10 +540,20 @@ pub fn symbols(data: &[u8], names: &mut obj::Names) -> Option<Symbols> {
|
||||
Some(Symbols { symbols, images, swatches, canvas_scale: r.canvas_scale, own_size: r.symbols_own_size })
|
||||
}
|
||||
|
||||
/// A reader of all of `data` for what doesn't depend on how its art draws (its artboards, its
|
||||
/// variable library): it checks no envelope and no stroke with aligned dashes against its drawn
|
||||
/// look, so it spends none of the import's checks ([`super::MAX_CHECKED`],
|
||||
/// [`super::MAX_DASH_CHECKS`]), which are the layers' reader's.
|
||||
fn reader_aside(data: &[u8]) -> Reader<'_> {
|
||||
let mut r = Reader::new(data);
|
||||
(r.envelope_checks, r.dash_checks) = (0, 0);
|
||||
r
|
||||
}
|
||||
|
||||
/// [`artboards`] as far as reading `data` from its start gets: those read before an error, and
|
||||
/// those of a `/Document` still open when it stopped (its art can be what stopped it).
|
||||
fn artboards_read(data: &[u8], names: &mut obj::Names) -> (Vec<(String, Rect)>, Option<usize>) {
|
||||
let mut r = Reader::new(data);
|
||||
let mut r = reader_aside(data);
|
||||
r.names = obj::Names::new(names.encoding);
|
||||
let _ = r.run();
|
||||
let open: Vec<Obj> = r.frames.iter().filter_map(|f| if let Kind::Obj(o) = &f.kind { Some((**o).clone()) } else { None }).collect();
|
||||
@@ -608,7 +622,7 @@ pub fn variables(data: &[u8], names: &mut obj::Names) -> VariableRead {
|
||||
if crate::import::ai::find(data, b"variableSets").is_none() {
|
||||
return VariableRead::default();
|
||||
}
|
||||
let mut r = Reader::new(data);
|
||||
let mut r = reader_aside(data);
|
||||
r.names = obj::Names::new(names.encoding);
|
||||
let _ = r.run();
|
||||
if r.variables.present {
|
||||
|
||||
@@ -832,15 +832,32 @@ impl<'a> Reader<'a> {
|
||||
})
|
||||
});
|
||||
// An image with a Warp is the object only where its live warp draws as its drawn look, and
|
||||
// while the import has a check left for it; otherwise its drawn look stays.
|
||||
// while the import has a check left for it; otherwise its drawn look stays. So is a stroke
|
||||
// with dashes aligned to corners and path ends, whose fitting is VectorCraft's own, within
|
||||
// checks of its own ([`crate::import::ai::MAX_DASH_CHECKS`]) and without weighing the page:
|
||||
// the envelopes' checks and share of the page check stay theirs alone. Type with such
|
||||
// dashes keeps its drawn look, as before.
|
||||
let appearance = match appearance {
|
||||
Some(ap) if aligns_dashes(&ap) && slot_of(object.name.as_deref()).is_some() => None,
|
||||
Some(ap) if matches!(object.kind, NodeKind::Image(_)) && ap.effects.iter().any(|e| e.id.starts_with("warp.")) => {
|
||||
let alike = self.envelope_checks > 0 && {
|
||||
self.envelope_checks -= 1;
|
||||
let layer = self.doc.alloc_id();
|
||||
let shared = crate::import::ai::envelope::Shared { patterns: &self.doc.patterns, images: &self.doc.images };
|
||||
let shown = !hidden && object.visible && look.visible;
|
||||
image_warp_alike(object, &ap, look, &self.hidden_ids, hidden, layer, &shared, page.filter(|_| shown), &mut self.envelope_spent)
|
||||
look_alike(object, &ap, look, &self.hidden_ids, hidden, layer, &shared, page.filter(|_| shown), &mut self.envelope_spent)
|
||||
};
|
||||
alike.then_some(ap)
|
||||
}
|
||||
Some(ap) if aligns_dashes(&ap) => {
|
||||
let alike = self.dash_checks > 0 && {
|
||||
self.dash_checks -= 1;
|
||||
#[cfg(test)]
|
||||
crate::import::ai::DASH_CHECKS_MADE.set(crate::import::ai::DASH_CHECKS_MADE.get() + 1);
|
||||
let layer = self.doc.alloc_id();
|
||||
let shared = crate::import::ai::envelope::Shared { patterns: &self.doc.patterns, images: &self.doc.images };
|
||||
let mut spent = crate::import::ai::envelope::Spent::default();
|
||||
look_alike(object, &ap, look, &self.hidden_ids, hidden, layer, &shared, None, &mut spent)
|
||||
};
|
||||
alike.then_some(ap)
|
||||
}
|
||||
@@ -1224,18 +1241,19 @@ fn moves_with(object: &Node, st: &crate::import::ai::style::ArtStyle) -> bool {
|
||||
|
||||
/// Is `object` an image without an opacity mask, and `st` one Warp on it with nothing else that
|
||||
/// paints ([`crate::import::ai::style::ArtStyle::image_warp`])? Such an image is read with its Warp
|
||||
/// live where that draws as its drawn look ([`image_warp_alike`]).
|
||||
/// live where that draws as its drawn look ([`look_alike`]).
|
||||
fn image_warps(object: &Node, st: &crate::import::ai::style::ArtStyle) -> bool {
|
||||
matches!(object.kind, NodeKind::Image(_)) && object.extras().mask.is_none() && st.image_warp
|
||||
}
|
||||
|
||||
/// Does image `object` with `appearance` (its style's Warp) draw as `look`, its drawn look, compared
|
||||
/// over all that the warp draws ([`crate::import::ai::envelope::warped_alike`]) on `layer`, a layer
|
||||
/// id no other node has? Both are drawn shown, opaque and in the Normal mode; a hidden look is drawn
|
||||
/// with every object in it shown, as the hidden object's look holds them. Unless the look is on
|
||||
/// `%_` lines itself (`hidden`), the copies in it that are on `%_` lines (`hidden_ids`) are left out.
|
||||
/// Does `object` with `appearance` (an image's Warp, or a stroke with dashes aligned to corners)
|
||||
/// draw as `look`, its drawn look, compared over all that it draws, effects included
|
||||
/// ([`crate::import::ai::envelope::warped_alike`]), on `layer`, a layer id no other node has? Both
|
||||
/// are drawn shown, opaque and in the Normal mode; a hidden look is drawn with every object in it
|
||||
/// shown, as the hidden object's look holds them. Unless the look is on `%_` lines itself
|
||||
/// (`hidden`), the copies in it that are on `%_` lines (`hidden_ids`) are left out.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn image_warp_alike(
|
||||
fn look_alike(
|
||||
object: &Node,
|
||||
appearance: &Appearance,
|
||||
look: &Node,
|
||||
@@ -1261,6 +1279,11 @@ fn image_warp_alike(
|
||||
crate::import::ai::envelope::warped_alike(&live, &plain, layer, shared, page, spent)
|
||||
}
|
||||
|
||||
/// Does `appearance` stroke with dashes aligned to corners and path ends?
|
||||
fn aligns_dashes(appearance: &Appearance) -> bool {
|
||||
appearance.items.iter().any(|i| matches!(i, AppearanceItem::Stroke(s) if s.dash.as_ref().is_some_and(|d| d.align_corners && d.is_dashed())))
|
||||
}
|
||||
|
||||
/// Show every object in container `n`, at any depth.
|
||||
fn show_members(n: &mut Node) {
|
||||
for c in n.children_mut().into_iter().flatten() {
|
||||
@@ -1282,7 +1305,7 @@ fn styled(object: &Node, look: &Node, st: &crate::import::ai::style::ArtStyle, p
|
||||
let slot = slot_of(object.name.as_deref()).is_some();
|
||||
// Several fills and strokes, on a path or a compound path.
|
||||
let stacked = !slot && !st.simple && st.stacked && matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. });
|
||||
// One Warp on an image, checked against its drawn look by the caller ([`image_warp_alike`]).
|
||||
// One Warp on an image, checked against its drawn look by the caller ([`look_alike`]).
|
||||
let image_warp = !st.simple && image_warps(object, st);
|
||||
// A symbol instance draws its symbol's art: it keeps its drawn look.
|
||||
if !st.plain
|
||||
|
||||
@@ -1469,11 +1469,10 @@ fn stroke_item(f: &Filter, align: StrokeAlign) -> Result<Option<StyleItem>, ()>
|
||||
if !f.paints.0 {
|
||||
return Ok(None);
|
||||
}
|
||||
// Dashes aligned to corners and path ends draw as the look's pieces: a solid end at each end
|
||||
// and the pattern, fitted, between them.
|
||||
if f.params.get("BSDashAdj").is_some_and(|v| *v != 0.0) {
|
||||
return Err(());
|
||||
}
|
||||
// Dashes aligned to corners and path ends (the switch in the stroke's dictionary): the look
|
||||
// draws them fitted between solid ends, which the reader checks the stroke against before it
|
||||
// takes it.
|
||||
let aligned = f.params.get("BSDashAdj").is_some_and(|v| *v != 0.0);
|
||||
match &f.stroke {
|
||||
Some(p) if !f.gradient && f.pattern.is_none() => Ok(Some(StyleItem::Stroke {
|
||||
paint: p.clone(),
|
||||
@@ -1481,7 +1480,7 @@ fn stroke_item(f: &Filter, align: StrokeAlign) -> Result<Option<StyleItem>, ()>
|
||||
cap: f.cap,
|
||||
join: f.join,
|
||||
miter: f.miter,
|
||||
dash: f.dash.clone(),
|
||||
dash: f.dash.clone().map(|d| Dash { align_corners: aligned, ..d }),
|
||||
profile: width_profile(&f.arrays),
|
||||
align,
|
||||
brush: None,
|
||||
|
||||
@@ -61,13 +61,17 @@ fn a_uniform_or_unreadable_width_profile_stays_a_live_stroke() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn dashes_aligned_to_corners_keep_the_drawn_look() {
|
||||
// GUARDS: the look holds the fitted pattern and the solid ends the style's dash array doesn't.
|
||||
fn dashes_aligned_to_corners_read_as_aligned_dashes() {
|
||||
// The look holds the fitted pattern, which the style's dash array doesn't: the reader takes the
|
||||
// stroke only where VectorCraft's own fitting draws as that look.
|
||||
let data = b"/KnownStyle :\n(Stitches) /Name ,\n/ActiveStyle :\n/CompoundFilter :\n(Chain Style Filter) 0 0 /Filter ,\n1 /Visible ,\n\
|
||||
/BasicFilter :\n(Stroke Style Filter) 0 0 /Filter ,\n1 /Visible ,\n2 /FillOrStroke ,\n/Dictionary : /NotRecorded ,\n\
|
||||
/Dictionary : /NotRecorded ,\n1 /Bool (BSDashAdj) ,\n; (kAIBeautifulStrokesParamsDictKey) ,\n\
|
||||
/StrokeStyle : 0 R\n0 0 0 0 0 0 1 XA\n1 J 0 j 2 w 10 M [5 10 ]0 d\n0 XR\n1 0 Xd\n/Def ;\n (StrokeStyle) ,\n; /Dict ;\n /Part ,\n;\n";
|
||||
assert!(!art_styles(data)["Stitches"].plain);
|
||||
let style = &art_styles(data)["Stitches"];
|
||||
assert!(style.plain, "{style:?}");
|
||||
let [StyleItem::Stroke { dash: Some(dash), .. }] = style.items.as_slice() else { panic!("{:?}", style.items) };
|
||||
assert_eq!((dash.pattern.as_slice(), dash.align_corners), ([5.0, 10.0].as_slice(), true));
|
||||
}
|
||||
|
||||
/// The style `Shade`: a Drop Shadow whose dictionary holds `keys`.
|
||||
|
||||
@@ -6367,21 +6367,13 @@ fn a_stroke_offset_filter_keeps_its_strokes_style() {
|
||||
}
|
||||
|
||||
/// A Stroke Offset stroke this doesn't read as a stroke keeps the object's drawn look: a switch
|
||||
/// written as another kind, dashes aligned to corners and path ends, a gradient.
|
||||
/// written as another kind, a gradient.
|
||||
#[test]
|
||||
fn a_stroke_offset_filter_with_a_stroke_this_does_not_read_keeps_the_drawn_look() {
|
||||
let outside = "0 /Bool (StrokeOffsetInside) ,\n";
|
||||
let gradient = "0 R\nBb\n0 0 0 0 Bh\n2 (Red ramp) 0 0 90 1 1 0 0 1 0 0 1 Bg\n0 BB\n0 J 0 j 2 w 10 M []0 d\n0 XR\n1 0 Xd";
|
||||
let cases = [
|
||||
("a switch written as a number", offset_stroke_style_with("Edge", "1 /Int (StrokeOffsetInside) ,\n", OFFSET_STROKE)),
|
||||
(
|
||||
"dashes aligned to corners",
|
||||
offset_stroke_style_with(
|
||||
"Edge",
|
||||
&format!("{outside}/Dictionary : /NotRecorded ,\n1 /Bool (BSDashAdj) ,\n; (kAIBeautifulStrokesParamsDictKey) ,\n"),
|
||||
&OFFSET_STROKE.replace("[]0 d", "[5 10 ]0 d"),
|
||||
),
|
||||
),
|
||||
("a gradient", offset_stroke_style_with("Edge", outside, gradient)),
|
||||
];
|
||||
for (why, style) in cases {
|
||||
@@ -6390,6 +6382,26 @@ fn a_stroke_offset_filter_with_a_stroke_this_does_not_read_keeps_the_drawn_look(
|
||||
}
|
||||
}
|
||||
|
||||
/// A Stroke Offset stroke with dashes aligned to corners and path ends reads as such a stroke,
|
||||
/// outside the path; the object takes it only where it draws as its drawn look. Here the look (a
|
||||
/// filled square) draws otherwise, so the look check keeps the drawn look.
|
||||
#[test]
|
||||
fn a_stroke_offset_with_dashes_aligned_to_corners_unlike_its_look_keeps_the_look() {
|
||||
use crate::import::ai::style::StyleItem;
|
||||
use vectorcraft_doc::StrokeAlign;
|
||||
let keys = "0 /Bool (StrokeOffsetInside) ,\n/Dictionary : /NotRecorded ,\n1 /Bool (BSDashAdj) ,\n; (kAIBeautifulStrokesParamsDictKey) ,\n";
|
||||
let style = offset_stroke_style_with("Edge", keys, &OFFSET_STROKE.replace("[]0 d", "[5 10 ]0 d"));
|
||||
let styles = crate::import::ai::style::art_styles(style.as_bytes());
|
||||
let Some(StyleItem::Stroke { dash: Some(dash), align, .. }) = styles["Edge"].items.iter().find(|i| matches!(i, StyleItem::Stroke { .. })) else {
|
||||
panic!("{:?}", styles["Edge"])
|
||||
};
|
||||
assert_eq!((dash.pattern.as_slice(), dash.align_corners, *align), ([5.0, 10.0].as_slice(), true, StrokeAlign::Outside));
|
||||
let r = read_ok(&format!("%AI9_BeginArtStyles\n{style}%AI9_EndArtStyles\n{}", layer(&styled_square("Edge"))));
|
||||
assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings);
|
||||
let a = art(&r.doc);
|
||||
assert!(matches!(a.as_slice(), [n] if matches!(n.kind, NodeKind::Group { .. })), "the drawn look: {a:#?}");
|
||||
}
|
||||
|
||||
/// A listed `[Default]` style whose stroke is aligned outside comes in as the default graphic
|
||||
/// style with that stroke.
|
||||
#[test]
|
||||
|
||||
@@ -7310,6 +7310,147 @@ fn warped_type_that_draws_apart_from_its_look_comes_in_as_the_look() {
|
||||
}
|
||||
}
|
||||
|
||||
/// An art style section with style `Dashed`: a black stroke 2 units wide with butt caps, miter joins
|
||||
/// and dashes of 6 and gaps of 4, aligned to corners and path ends (`BSDashAdj`).
|
||||
fn aligned_dash_style() -> String {
|
||||
"%AI9_BeginArtStyles\n/KnownStyle :\n(Dashed) /Name ,\n/ActiveStyle :\n/CompoundFilter :\n(Chain Style Filter) 0 0 /Filter ,\n1 /Visible ,\n\
|
||||
/BasicFilter :\n(Stroke Style Filter) 0 0 /Filter ,\n1 /Visible ,\n2 /FillOrStroke ,\n/Dictionary : /NotRecorded ,\n\
|
||||
/Dictionary : /NotRecorded ,\n1 /Bool (BSDashAdj) ,\n; (kAIBeautifulStrokesParamsDictKey) ,\n\
|
||||
/StrokeStyle : 0 R\n0 0 0 1 0 0 0 XA\n0 J 0 j 2 w 10 M [6 4 ]0 d\n0 XR\n1 0 Xd\n/Def ;\n (StrokeStyle) ,\n; /Dict ;\n /Part ,\n;\n%AI9_EndArtStyles\n"
|
||||
.to_string()
|
||||
}
|
||||
|
||||
/// The open path of [`aligned_dash_file`], a corner at (80, 20), in the document's coordinates.
|
||||
fn aligned_dash_path() -> kurbo::BezPath {
|
||||
let mut bp = kurbo::BezPath::new();
|
||||
bp.move_to((20.0, 20.0));
|
||||
bp.line_to((80.0, 20.0));
|
||||
bp.line_to((80.0, 70.0));
|
||||
bp
|
||||
}
|
||||
|
||||
/// What [`aligned_dash_style`] draws along [`aligned_dash_path`], with its dashes aligned to corners
|
||||
/// and path ends by VectorCraft or (`aligned` false) not, as look operators in black.
|
||||
fn aligned_dash_look(aligned: bool) -> String {
|
||||
use vectorcraft_color::{Color, Paint};
|
||||
use vectorcraft_doc::{Dash, LineCap, LineJoin, StrokeLayer};
|
||||
let mut stroke = StrokeLayer::new(Paint::solid(Color::BLACK), 2.0);
|
||||
(stroke.cap, stroke.join, stroke.miter_limit) = (LineCap::Butt, LineJoin::Miter, 10.0);
|
||||
stroke.dash = Some(Dash { pattern: vec![6.0, 4.0], offset: 0.0, align_corners: aligned });
|
||||
let outline = vectorcraft_effects::stroke::line_outline(&aligned_dash_path(), &stroke, 2.0, 0.01);
|
||||
assert!(!outline.elements().is_empty());
|
||||
drawn_as_operators(&outline).replace("0 1 1 0 1 0 0 Xa", "0 0 0 1 0 0 0 Xa")
|
||||
}
|
||||
|
||||
/// The editing copy of [`aligned_dash_path`] under [`aligned_dash_style`], with the look `drawing`.
|
||||
fn aligned_dash_file(drawing: &str) -> String {
|
||||
aligned_dash_files(drawing, 1)
|
||||
}
|
||||
|
||||
/// [`aligned_dash_file`] with `n` such paths.
|
||||
fn aligned_dash_files(drawing: &str, n: usize) -> String {
|
||||
let own = "%_0 0 0 1 0 0 0 XA\n%_2 w\n%_20 80 m\n%_80 80 L\n%_80 30 L\n%_S\n";
|
||||
let one = format!("u\n{drawing}\nU\n9 () XW\n{own}1 (Dashed) XW\n");
|
||||
native(&(aligned_dash_style() + &layer("Art", true, &one.repeat(n))))
|
||||
}
|
||||
|
||||
/// The paths of `d` that stroke with dashes, each with whether its dashes are aligned to corners.
|
||||
fn dashed_paths(d: &Document) -> Vec<bool> {
|
||||
let mut out = vec![];
|
||||
d.walk(|n| {
|
||||
if matches!(n.kind, NodeKind::Path { .. }) {
|
||||
for i in &n.appearance.items {
|
||||
if let vectorcraft_doc::AppearanceItem::Stroke(s) = i
|
||||
&& let Some(dash) = &s.dash
|
||||
{
|
||||
out.push(dash.align_corners);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
out
|
||||
}
|
||||
|
||||
/// A stroke whose dashes are aligned to corners and path ends comes in as the path with that stroke,
|
||||
/// editable, where VectorCraft's fitting draws as its drawn look.
|
||||
#[test]
|
||||
fn dashes_aligned_to_corners_that_draw_as_the_look_come_in_live() {
|
||||
let (d, notes) = crate::ai_alone(&private(&aligned_dash_file(&aligned_dash_look(true)))).unwrap();
|
||||
assert_eq!(dashed_paths(&d), [true], "{notes:?}");
|
||||
assert!(!notes.iter().any(|w| w.contains("drawn look")), "{notes:?}");
|
||||
}
|
||||
|
||||
/// Where the look draws the dashes elsewhere (here, not fitted), the path keeps its drawn look.
|
||||
#[test]
|
||||
fn dashes_aligned_to_corners_that_draw_apart_from_the_look_keep_it() {
|
||||
let (d, notes) = crate::ai_alone(&private(&aligned_dash_file(&aligned_dash_look(false)))).unwrap();
|
||||
assert!(dashed_paths(&d).is_empty(), "{notes:?}");
|
||||
let looks = d.layers[0].children().unwrap();
|
||||
assert!(matches!(looks.as_slice(), [l] if matches!(l.kind, NodeKind::Group { .. }) && l.visual_bounds().is_some()), "{looks:#?}");
|
||||
}
|
||||
|
||||
/// The strokes with aligned dashes one import checks against their looks are limited
|
||||
/// ([`crate::import::ai::MAX_DASH_CHECKS`]), apart from the envelopes' checks: past the
|
||||
/// limit, a path that would draw as its look keeps the look.
|
||||
#[test]
|
||||
fn dashes_aligned_to_corners_past_their_checks_keep_the_look() {
|
||||
let n = crate::import::ai::MAX_DASH_CHECKS;
|
||||
let (d, notes) = crate::ai_alone(&private(&aligned_dash_files(&aligned_dash_look(true), n + 1))).unwrap();
|
||||
assert_eq!(dashed_paths(&d).len(), n, "{notes:?}");
|
||||
let looks = d.layers[0].children().unwrap().iter().filter(|c| matches!(c.kind, NodeKind::Group { .. })).count();
|
||||
assert_eq!(looks, 1);
|
||||
}
|
||||
|
||||
/// The reads of a file apart from its layers check no stroke with dashes aligned to corners in its
|
||||
/// layers against its look: the import's checks ([`crate::import::ai::MAX_DASH_CHECKS`]) are its
|
||||
/// layers' reader's, though those reads go over all of the data. Its artboards and variable library
|
||||
/// are read with no checks at all, and its swatches (and so its brushes, styles and symbols, read
|
||||
/// the same way) with none once their reader reaches the layers. The layers' reader still checks
|
||||
/// the one such stroke.
|
||||
#[test]
|
||||
fn the_reads_apart_from_the_layers_check_no_aligned_dashes() {
|
||||
use vectorcraft_testkit::ai::{sample_variable_sets, variable_library_data};
|
||||
let library = variable_library_data(&sample_variable_sets("variableAndTypes", &[]));
|
||||
let own = "%_0 0 0 1 0 0 0 XA\n%_2 w\n%_20 80 m\n%_80 80 L\n%_80 30 L\n%_S\n";
|
||||
let one = format!("u\n{}\nU\n9 () XW\n{own}1 (Dashed) XW\n", aligned_dash_look(true));
|
||||
let data = native(&(library + &aligned_dash_style() + &layer("Art", true, &one)));
|
||||
let checks = |f: &dyn Fn()| {
|
||||
crate::import::ai::DASH_CHECKS_MADE.set(0);
|
||||
f();
|
||||
crate::import::ai::DASH_CHECKS_MADE.get()
|
||||
};
|
||||
let names = crate::import::ai::Names::default;
|
||||
assert_eq!(checks(&|| drop(crate::ai_alone(&private(&data)))), 1);
|
||||
assert_eq!(checks(&|| drop(crate::import::ai::artboards(data.as_bytes(), &mut names()))), 0);
|
||||
assert_eq!(checks(&|| assert!(crate::import::ai::variables(data.as_bytes(), &mut names()).present)), 0);
|
||||
assert_eq!(checks(&|| drop(crate::import::ai::palette(data.as_bytes(), &[], &mut names()))), 0);
|
||||
}
|
||||
|
||||
/// Type under a style with dashes aligned to corners keeps its drawn look, as before, and takes no
|
||||
/// such stroke: the look check isn't made for type.
|
||||
#[test]
|
||||
fn type_with_dashes_aligned_to_corners_keeps_its_drawn_look() {
|
||||
let doc = text_document(&[("TILT\r", 0, (8200.0, 8180.0), (0.0, 0.0), 0.0)]);
|
||||
let own: String = text_object(0).lines().map(|l| format!("%_{l}\n")).collect();
|
||||
let look = format!("u\n{}\nU\n9 () XW\n", aligned_dash_look(true));
|
||||
let file = native_with_text(&(aligned_dash_style() + &layer("Art", true, &format!("{look}{own}1 (Dashed) XW\n"))), &doc);
|
||||
let (d, notes) = crate::ai_alone(&private(&file)).unwrap();
|
||||
// The look stays, and the type takes no stroke with aligned dashes.
|
||||
let kids = d.layers[0].children().unwrap();
|
||||
assert!(kids.iter().any(|c| matches!(c.kind, NodeKind::Group { .. }) && c.visual_bounds().is_some()), "{notes:?}");
|
||||
let mut aligned = false;
|
||||
d.walk(|n| {
|
||||
if matches!(n.kind, NodeKind::Text(_)) {
|
||||
aligned |= n
|
||||
.appearance
|
||||
.items
|
||||
.iter()
|
||||
.any(|i| matches!(i, vectorcraft_doc::AppearanceItem::Stroke(s) if s.dash.as_ref().is_some_and(|d| d.align_corners)));
|
||||
}
|
||||
});
|
||||
assert!(!aligned, "{notes:?}");
|
||||
}
|
||||
|
||||
/// Warped type that a text variable binds stays type with the effect live and keeps its binding,
|
||||
/// though its live warp draws apart from its look.
|
||||
#[test]
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user