mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-16 06:38:03 +08:00
Add color converter and debug node to use graphic
This commit is contained in:
@@ -80,6 +80,9 @@ pub const ATTR_GRADIENT_TYPE: &str = "gradient_type";
|
||||
/// List<Graphic> data for fill.
|
||||
pub const ATTR_FILL_GRAPHIC: &str = "fill_graphic";
|
||||
|
||||
/// List<Graphic> data for stroke.
|
||||
pub const ATTR_STROKE_PAINT_GRAPHIC: &str = "stroke_paint_graphic";
|
||||
|
||||
// ========================
|
||||
// TRAIT: AnyAttributeValue
|
||||
// ========================
|
||||
|
||||
@@ -171,7 +171,7 @@ fn flatten_graphic_list<T>(content: List<Graphic>, extract_variant: fn(Graphic)
|
||||
}
|
||||
|
||||
/// Converts a `Fill` enum into the `List<Graphic>` representation used as paint storage.
|
||||
/// TODO: Remove once all paint sources flow through `List<Graphic>` directly without going through the `Fill` enum.
|
||||
/// TODO: Remove once all fill paint sources flow through `List<Graphic>` directly without going through the `Fill` enum.
|
||||
pub fn fill_to_graphic_list(fill: &Fill) -> Option<List<Graphic>> {
|
||||
match fill {
|
||||
Fill::None => None,
|
||||
@@ -188,6 +188,12 @@ pub fn fill_to_graphic_list(fill: &Fill) -> Option<List<Graphic>> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a `Color` into the `List<Graphic>` representation used as paint storage.
|
||||
/// TODO: Remove once all stroke paint sources flow through `List<Graphic>` directly without going through `Stroke.color`.
|
||||
pub fn color_to_graphic_list(color: Option<Color>) -> Option<List<Graphic>> {
|
||||
color.as_ref().map(|color| List::new_from_element((*color).into()))
|
||||
}
|
||||
|
||||
/// Maps from a concrete element type to its corresponding `Graphic` enum variant,
|
||||
/// enabling type-directed casting of typed `List`s from a `Graphic` value.
|
||||
pub trait TryFromGraphic: Clone + Sized {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use core_types::Context;
|
||||
use core_types::list::{ATTR_FILL_GRAPHIC, List};
|
||||
use core_types::list::{ATTR_FILL_GRAPHIC, ATTR_STROKE_PAINT_GRAPHIC, List};
|
||||
use core_types::registry::types::{Fraction, Percentage, PixelSize};
|
||||
use core_types::transform::Footprint;
|
||||
use core_types::{Color, Ctx, num_traits};
|
||||
@@ -1008,6 +1008,29 @@ fn fill_graphic<P: IntoGraphicList + 'n + Send>(
|
||||
vectors
|
||||
}
|
||||
|
||||
/// Sets the `stroke_paint_graphic` attribute on each item of the input vector list.
|
||||
/// Used for testing of gradient and clipping-based stroke rendering until the proper Stroke node refactor lands.
|
||||
#[node_macro::node(category("Debug"))]
|
||||
fn stroke_paint_graphic<P: IntoGraphicList + 'n + Send>(
|
||||
_: impl Ctx,
|
||||
mut vectors: List<Vector>,
|
||||
#[implementations(
|
||||
List<Graphic>,
|
||||
List<Vector>,
|
||||
List<Raster<CPU>>,
|
||||
List<Raster<GPU>>,
|
||||
List<Color>,
|
||||
List<GradientStops>,
|
||||
)]
|
||||
stroke_paint_graphic: P,
|
||||
) -> List<Vector> {
|
||||
let paint_list = stroke_paint_graphic.into_graphic_list();
|
||||
for row_idx in 0..vectors.len() {
|
||||
vectors.set_attribute(ATTR_STROKE_PAINT_GRAPHIC, row_idx, paint_list.clone());
|
||||
}
|
||||
vectors
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user