draw.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. # -*- coding: utf-8 -*-
  2. # Copyright (C) 2006-2007 Søren Roug, European Environment Agency
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. #
  18. # Contributor(s):
  19. #
  20. import sys, os.path
  21. sys.path.append(os.path.dirname(__file__))
  22. from odf.namespaces import DRAWNS, STYLENS, PRESENTATIONNS
  23. from odf.element import Element
  24. def StyleRefElement(stylename=None, classnames=None, **args):
  25. qattrs = {}
  26. if stylename is not None:
  27. f = stylename.getAttrNS(STYLENS, 'family')
  28. if f == 'graphic':
  29. qattrs[(DRAWNS,u'style-name')]= stylename
  30. elif f == 'presentation':
  31. qattrs[(PRESENTATIONNS,u'style-name')]= stylename
  32. else:
  33. raise ValueError( "Style's family must be either 'graphic' or 'presentation'")
  34. if classnames is not None:
  35. f = classnames[0].getAttrNS(STYLENS, 'family')
  36. if f == 'graphic':
  37. qattrs[(DRAWNS,u'class-names')]= classnames
  38. elif f == 'presentation':
  39. qattrs[(PRESENTATIONNS,u'class-names')]= classnames
  40. else:
  41. raise ValueError( "Style's family must be either 'graphic' or 'presentation'")
  42. return Element(qattributes=qattrs, **args)
  43. def DrawElement(name=None, **args):
  44. e = Element(name=name, **args)
  45. if 'displayname' not in args:
  46. e.setAttrNS(DRAWNS,'display-name', name)
  47. return e
  48. # Autogenerated
  49. def A(**args):
  50. args.setdefault('type', 'simple')
  51. return Element(qname = (DRAWNS,'a'), **args)
  52. def Applet(**args):
  53. return Element(qname = (DRAWNS,'applet'), **args)
  54. def AreaCircle(**args):
  55. return Element(qname = (DRAWNS,'area-circle'), **args)
  56. def AreaPolygon(**args):
  57. return Element(qname = (DRAWNS,'area-polygon'), **args)
  58. def AreaRectangle(**args):
  59. return Element(qname = (DRAWNS,'area-rectangle'), **args)
  60. def Caption(**args):
  61. return StyleRefElement(qname = (DRAWNS,'caption'), **args)
  62. def Circle(**args):
  63. return StyleRefElement(qname = (DRAWNS,'circle'), **args)
  64. def Connector(**args):
  65. return StyleRefElement(qname = (DRAWNS,'connector'), **args)
  66. def ContourPath(**args):
  67. return Element(qname = (DRAWNS,'contour-path'), **args)
  68. def ContourPolygon(**args):
  69. return Element(qname = (DRAWNS,'contour-polygon'), **args)
  70. def Control(**args):
  71. return StyleRefElement(qname = (DRAWNS,'control'), **args)
  72. def CustomShape(**args):
  73. return StyleRefElement(qname = (DRAWNS,'custom-shape'), **args)
  74. def Ellipse(**args):
  75. return StyleRefElement(qname = (DRAWNS,'ellipse'), **args)
  76. def EnhancedGeometry(**args):
  77. return Element(qname = (DRAWNS,'enhanced-geometry'), **args)
  78. def Equation(**args):
  79. return Element(qname = (DRAWNS,'equation'), **args)
  80. def FillImage(**args):
  81. args.setdefault('type', 'simple')
  82. return DrawElement(qname = (DRAWNS,'fill-image'), **args)
  83. def FloatingFrame(**args):
  84. args.setdefault('type', 'simple')
  85. return Element(qname = (DRAWNS,'floating-frame'), **args)
  86. def Frame(**args):
  87. return StyleRefElement(qname = (DRAWNS,'frame'), **args)
  88. def G(**args):
  89. return StyleRefElement(qname = (DRAWNS,'g'), **args)
  90. def GluePoint(**args):
  91. return Element(qname = (DRAWNS,'glue-point'), **args)
  92. def Gradient(**args):
  93. return DrawElement(qname = (DRAWNS,'gradient'), **args)
  94. def Handle(**args):
  95. return Element(qname = (DRAWNS,'handle'), **args)
  96. def Hatch(**args):
  97. return DrawElement(qname = (DRAWNS,'hatch'), **args)
  98. def Image(**args):
  99. return Element(qname = (DRAWNS,'image'), **args)
  100. def ImageMap(**args):
  101. return Element(qname = (DRAWNS,'image-map'), **args)
  102. def Layer(**args):
  103. return Element(qname = (DRAWNS,'layer'), **args)
  104. def LayerSet(**args):
  105. return Element(qname = (DRAWNS,'layer-set'), **args)
  106. def Line(**args):
  107. return StyleRefElement(qname = (DRAWNS,'line'), **args)
  108. def Marker(**args):
  109. return DrawElement(qname = (DRAWNS,'marker'), **args)
  110. def Measure(**args):
  111. return StyleRefElement(qname = (DRAWNS,'measure'), **args)
  112. def Object(**args):
  113. return Element(qname = (DRAWNS,'object'), **args)
  114. def ObjectOle(**args):
  115. return Element(qname = (DRAWNS,'object-ole'), **args)
  116. def Opacity(**args):
  117. return DrawElement(qname = (DRAWNS,'opacity'), **args)
  118. def Page(**args):
  119. return Element(qname = (DRAWNS,'page'), **args)
  120. def PageThumbnail(**args):
  121. return StyleRefElement(qname = (DRAWNS,'page-thumbnail'), **args)
  122. def Param(**args):
  123. return Element(qname = (DRAWNS,'param'), **args)
  124. def Path(**args):
  125. return StyleRefElement(qname = (DRAWNS,'path'), **args)
  126. def Plugin(**args):
  127. args.setdefault('type', 'simple')
  128. return Element(qname = (DRAWNS,'plugin'), **args)
  129. def Polygon(**args):
  130. return StyleRefElement(qname = (DRAWNS,'polygon'), **args)
  131. def Polyline(**args):
  132. return StyleRefElement(qname = (DRAWNS,'polyline'), **args)
  133. def Rect(**args):
  134. return StyleRefElement(qname = (DRAWNS,'rect'), **args)
  135. def RegularPolygon(**args):
  136. return StyleRefElement(qname = (DRAWNS,'regular-polygon'), **args)
  137. def StrokeDash(**args):
  138. return DrawElement(qname = (DRAWNS,'stroke-dash'), **args)
  139. def TextBox(**args):
  140. return Element(qname = (DRAWNS,'text-box'), **args)