@@ -18,23 +18,31 @@ class Length(int):
1818 _EMUS_PER_CM = 360000
1919 _EMUS_PER_MM = 36000
2020 _EMUS_PER_PX = 12700
21+ _EMUS_PER_TWIP = 635
2122
2223 def __new__ (cls , emu ):
2324 return int .__new__ (cls , emu )
2425
2526 @property
26- def inches (self ):
27+ def cm (self ):
2728 """
28- The equivalent length expressed in inches (float).
29+ The equivalent length expressed in centimeters (float).
2930 """
30- return self / float (self ._EMUS_PER_INCH )
31+ return self / float (self ._EMUS_PER_CM )
3132
3233 @property
33- def cm (self ):
34+ def emu (self ):
3435 """
35- The equivalent length expressed in centimeters (float ).
36+ The equivalent length expressed in English Metric Units (int ).
3637 """
37- return self / float (self ._EMUS_PER_CM )
38+ return self
39+
40+ @property
41+ def inches (self ):
42+ """
43+ The equivalent length expressed in inches (float).
44+ """
45+ return self / float (self ._EMUS_PER_INCH )
3846
3947 @property
4048 def mm (self ):
@@ -50,11 +58,11 @@ def px(self):
5058 return int (round (self / float (self ._EMUS_PER_PX )) + 0.1 )
5159
5260 @property
53- def emu (self ):
61+ def twips (self ):
5462 """
55- The equivalent length expressed in English Metric Units (int).
63+ The equivalent length expressed in twips (int).
5664 """
57- return self
65+ return int ( round ( self / float ( self . _EMUS_PER_TWIP )) + 0.1 )
5866
5967
6068class Inches (Length ):
@@ -116,6 +124,16 @@ def __new__(cls, px):
116124 return Length .__new__ (cls , emu )
117125
118126
127+ class Twips (Length ):
128+ """
129+ Convenience constructor for length in twips, e.g. ``width = Twips(42)``.
130+ A twip is a twentieth of a point, 635 EMU.
131+ """
132+ def __new__ (cls , twips ):
133+ emu = int (twips * Length ._EMUS_PER_TWIP )
134+ return Length .__new__ (cls , emu )
135+
136+
119137def lazyproperty (f ):
120138 """
121139 @lazyprop decorator. Decorated method will be called only on first access
0 commit comments