Skip to main content

text_styling_complete/
text_styling_complete.rs

1//! Example: Complete text styling with italic, underline, and colors
2//!
3//! Demonstrates all text formatting capabilities
4//! Run with: cargo run --example text_styling_complete
5
6use ppt_rs::generator::{SlideContent, create_pptx_with_content};
7use std::fs;
8
9fn main() -> Result<(), Box<dyn std::error::Error>> {
10    println!("╔════════════════════════════════════════════════════════════╗");
11    println!("║     Generating Complete Text Styling Examples             ║");
12    println!("╚════════════════════════════════════════════════════════════╝");
13    println!();
14
15    fs::create_dir_all("examples/output")?;
16
17    // Example 1: Italic and Underline
18    println!("1. Creating presentation with italic and underline...");
19    create_italic_underline_example()?;
20    println!("   ✓ Created: examples/output/italic_underline.pptx");
21    println!();
22
23    // Example 2: Text Colors
24    println!("2. Creating presentation with colored text...");
25    create_colored_text_example()?;
26    println!("   ✓ Created: examples/output/colored_text.pptx");
27    println!();
28
29    // Example 3: Combined Styling
30    println!("3. Creating presentation with combined styling...");
31    create_combined_styling_example()?;
32    println!("   ✓ Created: examples/output/combined_styling.pptx");
33    println!();
34
35    // Example 4: Professional Presentation
36    println!("4. Creating professional presentation...");
37    create_professional_example()?;
38    println!("   ✓ Created: examples/output/professional.pptx");
39    println!();
40
41    println!("✅ All text styling examples generated successfully!");
42    println!();
43    println!("Generated files:");
44    println!("  - examples/output/italic_underline.pptx");
45    println!("  - examples/output/colored_text.pptx");
46    println!("  - examples/output/combined_styling.pptx");
47    println!("  - examples/output/professional.pptx");
48    println!();
49
50    Ok(())
51}
52
53fn create_italic_underline_example() -> Result<(), Box<dyn std::error::Error>> {
54    let slides = vec![
55        SlideContent::new("Italic Text")
56            .title_italic(true)
57            .add_bullet("This is italic content")
58            .add_bullet("More italic text here"),
59        SlideContent::new("Underlined Text")
60            .title_underline(true)
61            .content_underline(true)
62            .add_bullet("Underlined bullet point 1")
63            .add_bullet("Underlined bullet point 2"),
64        SlideContent::new("Combined Effects")
65            .title_italic(true)
66            .title_underline(true)
67            .content_italic(true)
68            .add_bullet("Italic and underlined content")
69            .add_bullet("Multiple effects combined"),
70    ];
71
72    let pptx_data = create_pptx_with_content("Italic and Underline", slides)?;
73    fs::write("examples/output/italic_underline.pptx", pptx_data)?;
74    Ok(())
75}
76
77fn create_colored_text_example() -> Result<(), Box<dyn std::error::Error>> {
78    let slides = vec![
79        SlideContent::new("Red Title")
80            .title_color("FF0000")
81            .add_bullet("Red title text")
82            .add_bullet("Regular content"),
83        SlideContent::new("Blue Content")
84            .content_color("0000FF")
85            .add_bullet("Blue bullet point 1")
86            .add_bullet("Blue bullet point 2")
87            .add_bullet("Blue bullet point 3"),
88        SlideContent::new("Green Title & Content")
89            .title_color("00AA00")
90            .content_color("00AA00")
91            .add_bullet("Green title and content")
92            .add_bullet("All text is green"),
93        SlideContent::new("Purple Accent")
94            .title_color("9933FF")
95            .add_bullet("Purple title")
96            .add_bullet("Regular content"),
97    ];
98
99    let pptx_data = create_pptx_with_content("Colored Text", slides)?;
100    fs::write("examples/output/colored_text.pptx", pptx_data)?;
101    Ok(())
102}
103
104fn create_combined_styling_example() -> Result<(), Box<dyn std::error::Error>> {
105    let slides = vec![
106        SlideContent::new("Bold & Italic & Red")
107            .title_bold(true)
108            .title_italic(true)
109            .title_color("FF0000")
110            .title_size(52)
111            .add_bullet("Regular content"),
112        SlideContent::new("Underlined Blue Content")
113            .content_underline(true)
114            .content_color("0000FF")
115            .content_bold(true)
116            .add_bullet("Bold, underlined, blue bullet")
117            .add_bullet("Multiple effects applied"),
118        SlideContent::new("Mixed Effects")
119            .title_italic(true)
120            .title_color("FF6600")
121            .content_bold(true)
122            .content_underline(true)
123            .content_color("0066FF")
124            .add_bullet("Title: italic, orange")
125            .add_bullet("Content: bold, underlined, blue"),
126        SlideContent::new("Professional Look")
127            .title_bold(true)
128            .title_size(48)
129            .title_color("003366")
130            .content_size(24)
131            .add_bullet("Clean, professional styling")
132            .add_bullet("Dark blue title with bold")
133            .add_bullet("Larger content text"),
134    ];
135
136    let pptx_data = create_pptx_with_content("Combined Styling", slides)?;
137    fs::write("examples/output/combined_styling.pptx", pptx_data)?;
138    Ok(())
139}
140
141fn create_professional_example() -> Result<(), Box<dyn std::error::Error>> {
142    let slides = vec![
143        SlideContent::new("Company Presentation")
144            .title_bold(true)
145            .title_size(56)
146            .title_color("003366")
147            .content_size(32)
148            .add_bullet("2025 Annual Review"),
149        SlideContent::new("Key Highlights")
150            .title_bold(true)
151            .title_color("003366")
152            .content_bold(true)
153            .content_color("0066CC")
154            .add_bullet("Revenue growth: +25%")
155            .add_bullet("Market expansion: 3 new regions")
156            .add_bullet("Team growth: +50 employees"),
157        SlideContent::new("Strategic Initiatives")
158            .title_italic(true)
159            .title_color("FF6600")
160            .content_underline(true)
161            .add_bullet("Digital transformation")
162            .add_bullet("Customer experience improvement")
163            .add_bullet("Sustainability focus"),
164        SlideContent::new("Q1 2025 Goals")
165            .title_bold(true)
166            .title_underline(true)
167            .title_color("003366")
168            .content_bold(true)
169            .add_bullet("Launch new product line")
170            .add_bullet("Expand to 5 new markets")
171            .add_bullet("Achieve 30% revenue growth"),
172        SlideContent::new("Thank You")
173            .title_bold(true)
174            .title_size(60)
175            .title_color("003366")
176            .content_italic(true)
177            .content_size(28)
178            .add_bullet("Questions & Discussion"),
179    ];
180
181    let pptx_data = create_pptx_with_content("Professional Presentation", slides)?;
182    fs::write("examples/output/professional.pptx", pptx_data)?;
183    Ok(())
184}