Skip to content

Commit

Permalink
Only set outline if it's not empty
Browse files Browse the repository at this point in the history
  • Loading branch information
LaurenzV committed Dec 17, 2024
1 parent 8bbff37 commit e1a36bf
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions crates/krilla/src/object/outline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ pub struct Outline {
children: Vec<OutlineNode>,
}

impl Outline {
pub(crate) fn is_empty(&self) -> bool {
self.children.is_empty()
}
}

impl Default for Outline {
fn default() -> Self {
Self::new()
Expand Down
11 changes: 10 additions & 1 deletion crates/krilla/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,16 @@ impl SerializeContext {
}

pub(crate) fn set_outline(&mut self, outline: Outline) {
self.global_objects.outline = MaybeTaken::new(Some(outline));
// Only set it if it's not empty or if the current validator requires an
// outline.
if !outline.is_empty()
|| self
.serialize_settings
.validator
.prohibits(&ValidationError::MissingDocumentOutline)
{
self.global_objects.outline = MaybeTaken::new(Some(outline));
}
}

pub(crate) fn set_metadata(&mut self, metadata: Metadata) {
Expand Down

0 comments on commit e1a36bf

Please sign in to comment.