예제 #1
0
    def text(self, e):
        keys = e.keys()
        values = e.values()
        txt = e.text
        def txt_anchor():
            anchor_dict = {'hanging':'t', 'middle':'ctr', True:'t', False:'ctr', 'left':'ctr'}
            if 'dominant-baseline' in keys:
                anchor = anchor_dict[e.get('dominant-baseline')]
            elif 'dy' in keys:
                em = float(re.findall(".\d+", e.get('dy'))[0]) > 0.5
                anchor = anchor_dict[em]
            # elif 'text-anchor' in keys:
            #     anchor = anchor_dict[e.get('text-anchor')]
            else:
                anchor = 'ctr'
            return anchor

        def txt_align():
            if 'text-anchor' in keys:
                align_dict = {'end':'r', 'middle':'ctr', 'start':'l', 'left':'l'}
                align = align_dict[e.get('text-anchor')]
            else:
                align = 'l'
            return align

        if not e.text:
            return
        ax, ay = translate(e)
        x = float(interpret_str(e.get('x', 0))) + float(ax)
        y = float(interpret_str(e.get('y', 0))) + float(ay)
        shp = shape('rect', self.x(x), self.y(y), self.x(0), self.y(0))
        if 'transform' in keys:
            t_key = e.get('transform')
            rotate = str(int(t_key[(t_key.find('rotate')+7):-1].split()[0])*60000)
            shp.find('.//a:xfrm', namespaces=nsmap).set('rot', rotate)
        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

        e = tag_attrs(keys, values, e)
        keys = e.keys()
        text_style(keys, txt)

        self.shapes.append(shp)
        return shp
예제 #2
0
 def circle(self, e):
     ax, ay = translate(e)
     x = float(e.get('cx', 0)) + float(ax)
     y = float(e.get('cy', 0)) + float(ay)
     r = float(e.get('r', 0))
     shp = shape('ellipse', self.x(x - r), self.y(y - r),
                            self.x(2 * r), self.y(2 * r))
     self.shapes.append(shp)
     return shp
예제 #3
0
파일: svg2pptx.py 프로젝트: gramener/pypptx
 def circle(self, e):
     ax, ay = translate(e)
     x = float(e.get('cx', 0)) + float(ax)
     y = float(e.get('cy', 0)) + float(ay)
     r = float(e.get('r', 0))
     shp = shape('ellipse', self.x(x - r), self.y(y - r), self.x(2 * r),
                 self.y(2 * r))
     self.shapes.append(shp)
     return shp
예제 #4
0
 def ellipse(self, e):
     ax, ay = translate(e)
     x = float(e.get('cx', 0)) + float(ax)
     y = float(e.get('cy', 0)) + float(ay)
     rx = float(e.get('rx', 0))
     ry = float(e.get('ry', 0))
     shp = shape('ellipse', self.x(x - rx), self.y(y - ry),
                            self.x(2 * rx), self.y(2 * ry))
     self.shapes.append(shp)
     return shp
예제 #5
0
파일: svg2pptx.py 프로젝트: gramener/pypptx
 def ellipse(self, e):
     ax, ay = translate(e)
     x = float(e.get('cx', 0)) + float(ax)
     y = float(e.get('cy', 0)) + float(ay)
     rx = float(e.get('rx', 0))
     ry = float(e.get('ry', 0))
     shp = shape('ellipse', self.x(x - rx), self.y(y - ry), self.x(2 * rx),
                 self.y(2 * ry))
     self.shapes.append(shp)
     return shp
예제 #6
0
파일: svg2pptx.py 프로젝트: gramener/pypptx
 def rect(self, e):
     ax, ay = translate(e)
     x = float(interpret_str(e.get('x', 0))) + float(ax)
     y = float(interpret_str(e.get('y', 0))) + float(ay)
     keys = e.keys()
     shp_name = 'roundRect' if 'rx' in keys and 'ry' in keys else 'rect'
     shp = shape(shp_name, self.x(x), self.y(y),
                 self.x(interpret_str(e.get('width', 0))),
                 self.y(interpret_str(e.get('height', 0))))
     self.shapes.append(shp)
     return shp
