summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-07-08 22:33:44 +0200
committerLaurenz <laurmaedje@gmail.com>2021-07-08 22:33:44 +0200
commitfd0b89a1d8e4f811fcf3517d321a327a0cf72edf (patch)
tree75d247866f5db1a0ad32909da6e0fdaafa479592 /src
parent7e2c217cbc3805c4cae613baf4149cc82e10d503 (diff)
Rename Fill to Paint
Diffstat (limited to 'src')
-rw-r--r--src/exec/state.rs14
-rw-r--r--src/export/pdf.rs37
-rw-r--r--src/layout/background.rs15
-rw-r--r--src/layout/frame.rs23
-rw-r--r--src/layout/shaping.rs6
-rw-r--r--src/library/elements.rs11
-rw-r--r--src/library/mod.rs2
-rw-r--r--src/library/text.rs6
-rw-r--r--src/syntax/expr.rs4
9 files changed, 57 insertions, 61 deletions
diff --git a/src/exec/state.rs b/src/exec/state.rs
index 24e4b9f3..cbd65622 100644
--- a/src/exec/state.rs
+++ b/src/exec/state.rs
@@ -4,7 +4,7 @@ use std::rc::Rc;
use crate::color::{Color, RgbaColor};
use crate::font::{FontStretch, FontStyle, FontVariant, FontWeight, VerticalFontMetric};
use crate::geom::*;
-use crate::layout::Fill;
+use crate::layout::Paint;
use crate::paper::{Paper, PaperClass, PAPER_A4};
/// The execution state.
@@ -117,8 +117,8 @@ pub struct FontState {
pub top_edge: VerticalFontMetric,
/// The bottom end of the text bounding box.
pub bottom_edge: VerticalFontMetric,
- /// The glyph fill color / texture.
- pub fill: Fill,
+ /// Glyph color.
+ pub fill: Paint,
/// Whether the strong toggle is active or inactive. This determines
/// whether the next `*` adds or removes font weight.
pub strong: bool,
@@ -152,7 +152,7 @@ impl Default for FontState {
size: Length::pt(11.0),
top_edge: VerticalFontMetric::CapHeight,
bottom_edge: VerticalFontMetric::Baseline,
- fill: Fill::Color(Color::Rgba(RgbaColor::BLACK)),
+ fill: Paint::Color(Color::Rgba(RgbaColor::BLACK)),
strong: false,
emph: false,
strikethrough: None,
@@ -165,8 +165,10 @@ impl Default for FontState {
/// Describes a line that could be positioned over, under or on top of text.
#[derive(Debug, Copy, Clone, PartialEq, Hash)]
pub struct LineState {
- /// Stroke color of the line. Defaults to the text color if `None`.
- pub stroke: Option<Fill>,
+ /// Stroke color of the line.
+ ///
+ /// Defaults to the text color if `None`.
+ pub stroke: Option<Paint>,
/// Thickness of the line's stroke. Calling functions should attempt to
/// read this value from the appropriate font tables if this is `None`.
pub thickness: Option<Linear>,
diff --git a/src/export/pdf.rs b/src/export/pdf.rs
index 0439702f..7e55a601 100644
--- a/src/export/pdf.rs
+++ b/src/export/pdf.rs
@@ -18,7 +18,7 @@ use crate::color::Color;
use crate::font::{Em, FaceId};
use crate::geom::{self, Length, Size};
use crate::image::{Image, ImageId};
-use crate::layout::{Element, Fill, Frame, Shape};
+use crate::layout::{Element, Frame, Geometry, Paint};
/// Export a collection of frames into a PDF document.
///
@@ -142,7 +142,7 @@ impl<'a> PdfExporter<'a> {
// do that, we need to remember the active face.
let mut face = None;
let mut size = Length::zero();
- let mut fill: Option<Fill> = None;
+ let mut fill: Option<Paint> = None;
for (pos, element) in page.elements() {
let x = pos.x.to_pt() as f32;
@@ -172,30 +172,32 @@ impl<'a> PdfExporter<'a> {
text.show(Str(&shaped.encode_glyphs_be()));
}
- Element::Geometry(ref shape, fill) => {
+ Element::Geometry(ref geometry, paint) => {
content.save_state();
- write_fill(&mut content, fill);
- match *shape {
- Shape::Rect(Size { width, height }) => {
+ match *geometry {
+ Geometry::Rect(Size { width, height }) => {
let w = width.to_pt() as f32;
let h = height.to_pt() as f32;
if w > 0.0 && h > 0.0 {
+ write_fill(&mut content, paint);
content.rect(x, y - h, w, h, false, true);
}
}
- Shape::Ellipse(size) => {
+ Geometry::Ellipse(size) => {
let path = geom::Path::ellipse(size);
+ write_fill(&mut content, paint);
write_path(&mut content, x, y, &path, false, true);
}
- Shape::Line(target, stroke) => {
- write_stroke(&mut content, fill, stroke.to_pt() as f32);
+ Geometry::Line(target, thickness) => {
+ write_stroke(&mut content, paint, thickness.to_pt() as f32);
content.path(true, false).move_to(x, y).line_to(
x + target.x.to_pt() as f32,
y - target.y.to_pt() as f32,
);
}
- Shape::Path(ref path) => {
+ Geometry::Path(ref path) => {
+ write_fill(&mut content, paint);
write_path(&mut content, x, y, path, false, true)
}
}
@@ -369,18 +371,15 @@ impl<'a> PdfExporter<'a> {
}
/// Write a fill change into a content stream.
-fn write_fill(content: &mut Content, fill: Fill) {
- match fill {
- Fill::Color(Color::Rgba(c)) => {
- content.fill_rgb(c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0);
- }
- }
+fn write_fill(content: &mut Content, fill: Paint) {
+ let Paint::Color(Color::Rgba(c)) = fill;
+ content.fill_rgb(c.r as f32 / 255.0, c.g as f32 / 255.0, c.b as f32 / 255.0);
}
/// Write a stroke change into a content stream.
-fn write_stroke(content: &mut Content, fill: Fill, thickness: f32) {
- match fill {
- Fill::Color(Color::Rgba(c)) => {
+fn write_stroke(content: &mut Content, stroke: Paint, thickness: f32) {
+ match stroke {
+ Paint::Color(Color::Rgba(c)) => {
content.stroke_rgb(
c.r as f32 / 255.0,
c.g as f32 / 255.0,
diff --git a/src/layout/background.rs b/src/layout/background.rs
index 013a887a..0e93c06f 100644
--- a/src/layout/background.rs
+++ b/src/layout/background.rs
@@ -6,8 +6,8 @@ use super::*;
pub struct BackgroundNode {
/// The kind of shape to use as a background.
pub shape: BackgroundShape,
- /// The background fill.
- pub fill: Fill,
+ /// Background color / texture.
+ pub fill: Paint,
/// The child node to be filled.
pub child: AnyNode,
}
@@ -29,19 +29,16 @@ impl Layout for BackgroundNode {
for frame in &mut frames {
let mut new = Frame::new(frame.size, frame.baseline);
- let (point, shape) = match self.shape {
- BackgroundShape::Rect => (Point::zero(), Shape::Rect(frame.size)),
+ let (point, geometry) = match self.shape {
+ BackgroundShape::Rect => (Point::zero(), Geometry::Rect(frame.size)),
BackgroundShape::Ellipse => {
- (frame.size.to_point() / 2.0, Shape::Ellipse(frame.size))
+ (frame.size.to_point() / 2.0, Geometry::Ellipse(frame.size))
}
};
- let element = Element::Geometry(shape, self.fill);
- new.push(point, element);
-
let prev = std::mem::take(&mut frame.item);
+ new.push(point, Element::Geometry(geometry, self.fill));
new.push_frame(Point::zero(), prev);
-
*Rc::make_mut(&mut frame.item) = new;
}
frames
diff --git a/src/layout/frame.rs b/src/layout/frame.rs
index b6cf4645..65a55857 100644
--- a/src/layout/frame.rs
+++ b/src/layout/frame.rs
@@ -110,8 +110,9 @@ enum Child {
pub enum Element {
/// Shaped text.
Text(Text),
- /// A filled geometric shape.
- Geometry(Shape, Fill),
+ /// A geometric shape and the paint which with it should be filled or
+ /// stroked.
+ Geometry(Geometry, Paint),
/// A raster image.
Image(ImageId, Size),
}
@@ -123,8 +124,8 @@ pub struct Text {
pub face_id: FaceId,
/// The font size.
pub size: Length,
- /// The glyph's fill color.
- pub fill: Fill,
+ /// Glyph color.
+ pub fill: Paint,
/// The glyphs.
pub glyphs: Vec<Glyph>,
}
@@ -155,20 +156,20 @@ impl Text {
/// A geometric shape.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
-pub enum Shape {
- /// A rectangle with its origin in the topleft corner.
+pub enum Geometry {
+ /// A filled rectangle with its origin in the topleft corner.
Rect(Size),
- /// An ellipse with its origin in the center.
+ /// A filled ellipse with its origin in the center.
Ellipse(Size),
- /// A line to a `Point` (relative to its position) with a stroke width.
+ /// A stroked line to a point (relative to its position) with a thickness.
Line(Point, Length),
- /// A bezier path.
+ /// A filled bezier path.
Path(Path),
}
-/// How text and shapes are filled.
+/// How a fill or stroke should be painted.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
-pub enum Fill {
+pub enum Paint {
/// A solid color.
Color(Color),
}
diff --git a/src/layout/shaping.rs b/src/layout/shaping.rs
index c37300f7..9b8774cc 100644
--- a/src/layout/shaping.rs
+++ b/src/layout/shaping.rs
@@ -8,7 +8,7 @@ use super::{Element, Frame, Glyph, LayoutContext, Text};
use crate::exec::{FontState, LineState};
use crate::font::{Face, FaceId, FontStyle, LineMetrics};
use crate::geom::{Dir, Length, Point, Size};
-use crate::layout::Shape;
+use crate::layout::Geometry;
use crate::util::SliceExt;
/// The result of shaping text.
@@ -412,9 +412,7 @@ fn decorate(
let pos = Point::new(pos.x - extent, pos.y + offset);
let target = Point::new(width + 2.0 * extent, Length::zero());
- let shape = Shape::Line(target, thickness);
- let element = Element::Geometry(shape, stroke);
-
+ let element = Element::Geometry(Geometry::Line(target, thickness), stroke);
frame.push(pos, element);
};
diff --git a/src/library/elements.rs b/src/library/elements.rs
index 5271788f..c57504fb 100644
--- a/src/library/elements.rs
+++ b/src/library/elements.rs
@@ -3,9 +3,8 @@ use std::f64::consts::SQRT_2;
use decorum::N64;
use super::*;
-use crate::color::Color;
use crate::layout::{
- BackgroundNode, BackgroundShape, Fill, FixedNode, ImageNode, PadNode,
+ BackgroundNode, BackgroundShape, FixedNode, ImageNode, PadNode, Paint,
};
/// `image`: An image.
@@ -64,10 +63,10 @@ fn rect_impl(
let fixed = FixedNode { width, height, child: stack.into() };
- if let Some(color) = fill {
+ if let Some(fill) = fill {
ctx.push_into_par(BackgroundNode {
shape: BackgroundShape::Rect,
- fill: Fill::Color(color),
+ fill: Paint::Color(fill),
child: fixed.into(),
});
} else {
@@ -120,10 +119,10 @@ fn ellipse_impl(
.into(),
};
- if let Some(color) = fill {
+ if let Some(fill) = fill {
ctx.push_into_par(BackgroundNode {
shape: BackgroundShape::Ellipse,
- fill: Fill::Color(color),
+ fill: Paint::Color(fill),
child: fixed.into(),
});
} else {
diff --git a/src/library/mod.rs b/src/library/mod.rs
index 92ee9faa..abc9ff5f 100644
--- a/src/library/mod.rs
+++ b/src/library/mod.rs
@@ -16,7 +16,7 @@ pub use utility::*;
use std::fmt::{self, Display, Formatter};
use std::rc::Rc;
-use crate::color::RgbaColor;
+use crate::color::{Color, RgbaColor};
use crate::eval::{EvalContext, FuncArgs, Scope, TemplateValue, Value};
use crate::exec::{Exec, FontFamily};
use crate::font::{FontStyle, FontWeight, VerticalFontMetric};
diff --git a/src/library/text.rs b/src/library/text.rs
index 9c2863bc..e1fff9f3 100644
--- a/src/library/text.rs
+++ b/src/library/text.rs
@@ -1,6 +1,6 @@
use crate::exec::{FontState, LineState};
use crate::font::{FontStretch, FontStyle, FontWeight};
-use crate::layout::Fill;
+use crate::layout::Paint;
use super::*;
@@ -57,7 +57,7 @@ pub fn font(ctx: &mut EvalContext, args: &mut FuncArgs) -> Value {
}
if let Some(fill) = fill {
- font.fill = Fill::Color(fill);
+ font.fill = Paint::Color(fill);
}
if let Some(FamilyDef(serif)) = &serif {
@@ -244,7 +244,7 @@ fn line_impl(
// Suppress any existing strikethrough if strength is explicitly zero.
let state = thickness.map_or(true, |s| !s.is_zero()).then(|| {
Rc::new(LineState {
- stroke: stroke.map(Fill::Color),
+ stroke: stroke.map(Paint::Color),
thickness,
offset,
extent,
diff --git a/src/syntax/expr.rs b/src/syntax/expr.rs
index c4462ff8..368fe41f 100644
--- a/src/syntax/expr.rs
+++ b/src/syntax/expr.rs
@@ -33,7 +33,7 @@ pub enum Expr {
Ident(Ident),
/// An array expression: `(1, "hi", 12cm)`.
Array(ArrayExpr),
- /// A dictionary expression: `(color: #f79143, pattern: dashed)`.
+ /// A dictionary expression: `(thickness: 3pt, pattern: dashed)`.
Dict(DictExpr),
/// A template expression: `[*Hi* there!]`.
Template(TemplateExpr),
@@ -123,7 +123,7 @@ pub struct ArrayExpr {
pub items: Vec<Expr>,
}
-/// A dictionary expression: `(color: #f79143, pattern: dashed)`.
+/// A dictionary expression: `(thickness: 3pt, pattern: dashed)`.
#[derive(Debug, Clone, PartialEq)]
pub struct DictExpr {
/// The source code location.