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