MCPcopy Index your code
hub / github.com/python-openxml/python-docx / Length

Class Length

src/docx/shared.py:25–70  ·  view source on GitHub ↗

Base class for length constructor classes Inches, Cm, Mm, Px, and Emu. Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to the mm. Provides convenience unit conversion methods in the form of read-only properties. Immutable.

Source from the content-addressed store, hash-verified

23
24
25class Length(int):
26 """Base class for length constructor classes Inches, Cm, Mm, Px, and Emu.
27
28 Behaves as an int count of English Metric Units, 914,400 to the inch, 36,000 to the
29 mm. Provides convenience unit conversion methods in the form of read-only
30 properties. Immutable.
31 """
32
33 _EMUS_PER_INCH = 914400
34 _EMUS_PER_CM = 360000
35 _EMUS_PER_MM = 36000
36 _EMUS_PER_PT = 12700
37 _EMUS_PER_TWIP = 635
38
39 def __new__(cls, emu: int):
40 return int.__new__(cls, emu)
41
42 @property
43 def cm(self):
44 """The equivalent length expressed in centimeters (float)."""
45 return self / float(self._EMUS_PER_CM)
46
47 @property
48 def emu(self):
49 """The equivalent length expressed in English Metric Units (int)."""
50 return self
51
52 @property
53 def inches(self):
54 """The equivalent length expressed in inches (float)."""
55 return self / float(self._EMUS_PER_INCH)
56
57 @property
58 def mm(self):
59 """The equivalent length expressed in millimeters (float)."""
60 return self / float(self._EMUS_PER_MM)
61
62 @property
63 def pt(self):
64 """Floating point length in points."""
65 return self / float(self._EMUS_PER_PT)
66
67 @property
68 def twips(self):
69 """The equivalent length expressed in twips (int)."""
70 return int(round(self / float(self._EMUS_PER_TWIP)))
71
72
73class Inches(Length):

Callers 8

_add_width_ofMethod · 0.90
bottom_marginMethod · 0.90
footerMethod · 0.90
gutterMethod · 0.90
headerMethod · 0.90
left_marginMethod · 0.90
first_line_indentMethod · 0.90

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…