diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-14 22:35:31 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-14 22:53:54 +0100 |
| commit | 89f44f220de2972452dd816fe59836ba76953d59 (patch) | |
| tree | 2749428e8e10252588bb68c0e8e9bfd150f28a9c /src/model | |
| parent | 2a86e4db0bb3894d1cc3b94e1a1af31a6cd87b80 (diff) | |
Bibliography and citations
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/typeset.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/src/model/typeset.rs b/src/model/typeset.rs index 8719ea0c..fe433288 100644 --- a/src/model/typeset.rs +++ b/src/model/typeset.rs @@ -35,7 +35,7 @@ pub fn typeset(world: Tracked<dyn World>, content: &Content) -> SourceResult<Doc document = (library.items.layout)(&mut vt, content, styles)?; iter += 1; - if iter >= 5 || introspector.update(&document) { + if iter >= 5 || introspector.update(&document.pages) { break; } } @@ -49,13 +49,10 @@ pub fn typeset(world: Tracked<dyn World>, content: &Content) -> SourceResult<Doc /// [Vm](crate::eval::Vm) for typesetting. pub struct Vt<'a> { /// The compilation environment. - #[doc(hidden)] pub world: Tracked<'a, dyn World>, /// Provides stable identities to nodes. - #[doc(hidden)] pub provider: TrackedMut<'a, StabilityProvider>, /// Provides access to information about the document. - #[doc(hidden)] pub introspector: Tracked<'a, Introspector>, } @@ -127,7 +124,6 @@ impl StabilityProvider { } /// Provides access to information about the document. -#[doc(hidden)] pub struct Introspector { init: bool, nodes: Vec<(StableId, Content)>, @@ -136,7 +132,7 @@ pub struct Introspector { impl Introspector { /// Create a new introspector. - fn new() -> Self { + pub fn new() -> Self { Self { init: false, nodes: vec![], @@ -146,10 +142,10 @@ impl Introspector { /// Update the information given new frames and return whether we can stop /// layouting. - fn update(&mut self, document: &Document) -> bool { + pub fn update(&mut self, frames: &[Frame]) -> bool { self.nodes.clear(); - for (i, frame) in document.pages.iter().enumerate() { + for (i, frame) in frames.iter().enumerate() { let page = NonZeroUsize::new(1 + i).unwrap(); self.extract(frame, page, Transform::identity()); } @@ -171,6 +167,11 @@ impl Introspector { true } + /// Iterate over all nodes. + pub fn iter(&self) -> impl Iterator<Item = &Content> { + self.nodes.iter().map(|(_, node)| node) + } + /// Extract metadata from a frame. fn extract(&mut self, frame: &Frame, page: NonZeroUsize, ts: Transform) { for (pos, element) in frame.elements() { @@ -199,12 +200,12 @@ impl Introspector { #[comemo::track] impl Introspector { /// Whether this introspector is not yet initialized. - fn init(&self) -> bool { + pub fn init(&self) -> bool { self.init } /// Locate all metadata matches for the given selector. - fn locate(&self, selector: Selector) -> Vec<(StableId, &Content)> { + pub fn locate(&self, selector: Selector) -> Vec<(StableId, &Content)> { let nodes = self.locate_impl(&selector); let mut queries = self.queries.borrow_mut(); if !queries.iter().any(|(prev, _)| prev == &selector) { |
