1use hwpforge_foundation::{
25 ApplyPageType, HwpUnit, NumberFormatType, PageNumberPosition, ShowMode, TextDirection,
26};
27use schemars::JsonSchema;
28use serde::{Deserialize, Serialize};
29
30use crate::column::ColumnSettings;
31use crate::page::PageSettings;
32use crate::paragraph::Paragraph;
33
34#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
43pub struct Visibility {
44 #[serde(default)]
46 pub hide_first_header: bool,
47 #[serde(default)]
49 pub hide_first_footer: bool,
50 #[serde(default)]
52 pub hide_first_master_page: bool,
53 #[serde(default)]
55 pub hide_first_page_num: bool,
56 #[serde(default)]
58 pub hide_first_empty_line: bool,
59 #[serde(default)]
61 pub show_line_number: bool,
62 #[serde(default)]
64 pub border: ShowMode,
65 #[serde(default)]
67 pub fill: ShowMode,
68}
69
70impl Default for Visibility {
71 fn default() -> Self {
72 Self {
73 hide_first_header: false,
74 hide_first_footer: false,
75 hide_first_master_page: false,
76 hide_first_page_num: false,
77 hide_first_empty_line: false,
78 show_line_number: false,
79 border: ShowMode::ShowAll,
80 fill: ShowMode::ShowAll,
81 }
82 }
83}
84
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
93pub struct LineNumberShape {
94 #[serde(default)]
96 pub restart_type: u8,
97 #[serde(default)]
99 pub count_by: u16,
100 #[serde(default)]
102 pub distance: HwpUnit,
103 #[serde(default)]
105 pub start_number: u32,
106}
107
108#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
117pub struct PageBorderFillEntry {
118 pub apply_type: String,
120 #[serde(default = "PageBorderFillEntry::default_border_fill_id")]
122 pub border_fill_id: u32,
123 #[serde(default = "PageBorderFillEntry::default_text_border")]
125 pub text_border: String,
126 #[serde(default)]
128 pub header_inside: bool,
129 #[serde(default)]
131 pub footer_inside: bool,
132 #[serde(default = "PageBorderFillEntry::default_fill_area")]
134 pub fill_area: String,
135 #[serde(default = "PageBorderFillEntry::default_offset")]
137 pub offset: [HwpUnit; 4],
138}
139
140impl PageBorderFillEntry {
141 fn default_border_fill_id() -> u32 {
142 1
143 }
144 fn default_text_border() -> String {
145 "PAPER".to_string()
146 }
147 fn default_fill_area() -> String {
148 "PAPER".to_string()
149 }
150 fn default_offset() -> [HwpUnit; 4] {
151 [
153 HwpUnit::new(1417).unwrap(),
154 HwpUnit::new(1417).unwrap(),
155 HwpUnit::new(1417).unwrap(),
156 HwpUnit::new(1417).unwrap(),
157 ]
158 }
159}
160
161impl Default for PageBorderFillEntry {
162 fn default() -> Self {
163 Self {
164 apply_type: "BOTH".to_string(),
165 border_fill_id: 1,
166 text_border: "PAPER".to_string(),
167 header_inside: false,
168 footer_inside: false,
169 fill_area: "PAPER".to_string(),
170 offset: Self::default_offset(),
171 }
172 }
173}
174
175#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize, JsonSchema)]
185pub enum PageStartsOn {
186 #[default]
188 Both,
189 Even,
191 Odd,
193}
194
195#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
200pub struct BeginNum {
201 #[serde(default = "BeginNum::one")]
207 pub page: u32,
208 #[serde(default = "BeginNum::one")]
210 pub footnote: u32,
211 #[serde(default = "BeginNum::one")]
213 pub endnote: u32,
214 #[serde(default = "BeginNum::one")]
216 pub pic: u32,
217 #[serde(default = "BeginNum::one")]
219 pub tbl: u32,
220 #[serde(default = "BeginNum::one")]
222 pub equation: u32,
223 #[serde(default, skip_serializing_if = "PageStartsOn::is_default")]
225 pub page_starts_on: PageStartsOn,
226}
227
228impl PageStartsOn {
229 fn is_default(&self) -> bool {
231 *self == Self::Both
232 }
233}
234
235impl BeginNum {
236 fn one() -> u32 {
237 1
238 }
239}
240
241impl Default for BeginNum {
242 fn default() -> Self {
243 Self {
244 page: 1,
245 footnote: 1,
246 endnote: 1,
247 pic: 1,
248 tbl: 1,
249 equation: 1,
250 page_starts_on: PageStartsOn::Both,
251 }
252 }
253}
254
255#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
267pub struct MasterPage {
268 pub apply_page_type: ApplyPageType,
270 pub paragraphs: Vec<Paragraph>,
272}
273
274impl MasterPage {
275 pub fn new(apply_page_type: ApplyPageType, paragraphs: Vec<Paragraph>) -> Self {
277 Self { apply_page_type, paragraphs }
278 }
279}
280
281impl std::fmt::Display for MasterPage {
282 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
283 let n = self.paragraphs.len();
284 let word = if n == 1 { "paragraph" } else { "paragraphs" };
285 write!(f, "MasterPage({n} {word}, {:?})", self.apply_page_type)
286 }
287}
288
289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
314pub struct HeaderFooter {
315 pub paragraphs: Vec<Paragraph>,
317 pub apply_page_type: ApplyPageType,
319 #[serde(default)]
324 pub vert_align: hwpforge_foundation::VerticalAlign,
325 #[serde(default, skip_serializing_if = "HwpUnit::is_zero")]
327 pub text_width: HwpUnit,
328 #[serde(default, skip_serializing_if = "HwpUnit::is_zero")]
333 pub text_height: HwpUnit,
334}
335
336impl HeaderFooter {
337 pub fn new(paragraphs: Vec<Paragraph>, apply_page_type: ApplyPageType) -> Self {
342 Self {
343 paragraphs,
344 apply_page_type,
345 vert_align: hwpforge_foundation::VerticalAlign::default(),
346 text_width: HwpUnit::ZERO,
347 text_height: HwpUnit::ZERO,
348 }
349 }
350
351 pub fn all_pages(paragraphs: Vec<Paragraph>) -> Self {
368 Self::new(paragraphs, ApplyPageType::Both)
369 }
370
371 #[deprecated(since = "0.2.0", note = "Use `all_pages()` instead")]
373 pub fn both(paragraphs: Vec<Paragraph>) -> Self {
374 Self::all_pages(paragraphs)
375 }
376}
377
378impl std::fmt::Display for HeaderFooter {
379 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
380 let n = self.paragraphs.len();
381 let word = if n == 1 { "paragraph" } else { "paragraphs" };
382 write!(f, "HeaderFooter({n} {word}, {:?})", self.apply_page_type)
383 }
384}
385
386#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
408pub struct PageNumber {
409 pub position: PageNumberPosition,
411 pub number_format: NumberFormatType,
413 pub decoration: String,
416}
417
418impl PageNumber {
419 pub fn new(position: PageNumberPosition, number_format: NumberFormatType) -> Self {
421 Self { position, number_format, decoration: String::new() }
422 }
423
424 pub fn bottom_center() -> Self {
442 Self {
443 position: PageNumberPosition::BottomCenter,
444 number_format: NumberFormatType::Digit,
445 decoration: String::new(),
446 }
447 }
448
449 pub fn with_decoration(
465 position: PageNumberPosition,
466 number_format: NumberFormatType,
467 decoration: impl Into<String>,
468 ) -> Self {
469 Self { position, number_format, decoration: decoration.into() }
470 }
471
472 #[deprecated(since = "0.2.0", note = "Use `with_decoration()` instead")]
474 pub fn with_side_char(
475 position: PageNumberPosition,
476 number_format: NumberFormatType,
477 side_char: impl Into<String>,
478 ) -> Self {
479 Self::with_decoration(position, number_format, side_char)
480 }
481}
482
483impl std::fmt::Display for PageNumber {
484 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
485 write!(f, "PageNumber({:?}, {:?})", self.position, self.number_format)
486 }
487}
488
489#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
510pub struct Section {
511 pub paragraphs: Vec<Paragraph>,
513 pub page_settings: PageSettings,
515 #[serde(default, skip_serializing_if = "Vec::is_empty")]
524 pub headers: Vec<HeaderFooter>,
525 #[serde(default, skip_serializing_if = "Vec::is_empty")]
528 pub footers: Vec<HeaderFooter>,
529 #[serde(default, skip_serializing_if = "Option::is_none")]
531 pub page_number: Option<PageNumber>,
532 #[serde(default, skip_serializing_if = "Option::is_none")]
534 pub column_settings: Option<ColumnSettings>,
535 #[serde(default, skip_serializing_if = "Option::is_none")]
538 pub visibility: Option<Visibility>,
539 #[serde(default, skip_serializing_if = "Option::is_none")]
541 pub line_number_shape: Option<LineNumberShape>,
542 #[serde(default, skip_serializing_if = "Option::is_none")]
544 pub page_border_fills: Option<Vec<PageBorderFillEntry>>,
545 #[serde(default, skip_serializing_if = "Option::is_none")]
548 pub master_pages: Option<Vec<MasterPage>>,
549 #[serde(default, skip_serializing_if = "Option::is_none")]
552 pub begin_num: Option<BeginNum>,
553 #[serde(default)]
556 pub text_direction: TextDirection,
557}
558
559impl Section {
560 pub fn for_each_paragraph_mut<F: FnMut(&mut Paragraph)>(&mut self, mut f: F) {
563 self.walk_paragraphs_mut(&mut f);
564 }
565
566 pub(crate) fn walk_paragraphs_mut(&mut self, f: &mut dyn FnMut(&mut Paragraph)) {
568 for p in &mut self.paragraphs {
569 p.walk_paragraphs_mut(f);
570 }
571 for hf in self.headers.iter_mut().chain(self.footers.iter_mut()) {
572 for p in &mut hf.paragraphs {
573 p.walk_paragraphs_mut(f);
574 }
575 }
576 if let Some(master_pages) = &mut self.master_pages {
577 for mp in master_pages {
578 for p in &mut mp.paragraphs {
579 p.walk_paragraphs_mut(f);
580 }
581 }
582 }
583 }
584
585 pub fn new(page_settings: PageSettings) -> Self {
597 Self {
598 paragraphs: Vec::new(),
599 page_settings,
600 headers: Vec::new(),
601 footers: Vec::new(),
602 page_number: None,
603 column_settings: None,
604 visibility: None,
605 line_number_shape: None,
606 page_border_fills: None,
607 master_pages: None,
608 begin_num: None,
609 text_direction: TextDirection::Horizontal,
610 }
611 }
612
613 pub fn with_paragraphs(paragraphs: Vec<Paragraph>, page_settings: PageSettings) -> Self {
630 Self {
631 paragraphs,
632 page_settings,
633 headers: Vec::new(),
634 footers: Vec::new(),
635 page_number: None,
636 column_settings: None,
637 visibility: None,
638 line_number_shape: None,
639 page_border_fills: None,
640 master_pages: None,
641 begin_num: None,
642 text_direction: TextDirection::Horizontal,
643 }
644 }
645
646 pub fn with_text_direction(mut self, dir: TextDirection) -> Self {
660 self.text_direction = dir;
661 self
662 }
663
664 pub fn add_paragraph(&mut self, paragraph: Paragraph) {
666 self.paragraphs.push(paragraph);
667 }
668
669 pub fn paragraph_count(&self) -> usize {
671 self.paragraphs.len()
672 }
673
674 pub fn is_empty(&self) -> bool {
676 self.paragraphs.is_empty()
677 }
678
679 pub fn content_counts(&self) -> ContentCounts {
696 let mut tables: usize = 0;
697 let mut images: usize = 0;
698 let mut charts: usize = 0;
699
700 for para in &self.paragraphs {
701 for run in ¶.runs {
702 match &run.content {
703 crate::RunContent::Table(_) => tables += 1,
704 crate::RunContent::Image(_) => images += 1,
705 crate::RunContent::Control(c) => {
706 if matches!(**c, crate::control::Control::Chart { .. }) {
707 charts += 1;
708 }
709 }
710 _ => {}
711 }
712 }
713 }
714
715 ContentCounts { tables, images, charts }
716 }
717}
718
719#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
721pub struct ContentCounts {
722 pub tables: usize,
724 pub images: usize,
726 pub charts: usize,
728}
729
730impl std::fmt::Display for Section {
731 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
732 let n = self.paragraphs.len();
733 let word = if n == 1 { "paragraph" } else { "paragraphs" };
734 write!(f, "Section({n} {word})")
735 }
736}
737
738#[cfg(test)]
739mod tests {
740 use super::*;
741 use crate::run::Run;
742 use hwpforge_foundation::{
743 ApplyPageType, CharShapeIndex, NumberFormatType, PageNumberPosition, ParaShapeIndex,
744 };
745
746 fn simple_paragraph() -> Paragraph {
747 Paragraph::with_runs(
748 vec![Run::text("text", CharShapeIndex::new(0))],
749 ParaShapeIndex::new(0),
750 )
751 }
752
753 #[test]
754 fn new_is_empty() {
755 let section = Section::new(PageSettings::a4());
756 assert!(section.is_empty());
757 assert_eq!(section.paragraph_count(), 0);
758 }
759
760 #[test]
761 fn with_paragraphs() {
762 let section = Section::with_paragraphs(
763 vec![simple_paragraph(), simple_paragraph()],
764 PageSettings::a4(),
765 );
766 assert_eq!(section.paragraph_count(), 2);
767 assert!(!section.is_empty());
768 }
769
770 #[test]
771 fn add_paragraph() {
772 let mut section = Section::new(PageSettings::a4());
773 section.add_paragraph(simple_paragraph());
774 section.add_paragraph(simple_paragraph());
775 assert_eq!(section.paragraph_count(), 2);
776 }
777
778 #[test]
779 fn page_settings_preserved() {
780 let section = Section::new(PageSettings::letter());
781 assert_eq!(section.page_settings, PageSettings::letter());
782 }
783
784 #[test]
785 fn display_singular() {
786 let section = Section::with_paragraphs(vec![simple_paragraph()], PageSettings::a4());
787 assert_eq!(section.to_string(), "Section(1 paragraph)");
788 }
789
790 #[test]
791 fn display_plural() {
792 let section = Section::with_paragraphs(
793 vec![simple_paragraph(), simple_paragraph()],
794 PageSettings::a4(),
795 );
796 assert_eq!(section.to_string(), "Section(2 paragraphs)");
797 }
798
799 #[test]
800 fn equality() {
801 let a = Section::with_paragraphs(vec![simple_paragraph()], PageSettings::a4());
802 let b = Section::with_paragraphs(vec![simple_paragraph()], PageSettings::a4());
803 assert_eq!(a, b);
804 }
805
806 #[test]
807 fn inequality_different_page_settings() {
808 let a = Section::new(PageSettings::a4());
809 let b = Section::new(PageSettings::letter());
810 assert_ne!(a, b);
811 }
812
813 #[test]
814 fn clone_independence() {
815 let section = Section::with_paragraphs(vec![simple_paragraph()], PageSettings::a4());
816 let mut cloned = section.clone();
817 cloned.add_paragraph(simple_paragraph());
818 assert_eq!(section.paragraph_count(), 1);
819 assert_eq!(cloned.paragraph_count(), 2);
820 }
821
822 #[test]
823 fn serde_roundtrip() {
824 let section = Section::with_paragraphs(vec![simple_paragraph()], PageSettings::a4());
825 let json = serde_json::to_string(§ion).unwrap();
826 let back: Section = serde_json::from_str(&json).unwrap();
827 assert_eq!(section, back);
828 }
829
830 #[test]
831 fn serde_empty_section() {
832 let section = Section::new(PageSettings::a4());
833 let json = serde_json::to_string(§ion).unwrap();
834 let back: Section = serde_json::from_str(&json).unwrap();
835 assert_eq!(section, back);
836 }
837
838 #[test]
839 fn serde_letter_page() {
840 let section = Section::new(PageSettings::letter());
841 let json = serde_json::to_string(§ion).unwrap();
842 let back: Section = serde_json::from_str(&json).unwrap();
843 assert_eq!(section, back);
844 }
845
846 #[test]
851 fn header_footer_new() {
852 let hf =
853 HeaderFooter::new(vec![Paragraph::new(ParaShapeIndex::new(0))], ApplyPageType::Both);
854 assert_eq!(hf.paragraphs.len(), 1);
855 assert_eq!(hf.apply_page_type, ApplyPageType::Both);
856 }
857
858 #[test]
859 fn header_footer_even_odd() {
860 let even = HeaderFooter::new(vec![], ApplyPageType::Even);
861 let odd = HeaderFooter::new(vec![], ApplyPageType::Odd);
862 assert_eq!(even.apply_page_type, ApplyPageType::Even);
863 assert_eq!(odd.apply_page_type, ApplyPageType::Odd);
864 assert_ne!(even, odd);
865 }
866
867 #[test]
868 fn header_footer_display() {
869 let hf =
870 HeaderFooter::new(vec![Paragraph::new(ParaShapeIndex::new(0))], ApplyPageType::Both);
871 let s = hf.to_string();
872 assert!(s.contains("1 paragraph"), "display: {s}");
873 assert!(s.contains("Both"), "display: {s}");
874 }
875
876 #[test]
877 fn header_footer_serde_roundtrip() {
878 let hf = HeaderFooter::new(
879 vec![Paragraph::with_runs(
880 vec![Run::text("Header text", CharShapeIndex::new(0))],
881 ParaShapeIndex::new(0),
882 )],
883 ApplyPageType::Both,
884 );
885 let json = serde_json::to_string(&hf).unwrap();
886 let back: HeaderFooter = serde_json::from_str(&json).unwrap();
887 assert_eq!(hf, back);
888 }
889
890 #[test]
891 fn header_footer_clone_independence() {
892 let hf =
893 HeaderFooter::new(vec![Paragraph::new(ParaShapeIndex::new(0))], ApplyPageType::Both);
894 let mut cloned = hf.clone();
895 cloned.paragraphs.push(Paragraph::new(ParaShapeIndex::new(1)));
896 assert_eq!(hf.paragraphs.len(), 1);
897 assert_eq!(cloned.paragraphs.len(), 2);
898 }
899
900 #[test]
905 fn page_number_new() {
906 let pn = PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit);
907 assert_eq!(pn.position, PageNumberPosition::BottomCenter);
908 assert_eq!(pn.number_format, NumberFormatType::Digit);
909 assert!(pn.decoration.is_empty());
910 }
911
912 #[test]
913 fn page_number_with_decoration() {
914 let pn = PageNumber::with_decoration(
915 PageNumberPosition::BottomCenter,
916 NumberFormatType::RomanCapital,
917 "- ",
918 );
919 assert_eq!(pn.decoration, "- ");
920 assert_eq!(pn.number_format, NumberFormatType::RomanCapital);
921 }
922
923 #[test]
924 #[allow(deprecated)]
925 fn page_number_with_side_char_deprecated() {
926 let pn = PageNumber::with_side_char(
927 PageNumberPosition::BottomCenter,
928 NumberFormatType::Digit,
929 "- ",
930 );
931 assert_eq!(pn.decoration, "- ");
932 }
933
934 #[test]
935 fn page_number_display() {
936 let pn = PageNumber::new(PageNumberPosition::TopCenter, NumberFormatType::Digit);
937 let s = pn.to_string();
938 assert!(s.contains("TopCenter"), "display: {s}");
939 assert!(s.contains("Digit"), "display: {s}");
940 }
941
942 #[test]
943 fn page_number_serde_roundtrip() {
944 let pn = PageNumber::with_decoration(
945 PageNumberPosition::BottomCenter,
946 NumberFormatType::CircledDigit,
947 "< ",
948 );
949 let json = serde_json::to_string(&pn).unwrap();
950 let back: PageNumber = serde_json::from_str(&json).unwrap();
951 assert_eq!(pn, back);
952 }
953
954 #[test]
955 fn page_number_equality() {
956 let a = PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit);
957 let b = PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit);
958 assert_eq!(a, b);
959 }
960
961 #[test]
962 fn page_number_inequality() {
963 let a = PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit);
964 let b = PageNumber::new(PageNumberPosition::TopCenter, NumberFormatType::Digit);
965 assert_ne!(a, b);
966 }
967
968 #[test]
973 fn section_new_has_empty_header_footer_vecs() {
974 let section = Section::new(PageSettings::a4());
975 assert!(section.headers.is_empty());
976 assert!(section.footers.is_empty());
977 assert!(section.page_number.is_none());
978 assert!(section.column_settings.is_none());
979 }
980
981 #[test]
982 fn section_with_header_footer() {
983 let mut section = Section::new(PageSettings::a4());
984 section.headers.push(HeaderFooter::new(
985 vec![Paragraph::with_runs(
986 vec![Run::text("Header", CharShapeIndex::new(0))],
987 ParaShapeIndex::new(0),
988 )],
989 ApplyPageType::Both,
990 ));
991 section.footers.push(HeaderFooter::new(
992 vec![Paragraph::with_runs(
993 vec![Run::text("Footer", CharShapeIndex::new(0))],
994 ParaShapeIndex::new(0),
995 )],
996 ApplyPageType::Both,
997 ));
998 assert_eq!(section.headers.len(), 1);
999 assert_eq!(section.footers.len(), 1);
1000 }
1001
1002 #[test]
1003 fn section_with_page_number() {
1004 let mut section = Section::new(PageSettings::a4());
1005 section.page_number =
1006 Some(PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit));
1007 assert!(section.page_number.is_some());
1008 }
1009
1010 #[test]
1011 fn section_serde_with_optional_fields() {
1012 let mut section = Section::new(PageSettings::a4());
1013 section.headers.push(HeaderFooter::new(vec![], ApplyPageType::Both));
1014 section.page_number =
1015 Some(PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit));
1016 let json = serde_json::to_string(§ion).unwrap();
1017 let back: Section = serde_json::from_str(&json).unwrap();
1018 assert_eq!(section, back);
1019 }
1020
1021 #[test]
1022 fn section_serde_none_fields_skipped() {
1023 let section = Section::new(PageSettings::a4());
1024 let json = serde_json::to_string(§ion).unwrap();
1025 assert!(!json.contains("\"header\""));
1028 assert!(!json.contains("\"footer\""));
1029 assert!(!json.contains("\"page_number\""));
1030 assert!(!json.contains("\"column_settings\""));
1031 let back: Section = serde_json::from_str(&json).unwrap();
1032 assert_eq!(section, back);
1033 }
1034
1035 #[test]
1040 fn header_footer_all_pages_apply_page_type() {
1041 let hf = HeaderFooter::all_pages(vec![Paragraph::new(ParaShapeIndex::new(0))]);
1042 assert_eq!(hf.apply_page_type, ApplyPageType::Both);
1043 }
1044
1045 #[test]
1046 fn header_footer_all_pages_preserves_paragraphs() {
1047 let paras = vec![simple_paragraph(), simple_paragraph()];
1048 let hf = HeaderFooter::all_pages(paras);
1049 assert_eq!(hf.paragraphs.len(), 2);
1050 }
1051
1052 #[test]
1053 fn header_footer_all_pages_empty_paragraphs() {
1054 let hf = HeaderFooter::all_pages(vec![]);
1055 assert_eq!(hf.apply_page_type, ApplyPageType::Both);
1056 assert!(hf.paragraphs.is_empty());
1057 }
1058
1059 #[test]
1060 #[allow(deprecated)]
1061 fn header_footer_both_deprecated_alias() {
1062 let hf = HeaderFooter::both(vec![Paragraph::new(ParaShapeIndex::new(0))]);
1063 assert_eq!(hf.apply_page_type, ApplyPageType::Both);
1064 }
1065
1066 #[test]
1071 fn page_number_bottom_center_position() {
1072 let pn = PageNumber::bottom_center();
1073 assert_eq!(pn.position, PageNumberPosition::BottomCenter);
1074 }
1075
1076 #[test]
1077 fn page_number_bottom_center_format() {
1078 let pn = PageNumber::bottom_center();
1079 assert_eq!(pn.number_format, NumberFormatType::Digit);
1080 }
1081
1082 #[test]
1083 fn page_number_bottom_center_no_decoration() {
1084 let pn = PageNumber::bottom_center();
1085 assert!(pn.decoration.is_empty());
1086 }
1087
1088 #[test]
1089 fn page_number_bottom_center_equals_explicit() {
1090 let shortcut = PageNumber::bottom_center();
1091 let explicit = PageNumber::new(PageNumberPosition::BottomCenter, NumberFormatType::Digit);
1092 assert_eq!(shortcut, explicit);
1093 }
1094
1095 #[test]
1096 fn section_backward_compat_deserialize() {
1097 let a4 = PageSettings::a4();
1099 let json = serde_json::to_string(&Section::with_paragraphs(vec![], a4)).unwrap();
1100 let section: Section = serde_json::from_str(&json).unwrap();
1101 assert!(section.headers.is_empty());
1102 assert!(section.footers.is_empty());
1103 assert!(section.page_number.is_none());
1104 }
1105
1106 #[test]
1107 fn all_pages_equals_new_with_both() {
1108 let paras = vec![simple_paragraph()];
1109 let from_all_pages = HeaderFooter::all_pages(paras.clone());
1110 let from_new = HeaderFooter::new(paras, ApplyPageType::Both);
1111 assert_eq!(from_all_pages, from_new);
1112 }
1113}