Resolve spacing before comparing (#2235)
@ -1,5 +1,3 @@
|
|||||||
use std::cmp::Ordering;
|
|
||||||
|
|
||||||
use crate::prelude::*;
|
use crate::prelude::*;
|
||||||
|
|
||||||
/// Inserts horizontal spacing into a paragraph.
|
/// Inserts horizontal spacing into a paragraph.
|
||||||
@ -64,9 +62,19 @@ impl Behave for HElem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn larger(&self, prev: &Content) -> bool {
|
fn larger(
|
||||||
let Some(prev) = prev.to::<Self>() else { return false };
|
&self,
|
||||||
self.amount() > prev.amount()
|
prev: &(Content, Behaviour, StyleChain),
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> bool {
|
||||||
|
let Some(other) = prev.0.to::<Self>() else { return false };
|
||||||
|
match (self.amount(), other.amount()) {
|
||||||
|
(Spacing::Fr(this), Spacing::Fr(other)) => this > other,
|
||||||
|
(Spacing::Rel(this), Spacing::Rel(other)) => {
|
||||||
|
this.resolve(styles) > other.resolve(prev.2)
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,9 +164,19 @@ impl Behave for VElem {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn larger(&self, prev: &Content) -> bool {
|
fn larger(
|
||||||
let Some(prev) = prev.to::<Self>() else { return false };
|
&self,
|
||||||
self.amount() > prev.amount()
|
prev: &(Content, Behaviour, StyleChain),
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> bool {
|
||||||
|
let Some(other) = prev.0.to::<Self>() else { return false };
|
||||||
|
match (self.amount(), other.amount()) {
|
||||||
|
(Spacing::Fr(this), Spacing::Fr(other)) => this > other,
|
||||||
|
(Spacing::Rel(this), Spacing::Rel(other)) => {
|
||||||
|
this.resolve(styles) > other.resolve(prev.2)
|
||||||
|
}
|
||||||
|
_ => false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,16 +234,6 @@ impl From<Fr> for Spacing {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PartialOrd for Spacing {
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
|
||||||
match (self, other) {
|
|
||||||
(Self::Rel(a), Self::Rel(b)) => a.partial_cmp(b),
|
|
||||||
(Self::Fr(a), Self::Fr(b)) => a.partial_cmp(b),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cast! {
|
cast! {
|
||||||
Spacing,
|
Spacing,
|
||||||
self => match self {
|
self => match self {
|
||||||
|
@ -53,7 +53,7 @@ impl<'a> BehavedBuilder<'a> {
|
|||||||
let i = self.staged.iter().position(|prev| {
|
let i = self.staged.iter().position(|prev| {
|
||||||
let Behaviour::Weak(prev_level) = prev.1 else { return false };
|
let Behaviour::Weak(prev_level) = prev.1 else { return false };
|
||||||
level < prev_level
|
level < prev_level
|
||||||
|| (level == prev_level && item.larger(&prev.0))
|
|| (level == prev_level && item.larger(prev, styles))
|
||||||
});
|
});
|
||||||
let Some(i) = i else { return };
|
let Some(i) = i else { return };
|
||||||
self.staged.remove(i);
|
self.staged.remove(i);
|
||||||
|
@ -198,7 +198,11 @@ pub trait Behave {
|
|||||||
/// Whether this weak element is larger than a previous one and thus picked
|
/// Whether this weak element is larger than a previous one and thus picked
|
||||||
/// as the maximum when the levels are the same.
|
/// as the maximum when the levels are the same.
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn larger(&self, prev: &Content) -> bool {
|
fn larger(
|
||||||
|
&self,
|
||||||
|
prev: &(Content, Behaviour, StyleChain),
|
||||||
|
styles: StyleChain,
|
||||||
|
) -> bool {
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Before Width: | Height: | Size: 8.2 KiB After Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 51 KiB After Width: | Height: | Size: 43 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 3.3 KiB After Width: | Height: | Size: 4.1 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 61 KiB |
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 32 KiB |
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 21 KiB |
@ -24,6 +24,16 @@ A #h(0pt) B #h(0pt) \
|
|||||||
A B \
|
A B \
|
||||||
A #h(-1fr) B
|
A #h(-1fr) B
|
||||||
|
|
||||||
|
---
|
||||||
|
// Test spacing collapsing with different font sizes.
|
||||||
|
#grid(columns: 2)[
|
||||||
|
#text(size: 12pt, block(below: 1em)[A])
|
||||||
|
#text(size: 8pt, block(above: 1em)[B])
|
||||||
|
][
|
||||||
|
#text(size: 12pt, block(below: 1em)[A])
|
||||||
|
#text(size: 8pt, block(above: 1.25em)[B])
|
||||||
|
]
|
||||||
|
|
||||||
---
|
---
|
||||||
// Test RTL spacing.
|
// Test RTL spacing.
|
||||||
#set text(dir: rtl)
|
#set text(dir: rtl)
|
||||||
|