ppt-rs 0.2.14

Create, read, and update PowerPoint 2007+ (.pptx) files with rich formatting, bullet styles, themes, and templates.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
//! Shape creation support for PPTX generation
//!
//! Provides shape types, fills, lines, and builders for creating shapes in slides.

/// Shape types available in PPTX
#[derive(Clone, Debug, Copy, PartialEq)]
pub enum ShapeType {
    // Basic shapes
    Rectangle,
    RoundedRectangle,
    Ellipse,
    Circle, // Alias for Ellipse
    Triangle,
    RightTriangle,
    Diamond,
    Pentagon,
    Hexagon,
    Octagon,
    
    // Arrows
    RightArrow,
    LeftArrow,
    UpArrow,
    DownArrow,
    LeftRightArrow,
    UpDownArrow,
    BentArrow,
    UTurnArrow,
    
    // Stars and banners
    Star4,
    Star5,
    Star6,
    Star8,
    Ribbon,
    Wave,
    
    // Callouts
    WedgeRectCallout,
    WedgeEllipseCallout,
    CloudCallout,
    
    // Flow chart
    FlowChartProcess,
    FlowChartDecision,
    FlowChartTerminator,
    FlowChartDocument,
    FlowChartPredefinedProcess,
    FlowChartInternalStorage,
    FlowChartData,
    FlowChartInputOutput,
    FlowChartManualInput,
    FlowChartManualOperation,
    FlowChartConnector,
    FlowChartOffPageConnector,
    FlowChartPunchedCard,
    FlowChartPunchedTape,
    FlowChartSummingJunction,
    FlowChartOr,
    FlowChartCollate,
    FlowChartSort,
    FlowChartExtract,
    FlowChartMerge,
    FlowChartOnlineStorage,
    FlowChartDelay,
    FlowChartMagneticTape,
    FlowChartMagneticDisk,
    FlowChartMagneticDrum,
    FlowChartDisplay,
    FlowChartPreparation,
    
    // More arrows
    CurvedRightArrow,
    CurvedLeftArrow,
    CurvedUpArrow,
    CurvedDownArrow,
    CurvedLeftRightArrow,
    CurvedUpDownArrow,
    StripedRightArrow,
    NotchedRightArrow,
    PentagonArrow,
    ChevronArrow,
    RightArrowCallout,
    LeftArrowCallout,
    UpArrowCallout,
    DownArrowCallout,
    LeftRightArrowCallout,
    UpDownArrowCallout,
    QuadArrow,
    LeftRightUpArrow,
    CircularArrow,
    
    // More geometric shapes
    Parallelogram,
    Trapezoid,
    NonIsoscelesTrapezoid,
    IsoscelesTrapezoid,
    Cube,
    Can,
    Cone,
    Cylinder,
    Bevel,
    Donut,
    NoSmoking,
    BlockArc,
    FoldedCorner,
    SmileyFace,
    Arc,
    Chord,
    Pie,
    Teardrop,
    Plaque,
    MusicNote,
    PictureFrame,
    
    // More decorative
    Star10,
    Star12,
    Star16,
    Star24,
    Star32,
    Seal,
    Seal4,
    Seal8,
    Seal16,
    Seal32,
    ActionButtonBlank,
    ActionButtonHome,
    ActionButtonHelp,
    ActionButtonInformation,
    ActionButtonForwardNext,
    ActionButtonBackPrevious,
    ActionButtonBeginning,
    ActionButtonEnd,
    ActionButtonReturn,
    ActionButtonDocument,
    ActionButtonSound,
    ActionButtonMovie,
    
    // Other (original shapes)
    Heart,
    Lightning,
    Sun,
    Moon,
    Cloud,
    Brace,
    Bracket,
    Plus,
    Minus,
}

