forked from reingart/pyfpdf
-
Notifications
You must be signed in to change notification settings - Fork 264
/
Copy pathtransitions.py
128 lines (95 loc) · 4.34 KB
/
transitions.py
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
from abc import ABC
class Transition(ABC):
def serialize(self, _security_handler=None, _obj_id=None):
raise NotImplementedError
class SplitTransition(Transition):
def __init__(self, dimension, direction):
if dimension not in ("H", "V"):
raise ValueError(
f"Unsupported dimension '{dimension}', must be H(horizontal) or V(ertical)"
)
self.dimension = dimension
if direction not in ("I", "O"):
raise ValueError(
f"Unsupported direction '{direction}', must be I(nward) or O(utward)"
)
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Split /DM /{self.dimension} /M /{self.direction}>>"
class BlindsTransition(Transition):
def __init__(self, dimension):
if dimension not in ("H", "V"):
raise ValueError(
f"Unsupported dimension '{dimension}', must be H(horizontal) or V(ertical)"
)
self.dimension = dimension
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Blinds /DM /{self.dimension}>>"
class BoxTransition(Transition):
def __init__(self, direction):
if direction not in ("I", "O"):
raise ValueError(
f"Unsupported direction '{direction}', must be I(nward) or O(utward)"
)
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Blinds /M /{self.direction}>>"
class WipeTransition(Transition):
def __init__(self, direction):
if direction not in (0, 90, 180, 270):
raise ValueError(
f"Unsupported direction '{direction}', must 0, 90, 180 or 270"
)
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Wipe /Di /{self.direction}>>"
class DissolveTransition(Transition):
def serialize(self, _security_handler=None, _obj_id=None):
return "<</Type /Trans /S /Dissolve>>"
class GlitterTransition(Transition):
def __init__(self, direction):
if direction not in (0, 270, 315):
raise ValueError(f"Unsupported direction '{direction}', must 0, 270 or 315")
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Glitter /Di /{self.direction}>>"
class FlyTransition(Transition):
def __init__(self, dimension, direction=None):
if dimension not in ("H", "V"):
raise ValueError(
f"Unsupported dimension '{dimension}', must be H(horizontal) or V(ertical)"
)
self.dimension = dimension
if direction not in (0, 270, None):
raise ValueError(
f"Unsupported direction '{direction}', must 0, 270 or None"
)
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return (
f"<</Type /Trans /S /Glitter /M /{self.dimension} /Di /{self.direction}>>"
)
class PushTransition(Transition):
def __init__(self, direction):
if direction not in (0, 270):
raise ValueError(f"Unsupported direction '{direction}', must 0 or 270")
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Push /Di /{self.direction}>>"
class CoverTransition(Transition):
def __init__(self, direction):
if direction not in (0, 270):
raise ValueError(f"Unsupported direction '{direction}', must 0 or 270")
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Cover /Di /{self.direction}>>"
class UncoverTransition(Transition):
def __init__(self, direction):
if direction not in (0, 270):
raise ValueError(f"Unsupported direction '{direction}', must 0 or 270")
self.direction = direction
def serialize(self, _security_handler=None, _obj_id=None):
return f"<</Type /Trans /S /Uncover /Di /{self.direction}>>"
class FadeTransition(Transition):
def serialize(self, _security_handler=None, _obj_id=None):
return "<</Type /Fade /S /Dissolve>>"