示例#1
0
            def styles(keys):
                def clr_grad(color):
                    if color.startswith('rgba('):
                        r, g, b, a = rgba(color)
                        return '%d' % int(a * 100000)
                    elif 'opacity' in keys:
                        return '%d' % int(float(e.get('opacity')) * 100000)
                    else:
                        return '%d' % 100000

                # TODO: Optimize
                if 'fill' in keys:
                    if e.get('fill') == 'none':
                        shape.spPr.append(a.noFill())
                    else:
                        shape.spPr.append(
                            a.solidFill(
                                a.srgbClr(
                                    a.alpha(val=str(clr_grad(e.get('fill')))),
                                    val=str(msclr(e.get('fill'))))))
                elif not 'fill' in keys:
                    if tag not in ['line']:
                        shape.spPr.append(a.solidFill(color(srgbClr='000000')))

                if 'stroke' in keys and 'stroke-width' in keys:
                    shape.spPr.append(
                        a.ln(a.solidFill(
                            a.srgbClr(
                                a.alpha(val=str(clr_grad(e.get('stroke')))),
                                val=str(msclr(e.get('stroke'))))),
                             w=str(
                                 int(
                                     float(interpret_str(
                                         e.get('stroke-width'))) * 12700))))
                elif 'stroke' in keys:
                    if e.get('stroke') == 'none':
                        shape.spPr.append(a.ln(a.noFill()))
                    else:
                        shape.spPr.append(
                            a.ln(
                                a.solidFill(
                                    a.srgbClr(a.alpha(
                                        val=str(clr_grad(e.get('stroke')))),
                                              val=str(msclr(
                                                  e.get('stroke')))))))
                elif 'stroke' and 'fill' not in keys:
                    shape.spPr.append(
                        a.ln(a.solidFill(color(srgbClr='000000'))))
                elif not 'stroke' and 'fill' in keys:
                    if tag in ['rect']:
                        shape.spPr.append(a.ln(a.noFill()))
                    elif tag in ['circle', 'ellipse']:
                        shape.spPr.append(
                            a.ln(
                                a.solidFill(
                                    color(srgbClr=msclr(e.get('fill'))))))
                    elif tag in ['path', 'line']:
                        shape.spPr.append(
                            a.ln(a.solidFill(color(srgbClr='000000'))))
                return shape
示例#2
0
        def text_style(keys, txt):

            bold = '1' if 'font-weight' in keys else '0'

            fill_text_ml = a.solidFill(
                color(srgbClr=msclr(
                    e.get('fill') if 'fill' in keys else 'black')))

            autofit_ml = a.normAutofit(fontScale="62500",
                                       lnSpcReduction="20000")  # Auto fit

            font_size = str(int(
                float(interpret_str(e.get('font-size'))) *
                100)) if 'font-size' in keys else '1600'

            shp.append(
                p.txBody(
                    a.bodyPr(anchor=txt_anchor(), wrap='none'),
                    a.p(
                        a.pPr(algn=txt_align()),
                        a.r(
                            a.rPr(fill_text_ml,
                                  lang='en-US',
                                  sz=font_size,
                                  b=bold,
                                  dirty='0',
                                  smtClean='0'), a.t(txt)))))

            return shp