impl ShapeType {
    /// Get the preset geometry name for the shape (OOXML preset name)
    pub fn preset_name(&self) -> &'static str {
        match self {
            ShapeType::Rectangle => "rect",
            ShapeType::RoundedRectangle => "roundRect",
            ShapeType::Ellipse | ShapeType::Circle => "ellipse",
            ShapeType::Triangle => "triangle",
            ShapeType::RightTriangle => "rtTriangle",
            ShapeType::Diamond => "diamond",
            ShapeType::Pentagon => "pentagon",
            ShapeType::Hexagon => "hexagon",
            ShapeType::Octagon => "octagon",
            
            ShapeType::RightArrow => "rightArrow",
            ShapeType::LeftArrow => "leftArrow",
            ShapeType::UpArrow => "upArrow",
            ShapeType::DownArrow => "downArrow",
            ShapeType::LeftRightArrow => "leftRightArrow",
            ShapeType::UpDownArrow => "upDownArrow",
            ShapeType::BentArrow => "bentArrow",
            ShapeType::UTurnArrow => "uturnArrow",
            
            ShapeType::Star4 => "star4",
            ShapeType::Star5 => "star5",
            ShapeType::Star6 => "star6",
            ShapeType::Star8 => "star8",
            ShapeType::Ribbon => "ribbon2",
            ShapeType::Wave => "wave",
            
            ShapeType::WedgeRectCallout => "wedgeRectCallout",
            ShapeType::WedgeEllipseCallout => "wedgeEllipseCallout",
            ShapeType::CloudCallout => "cloudCallout",
            
            ShapeType::FlowChartProcess => "flowChartProcess",
            ShapeType::FlowChartDecision => "flowChartDecision",
            ShapeType::FlowChartTerminator => "flowChartTerminator",
            ShapeType::FlowChartDocument => "flowChartDocument",
            ShapeType::FlowChartPredefinedProcess => "flowChartPredefinedProcess",
            ShapeType::FlowChartInternalStorage => "flowChartInternalStorage",
            ShapeType::FlowChartData => "flowChartData",
            ShapeType::FlowChartInputOutput => "flowChartInputOutput",
            ShapeType::FlowChartManualInput => "flowChartManualInput",
            ShapeType::FlowChartManualOperation => "flowChartManualOperation",
            ShapeType::FlowChartConnector => "flowChartConnector",
            ShapeType::FlowChartOffPageConnector => "flowChartOffPageConnector",
            ShapeType::FlowChartPunchedCard => "flowChartPunchedCard",
            ShapeType::FlowChartPunchedTape => "flowChartPunchedTape",
            ShapeType::FlowChartSummingJunction => "flowChartSummingJunction",
            ShapeType::FlowChartOr => "flowChartOr",
            ShapeType::FlowChartCollate => "flowChartCollate",
            ShapeType::FlowChartSort => "flowChartSort",
            ShapeType::FlowChartExtract => "flowChartExtract",
            ShapeType::FlowChartMerge => "flowChartMerge",
            ShapeType::FlowChartOnlineStorage => "flowChartOnlineStorage",
            ShapeType::FlowChartDelay => "flowChartDelay",
            ShapeType::FlowChartMagneticTape => "flowChartMagneticTape",
            ShapeType::FlowChartMagneticDisk => "flowChartMagneticDisk",
            ShapeType::FlowChartMagneticDrum => "flowChartMagneticDrum",
            ShapeType::FlowChartDisplay => "flowChartDisplay",
            ShapeType::FlowChartPreparation => "flowChartPreparation",
            
            ShapeType::CurvedRightArrow => "curvedRightArrow",
            ShapeType::CurvedLeftArrow => "curvedLeftArrow",
            ShapeType::CurvedUpArrow => "curvedUpArrow",
            ShapeType::CurvedDownArrow => "curvedDownArrow",
            ShapeType::CurvedLeftRightArrow => "curvedLeftRightArrow",
            ShapeType::CurvedUpDownArrow => "curvedUpDownArrow",
            ShapeType::StripedRightArrow => "stripedRightArrow",
            ShapeType::NotchedRightArrow => "notchedRightArrow",
            ShapeType::PentagonArrow => "pentArrow",
            ShapeType::ChevronArrow => "chevron",
            ShapeType::RightArrowCallout => "rightArrowCallout",
            ShapeType::LeftArrowCallout => "leftArrowCallout",
            ShapeType::UpArrowCallout => "upArrowCallout",
            ShapeType::DownArrowCallout => "downArrowCallout",
            ShapeType::LeftRightArrowCallout => "leftRightArrowCallout",
            ShapeType::UpDownArrowCallout => "upDownArrowCallout",
            ShapeType::QuadArrow => "quadArrow",
            ShapeType::LeftRightUpArrow => "leftRightUpArrow",
            ShapeType::CircularArrow => "circularArrow",
            
            ShapeType::Parallelogram => "parallelogram",
            ShapeType::Trapezoid => "trapezoid",
            ShapeType::NonIsoscelesTrapezoid => "nonIsoscelesTrapezoid",
            ShapeType::IsoscelesTrapezoid => "isoTrapezoid",
            ShapeType::Cube => "cube",
            ShapeType::Can => "can",
            ShapeType::Cone => "cone",
            ShapeType::Cylinder => "cylinder",
            ShapeType::Bevel => "bevel",
            ShapeType::Donut => "donut",
            ShapeType::NoSmoking => "noSmoking",
            ShapeType::BlockArc => "blockArc",
            ShapeType::FoldedCorner => "foldedCorner",
            ShapeType::SmileyFace => "smileyFace",
            ShapeType::Arc => "arc",
            ShapeType::Chord => "chord",
            ShapeType::Pie => "pie",
            ShapeType::Teardrop => "teardrop",
            ShapeType::Plaque => "plaque",
            ShapeType::MusicNote => "musicNote",
            ShapeType::PictureFrame => "frame",
            
            ShapeType::Star10 => "star10",
            ShapeType::Star12 => "star12",
            ShapeType::Star16 => "star16",
            ShapeType::Star24 => "star24",
            ShapeType::Star32 => "star32",
            ShapeType::Seal => "seal",
            ShapeType::Seal4 => "seal4",
            ShapeType::Seal8 => "seal8",
            ShapeType::Seal16 => "seal16",
            ShapeType::Seal32 => "seal32",
            ShapeType::ActionButtonBlank => "actionButtonBlank",
            ShapeType::ActionButtonHome => "actionButtonHome",
            ShapeType::ActionButtonHelp => "actionButtonHelp",
            ShapeType::ActionButtonInformation => "actionButtonInformation",
            ShapeType::ActionButtonForwardNext => "actionButtonForwardNext",
            ShapeType::ActionButtonBackPrevious => "actionButtonBackPrevious",
            ShapeType::ActionButtonBeginning => "actionButtonBeginning",
            ShapeType::ActionButtonEnd => "actionButtonEnd",
            ShapeType::ActionButtonReturn => "actionButtonReturn",
            ShapeType::ActionButtonDocument => "actionButtonDocument",
            ShapeType::ActionButtonSound => "actionButtonSound",
            ShapeType::ActionButtonMovie => "actionButtonMovie",
            
            ShapeType::Heart => "heart",
            ShapeType::Lightning => "lightningBolt",
            ShapeType::Sun => "sun",
            ShapeType::Moon => "moon",
            ShapeType::Cloud => "cloud",
            ShapeType::Brace => "leftBrace",
            ShapeType::Bracket => "leftBracket",
            ShapeType::Plus => "mathPlus",
            ShapeType::Minus => "mathMinus",
        }
    }

    /// Get a user-friendly name for the shape
    pub fn display_name(&self) -> &'static str {
        match self {
            ShapeType::Rectangle => "Rectangle",
            ShapeType::RoundedRectangle => "Rounded Rectangle",
            ShapeType::Ellipse => "Ellipse",
            ShapeType::Circle => "Circle",
            ShapeType::Triangle => "Triangle",
            ShapeType::RightTriangle => "Right Triangle",
            ShapeType::Diamond => "Diamond",
            ShapeType::Pentagon => "Pentagon",
            ShapeType::Hexagon => "Hexagon",
            ShapeType::Octagon => "Octagon",
            ShapeType::RightArrow => "Right Arrow",
            ShapeType::LeftArrow => "Left Arrow",
            ShapeType::UpArrow => "Up Arrow",
            ShapeType::DownArrow => "Down Arrow",
            ShapeType::LeftRightArrow => "Left-Right Arrow",
            ShapeType::UpDownArrow => "Up-Down Arrow",
            ShapeType::BentArrow => "Bent Arrow",
            ShapeType::UTurnArrow => "U-Turn Arrow",
            ShapeType::Star4 => "4-Point Star",
            ShapeType::Star5 => "5-Point Star",
            ShapeType::Star6 => "6-Point Star",
            ShapeType::Star8 => "8-Point Star",
            ShapeType::Ribbon => "Ribbon",
            ShapeType::Wave => "Wave",
            ShapeType::WedgeRectCallout => "Rectangle Callout",
            ShapeType::WedgeEllipseCallout => "Oval Callout",
            ShapeType::CloudCallout => "Cloud Callout",
            ShapeType::FlowChartProcess => "Process",
            ShapeType::FlowChartDecision => "Decision",
            ShapeType::FlowChartTerminator => "Terminator",
            ShapeType::FlowChartDocument => "Document",
            ShapeType::FlowChartPredefinedProcess => "Predefined Process",
            ShapeType::FlowChartInternalStorage => "Internal Storage",
            ShapeType::FlowChartData => "Data",
            ShapeType::FlowChartInputOutput => "Input/Output",
            ShapeType::FlowChartManualInput => "Manual Input",
            ShapeType::FlowChartManualOperation => "Manual Operation",
            ShapeType::FlowChartConnector => "Connector",
            ShapeType::FlowChartOffPageConnector => "Off-page Connector",
            ShapeType::FlowChartPunchedCard => "Punched Card",
            ShapeType::FlowChartPunchedTape => "Punched Tape",
            ShapeType::FlowChartSummingJunction => "Summing Junction",
            ShapeType::FlowChartOr => "Or",
            ShapeType::FlowChartCollate => "Collate",
            ShapeType::FlowChartSort => "Sort",
            ShapeType::FlowChartExtract => "Extract",
            ShapeType::FlowChartMerge => "Merge",
            ShapeType::FlowChartOnlineStorage => "Online Storage",
            ShapeType::FlowChartDelay => "Delay",
            ShapeType::FlowChartMagneticTape => "Magnetic Tape",
            ShapeType::FlowChartMagneticDisk => "Magnetic Disk",
            ShapeType::FlowChartMagneticDrum => "Magnetic Drum",
            ShapeType::FlowChartDisplay => "Display",
            ShapeType::FlowChartPreparation => "Preparation",
            
            ShapeType::CurvedRightArrow => "Curved Right Arrow",
            ShapeType::CurvedLeftArrow => "Curved Left Arrow",
            ShapeType::CurvedUpArrow => "Curved Up Arrow",
            ShapeType::CurvedDownArrow => "Curved Down Arrow",
            ShapeType::CurvedLeftRightArrow => "Curved Left-Right Arrow",
            ShapeType::CurvedUpDownArrow => "Curved Up-Down Arrow",
            ShapeType::StripedRightArrow => "Striped Right Arrow",
            ShapeType::NotchedRightArrow => "Notched Right Arrow",
            ShapeType::PentagonArrow => "Pentagon Arrow",
            ShapeType::ChevronArrow => "Chevron Arrow",
            ShapeType::RightArrowCallout => "Right Arrow Callout",
            ShapeType::LeftArrowCallout => "Left Arrow Callout",
            ShapeType::UpArrowCallout => "Up Arrow Callout",
            ShapeType::DownArrowCallout => "Down Arrow Callout",
            ShapeType::LeftRightArrowCallout => "Left-Right Arrow Callout",
            ShapeType::UpDownArrowCallout => "Up-Down Arrow Callout",
            ShapeType::QuadArrow => "Quad Arrow",
            ShapeType::LeftRightUpArrow => "Left-Right-Up Arrow",
            ShapeType::CircularArrow => "Circular Arrow",
            
            ShapeType::Parallelogram => "Parallelogram",
            ShapeType::Trapezoid => "Trapezoid",
            ShapeType::NonIsoscelesTrapezoid => "Non-Isosceles Trapezoid",
            ShapeType::IsoscelesTrapezoid => "Isosceles Trapezoid",
            ShapeType::Cube => "Cube",
            ShapeType::Can => "Can",
            ShapeType::Cone => "Cone",
            ShapeType::Cylinder => "Cylinder",
            ShapeType::Bevel => "Bevel",
            ShapeType::Donut => "Donut",
            ShapeType::NoSmoking => "No Smoking",
            ShapeType::BlockArc => "Block Arc",
            ShapeType::FoldedCorner => "Folded Corner",
            ShapeType::SmileyFace => "Smiley Face",
            ShapeType::Arc => "Arc",
            ShapeType::Chord => "Chord",
            ShapeType::Pie => "Pie",
            ShapeType::Teardrop => "Teardrop",
            ShapeType::Plaque => "Plaque",
            ShapeType::MusicNote => "Music Note",
            ShapeType::PictureFrame => "Picture Frame",
            
            ShapeType::Star10 => "10-Point Star",
            ShapeType::Star12 => "12-Point Star",
            ShapeType::Star16 => "16-Point Star",
            ShapeType::Star24 => "24-Point Star",
            ShapeType::Star32 => "32-Point Star",
            ShapeType::Seal => "Seal",
            ShapeType::Seal4 => "4-Point Seal",
            ShapeType::Seal8 => "8-Point Seal",
            ShapeType::Seal16 => "16-Point Seal",
            ShapeType::Seal32 => "32-Point Seal",
            ShapeType::ActionButtonBlank => "Action Button (Blank)",
            ShapeType::ActionButtonHome => "Action Button (Home)",
            ShapeType::ActionButtonHelp => "Action Button (Help)",
            ShapeType::ActionButtonInformation => "Action Button (Information)",
            ShapeType::ActionButtonForwardNext => "Action Button (Forward/Next)",
            ShapeType::ActionButtonBackPrevious => "Action Button (Back/Previous)",
            ShapeType::ActionButtonBeginning => "Action Button (Beginning)",
            ShapeType::ActionButtonEnd => "Action Button (End)",
            ShapeType::ActionButtonReturn => "Action Button (Return)",
            ShapeType::ActionButtonDocument => "Action Button (Document)",
            ShapeType::ActionButtonSound => "Action Button (Sound)",
            ShapeType::ActionButtonMovie => "Action Button (Movie)",
            
            ShapeType::Heart => "Heart",
            ShapeType::Lightning => "Lightning Bolt",
            ShapeType::Sun => "Sun",
            ShapeType::Moon => "Moon",
            ShapeType::Cloud => "Cloud",
            ShapeType::Brace => "Brace",
            ShapeType::Bracket => "Bracket",
            ShapeType::Plus => "Plus",
            ShapeType::Minus => "Minus",
        }
    }
}

