Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/openpyxl/drawing/drawing.py: 28%
58 statements
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-20 06:34 +0000
2# Copyright (c) 2010-2023 openpyxl
4import math
6from openpyxl.utils.units import pixels_to_EMU
9class Drawing(object):
10 """ a drawing object - eg container for shapes or charts
11 we assume user specifies dimensions in pixels; units are
12 converted to EMU in the drawing part
13 """
15 count = 0
17 def __init__(self):
19 self.name = ''
20 self.description = ''
21 self.coordinates = ((1, 2), (16, 8))
22 self.left = 0
23 self.top = 0
24 self._width = 21 # default in px
25 self._height = 192 #default in px
26 self.resize_proportional = False
27 self.rotation = 0
28 self.anchortype = "absolute"
29 self.anchorcol = 0 # left cell
30 self.anchorrow = 0 # top row
33 @property
34 def width(self):
35 return self._width
38 @width.setter
39 def width(self, w):
40 if self.resize_proportional and w:
41 ratio = self._height / self._width
42 self._height = round(ratio * w)
43 self._width = w
46 @property
47 def height(self):
48 return self._height
51 @height.setter
52 def height(self, h):
53 if self.resize_proportional and h:
54 ratio = self._width / self._height
55 self._width = round(ratio * h)
56 self._height = h
59 def set_dimension(self, w=0, h=0):
61 xratio = w / self._width
62 yratio = h / self._height
64 if self.resize_proportional and w and h:
65 if (xratio * self._height) < h:
66 self._height = math.ceil(xratio * self._height)
67 self._width = w
68 else:
69 self._width = math.ceil(yratio * self._width)
70 self._height = h
73 @property
74 def anchor(self):
75 from .spreadsheet_drawing import (
76 OneCellAnchor,
77 TwoCellAnchor,
78 AbsoluteAnchor)
79 if self.anchortype == "absolute":
80 anchor = AbsoluteAnchor()
81 anchor.pos.x = pixels_to_EMU(self.left)
82 anchor.pos.y = pixels_to_EMU(self.top)
84 elif self.anchortype == "oneCell":
85 anchor = OneCellAnchor()
86 anchor._from.col = self.anchorcol
87 anchor._from.row = self.anchorrow
89 anchor.ext.width = pixels_to_EMU(self._width)
90 anchor.ext.height = pixels_to_EMU(self._height)
92 return anchor