summaryrefslogtreecommitdiff
path: root/src/doc.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2023-03-17 11:32:15 +0100
committerLaurenz <laurmaedje@gmail.com>2023-03-17 11:45:57 +0100
commit312197b276748e1a17258ad21837850f582a467c (patch)
tree3fd0c078a2673a98b74bc12b4d654a4c143b4e1f /src/doc.rs
parente8435df5ec718e8ecc8a2ad48e4eb3ddd1f92a72 (diff)
Counters
Diffstat (limited to 'src/doc.rs')
-rw-r--r--src/doc.rs66
1 files changed, 22 insertions, 44 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 03885b03..f575ff1f 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -14,7 +14,7 @@ use crate::geom::{
Numeric, Paint, Point, Rel, RgbaColor, Shape, Sides, Size, Stroke, Transform,
};
use crate::image::Image;
-use crate::model::{node, Content, Fold, Introspector, StableId, StyleChain};
+use crate::model::{Content, Introspector, MetaNode, StableId, StyleChain};
use crate::syntax::Span;
/// A finished document with metadata and page frames.
@@ -271,16 +271,15 @@ impl Frame {
}
/// Attach the metadata from this style chain to the frame.
- pub fn meta(&mut self, styles: StyleChain) {
- if self.is_empty() {
- return;
- }
- for meta in MetaNode::data_in(styles) {
- if matches!(meta, Meta::Hide) {
- self.clear();
- break;
+ pub fn meta(&mut self, styles: StyleChain, force: bool) {
+ if force || !self.is_empty() {
+ for meta in MetaNode::data_in(styles) {
+ if matches!(meta, Meta::Hide) {
+ self.clear();
+ break;
+ }
+ self.prepend(Point::zero(), Element::Meta(meta, self.size));
}
- self.prepend(Point::zero(), Element::Meta(meta, self.size));
}
}
@@ -607,6 +606,16 @@ pub enum Meta {
Node(Content),
}
+cast_from_value! {
+ Meta: "meta",
+}
+
+impl PartialEq for Meta {
+ fn eq(&self, other: &Self) -> bool {
+ crate::util::hash128(self) == crate::util::hash128(other)
+ }
+}
+
/// A possibly unresolved link.
#[derive(Debug, Clone, Hash)]
pub enum Link {
@@ -623,45 +632,14 @@ impl Link {
pub fn resolve<'a>(
&self,
introspector: impl FnOnce() -> &'a Introspector,
- ) -> Option<Destination> {
+ ) -> Destination {
match self {
- Self::Dest(dest) => Some(dest.clone()),
- Self::Node(id) => introspector().location(*id).map(Destination::Internal),
+ Self::Dest(dest) => dest.clone(),
+ Self::Node(id) => Destination::Internal(introspector().location(*id)),
}
}
}
-/// Host for metadata.
-///
-/// Display: Meta
-/// Category: special
-#[node]
-pub struct MetaNode {
- /// Metadata that should be attached to all elements affected by this style
- /// property.
- #[fold]
- pub data: Vec<Meta>,
-}
-
-impl Fold for Vec<Meta> {
- type Output = Self;
-
- fn fold(mut self, outer: Self::Output) -> Self::Output {
- self.extend(outer);
- self
- }
-}
-
-cast_from_value! {
- Meta: "meta",
-}
-
-impl PartialEq for Meta {
- fn eq(&self, other: &Self) -> bool {
- crate::util::hash128(self) == crate::util::hash128(other)
- }
-}
-
/// A link destination.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum Destination {