-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathPPspliT.bas
2333 lines (2188 loc) · 113 KB
/
PPspliT.bas
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
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
Attribute VB_Name = "PPspliT"
'
'
' _____ _____ _ _ _______
' | __ \| __ \ | (_)__ __|
' | |__) | |__) |__ _ __ | |_ | |
' | ___/| ___/ __| '_ \| | | | |
' | | | | \__ \ |_) | | | | |
' |_| |_| |___/ .__/|_|_| |_|
' | |
' |_| by Massimo Rimondini - version 2.6
'
' first written by Massimo Rimondini in November 2009
' last update: Mar 2024
' Source code for PowerPoint 2007+
'
'
' This global variable indicates whether and how slide numbers should be kept
' consistent with the original set of slides. For example, if slide 6 is split
' into 3 slides, then all those 3 slides will be numbered 6 after splitting.
' As an alternative option, a subindex can be added to slide numbers, so that,
' for example, slide 6 is split into 6.1, 6.2, 6.3, etc.
Public slideNumbersAdjustMode As Integer
Public Const SLIDENUMBER_DONOTHING = 0
Public Const SLIDENUMBER_BAKE = 1
Public Const SLIDENUMBER_SUBINDEX = 2
' This global variable indicates whether animations should be split
' at each mouse-triggered event. If set to false, a separate slide is
' created for each and every animation.
Public splitMouseTriggered As Boolean
' The following variables are for internal use only.
Public cancelStatus As Boolean
Public slide_number As Integer
' Required at least for Office 2010 64 bit, as Windows Common Controls are
' not available
Public Const maxProgressWidth = 324
'
' Convert decimal separators in the argument string from '.' to the most
' appropriate character for the system-configured locale.
'
Private Function localizeDecimalSeparators(ByVal s As String)
Dim d As Double, useCommaAsSeparator As Boolean
useCommaAsSeparator = False
' Use a test value to check for the currently used decimal
' separator. In principle, we could use the user-supplied
' argument, but if it is a value between 0 and 1, it could
' miss the leading zero (e.g., -.1234), thus raising errors
' if we are not using the correct decimal separator in the
' assignment (which is exactly what we are trying to
' discover here).
d = "1,2"
' If "," is not the decimal separator in use for the current
' system locale, this assignment results in losing the decimal
' separator.
' Now, this test requires care: in fact, localization of
' Double values seems to happen whenever a value is output on
' screen or is converted from a string, but in some way it does
' not seem to affect the internal representation of the Double
' value. Therefore, to check whether the decimal separator
' has survived the assignment, we need to look for its
' internal representation (which is "."), not its localized one.
useCommaAsSeparator = (InStr(Trim(Str$(d)), ".") > 0)
If useCommaAsSeparator Then
d = Replace(s, ".", ",")
Else
d = s
End If
localizeDecimalSeparators = d
End Function
'
' This function looks for a shape in a slide by its ID (which has
' been previously copied to a tag).
' It returns Nothing if no such shape is found.
'
Private Function findShapeByIDinTag(shapeID As Long, slide As slide)
Dim s As Shape
Set findShapeByIDinTag = Nothing
For Each s In slide.Shapes
If s.Tags("PPspliT_ID") = Str$(shapeID) Then
Set findShapeByIDinTag = s
Exit Function
End If
Next s
End Function
'
' This utility sub is required to wrap the action of accessing
' property Brightness of ColorFormat objects, because this
' property is only exposed starting from Office 2010 (14.0).
' Since VBA's compiler evaluates the full code of a subroutine
' when it is about to execute it, putting this assignment in a
' conditional statement is not enough to prevent it from raising
' a "Method or data member not found" error at runtime.
'
Private Sub assignColorBrightness(col1 As ColorFormat, col2)
If TypeOf col2 Is ColorFormat Then
col1.Brightness = col2.Brightness
Else
col1.Brightness = col2("Brightness")
End If
End Sub
'
' Similar to assignColorBrightness (and serving the same purpose),
' but adapted to add a Brightness object to a Collection.
'
Private Sub addBrightnessToCollection(cf As ColorFormat, coll As Collection)
coll.Add cf.Brightness, "Brightness"
End Sub
'
' This subroutine assigns the color in the ColorFormat object
' col2 to the ColorFormat object col1. To work around issues in
' other code fragments, col2 is also accepted in the form of a
' Collection containing the same attributes as a ColorFormat
' object, but in the form of Collection items.
' Since color assignments may involve several object types (e.g.,
' shapes, text, color change effects), care must be taken in
' that the color may be specified as an index referring to the
' slide color scheme or as an RGB value. There are cases (e.g.,
' target color in color change effects) in which directly
' assigning the RGB value when the target color is indeed
' derived from the slide color scheme can result in a
' "ColorFormat: Invalid request. This object has no associated
' color scheme" runtime error, actually meaning the RGB value
' is inaccessible.
'
Private Sub assignColor(col1 As ColorFormat, ByVal col2)
If TypeOf col2 Is ColorFormat Then
If col2.Type = msoColorTypeRGB Then
col1.RGB = col2.RGB
Else
' I must protect from invalid assignments of color
' scheme indexes.
On Error Resume Next
col1.SchemeColor = col2.SchemeColor
' Sometimes the scheme color may be associated with a Brightness
' attribute, referred to the color in the first row of the color
' palette (that is, the scheme color).
' Apparently, this attribute is only supported starting
' from Office 2010 (14.0) and, in addition, may sometimes be
' missing altogether. There are no ways I am aware of to determine
' whether the color selected by the user really has this attribute,
' therefore the following code frament is still within the
' "On Error Resume Next" block.
If Int(Mid$(Application.Version, 1, Len(Application.Version) - 2)) > 12 Then
' The brightness level is
assignColorBrightness col1, col2
End If
On Error GoTo 0
End If
Else
If col2("Type") = msoColorTypeRGB Then
col1.RGB = col2("RGB")
Else
' I must protect from invalid assignments of color
' scheme indexes.
On Error Resume Next
col1.SchemeColor = col2("SchemeColor")
' Sometimes the scheme color may be associated with a Brightness
' attribute, referred to the color in the first row of the color
' palette (that is, the scheme color).
' Apparently, this attribute is only supported starting
' from Office 2010 (14.0) and, in addition, may sometimes be
' missing altogether. There are no ways I am aware of to determine
' whether the color selected by the user really has this attribute,
' therefore the following code frament is still within the
' "On Error Resume Next" block.
If Int(Mid$(Application.Version, 1, Len(Application.Version) - 2)) > 12 Then
assignColorBrightness col1, col2
End If
On Error GoTo 0
End If
End If
End Sub
'
' This subroutine converts a color value from the RGB space to the
' HSL space. The result will be put in the last 3 arguments.
' The procedure is taken from http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_overview
'
Private Sub RGBtoHSL(r, g, b, h, s, l)
max = 0: min = 255
r = r / 255: g = g / 255: b = b / 255
If r > max Then max = r
If g > max Then max = g
If b > max Then max = b
If r < min Then min = r
If g < min Then min = g
If b < min Then min = b
If max = min Then
h = 0
ElseIf max = r Then
h = (60 * (g - b) / (max - min) + 360) Mod 360
ElseIf max = g Then
h = 60 * (b - r) / (max - min) + 120
ElseIf max = b Then
h = 60 * (r - g) / (max - min) + 240
End If
l = (max + min) / 2
If max = min Then
s = 0
ElseIf l <= 1 / 2 Then
s = (max - min) / (2 * l)
ElseIf l > 1 / 2 Then
s = (max - min) / (2 - 2 * l)
End If
End Sub
'
' This subroutine converts a color value from the HSL space to the
' RGB space. The result will be put in the last 3 arguments.
' The procedure is taken from http://en.wikipedia.org/wiki/HSL_and_HSV#Conversion_from_RGB_to_HSL_overview
'
Private Sub HSLtoRGB(h, s, l, r, g, b)
If l < 1 / 2 Then
q = l * (1 + s)
Else
q = l + s - l * s
End If
p = 2 * l - q
hk = h / 360
tr = hk + 1 / 3
' Cannot use the Mod operator here, as it only supports integer arithmetic
If tr < 0 Then tr = tr + 1
If tr > 1 Then tr = tr - 1
tg = hk
If tg < 0 Then tg = tg + 1
If tg > 1 Then tg = tg - 1
tb = hk - 1 / 3
If tb < 0 Then tb = tb + 1
If tb > 1 Then tb = tb - 1
If tr < 1 / 6 Then
r = p + ((q - p) * 6 * tr)
ElseIf tr >= 1 / 6 And tr < 1 / 2 Then
r = q
ElseIf tr >= 1 / 2 And tr < 2 / 3 Then
r = p + ((q - p) * 6 * (2 / 3 - tr))
Else
r = p
End If
If tg < 1 / 6 Then
g = p + ((q - p) * 6 * tg)
ElseIf tg >= 1 / 6 And tg < 1 / 2 Then
g = q
ElseIf tg >= 1 / 2 And tg < 2 / 3 Then
g = p + ((q - p) * 6 * (2 / 3 - tg))
Else
g = p
End If
If tb < 1 / 6 Then
b = p + ((q - p) * 6 * tb)
ElseIf tb >= 1 / 6 And tb < 1 / 2 Then
b = q
ElseIf tb >= 1 / 2 And tb < 2 / 3 Then
b = p + ((q - p) * 6 * (2 / 3 - tb))
Else
b = p
End If
r = r * 255: g = g * 255: b = b * 255
End Sub
'
' This subroutine converts a color value represented by VBA as a Long
' integer into its RGB components. The result is put in the last
' 3 arguments of the subroutine.
'
Private Sub colToRGB(col, r, g, b)
r = col Mod 256
g = (col \ 256) Mod 256
b = (col \ 256 \ 256) Mod 256
End Sub
'
' This subroutine "rotates" the hue of a given color of the
' specified angle (in degrees).
'
Private Sub rotateColor(col As ColorFormat, rot)
colToRGB col.RGB, r, g, b
RGBtoHSL r, g, b, h, s, l
h = (h + rot) Mod 360
HSLtoRGB h, s, l, r, g, b
col.RGB = RGB(r, g, b)
End Sub
'
' This subroutine alters the lightness of a given color.
' The amount should be between 0 and 1.
'
Private Sub changeLightness(col As ColorFormat, amount)
colToRGB col.RGB, r, g, b
RGBtoHSL r, g, b, h, s, l
l = l + amount
If l > 1 Then l = 1
If l < 0 Then l = 0
HSLtoRGB h, s, l, r, g, b
col.RGB = RGB(r, g, b)
End Sub
'
' After a motion effect has been applied to a shape, the coordinates
' of all subsequent motion effects have been moved together with the
' shape. This subroutine applies a given shift to the arrival
' coordinates (indeed, arrival coordinates is all I need to update)
' of all the other motion effects for the same shape. Arguments
' effectSequence (the sequence of effects applied to the shape) and
' sh (the affected shape) do not need, and in general do not, refer
' to the same slide.
'
' A motion path is specified in VML. Information about the specification
' can be found here: http://www.w3.org/TR/NOTE-VML#_Toc416858391
'
Private Sub shiftAllMotions(effectSequence As Sequence, sh As Shape, shiftX, shiftY)
Dim currentEffect As effect, lastX As Double, lastY As Double
For Each currentEffect In effectSequence
' The following variable is where I will put the reconstructed
' path with updated arrival coordinates
motionPathString$ = ""
' Keep in mind that sh is a shape the effect is applied to (therefore
' it comes from a certain slide), while effectSequence is the sequence of effects
' under consideration (which comes from a different slide). Therefore,
' operator "Is" cannot be used to match the shapes whose motion effects
' should be updated.
If isPathEffect(currentEffect) And currentEffect.Shape.Id = sh.Id Then
' This is a motion effect applied to the shape under consideration
motionPathTokens = Split(currentEffect.Behaviors(1).MotionEffect.Path)
' The first character states this is a path motion, therefore I preserve it
motionPathString$ = motionPathString$ + Trim(motionPathTokens(0)) + " "
If currentEffect.Behaviors(1).Timing.Speed < 0 Then
' The path has been reversed: update origin coordinates instead
lastX = localizeDecimalSeparators(motionPathTokens(1))
lastY = localizeDecimalSeparators(motionPathTokens(2))
lastX = lastX + shiftX
lastY = lastY + shiftY
motionPathString$ = motionPathString$ + Trim(Str$(lastX)) + " " + Trim(Str$(lastY)) + " "
' Append the rest of the motion string
For i = 3 To UBound(motionPathTokens)
motionPathString$ = motionPathString$ + motionPathTokens(i) + " "
Next i
Else
' Update the last two (i.e., arrival) coordinates
getLastCoordinates currentEffect.Behaviors(1).MotionEffect.Path, lastX, lastY, lastToken
lastX = lastX + shiftX
lastY = lastY + shiftY
' Copy everything but the last two coordinates from the original
' motion string
For i = 0 To lastToken
motionPathString$ = motionPathString$ + motionPathTokens(i) + " "
Next i
' Append the modified coordinates
motionPathString$ = motionPathString$ + Trim(Str$(lastX)) + " " + Trim(Str$(lastY)) + " "
End If
' Assign the new path
currentEffect.Behaviors(1).MotionEffect.Path = motionPathString$
End If
Next currentEffect
End Sub
'
' This converts an angle from degrees to radians. At the
' same time, since shape rotation angles are computed in PowerPoint
' starting from the positive Y semiaxis and going in
' clockwise direction, it reverses the convention by returning
' an angle in radiants that starts from the positive X semiaxis
' and goes counterclockwise.
'
Private Function degToRad(degAngle) As Double
degToRad = 3.14159265358979 * ((360 - degAngle) Mod 360) / 180
End Function
'
' This subroutine gets the last (i.e., arrival) coordinates from
' a string describing a motion path. Extracted coordinates are put
' in lastX and lastY, while lastTokenBeforeCoordinates will be
' updated with the index of the token in pathString$ that precedes
' the last coordinates.
'
Private Sub getLastCoordinates(pathString$, lastX As Double, lastY As Double, lastTokenBeforeCoordinates)
pathStringTokens = Split(pathString$)
tokenIndex = UBound(pathStringTokens)
While tokenIndex > 0
If pathStringTokens(tokenIndex) <> "" And _
Not (Mid$(pathStringTokens(tokenIndex), 1, 1) >= "A" And _
Mid$(pathStringTokens(tokenIndex), 1, 1) <= "Z") Then
lastY = localizeDecimalSeparators(pathStringTokens(tokenIndex))
lastX = localizeDecimalSeparators(pathStringTokens(tokenIndex - 1))
lastTokenBeforeCoordinates = tokenIndex - 2
Exit Sub
End If
tokenIndex = tokenIndex - 1
Wend
End Sub
'
' This subroutine does what it says: it applies an emphasis
' (or motion) effect to a shape. Arguments are:
' - seq: a sequence of effects which will only be modified to update
' motion path coordinates for the specific case of a motion effect
' - e: the emphasis effect to be applied
' - sh: the shape it applies to
'
Private Sub applyEmphasisEffect(seq As Sequence, e As effect, sh As Shape, final_colors As Collection)
On Error GoTo recover
ePar = getEffectParagraph(e)
' Here I should be supposed to check the value of
' e.Shape.HasTextFrame before attemping to access
' the sh.TextFrame.TextRange property. Unfortunately,
' in some cases PowerPoint returns false even if
' properties like sh.TextFrame.TextRange.Font.Size
' can be accessed.
' Worked around by attempting assignments anyway, and
' watching for errors during the process.
On Error Resume Next
shTextRange = Null
shTextRange2 = Null
If ePar > 0 Then
' This effect applies to a text paragraph.
' In some rare cases, the effect may be improperly applied to an
' empty paragraph, which is generally forbidden by PowerPoint.
' Unfortunately, empty paragraphs occurring at the end of a text
' frame do not contribute to the total paragraphs count: as a
' consequence, the index of the paragraph the effect
' is applied to may sometimed exceed the total paragraph count.
' In this case the subroutine simply silently exits.
If ePar > sh.TextFrame.TextRange.Paragraphs.Count Then
On Error GoTo 0
Exit Sub
End If
Set shTextRange = sh.TextFrame.TextRange.Paragraphs(ePar)
Set shTextRange2 = sh.TextFrame2.TextRange.Paragraphs(ePar)
Else
Set shTextRange = sh.TextFrame.TextRange
Set shTextRange2 = sh.TextFrame2.TextRange
End If
On Error GoTo recover
' Note: if an effect acts both on a text element and on its container
' shape, then the effect must first be applied to the container shape,
' in order to avoid unpredictable automatic resizing.
If e.EffectType = msoAnimEffectGrowShrink Then
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
' I am not scaling a bitmap here, therefore I need to
' recompute map X and Y scaling in accordance with the shape
' rotation.
rotCos = Cos(degToRad(sh.Rotation))
rotSin = Sin(degToRad(sh.Rotation))
scaleX = e.Behaviors(1).ScaleEffect.ByX / 100 * Abs(rotCos) + e.Behaviors(1).ScaleEffect.ByY / 100 * Abs(rotSin)
scaleY = e.Behaviors(1).ScaleEffect.ByX / 100 * Abs(rotSin) + e.Behaviors(1).ScaleEffect.ByY / 100 * Abs(rotCos)
' Disable size autofitting for text frames and unlock
' aspect ratio
sh.LockAspectRatio = msoFalse
On Error Resume Next
sh.TextFrame.AutoSize = ppAutoSizeNone
On Error GoTo recover
sh.ScaleWidth scaleX, msoFalse, msoScaleFromMiddle
sh.ScaleHeight scaleY, msoFalse, msoScaleFromMiddle
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
shTextRange.Font.Size = shTextRange.Font.Size * (e.Behaviors(1).ScaleEffect.ByX / 100 + e.Behaviors(1).ScaleEffect.ByY / 100) / 2
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectChangeFontColor Then
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
assignColor shTextRange.Font.Color, final_colors
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectChangeFillColor Then
If sh.Fill.Transparency < 1 Then
sh.Fill.Solid
End If
' Use the final_colors Collection here, to retrieve the
' correct target color value
assignColor sh.Fill.ForeColor, final_colors
' Original statement follows
' assignColor sh.Fill.ForeColor, e.EffectParameters.Color2
ElseIf e.EffectType = msoAnimEffectChangeFontStyle Then
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
shTextRange.Font.Italic = (e.Behaviors(1).SetEffect.To = 1)
shTextRange.Font.Bold = (e.Behaviors(2).SetEffect.To = 1)
shTextRange.Font.Underline = (e.Behaviors(3).SetEffect.To = 1)
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectTransparency Then
' Potentially bad consequence: objects that are made totally
' transparent cannot have their transparency changed
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Line.Transparency < 1 Then
sh.Line.Transparency = e.EffectParameters.amount
End If
If sh.Fill.Transparency < 1 Then
sh.Fill.Transparency = e.EffectParameters.amount
End If
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange2 = Null
On Error Resume Next
Set shTextRange2 = sh.GroupItems(shapeID).TextFrame2.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange2) Then
If shTextRange2.Font.Fill.Transparency < 1 Then
shTextRange2.Font.Fill.Transparency = e.EffectParameters.amount
End If
If shTextRange2.Font.Line.Transparency < 1 Then
shTextRange2.Font.Line.Transparency = e.EffectParameters.amount
End If
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange2 = Null
On Error Resume Next
Set shTextRange2 = sh.GroupItems(shapeID).TextFrame2.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectChangeFont Then
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
shTextRange.Font.Name = e.EffectParameters.FontName
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectChangeLineColor Then
If Not sh.Line.Visible Then sh.Line.Visible = msoTrue
' Use the final_colors Collection here, to retrieve the
' correct target color value
assignColor sh.Line.ForeColor, final_colors
' Original statement follows
' assignColor sh.Line.ForeColor, e.EffectParameters.Color2
ElseIf e.EffectType = msoAnimEffectChangeFontSize Then
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
' Please leave the /1 alone: it is required for some strange internal
' type conversion, otherwise leading to improper font sizes :-(
shTextRange.Font.Size = shTextRange.Font.Size * e.Behaviors(1).PropertyEffect.To / 1
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectSpin Then
' Rotating just the text is not supported
sh.Rotation = sh.Rotation + e.Behaviors(1).RotationEffect.By
ElseIf e.EffectType = msoAnimEffectDesaturate Then
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
With sh.Fill.ForeColor
colToRGB .RGB, r, g, b
.RGB = RGB((r + g + b) / 3, (r + g + b) / 3, (r + g + b) / 3)
End With
With sh.Fill.BackColor
colToRGB .RGB, r, g, b
.RGB = RGB((r + g + b) / 3, (r + g + b) / 3, (r + g + b) / 3)
End With
End If
If sh.Line.Transparency < 1 Then
With sh.Line.ForeColor
colToRGB .RGB, r, g, b
.RGB = RGB((r + g + b) / 3, (r + g + b) / 3, (r + g + b) / 3)
End With
End If
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
With shTextRange.Font.Color
colToRGB .RGB, r, g, b
.RGB = RGB((r + g + b) / 3, (r + g + b) / 3, (r + g + b) / 3)
End With
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectColorWave Or e.EffectType = msoAnimEffectColorBlend Or _
e.EffectType = msoAnimEffectBrushOnColor Or e.EffectType = msoAnimEffectTeeter Then
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
assignColor sh.Fill.ForeColor, e.EffectParameters.Color2
End If
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
assignColor shTextRange.Font.Color, final_colors
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectComplementaryColor2 Then
' PowerPoint computes the complementary color in some other way.
' I feel pretty satisfied with this rotation in the HSL space
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
rotateColor sh.Fill.ForeColor, 180
End If
If sh.Line.Transparency < 1 Then
rotateColor sh.Line.ForeColor, 180
End If
End If
ElseIf e.EffectType = msoAnimEffectVerticalGrow Then
' Font scaling alone is not supported for this effect
' Disable size autofitting for text frames and unlock
' aspect ratio
sh.LockAspectRatio = msoFalse
On Error Resume Next
sh.TextFrame.AutoSize = ppAutoSizeNone
On Error GoTo recover
sh.ScaleHeight 1.5, msoFalse
shiftY = sh.Height / 4
If sh.Fill.Transparency < 1 Then
assignColor sh.Fill.ForeColor, e.EffectParameters.Color2
End If
sh.Top = sh.Top - shiftY
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
assignColor shTextRange.Font.Color, final_colors
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectLighten Then
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
changeLightness sh.Fill.ForeColor, 0.3
End If
If sh.Line.Transparency < 1 Then
changeLightness sh.Line.ForeColor, 0.3
End If
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
changeLightness shTextRange.Font.Color, 0.3
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectBrushOnUnderline Then
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
shTextRange.Font.Underline = msoTrue
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectComplementaryColor Then
' PowerPoint computes the complementary color in some other way.
' I feel pretty satisfied with this rotation in the HSL space
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
rotateColor sh.Fill.ForeColor, 120
End If
If sh.Line.Transparency < 1 Then
rotateColor sh.Line.ForeColor, 120
End If
End If
ElseIf e.EffectType = msoAnimEffectContrastingColor Then
' PowerPoint computes the contrasting color in some other way.
' I feel pretty satisfied with this rotation in the HSL space
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
rotateColor sh.Fill.ForeColor, 90
End If
If sh.Line.Transparency < 1 Then
rotateColor sh.Line.ForeColor, 90
End If
End If
ElseIf e.EffectType = msoAnimEffectBoldFlash Then
' msoAnimEffectBoldFlash is a non-permanent effect
ElseIf e.EffectType = msoAnimEffectFlashBulb Then
' msoAnimEffectFlashBulb is a non-permanent effect
ElseIf e.EffectType = msoAnimEffectDarken Then
If e.Shape.Type = msoPlaceholder Or e.EffectInformation.AnimateBackground Or Not e.Shape.TextFrame.HasText Or e.Shape.Type = msoGroup Then
If sh.Fill.Transparency < 1 Then
changeLightness sh.Fill.ForeColor, -0.3
End If
If sh.Line.Transparency < 1 Then
changeLightness sh.Line.ForeColor, -0.3
End If
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
changeLightness shTextRange.Font.Color, -0.3
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectGrowWithColor Then
If sh.Fill.Transparency < 1 Then
sh.Fill.Solid
assignColor sh.Fill.ForeColor, e.EffectParameters.Color2
End If
' Font effects may be applied to a group. In that case,
' at least for versions of PowerPoint prior to 2007, we
' are forced to apply the effect for each member of the
' group.
shapeID = 1
If sh.Type = msoGroup Then
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Do
If Not IsNull(shTextRange) Then
shTextRange.Font.Size = shTextRange.Font.Size * 1.5
assignColor shTextRange.Font.Color, final_colors
End If
shapeID = shapeID + 1
If sh.Type = msoGroup Then
If shapeID > sh.GroupItems.Count Then
shapeID = 0
Else
shTextRange = Null
On Error Resume Next
Set shTextRange = sh.GroupItems(shapeID).TextFrame.TextRange
On Error GoTo recover
End If
Else
shapeID = 0
End If
Loop Until shapeID = 0
ElseIf e.EffectType = msoAnimEffectFlicker Then