make_rectangle.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. # -*- coding:utf-8 -*-
  2. from random import randint
  3. def make_shape_fun(text, x, y, boder_size, width, height, font_color, fill_color, font_size, boder_color, chinese_font, english_font, dash,
  4. shape_type='rect',rotate_angle=0,behindDoc=0):
  5. """
  6. rotate_angle:角度,顺时针30,60,90等
  7. behindDoc为0浮于文字上方,为1浮于文字下方"""
  8. if x > 600: x = 600
  9. if y > 800: y = 800
  10. font_size = font_size * 2
  11. boder_size = boder_size * 12700
  12. dash_elem = '<a:prstDash val="dash"/>' if dash else ''
  13. idid = randint(1, 99999)
  14. x, y, width, height = x * 10000, y * 10000, width * 10000, height * 10000
  15. if fill_color:
  16. filled = f"""<a:solidFill><a:srgbClr val="{fill_color}"/></a:solidFill>"""
  17. nofilled = ''
  18. else:
  19. filled = ''
  20. nofilled = """<a:noFill/>"""
  21. if boder_color:
  22. boder = f"""<a:lnRef idx="2"><a:srgbClr val="{boder_color}"/></a:lnRef>"""
  23. noboder = f"""<a:ln w="{boder_size}"><a:srgbClr val="{boder_color}"/>{dash_elem}</a:ln>"""
  24. else:
  25. boder = """<a:lnRef idx="2"><a:noFill/></a:lnRef>"""
  26. noboder = """<a:ln w="12700"><a:noFill/></a:ln>"""
  27. if not text:
  28. text = f'<w:t> </w:t>'
  29. else:
  30. text = f'<w:t>{text}</w:t>'
  31. if shape_type != 'line':
  32. insert_text_xml = f"""
  33. <wps:txbx>
  34. <w:txbxContent>
  35. <w:p w:rsidR="00305AED" w:rsidRDefault="00305AED" w:rsidP="00305AED">
  36. <w:pPr>
  37. <w:jc w:val="center"/>
  38. <w:rPr>
  39. <w:color w:val="ff0000" w:themeColor="text1"/>
  40. <w:sz w:val="32"/>
  41. </w:rPr>
  42. </w:pPr>
  43. <w:r>
  44. <w:rPr>
  45. <w:rFonts w:ascii="{english_font}" w:eastAsia="{chinese_font}" w:hAnsi="{english_font}" w:hint="eastAsia"/>
  46. <w:color w:val="{font_color}"/>
  47. <w:sz w:val="{font_size}"/>
  48. </w:rPr>
  49. {text}
  50. </w:r>
  51. </w:p>
  52. </w:txbxContent>
  53. </wps:txbx>"""
  54. else:
  55. insert_text_xml = ''
  56. shape_geom_map = {
  57. 'rect': '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>',
  58. 'circle': '<a:prstGeom prst="ellipse"><a:avLst/></a:prstGeom>',
  59. 'triangle': '<a:prstGeom prst="triangle"><a:avLst/></a:prstGeom>',
  60. 'diamond': '<a:prstGeom prst="diamond"><a:avLst/></a:prstGeom>',
  61. 'pie': '<a:prstGeom prst="pie"><a:avLst/></a:prstGeom>',
  62. 'heart': '<a:prstGeom prst="heart"><a:avLst/></a:prstGeom>',
  63. 'star': '<a:prstGeom prst="star"><a:avLst/></a:prstGeom>',
  64. 'polygon': '<a:prstGeom prst="polygon"><a:avLst/></a:prstGeom>',
  65. 'line': '<a:prstGeom prst="line"><a:avLst/></a:prstGeom>',
  66. 'smileyFace': '<a:prstGeom prst="smileyFace"><a:avLst/></a:prstGeom>',
  67. 'moon': '<a:prstGeom prst="moon"><a:avLst/></a:prstGeom>',
  68. 'cloud': '<a:prstGeom prst="cloud"><a:avLst/></a:prstGeom>',
  69. 'bevel': '<a:prstGeom prst="bevel"><a:avLst/></a:prstGeom>',
  70. 'invertedTriangle': '<a:prstGeom prst="invertedTriangle"><a:avLst/></a:prstGeom>',
  71. 'arc': '<a:prstGeom prst="arc"><a:avLst/></a:prstGeom>',
  72. }
  73. shape_geom = shape_geom_map.get(shape_type, '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>')
  74. r = f"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  75. <w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
  76. xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
  77. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  78. xmlns:o="urn:schemas-microsoft-com:office:office"
  79. xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  80. xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
  81. xmlns:v="urn:schemas-microsoft-com:vml"
  82. xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
  83. xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
  84. xmlns:w10="urn:schemas-microsoft-com:office:word"
  85. xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
  86. xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
  87. xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
  88. xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex"
  89. xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
  90. xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
  91. xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
  92. xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
  93. mc:Ignorable="w14 w15 w16se wp14">
  94. <w:body>
  95. <w:p w:rsidR="00943687"
  96. w:rsidRDefault="00305AED">
  97. <w:bookmarkStart w:id="0"
  98. w:name="_GoBack"/>
  99. <w:bookmarkEnd w:id="0"/>
  100. <w:r>
  101. <w:rPr>
  102. <w:noProof/>
  103. </w:rPr>
  104. <mc:AlternateContent>
  105. <mc:Choice Requires="wps">
  106. <w:drawing>
  107. <wp:anchor distT="0"
  108. distB="0"
  109. distL="114300"
  110. distR="114300"
  111. simplePos="0"
  112. relativeHeight="251659264"
  113. behindDoc="{behindDoc}"
  114. locked="0"
  115. layoutInCell="1"
  116. allowOverlap="1">
  117. <wp:simplePos x="0"
  118. y="0"/>
  119. <wp:positionH relativeFrom="column">
  120. <wp:posOffset>{x}</wp:posOffset>
  121. </wp:positionH>
  122. <wp:positionV relativeFrom="paragraph">
  123. <wp:posOffset>{y}</wp:posOffset>
  124. </wp:positionV>
  125. <wp:extent cx="{width}"
  126. cy="{height}"/>
  127. <wp:effectExtent l="0"
  128. t="0"
  129. r="13335"
  130. b="14605"/>
  131. <wp:wrapNone/>
  132. <wp:docPr id="{idid}"
  133. name="形状 {idid}"/>
  134. <wp:cNvGraphicFramePr/>
  135. <a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
  136. <a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
  137. <wps:wsp>
  138. <wps:cNvSpPr/>
  139. <wps:spPr>
  140. <a:xfrm rot="{60000*rotate_angle}">
  141. <a:off x="0"
  142. y="0"/>
  143. <a:ext cx="1777593"
  144. cy="614477"/>
  145. </a:xfrm>
  146. {shape_geom}
  147. {filled}
  148. {nofilled}
  149. {noboder}
  150. </wps:spPr>
  151. <wps:style>
  152. {boder}
  153. <a:fillRef idx="1">
  154. <a:schemeClr val="accent1"/>
  155. </a:fillRef>
  156. <a:effectRef idx="0">
  157. <a:schemeClr val="accent1"/>
  158. </a:effectRef>
  159. <a:fontRef idx="minor">
  160. <a:schemeClr val="lt1"/>
  161. </a:fontRef>
  162. </wps:style>
  163. {insert_text_xml}
  164. <wps:bodyPr rot="0"
  165. spcFirstLastPara="0"
  166. vertOverflow="overflow"
  167. horzOverflow="overflow"
  168. vert="horz"
  169. wrap="square"
  170. lIns="91440"
  171. tIns="45720"
  172. rIns="91440"
  173. bIns="45720"
  174. numCol="1"
  175. spcCol="0"
  176. rtlCol="0"
  177. fromWordArt="0"
  178. anchor="ctr"
  179. anchorCtr="0"
  180. forceAA="0"
  181. compatLnSpc="1">
  182. <a:prstTxWarp prst="textNoShape">
  183. <a:avLst/>
  184. </a:prstTxWarp>
  185. <a:noAutofit/>
  186. </wps:bodyPr>
  187. </wps:wsp>
  188. </a:graphicData>
  189. </a:graphic>
  190. </wp:anchor>
  191. </w:drawing>
  192. </mc:Choice>
  193. </mc:AlternateContent>
  194. </w:r>
  195. </w:p>
  196. <w:sectPr w:rsidR="00943687">
  197. <w:pgSz w:w="11906"
  198. w:h="16838"/>
  199. <w:pgMar w:top="1440"
  200. w:right="1800"
  201. w:bottom="1440"
  202. w:left="1800"
  203. w:header="851"
  204. w:footer="992"
  205. w:gutter="0"/>
  206. <w:cols w:space="425"/>
  207. <w:docGrid w:type="lines"
  208. w:linePitch="312"/>
  209. </w:sectPr>
  210. </w:body>
  211. </w:document>"""
  212. return r