Пример #1
0
    def pict_to_html(self, pict, page):
        # First see if we have an <hr>
        is_hr = len(pict) == 1 and get(pict[0], 'o:hr') in {'t', 'true'}
        if is_hr:
            style = {}
            hr = HR()
            try:
                pct = float(get(pict[0], 'o:hrpct'))
            except (ValueError, TypeError, AttributeError):
                pass
            else:
                if pct > 0:
                    style['width'] = '%.3g%%' % pct
            align = get(pict[0], 'o:hralign', 'center')
            if align in {'left', 'right'}:
                style['margin-left'] = '0' if align == 'left' else 'auto'
                style['margin-right'] = 'auto' if align == 'left' else '0'
            if style:
                hr.set('style', '; '.join(('%s:%s' % (k, v) for k, v in style.iteritems())))
            yield hr

        for imagedata in XPath('descendant::v:imagedata[@r:id]')(pict):
            rid = get(imagedata, 'r:id')
            if rid in self.rid_map:
                try:
                    src = self.generate_filename(rid)
                except LinkedImageNotFound as err:
                    self.log.warn('Linked image: %s not found, ignoring' % err.fname)
                    continue
                img = IMG(src='images/%s' % src, style="display:block")
                alt = get(imagedata, 'o:title')
                img.set('alt', alt or 'Image')
                yield img
Пример #2
0
    def pic_to_img(self, pic, alt, parent):
        name = None
        link = None
        for hl in XPath('descendant::a:hlinkClick[@r:id]')(parent):
            link = {'id':get(hl, 'r:id')}
            tgt = hl.get('tgtFrame', None)
            if tgt:
                link['target'] = tgt
            title = hl.get('tooltip', None)
            if title:
                link['title'] = title

        for pr in XPath('descendant::pic:cNvPr')(pic):
            name = pr.get('name', None)
            if name:
                name = ascii_filename(name).replace(' ', '_')
            alt = pr.get('descr', None)
            for a in XPath('descendant::a:blip[@r:embed]')(pic):
                rid = get(a, 'r:embed')
                if rid in self.rid_map:
                    src = self.generate_filename(rid, name)
                    img = IMG(src='images/%s' % src)
                    img.set('alt', alt or 'Image')
                    if link is not None:
                        self.links.append((img, link))
                    return img
Пример #3
0
    def pic_to_img(self, pic, alt, parent):
        name = None
        link = None
        for hl in XPath('descendant::a:hlinkClick[@r:id]')(parent):
            link = {'id':get(hl, 'r:id')}
            tgt = hl.get('tgtFrame', None)
            if tgt:
                link['target'] = tgt
            title = hl.get('tooltip', None)
            if title:
                link['title'] = title

        for pr in XPath('descendant::pic:cNvPr')(pic):
            name = pr.get('name', None)
            if name:
                name = ascii_filename(name).replace(' ', '_')
            alt = pr.get('descr', None)
            for a in XPath('descendant::a:blip[@r:embed or @r:link]')(pic):
                rid = get(a, 'r:embed')
                if not rid:
                    rid = get(a, 'r:link')
                if rid and rid in self.rid_map:
                    try:
                        src = self.generate_filename(rid, name)
                    except LinkedImageNotFound as err:
                        self.log.warn('Linked image: %s not found, ignoring' % err.fname)
                        continue
                    img = IMG(src='images/%s' % src)
                    img.set('alt', alt or 'Image')
                    if link is not None:
                        self.links.append((img, link))
                    return img
Пример #4
0
    def pic_to_img(self, pic, alt, parent):
        XPath, get = self.namespace.XPath, self.namespace.get
        name = None
        link = None
        for hl in XPath("descendant::a:hlinkClick[@r:id]")(parent):
            link = {"id": get(hl, "r:id")}
            tgt = hl.get("tgtFrame", None)
            if tgt:
                link["target"] = tgt
            title = hl.get("tooltip", None)
            if title:
                link["title"] = title

        for pr in XPath("descendant::pic:cNvPr")(pic):
            name = pr.get("name", None)
            if name:
                name = ascii_filename(name).replace(" ", "_")
            alt = pr.get("descr", None)
            for a in XPath("descendant::a:blip[@r:embed or @r:link]")(pic):
                rid = get(a, "r:embed")
                if not rid:
                    rid = get(a, "r:link")
                if rid and rid in self.rid_map:
                    try:
                        src = self.generate_filename(rid, name)
                    except LinkedImageNotFound as err:
                        self.log.warn("Linked image: %s not found, ignoring" % err.fname)
                        continue
                    img = IMG(src="images/%s" % src)
                    img.set("alt", alt or "Image")
                    if link is not None:
                        self.links.append((img, link, self.rid_map))
                    return img