/// Gradient direction for linear gradients
#[derive(Clone, Debug, Copy, PartialEq)]
pub enum GradientDirection {
    /// Left to right (0 degrees)
    Horizontal,
    /// Top to bottom (90 degrees)
    Vertical,
    /// Top-left to bottom-right (45 degrees)
    DiagonalDown,
    /// Bottom-left to top-right (315 degrees)
    DiagonalUp,
    /// Custom angle in degrees (0-360)
    Angle(u32),
}

impl GradientDirection {
    /// Get angle in 60000ths of a degree (OOXML format)
    pub fn to_angle(&self) -> u32 {
        match self {
            GradientDirection::Horizontal => 0,
            GradientDirection::Vertical => 5400000,      // 90 * 60000
            GradientDirection::DiagonalDown => 2700000,  // 45 * 60000
            GradientDirection::DiagonalUp => 18900000,   // 315 * 60000
            GradientDirection::Angle(deg) => deg * 60000,
        }
    }
}

/// A gradient stop (color at a position)
#[derive(Clone, Debug)]
pub struct GradientStop {
    pub color: String,
    pub position: u32,  // 0-100000 (percentage * 1000)
    pub transparency: Option<u32>,
}

impl GradientStop {
    /// Create a gradient stop at a position (0-100%)
    pub fn new(color: &str, position_percent: u32) -> Self {
        GradientStop {
            color: color.trim_start_matches('#').to_uppercase(),
            position: position_percent.min(100) * 1000,
            transparency: None,
        }
    }
    
