Skip to main content

ppt_rs/generator/layouts/
title_only.rs

1//! Title-only slide layout
2
3use super::common::{SlideXmlBuilder, generate_text_props, ShapePosition, TextContent};
4use crate::generator::slide_content::SlideContent;
5use crate::generator::constants::{
6    TITLE_X, TITLE_Y, TITLE_WIDTH, TITLE_HEIGHT, TITLE_FONT_SIZE,
7};
8
9/// Title-only slide layout generator
10pub struct TitleOnlyLayout;
11
12impl TitleOnlyLayout {
13    /// Generate title-only slide XML
14    pub fn generate(content: &SlideContent) -> String {
15        let title_size = content.title_size.unwrap_or(TITLE_FONT_SIZE / 100 * 100);
16        let title_props = generate_text_props(
17            title_size,
18            content.title_bold,
19            content.title_italic,
20            content.title_underline,
21            content.title_color.as_deref(),
22        );
23
24        let position = ShapePosition::new(TITLE_X, TITLE_Y, TITLE_WIDTH, TITLE_HEIGHT);
25        let text_content = TextContent::new(&content.title, &title_props);
26
27        SlideXmlBuilder::new()
28            .start_slide_with_bg()
29            .start_sp_tree()
30            .add_title(2, position, text_content, "title")
31            .end_sp_tree()
32            .end_slide()
33            .build()
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use super::*;
40
41    #[test]
42    fn test_title_only_layout() {
43        let content = SlideContent::new("Test Title");
44        let xml = TitleOnlyLayout::generate(&content);
45        
46        assert!(xml.contains("Test Title"));
47        assert!(xml.contains("p:ph type=\"title\""));
48    }
49}