mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Move paint and colors into geom
This commit is contained in:
parent
f4ed775df0
commit
d4cc8c775d
@ -1,11 +1,9 @@
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::color::{Color, RgbaColor};
|
|
||||||
use crate::font::{
|
use crate::font::{
|
||||||
FontFamily, FontStretch, FontStyle, FontVariant, FontWeight, VerticalFontMetric,
|
FontFamily, FontStretch, FontStyle, FontVariant, FontWeight, VerticalFontMetric,
|
||||||
};
|
};
|
||||||
use crate::geom::*;
|
use crate::geom::*;
|
||||||
use crate::layout::Paint;
|
|
||||||
use crate::paper::{PaperClass, ISO_A4};
|
use crate::paper::{PaperClass, ISO_A4};
|
||||||
|
|
||||||
/// Defines an set of properties a template can be instantiated with.
|
/// Defines an set of properties a template can be instantiated with.
|
||||||
|
@ -4,9 +4,8 @@ use std::fmt::{self, Debug, Formatter};
|
|||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use super::{ops, Array, Dict, Function, Str, Template};
|
use super::{ops, Array, Dict, Function, Str, Template};
|
||||||
use crate::color::{Color, RgbaColor};
|
|
||||||
use crate::diag::StrResult;
|
use crate::diag::StrResult;
|
||||||
use crate::geom::{Angle, Fractional, Length, Linear, Relative};
|
use crate::geom::{Angle, Color, Fractional, Length, Linear, Relative, RgbaColor};
|
||||||
use crate::syntax::Spanned;
|
use crate::syntax::Spanned;
|
||||||
use crate::util::EcoString;
|
use crate::util::EcoString;
|
||||||
|
|
||||||
|
@ -13,11 +13,10 @@ use pdf_writer::{Content, Filter, Finish, Name, PdfWriter, Rect, Ref, Str, Unico
|
|||||||
use ttf_parser::{name_id, GlyphId, Tag};
|
use ttf_parser::{name_id, GlyphId, Tag};
|
||||||
|
|
||||||
use super::subset;
|
use super::subset;
|
||||||
use crate::color::Color;
|
|
||||||
use crate::font::{find_name, FaceId, FontStore};
|
use crate::font::{find_name, FaceId, FontStore};
|
||||||
use crate::geom::{self, Em, Length, Size};
|
use crate::geom::{self, Color, Em, Length, Paint, Size};
|
||||||
use crate::image::{Image, ImageId, ImageStore};
|
use crate::image::{Image, ImageId, ImageStore};
|
||||||
use crate::layout::{Element, Frame, Geometry, Paint};
|
use crate::layout::{Element, Frame, Geometry};
|
||||||
use crate::Context;
|
use crate::Context;
|
||||||
|
|
||||||
/// Export a collection of frames into a PDF document.
|
/// Export a collection of frames into a PDF document.
|
||||||
|
@ -10,6 +10,7 @@ mod fr;
|
|||||||
mod gen;
|
mod gen;
|
||||||
mod length;
|
mod length;
|
||||||
mod linear;
|
mod linear;
|
||||||
|
mod paint;
|
||||||
mod path;
|
mod path;
|
||||||
mod point;
|
mod point;
|
||||||
mod relative;
|
mod relative;
|
||||||
@ -25,6 +26,7 @@ pub use fr::*;
|
|||||||
pub use gen::*;
|
pub use gen::*;
|
||||||
pub use length::*;
|
pub use length::*;
|
||||||
pub use linear::*;
|
pub use linear::*;
|
||||||
|
pub use paint::*;
|
||||||
pub use path::*;
|
pub use path::*;
|
||||||
pub use point::*;
|
pub use point::*;
|
||||||
pub use relative::*;
|
pub use relative::*;
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
//! Color handling.
|
use std::fmt::Display;
|
||||||
|
|
||||||
use std::fmt::{self, Debug, Display, Formatter};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
use super::*;
|
||||||
|
|
||||||
|
/// How a fill or stroke should be painted.
|
||||||
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Paint {
|
||||||
|
/// A solid color.
|
||||||
|
Color(Color),
|
||||||
|
}
|
||||||
|
|
||||||
/// A color in a dynamic format.
|
/// A color in a dynamic format.
|
||||||
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
@ -4,9 +4,8 @@ use std::rc::Rc;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use super::{Constrained, Constraints};
|
use super::{Constrained, Constraints};
|
||||||
use crate::color::Color;
|
|
||||||
use crate::font::FaceId;
|
use crate::font::FaceId;
|
||||||
use crate::geom::{Em, Length, Path, Point, Size};
|
use crate::geom::{Em, Length, Paint, Path, Point, Size};
|
||||||
use crate::image::ImageId;
|
use crate::image::ImageId;
|
||||||
|
|
||||||
/// A finished layout with elements at fixed positions.
|
/// A finished layout with elements at fixed positions.
|
||||||
@ -36,7 +35,7 @@ pub enum Element {
|
|||||||
/// Shaped text.
|
/// Shaped text.
|
||||||
Text(Text),
|
Text(Text),
|
||||||
/// A geometric shape and the paint which with it should be filled or
|
/// A geometric shape and the paint which with it should be filled or
|
||||||
/// stroked.
|
/// stroked (which one depends on the kind of geometry).
|
||||||
Geometry(Geometry, Paint),
|
Geometry(Geometry, Paint),
|
||||||
/// A raster image.
|
/// A raster image.
|
||||||
Image(ImageId, Size),
|
Image(ImageId, Size),
|
||||||
@ -83,13 +82,6 @@ pub enum Geometry {
|
|||||||
Path(Path),
|
Path(Path),
|
||||||
}
|
}
|
||||||
|
|
||||||
/// How a fill or stroke should be painted.
|
|
||||||
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
|
|
||||||
pub enum Paint {
|
|
||||||
/// A solid color.
|
|
||||||
Color(Color),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
/// Create a new, empty frame.
|
/// Create a new, empty frame.
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
|
@ -33,7 +33,6 @@
|
|||||||
pub mod diag;
|
pub mod diag;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod eval;
|
pub mod eval;
|
||||||
pub mod color;
|
|
||||||
pub mod export;
|
pub mod export;
|
||||||
pub mod font;
|
pub mod font;
|
||||||
pub mod geom;
|
pub mod geom;
|
||||||
|
@ -5,9 +5,7 @@ use decorum::N64;
|
|||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::diag::Error;
|
use crate::diag::Error;
|
||||||
use crate::layout::{
|
use crate::layout::{BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode};
|
||||||
BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode, Paint,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// `image`: An image.
|
/// `image`: An image.
|
||||||
pub fn image(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
pub fn image(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
||||||
|
@ -16,7 +16,6 @@ pub use utility::*;
|
|||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use crate::color::{Color, RgbaColor};
|
|
||||||
use crate::diag::{At, TypResult};
|
use crate::diag::{At, TypResult};
|
||||||
use crate::eval::{Args, Array, EvalContext, Scope, State, Str, Template, Value};
|
use crate::eval::{Args, Array, EvalContext, Scope, State, Str, Template, Value};
|
||||||
use crate::font::{FontFamily, FontStretch, FontStyle, FontWeight, VerticalFontMetric};
|
use crate::font::{FontFamily, FontStretch, FontStyle, FontWeight, VerticalFontMetric};
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use super::*;
|
use super::*;
|
||||||
use crate::layout::{Decoration, LineDecoration, LineKind, Paint};
|
use crate::layout::{Decoration, LineDecoration, LineKind};
|
||||||
|
|
||||||
/// `font`: Configure the font.
|
/// `font`: Configure the font.
|
||||||
pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
pub fn font(ctx: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
||||||
|
@ -2,7 +2,6 @@ use std::cmp::Ordering;
|
|||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::color::{Color, RgbaColor};
|
|
||||||
|
|
||||||
/// `assert`: Ensure that a condition is fulfilled.
|
/// `assert`: Ensure that a condition is fulfilled.
|
||||||
pub fn assert(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
pub fn assert(_: &mut EvalContext, args: &mut Args) -> TypResult<Value> {
|
||||||
|
@ -9,15 +9,16 @@ use tiny_skia as sk;
|
|||||||
use ttf_parser::{GlyphId, OutlineBuilder};
|
use ttf_parser::{GlyphId, OutlineBuilder};
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
use typst::color::{Color, RgbaColor};
|
|
||||||
use typst::diag::Error;
|
use typst::diag::Error;
|
||||||
use typst::eval::{State, Value};
|
use typst::eval::{State, Value};
|
||||||
use typst::font::Face;
|
use typst::font::Face;
|
||||||
use typst::geom::{self, Length, PathElement, Point, Sides, Size};
|
use typst::geom::{
|
||||||
|
self, Color, Length, Paint, PathElement, Point, RgbaColor, Sides, Size,
|
||||||
|
};
|
||||||
use typst::image::Image;
|
use typst::image::Image;
|
||||||
#[cfg(feature = "layout-cache")]
|
#[cfg(feature = "layout-cache")]
|
||||||
use typst::layout::LayoutTree;
|
use typst::layout::LayoutTree;
|
||||||
use typst::layout::{layout, Element, Frame, Geometry, Paint, Text};
|
use typst::layout::{layout, Element, Frame, Geometry, Text};
|
||||||
use typst::loading::FsLoader;
|
use typst::loading::FsLoader;
|
||||||
use typst::parse::Scanner;
|
use typst::parse::Scanner;
|
||||||
use typst::source::SourceFile;
|
use typst::source::SourceFile;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user