    /// Set transparency (0-100 percent)
    pub fn with_transparency(mut self, percent: u32) -> Self {
        let alpha = (100 - percent.min(100)) * 1000;
        self.transparency = Some(alpha);
        self
    }
}

/// Gradient fill definition
#[derive(Clone, Debug)]
pub struct GradientFill {
    pub stops: Vec<GradientStop>,
    pub direction: GradientDirection,
}

impl GradientFill {
    /// Create a simple two-color gradient
    pub fn linear(start_color: &str, end_color: &str, direction: GradientDirection) -> Self {
        GradientFill {
            stops: vec![
                GradientStop::new(start_color, 0),
                GradientStop::new(end_color, 100),
            ],
            direction,
        }
    }
    
    /// Create a three-color gradient
    pub fn three_color(start: &str, middle: &str, end: &str, direction: GradientDirection) -> Self {
        GradientFill {
            stops: vec![
                GradientStop::new(start, 0),
                GradientStop::new(middle, 50),
                GradientStop::new(end, 100),
            ],
            direction,
        }
    }
    
    /// Add a custom stop
    pub fn with_stop(mut self, stop: GradientStop) -> Self {
        self.stops.push(stop);
        self.stops.sort_by_key(|s| s.position);
        self
    }
}

/// Shape fill type - solid color or gradient
#[derive(Clone, Debug)]
pub enum FillType {
    Solid(ShapeFill),
    Gradient(GradientFill),
    NoFill,
}