Пример #5
0
    def pict_to_html(self, pict, page):
        XPath, get = self.namespace.XPath, self.namespace.get
        # First see if we have an <hr>
        is_hr = len(pict) == 1 and get(pict[0], "o:hr") in {"t", "true"}
        if is_hr:
            style = {}
            hr = HR()
            try:
                pct = float(get(pict[0], "o:hrpct"))
            except (ValueError, TypeError, AttributeError):
                pass
            else:
                if pct > 0:
                    style["width"] = "%.3g%%" % pct
            align = get(pict[0], "o:hralign", "center")
            if align in {"left", "right"}:
                style["margin-left"] = "0" if align == "left" else "auto"
                style["margin-right"] = "auto" if align == "left" else "0"
            if style:
                hr.set("style", "; ".join(("%s:%s" % (k, v) for k, v in style.iteritems())))
            yield hr

        for imagedata in XPath("descendant::v:imagedata[@r:id]")(pict):
            rid = get(imagedata, "r:id")
            if rid in self.rid_map:
                try:
                    src = self.generate_filename(rid)
                except LinkedImageNotFound as err:
                    self.log.warn("Linked image: %s not found, ignoring" % err.fname)
                    continue
                img = IMG(src="images/%s" % src, style="display:block")
                alt = get(imagedata, "o:title")
                img.set("alt", alt or "Image")
                yield img
Пример #6
0
    def pic_to_img(self, pic, alt, parent):
        name = None
        link = None
        for hl in XPath('descendant::a:hlinkClick[@r:id]')(parent):
            link = {'id':get(hl, 'r:id')}
            tgt = hl.get('tgtFrame', None)
            if tgt:
                link['target'] = tgt
            title = hl.get('tooltip', None)
            if title:
                link['title'] = title

        for pr in XPath('descendant::pic:cNvPr')(pic):
            name = pr.get('name', None)
            if name:
                name = ascii_filename(name).replace(' ', '_')
            alt = pr.get('descr', None)
            for a in XPath('descendant::a:blip[@r:embed]')(pic):
                rid = get(a, 'r:embed')
                if rid in self.rid_map:
                    src = self.generate_filename(rid, name)
                    img = IMG(src='images/%s' % src)
                    img.set('alt', alt or 'Image')
                    if link is not None:
                        self.links.append((img, link))
                    return img
Пример #7
0
 def pict_to_html(self, pict, page):
     for imagedata in XPath('descendant::v:imagedata[@r:id]')(pict):
         rid = get(imagedata, 'r:id')
         if rid in self.rid_map:
             src = self.generate_filename(rid)
             img = IMG(src='images/%s' % src, style="display:block")
             alt = get(imagedata, 'o:title')
             if alt:
                 img.set('alt', alt)
             yield img
Пример #8
0
 def pict_to_html(self, pict, page):
     for imagedata in XPath('descendant::v:imagedata[@r:id]')(pict):
         rid = get(imagedata, 'r:id')
         if rid in self.rid_map:
             src = self.generate_filename(rid)
             img = IMG(src='images/%s' % src, style="display:block")
             alt = get(imagedata, 'o:title')
             if alt:
                 img.set('alt', alt)
             yield img
Пример #9
0
 def pic_to_img(self, pic, alt=None):
     name = None
     for pr in XPath('descendant::pic:cNvPr')(pic):
         name = pr.get('name', None)
         if name:
             name = ascii_filename(name).replace(' ', '_')
         alt = pr.get('descr', None)
         for a in XPath('descendant::a:blip[@r:embed]')(pic):
             rid = get(a, 'r:embed')
             if rid in self.rid_map:
                 src = self.generate_filename(rid, name)
                 img = IMG(src='images/%s' % src)
                 if alt:
                     img.set('alt', alt)
                 return img
Пример #10
0
 def pic_to_img(self, pic, alt=None):
     name = None
     for pr in XPath('descendant::pic:cNvPr')(pic):
         name = pr.get('name', None)
         if name:
             name = ascii_filename(name).replace(' ', '_')
         alt = pr.get('descr', None)
         for a in XPath('descendant::a:blip[@r:embed]')(pic):
             rid = get(a, 'r:embed')
             if rid in self.rid_map:
                 src = self.generate_filename(rid, name)
                 img = IMG(src='images/%s' % src)
                 if alt:
                     img.set('alt', alt)
                 return img