refactor: replace pub(crate) -> pub for items in private tags module

This commit is contained in:
Tobias Schmitz 2025-08-01 11:17:26 +02:00
parent 71433334b4
commit 9e7ef68bce
No known key found for this signature in database
5 changed files with 90 additions and 95 deletions

View File

@ -33,10 +33,7 @@ pub fn pdf(document: &PagedDocument, options: &PdfOptions) -> SourceResult<Vec<u
/// Generate the document tag tree and display it in a human readable form. /// Generate the document tag tree and display it in a human readable form.
#[doc(hidden)] #[doc(hidden)]
pub fn pdf_tags( pub fn pdf_tags(document: &PagedDocument, options: &PdfOptions) -> SourceResult<String> {
document: &PagedDocument,
options: &PdfOptions,
) -> SourceResult<String> {
convert::tag_tree(document, options) convert::tag_tree(document, options)
} }

View File

@ -3,7 +3,7 @@ use krilla::tagging::{ListNumbering, Tag, TagKind};
use crate::tags::{GroupContents, TagNode}; use crate::tags::{GroupContents, TagNode};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct ListCtx { pub struct ListCtx {
numbering: ListNumbering, numbering: ListNumbering,
items: Vec<ListItem>, items: Vec<ListItem>,
} }
@ -16,11 +16,11 @@ struct ListItem {
} }
impl ListCtx { impl ListCtx {
pub(crate) fn new(numbering: ListNumbering) -> Self { pub fn new(numbering: ListNumbering) -> Self {
Self { numbering, items: Vec::new() } Self { numbering, items: Vec::new() }
} }
pub(crate) fn push_label(&mut self, contents: GroupContents) { pub fn push_label(&mut self, contents: GroupContents) {
self.items.push(ListItem { self.items.push(ListItem {
label: TagNode::group(Tag::Lbl, contents), label: TagNode::group(Tag::Lbl, contents),
body: None, body: None,
@ -28,7 +28,7 @@ impl ListCtx {
}); });
} }
pub(crate) fn push_body(&mut self, mut contents: GroupContents) { pub fn push_body(&mut self, mut contents: GroupContents) {
let item = self.items.last_mut().expect("ListItemLabel"); let item = self.items.last_mut().expect("ListItemLabel");
// Nested lists are expected to have the following structure: // Nested lists are expected to have the following structure:
@ -73,7 +73,7 @@ impl ListCtx {
item.body = Some(TagNode::group(Tag::LBody, contents)); item.body = Some(TagNode::group(Tag::LBody, contents));
} }
pub(crate) fn push_bib_entry(&mut self, contents: GroupContents) { pub fn push_bib_entry(&mut self, contents: GroupContents) {
let nodes = vec![TagNode::group(Tag::BibEntry, contents)]; let nodes = vec![TagNode::group(Tag::BibEntry, contents)];
// Bibliography lists cannot be nested, but may be missing labels. // Bibliography lists cannot be nested, but may be missing labels.
let body = TagNode::virtual_group(Tag::LBody, nodes); let body = TagNode::virtual_group(Tag::LBody, nodes);
@ -88,7 +88,7 @@ impl ListCtx {
} }
} }
pub(crate) fn build_list(self, mut contents: GroupContents) -> TagNode { pub fn build_list(self, mut contents: GroupContents) -> TagNode {
for item in self.items.into_iter() { for item in self.items.into_iter() {
contents.nodes.push(TagNode::virtual_group( contents.nodes.push(TagNode::virtual_group(
Tag::LI, Tag::LI,

View File

@ -40,7 +40,7 @@ mod outline;
mod table; mod table;
mod util; mod util;
pub(crate) fn handle_start( pub fn handle_start(
gc: &mut GlobalContext, gc: &mut GlobalContext,
surface: &mut Surface, surface: &mut Surface,
elem: &Content, elem: &Content,
@ -240,7 +240,7 @@ fn push_artifact(
gc.tags.in_artifact = Some((loc, kind)); gc.tags.in_artifact = Some((loc, kind));
} }
pub(crate) fn handle_end( pub fn handle_end(
gc: &mut GlobalContext, gc: &mut GlobalContext,
surface: &mut Surface, surface: &mut Surface,
loc: Location, loc: Location,
@ -452,7 +452,7 @@ fn pop_artifact(gc: &mut GlobalContext, surface: &mut Surface) {
gc.tags.in_artifact = None; gc.tags.in_artifact = None;
} }
pub(crate) fn page_start(gc: &mut GlobalContext, surface: &mut Surface) { pub fn page_start(gc: &mut GlobalContext, surface: &mut Surface) {
if gc.options.disable_tags { if gc.options.disable_tags {
return; return;
} }
@ -464,7 +464,7 @@ pub(crate) fn page_start(gc: &mut GlobalContext, surface: &mut Surface) {
} }
} }
pub(crate) fn page_end(gc: &mut GlobalContext, surface: &mut Surface) { pub fn page_end(gc: &mut GlobalContext, surface: &mut Surface) {
if gc.options.disable_tags { if gc.options.disable_tags {
return; return;
} }
@ -475,7 +475,7 @@ pub(crate) fn page_end(gc: &mut GlobalContext, surface: &mut 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_link_annotations( pub fn add_link_annotations(
gc: &mut GlobalContext, gc: &mut GlobalContext,
page: &mut Page, page: &mut Page,
annotations: Vec<LinkAnnotation>, annotations: Vec<LinkAnnotation>,
@ -499,7 +499,7 @@ pub(crate) fn add_link_annotations(
} }
} }
pub(crate) fn update_bbox( pub fn update_bbox(
gc: &mut GlobalContext, gc: &mut GlobalContext,
fc: &FrameContext, fc: &FrameContext,
compute_bbox: impl FnOnce() -> Rect, compute_bbox: impl FnOnce() -> Rect,
@ -511,19 +511,19 @@ pub(crate) fn update_bbox(
} }
} }
pub(crate) struct Tags { pub struct Tags {
/// The language of the first text item that has been encountered. /// The language of the first text item that has been encountered.
pub(crate) doc_lang: Option<Lang>, pub doc_lang: Option<Lang>,
/// The intermediary stack of nested tag groups. /// The intermediary stack of nested tag groups.
pub(crate) stack: TagStack, pub stack: TagStack,
/// A list of placeholders corresponding to a [`TagNode::Placeholder`]. /// A list of placeholders corresponding to a [`TagNode::Placeholder`].
pub(crate) placeholders: Placeholders, pub placeholders: Placeholders,
/// Footnotes are inserted directly after the footenote reference in the /// Footnotes are inserted directly after the footenote reference in the
/// reading order. Because of some layouting bugs, the entry might appear /// reading order. Because of some layouting bugs, the entry might appear
/// before the reference in the text, so we only resolve them once tags /// before the reference in the text, so we only resolve them once tags
/// for the whole document are generated. /// for the whole document are generated.
pub(crate) footnotes: HashMap<Location, FootnoteCtx>, pub footnotes: HashMap<Location, FootnoteCtx>,
pub(crate) in_artifact: Option<(Location, ArtifactKind)>, pub in_artifact: Option<(Location, ArtifactKind)>,
/// Used to group multiple link annotations using quad points. /// Used to group multiple link annotations using quad points.
link_id: LinkId, link_id: LinkId,
/// Used to generate IDs referenced in table `Headers` attributes. /// Used to generate IDs referenced in table `Headers` attributes.
@ -531,11 +531,11 @@ pub(crate) struct Tags {
table_id: TableId, table_id: TableId,
/// The output. /// The output.
pub(crate) tree: Vec<TagNode>, pub tree: Vec<TagNode>,
} }
impl Tags { impl Tags {
pub(crate) fn new() -> Self { pub fn new() -> Self {
Self { Self {
doc_lang: None, doc_lang: None,
stack: TagStack::new(), stack: TagStack::new(),
@ -550,7 +550,7 @@ impl Tags {
} }
} }
pub(crate) fn push(&mut self, node: TagNode) { pub fn push(&mut self, node: TagNode) {
if let Some(entry) = self.stack.last_mut() { if let Some(entry) = self.stack.last_mut() {
entry.nodes.push(node); entry.nodes.push(node);
} else { } else {
@ -558,7 +558,7 @@ impl Tags {
} }
} }
pub(crate) fn extend(&mut self, nodes: impl IntoIterator<Item = TagNode>) { pub fn extend(&mut self, nodes: impl IntoIterator<Item = TagNode>) {
if let Some(entry) = self.stack.last_mut() { if let Some(entry) = self.stack.last_mut() {
entry.nodes.extend(nodes); entry.nodes.extend(nodes);
} else { } else {
@ -566,7 +566,7 @@ impl Tags {
} }
} }
pub(crate) fn build_tree(&mut self) -> TagTree { pub fn build_tree(&mut self) -> TagTree {
let children = std::mem::take(&mut self.tree) let children = std::mem::take(&mut self.tree)
.into_iter() .into_iter()
.map(|node| self.resolve_node(node)) .map(|node| self.resolve_node(node))
@ -578,7 +578,7 @@ impl Tags {
/// If the language couldn't be set and is different from the existing one, /// If the language couldn't be set and is different from the existing one,
/// this will return `Some`, and the language should be specified on the /// this will return `Some`, and the language should be specified on the
/// marked content directly. /// marked content directly.
pub(crate) fn try_set_lang(&mut self, lang: Lang) -> Option<Lang> { pub fn try_set_lang(&mut self, lang: Lang) -> Option<Lang> {
// Discard languages within artifacts. // Discard languages within artifacts.
if self.in_artifact.is_some() { if self.in_artifact.is_some() {
return None; return None;
@ -622,7 +622,7 @@ impl Tags {
true true
} }
pub(crate) fn next_link_id(&mut self) -> LinkId { pub fn next_link_id(&mut self) -> LinkId {
self.link_id.0 += 1; self.link_id.0 += 1;
self.link_id self.link_id
} }
@ -634,7 +634,7 @@ impl Tags {
} }
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct TagStack { pub struct TagStack {
items: Vec<StackEntry>, items: Vec<StackEntry>,
/// The index of the topmost stack entry that has a bbox. /// The index of the topmost stack entry that has a bbox.
bbox_idx: Option<usize>, bbox_idx: Option<usize>,
@ -657,34 +657,34 @@ impl<I: SliceIndex<[StackEntry]>> std::ops::IndexMut<I> for TagStack {
} }
impl TagStack { impl TagStack {
pub(crate) fn new() -> Self { pub fn new() -> Self {
Self { items: Vec::new(), bbox_idx: None } Self { items: Vec::new(), bbox_idx: None }
} }
pub(crate) fn len(&self) -> usize { pub fn len(&self) -> usize {
self.items.len() self.items.len()
} }
pub(crate) fn last(&self) -> Option<&StackEntry> { pub fn last(&self) -> Option<&StackEntry> {
self.items.last() self.items.last()
} }
pub(crate) fn last_mut(&mut self) -> Option<&mut StackEntry> { pub fn last_mut(&mut self) -> Option<&mut StackEntry> {
self.items.last_mut() self.items.last_mut()
} }
pub(crate) fn iter(&self) -> std::slice::Iter<StackEntry> { pub fn iter(&self) -> std::slice::Iter<StackEntry> {
self.items.iter() self.items.iter()
} }
pub(crate) fn push(&mut self, entry: StackEntry) { pub fn push(&mut self, entry: StackEntry) {
if entry.kind.bbox().is_some() { if entry.kind.bbox().is_some() {
self.bbox_idx = Some(self.len()); self.bbox_idx = Some(self.len());
} }
self.items.push(entry); self.items.push(entry);
} }
pub(crate) fn extend(&mut self, iter: impl IntoIterator<Item = StackEntry>) { pub fn extend(&mut self, iter: impl IntoIterator<Item = StackEntry>) {
let start = self.len(); let start = self.len();
self.items.extend(iter); self.items.extend(iter);
let last_bbox_offset = self.items[start..] let last_bbox_offset = self.items[start..]
@ -697,7 +697,7 @@ impl TagStack {
/// Remove the last stack entry if the predicate returns true. /// Remove the last stack entry if the predicate returns true.
/// This takes care of updating the parent bboxes. /// This takes care of updating the parent bboxes.
pub(crate) fn pop_if( pub fn pop_if(
&mut self, &mut self,
mut predicate: impl FnMut(&mut StackEntry) -> bool, mut predicate: impl FnMut(&mut StackEntry) -> bool,
) -> Option<StackEntry> { ) -> Option<StackEntry> {
@ -707,7 +707,7 @@ impl TagStack {
/// Remove the last stack entry. /// Remove the last stack entry.
/// This takes care of updating the parent bboxes. /// This takes care of updating the parent bboxes.
pub(crate) fn pop(&mut self) -> Option<StackEntry> { pub fn pop(&mut self) -> Option<StackEntry> {
let removed = self.items.pop()?; let removed = self.items.pop()?;
let Some(inner_bbox) = removed.kind.bbox() else { return Some(removed) }; let Some(inner_bbox) = removed.kind.bbox() else { return Some(removed) };
@ -723,32 +723,30 @@ impl TagStack {
Some(removed) Some(removed)
} }
pub(crate) fn parent(&mut self) -> Option<&mut StackEntryKind> { pub fn parent(&mut self) -> Option<&mut StackEntryKind> {
self.items.last_mut().map(|e| &mut e.kind) self.items.last_mut().map(|e| &mut e.kind)
} }
pub(crate) fn parent_table(&mut self) -> Option<&mut TableCtx> { pub fn parent_table(&mut self) -> Option<&mut TableCtx> {
self.parent()?.as_table_mut() self.parent()?.as_table_mut()
} }
pub(crate) fn parent_list(&mut self) -> Option<&mut ListCtx> { pub fn parent_list(&mut self) -> Option<&mut ListCtx> {
self.parent()?.as_list_mut() self.parent()?.as_list_mut()
} }
pub(crate) fn parent_figure(&mut self) -> Option<&mut FigureCtx> { pub fn parent_figure(&mut self) -> Option<&mut FigureCtx> {
self.parent()?.as_figure_mut() self.parent()?.as_figure_mut()
} }
pub(crate) fn parent_outline( pub fn parent_outline(&mut self) -> Option<(&mut OutlineCtx, &mut Vec<TagNode>)> {
&mut self,
) -> Option<(&mut OutlineCtx, &mut Vec<TagNode>)> {
self.items.last_mut().and_then(|e| { self.items.last_mut().and_then(|e| {
let ctx = e.kind.as_outline_mut()?; let ctx = e.kind.as_outline_mut()?;
Some((ctx, &mut e.nodes)) Some((ctx, &mut e.nodes))
}) })
} }
pub(crate) fn find_parent_link( pub fn find_parent_link(
&mut self, &mut self,
) -> Option<(LinkId, &Packed<LinkMarker>, &mut Vec<TagNode>)> { ) -> Option<(LinkId, &Packed<LinkMarker>, &mut Vec<TagNode>)> {
self.items.iter_mut().rev().find_map(|e| { self.items.iter_mut().rev().find_map(|e| {
@ -758,49 +756,49 @@ impl TagStack {
} }
/// Finds the first parent that has a bounding box. /// Finds the first parent that has a bounding box.
pub(crate) fn find_parent_bbox(&mut self) -> Option<&mut BBoxCtx> { pub fn find_parent_bbox(&mut self) -> Option<&mut BBoxCtx> {
self.items[self.bbox_idx?].kind.bbox_mut() self.items[self.bbox_idx?].kind.bbox_mut()
} }
} }
pub(crate) struct Placeholders(Vec<OnceCell<Node>>); pub struct Placeholders(Vec<OnceCell<Node>>);
impl Placeholders { impl Placeholders {
pub(crate) fn reserve(&mut self) -> Placeholder { pub fn reserve(&mut self) -> Placeholder {
let idx = self.0.len(); let idx = self.0.len();
self.0.push(OnceCell::new()); self.0.push(OnceCell::new());
Placeholder(idx) Placeholder(idx)
} }
pub(crate) fn init(&mut self, placeholder: Placeholder, node: Node) { pub fn init(&mut self, placeholder: Placeholder, node: Node) {
self.0[placeholder.0] self.0[placeholder.0]
.set(node) .set(node)
.map_err(|_| ()) .map_err(|_| ())
.expect("placeholder to be uninitialized"); .expect("placeholder to be uninitialized");
} }
pub(crate) fn take(&mut self, placeholder: Placeholder) -> Node { pub fn take(&mut self, placeholder: Placeholder) -> Node {
self.0[placeholder.0].take().expect("initialized placeholder node") self.0[placeholder.0].take().expect("initialized placeholder node")
} }
} }
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct TableId(u32); pub struct TableId(u32);
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct LinkId(u32); pub struct LinkId(u32);
#[derive(Debug)] #[derive(Debug)]
pub(crate) struct StackEntry { pub struct StackEntry {
pub(crate) loc: Location, pub loc: Location,
pub(crate) span: Span, pub span: Span,
pub(crate) lang: Option<Lang>, pub lang: Option<Lang>,
pub(crate) kind: StackEntryKind, pub kind: StackEntryKind,
pub(crate) nodes: Vec<TagNode>, pub nodes: Vec<TagNode>,
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) enum StackEntryKind { pub enum StackEntryKind {
Standard(TagKind), Standard(TagKind),
Outline(OutlineCtx), Outline(OutlineCtx),
OutlineEntry(Packed<OutlineEntry>), OutlineEntry(Packed<OutlineEntry>),
@ -822,27 +820,27 @@ pub(crate) enum StackEntryKind {
} }
impl StackEntryKind { impl StackEntryKind {
pub(crate) fn as_outline_mut(&mut self) -> Option<&mut OutlineCtx> { pub fn as_outline_mut(&mut self) -> Option<&mut OutlineCtx> {
if let Self::Outline(v) = self { Some(v) } else { None } if let Self::Outline(v) = self { Some(v) } else { None }
} }
pub(crate) fn as_table_mut(&mut self) -> Option<&mut TableCtx> { pub fn as_table_mut(&mut self) -> Option<&mut TableCtx> {
if let Self::Table(v) = self { Some(v) } else { None } if let Self::Table(v) = self { Some(v) } else { None }
} }
pub(crate) fn as_list_mut(&mut self) -> Option<&mut ListCtx> { pub fn as_list_mut(&mut self) -> Option<&mut ListCtx> {
if let Self::List(v) = self { Some(v) } else { None } if let Self::List(v) = self { Some(v) } else { None }
} }
pub(crate) fn as_figure_mut(&mut self) -> Option<&mut FigureCtx> { pub fn as_figure_mut(&mut self) -> Option<&mut FigureCtx> {
if let Self::Figure(v) = self { Some(v) } else { None } if let Self::Figure(v) = self { Some(v) } else { None }
} }
pub(crate) fn as_link(&self) -> Option<(LinkId, &Packed<LinkMarker>)> { pub fn as_link(&self) -> Option<(LinkId, &Packed<LinkMarker>)> {
if let Self::Link(id, link) = self { Some((*id, link)) } else { None } if let Self::Link(id, link) = self { Some((*id, link)) } else { None }
} }
pub(crate) fn bbox(&self) -> Option<&BBoxCtx> { pub fn bbox(&self) -> Option<&BBoxCtx> {
match self { match self {
Self::Table(ctx) => Some(&ctx.bbox), Self::Table(ctx) => Some(&ctx.bbox),
Self::Figure(ctx) => Some(&ctx.bbox), Self::Figure(ctx) => Some(&ctx.bbox),
@ -851,7 +849,7 @@ impl StackEntryKind {
} }
} }
pub(crate) fn bbox_mut(&mut self) -> Option<&mut BBoxCtx> { pub fn bbox_mut(&mut self) -> Option<&mut BBoxCtx> {
match self { match self {
Self::Table(ctx) => Some(&mut ctx.bbox), Self::Table(ctx) => Some(&mut ctx.bbox),
Self::Figure(ctx) => Some(&mut ctx.bbox), Self::Figure(ctx) => Some(&mut ctx.bbox),
@ -920,7 +918,7 @@ impl StackEntryKind {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub(crate) struct FootnoteCtx { pub struct FootnoteCtx {
/// Whether this footenote has been referenced inside the document. The /// Whether this footenote has been referenced inside the document. The
/// entry will be inserted inside the reading order after the first /// entry will be inserted inside the reading order after the first
/// reference. All other references will still have links to the footnote. /// reference. All other references will still have links to the footnote.
@ -937,7 +935,7 @@ impl FootnoteCtx {
/// Figure/Formula context /// Figure/Formula context
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub(crate) struct FigureCtx { pub struct FigureCtx {
alt: Option<String>, alt: Option<String>,
bbox: BBoxCtx, bbox: BBoxCtx,
} }
@ -949,23 +947,23 @@ impl FigureCtx {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub(crate) struct BBoxCtx { pub struct BBoxCtx {
rect: Option<(usize, Rect)>, rect: Option<(usize, Rect)>,
multi_page: bool, multi_page: bool,
} }
impl BBoxCtx { impl BBoxCtx {
pub(crate) fn new() -> Self { pub fn new() -> Self {
Self { rect: None, multi_page: false } Self { rect: None, multi_page: false }
} }
pub(crate) fn reset(&mut self) { pub fn reset(&mut self) {
*self = Self::new(); *self = Self::new();
} }
/// Expand the bounding box with a `rect` relative to the current frame /// Expand the bounding box with a `rect` relative to the current frame
/// context transform. /// context transform.
pub(crate) fn expand_frame(&mut self, fc: &FrameContext, rect: Rect) { pub fn expand_frame(&mut self, fc: &FrameContext, rect: Rect) {
let Some(page_idx) = fc.page_idx else { return }; let Some(page_idx) = fc.page_idx else { return };
if self.multi_page { if self.multi_page {
return; return;
@ -995,7 +993,7 @@ impl BBoxCtx {
/// Expand the bounding box with a rectangle that's already transformed into /// Expand the bounding box with a rectangle that's already transformed into
/// page coordinates. /// page coordinates.
pub(crate) fn expand_page(&mut self, page_idx: usize, rect: Rect) { pub fn expand_page(&mut self, page_idx: usize, rect: Rect) {
if self.multi_page { if self.multi_page {
return; return;
} }
@ -1013,7 +1011,7 @@ impl BBoxCtx {
bbox.max = bbox.max.max(rect.max); bbox.max = bbox.max.max(rect.max);
} }
pub(crate) fn get(&self) -> Option<BBox> { pub fn get(&self) -> Option<BBox> {
let (page_idx, rect) = self.rect?; let (page_idx, rect) = self.rect?;
let rect = kg::Rect::from_ltrb( let rect = kg::Rect::from_ltrb(
rect.min.x.to_f32(), rect.min.x.to_f32(),
@ -1027,7 +1025,7 @@ impl BBoxCtx {
} }
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub(crate) enum TagNode { pub enum TagNode {
Group(TagGroup), Group(TagGroup),
Leaf(Identifier), Leaf(Identifier),
/// Allows inserting a placeholder into the tag tree. /// Allows inserting a placeholder into the tag tree.
@ -1072,10 +1070,10 @@ pub struct GroupContents {
} }
#[derive(Clone, Copy, Debug, Eq, PartialEq)] #[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) struct Placeholder(usize); pub struct Placeholder(usize);
/// Automatically calls [`Surface::end_tagged`] when dropped. /// Automatically calls [`Surface::end_tagged`] when dropped.
pub(crate) struct TagHandle<'a, 'b> { pub struct TagHandle<'a, 'b> {
surface: &'b mut Surface<'a>, surface: &'b mut Surface<'a>,
/// Whether this tag handle started the marked content sequence, and should /// Whether this tag handle started the marked content sequence, and should
/// thus end it when it is dropped. /// thus end it when it is dropped.
@ -1091,14 +1089,14 @@ impl Drop for TagHandle<'_, '_> {
} }
impl<'a> TagHandle<'a, '_> { impl<'a> TagHandle<'a, '_> {
pub(crate) fn surface<'c>(&'c mut self) -> &'c mut Surface<'a> { pub fn surface<'c>(&'c mut self) -> &'c mut Surface<'a> {
self.surface self.surface
} }
} }
/// Returns a [`TagHandle`] that automatically calls [`Surface::end_tagged`] /// Returns a [`TagHandle`] that automatically calls [`Surface::end_tagged`]
/// when dropped. /// when dropped.
pub(crate) fn start_span<'a, 'b>( pub fn start_span<'a, 'b>(
gc: &mut GlobalContext, gc: &mut GlobalContext,
surface: &'b mut Surface<'a>, surface: &'b mut Surface<'a>,
span: SpanTag, span: SpanTag,
@ -1108,7 +1106,7 @@ pub(crate) fn start_span<'a, 'b>(
/// Returns a [`TagHandle`] that automatically calls [`Surface::end_tagged`] /// Returns a [`TagHandle`] that automatically calls [`Surface::end_tagged`]
/// when dropped. /// when dropped.
pub(crate) fn start_artifact<'a, 'b>( pub fn start_artifact<'a, 'b>(
gc: &mut GlobalContext, gc: &mut GlobalContext,
surface: &'b mut Surface<'a>, surface: &'b mut Surface<'a>,
kind: ArtifactKind, kind: ArtifactKind,

View File

@ -5,16 +5,16 @@ use typst_library::model::OutlineEntry;
use crate::tags::{GroupContents, TagNode}; use crate::tags::{GroupContents, TagNode};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct OutlineCtx { pub struct OutlineCtx {
stack: Vec<OutlineSection>, stack: Vec<OutlineSection>,
} }
impl OutlineCtx { impl OutlineCtx {
pub(crate) fn new() -> Self { pub fn new() -> Self {
Self { stack: Vec::new() } Self { stack: Vec::new() }
} }
pub(crate) fn insert( pub fn insert(
&mut self, &mut self,
outline_nodes: &mut Vec<TagNode>, outline_nodes: &mut Vec<TagNode>,
entry: Packed<OutlineEntry>, entry: Packed<OutlineEntry>,
@ -45,7 +45,7 @@ impl OutlineCtx {
} }
} }
pub(crate) fn build_outline(mut self, mut contents: GroupContents) -> TagNode { pub fn build_outline(mut self, mut contents: GroupContents) -> TagNode {
while !self.stack.is_empty() { while !self.stack.is_empty() {
self.finish_section(&mut contents.nodes); self.finish_section(&mut contents.nodes);
} }
@ -54,7 +54,7 @@ impl OutlineCtx {
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct OutlineSection { pub struct OutlineSection {
entries: Vec<TagNode>, entries: Vec<TagNode>,
} }

View File

@ -12,16 +12,16 @@ use crate::tags::util::PropertyValCopied;
use crate::tags::{BBoxCtx, GroupContents, TableId, TagNode}; use crate::tags::{BBoxCtx, GroupContents, TableId, TagNode};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct TableCtx { pub struct TableCtx {
pub(crate) id: TableId, pub id: TableId,
pub(crate) summary: Option<String>, pub summary: Option<String>,
pub(crate) bbox: BBoxCtx, pub bbox: BBoxCtx,
rows: Vec<Vec<GridCell>>, rows: Vec<Vec<GridCell>>,
min_width: usize, min_width: usize,
} }
impl TableCtx { impl TableCtx {
pub(crate) fn new(id: TableId, summary: Option<String>) -> Self { pub fn new(id: TableId, summary: Option<String>) -> Self {
Self { Self {
id, id,
summary, summary,
@ -49,7 +49,7 @@ impl TableCtx {
} }
} }
pub(crate) fn contains(&self, cell: &Packed<TableCell>) -> bool { pub fn contains(&self, cell: &Packed<TableCell>) -> bool {
let x = cell.x.val().unwrap_or_else(|| unreachable!()); let x = cell.x.val().unwrap_or_else(|| unreachable!());
let y = cell.y.val().unwrap_or_else(|| unreachable!()); let y = cell.y.val().unwrap_or_else(|| unreachable!());
self.get(x, y).is_some() self.get(x, y).is_some()
@ -63,7 +63,7 @@ impl TableCtx {
} }
} }
pub(crate) fn insert(&mut self, cell: &Packed<TableCell>, contents: GroupContents) { pub fn insert(&mut self, cell: &Packed<TableCell>, contents: GroupContents) {
let x = cell.x.val().unwrap_or_else(|| unreachable!()); let x = cell.x.val().unwrap_or_else(|| unreachable!());
let y = cell.y.val().unwrap_or_else(|| unreachable!()); let y = cell.y.val().unwrap_or_else(|| unreachable!());
let rowspan = cell.rowspan.val(); let rowspan = cell.rowspan.val();
@ -101,7 +101,7 @@ impl TableCtx {
}); });
} }
pub(crate) fn build_table(mut self, mut contents: GroupContents) -> TagNode { pub fn build_table(mut self, mut contents: GroupContents) -> TagNode {
// Table layouting ensures that there are no overlapping cells, and that // Table layouting ensures that there are no overlapping cells, and that
// any gaps left by the user are filled with empty cells. // any gaps left by the user are filled with empty cells.
if self.rows.is_empty() { if self.rows.is_empty() {