summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2024-01-16 14:49:52 +0100
committerLaurenz <laurmaedje@gmail.com>2024-01-16 14:52:50 +0100
commit7cb257a1accdf0af99b7210a2db53ea562764e15 (patch)
treea513a9465ebc2d830b889ed180a8ee0747a6e031
parent55a50ace1e72d739769c38cc365742aa723c5221 (diff)
More consistent naming
-rw-r--r--crates/typst-pdf/src/outline.rs2
-rw-r--r--crates/typst/src/engine.rs2
-rw-r--r--crates/typst/src/foundations/cast.rs2
-rw-r--r--crates/typst/src/foundations/content.rs29
-rw-r--r--crates/typst/src/foundations/selector.rs2
-rw-r--r--crates/typst/src/introspection/counter.rs2
-rw-r--r--crates/typst/src/introspection/state.rs2
-rw-r--r--crates/typst/src/layout/align.rs32
-rw-r--r--crates/typst/src/layout/flow.rs47
-rw-r--r--crates/typst/src/layout/frame.rs6
-rw-r--r--crates/typst/src/layout/grid/mod.rs6
-rw-r--r--crates/typst/src/layout/inline/mod.rs18
-rw-r--r--crates/typst/src/layout/spacing.rs6
-rw-r--r--crates/typst/src/layout/stack.rs8
-rw-r--r--crates/typst/src/layout/transform.rs10
-rw-r--r--crates/typst/src/math/accent.rs2
-rw-r--r--crates/typst/src/math/equation.rs8
-rw-r--r--crates/typst/src/math/lr.rs2
-rw-r--r--crates/typst/src/math/matrix.rs10
-rw-r--r--crates/typst/src/math/mod.rs8
-rw-r--r--crates/typst/src/math/row.rs12
-rw-r--r--crates/typst/src/math/underover.rs6
-rw-r--r--crates/typst/src/model/bibliography.rs8
-rw-r--r--crates/typst/src/model/cite.rs2
-rw-r--r--crates/typst/src/model/document.rs4
-rw-r--r--crates/typst/src/model/enum.rs5
-rw-r--r--crates/typst/src/model/figure.rs5
-rw-r--r--crates/typst/src/model/footnote.rs7
-rw-r--r--crates/typst/src/model/list.rs5
-rw-r--r--crates/typst/src/model/table.rs6
-rw-r--r--crates/typst/src/model/terms.rs2
-rw-r--r--crates/typst/src/realize/mod.rs28
-rw-r--r--crates/typst/src/text/shift.rs2
-rw-r--r--crates/typst/src/visualize/image/mod.rs6
34 files changed, 150 insertions, 152 deletions
diff --git a/crates/typst-pdf/src/outline.rs b/crates/typst-pdf/src/outline.rs
index 172f6d3c..23893873 100644
--- a/crates/typst-pdf/src/outline.rs
+++ b/crates/typst-pdf/src/outline.rs
@@ -19,7 +19,7 @@ pub(crate) fn write_outline(ctx: &mut PdfContext) -> Option<Ref> {
let mut last_skipped_level = None;
let elements = ctx.document.introspector.query(&HeadingElem::elem().select());
for elem in elements.iter() {
- let heading = elem.to::<HeadingElem>().unwrap();
+ let heading = elem.to_packed::<HeadingElem>().unwrap();
let leaf = HeadingNode::leaf(heading);
if leaf.bookmarked {
diff --git a/crates/typst/src/engine.rs b/crates/typst/src/engine.rs
index 7f094578..a5408d29 100644
--- a/crates/typst/src/engine.rs
+++ b/crates/typst/src/engine.rs
@@ -1,3 +1,5 @@
+//! Definition of the central compilation context.
+
use std::sync::atomic::{AtomicUsize, Ordering};
use comemo::{Track, Tracked, TrackedMut, Validate};
diff --git a/crates/typst/src/foundations/cast.rs b/crates/typst/src/foundations/cast.rs
index 2f7e1dad..9c25aa8e 100644
--- a/crates/typst/src/foundations/cast.rs
+++ b/crates/typst/src/foundations/cast.rs
@@ -256,7 +256,7 @@ impl FromValue for Value {
impl<T: NativeElement + FromValue> FromValue for Packed<T> {
fn from_value(mut value: Value) -> StrResult<Self> {
if let Value::Content(content) = value {
- match content.to_packed::<T>() {
+ match content.into_packed::<T>() {
Ok(packed) => return Ok(packed),
Err(content) => value = Value::Content(content),
}
diff --git a/crates/typst/src/foundations/content.rs b/crates/typst/src/foundations/content.rs
index 3ba458af..52198642 100644
--- a/crates/typst/src/foundations/content.rs
+++ b/crates/typst/src/foundations/content.rs
@@ -240,20 +240,25 @@ impl Content {
}
/// Downcasts the element to a packed value.
- pub fn to<T: NativeElement>(&self) -> Option<&Packed<T>> {
+ pub fn to_packed<T: NativeElement>(&self) -> Option<&Packed<T>> {
Packed::from_ref(self)
}
/// Downcasts the element to a mutable packed value.
- pub fn to_mut<T: NativeElement>(&mut self) -> Option<&mut Packed<T>> {
+ pub fn to_packed_mut<T: NativeElement>(&mut self) -> Option<&mut Packed<T>> {
Packed::from_mut(self)
}
/// Downcasts the element into an owned packed value.
- pub fn to_packed<T: NativeElement>(self) -> Result<Packed<T>, Self> {
+ pub fn into_packed<T: NativeElement>(self) -> Result<Packed<T>, Self> {
Packed::from_owned(self)
}
+ /// Extract the raw underlying element.
+ pub fn unpack<T: NativeElement>(self) -> Result<T, Self> {
+ self.into_packed::<T>().map(Packed::unpack)
+ }
+
/// Makes sure the content is not shared and returns a mutable reference to
/// the inner data.
fn make_mut(&mut self) -> &mut Inner<dyn Bounds> {
@@ -309,7 +314,7 @@ impl Content {
/// Whether the content is an empty sequence.
pub fn is_empty(&self) -> bool {
- let Some(sequence) = self.to::<SequenceElem>() else {
+ let Some(sequence) = self.to_packed::<SequenceElem>() else {
return false;
};
@@ -323,7 +328,7 @@ impl Content {
/// Access the children if this is a sequence.
pub fn to_sequence(&self) -> Option<impl Iterator<Item = &Prehashed<Content>>> {
- let sequence = self.to::<SequenceElem>()?;
+ let sequence = self.to_packed::<SequenceElem>()?;
Some(sequence.children.iter())
}
@@ -338,7 +343,7 @@ impl Content {
/// Access the child and styles.
pub fn to_styled(&self) -> Option<(&Content, &Styles)> {
- let styled = self.to::<StyledElem>()?;
+ let styled = self.to_packed::<StyledElem>()?;
let child = styled.child();
let styles = styled.styles();
Some((child, styles))
@@ -364,7 +369,7 @@ impl Content {
/// Style this content with a style entry.
pub fn styled(mut self, style: impl Into<Style>) -> Self {
- if let Some(style_elem) = self.to_mut::<StyledElem>() {
+ if let Some(style_elem) = self.to_packed_mut::<StyledElem>() {
style_elem.styles.apply_one(style.into());
self
} else {
@@ -378,7 +383,7 @@ impl Content {
return self;
}
- if let Some(style_elem) = self.to_mut::<StyledElem>() {
+ if let Some(style_elem) = self.to_packed_mut::<StyledElem>() {
style_elem.styles.apply(styles);
self
} else {
@@ -617,7 +622,7 @@ impl Add for Content {
fn add(self, mut rhs: Self) -> Self::Output {
let mut lhs = self;
- match (lhs.to_mut::<SequenceElem>(), rhs.to_mut::<SequenceElem>()) {
+ match (lhs.to_packed_mut::<SequenceElem>(), rhs.to_packed_mut::<SequenceElem>()) {
(Some(seq_lhs), Some(rhs)) => {
seq_lhs.children.extend(rhs.children.iter().cloned());
lhs
@@ -640,7 +645,7 @@ impl<'a> Add<&'a Self> for Content {
fn add(self, rhs: &'a Self) -> Self::Output {
let mut lhs = self;
- match (lhs.to_mut::<SequenceElem>(), rhs.to::<SequenceElem>()) {
+ match (lhs.to_packed_mut::<SequenceElem>(), rhs.to_packed::<SequenceElem>()) {
(Some(seq_lhs), Some(rhs)) => {
seq_lhs.children.extend(rhs.children.iter().cloned());
lhs
@@ -651,7 +656,7 @@ impl<'a> Add<&'a Self> for Content {
}
(None, Some(_)) => {
let mut rhs = rhs.clone();
- rhs.to_mut::<SequenceElem>()
+ rhs.to_packed_mut::<SequenceElem>()
.unwrap()
.children
.insert(0, Prehashed::new(lhs));
@@ -729,7 +734,7 @@ impl<T: NativeElement> Bounds for T {
}
fn dyn_eq(&self, other: &Content) -> bool {
- let Some(other) = other.to::<Self>() else {
+ let Some(other) = other.to_packed::<Self>() else {
return false;
};
*self == **other
diff --git a/crates/typst/src/foundations/selector.rs b/crates/typst/src/foundations/selector.rs
index 05bc480e..0cf3214c 100644
--- a/crates/typst/src/foundations/selector.rs
+++ b/crates/typst/src/foundations/selector.rs
@@ -140,7 +140,7 @@ impl Selector {
}
Self::Label(label) => target.label() == Some(*label),
Self::Regex(regex) => target
- .to::<TextElem>()
+ .to_packed::<TextElem>()
.map_or(false, |elem| regex.is_match(elem.text())),
Self::Can(cap) => target.func().can_type_id(*cap),
Self::Or(selectors) => selectors.iter().any(move |sel| sel.matches(target)),
diff --git a/crates/typst/src/introspection/counter.rs b/crates/typst/src/introspection/counter.rs
index e4bb282f..2b4ccbbb 100644
--- a/crates/typst/src/introspection/counter.rs
+++ b/crates/typst/src/introspection/counter.rs
@@ -723,7 +723,7 @@ impl ManualPageCounter {
match item {
FrameItem::Group(group) => self.visit(engine, &group.frame)?,
FrameItem::Meta(Meta::Elem(elem), _) => {
- let Some(elem) = elem.to::<UpdateElem>() else { continue };
+ let Some(elem) = elem.to_packed::<UpdateElem>() else { continue };
if *elem.key() == CounterKey::Page {
let mut state = CounterState(smallvec![self.logical]);
state.update(engine, elem.update.clone())?;
diff --git a/crates/typst/src/introspection/state.rs b/crates/typst/src/introspection/state.rs
index 1f593549..4cfa6754 100644
--- a/crates/typst/src/introspection/state.rs
+++ b/crates/typst/src/introspection/state.rs
@@ -237,7 +237,7 @@ impl State {
let mut stops = eco_vec![state.clone()];
for elem in introspector.query(&self.selector()) {
- let elem = elem.to::<UpdateElem>().unwrap();
+ let elem = elem.to_packed::<UpdateElem>().unwrap();
match elem.update() {
StateUpdate::Set(value) => state = value.clone(),
StateUpdate::Func(func) => state = func.call(&mut engine, [state])?,
diff --git a/crates/typst/src/layout/align.rs b/crates/typst/src/layout/align.rs
index 3dbba643..e6b56f18 100644
--- a/crates/typst/src/layout/align.rs
+++ b/crates/typst/src/layout/align.rs
@@ -122,7 +122,7 @@ impl Alignment {
}
/// Normalize the alignment to a LTR-TTB space.
- pub fn fix(self, text_dir: Dir) -> Axes<FixedAlign> {
+ pub fn fix(self, text_dir: Dir) -> Axes<FixedAlignment> {
Axes::new(
self.x().unwrap_or_default().fix(text_dir),
self.y().unwrap_or_default().fix(),
@@ -227,7 +227,7 @@ impl Fold for Alignment {
}
impl Resolve for Alignment {
- type Output = Axes<FixedAlign>;
+ type Output = Axes<FixedAlignment>;
fn resolve(self, styles: StyleChain) -> Self::Output {
self.fix(TextElem::dir_in(styles))
@@ -269,13 +269,13 @@ impl HAlignment {
}
/// Resolve the axis alignment based on the horizontal direction.
- pub const fn fix(self, dir: Dir) -> FixedAlign {
+ pub const fn fix(self, dir: Dir) -> FixedAlignment {
match (self, dir.is_positive()) {
- (Self::Start, true) | (Self::End, false) => FixedAlign::Start,
- (Self::Left, _) => FixedAlign::Start,
- (Self::Center, _) => FixedAlign::Center,
- (Self::Right, _) => FixedAlign::End,
- (Self::End, true) | (Self::Start, false) => FixedAlign::End,
+ (Self::Start, true) | (Self::End, false) => FixedAlignment::Start,
+ (Self::Left, _) => FixedAlignment::Start,
+ (Self::Center, _) => FixedAlignment::Center,
+ (Self::Right, _) => FixedAlignment::End,
+ (Self::End, true) | (Self::Start, false) => FixedAlignment::End,
}
}
}
@@ -307,7 +307,7 @@ impl From<HAlignment> for Alignment {
}
impl Resolve for HAlignment {
- type Output = FixedAlign;
+ type Output = FixedAlignment;
fn resolve(self, styles: StyleChain) -> Self::Output {
self.fix(TextElem::dir_in(styles))
@@ -343,11 +343,11 @@ impl VAlignment {
}
/// Turns into a fixed alignment.
- pub const fn fix(self) -> FixedAlign {
+ pub const fn fix(self) -> FixedAlignment {
match self {
- Self::Top => FixedAlign::Start,
- Self::Horizon => FixedAlign::Center,
- Self::Bottom => FixedAlign::End,
+ Self::Top => FixedAlignment::Start,
+ Self::Horizon => FixedAlignment::Center,
+ Self::Bottom => FixedAlignment::End,
}
}
}
@@ -390,13 +390,13 @@ cast! {
/// For horizontal alignment, start is globally left and for vertical alignment
/// it is globally top.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
-pub enum FixedAlign {
+pub enum FixedAlignment {
Start,
Center,
End,
}
-impl FixedAlign {
+impl FixedAlignment {
/// Returns the position of this alignment in a container with the given
/// extent.
pub fn position(self, extent: Abs) -> Abs {
@@ -408,7 +408,7 @@ impl FixedAlign {
}
}
-impl From<Side> for FixedAlign {
+impl From<Side> for FixedAlignment {
fn from(side: Side) -> Self {
match side {
Side::Left => Self::Start,
diff --git a/crates/typst/src/layout/flow.rs b/crates/typst/src/layout/flow.rs
index 65774c69..f5d44d9b 100644
--- a/crates/typst/src/layout/flow.rs
+++ b/crates/typst/src/layout/flow.rs
@@ -7,9 +7,9 @@ use crate::foundations::{
};
use crate::introspection::{Meta, MetaElem};
use crate::layout::{
- Abs, AlignElem, Axes, BlockElem, ColbreakElem, ColumnsElem, FixedAlign, Fr, Fragment,
- Frame, FrameItem, Layout, PlaceElem, Point, Regions, Rel, Size, Spacing, VAlignment,
- VElem,
+ Abs, AlignElem, Axes, BlockElem, ColbreakElem, ColumnsElem, FixedAlignment, Fr,
+ Fragment, Frame, FrameItem, Layout, PlaceElem, Point, Regions, Rel, Size, Spacing,
+ VAlignment, VElem,
};
use crate::model::{FootnoteElem, FootnoteEntry, ParElem};
use crate::util::Numeric;
@@ -53,9 +53,9 @@ impl Layout for Packed<FlowElem> {
styles = outer.chain(map);
}
- if let Some(elem) = child.to::<VElem>() {
+ if let Some(elem) = child.to_packed::<VElem>() {
layouter.layout_spacing(engine, elem, styles)?;
- } else if let Some(elem) = child.to::<ParElem>() {
+ } else if let Some(elem) = child.to_packed::<ParElem>() {
layouter.layout_par(engine, elem, styles)?;
} else if child.is::<LineElem>()
|| child.is::<RectElem>()
@@ -73,11 +73,11 @@ impl Layout for Packed<FlowElem> {
frame.meta(styles, true);
layouter.items.push(FlowItem::Frame {
frame,
- align: Axes::splat(FixedAlign::Start),
+ align: Axes::splat(FixedAlignment::Start),
sticky: true,
movable: false,
});
- } else if let Some(placed) = child.to::<PlaceElem>() {
+ } else if let Some(placed) = child.to_packed::<PlaceElem>() {
layouter.layout_placed(engine, placed, styles)?;
} else if child.can::<dyn Layout>() {
layouter.layout_multiple(engine, child, styles)?;
@@ -139,12 +139,12 @@ enum FlowItem {
/// A frame for a layouted block, how to align it, whether it sticks to the
/// item after it (for orphan prevention), and whether it is movable
/// (to keep it together with its footnotes).
- Frame { frame: Frame, align: Axes<FixedAlign>, sticky: bool, movable: bool },
+ Frame { frame: Frame, align: Axes<FixedAlignment>, sticky: bool, movable: bool },
/// An absolutely placed frame.
Placed {
frame: Frame,
- x_align: FixedAlign,
- y_align: Smart<Option<FixedAlign>>,
+ x_align: FixedAlignment,
+ y_align: Smart<Option<FixedAlignment>>,
delta: Axes<Rel<Abs>>,
float: bool,
clearance: Abs,
@@ -308,7 +308,7 @@ impl<'a> FlowLayouter<'a> {
let clearance = placed.clearance(styles);
let alignment = placed.alignment(styles);
let delta = Axes::new(placed.dx(styles), placed.dy(styles)).resolve(styles);
- let x_align = alignment.map_or(FixedAlign::Center, |align| {
+ let x_align = alignment.map_or(FixedAlignment::Center, |align| {
align.x().unwrap_or_default().resolve(styles)
});
let y_align = alignment.map(|align| align.y().map(VAlignment::fix));
@@ -339,7 +339,7 @@ impl<'a> FlowLayouter<'a> {
}
// How to align the block.
- let align = if let Some(align) = block.to::<AlignElem>() {
+ let align = if let Some(align) = block.to_packed::<AlignElem>() {
align.alignment(styles)
} else if let Some((_, local)) = block.to_styled() {
AlignElem::alignment_in(styles.chain(local))
@@ -436,15 +436,18 @@ impl<'a> FlowLayouter<'a> {
let ratio = (self.regions.size.y
- (frame.height() + clearance) / 2.0)
/ self.regions.full;
- let better_align =
- if ratio <= 0.5 { FixedAlign::End } else { FixedAlign::Start };
+ let better_align = if ratio <= 0.5 {
+ FixedAlignment::End
+ } else {
+ FixedAlignment::Start
+ };
*y_align = Smart::Custom(Some(better_align));
}
// Add some clearance so that the float doesn't touch the main
// content.
frame.size_mut().y += clearance;
- if *y_align == Smart::Custom(Some(FixedAlign::End)) {
+ if *y_align == Smart::Custom(Some(FixedAlignment::End)) {
frame.translate(Point::with_y(clearance));
}
@@ -506,10 +509,10 @@ impl<'a> FlowLayouter<'a> {
}
FlowItem::Placed { float: false, .. } => {}
FlowItem::Placed { frame, float: true, y_align, .. } => match y_align {
- Smart::Custom(Some(FixedAlign::Start)) => {
+ Smart::Custom(Some(FixedAlignment::Start)) => {
float_top_height += frame.height()
}
- Smart::Custom(Some(FixedAlign::End)) => {
+ Smart::Custom(Some(FixedAlignment::End)) => {
float_bottom_height += frame.height()
}
_ => {}
@@ -535,7 +538,7 @@ impl<'a> FlowLayouter<'a> {
}
let mut output = Frame::soft(size);
- let mut ruler = FixedAlign::Start;
+ let mut ruler = FixedAlignment::Start;
let mut float_top_offset = Abs::zero();
let mut offset = float_top_height;
let mut float_bottom_offset = Abs::zero();
@@ -563,12 +566,12 @@ impl<'a> FlowLayouter<'a> {
let x = x_align.position(size.x - frame.width());
let y = if float {
match y_align {
- Smart::Custom(Some(FixedAlign::Start)) => {
+ Smart::Custom(Some(FixedAlignment::Start)) => {
let y = float_top_offset;
float_top_offset += frame.height();
y
}
- Smart::Custom(Some(FixedAlign::End)) => {
+ Smart::Custom(Some(FixedAlignment::End)) => {
let y = size.y - footnote_height - float_bottom_height
+ float_bottom_offset;
float_bottom_offset += frame.height();
@@ -744,7 +747,9 @@ fn find_footnotes(notes: &mut Vec<Packed<FootnoteElem>>, frame: &Frame) {
FrameItem::Meta(Meta::Elem(content), _)
if !notes.iter().any(|note| note.location() == content.location()) =>
{
- let Some(footnote) = content.to::<FootnoteElem>() else { continue };
+ let Some(footnote) = content.to_packed::<FootnoteElem>() else {
+ continue;
+ };
notes.push(footnote.clone());
}
_ => {}
diff --git a/crates/typst/src/layout/frame.rs b/crates/typst/src/layout/frame.rs
index 40dbba8e..43cab1f4 100644
--- a/crates/typst/src/layout/frame.rs
+++ b/crates/typst/src/layout/frame.rs
@@ -9,7 +9,7 @@ use ecow::{eco_format, EcoString};
use crate::foundations::{cast, dict, Dict, Repr, StyleChain, Value};
use crate::introspection::{Meta, MetaElem};
use crate::layout::{
- Abs, Axes, Corners, FixedAlign, Length, Point, Rel, Sides, Size, Transform,
+ Abs, Axes, Corners, FixedAlignment, Length, Point, Rel, Sides, Size, Transform,
};
use crate::syntax::Span;
use crate::text::TextItem;
@@ -259,9 +259,9 @@ impl Frame {
/// Resize the frame to a new size, distributing new space according to the
/// given alignments.
- pub fn resize(&mut self, target: Size, align: Axes<FixedAlign>) {
+ pub fn resize(&mut self, target: Size, align: Axes<FixedAlignment>) {
if self.size != target {
- let offset = align.zip_map(target - self.size, FixedAlign::position);
+ let offset = align.zip_map(target - self.size, FixedAlignment::position);
self.size = target;
self.translate(offset.to_point());
}
diff --git a/crates/typst/src/layout/grid/mod.rs b/crates/typst/src/layout/grid/mod.rs
index fb82dbcf..ab758e98 100644
--- a/crates/typst/src/layout/grid/mod.rs
+++ b/crates/typst/src/layout/grid/mod.rs
@@ -354,10 +354,8 @@ impl Show for Packed<GridCell> {
impl From<Content> for GridCell {
fn from(value: Content) -> Self {
- match value.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::new(v),
- }
+ #[allow(clippy::unwrap_or_default)]
+ value.unpack::<Self>().unwrap_or_else(Self::new)
}
}
diff --git a/crates/typst/src/layout/inline/mod.rs b/crates/typst/src/layout/inline/mod.rs
index 7c243da3..1c04d0ce 100644
--- a/crates/typst/src/layout/inline/mod.rs
+++ b/crates/typst/src/layout/inline/mod.rs
@@ -16,7 +16,7 @@ use crate::eval::Tracer;
use crate::foundations::{Content, Packed, Resolve, Smart, StyleChain};
use crate::introspection::{Introspector, Locator, MetaElem};
use crate::layout::{
- Abs, AlignElem, Axes, BoxElem, Dir, Em, FixedAlign, Fr, Fragment, Frame, HElem,
+ Abs, AlignElem, Axes, BoxElem, Dir, Em, FixedAlignment, Fr, Fragment, Frame, HElem,
Layout, Point, Regions, Size, Sizing, Spacing,
};
use crate::math::{EquationElem, MathParItem};
@@ -119,7 +119,7 @@ struct Preparation<'a> {
/// The text language if it's the same for all children.
lang: Option<Lang>,
/// The paragraph's resolved horizontal alignment.
- align: FixedAlign,
+ align: FixedAlignment,
/// Whether to justify the paragraph.
justify: bool,
/// The paragraph's hanging indent.
@@ -443,7 +443,7 @@ fn collect<'a>(
let segment = if child.is::<SpaceElem>() {
full.push(' ');
Segment::Text(1)
- } else if let Some(elem) = child.to::<TextElem>() {
+ } else if let Some(elem) = child.to_packed::<TextElem>() {
let prev = full.len();
if let Some(case) = TextElem::case_in(styles) {
full.push_str(&case.apply(elem.text()));
@@ -451,18 +451,18 @@ fn collect<'a>(
full.push_str(elem.text());
}
Segment::Text(full.len() - prev)
- } else if let Some(elem) = child.to::<HElem>() {
+ } else if let Some(elem) = child.to_packed::<HElem>() {
if elem.amount().is_zero() {
continue;
}
full.push(SPACING_REPLACE);
Segment::Spacing(*elem.amount())
- } else if let Some(elem) = child.to::<LinebreakElem>() {
+ } else if let Some(elem) = child.to_packed::<LinebreakElem>() {
let c = if elem.justify(styles) { '\u{2028}' } else { '\n' };
full.push(c);
Segment::Text(c.len_utf8())
- } else if let Some(elem) = child.to::<SmartQuoteElem>() {
+ } else if let Some(elem) = child.to_packed::<SmartQuoteElem>() {
let prev = full.len();
if SmartQuoteElem::enabled_in(styles) {
let quotes = SmartQuoteElem::quotes_in(styles);
@@ -480,7 +480,7 @@ fn collect<'a>(
} else {
child
};
- if let Some(elem) = child.to::<TextElem>() {
+ if let Some(elem) = child.to_packed::<TextElem>() {
elem.text().chars().next()
} else if child.is::<SmartQuoteElem>() {
Some('"')
@@ -499,12 +499,12 @@ fn collect<'a>(
full.push(if elem.double(styles) { '"' } else { '\'' });
}
Segment::Text(full.len() - prev)
- } else if let Some(elem) = child.to::<EquationElem>() {
+ } else if let Some(elem) = child.to_packed::<EquationElem>() {
let pod = Regions::one(region, Axes::splat(false));
let items = elem.layout_inline(engine, styles, pod)?;
full.extend(items.iter().map(MathParItem::text));
Segment::Equation(elem, items)
- } else if let Some(elem) = child.to::<BoxElem>() {
+ } else if let Some(elem) = child.to_packed::<BoxElem>() {
let frac = elem.width(styles).is_fractional();
full.push(if frac { SPACING_REPLACE } else { OBJ_REPLACE });
Segment::Box(elem, frac)
diff --git a/crates/typst/src/layout/spacing.rs b/crates/typst/src/layout/spacing.rs
index 4e65fff2..ec029ecd 100644
--- a/crates/typst/src/layout/spacing.rs
+++ b/crates/typst/src/layout/spacing.rs
@@ -80,7 +80,7 @@ impl Behave for Packed<HElem> {
prev: &(Cow<Content>, Behaviour, StyleChain),
styles: StyleChain,
) -> bool {
- let Some(other) = prev.0.to::<HElem>() else { return false };
+ let Some(other) = prev.0.to_packed::<HElem>() else { return false };
match (self.amount(), other.amount()) {
(Spacing::Fr(this), Spacing::Fr(other)) => this > other,
(Spacing::Rel(this), Spacing::Rel(other)) => {
@@ -182,7 +182,7 @@ impl Behave for Packed<VElem> {
prev: &(Cow<Content>, Behaviour, StyleChain),
styles: StyleChain,
) -> bool {
- let Some(other) = prev.0.to::<VElem>() else { return false };
+ let Some(other) = prev.0.to_packed::<VElem>() else { return false };
match (self.amount(), other.amount()) {
(Spacing::Fr(this), Spacing::Fr(other)) => this > other,
(Spacing::Rel(this), Spacing::Rel(other)) => {
@@ -195,7 +195,7 @@ impl Behave for Packed<VElem> {
cast! {
VElem,
- v: Content => v.to_packed::<Self>().map_err(|_| "expected `v` element")?.unpack(),
+ v: Content => v.unpack::<Self>().map_err(|_| "expected `v` element")?,
}
/// Kinds of spacing.
diff --git a/crates/typst/src/layout/stack.rs b/crates/typst/src/layout/stack.rs
index 477105f7..ab2d043b 100644
--- a/crates/typst/src/layout/stack.rs
+++ b/crates/typst/src/layout/stack.rs
@@ -4,7 +4,7 @@ use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{cast, elem, Content, Packed, Resolve, StyleChain};
use crate::layout::{
- Abs, AlignElem, Axes, Axis, Dir, FixedAlign, Fr, Fragment, Frame, Layout, Point,
+ Abs, AlignElem, Axes, Axis, Dir, FixedAlignment, Fr, Fragment, Frame, Layout, Point,
Regions, Size, Spacing,
};
use crate::util::{Get, Numeric};
@@ -146,7 +146,7 @@ enum StackItem {
/// Fractional spacing between other items.
Fractional(Fr),
/// A frame for a layouted block.
- Frame(Frame, Axes<FixedAlign>),
+ Frame(Frame, Axes<FixedAlignment>),
}
impl<'a> StackLayouter<'a> {
@@ -207,7 +207,7 @@ impl<'a> StackLayouter<'a> {
}
// Block-axis alignment of the `AlignElement` is respected by stacks.
- let align = if let Some(align) = block.to::<AlignElem>() {
+ let align = if let Some(align) = block.to_packed::<AlignElem>() {
align.alignment(styles)
} else if let Some((_, local)) = block.to_styled() {
AlignElem::alignment_in(styles.chain(local))
@@ -262,7 +262,7 @@ impl<'a> StackLayouter<'a> {
let mut output = Frame::hard(size);
let mut cursor = Abs::zero();
- let mut ruler: FixedAlign = self.dir.start().into();
+ let mut ruler: FixedAlignment = self.dir.start().into();
// Place all frames.
for item in self.items.drain(..) {
diff --git a/crates/typst/src/layout/transform.rs b/crates/typst/src/layout/transform.rs
index 527bad7c..c0786d8e 100644
--- a/crates/typst/src/layout/transform.rs
+++ b/crates/typst/src/layout/transform.rs
@@ -2,8 +2,8 @@ use crate::diag::SourceResult;
use crate::engine::Engine;
use crate::foundations::{elem, Content, Packed, Resolve, StyleChain};
use crate::layout::{
- Abs, Alignment, Angle, Axes, FixedAlign, Fragment, Frame, HAlignment, Layout, Length,
- Point, Ratio, Regions, Rel, Size, VAlignment,
+ Abs, Alignment, Angle, Axes, FixedAlignment, Fragment, Frame, HAlignment, Layout,
+ Length, Point, Ratio, Regions, Rel, Size, VAlignment,
};
/// Moves content without affecting layout.
@@ -368,14 +368,14 @@ fn measure_and_layout(
styles: StyleChain,
body: &Content,
transform: Transform,
- align: Axes<FixedAlign>,
+ align: Axes<FixedAlignment>,
reflow: bool,
) -> SourceResult<Fragment> {
if !reflow {
// Layout the body.
let pod = Regions::one(base_size, Axes::splat(false));
let mut frame = body.layout(engine, styles, pod)?.into_frame();
- let Axes { x, y } = align.zip_map(frame.size(), FixedAlign::position);
+ let Axes { x, y } = align.zip_map(frame.size(), FixedAlignment::position);
// Apply the transform.
let ts = Transform::translate(x, y)
@@ -393,7 +393,7 @@ fn measure_and_layout(
// Actually perform the layout.
let pod = Regions::one(frame.size(), Axes::splat(true));
let mut frame = body.layout(engine, styles, pod)?.into_frame();
- let Axes { x, y } = align.zip_map(frame.size(), FixedAlign::position);
+ let Axes { x, y } = align.zip_map(frame.size(), FixedAlignment::position);
// Apply the transform.
let ts = Transform::translate(x, y)
diff --git a/crates/typst/src/math/accent.rs b/crates/typst/src/math/accent.rs
index f1602f3c..d325596c 100644
--- a/crates/typst/src/math/accent.rs
+++ b/crates/typst/src/math/accent.rs
@@ -138,7 +138,7 @@ cast! {
Accent,
self => self.0.into_value(),
v: char => Self::new(v),
- v: Content => match v.to::<TextElem>() {
+ v: Content => match v.to_packed::<TextElem>() {
Some(elem) => Value::Str(elem.text().clone().into()).cast()?,
None => bail!("expected text"),
},
diff --git a/crates/typst/src/math/equation.rs b/crates/typst/src/math/equation.rs
index 4a0ee9b8..9cd771e6 100644
--- a/crates/typst/src/math/equation.rs
+++ b/crates/typst/src/math/equation.rs
@@ -8,8 +8,8 @@ use crate::foundations::{
};
use crate::introspection::{Count, Counter, CounterUpdate, Locatable};
use crate::layout::{
- Abs, AlignElem, Alignment, Axes, Dir, Em, FixedAlign, Fragment, Frame, Layout, Point,
- Regions, Size,
+ Abs, AlignElem, Alignment, Axes, Dir, Em, FixedAlignment, Fragment, Frame, Layout,
+ Point, Regions, Size,
};
use crate::math::{LayoutMath, MathContext};
use crate::model::{Numbering, Outlinable, ParElem, Refable, Supplement};
@@ -235,8 +235,8 @@ impl Layout for Packed<EquationElem> {
let dir = TextElem::dir_in(styles);
let offset = match (align, dir) {
- (FixedAlign::Start, Dir::RTL) => full_counter_width,
- (FixedAlign::End, Dir::LTR) => -full_counter_width,
+ (FixedAlignment::Start, Dir::RTL) => full_counter_width,
+ (FixedAlignment::End, Dir::LTR) => -full_counter_width,
_ => Abs::zero(),
};
frame.translate(Point::with_x(offset));
diff --git a/crates/typst/src/math/lr.rs b/crates/typst/src/math/lr.rs
index e2c098e7..6d2bdbf1 100644
--- a/crates/typst/src/math/lr.rs
+++ b/crates/typst/src/math/lr.rs
@@ -39,7 +39,7 @@ impl LayoutMath for Packed<LrElem> {
#[typst_macros::time(name = "math.lr", span = self.span())]
fn layout_math(&self, ctx: &mut MathContext) -> SourceResult<()> {
let mut body = self.body();
- if let Some(elem) = body.to::<LrElem>() {
+ if let Some(elem) = body.to_packed::<LrElem>() {
if elem.size(ctx.styles()).is_auto() {
body = elem.body();
}
diff --git a/crates/typst/src/math/matrix.rs b/crates/typst/src/math/matrix.rs
index 0a3d0c2f..24563a45 100644
--- a/crates/typst/src/math/matrix.rs
+++ b/crates/typst/src/math/matrix.rs
@@ -6,7 +6,7 @@ use crate::foundations::{
StyleChain, Value,
};
use crate::layout::{
- Abs, Axes, Em, FixedAlign, Frame, FrameItem, Length, Point, Ratio, Rel, Size,
+ Abs, Axes, Em, FixedAlignment, Frame, FrameItem, Length, Point, Ratio, Rel, Size,
};
use crate::math::{
alignments, stack, AlignmentResult, FrameFragment, GlyphFragment, LayoutMath,
@@ -64,7 +64,7 @@ impl LayoutMath for Packed<VecElem> {
let frame = layout_vec_body(
ctx,
self.children(),
- FixedAlign::Center,
+ FixedAlignment::Center,
self.gap(ctx.styles()),
)?;
layout_delimiters(
@@ -316,7 +316,7 @@ impl LayoutMath for Packed<CasesElem> {
let frame = layout_vec_body(
ctx,
self.children(),
- FixedAlign::Start,
+ FixedAlignment::Start,
self.gap(ctx.styles()),
)?;
@@ -378,7 +378,7 @@ impl Delimiter {
fn layout_vec_body(
ctx: &mut MathContext,
column: &[Content],
- align: FixedAlign,
+ align: FixedAlignment,
row_gap: Rel<Abs>,
) -> SourceResult<Frame> {
let gap = row_gap.relative_to(ctx.regions.base().y);
@@ -472,7 +472,7 @@ fn layout_mat_body(
let mut y = Abs::zero();
for (cell, &(ascent, descent)) in col.into_iter().zip(&heights) {
- let cell = cell.into_aligned_frame(ctx, &points, FixedAlign::Center);
+ let cell = cell.into_aligned_frame(ctx, &points, FixedAlignment::Center);
let pos = Point::new(
if points.is_empty() { x + (rcol - cell.width()) / 2.0 } else { x },
y + ascent - cell.ascent(),
diff --git a/crates/typst/src/math/mod.rs b/crates/typst/src/math/mod.rs
index e355cca1..ee0a3825 100644
--- a/crates/typst/src/math/mod.rs
+++ b/crates/typst/src/math/mod.rs
@@ -227,7 +227,7 @@ impl LayoutMath for Content {
// #let my = $pi$
// $ my r^2 $
// ```
- if let Some(elem) = self.to::<EquationElem>() {
+ if let Some(elem) = self.to_packed::<EquationElem>() {
return elem.layout_math(ctx);
}
@@ -276,7 +276,7 @@ impl LayoutMath for Content {
return Ok(());
}
- if let Some(elem) = self.to::<HElem>() {
+ if let Some(elem) = self.to_packed::<HElem>() {
if let Spacing::Rel(rel) = elem.amount() {
if rel.rel.is_zero() {
ctx.push(SpacingFragment {
@@ -288,13 +288,13 @@ impl LayoutMath for Content {
return Ok(());
}
- if let Some(elem) = self.to::<TextElem>() {
+ if let Some(elem) = self.to_packed::<TextElem>() {
let fragment = ctx.layout_text(elem)?;
ctx.push(fragment);
return Ok(());
}
- if let Some(boxed) = self.to::<BoxElem>() {
+ if let Some(boxed) = self.to_packed::<BoxElem>() {
let frame = ctx.layout_box(boxed)?;
ctx.push(FrameFragment::new(ctx, frame).with_spaced(true));
return Ok(());
diff --git a/crates/typst/src/math/row.rs b/crates/typst/src/math/row.rs
index 4f3e6390..f569e258 100644
--- a/crates/typst/src/math/row.rs
+++ b/crates/typst/src/math/row.rs
@@ -3,7 +3,7 @@ use std::iter::once;
use unicode_math_class::MathClass;
use crate::foundations::Resolve;
-use crate::layout::{Abs, AlignElem, Em, FixedAlign, Frame, FrameKind, Point, Size};
+use crate::layout::{Abs, AlignElem, Em, FixedAlignment, Frame, FrameKind, Point, Size};
use crate::math::{
alignments, spacing, AlignmentResult, FrameFragment, MathContext, MathFragment,
MathParItem, MathSize, Scaled,
@@ -158,7 +158,7 @@ impl MathRow {
self,
ctx: &MathContext,
points: &[Abs],
- align: FixedAlign,
+ align: FixedAlignment,
) -> Frame {
if !self.iter().any(|frag| matches!(frag, MathFragment::Linebreak)) {
return self.into_line_frame(points, align);
@@ -198,14 +198,14 @@ impl MathRow {
frame
}
- fn into_line_frame(self, points: &[Abs], align: FixedAlign) -> Frame {
+ fn into_line_frame(self, points: &[Abs], align: FixedAlignment) -> Frame {
let ascent = self.ascent();
let mut frame = Frame::soft(Size::new(Abs::zero(), ascent + self.descent()));
frame.set_baseline(ascent);
let mut next_x = {
let mut widths = Vec::new();
- if !points.is_empty() && align != FixedAlign::Start {
+ if !points.is_empty() && align != FixedAlignment::Start {
let mut width = Abs::zero();
for fragment in self.iter() {
if matches!(fragment, MathFragment::Align) {
@@ -223,8 +223,8 @@ impl MathRow {
let mut point_widths = points.iter().copied().zip(widths);
let mut alternator = LeftRightAlternator::Right;
move || match align {
- FixedAlign::Start => prev_points.next(),
- FixedAlign::End => {
+ FixedAlignment::Start => prev_points.next(),
+ FixedAlignment::End => {
point_widths.next().map(|(point, width)| point - width)
}
_ => point_widths
diff --git a/crates/typst/src/math/underover.rs b/crates/typst/src/math/underover.rs
index 593493b8..84edf036 100644
--- a/crates/typst/src/math/underover.rs
+++ b/crates/typst/src/math/underover.rs
@@ -2,7 +2,7 @@ use unicode_math_class::MathClass;
use crate::diag::SourceResult;
use crate::foundations::{elem, Content, Packed};
-use crate::layout::{Abs, Em, FixedAlign, Frame, FrameItem, Point, Size};
+use crate::layout::{Abs, Em, FixedAlignment, Frame, FrameItem, Point, Size};
use crate::math::{
alignments, AlignmentResult, FrameFragment, GlyphFragment, LayoutMath, MathContext,
MathRow, Scaled,
@@ -281,7 +281,7 @@ fn layout_underoverspreader(
baseline = rows.len() - 1;
}
- let frame = stack(ctx, rows, FixedAlign::Center, gap, baseline);
+ let frame = stack(ctx, rows, FixedAlignment::Center, gap, baseline);
ctx.push(FrameFragment::new(ctx, frame).with_class(body_class));
Ok(())
@@ -294,7 +294,7 @@ fn layout_underoverspreader(
pub(super) fn stack(
ctx: &MathContext,
rows: Vec<MathRow>,
- align: FixedAlign,
+ align: FixedAlignment,
gap: Abs,
baseline: usize,
) -> Frame {
diff --git a/crates/typst/src/model/bibliography.rs b/crates/typst/src/model/bibliography.rs
index 06a80d6b..81caf953 100644
--- a/crates/typst/src/model/bibliography.rs
+++ b/crates/typst/src/model/bibliography.rs
@@ -166,7 +166,7 @@ impl BibliographyElem {
bail!("multiple bibliographies are not yet supported");
}
- Ok(elem.to::<Self>().unwrap().clone())
+ Ok(elem.to_packed::<Self>().unwrap().clone())
}
/// Whether the bibliography contains the given key.
@@ -176,7 +176,7 @@ impl BibliographyElem {
.introspector
.query(&Self::elem().select())
.iter()
- .any(|elem| elem.to::<Self>().unwrap().bibliography().has(key))
+ .any(|elem| elem.to_packed::<Self>().unwrap().bibliography().has(key))
}
/// Find all bibliography keys.
@@ -185,7 +185,7 @@ impl BibliographyElem {
) -> Vec<(EcoString, Option<EcoString>)> {
let mut vec = vec![];
for elem in introspector.query(&Self::elem().select()).iter() {
- let this = elem.to::<Self>().unwrap();
+ let this = elem.to_packed::<Self>().unwrap();
for entry in this.bibliography().entries() {
let key = entry.key().into();
let detail = entry.title().map(|title| title.value.to_str().into());
@@ -672,7 +672,7 @@ impl<'a> Generator<'a> {
// Process all citation groups.
let mut driver = BibliographyDriver::new();
for elem in &self.groups {
- let group = elem.to::<CiteGroup>().unwrap();
+ let group = elem.to_packed::<CiteGroup>().unwrap();
let location = elem.location().unwrap();
let children = group.children();
diff --git a/crates/typst/src/model/cite.rs b/crates/typst/src/model/cite.rs
index 2e28a834..0e38b1bd 100644
--- a/crates/typst/src/model/cite.rs
+++ b/crates/typst/src/model/cite.rs
@@ -113,7 +113,7 @@ impl Synthesize for Packed<CiteElem> {
cast! {
CiteElem,
- v: Content => v.to_packed::<Self>().map_err(|_| "expected citation")?.unpack(),
+ v: Content => v.unpack::<Self>().map_err(|_| "expected citation")?,
}
/// The form of the citation.
diff --git a/crates/typst/src/model/document.rs b/crates/typst/src/model/document.rs
index 018a8d25..fedecc88 100644
--- a/crates/typst/src/model/document.rs
+++ b/crates/typst/src/model/document.rs
@@ -88,11 +88,11 @@ impl LayoutRoot for Packed<DocumentElem> {
child = elem;
}
- if let Some(page) = child.to::<PageElem>() {
+ if let Some(page) = child.to_packed::<PageElem>() {
let extend_to = iter.peek().and_then(|&next| {
next.to_styled()
.map_or(next, |(elem, _)| elem)
- .to::<PageElem>()?
+ .to_packed::<PageElem>()?
.clear_to(styles)
});
let fragment =
diff --git a/crates/typst/src/model/enum.rs b/crates/typst/src/model/enum.rs
index 870ff3b6..3da875e6 100644
--- a/crates/typst/src/model/enum.rs
+++ b/crates/typst/src/model/enum.rs
@@ -308,10 +308,7 @@ cast! {
};
Self::new(body).with_number(number)
},
- v: Content => match v.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::new(v),
- },
+ v: Content => v.unpack::<Self>().unwrap_or_else(Self::new),
}
#[derive(Debug, Clone, Copy, PartialEq, Hash)]
diff --git a/crates/typst/src/model/figure.rs b/crates/typst/src/model/figure.rs
index e42bf68a..961e3eb9 100644
--- a/crates/typst/src/model/figure.rs
+++ b/crates/typst/src/model/figure.rs
@@ -587,10 +587,7 @@ impl Show for Packed<FigureCaption> {
cast! {
FigureCaption,
- v: Content => match v.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::new(v),
- },
+ v: Content => v.unpack::<Self>().unwrap_or_else(Self::new),
}
/// The `kind` parameter of a [`FigureElem`].
diff --git a/crates/typst/src/model/footnote.rs b/crates/typst/src/model/footnote.rs
index 241f8db5..bb67abf9 100644
--- a/crates/typst/src/model/footnote.rs
+++ b/crates/typst/src/model/footnote.rs
@@ -113,7 +113,7 @@ impl Packed<FootnoteElem> {
FootnoteBody::Reference(label) => {
let element = engine.introspector.query_label(*label)?;
let footnote = element
- .to::<FootnoteElem>()
+ .to_packed::<FootnoteElem>()
.ok_or("referenced element should be a footnote")?;
footnote.declaration_location(engine)
}
@@ -314,8 +314,5 @@ impl Finalize for Packed<FootnoteEntry> {
cast! {
FootnoteElem,
- v: Content => match v.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::with_content(v),
- }
+ v: Content => v.unpack::<Self>().unwrap_or_else(Self::with_content)
}
diff --git a/crates/typst/src/model/list.rs b/crates/typst/src/model/list.rs
index dc0312d2..528218e2 100644
--- a/crates/typst/src/model/list.rs
+++ b/crates/typst/src/model/list.rs
@@ -194,10 +194,7 @@ pub struct ListItem {
cast! {
ListItem,
- v: Content => match v.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::new(v),
- }
+ v: Content => v.unpack::<Self>().unwrap_or_else(Self::new)
}
/// A list's marker.
diff --git a/crates/typst/src/model/table.rs b/crates/typst/src/model/table.rs
index b405bd9f..ef0d3f91 100644
--- a/crates/typst/src/model/table.rs
+++ b/crates/typst/src/model/table.rs
@@ -323,9 +323,7 @@ impl Show for Packed<TableCell> {
impl From<Content> for TableCell {
fn from(value: Content) -> Self {
- match value.to_packed::<Self>() {
- Ok(packed) => packed.unpack(),
- Err(v) => Self::new(v),
- }
+ #[allow(clippy::unwrap_or_default)]
+ value.unpack::<Self>().unwrap_or_else(Self::new)
}
}
diff --git a/crates/typst/src/model/terms.rs b/crates/typst/src/model/terms.rs
index 9fa7365b..9663b7c1 100644
--- a/crates/typst/src/model/terms.rs
+++ b/crates/typst/src/model/terms.rs
@@ -166,5 +166,5 @@ cast! {
};
Self::new(term, description)
},
- v: Content => v.to_packed::<Self>().map_err(|_| "expected term item or array")?.unpack(),
+ v: Content => v.unpack::<Self>().map_err(|_| "expected term item or array")?,
}
diff --git a/crates/typst/src/realize/mod.rs b/crates/typst/src/realize/mod.rs
index 080b854f..4dee2eb5 100644
--- a/crates/typst/src/realize/mod.rs
+++ b/crates/typst/src/realize/mod.rs
@@ -206,7 +206,7 @@ fn try_apply(
}
Some(Selector::Regex(regex)) => {
- let Some(elem) = target.to::<TextElem>() else {
+ let Some(elem) = target.to_packed::<TextElem>() else {
return Ok(None);
};
@@ -363,7 +363,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
}
let keep = content
- .to::<PagebreakElem>()
+ .to_packed::<PagebreakElem>()
.map_or(false, |pagebreak| !pagebreak.weak(styles));
self.interrupt_page(keep.then_some(styles), false)?;
@@ -503,13 +503,13 @@ struct DocBuilder<'a> {
impl<'a> DocBuilder<'a> {
fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool {
- if let Some(pagebreak) = content.to::<PagebreakElem>() {
+ if let Some(pagebreak) = content.to_packed::<PagebreakElem>() {
self.keep_next = !pagebreak.weak(styles);
self.clear_next = pagebreak.to(styles);
return true;
}
- if let Some(page) = content.to::<PageElem>() {
+ if let Some(page) = content.to_packed::<PageElem>() {
let elem = if let Some(clear_to) = self.clear_next.take() {
let mut page = page.clone();
page.push_clear_to(Some(clear_to));
@@ -561,11 +561,11 @@ impl<'a> FlowBuilder<'a> {
}
if content.can::<dyn Layout>() || content.is::<ParElem>() {
- let is_tight_list = if let Some(elem) = content.to::<ListElem>() {
+ let is_tight_list = if let Some(elem) = content.to_packed::<ListElem>() {
elem.tight(styles)
- } else if let Some(elem) = content.to::<EnumElem>() {
+ } else if let Some(elem) = content.to_packed::<EnumElem>() {
elem.tight(styles)
- } else if let Some(elem) = content.to::<TermsElem>() {
+ } else if let Some(elem) = content.to_packed::<TermsElem>() {
elem.tight(styles)
} else {
false
@@ -577,7 +577,7 @@ impl<'a> FlowBuilder<'a> {
self.0.push(Cow::Owned(spacing.pack()), styles);
}
- let (above, below) = if let Some(block) = content.to::<BlockElem>() {
+ let (above, below) = if let Some(block) = content.to_packed::<BlockElem>() {
(block.above(styles), block.below(styles))
} else {
(BlockElem::above_in(styles), BlockElem::below_in(styles))
@@ -609,7 +609,9 @@ impl<'a> ParBuilder<'a> {
|| content.is::<HElem>()
|| content.is::<LinebreakElem>()
|| content.is::<SmartQuoteElem>()
- || content.to::<EquationElem>().map_or(false, |elem| !elem.block(styles))
+ || content
+ .to_packed::<EquationElem>()
+ .map_or(false, |elem| !elem.block(styles))
|| content.is::<BoxElem>()
{
self.0.push(Cow::Borrowed(content), styles);
@@ -671,7 +673,7 @@ impl<'a> ListBuilder<'a> {
items
.iter()
.map(|(item, local)| {
- let mut item = item.to::<ListItem>().unwrap().clone();
+ let mut item = item.to_packed::<ListItem>().unwrap().clone();
let body = item.body().clone().styled_with_map(local.clone());
item.push_body(body);
item
@@ -686,7 +688,7 @@ impl<'a> ListBuilder<'a> {
items
.iter()
.map(|(item, local)| {
- let mut item = item.to::<EnumItem>().unwrap().clone();
+ let mut item = item.to_packed::<EnumItem>().unwrap().clone();
let body = item.body().clone().styled_with_map(local.clone());
item.push_body(body);
item
@@ -701,7 +703,7 @@ impl<'a> ListBuilder<'a> {
items
.iter()
.map(|(item, local)| {
- let mut item = item.to::<TermItem>().unwrap().clone();
+ let mut item = item.to_packed::<TermItem>().unwrap().clone();
let term = item.term().clone().styled_with_map(local.clone());
let description =
item.description().clone().styled_with_map(local.clone());
@@ -751,7 +753,7 @@ impl<'a> CiteGroupBuilder<'a> {
return true;
}
- if let Some(citation) = content.to::<CiteElem>() {
+ if let Some(citation) = content.to_packed::<CiteElem>() {
if self.items.is_empty() {
self.styles = styles;
}
diff --git a/crates/typst/src/text/shift.rs b/crates/typst/src/text/shift.rs
index 46ef703e..dcff1c48 100644
--- a/crates/typst/src/text/shift.rs
+++ b/crates/typst/src/text/shift.rs
@@ -132,7 +132,7 @@ impl Show for Packed<SuperElem> {
fn search_text(content: &Content, sub: bool) -> Option<EcoString> {
if content.is::<SpaceElem>() {
Some(' '.into())
- } else if let Some(elem) = content.to::<TextElem>() {
+ } else if let Some(elem) = content.to_packed::<TextElem>() {
convert_script(elem.text(), sub)
} else if let Some(children) = content.to_sequence() {
let mut full = EcoString::new();
diff --git a/crates/typst/src/visualize/image/mod.rs b/crates/typst/src/visualize/image/mod.rs
index 15f9276f..9d26a8ed 100644
--- a/crates/typst/src/visualize/image/mod.rs
+++ b/crates/typst/src/visualize/image/mod.rs
@@ -20,8 +20,8 @@ use crate::foundations::{
StyleChain,
};
use crate::layout::{
- Abs, Axes, FixedAlign, Fragment, Frame, FrameItem, Layout, Length, Point, Regions,
- Rel, Size,
+ Abs, Axes, FixedAlignment, Fragment, Frame, FrameItem, Layout, Length, Point,
+ Regions, Rel, Size,
};
use crate::loading::Readable;
use crate::model::Figurable;
@@ -232,7 +232,7 @@ impl Layout for Packed<ImageElem> {
// process.
let mut frame = Frame::soft(fitted);
frame.push(Point::zero(), FrameItem::Image(image, fitted, self.span()));
- frame.resize(target, Axes::splat(FixedAlign::Center));
+ frame.resize(target, Axes::splat(FixedAlignment::Center));
// Create a clipping group if only part of the image should be visible.
if fit == ImageFit::Cover && !target.fits(fitted) {