/// Shape fill/color properties
#[derive(Clone, Debug)]
pub struct ShapeFill {
    pub color: String, // RGB hex color (e.g., "FF0000")
    pub transparency: Option<u32>, // 0-100000 (100000 = fully transparent)
}

impl ShapeFill {
    /// Create new shape fill with color
    pub fn new(color: &str) -> Self {
        ShapeFill {
            color: color.trim_start_matches('#').to_uppercase(),
            transparency: None,
        }
    }

    /// Set transparency (0-100 percent)
    pub fn with_transparency(mut self, percent: u32) -> Self {
        let alpha = (100 - percent.min(100)) * 1000;
        self.transparency = Some(alpha);
        self
    }
    
    /// Set transparency (0-100 percent) - builder style (deprecated, use with_transparency)
    pub fn transparency(self, percent: u32) -> Self {
        self.with_transparency(percent)
    }
}

/// Shape line/border properties
#[derive(Clone, Debug)]
pub struct ShapeLine {
    pub color: String,
    pub width: u32, // in EMU (English Metric Units)
}

impl ShapeLine {
    /// Create new shape line with color and width
    pub fn new(color: &str, width: u32) -> Self {
        ShapeLine {
            color: color.trim_start_matches('#').to_uppercase(),
            width,
        }
    }
}