예제 #7
0
 def line(self, e):
     ax, ay = translate(e)
     x1 = self.x(float(interpret_str(e.get('x1', 0))) + float(ax))
     y1 = self.y(float(interpret_str(e.get('y1', 0))) + float(ay))
     x2 = self.x(float(interpret_str(e.get('x2', 0))) + float(ax))
     y2 = self.y(float(interpret_str(e.get('y2', 0))) + float(ay))
     ax1 = x1 if x2 > x1 else x2
     ax2 = x2 if x1 < x2 else x1
     ay1 = y1 if y2 > y1 else y2
     ay2 = y2 if y1 < y2 else y1
     shp = shape('line', ax1, ay1, ax2-ax1, ay2-ay1)
     self.shapes.append(shp)
     return shp
예제 #8
0
파일: svg2pptx.py 프로젝트: gramener/pypptx
 def line(self, e):
     ax, ay = translate(e)
     x1 = self.x(float(interpret_str(e.get('x1', 0))) + float(ax))
     y1 = self.y(float(interpret_str(e.get('y1', 0))) + float(ay))
     x2 = self.x(float(interpret_str(e.get('x2', 0))) + float(ax))
     y2 = self.y(float(interpret_str(e.get('y2', 0))) + float(ay))
     ax1 = x1 if x2 > x1 else x2
     ax2 = x2 if x1 < x2 else x1
     ay1 = y1 if y2 > y1 else y2
     ay2 = y2 if y1 < y2 else y1
     shp = shape('line', ax1, ay1, ax2 - ax1, ay2 - ay1)
     self.shapes.append(shp)
     return shp
예제 #9
0
 def rect(self, e):
     ax, ay = translate(e)
     x = float(interpret_str(e.get('x', 0))) + float(ax)
     y = float(interpret_str(e.get('y', 0))) + float(ay)
     keys = e.keys()
     shp_name = 'roundRect' if 'rx' in keys and 'ry' in keys else 'rect'
     shp = shape(shp_name,
         self.x(x),
         self.y(y),
         self.x(interpret_str(e.get('width', 0))),
         self.y(interpret_str(e.get('height', 0)))
     )
     self.shapes.append(shp)
     return shp
예제 #10
0
파일: svg2pptx.py 프로젝트: gramener/pypptx
    def text(self, e):
        keys = e.keys()
        values = e.values()
        txt = e.text

        def txt_anchor():
            anchor_dict = {
                'hanging': 't',
                'middle': 'ctr',
                True: 't',
                False: 'ctr',
                'left': 'ctr'
            }
            if 'dominant-baseline' in keys:
                anchor = anchor_dict[e.get('dominant-baseline')]
            elif 'dy' in keys:
                em = float(re.findall(".\d+", e.get('dy'))[0]) > 0.5
                anchor = anchor_dict[em]
            # elif 'text-anchor' in keys:
            #     anchor = anchor_dict[e.get('text-anchor')]
            else:
                anchor = 'ctr'
            return anchor

        def txt_align():
            if 'text-anchor' in keys:
                align_dict = {
                    'end': 'r',
                    'middle': 'ctr',
                    'start': 'l',
                    'left': 'l'
                }
                align = align_dict[e.get('text-anchor')]
            else:
                align = 'l'
            return align

        if not e.text:
            return
        ax, ay = translate(e)
        x = float(interpret_str(e.get('x', 0))) + float(ax)
        y = float(interpret_str(e.get('y', 0))) + float(ay)
        shp = shape('rect', self.x(x), self.y(y), self.x(0), self.y(0))
        if 'transform' in keys:
            t_key = e.get('transform')
            rotate = str(
                int(t_key[(t_key.find('rotate') + 7):-1].split()[0]) * 60000)
            shp.find('.//a:xfrm', namespaces=nsmap).set('rot', rotate)

        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

        e = tag_attrs(keys, values, e)
        keys = e.keys()
        text_style(keys, txt)

        self.shapes.append(shp)
        return shp
예제 #11
0
파일: sample.py 프로젝트: Rahuketu86/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
)))

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

# Fill with an RGB colour
예제 #12
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
        )))