Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/drawing/drawing.py: 29%
64 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1from __future__ import division
2# Copyright (c) 2010-2022 openpyxl
4import math
6from openpyxl.compat import deprecated
8from openpyxl.styles.colors import Color, BLACK, WHITE
9from openpyxl.utils.units import (
10 pixels_to_EMU,
11 EMU_to_pixels,
12 short_color,
13)
16class Drawing(object):
17 """ a drawing object - eg container for shapes or charts
18 we assume user specifies dimensions in pixels; units are
19 converted to EMU in the drawing part
20 """
22 count = 0
24 def __init__(self):
26 self.name = ''
27 self.description = ''
28 self.coordinates = ((1, 2), (16, 8))
29 self.left = 0
30 self.top = 0
31 self._width = 21 # default in px
32 self._height = 192 #default in px
33 self.resize_proportional = False
34 self.rotation = 0
35 self.anchortype = "absolute"
36 self.anchorcol = 0 # left cell
37 self.anchorrow = 0 # top row
40 @property
41 def width(self):
42 return self._width
44 @width.setter
45 def width(self, w):
46 if self.resize_proportional and w:
47 ratio = self._height / self._width
48 self._height = round(ratio * w)
49 self._width = w
51 @property
52 def height(self):
53 return self._height
55 @height.setter
56 def height(self, h):
57 if self.resize_proportional and h:
58 ratio = self._width / self._height
59 self._width = round(ratio * h)
60 self._height = h
62 def set_dimension(self, w=0, h=0):
64 xratio = w / self._width
65 yratio = h / self._height
67 if self.resize_proportional and w and h:
68 if (xratio * self._height) < h:
69 self._height = math.ceil(xratio * self._height)
70 self._width = w
71 else:
72 self._width = math.ceil(yratio * self._width)
73 self._height = h
75 @deprecated("Private method used when serialising")
76 def get_emu_dimensions(self):
77 """ return (x, y, w, h) in EMU """
79 return (pixels_to_EMU(self.left), pixels_to_EMU(self.top),
80 pixels_to_EMU(self._width), pixels_to_EMU(self._height))
83 @property
84 def anchor(self):
85 from .spreadsheet_drawing import (
86 OneCellAnchor,
87 TwoCellAnchor,
88 AbsoluteAnchor)
89 if self.anchortype == "absolute":
90 anchor = AbsoluteAnchor()
91 anchor.pos.x = pixels_to_EMU(self.left)
92 anchor.pos.y = pixels_to_EMU(self.top)
94 elif self.anchortype == "oneCell":
95 anchor = OneCellAnchor()
96 anchor._from.col = self.anchorcol
97 anchor._from.row = self.anchorrow
99 anchor.ext.width = pixels_to_EMU(self._width)
100 anchor.ext.height = pixels_to_EMU(self._height)
102 return anchor