use crate::core::{Positioned, ElementSized, Dimension};

/// Shape definition
#[derive(Clone, Debug)]
pub struct Shape {
    pub shape_type: ShapeType,
    pub x: u32,      // Position X in EMU
    pub y: u32,      // Position Y in EMU
    pub width: u32,  // Width in EMU
    pub height: u32, // Height in EMU
    pub fill: Option<ShapeFill>,
    pub gradient: Option<GradientFill>,
    pub line: Option<ShapeLine>,
    pub text: Option<String>,
    /// Optional fixed shape ID for connector anchoring
    pub id: Option<u32>,
    /// Rotation in degrees (0-360)
    pub rotation: Option<i32>,
    /// Optional hyperlink
    pub hyperlink: Option<crate::generator::hyperlinks::Hyperlink>,
}

impl Shape {
    /// Create a new shape
    pub fn new(shape_type: ShapeType, x: u32, y: u32, width: u32, height: u32) -> Self {
        Shape {
            shape_type,
            x,
            y,
            width,
            height,
            fill: None,
            gradient: None,
            line: None,
            text: None,
            id: None,
            rotation: None,
            hyperlink: None,
        }
    }

    /// Set shape ID for connector anchoring
    pub fn with_id(mut self, id: u32) -> Self {
        self.id = Some(id);
        self
    }

    /// Set shape rotation in degrees
    pub fn with_rotation(mut self, degrees: i32) -> Self {
        self.rotation = Some(degrees);
        self
    }

