# -*- coding:utf-8 -*-
from random import randint

def make_shape_fun(text, x, y, boder_size, width, height, font_color, fill_color, font_size, boder_color, chinese_font, english_font, dash,
                   shape_type='rect',rotate_angle=0,behindDoc=0):
    """
    rotate_angle:角度,顺时针30,60,90等
    behindDoc为0浮于文字上方,为1浮于文字下方"""
    if x > 600: x = 600
    if y > 800: y = 800
    font_size = font_size * 2
    boder_size = boder_size * 12700 
    dash_elem = '<a:prstDash val="dash"/>' if dash else ''

    idid = randint(1, 99999)
    x, y, width, height = x * 10000, y * 10000, width * 10000, height * 10000

    if fill_color:
        filled = f"""<a:solidFill><a:srgbClr val="{fill_color}"/></a:solidFill>"""
        nofilled = ''
    else:
        filled = ''
        nofilled = """<a:noFill/>"""

    if boder_color:
        boder = f"""<a:lnRef idx="2"><a:srgbClr val="{boder_color}"/></a:lnRef>"""
        noboder = f"""<a:ln w="{boder_size}"><a:srgbClr val="{boder_color}"/>{dash_elem}</a:ln>"""
    else:
       
       
       
        boder = """<a:lnRef idx="2"><a:noFill/></a:lnRef>"""
        noboder = """<a:ln w="12700"><a:noFill/></a:ln>"""

    if not text:
        text = f'<w:t> </w:t>'
    else:
        text = f'<w:t>{text}</w:t>'

    if shape_type != 'line':
        insert_text_xml = f"""
<wps:txbx>
    <w:txbxContent>
        <w:p w:rsidR="00305AED" w:rsidRDefault="00305AED" w:rsidP="00305AED">
            <w:pPr>
                <w:jc w:val="center"/>
                <w:rPr>
                    <w:color w:val="ff0000" w:themeColor="text1"/>
                    <w:sz w:val="32"/>
                </w:rPr>
            </w:pPr>
            <w:r>
                <w:rPr>
                    <w:rFonts w:ascii="{english_font}" w:eastAsia="{chinese_font}" w:hAnsi="{english_font}" w:hint="eastAsia"/>
                    <w:color w:val="{font_color}"/>
                    <w:sz w:val="{font_size}"/>
                </w:rPr>
                {text}
            </w:r>
        </w:p>
    </w:txbxContent>
</wps:txbx>"""
    else:
        insert_text_xml = ''

   
    shape_geom_map = {
        'rect': '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>',
        'circle': '<a:prstGeom prst="ellipse"><a:avLst/></a:prstGeom>',
        'triangle': '<a:prstGeom prst="triangle"><a:avLst/></a:prstGeom>',
        'diamond': '<a:prstGeom prst="diamond"><a:avLst/></a:prstGeom>',
        'pie': '<a:prstGeom prst="pie"><a:avLst/></a:prstGeom>',
        'heart': '<a:prstGeom prst="heart"><a:avLst/></a:prstGeom>',
        'star': '<a:prstGeom prst="star"><a:avLst/></a:prstGeom>',
        'polygon': '<a:prstGeom prst="polygon"><a:avLst/></a:prstGeom>',
        'line': '<a:prstGeom prst="line"><a:avLst/></a:prstGeom>',
        'smileyFace': '<a:prstGeom prst="smileyFace"><a:avLst/></a:prstGeom>',
        'moon': '<a:prstGeom prst="moon"><a:avLst/></a:prstGeom>',
        'cloud': '<a:prstGeom prst="cloud"><a:avLst/></a:prstGeom>',
        'bevel': '<a:prstGeom prst="bevel"><a:avLst/></a:prstGeom>',
        'invertedTriangle': '<a:prstGeom prst="invertedTriangle"><a:avLst/></a:prstGeom>',
        'arc': '<a:prstGeom prst="arc"><a:avLst/></a:prstGeom>',
    }

   
    shape_geom = shape_geom_map.get(shape_type, '<a:prstGeom prst="rect"><a:avLst/></a:prstGeom>')

    r = f"""<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas"
            xmlns:cx="http://schemas.microsoft.com/office/drawing/2014/chartex"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:o="urn:schemas-microsoft-com:office:office"
            xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
            xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math"
            xmlns:v="urn:schemas-microsoft-com:vml"
            xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing"
            xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"
            xmlns:w10="urn:schemas-microsoft-com:office:word"
            xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"
            xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml"
            xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml"
            xmlns:w16se="http://schemas.microsoft.com/office/word/2015/wordml/symex"
            xmlns:wpg="http://schemas.microsoft.com/office/word/2010/wordprocessingGroup"
            xmlns:wpi="http://schemas.microsoft.com/office/word/2010/wordprocessingInk"
            xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml"
            xmlns:wps="http://schemas.microsoft.com/office/word/2010/wordprocessingShape"
            mc:Ignorable="w14 w15 w16se wp14">
	<w:body>
		<w:p w:rsidR="00943687"
		     w:rsidRDefault="00305AED">
			<w:bookmarkStart w:id="0"
			                 w:name="_GoBack"/>
			<w:bookmarkEnd w:id="0"/>
			<w:r>
				<w:rPr>
					<w:noProof/>
				</w:rPr>
				<mc:AlternateContent>
					<mc:Choice Requires="wps">
						<w:drawing>
							<wp:anchor distT="0"
							           distB="0"
							           distL="114300"
							           distR="114300"
							           simplePos="0"
							           relativeHeight="251659264"
							           behindDoc="{behindDoc}"
							           locked="0"
							           layoutInCell="1"
							           allowOverlap="1">
								<wp:simplePos x="0"
								              y="0"/>
								<wp:positionH relativeFrom="column">
									<wp:posOffset>{x}</wp:posOffset>
								</wp:positionH>
								<wp:positionV relativeFrom="paragraph">
									<wp:posOffset>{y}</wp:posOffset>
								</wp:positionV>
								<wp:extent cx="{width}"
								           cy="{height}"/>
								<wp:effectExtent l="0"
								                 t="0"
								                 r="13335"
								                 b="14605"/>
								<wp:wrapNone/>
								<wp:docPr id="{idid}"
								          name="形状 {idid}"/>
								<wp:cNvGraphicFramePr/>
								<a:graphic xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main">
									<a:graphicData uri="http://schemas.microsoft.com/office/word/2010/wordprocessingShape">
										<wps:wsp>
											<wps:cNvSpPr/>
											<wps:spPr>
												<a:xfrm rot="{60000*rotate_angle}">
													<a:off x="0"
													       y="0"/>
													<a:ext cx="1777593"
													       cy="614477"/>
												</a:xfrm>
												{shape_geom}
												{filled}
												{nofilled}
												{noboder}
											</wps:spPr>
											<wps:style>
                                                {boder}
												<a:fillRef idx="1">
													<a:schemeClr val="accent1"/>
												</a:fillRef>
												<a:effectRef idx="0">
													<a:schemeClr val="accent1"/>
												</a:effectRef>
												<a:fontRef idx="minor">
													<a:schemeClr val="lt1"/>
												</a:fontRef>
											</wps:style>
											{insert_text_xml}
											<wps:bodyPr rot="0"
											            spcFirstLastPara="0"
											            vertOverflow="overflow"
											            horzOverflow="overflow"
											            vert="horz"
											            wrap="square"
											            lIns="91440"
											            tIns="45720"
											            rIns="91440"
											            bIns="45720"
											            numCol="1"
											            spcCol="0"
											            rtlCol="0"
											            fromWordArt="0"
											            anchor="ctr"
											            anchorCtr="0"
											            forceAA="0"
											            compatLnSpc="1">
												<a:prstTxWarp prst="textNoShape">
													<a:avLst/>
												</a:prstTxWarp>
												<a:noAutofit/>
											</wps:bodyPr>
										</wps:wsp>
									</a:graphicData>
								</a:graphic>
							</wp:anchor>
						</w:drawing>
					</mc:Choice>

				</mc:AlternateContent>
			</w:r>
		</w:p>
		<w:sectPr w:rsidR="00943687">
			<w:pgSz w:w="11906"
			        w:h="16838"/>
			<w:pgMar w:top="1440"
			         w:right="1800"
			         w:bottom="1440"
			         w:left="1800"
			         w:header="851"
			         w:footer="992"
			         w:gutter="0"/>
			<w:cols w:space="425"/>
			<w:docGrid w:type="lines"
			           w:linePitch="312"/>
		</w:sectPr>
	</w:body>
</w:document>"""
    return r