mirror of
https://github.com/typst/typst
synced 2025-05-14 04:56:26 +08:00
feat: just expand text link boxes by 0.25em in height
This commit is contained in:
parent
d02f8c33a8
commit
5291bf3661
@ -327,7 +327,7 @@ impl<'a> ShapedText<'a> {
|
||||
offset += width;
|
||||
}
|
||||
|
||||
frame.modify(&FrameModifiers::get_in(self.styles));
|
||||
frame.modify(&FrameModifiers::get_in(self.styles).set_text(self.styles));
|
||||
frame
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
use typst_library::foundations::StyleChain;
|
||||
use typst_library::layout::{
|
||||
Abs, Fragment, Frame, FrameItem, HideElem, Point, Rel, Sides,
|
||||
};
|
||||
use typst_library::foundations::{Resolve, StyleChain};
|
||||
use typst_library::layout::{Abs, Em, Fragment, Frame, FrameItem, HideElem, Point};
|
||||
use typst_library::model::{Destination, LinkElem};
|
||||
|
||||
/// Frame-level modifications resulting from styles that do not impose any
|
||||
@ -23,8 +21,7 @@ use typst_library::model::{Destination, LinkElem};
|
||||
pub struct FrameModifiers {
|
||||
/// A destination to link to.
|
||||
dest: Option<Destination>,
|
||||
/// Outset of the link box to [`Self::dest`].
|
||||
link_box_outset: Sides<Option<Rel<Abs>>>,
|
||||
expand_text_height: Option<Abs>,
|
||||
/// Whether the contents of the frame should be hidden.
|
||||
hidden: bool,
|
||||
}
|
||||
@ -34,10 +31,18 @@ impl FrameModifiers {
|
||||
pub fn get_in(styles: StyleChain) -> Self {
|
||||
Self {
|
||||
dest: LinkElem::current_in(styles),
|
||||
link_box_outset: LinkElem::box_outset_in(styles),
|
||||
expand_text_height: None,
|
||||
hidden: HideElem::hidden_in(styles),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_text(mut self, styles: StyleChain) -> Self {
|
||||
if self.dest.is_some() {
|
||||
let height = Em::one().resolve(styles);
|
||||
self.expand_text_height = Some(height);
|
||||
}
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies [`FrameModifiers`].
|
||||
@ -58,10 +63,14 @@ pub trait FrameModify {
|
||||
impl FrameModify for Frame {
|
||||
fn modify(&mut self, modifiers: &FrameModifiers) {
|
||||
if let Some(dest) = &modifiers.dest {
|
||||
let mut pos = Point::zero();
|
||||
let mut size = self.size();
|
||||
let outset = modifiers.link_box_outset.unwrap_or_default().relative_to(size);
|
||||
size += outset.sum_by_axis();
|
||||
let pos = Point::new(-outset.left, -outset.top);
|
||||
if let Some(height) = modifiers.expand_text_height {
|
||||
let expand_top = 0.25 * height;
|
||||
let expand_bottom = 0.25 * height;
|
||||
pos.y -= expand_top;
|
||||
size.y += expand_top + expand_bottom;
|
||||
}
|
||||
self.push(pos, FrameItem::Link(dest.clone(), size));
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ use crate::foundations::{
|
||||
};
|
||||
use crate::html::{attr, tag, HtmlElem};
|
||||
use crate::introspection::Location;
|
||||
use crate::layout::{Em, Length, Position, Rel, Sides};
|
||||
use crate::layout::Position;
|
||||
use crate::text::TextElem;
|
||||
|
||||
/// Links to a URL or a location in the document.
|
||||
@ -93,13 +93,6 @@ pub struct LinkElem {
|
||||
#[internal]
|
||||
#[ghost]
|
||||
pub current: Option<Destination>,
|
||||
|
||||
/// How much to expand the link box size without affecting the layout. See
|
||||
/// the [box's documentation]($box.outset) for more details.
|
||||
#[resolve]
|
||||
#[fold]
|
||||
#[default(Sides::splat(Some(Em::new(0.25).into())))]
|
||||
pub box_outset: Sides<Option<Rel<Length>>>,
|
||||
}
|
||||
|
||||
impl LinkElem {
|
||||
|
Loading…
x
Reference in New Issue
Block a user