    /// Set shape hyperlink
    pub fn with_hyperlink(mut self, hyperlink: crate::generator::hyperlinks::Hyperlink) -> Self {
        self.hyperlink = Some(hyperlink);
        self
    }

    /// Set shape fill (solid color)
    pub fn with_fill(mut self, fill: ShapeFill) -> Self {
        self.fill = Some(fill);
        self.gradient = None; // Clear gradient if setting solid fill
        self
    }
    
    /// Set gradient fill
    pub fn with_gradient(mut self, gradient: GradientFill) -> Self {
        self.gradient = Some(gradient);
        self.fill = None; // Clear solid fill if setting gradient
        self
    }

    /// Set shape line
    pub fn with_line(mut self, line: ShapeLine) -> Self {
        self.line = Some(line);
        self
    }

    /// Set shape text
    pub fn with_text(mut self, text: &str) -> Self {
        self.text = Some(text.to_string());
        self
    }

    /// Create a shape using flexible Dimension units for position and size.
    ///
    /// ```
    /// use ppt_rs::core::Dimension;
    /// use ppt_rs::generator::shapes::{Shape, ShapeType};
    ///
    /// // Position at 10% from left, 20% from top; size = 80% width, 2 inches height
    /// let shape = Shape::from_dimensions(
    ///     ShapeType::Rectangle,
    ///     Dimension::Ratio(0.1), Dimension::Ratio(0.2),
    ///     Dimension::Ratio(0.8), Dimension::Inches(2.0),
    /// );
    /// ```
    pub fn from_dimensions(shape_type: ShapeType, x: Dimension, y: Dimension, width: Dimension, height: Dimension) -> Self {
        Shape::new(shape_type, x.to_emu_x(), y.to_emu_y(), width.to_emu_x(), height.to_emu_y())
    }

    /// Set position using flexible Dimension units (fluent).
    ///
    /// ```
    /// use ppt_rs::core::Dimension;
    /// use ppt_rs::generator::shapes::{Shape, ShapeType};
    ///
    /// let shape = Shape::new(ShapeType::Rectangle, 0, 0, 914400, 914400)
    ///     .at(Dimension::Ratio(0.5), Dimension::Ratio(0.5));
    /// ```
    pub fn at(mut self, x: Dimension, y: Dimension) -> Self {
        self.x = x.to_emu_x();
        self.y = y.to_emu_y();
        self
    }

    /// Set size using flexible Dimension units (fluent).
    ///
    /// ```
    /// use ppt_rs::core::Dimension;
    /// use ppt_rs::generator::shapes::{Shape, ShapeType};
    ///
    /// let shape = Shape::new(ShapeType::Rectangle, 0, 0, 0, 0)
    ///     .with_dimensions(Dimension::Inches(3.0), Dimension::Cm(5.0));
    /// ```
    pub fn with_dimensions(mut self, width: Dimension, height: Dimension) -> Self {
        self.width = width.to_emu_x();
        self.height = height.to_emu_y();
        self
    }
}

impl Positioned for Shape {
    fn x(&self) -> u32 { self.x }
    fn y(&self) -> u32 { self.y }
    fn set_position(&mut self, x: u32, y: u32) {
        self.x = x;
        self.y = y;
    }
}

impl ElementSized for Shape {
    fn width(&self) -> u32 { self.width }
    fn height(&self) -> u32 { self.height }
    fn set_size(&mut self, width: u32, height: u32) {
        self.width = width;
        self.height = height;
    }
}

/// Convert EMU (English Metric Units) to inches
pub fn emu_to_inches(emu: u32) -> f64 {
    emu as f64 / 914400.0
}

/// Convert inches to EMU
pub fn inches_to_emu(inches: f64) -> u32 {
    (inches * 914400.0) as u32
}

