summaryrefslogtreecommitdiff
path: root/src/eval
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2022-04-10 23:23:50 +0200
committerLaurenz <laurmaedje@gmail.com>2022-04-10 23:36:36 +0200
commit34fa8df044f1491069c9ae69f1c1e73d635c8955 (patch)
tree30b9144690f55f0343a1fdbfcac6c9238c617077 /src/eval
parent29eb13ca6214461a4b0deb63d589cd39ad6d41c2 (diff)
Move language-related properties from `par` to `text`
Closes #67
Diffstat (limited to 'src/eval')
-rw-r--r--src/eval/raw.rs4
-rw-r--r--src/eval/styles.rs19
2 files changed, 20 insertions, 3 deletions
diff --git a/src/eval/raw.rs b/src/eval/raw.rs
index b0f46fc9..a83c363f 100644
--- a/src/eval/raw.rs
+++ b/src/eval/raw.rs
@@ -6,7 +6,7 @@ use super::{Fold, Resolve, Smart, StyleChain, Value};
use crate::geom::{
Align, Em, Get, Length, Numeric, Paint, Relative, Spec, SpecAxis, Stroke,
};
-use crate::library::text::{ParNode, TextNode};
+use crate::library::text::TextNode;
/// The unresolved alignment representation.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
@@ -23,7 +23,7 @@ impl Resolve for RawAlign {
type Output = Align;
fn resolve(self, styles: StyleChain) -> Self::Output {
- let dir = styles.get(ParNode::DIR);
+ let dir = styles.get(TextNode::DIR);
match self {
Self::Start => dir.start().into(),
Self::End => dir.end().into(),
diff --git a/src/eval/styles.rs b/src/eval/styles.rs
index 71293f40..f147d8cf 100644
--- a/src/eval/styles.rs
+++ b/src/eval/styles.rs
@@ -66,6 +66,14 @@ impl StyleMap {
self.0.push(Entry::Recipe(Recipe::new::<T>(func, span)));
}
+ /// Whether the map contains a style property for the given key.
+ pub fn contains<'a, K: Key<'a>>(&self, _: K) -> bool {
+ self.0
+ .iter()
+ .filter_map(|entry| entry.property())
+ .any(|property| property.key == TypeId::of::<K>())
+ }
+
/// Make `self` the first link of the `tail` chain.
///
/// The resulting style chain contains styles from `self` as well as
@@ -261,7 +269,7 @@ where
///
/// This trait is not intended to be implemented manually, but rather through
/// the `#[node]` proc-macro.
-pub trait Key<'a>: 'static {
+pub trait Key<'a>: Copy + 'static {
/// The unfolded type which this property is stored as in a style map. For
/// example, this is [`Toggle`](crate::geom::Length) for the
/// [`STRONG`](TextNode::STRONG) property.
@@ -680,6 +688,15 @@ impl<T> StyleVec<T> {
self.items.len()
}
+ /// Iterate over the contained maps. Note that zipping this with `items()`
+ /// does not yield the same result as calling `iter()` because this method
+ /// only returns maps once that are shared by consecutive items. This method
+ /// is designed for use cases where you want to check, for example, whether
+ /// any of the maps fulfills a specific property.
+ pub fn maps(&self) -> impl Iterator<Item = &StyleMap> {
+ self.maps.iter().map(|(map, _)| map)
+ }
+
/// Iterate over the contained items.
pub fn items(&self) -> std::slice::Iter<'_, T> {
self.items.iter()