示例#3
0
            def styles(keys):
                def clr_grad(color):
                    if color.startswith('rgba('):
                        r, g, b, a = rgba(color)
                        return  '%d' % int(a*100000)
                    elif 'opacity' in keys:
                        return '%d' % int(float(e.get('opacity')) * 100000)
                    else:
                        return '%d' % 100000


                # TODO: Optimize
                if 'fill' in keys:
                    if e.get('fill') == 'none':
                        shape.spPr.append(a.noFill())
                    else:
                        shape.spPr.append(a.solidFill(a.srgbClr(a.alpha(val=str(clr_grad(e.get('fill')))),
                            val=str(msclr(e.get('fill'))))))
                elif not 'fill' in keys:
                    if tag not in ['line']:
                        shape.spPr.append(a.solidFill(color(srgbClr='000000')))

                if 'stroke' in keys and 'stroke-width' in keys:
                    shape.spPr.append(a.ln(a.solidFill(a.srgbClr(a.alpha(val=str(clr_grad(e.get('stroke')))),
                        val=str(msclr(e.get('stroke'))))),
                        w=str(int(float(interpret_str(e.get('stroke-width')))*12700))))
                elif 'stroke' in keys:
                    if e.get('stroke') == 'none':
                        shape.spPr.append(a.ln(a.noFill()))
                    else:
                        shape.spPr.append(a.ln(a.solidFill(a.srgbClr(a.alpha(val=str(clr_grad(e.get('stroke')))), val=str(msclr(e.get('stroke')))))))
                elif 'stroke' and 'fill' not in keys:
                    shape.spPr.append(a.ln(a.solidFill(color(srgbClr='000000'))))
                elif not 'stroke' and 'fill' in keys:
                    if tag in ['rect']:
                        shape.spPr.append(a.ln(a.noFill()))
                    elif tag in ['circle','ellipse']:
                        shape.spPr.append(a.ln(a.solidFill(color(srgbClr=msclr(e.get('fill'))))))
                    elif tag in ['path', 'line']:
                        shape.spPr.append(a.ln(a.solidFill(color(srgbClr='000000'))))
                return shape
示例#4
0
        def text_style(keys, txt):

            bold = '1' if 'font-weight' in keys else '0'

            fill_text_ml = a.solidFill(color(srgbClr=msclr(e.get('fill') if 'fill' in keys else 'black')))

            autofit_ml = a.normAutofit(fontScale="62500", lnSpcReduction="20000")    # Auto fit

            font_size = str(int(float(interpret_str(e.get('font-size')))*100)) if 'font-size' in keys else '1600'


            shp.append(p.txBody(a.bodyPr(anchor=txt_anchor(), wrap='none'),
            a.p(a.pPr(algn=txt_align()), a.r(a.rPr(fill_text_ml, lang='en-US', sz=font_size, b=bold, dirty='0', smtClean='0'),
                    a.t(txt)))))

            return shp
示例#5
0
from pptx import Presentation
from pypptx import nsmap, a, p, shape, color

prs = Presentation()
slide = prs.slides.add_slide(prs.slidelayouts[6])
shapes = slide._element.find('.//p:spTree', namespaces=nsmap)

shp = shape('ellipse', 0, 0, 999999, 999999)
shapes.append(shp)

# Fill with a scheme colour
shp.spPr.append(a.solidFill(color(
    schemeClr='accent2',  # 2nd theme colour
    tint='50%',           # 50% white mixed
    alpha='30%'           # 30% opaque, 70% transparent
)))

shp = shape('ellipse', 999999, 0, 999999, 999999)
shapes.append(shp)

# Fill with an RGB colour
shp.spPr.append(a.solidFill(color(
    srgbClr='FF0000',     # Red
    shade='50%',          # 50% black mixed
    sat='30%'             # 30% saturation
)))

shp = shape('ellipse', 0, 999999, 999999, 999999)
shapes.append(shp)

# Fill with an RGB colour
示例#6
0
文件: sample.py 项目: gramener/pypptx
from pptx import Presentation
from pypptx import nsmap, a, p, shape, color

prs = Presentation()
slide = prs.slides.add_slide(prs.slidelayouts[6])
shapes = slide._element.find('.//p:spTree', namespaces=nsmap)

shp = shape('ellipse', 0, 0, 999999, 999999)
shapes.append(shp)

# Fill with a scheme colour
shp.spPr.append(
    a.solidFill(
        color(
            schemeClr='accent2',  # 2nd theme colour
            tint='50%',  # 50% white mixed
            alpha='30%'  # 30% opaque, 70% transparent
        )))

shp = shape('ellipse', 999999, 0, 999999, 999999)
shapes.append(shp)

# Fill with an RGB colour
shp.spPr.append(
    a.solidFill(
        color(
            srgbClr='FF0000',  # Red
            shade='50%',  # 50% black mixed
            sat='30%'  # 30% saturation
        )))