/// Convert centimeters to EMU
pub fn cm_to_emu(cm: f64) -> u32 {
    (cm * 360000.0) as u32
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_shape_type_names() {
        assert_eq!(ShapeType::Rectangle.preset_name(), "rect");
        assert_eq!(ShapeType::Circle.preset_name(), "ellipse");
        assert_eq!(ShapeType::RightArrow.preset_name(), "rightArrow");
        assert_eq!(ShapeType::Star5.preset_name(), "star5");
        assert_eq!(ShapeType::Heart.preset_name(), "heart");
    }

    #[test]
    fn test_shape_fill_builder() {
        let fill = ShapeFill::new("FF0000").transparency(50);
        assert_eq!(fill.color, "FF0000");
        assert_eq!(fill.transparency, Some(50000));
    }

    #[test]
    fn test_shape_builder() {
        let shape = Shape::new(ShapeType::Rectangle, 0, 0, 1000000, 500000)
            .with_fill(ShapeFill::new("0000FF"))
            .with_line(ShapeLine::new("000000", 25400))
            .with_text("Hello");

        assert_eq!(shape.x, 0);
        assert_eq!(shape.width, 1000000);
        assert_eq!(shape.text, Some("Hello".to_string()));
    }

    #[test]
    fn test_emu_conversions() {
        let emu = inches_to_emu(1.0);
        assert_eq!(emu, 914400);
        assert!((emu_to_inches(emu) - 1.0).abs() < 0.001);
    }

    #[test]
    fn test_cm_to_emu() {
        let emu = cm_to_emu(2.54); // 1 inch
        assert_eq!(emu, 914400);
    }

    #[test]
    fn test_shape_from_dimensions_ratio() {
        let shape = Shape::from_dimensions(
            ShapeType::Rectangle,
            Dimension::Ratio(0.1), Dimension::Ratio(0.2),
            Dimension::Ratio(0.8), Dimension::Ratio(0.6),
        );
        // 10% of 9144000 = 914400
        assert_eq!(shape.x, 914400);
        // 20% of 6858000 = 1371600
        assert_eq!(shape.y, 1371600);
        // 80% of 9144000 = 7315200
        assert_eq!(shape.width, 7315200);
        // 60% of 6858000 = 4114800
        assert_eq!(shape.height, 4114800);
    }

    #[test]
    fn test_shape_from_dimensions_mixed() {
        let shape = Shape::from_dimensions(
            ShapeType::Ellipse,
            Dimension::Inches(1.0), Dimension::Cm(2.54),
            Dimension::Pt(72.0), Dimension::Ratio(0.5),
        );
        assert_eq!(shape.x, 914400);   // 1 inch
        assert_eq!(shape.y, 914400);   // 2.54 cm = 1 inch
        assert_eq!(shape.width, 914400); // 72pt = 1 inch
        assert_eq!(shape.height, 6858000 / 2); // 50% of slide height
    }

    #[test]
    fn test_shape_at_fluent() {
        let shape = Shape::new(ShapeType::Rectangle, 0, 0, 1000000, 500000)
            .at(Dimension::Ratio(0.5), Dimension::Inches(2.0));
        assert_eq!(shape.x, 9144000 / 2);
        assert_eq!(shape.y, 914400 * 2);
        assert_eq!(shape.width, 1000000); // unchanged
    }

    #[test]
    fn test_shape_with_dimensions_fluent() {
        let shape = Shape::new(ShapeType::Rectangle, 100, 200, 0, 0)
            .with_dimensions(Dimension::Ratio(0.9), Dimension::Cm(5.0));
        assert_eq!(shape.x, 100); // unchanged
        assert_eq!(shape.y, 200); // unchanged
        assert_eq!(shape.width, (9144000.0 * 0.9) as u32);
        assert_eq!(shape.height, (5.0 * 360000.0) as u32);
    }

    #[test]
    fn test_shape_chained_at_and_dimensions() {
        let shape = Shape::new(ShapeType::Star5, 0, 0, 0, 0)
            .at(Dimension::percent(10.0), Dimension::percent(20.0))
            .with_dimensions(Dimension::percent(80.0), Dimension::percent(60.0))
            .with_fill(ShapeFill::new("FF0000"));
        assert_eq!(shape.x, 914400);
        assert_eq!(shape.y, 1371600);
        assert_eq!(shape.width, 7315200);
        assert_eq!(shape.height, 4114800);
        assert!(shape.fill.is_some());
    }
}