Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/styles/fonts.py: 81%

70 statements  

« prev     ^ index     » next       coverage.py v6.4.4, created at 2023-07-17 14:22 -0600

1# Copyright (c) 2010-2022 openpyxl 

2 

3 

4from openpyxl.descriptors import ( 

5 Alias, 

6 Sequence, 

7 Integer 

8) 

9from openpyxl.descriptors.serialisable import Serialisable 

10 

11from openpyxl.descriptors.nested import ( 

12 NestedValue, 

13 NestedBool, 

14 NestedNoneSet, 

15 NestedMinMax, 

16 NestedString, 

17 NestedInteger, 

18 NestedFloat, 

19) 

20from .colors import ColorDescriptor, Color, BLACK 

21 

22from openpyxl.compat import safe_string 

23from openpyxl.xml.functions import Element, SubElement 

24from openpyxl.xml.constants import SHEET_MAIN_NS 

25 

26 

27def _no_value(tagname, value, namespace=None): 

28 if value: 

29 return Element(tagname, val=safe_string(value)) 

30 

31 

32class Font(Serialisable): 

33 """Font options used in styles.""" 

34 

35 UNDERLINE_DOUBLE = 'double' 

36 UNDERLINE_DOUBLE_ACCOUNTING = 'doubleAccounting' 

37 UNDERLINE_SINGLE = 'single' 

38 UNDERLINE_SINGLE_ACCOUNTING = 'singleAccounting' 

39 

40 name = NestedString(allow_none=True) 

41 charset = NestedInteger(allow_none=True) 

42 family = NestedMinMax(min=0, max=14, allow_none=True) 

43 sz = NestedFloat(allow_none=True) 

44 size = Alias("sz") 

45 b = NestedBool(to_tree=_no_value) 

46 bold = Alias("b") 

47 i = NestedBool(to_tree=_no_value) 

48 italic = Alias("i") 

49 strike = NestedBool(allow_none=True) 

50 strikethrough = Alias("strike") 

51 outline = NestedBool(allow_none=True) 

52 shadow = NestedBool(allow_none=True) 

53 condense = NestedBool(allow_none=True) 

54 extend = NestedBool(allow_none=True) 

55 u = NestedNoneSet(values=('single', 'double', 'singleAccounting', 

56 'doubleAccounting')) 

57 underline = Alias("u") 

58 vertAlign = NestedNoneSet(values=('superscript', 'subscript', 'baseline')) 

59 color = ColorDescriptor(allow_none=True) 

60 scheme = NestedNoneSet(values=("major", "minor")) 

61 

62 tagname = "font" 

63 

64 __elements__ = ('name', 'charset', 'family', 'b', 'i', 'strike', 'outline', 

65 'shadow', 'condense', 'color', 'extend', 'sz', 'u', 'vertAlign', 

66 'scheme') 

67 

68 

69 def __init__(self, name=None, sz=None, b=None, i=None, charset=None, 

70 u=None, strike=None, color=None, scheme=None, family=None, size=None, 

71 bold=None, italic=None, strikethrough=None, underline=None, 

72 vertAlign=None, outline=None, shadow=None, condense=None, 

73 extend=None): 

74 self.name = name 

75 self.family = family 

76 if size is not None: 76 ↛ 77line 76 didn't jump to line 77, because the condition on line 76 was never true

77 sz = size 

78 self.sz = sz 

79 if bold is not None: 79 ↛ 80line 79 didn't jump to line 80, because the condition on line 79 was never true

80 b = bold 

81 self.b = b 

82 if italic is not None: 82 ↛ 83line 82 didn't jump to line 83, because the condition on line 82 was never true

83 i = italic 

84 self.i = i 

85 if underline is not None: 85 ↛ 86line 85 didn't jump to line 86, because the condition on line 85 was never true

86 u = underline 

87 self.u = u 

88 if strikethrough is not None: 88 ↛ 89line 88 didn't jump to line 89, because the condition on line 88 was never true

89 strike = strikethrough 

90 self.strike = strike 

91 self.color = color 

92 self.vertAlign = vertAlign 

93 self.charset = charset 

94 self.outline = outline 

95 self.shadow = shadow 

96 self.condense = condense 

97 self.extend = extend 

98 self.scheme = scheme 

99 

100 

101 @classmethod 

102 def from_tree(cls, node): 

103 """ 

104 Set default value for underline if child element is present 

105 """ 

106 underline = node.find("{%s}u" % SHEET_MAIN_NS) 

107 if underline is not None and underline.get('val') is None: 107 ↛ 108line 107 didn't jump to line 108, because the condition on line 107 was never true

108 underline.set("val", "single") 

109 return super(Font, cls).from_tree(node) 

110 

111 

112DEFAULT_FONT = Font(name="Calibri", sz=11, family=2, b=False, i=False, 

113 color=Color(theme=1), scheme="minor")