mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-12 15:52:52 +00:00
Flattening for PDF/X-1a, PDF/X-3, PDF 1.3 and EPS rasterized a picture, gradient, pattern, mesh or raster effect over its whole frame when a clipping mask cropped it. The hidden part came out as opaque white and covered the art under it, on the same page and on the next one. - Flattening rasterizes clipped art only where its clipping path shows it, nested clip groups included. - Art in a clipping layer is flattened as the layer's clipping path shows it. A flattened group that also holds art from outside the layer takes the place of that art, so the layer's clipping path no longer cuts it. Documents in which no clip group hides flattened art, and no clipping layer holds it, export the same bytes as before.
59 lines
3.1 KiB
Rust
59 lines
3.1 KiB
Rust
//! Object → Flatten Transparency: transparent art becomes opaque art that looks the same.
|
|
//!
|
|
//! The targets (`ids` or the selection) split into groups of overlapping objects. Groups without
|
|
//! transparency stay as they are (their type and strokes are outlined on request). The others are
|
|
//! cut into atomic regions: the faces of the planar arrangement of every fill, outlined stroke and
|
|
//! clipping path in them ([`po::regions`]). The same paints cover each whole region, so its colour
|
|
//! is exact: those paints composited as the renderer composites them ([`Composer`], blend modes by
|
|
//! [`composite`]), with white under the finished art (or nothing with Preserve Alpha); in CMYK documents their inks
|
|
//! composite, plane by plane ([`cmyk_planes`]), and the colour is CMYK. Each region becomes a path
|
|
//! filled with that flat colour. Where gradients, patterns, images, opacity masks or raster
|
|
//! effects reach there is no single colour: those regions are rendered into one image per group,
|
|
//! clipped to them with Clip Complex Regions (else the image is a rectangle that takes in the
|
|
//! regions it overlaps). The raster/vector balance rasterizes whole groups that split into more
|
|
//! regions than it allows (all of them at 0). For files without transparency (PDF/X-1a, PDF/X-3)
|
|
//! a CMYK document's images are opaque CMYK: its colours keep their inks there too.
|
|
//!
|
|
//! Edit → Transparency Flattener Presets: the built-in presets plus the user's, saved with the
|
|
//! preferences ([`crate::Prefs::flattener_presets`]); a `preset` named anywhere options are taken
|
|
//! finds both.
|
|
//!
|
|
//! Window → Flattener Preview: the same plan, worked out without rendering, reports what flattening
|
|
//! the document would touch ([`FlattenReport`], `flattener.preview`).
|
|
|
|
use std::collections::BTreeSet;
|
|
use std::sync::Arc;
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use serde_json::{Value, json};
|
|
use vectorcraft_color::blend::{cmyk_planes, composite, planes_cmyk};
|
|
use vectorcraft_color::{BlendMode, Color, Paint};
|
|
use vectorcraft_doc::appearance::{AppearanceItem, FillLayer};
|
|
use vectorcraft_doc::cmyk::Inks;
|
|
use vectorcraft_doc::{Appearance, ColorMode, Document, Effect, ImageBlob, ImageObject, Knockout, Node, NodeId, NodeKind};
|
|
use vectorcraft_geom::{Affine, FillRule, PathData, Rect, shapes};
|
|
use vectorcraft_pathops as po;
|
|
use vectorcraft_render::effects;
|
|
|
|
use super::edit::roots_of;
|
|
use super::menucmds::{MAX_PIXELS, isolated_doc, unique_key};
|
|
use super::pathops::{node_path, outline_strokes, outline_strokes_under, separate, shape_node};
|
|
use super::{CommandSpec, EngineError, Result, Session, always, bad, bool_or, cmd, has_doc, str_param, targets, unique_name};
|
|
|
|
mod analysis;
|
|
mod apply;
|
|
mod commands;
|
|
mod compose;
|
|
mod options;
|
|
mod presets;
|
|
mod report;
|
|
|
|
pub(crate) use analysis::{outlined_text, see_through_images};
|
|
pub(crate) use apply::{expand_transparent_tile_images, flatten_document, flatten_expanded, has_transparent_tile_images};
|
|
#[cfg(test)]
|
|
pub(crate) use apply::{with_clips_ignored, with_every_region};
|
|
pub use commands::specs;
|
|
pub use options::FlattenOptions;
|
|
pub use presets::{FlattenerPreset, PRESET_EXTS, PRESET_FORMAT};
|
|
pub use report::{FlattenReport, Highlight, Overprints, report};
|