mirror of
https://github.com/typst/typst
synced 2025-08-23 19:24:14 +08:00
Compare commits
23 Commits
1fa4cc972e
...
d35640bf8e
Author | SHA1 | Date | |
---|---|---|---|
|
d35640bf8e | ||
|
c20732bdbf | ||
|
4031811fc7 | ||
|
03a73284da | ||
|
8266f321f4 | ||
|
a629f4cf94 | ||
|
b2979fcb61 | ||
|
7d67db2346 | ||
|
ce997cf8b4 | ||
|
365dd69028 | ||
|
cf15c62256 | ||
|
af34645518 | ||
|
c17d24c335 | ||
|
9809112630 | ||
|
0b3aa10bb8 | ||
|
f2f527c451 | ||
|
9e3c1199ed | ||
|
70399a94fd | ||
|
d4be7c4ca5 | ||
|
f162c37101 | ||
|
87c5686560 | ||
|
899de6d5d5 | ||
|
24293a6c12 |
1
.github/workflows/ci.yml
vendored
1
.github/workflows/ci.yml
vendored
@ -81,6 +81,7 @@ jobs:
|
|||||||
- run: cargo clippy --workspace --all-targets --no-default-features
|
- run: cargo clippy --workspace --all-targets --no-default-features
|
||||||
- run: cargo fmt --check --all
|
- run: cargo fmt --check --all
|
||||||
- run: cargo doc --workspace --no-deps
|
- run: cargo doc --workspace --no-deps
|
||||||
|
- run: git diff --exit-code
|
||||||
|
|
||||||
min-version:
|
min-version:
|
||||||
name: Check minimum Rust version
|
name: Check minimum Rust version
|
||||||
|
@ -113,7 +113,7 @@ fn write_element(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
|
|||||||
/// Encodes the children of an element.
|
/// Encodes the children of an element.
|
||||||
fn write_children(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
|
fn write_children(w: &mut Writer, element: &HtmlElement) -> SourceResult<()> {
|
||||||
// See HTML spec § 13.1.2.5.
|
// See HTML spec § 13.1.2.5.
|
||||||
if element.tag == tag::pre && starts_with_newline(element) {
|
if matches!(element.tag, tag::pre | tag::textarea) && starts_with_newline(element) {
|
||||||
w.buf.push('\n');
|
w.buf.push('\n');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ pub fn jump_from_click(
|
|||||||
) -> Option<Jump> {
|
) -> Option<Jump> {
|
||||||
// Try to find a link first.
|
// Try to find a link first.
|
||||||
for (pos, item) in frame.items() {
|
for (pos, item) in frame.items() {
|
||||||
if let FrameItem::Link(link, size) = item {
|
if let FrameItem::Link(dest, size) = item {
|
||||||
if is_in_rect(*pos, *size, click) {
|
if is_in_rect(*pos, *size, click) {
|
||||||
return Some(match &link.dest {
|
return Some(match dest {
|
||||||
Destination::Url(url) => Jump::Url(url.clone()),
|
Destination::Url(url) => Jump::Url(url.clone()),
|
||||||
Destination::Position(pos) => Jump::Position(*pos),
|
Destination::Position(pos) => Jump::Position(*pos),
|
||||||
Destination::Location(loc) => {
|
Destination::Location(loc) => {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use typst_library::foundations::{LinkMarker, Packed, StyleChain};
|
use typst_library::foundations::StyleChain;
|
||||||
use typst_library::layout::{Abs, Fragment, Frame, FrameItem, HideElem, Point, Sides};
|
use typst_library::layout::{Abs, Fragment, Frame, FrameItem, HideElem, Point, Sides};
|
||||||
use typst_library::model::ParElem;
|
use typst_library::model::{Destination, LinkElem, ParElem};
|
||||||
|
|
||||||
/// Frame-level modifications resulting from styles that do not impose any
|
/// Frame-level modifications resulting from styles that do not impose any
|
||||||
/// layout structure.
|
/// layout structure.
|
||||||
@ -20,7 +20,7 @@ use typst_library::model::ParElem;
|
|||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct FrameModifiers {
|
pub struct FrameModifiers {
|
||||||
/// A destination to link to.
|
/// A destination to link to.
|
||||||
link: Option<Packed<LinkMarker>>,
|
dest: Option<Destination>,
|
||||||
/// Whether the contents of the frame should be hidden.
|
/// Whether the contents of the frame should be hidden.
|
||||||
hidden: bool,
|
hidden: bool,
|
||||||
}
|
}
|
||||||
@ -28,9 +28,8 @@ pub struct FrameModifiers {
|
|||||||
impl FrameModifiers {
|
impl FrameModifiers {
|
||||||
/// Retrieve all modifications that should be applied per-frame.
|
/// Retrieve all modifications that should be applied per-frame.
|
||||||
pub fn get_in(styles: StyleChain) -> Self {
|
pub fn get_in(styles: StyleChain) -> Self {
|
||||||
// TODO: maybe verify that an alt text was provided here
|
|
||||||
Self {
|
Self {
|
||||||
link: LinkMarker::current_in(styles),
|
dest: LinkElem::current_in(styles),
|
||||||
hidden: HideElem::hidden_in(styles),
|
hidden: HideElem::hidden_in(styles),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,7 +94,7 @@ fn modify_frame(
|
|||||||
modifiers: &FrameModifiers,
|
modifiers: &FrameModifiers,
|
||||||
link_box_outset: Option<Sides<Abs>>,
|
link_box_outset: Option<Sides<Abs>>,
|
||||||
) {
|
) {
|
||||||
if let Some(link) = &modifiers.link {
|
if let Some(dest) = &modifiers.dest {
|
||||||
let mut pos = Point::zero();
|
let mut pos = Point::zero();
|
||||||
let mut size = frame.size();
|
let mut size = frame.size();
|
||||||
if let Some(outset) = link_box_outset {
|
if let Some(outset) = link_box_outset {
|
||||||
@ -103,7 +102,7 @@ fn modify_frame(
|
|||||||
pos.x -= outset.left;
|
pos.x -= outset.left;
|
||||||
size += outset.sum_by_axis();
|
size += outset.sum_by_axis();
|
||||||
}
|
}
|
||||||
frame.push(pos, FrameItem::Link(link.clone(), size));
|
frame.push(pos, FrameItem::Link(dest.clone(), size));
|
||||||
}
|
}
|
||||||
|
|
||||||
if modifiers.hidden {
|
if modifiers.hidden {
|
||||||
@ -130,8 +129,8 @@ where
|
|||||||
let reset;
|
let reset;
|
||||||
let outer = styles;
|
let outer = styles;
|
||||||
let mut styles = styles;
|
let mut styles = styles;
|
||||||
if modifiers.link.is_some() {
|
if modifiers.dest.is_some() {
|
||||||
reset = LinkMarker::set_current(None).wrap();
|
reset = LinkElem::set_current(None).wrap();
|
||||||
styles = outer.chain(&reset);
|
styles = outer.chain(&reset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ use crate::foundations::{
|
|||||||
};
|
};
|
||||||
use crate::introspection::{Locatable, Location};
|
use crate::introspection::{Locatable, Location};
|
||||||
use crate::layout::{AlignElem, Alignment, Axes, Length, MoveElem, PadElem, Rel, Sides};
|
use crate::layout::{AlignElem, Alignment, Axes, Length, MoveElem, PadElem, Rel, Sides};
|
||||||
use crate::model::{Destination, EmphElem, StrongElem};
|
use crate::model::{Destination, EmphElem, LinkElem, StrongElem};
|
||||||
use crate::pdf::{ArtifactElem, ArtifactKind};
|
use crate::pdf::{ArtifactElem, ArtifactKind};
|
||||||
use crate::text::UnderlineElem;
|
use crate::text::UnderlineElem;
|
||||||
|
|
||||||
@ -506,11 +506,10 @@ impl Content {
|
|||||||
/// Link the content somewhere.
|
/// Link the content somewhere.
|
||||||
pub fn linked(self, dest: Destination, alt: Option<EcoString>) -> Self {
|
pub fn linked(self, dest: Destination, alt: Option<EcoString>) -> Self {
|
||||||
let span = self.span();
|
let span = self.span();
|
||||||
let link = Packed::new(LinkMarker::new(self, dest, alt));
|
LinkMarker::new(self, dest.clone(), alt)
|
||||||
link.clone()
|
|
||||||
.pack()
|
.pack()
|
||||||
.spanned(span)
|
.spanned(span)
|
||||||
.styled(LinkMarker::set_current(Some(link)))
|
.styled(LinkElem::set_current(Some(dest)))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Set alignments for this content.
|
/// Set alignments for this content.
|
||||||
@ -1002,11 +1001,6 @@ pub struct LinkMarker {
|
|||||||
pub dest: Destination,
|
pub dest: Destination,
|
||||||
#[required]
|
#[required]
|
||||||
pub alt: Option<EcoString>,
|
pub alt: Option<EcoString>,
|
||||||
|
|
||||||
/// A link style that should be applied to elements.
|
|
||||||
#[internal]
|
|
||||||
#[ghost]
|
|
||||||
pub current: Option<Packed<LinkMarker>>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Show for Packed<LinkMarker> {
|
impl Show for Packed<LinkMarker> {
|
||||||
|
@ -7,9 +7,10 @@ use std::sync::Arc;
|
|||||||
use typst_syntax::Span;
|
use typst_syntax::Span;
|
||||||
use typst_utils::{LazyHash, Numeric};
|
use typst_utils::{LazyHash, Numeric};
|
||||||
|
|
||||||
use crate::foundations::{cast, dict, Dict, Label, LinkMarker, Packed, Value};
|
use crate::foundations::{cast, dict, Dict, Label, Value};
|
||||||
use crate::introspection::{Location, Tag};
|
use crate::introspection::{Location, Tag};
|
||||||
use crate::layout::{Abs, Axes, FixedAlignment, Length, Point, Size, Transform};
|
use crate::layout::{Abs, Axes, FixedAlignment, Length, Point, Size, Transform};
|
||||||
|
use crate::model::Destination;
|
||||||
use crate::text::TextItem;
|
use crate::text::TextItem;
|
||||||
use crate::visualize::{Color, Curve, FixedStroke, Geometry, Image, Paint, Shape};
|
use crate::visualize::{Color, Curve, FixedStroke, Geometry, Image, Paint, Shape};
|
||||||
|
|
||||||
@ -472,7 +473,7 @@ pub enum FrameItem {
|
|||||||
/// An image and its size.
|
/// An image and its size.
|
||||||
Image(Image, Size, Span),
|
Image(Image, Size, Span),
|
||||||
/// An internal or external link to a destination.
|
/// An internal or external link to a destination.
|
||||||
Link(Packed<LinkMarker>, Size),
|
Link(Destination, Size),
|
||||||
/// An introspectable element that produced something within this frame.
|
/// An introspectable element that produced something within this frame.
|
||||||
Tag(Tag),
|
Tag(Tag),
|
||||||
}
|
}
|
||||||
@ -484,7 +485,7 @@ impl Debug for FrameItem {
|
|||||||
Self::Text(text) => write!(f, "{text:?}"),
|
Self::Text(text) => write!(f, "{text:?}"),
|
||||||
Self::Shape(shape, _) => write!(f, "{shape:?}"),
|
Self::Shape(shape, _) => write!(f, "{shape:?}"),
|
||||||
Self::Image(image, _, _) => write!(f, "{image:?}"),
|
Self::Image(image, _, _) => write!(f, "{image:?}"),
|
||||||
Self::Link(link, _) => write!(f, "Link({:?}, {:?})", link.dest, link.alt),
|
Self::Link(dest, _) => write!(f, "Link({dest:?})"),
|
||||||
Self::Tag(tag) => write!(f, "{tag:?}"),
|
Self::Tag(tag) => write!(f, "{tag:?}"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ pub struct Library {
|
|||||||
/// The default style properties (for page size, font selection, and
|
/// The default style properties (for page size, font selection, and
|
||||||
/// everything else configurable via set and show rules).
|
/// everything else configurable via set and show rules).
|
||||||
pub styles: Styles,
|
pub styles: Styles,
|
||||||
/// The standard library as a value. Used to provide the `std` variable.
|
/// The standard library as a value. Used to provide the `std` module.
|
||||||
pub std: Binding,
|
pub std: Binding,
|
||||||
/// In-development features that were enabled.
|
/// In-development features that were enabled.
|
||||||
pub features: Features,
|
pub features: Features,
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
|
use icu_properties::maps::CodePointMapData;
|
||||||
|
use icu_properties::CanonicalCombiningClass;
|
||||||
|
use icu_provider::AsDeserializingBufferProvider;
|
||||||
|
use icu_provider_blob::BlobDataProvider;
|
||||||
|
|
||||||
use crate::diag::bail;
|
use crate::diag::bail;
|
||||||
use crate::foundations::{cast, elem, func, Content, NativeElement, SymbolElem};
|
use crate::foundations::{cast, elem, func, Content, NativeElement, SymbolElem};
|
||||||
use crate::layout::{Length, Rel};
|
use crate::layout::{Length, Rel};
|
||||||
@ -81,17 +88,22 @@ impl Accent {
|
|||||||
Self(Self::combine(c).unwrap_or(c))
|
Self(Self::combine(c).unwrap_or(c))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// List of bottom accents. Currently just a list of ones included in the
|
|
||||||
/// Unicode math class document.
|
|
||||||
const BOTTOM: &[char] = &[
|
|
||||||
'\u{0323}', '\u{032C}', '\u{032D}', '\u{032E}', '\u{032F}', '\u{0330}',
|
|
||||||
'\u{0331}', '\u{0332}', '\u{0333}', '\u{033A}', '\u{20E8}', '\u{20EC}',
|
|
||||||
'\u{20ED}', '\u{20EE}', '\u{20EF}',
|
|
||||||
];
|
|
||||||
|
|
||||||
/// Whether this accent is a bottom accent or not.
|
/// Whether this accent is a bottom accent or not.
|
||||||
pub fn is_bottom(&self) -> bool {
|
pub fn is_bottom(&self) -> bool {
|
||||||
Self::BOTTOM.contains(&self.0)
|
static COMBINING_CLASS_DATA: LazyLock<CodePointMapData<CanonicalCombiningClass>> =
|
||||||
|
LazyLock::new(|| {
|
||||||
|
icu_properties::maps::load_canonical_combining_class(
|
||||||
|
&BlobDataProvider::try_new_from_static_blob(typst_assets::icu::ICU)
|
||||||
|
.unwrap()
|
||||||
|
.as_deserializing(),
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
|
matches!(
|
||||||
|
COMBINING_CLASS_DATA.as_borrowed().get(self.0),
|
||||||
|
CanonicalCombiningClass::Below
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,6 +91,11 @@ pub struct LinkElem {
|
|||||||
_ => args.expect("body")?,
|
_ => args.expect("body")?,
|
||||||
})]
|
})]
|
||||||
pub body: Content,
|
pub body: Content,
|
||||||
|
|
||||||
|
/// A destination style that should be applied to elements.
|
||||||
|
#[internal]
|
||||||
|
#[ghost]
|
||||||
|
pub current: Option<Destination>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LinkElem {
|
impl LinkElem {
|
||||||
|
@ -226,25 +226,21 @@ pub struct OutlineElem {
|
|||||||
/// to just specifying `{2em}`.
|
/// to just specifying `{2em}`.
|
||||||
///
|
///
|
||||||
/// ```example
|
/// ```example
|
||||||
/// #set heading(numbering: "1.a.")
|
/// >>> #show heading: none
|
||||||
|
/// #set heading(numbering: "I-I.")
|
||||||
|
/// #set outline(title: none)
|
||||||
///
|
///
|
||||||
/// #outline(
|
/// #outline()
|
||||||
/// title: [Contents (Automatic)],
|
/// #line(length: 100%)
|
||||||
/// indent: auto,
|
/// #outline(indent: 3em)
|
||||||
/// )
|
|
||||||
///
|
///
|
||||||
/// #outline(
|
/// = Software engineering technologies
|
||||||
/// title: [Contents (Length)],
|
/// == Requirements
|
||||||
/// indent: 2em,
|
/// == Tools and technologies
|
||||||
/// )
|
/// === Code editors
|
||||||
///
|
/// == Analyzing alternatives
|
||||||
/// = About ACME Corp.
|
/// = Designing software components
|
||||||
/// == History
|
/// = Testing and integration
|
||||||
/// === Origins
|
|
||||||
/// #lorem(10)
|
|
||||||
///
|
|
||||||
/// == Products
|
|
||||||
/// #lorem(10)
|
|
||||||
/// ```
|
/// ```
|
||||||
pub indent: Smart<OutlineIndent>,
|
pub indent: Smart<OutlineIndent>,
|
||||||
}
|
}
|
||||||
@ -462,8 +458,9 @@ impl OutlineEntry {
|
|||||||
/// at the same level are aligned.
|
/// at the same level are aligned.
|
||||||
///
|
///
|
||||||
/// If the outline's indent is a fixed value or a function, the prefixes are
|
/// If the outline's indent is a fixed value or a function, the prefixes are
|
||||||
/// indented, but the inner contents are simply inset from the prefix by the
|
/// indented, but the inner contents are simply offset from the prefix by
|
||||||
/// specified `gap`, rather than aligning outline-wide.
|
/// the specified `gap`, rather than aligning outline-wide. For a visual
|
||||||
|
/// explanation, see [`outline.indent`]($outline.indent).
|
||||||
#[func(contextual)]
|
#[func(contextual)]
|
||||||
pub fn indented(
|
pub fn indented(
|
||||||
&self,
|
&self,
|
||||||
|
@ -79,6 +79,36 @@ use crate::text::TextElem;
|
|||||||
/// reference: `[@intro[Chapter]]`.
|
/// reference: `[@intro[Chapter]]`.
|
||||||
///
|
///
|
||||||
/// # Customization
|
/// # Customization
|
||||||
|
/// When you only ever need to reference pages of a figure/table/heading/etc. in
|
||||||
|
/// a document, the default `form` field value can be changed to `{"page"}` with
|
||||||
|
/// a set rule. If you prefer a short "p." supplement over "page", the
|
||||||
|
/// [`page.supplement`]($page.supplement) field can be used for changing this:
|
||||||
|
///
|
||||||
|
/// ```example
|
||||||
|
/// #set page(
|
||||||
|
/// numbering: "1",
|
||||||
|
/// supplement: "p.",
|
||||||
|
/// >>> margin: (bottom: 3em),
|
||||||
|
/// >>> footer-descent: 1.25em,
|
||||||
|
/// )
|
||||||
|
/// #set ref(form: "page")
|
||||||
|
///
|
||||||
|
/// #figure(
|
||||||
|
/// stack(
|
||||||
|
/// dir: ltr,
|
||||||
|
/// spacing: 1em,
|
||||||
|
/// circle(),
|
||||||
|
/// square(),
|
||||||
|
/// ),
|
||||||
|
/// caption: [Shapes],
|
||||||
|
/// ) <shapes>
|
||||||
|
///
|
||||||
|
/// #pagebreak()
|
||||||
|
///
|
||||||
|
/// See @shapes for examples
|
||||||
|
/// of different shapes.
|
||||||
|
/// ```
|
||||||
|
///
|
||||||
/// If you write a show rule for references, you can access the referenced
|
/// If you write a show rule for references, you can access the referenced
|
||||||
/// element through the `element` field of the reference. The `element` may
|
/// element through the `element` field of the reference. The `element` may
|
||||||
/// be `{none}` even if it exists if Typst hasn't discovered it yet, so you
|
/// be `{none}` even if it exists if Typst hasn't discovered it yet, so you
|
||||||
@ -91,16 +121,13 @@ use crate::text::TextElem;
|
|||||||
/// #show ref: it => {
|
/// #show ref: it => {
|
||||||
/// let eq = math.equation
|
/// let eq = math.equation
|
||||||
/// let el = it.element
|
/// let el = it.element
|
||||||
/// if el != none and el.func() == eq {
|
/// // Skip all other references.
|
||||||
/// // Override equation references.
|
/// if el == none or el.func() != eq { return it }
|
||||||
/// link(el.location(),numbering(
|
/// // Override equation references.
|
||||||
/// el.numbering,
|
/// link(el.location(), numbering(
|
||||||
/// ..counter(eq).at(el.location())
|
/// el.numbering,
|
||||||
/// ))
|
/// ..counter(eq).at(el.location())
|
||||||
/// } else {
|
/// ))
|
||||||
/// // Other references as usual.
|
|
||||||
/// it
|
|
||||||
/// }
|
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// = Beginnings <beginning>
|
/// = Beginnings <beginning>
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
use ecow::EcoString;
|
use ecow::EcoString;
|
||||||
use typst_macros::{cast, elem};
|
use typst_macros::{cast, elem, Cast};
|
||||||
|
|
||||||
use crate::diag::SourceResult;
|
use crate::diag::SourceResult;
|
||||||
use crate::engine::Engine;
|
use crate::engine::Engine;
|
||||||
@ -200,7 +200,7 @@ pub struct ArtifactElem {
|
|||||||
pub body: Content,
|
pub body: Content,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
|
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Cast)]
|
||||||
pub enum ArtifactKind {
|
pub enum ArtifactKind {
|
||||||
/// Page header artifacts.
|
/// Page header artifacts.
|
||||||
Header,
|
Header,
|
||||||
@ -213,20 +213,6 @@ pub enum ArtifactKind {
|
|||||||
Other,
|
Other,
|
||||||
}
|
}
|
||||||
|
|
||||||
cast! {
|
|
||||||
ArtifactKind,
|
|
||||||
self => match self {
|
|
||||||
ArtifactKind::Header => "header".into_value(),
|
|
||||||
ArtifactKind::Footer => "footer".into_value(),
|
|
||||||
ArtifactKind::Page => "page".into_value(),
|
|
||||||
ArtifactKind::Other => "other".into_value(),
|
|
||||||
},
|
|
||||||
"header" => Self::Header,
|
|
||||||
"footer" => Self::Footer,
|
|
||||||
"page" => Self::Page,
|
|
||||||
"other" => Self::Other,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Show for Packed<ArtifactElem> {
|
impl Show for Packed<ArtifactElem> {
|
||||||
#[typst_macros::time(name = "pdf.artifact", span = self.span())]
|
#[typst_macros::time(name = "pdf.artifact", span = self.span())]
|
||||||
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
|
fn show(&self, _: &mut Engine, _: StyleChain) -> SourceResult<Content> {
|
||||||
|
@ -13,7 +13,7 @@ use krilla::{Document, SerializeSettings};
|
|||||||
use krilla_svg::render_svg_glyph;
|
use krilla_svg::render_svg_glyph;
|
||||||
use typst_library::diag::{bail, error, SourceDiagnostic, SourceResult};
|
use typst_library::diag::{bail, error, SourceDiagnostic, SourceResult};
|
||||||
use typst_library::foundations::{NativeElement, Repr};
|
use typst_library::foundations::{NativeElement, Repr};
|
||||||
use typst_library::introspection::{self, Location};
|
use typst_library::introspection::{Location, Tag};
|
||||||
use typst_library::layout::{
|
use typst_library::layout::{
|
||||||
Abs, Frame, FrameItem, GroupItem, PagedDocument, Size, Transform,
|
Abs, Frame, FrameItem, GroupItem, PagedDocument, Size, Transform,
|
||||||
};
|
};
|
||||||
@ -110,8 +110,6 @@ fn convert_pages(gc: &mut GlobalContext, document: &mut Document) -> SourceResul
|
|||||||
let mut surface = page.surface();
|
let mut surface = page.surface();
|
||||||
let mut fc = FrameContext::new(typst_page.frame.size());
|
let mut fc = FrameContext::new(typst_page.frame.size());
|
||||||
|
|
||||||
tags::restart_open(gc, &mut surface);
|
|
||||||
|
|
||||||
handle_frame(
|
handle_frame(
|
||||||
&mut fc,
|
&mut fc,
|
||||||
&typst_page.frame,
|
&typst_page.frame,
|
||||||
@ -120,8 +118,6 @@ fn convert_pages(gc: &mut GlobalContext, document: &mut Document) -> SourceResul
|
|||||||
gc,
|
gc,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
tags::end_open(gc, &mut surface);
|
|
||||||
|
|
||||||
surface.finish();
|
surface.finish();
|
||||||
|
|
||||||
tags::add_annotations(gc, &mut page, fc.link_annotations);
|
tags::add_annotations(gc, &mut page, fc.link_annotations);
|
||||||
@ -285,13 +281,9 @@ pub(crate) fn handle_frame(
|
|||||||
FrameItem::Image(image, size, span) => {
|
FrameItem::Image(image, size, span) => {
|
||||||
handle_image(gc, fc, image, *size, surface, *span)?
|
handle_image(gc, fc, image, *size, surface, *span)?
|
||||||
}
|
}
|
||||||
FrameItem::Link(link, size) => handle_link(fc, gc, link, *size),
|
FrameItem::Link(dest, size) => handle_link(fc, gc, dest, *size),
|
||||||
FrameItem::Tag(introspection::Tag::Start(elem)) => {
|
FrameItem::Tag(Tag::Start(elem)) => tags::handle_start(gc, elem),
|
||||||
tags::handle_start(gc, surface, elem)
|
FrameItem::Tag(Tag::End(loc, _)) => tags::handle_end(gc, *loc),
|
||||||
}
|
|
||||||
FrameItem::Tag(introspection::Tag::End(loc, _)) => {
|
|
||||||
tags::handle_end(gc, surface, *loc);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fc.pop();
|
fc.pop();
|
||||||
@ -306,7 +298,7 @@ pub(crate) fn handle_group(
|
|||||||
fc: &mut FrameContext,
|
fc: &mut FrameContext,
|
||||||
group: &GroupItem,
|
group: &GroupItem,
|
||||||
surface: &mut Surface,
|
surface: &mut Surface,
|
||||||
context: &mut GlobalContext,
|
gc: &mut GlobalContext,
|
||||||
) -> SourceResult<()> {
|
) -> SourceResult<()> {
|
||||||
fc.push();
|
fc.push();
|
||||||
fc.state_mut().pre_concat(group.transform);
|
fc.state_mut().pre_concat(group.transform);
|
||||||
@ -322,10 +314,12 @@ pub(crate) fn handle_group(
|
|||||||
.and_then(|p| p.transform(fc.state().transform.to_krilla()));
|
.and_then(|p| p.transform(fc.state().transform.to_krilla()));
|
||||||
|
|
||||||
if let Some(clip_path) = &clip_path {
|
if let Some(clip_path) = &clip_path {
|
||||||
|
let mut handle = tags::start_marked(gc, surface);
|
||||||
|
let surface = handle.surface();
|
||||||
surface.push_clip_path(clip_path, &krilla::paint::FillRule::NonZero);
|
surface.push_clip_path(clip_path, &krilla::paint::FillRule::NonZero);
|
||||||
}
|
}
|
||||||
|
|
||||||
handle_frame(fc, &group.frame, None, surface, context)?;
|
handle_frame(fc, &group.frame, None, surface, gc)?;
|
||||||
|
|
||||||
if clip_path.is_some() {
|
if clip_path.is_some() {
|
||||||
surface.pop();
|
surface.pop();
|
||||||
|
@ -14,6 +14,7 @@ use typst_library::visualize::{
|
|||||||
use typst_syntax::Span;
|
use typst_syntax::Span;
|
||||||
|
|
||||||
use crate::convert::{FrameContext, GlobalContext};
|
use crate::convert::{FrameContext, GlobalContext};
|
||||||
|
use crate::tags;
|
||||||
use crate::util::{SizeExt, TransformExt};
|
use crate::util::{SizeExt, TransformExt};
|
||||||
|
|
||||||
#[typst_macros::time(name = "handle image")]
|
#[typst_macros::time(name = "handle image")]
|
||||||
@ -32,6 +33,8 @@ pub(crate) fn handle_image(
|
|||||||
|
|
||||||
gc.image_spans.insert(span);
|
gc.image_spans.insert(span);
|
||||||
|
|
||||||
|
let mut handle = tags::start_marked(gc, surface);
|
||||||
|
let surface = handle.surface();
|
||||||
match image.kind() {
|
match image.kind() {
|
||||||
ImageKind::Raster(raster) => {
|
ImageKind::Raster(raster) => {
|
||||||
let (exif_transform, new_size) = exif_transform(raster, size);
|
let (exif_transform, new_size) = exif_transform(raster, size);
|
||||||
|
@ -5,7 +5,6 @@ use krilla::action::{Action, LinkAction};
|
|||||||
use krilla::annotation::Target;
|
use krilla::annotation::Target;
|
||||||
use krilla::destination::XyzDestination;
|
use krilla::destination::XyzDestination;
|
||||||
use krilla::geom as kg;
|
use krilla::geom as kg;
|
||||||
use typst_library::foundations::LinkMarker;
|
|
||||||
use typst_library::layout::{Abs, Point, Position, Size};
|
use typst_library::layout::{Abs, Point, Position, Size};
|
||||||
use typst_library::model::Destination;
|
use typst_library::model::Destination;
|
||||||
|
|
||||||
@ -24,10 +23,10 @@ pub(crate) struct LinkAnnotation {
|
|||||||
pub(crate) fn handle_link(
|
pub(crate) fn handle_link(
|
||||||
fc: &mut FrameContext,
|
fc: &mut FrameContext,
|
||||||
gc: &mut GlobalContext,
|
gc: &mut GlobalContext,
|
||||||
link: &LinkMarker,
|
dest: &Destination,
|
||||||
size: Size,
|
size: Size,
|
||||||
) {
|
) {
|
||||||
let target = match &link.dest {
|
let target = match dest {
|
||||||
Destination::Url(u) => {
|
Destination::Url(u) => {
|
||||||
Target::Action(Action::Link(LinkAction::new(u.to_string())))
|
Target::Action(Action::Link(LinkAction::new(u.to_string())))
|
||||||
}
|
}
|
||||||
@ -51,14 +50,15 @@ pub(crate) fn handle_link(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let entry = gc.tags.stack.last_mut().expect("a link parent");
|
let entry = gc.tags.stack.last_mut().expect("a link parent");
|
||||||
let StackEntryKind::Link(link_id, _) = entry.kind else {
|
let StackEntryKind::Link(link_id, link) = &entry.kind else {
|
||||||
unreachable!("expected a link parent")
|
unreachable!("expected a link parent")
|
||||||
};
|
};
|
||||||
|
let alt = link.alt.as_ref().map(EcoString::to_string);
|
||||||
|
|
||||||
let rect = to_rect(fc, size);
|
let rect = to_rect(fc, size);
|
||||||
let quadpoints = quadpoints(rect);
|
let quadpoints = quadpoints(rect);
|
||||||
|
|
||||||
match fc.link_annotations.entry(link_id) {
|
match fc.link_annotations.entry(*link_id) {
|
||||||
Entry::Occupied(occupied) => {
|
Entry::Occupied(occupied) => {
|
||||||
// Update the bounding box and add the quadpoints of an existing link annotation.
|
// Update the bounding box and add the quadpoints of an existing link annotation.
|
||||||
let annotation = occupied.into_mut();
|
let annotation = occupied.into_mut();
|
||||||
@ -73,7 +73,7 @@ pub(crate) fn handle_link(
|
|||||||
placeholder,
|
placeholder,
|
||||||
rect,
|
rect,
|
||||||
quad_points: quadpoints.to_vec(),
|
quad_points: quadpoints.to_vec(),
|
||||||
alt: link.alt.as_ref().map(EcoString::to_string),
|
alt,
|
||||||
target,
|
target,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -5,8 +5,8 @@ use typst_library::visualize::{Geometry, Shape};
|
|||||||
use typst_syntax::Span;
|
use typst_syntax::Span;
|
||||||
|
|
||||||
use crate::convert::{FrameContext, GlobalContext};
|
use crate::convert::{FrameContext, GlobalContext};
|
||||||
use crate::paint;
|
|
||||||
use crate::util::{convert_path, AbsExt, TransformExt};
|
use crate::util::{convert_path, AbsExt, TransformExt};
|
||||||
|
use crate::{paint, tags};
|
||||||
|
|
||||||
#[typst_macros::time(name = "handle shape")]
|
#[typst_macros::time(name = "handle shape")]
|
||||||
pub(crate) fn handle_shape(
|
pub(crate) fn handle_shape(
|
||||||
@ -16,6 +16,9 @@ pub(crate) fn handle_shape(
|
|||||||
gc: &mut GlobalContext,
|
gc: &mut GlobalContext,
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> SourceResult<()> {
|
) -> SourceResult<()> {
|
||||||
|
let mut handle = tags::start_marked(gc, surface);
|
||||||
|
let surface = handle.surface();
|
||||||
|
|
||||||
surface.set_location(span.into_raw().get());
|
surface.set_location(span.into_raw().get());
|
||||||
surface.push_transform(&fc.state().transform().to_krilla());
|
surface.push_transform(&fc.state().transform().to_krilla());
|
||||||
|
|
||||||
|
@ -45,6 +45,16 @@ pub(crate) enum StackEntryKind {
|
|||||||
TableCell(Packed<TableCell>),
|
TableCell(Packed<TableCell>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl StackEntryKind {
|
||||||
|
pub(crate) fn as_standard_mut(&mut self) -> Option<&mut Tag> {
|
||||||
|
if let Self::Standard(v) = self {
|
||||||
|
Some(v)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) struct TableCtx {
|
pub(crate) struct TableCtx {
|
||||||
table: Packed<TableElem>,
|
table: Packed<TableElem>,
|
||||||
rows: Vec<Vec<Option<(Packed<TableCell>, Tag, Vec<TagNode>)>>>,
|
rows: Vec<Vec<Option<(Packed<TableCell>, Tag, Vec<TagNode>)>>>,
|
||||||
@ -144,10 +154,6 @@ impl Tags {
|
|||||||
.expect("initialized placeholder node")
|
.expect("initialized placeholder node")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn is_root(&self) -> bool {
|
|
||||||
self.stack.is_empty()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns the current parent's list of children and the structure type ([Tag]).
|
/// Returns the current parent's list of children and the structure type ([Tag]).
|
||||||
/// In case of the document root the structure type will be `None`.
|
/// In case of the document root the structure type will be `None`.
|
||||||
pub(crate) fn parent(&mut self) -> (Option<&mut StackEntryKind>, &mut Vec<TagNode>) {
|
pub(crate) fn parent(&mut self) -> (Option<&mut StackEntryKind>, &mut Vec<TagNode>) {
|
||||||
@ -196,25 +202,40 @@ impl Tags {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marked-content may not cross page boundaries: restart tag that was still open
|
/// Automatically calls [`Surface::end_tagged`] when dropped.
|
||||||
/// at the end of the last page.
|
pub(crate) struct TagHandle<'a, 'b> {
|
||||||
pub(crate) fn restart_open(gc: &mut GlobalContext, surface: &mut Surface) {
|
surface: &'b mut Surface<'a>,
|
||||||
// TODO: somehow avoid empty marked-content sequences
|
}
|
||||||
if let Some((loc, kind)) = gc.tags.in_artifact {
|
|
||||||
start_artifact(gc, surface, loc, kind);
|
impl Drop for TagHandle<'_, '_> {
|
||||||
} else if let Some(entry) = gc.tags.stack.last_mut() {
|
fn drop(&mut self) {
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
self.surface.end_tagged();
|
||||||
entry.nodes.push(TagNode::Leaf(id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Marked-content may not cross page boundaries: end any open tag.
|
impl<'a> TagHandle<'a, '_> {
|
||||||
pub(crate) fn end_open(gc: &mut GlobalContext, surface: &mut Surface) {
|
pub(crate) fn surface<'c>(&'c mut self) -> &'c mut Surface<'a> {
|
||||||
if !gc.tags.stack.is_empty() || gc.tags.in_artifact.is_some() {
|
&mut self.surface
|
||||||
surface.end_tagged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns a [`TagHandle`] that automatically calls [`Surface::end_tagged`]
|
||||||
|
/// when dropped.
|
||||||
|
pub(crate) fn start_marked<'a, 'b>(
|
||||||
|
gc: &mut GlobalContext,
|
||||||
|
surface: &'b mut Surface<'a>,
|
||||||
|
) -> TagHandle<'a, 'b> {
|
||||||
|
let content = if let Some((_, kind)) = gc.tags.in_artifact {
|
||||||
|
let ty = artifact_type(kind);
|
||||||
|
ContentTag::Artifact(ty)
|
||||||
|
} else {
|
||||||
|
ContentTag::Other
|
||||||
|
};
|
||||||
|
let id = surface.start_tagged(content);
|
||||||
|
gc.tags.push(TagNode::Leaf(id));
|
||||||
|
TagHandle { surface }
|
||||||
|
}
|
||||||
|
|
||||||
/// Add all annotations that were found in the page frame.
|
/// Add all annotations that were found in the page frame.
|
||||||
pub(crate) fn add_annotations(
|
pub(crate) fn add_annotations(
|
||||||
gc: &mut GlobalContext,
|
gc: &mut GlobalContext,
|
||||||
@ -232,11 +253,7 @@ pub(crate) fn add_annotations(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_start(
|
pub(crate) fn handle_start(gc: &mut GlobalContext, elem: &Content) {
|
||||||
gc: &mut GlobalContext,
|
|
||||||
surface: &mut Surface,
|
|
||||||
elem: &Content,
|
|
||||||
) {
|
|
||||||
if gc.tags.in_artifact.is_some() {
|
if gc.tags.in_artifact.is_some() {
|
||||||
// Don't nest artifacts
|
// Don't nest artifacts
|
||||||
return;
|
return;
|
||||||
@ -245,9 +262,8 @@ pub(crate) fn handle_start(
|
|||||||
let loc = elem.location().unwrap();
|
let loc = elem.location().unwrap();
|
||||||
|
|
||||||
if let Some(artifact) = elem.to_packed::<ArtifactElem>() {
|
if let Some(artifact) = elem.to_packed::<ArtifactElem>() {
|
||||||
end_open(gc, surface);
|
|
||||||
let kind = artifact.kind(StyleChain::default());
|
let kind = artifact.kind(StyleChain::default());
|
||||||
start_artifact(gc, surface, loc, kind);
|
start_artifact(gc, loc, kind);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -279,79 +295,55 @@ pub(crate) fn handle_start(
|
|||||||
} else if let Some(image) = elem.to_packed::<ImageElem>() {
|
} else if let Some(image) = elem.to_packed::<ImageElem>() {
|
||||||
let alt = image.alt(StyleChain::default()).map(|s| s.to_string());
|
let alt = image.alt(StyleChain::default()).map(|s| s.to_string());
|
||||||
|
|
||||||
end_open(gc, surface);
|
let figure_tag = (gc.tags.parent().0)
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
.and_then(|parent| parent.as_standard_mut())
|
||||||
let mut node = TagNode::Leaf(id);
|
.filter(|tag| tag.kind == TagKind::Figure && tag.alt_text.is_none());
|
||||||
|
if let Some(figure_tag) = figure_tag {
|
||||||
if let Some(StackEntryKind::Standard(parent)) = gc.tags.parent().0 {
|
// HACK: set alt text of outer figure tag, if the contained image
|
||||||
if parent.kind == TagKind::Figure && parent.alt_text.is_none() {
|
// has alt text specified
|
||||||
// HACK: set alt text of outer figure tag, if the contained image
|
figure_tag.alt_text = alt;
|
||||||
// has alt text specified
|
return;
|
||||||
parent.alt_text = alt;
|
|
||||||
} else {
|
|
||||||
node = TagNode::Group(TagKind::Figure.with_alt_text(alt), vec![node]);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
node = TagNode::Group(TagKind::Figure.with_alt_text(alt), vec![node]);
|
TagKind::Figure.with_alt_text(alt)
|
||||||
}
|
}
|
||||||
gc.tags.push(node);
|
|
||||||
|
|
||||||
return;
|
|
||||||
} else if let Some(_) = elem.to_packed::<FigureCaption>() {
|
} else if let Some(_) = elem.to_packed::<FigureCaption>() {
|
||||||
TagKind::Caption.into()
|
TagKind::Caption.into()
|
||||||
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
|
} else if let Some(link) = elem.to_packed::<LinkMarker>() {
|
||||||
let link_id = gc.tags.next_link_id();
|
let link_id = gc.tags.next_link_id();
|
||||||
push_stack(gc, surface, loc, StackEntryKind::Link(link_id, link.clone()));
|
push_stack(gc, loc, StackEntryKind::Link(link_id, link.clone()));
|
||||||
return;
|
return;
|
||||||
} else if let Some(table) = elem.to_packed::<TableElem>() {
|
} else if let Some(table) = elem.to_packed::<TableElem>() {
|
||||||
let ctx = TableCtx { table: table.clone(), rows: Vec::new() };
|
let ctx = TableCtx { table: table.clone(), rows: Vec::new() };
|
||||||
push_stack(gc, surface, loc, StackEntryKind::Table(ctx));
|
push_stack(gc, loc, StackEntryKind::Table(ctx));
|
||||||
return;
|
return;
|
||||||
} else if let Some(cell) = elem.to_packed::<TableCell>() {
|
} else if let Some(cell) = elem.to_packed::<TableCell>() {
|
||||||
push_stack(gc, surface, loc, StackEntryKind::TableCell(cell.clone()));
|
push_stack(gc, loc, StackEntryKind::TableCell(cell.clone()));
|
||||||
return;
|
return;
|
||||||
} else if let Some(_) = elem.to_packed::<TableHLine>() {
|
} else if let Some(_) = elem.to_packed::<TableHLine>() {
|
||||||
end_open(gc, surface);
|
start_artifact(gc, loc, ArtifactKind::Other);
|
||||||
start_artifact(gc, surface, loc, ArtifactKind::Other);
|
|
||||||
return;
|
return;
|
||||||
} else if let Some(_) = elem.to_packed::<TableVLine>() {
|
} else if let Some(_) = elem.to_packed::<TableVLine>() {
|
||||||
end_open(gc, surface);
|
start_artifact(gc, loc, ArtifactKind::Other);
|
||||||
start_artifact(gc, surface, loc, ArtifactKind::Other);
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
push_stack(gc, surface, loc, StackEntryKind::Standard(tag));
|
push_stack(gc, loc, StackEntryKind::Standard(tag));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn push_stack(
|
fn push_stack(gc: &mut GlobalContext, loc: Location, kind: StackEntryKind) {
|
||||||
gc: &mut GlobalContext,
|
|
||||||
surface: &mut Surface,
|
|
||||||
loc: Location,
|
|
||||||
kind: StackEntryKind,
|
|
||||||
) {
|
|
||||||
if !gc.tags.context_supports(&kind) {
|
if !gc.tags.context_supports(&kind) {
|
||||||
// TODO: error or warning?
|
// TODO: error or warning?
|
||||||
}
|
}
|
||||||
|
|
||||||
// close previous marked-content and open a nested tag.
|
gc.tags.stack.push(StackEntry { loc, kind, nodes: Vec::new() });
|
||||||
end_open(gc, surface);
|
|
||||||
let id = surface.start_tagged(krilla::tagging::ContentTag::Other);
|
|
||||||
gc.tags
|
|
||||||
.stack
|
|
||||||
.push(StackEntry { loc, kind, nodes: vec![TagNode::Leaf(id)] });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn handle_end(gc: &mut GlobalContext, surface: &mut Surface, loc: Location) {
|
pub(crate) fn handle_end(gc: &mut GlobalContext, loc: Location) {
|
||||||
if let Some((l, _)) = gc.tags.in_artifact {
|
if let Some((l, _)) = gc.tags.in_artifact {
|
||||||
if l == loc {
|
if l == loc {
|
||||||
gc.tags.in_artifact = None;
|
gc.tags.in_artifact = None;
|
||||||
surface.end_tagged();
|
|
||||||
if let Some(entry) = gc.tags.stack.last_mut() {
|
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
|
||||||
entry.nodes.push(TagNode::Leaf(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -360,8 +352,6 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, surface: &mut Surface, loc: Loc
|
|||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
surface.end_tagged();
|
|
||||||
|
|
||||||
let node = match entry.kind {
|
let node = match entry.kind {
|
||||||
StackEntryKind::Standard(tag) => TagNode::Group(tag, entry.nodes),
|
StackEntryKind::Standard(tag) => TagNode::Group(tag, entry.nodes),
|
||||||
StackEntryKind::Link(_, link) => {
|
StackEntryKind::Link(_, link) => {
|
||||||
@ -387,30 +377,14 @@ pub(crate) fn handle_end(gc: &mut GlobalContext, surface: &mut Surface, loc: Loc
|
|||||||
|
|
||||||
table_ctx.insert(cell, entry.nodes);
|
table_ctx.insert(cell, entry.nodes);
|
||||||
|
|
||||||
// TODO: somehow avoid empty marked-content sequences
|
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
|
||||||
gc.tags.push(TagNode::Leaf(id));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
gc.tags.push(node);
|
gc.tags.push(node);
|
||||||
if !gc.tags.is_root() {
|
|
||||||
// TODO: somehow avoid empty marked-content sequences
|
|
||||||
let id = surface.start_tagged(ContentTag::Other);
|
|
||||||
gc.tags.push(TagNode::Leaf(id));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_artifact(
|
fn start_artifact(gc: &mut GlobalContext, loc: Location, kind: ArtifactKind) {
|
||||||
gc: &mut GlobalContext,
|
|
||||||
surface: &mut Surface,
|
|
||||||
loc: Location,
|
|
||||||
kind: ArtifactKind,
|
|
||||||
) {
|
|
||||||
let ty = artifact_type(kind);
|
|
||||||
let id = surface.start_tagged(ContentTag::Artifact(ty));
|
|
||||||
gc.tags.push(TagNode::Leaf(id));
|
|
||||||
gc.tags.in_artifact = Some((loc, kind));
|
gc.tags.in_artifact = Some((loc, kind));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,8 +11,8 @@ use typst_library::visualize::FillRule;
|
|||||||
use typst_syntax::Span;
|
use typst_syntax::Span;
|
||||||
|
|
||||||
use crate::convert::{FrameContext, GlobalContext};
|
use crate::convert::{FrameContext, GlobalContext};
|
||||||
use crate::paint;
|
|
||||||
use crate::util::{display_font, AbsExt, TransformExt};
|
use crate::util::{display_font, AbsExt, TransformExt};
|
||||||
|
use crate::{paint, tags};
|
||||||
|
|
||||||
#[typst_macros::time(name = "handle text")]
|
#[typst_macros::time(name = "handle text")]
|
||||||
pub(crate) fn handle_text(
|
pub(crate) fn handle_text(
|
||||||
@ -23,6 +23,9 @@ pub(crate) fn handle_text(
|
|||||||
) -> SourceResult<()> {
|
) -> SourceResult<()> {
|
||||||
*gc.languages.entry(t.lang).or_insert(0) += t.glyphs.len();
|
*gc.languages.entry(t.lang).or_insert(0) += t.glyphs.len();
|
||||||
|
|
||||||
|
let mut handle = tags::start_marked(gc, surface);
|
||||||
|
let surface = handle.surface();
|
||||||
|
|
||||||
let font = convert_font(gc, t.font.clone())?;
|
let font = convert_font(gc, t.font.clone())?;
|
||||||
let fill = paint::convert_fill(
|
let fill = paint::convert_fill(
|
||||||
gc,
|
gc,
|
||||||
|
@ -137,6 +137,59 @@
|
|||||||
In addition to the functions listed below, the `calc` module also defines
|
In addition to the functions listed below, the `calc` module also defines
|
||||||
the constants `pi`, `tau`, `e`, and `inf`.
|
the constants `pi`, `tau`, `e`, and `inf`.
|
||||||
|
|
||||||
|
- name: std
|
||||||
|
title: Standard library
|
||||||
|
category: foundations
|
||||||
|
path: ["std"]
|
||||||
|
details: |
|
||||||
|
A module that contains all globally accessible items.
|
||||||
|
|
||||||
|
# Using "shadowed" definitions
|
||||||
|
The `std` module is useful whenever you overrode a name from the global
|
||||||
|
scope (this is called _shadowing_). For instance, you might have used the
|
||||||
|
name `text` for a parameter. To still access the `text` element, write
|
||||||
|
`std.text`.
|
||||||
|
|
||||||
|
```example
|
||||||
|
>>> #set page(margin: (left: 3em))
|
||||||
|
#let par = [My special paragraph.]
|
||||||
|
#let special(text) = {
|
||||||
|
set std.text(style: "italic")
|
||||||
|
set std.par.line(numbering: "1")
|
||||||
|
text
|
||||||
|
}
|
||||||
|
|
||||||
|
#special(par)
|
||||||
|
|
||||||
|
#lorem(10)
|
||||||
|
```
|
||||||
|
|
||||||
|
# Conditional access
|
||||||
|
You can also use this in combination with the [dictionary
|
||||||
|
constructor]($dictionary) to conditionally access global definitions. This
|
||||||
|
can, for instance, be useful to use new or experimental functionality when
|
||||||
|
it is available, while falling back to an alternative implementation if
|
||||||
|
used on an older Typst version. In particular, this allows us to create
|
||||||
|
[polyfills](https://en.wikipedia.org/wiki/Polyfill_(programming)).
|
||||||
|
|
||||||
|
This can be as simple as creating an alias to prevent warning messages, for
|
||||||
|
example, conditionally using `pattern` in Typst version 0.12, but using
|
||||||
|
[`tiling`] in newer versions. Since the parameters accepted by the `tiling`
|
||||||
|
function match those of the older `pattern` function, using the `tiling`
|
||||||
|
function when available and falling back to `pattern` otherwise will unify
|
||||||
|
the usage across all versions. Note that, when creating a polyfill,
|
||||||
|
[`sys.version`]($category/foundations/sys) can also be very useful.
|
||||||
|
|
||||||
|
```typ
|
||||||
|
#let tiling = if "tiling" in dictionary(std) {
|
||||||
|
tiling
|
||||||
|
} else {
|
||||||
|
pattern
|
||||||
|
}
|
||||||
|
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
- name: sys
|
- name: sys
|
||||||
title: System
|
title: System
|
||||||
category: foundations
|
category: foundations
|
||||||
|
@ -37,7 +37,7 @@ static GROUPS: LazyLock<Vec<GroupData>> = LazyLock::new(|| {
|
|||||||
let mut groups: Vec<GroupData> =
|
let mut groups: Vec<GroupData> =
|
||||||
yaml::from_str(load!("reference/groups.yml")).unwrap();
|
yaml::from_str(load!("reference/groups.yml")).unwrap();
|
||||||
for group in &mut groups {
|
for group in &mut groups {
|
||||||
if group.filter.is_empty() {
|
if group.filter.is_empty() && group.name != "std" {
|
||||||
group.filter = group
|
group.filter = group
|
||||||
.module()
|
.module()
|
||||||
.scope()
|
.scope()
|
||||||
|
10
tests/ref/html/html-textarea-starting-with-newline.html
Normal file
10
tests/ref/html/html-textarea-starting-with-newline.html
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
</head>
|
||||||
|
<body><textarea>
|
||||||
|
|
||||||
|
enter</textarea></body>
|
||||||
|
</html>
|
@ -11,6 +11,9 @@
|
|||||||
#html.pre("\nhello")
|
#html.pre("\nhello")
|
||||||
#html.pre("\n\nhello")
|
#html.pre("\n\nhello")
|
||||||
|
|
||||||
|
--- html-textarea-starting-with-newline html ---
|
||||||
|
#html.textarea("\nenter")
|
||||||
|
|
||||||
--- html-script html ---
|
--- html-script html ---
|
||||||
// This should be pretty and indented.
|
// This should be pretty and indented.
|
||||||
#html.script(
|
#html.script(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user