Skip to main content

ppt_rs/generator/
mod.rs

1//! PPTX file generator - creates proper ZIP-based PPTX files
2
3// Layout constants (shared positioning and sizing values)
4pub mod constants;
5
6// Core XML generation modules
7pub mod slide_content;
8pub mod package_xml;
9pub mod slide_xml;
10pub mod theme_xml;
11pub mod presentation_theme;
12pub mod props_xml;
13
14pub mod layout_parts;
15pub mod template;
16
17// Modular layout system
18pub mod layouts;
19
20// Builder and content modules
21pub mod builder;
22pub mod memory_profile;
23pub mod package_cache;
24pub mod media_registry;
25
26// Text module (modularized)
27pub mod text;
28
29pub mod shapes;
30pub mod shapes_xml;
31
32// Table module (modularized)
33pub mod table;
34
35pub mod images;
36pub mod image_effects;
37pub mod images_xml;
38
39// Charts module (modularized)
40#[path = "charts/mod.rs"]
41pub mod charts;
42
43// Notes module for speaker notes
44pub mod notes_xml;
45
46// Slide utilities (formatting, etc.)
47pub mod slide;
48
49// New element modules
50pub mod connectors;
51pub mod hyperlinks;
52pub mod gradients;
53pub mod media;
54
55pub use builder::{
56    create_pptx, create_pptx_with_content, create_pptx_with_settings, create_pptx_with_template,
57    create_pptx_to_writer, create_pptx_with_content_to_writer, create_pptx_lazy_to_writer,
58    LazySlideSource,
59};
60pub use template::PptxTemplate;
61pub use layout_parts::STANDARD_LAYOUT_COUNT;
62pub use notes_xml::{create_notes_xml, create_notes_rels_xml, create_notes_master_xml, create_notes_master_rels_xml};
63pub use slide_content::{SlideContent, SlideLayout};
64pub use presentation_theme::{PresentationTheme, ThemeColorScheme, ThemeFonts};
65pub use slide_content::{CodeBlock, BulletStyle, BulletPoint, BulletTextFormat, TransitionType, Comment, CommentAuthor, CommentAuthorList, SlideComments, SlideSection, SectionManager, DigitalSignature, SignerInfo, HashAlgorithm, SignatureCommitment, InkAnnotations, InkStroke, InkPen, InkPoint, PenTip, SlideShowSettings, ShowType, PenColor, SlideRange, PrintSettings, HandoutLayout, PrintColorMode, PrintWhat, Orientation, TableMergeMap, MergeRegion, CellMergeState, EmbeddedFontList, EmbeddedFont, FontStyle, FontCharset, PresentationSettings};
66pub use text::{TextFormat, FormattedText, TextFrame, Paragraph, Run, TextAlign, TextAnchor, TextDirection, RtlLanguage, RtlTextProps};
67pub use shapes::{Shape, ShapeType, ShapeFill, ShapeLine, GradientFill as ShapeGradientFill, GradientStop as ShapeGradientStop, GradientDirection as ShapeGradientDirection, FillType, emu_to_inches, inches_to_emu, cm_to_emu};
68pub use shapes_xml::{generate_shape_xml, generate_shapes_xml, generate_connector_xml};
69pub use table::{Table, TableRow, TableCell, TableBuilder, CellAlign, CellVAlign, generate_table_xml as generate_table_xml_new};
70pub use images::{Image, ImageBuilder, ImageSource};
71pub use images_xml::{generate_image_xml, generate_image_relationship, generate_image_content_type};
72pub use charts::{Chart, ChartType, ChartSeries, ChartBuilder, generate_chart_part_xml, generate_chart_ref_xml};
73
74// New element exports
75pub use connectors::{Connector, ConnectorType, ConnectorLine, ArrowType, ArrowSize, ConnectionSite, LineDash, generate_connector_xml as generate_cxn_xml};
76pub use hyperlinks::{Hyperlink, HyperlinkAction, generate_text_hyperlink_xml, generate_shape_hyperlink_xml, generate_hyperlink_relationship_xml};
77pub use gradients::{GradientFill, GradientType, GradientDirection, GradientStop, PresetGradients, generate_gradient_fill_xml};
78pub use media::{Video, Audio, VideoFormat, AudioFormat, VideoOptions, AudioOptions, generate_video_xml, generate_audio_xml};
79
80#[cfg(test)]
81mod tests {
82    use super::*;
83
84    #[test]
85    fn test_slide_content_builder() {
86        let slide = SlideContent::new("Title")
87            .add_bullet("Point 1")
88            .add_bullet("Point 2");
89        
90        assert_eq!(slide.title, "Title");
91        assert_eq!(slide.content.len(), 2);
92        assert_eq!(slide.content[0], "Point 1");
93    }
94    
95    #[test]
96    fn test_bullet_styles() {
97        let bullet = BulletStyle::Bullet;
98        assert!(bullet.to_xml().contains("buChar"));
99        
100        let number = BulletStyle::Number;
101        assert!(number.to_xml().contains("arabicPeriod"));
102        
103        let letter = BulletStyle::LetterLower;
104        assert!(letter.to_xml().contains("alphaLcPeriod"));
105        
106        let roman = BulletStyle::RomanUpper;
107        assert!(roman.to_xml().contains("romanUcPeriod"));
108        
109        let custom = BulletStyle::Custom('★');
110        assert!(custom.to_xml().contains("★"));
111        
112        let none = BulletStyle::None;
113        assert!(none.to_xml().contains("buNone"));
114    }
115    
116    #[test]
117    fn test_numbered_slide() {
118        let slide = SlideContent::new("Steps")
119            .with_bullet_style(BulletStyle::Number)
120            .add_bullet("First step")
121            .add_bullet("Second step")
122            .add_bullet("Third step");
123        
124        assert_eq!(slide.bullets.len(), 3);
125        assert_eq!(slide.bullets[0].style, BulletStyle::Number);
126    }
127    
128    #[test]
129    fn test_mixed_bullet_styles() {
130        let slide = SlideContent::new("Mixed")
131            .add_numbered("Step 1")
132            .add_numbered("Step 2")
133            .add_lettered("Option a")
134            .add_lettered("Option b");
135        
136        assert_eq!(slide.bullets.len(), 4);
137        assert_eq!(slide.bullets[0].style, BulletStyle::Number);
138        assert_eq!(slide.bullets[2].style, BulletStyle::LetterLower);
139    }
140    
141    #[test]
142    fn test_sub_bullets() {
143        let slide = SlideContent::new("Hierarchy")
144            .add_bullet("Main point")
145            .add_sub_bullet("Sub point 1")
146            .add_sub_bullet("Sub point 2")
147            .add_bullet("Another main point");
148        
149        assert_eq!(slide.bullets.len(), 4);
150        assert_eq!(slide.bullets[0].level, 0);
151        assert_eq!(slide.bullets[1].level, 1);
152        assert_eq!(slide.bullets[2].level, 1);
153        assert_eq!(slide.bullets[3].level, 0);
154    }
155}