Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/utils/units.py: 52%
42 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
7#constants
9DEFAULT_ROW_HEIGHT = 15. # Default row height measured in point size.
10BASE_COL_WIDTH = 8 # in characters
11DEFAULT_COLUMN_WIDTH = BASE_COL_WIDTH + 5
12# = baseColumnWidth + {margin padding (2 pixels on each side, totalling 4 pixels)} + {gridline (1pixel)}
15DEFAULT_LEFT_MARGIN = 0.7 # in inches, = right margin
16DEFAULT_TOP_MARGIN = 0.7874 # in inches = bottom margin
17DEFAULT_HEADER = 0.3 # in inches
20# Conversion functions
21"""
22From the ECMA Spec (4th Edition part 1)
23Page setup: "Left Page Margin in inches" p. 1647
25Docs from
26http://startbigthinksmall.wordpress.com/2010/01/04/points-inches-and-emus-measuring-units-in-office-open-xml/
28See also http://msdn.microsoft.com/en-us/library/dd560821(v=office.12).aspx
30dxa: The main unit in OOXML is a twentieth of a point. Also called twips.
31pt: point. In Excel there are 72 points to an inch
32hp: half-points are used to specify font sizes. A font-size of 12pt equals 24 half points
33pct: Half-points are used to specify font sizes. A font-size of 12pt equals 24 half points
35EMU: English Metric Unit, EMUs are used for coordinates in vector-based
36drawings and embedded pictures. One inch equates to 914400 EMUs and a
37centimeter is 360000. For bitmaps the default resolution is 96 dpi (known as
38PixelsPerInch in Excel). Spec p. 1122
40For radial geometry Excel uses integert units of 1/60000th of a degree.
41"""
45def inch_to_dxa(value):
46 """1 inch = 72 * 20 dxa"""
47 return int(value * 20 * 72)
49def dxa_to_inch(value):
50 return value / 72 / 20
53def dxa_to_cm(value):
54 return 2.54 * dxa_to_inch(value)
56def cm_to_dxa(value):
57 emu = cm_to_EMU(value)
58 inch = EMU_to_inch(emu)
59 return inch_to_dxa(inch)
62def pixels_to_EMU(value):
63 """1 pixel = 9525 EMUs"""
64 return int(value * 9525)
66def EMU_to_pixels(value):
67 return round(value / 9525)
70def cm_to_EMU(value):
71 """1 cm = 360000 EMUs"""
72 return int(value * 360000)
74def EMU_to_cm(value):
75 return round(value / 360000, 4)
78def inch_to_EMU(value):
79 """1 inch = 914400 EMUs"""
80 return int(value * 914400)
82def EMU_to_inch(value):
83 return round(value / 914400, 4)
86def pixels_to_points(value, dpi=96):
87 """96 dpi, 72i"""
88 return value * 72 / dpi
91def points_to_pixels(value, dpi=96):
92 return int(math.ceil(value * dpi / 72))
95def degrees_to_angle(value):
96 """1 degree = 60000 angles"""
97 return int(round(value * 60000))
100def angle_to_degrees(value):
101 return round(value / 60000, 2)
104def short_color(color):
105 """ format a color to its short size """
106 if len(color) > 6:
107 return color[2:]
108 return color