line.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. # Copyright (c) 2010-2024 openpyxl
  2. from openpyxl.descriptors.serialisable import Serialisable
  3. from openpyxl.descriptors import (
  4. Typed,
  5. Integer,
  6. MinMax,
  7. NoneSet,
  8. Alias,
  9. Sequence
  10. )
  11. from openpyxl.descriptors.nested import (
  12. NestedInteger,
  13. NestedNoneSet,
  14. EmptyTag,
  15. )
  16. from openpyxl.xml.constants import DRAWING_NS
  17. from .colors import ColorChoiceDescriptor
  18. from .fill import GradientFillProperties, PatternFillProperties
  19. from openpyxl.descriptors.excel import ExtensionList as OfficeArtExtensionList
  20. """
  21. Line elements from drawing main schema
  22. """
  23. class LineEndProperties(Serialisable):
  24. tagname = "end"
  25. namespace = DRAWING_NS
  26. type = NoneSet(values=(['none', 'triangle', 'stealth', 'diamond', 'oval', 'arrow']))
  27. w = NoneSet(values=(['sm', 'med', 'lg']))
  28. len = NoneSet(values=(['sm', 'med', 'lg']))
  29. def __init__(self,
  30. type=None,
  31. w=None,
  32. len=None,
  33. ):
  34. self.type = type
  35. self.w = w
  36. self.len = len
  37. class DashStop(Serialisable):
  38. tagname = "ds"
  39. namespace = DRAWING_NS
  40. d = Integer()
  41. length = Alias('d')
  42. sp = Integer()
  43. space = Alias('sp')
  44. def __init__(self,
  45. d=0,
  46. sp=0,
  47. ):
  48. self.d = d
  49. self.sp = sp
  50. class DashStopList(Serialisable):
  51. ds = Sequence(expected_type=DashStop, allow_none=True)
  52. def __init__(self,
  53. ds=None,
  54. ):
  55. self.ds = ds
  56. class LineProperties(Serialisable):
  57. tagname = "ln"
  58. namespace = DRAWING_NS
  59. w = MinMax(min=0, max=20116800, allow_none=True) # EMU
  60. width = Alias('w')
  61. cap = NoneSet(values=(['rnd', 'sq', 'flat']))
  62. cmpd = NoneSet(values=(['sng', 'dbl', 'thickThin', 'thinThick', 'tri']))
  63. algn = NoneSet(values=(['ctr', 'in']))
  64. noFill = EmptyTag()
  65. solidFill = ColorChoiceDescriptor()
  66. gradFill = Typed(expected_type=GradientFillProperties, allow_none=True)
  67. pattFill = Typed(expected_type=PatternFillProperties, allow_none=True)
  68. prstDash = NestedNoneSet(values=(['solid', 'dot', 'dash', 'lgDash', 'dashDot',
  69. 'lgDashDot', 'lgDashDotDot', 'sysDash', 'sysDot', 'sysDashDot',
  70. 'sysDashDotDot']), namespace=namespace)
  71. dashStyle = Alias('prstDash')
  72. custDash = Typed(expected_type=DashStop, allow_none=True)
  73. round = EmptyTag()
  74. bevel = EmptyTag()
  75. miter = NestedInteger(allow_none=True, attribute="lim")
  76. headEnd = Typed(expected_type=LineEndProperties, allow_none=True)
  77. tailEnd = Typed(expected_type=LineEndProperties, allow_none=True)
  78. extLst = Typed(expected_type=OfficeArtExtensionList, allow_none=True)
  79. __elements__ = ('noFill', 'solidFill', 'gradFill', 'pattFill',
  80. 'prstDash', 'custDash', 'round', 'bevel', 'miter', 'headEnd', 'tailEnd')
  81. def __init__(self,
  82. w=None,
  83. cap=None,
  84. cmpd=None,
  85. algn=None,
  86. noFill=None,
  87. solidFill=None,
  88. gradFill=None,
  89. pattFill=None,
  90. prstDash=None,
  91. custDash=None,
  92. round=None,
  93. bevel=None,
  94. miter=None,
  95. headEnd=None,
  96. tailEnd=None,
  97. extLst=None,
  98. ):
  99. self.w = w
  100. self.cap = cap
  101. self.cmpd = cmpd
  102. self.algn = algn
  103. self.noFill = noFill
  104. self.solidFill = solidFill
  105. self.gradFill = gradFill
  106. self.pattFill = pattFill
  107. if prstDash is None:
  108. prstDash = "solid"
  109. self.prstDash = prstDash
  110. self.custDash = custDash
  111. self.round = round
  112. self.bevel = bevel
  113. self.miter = miter
  114. self.headEnd = headEnd
  115. self.tailEnd = tailEnd