Exemplo n.º 1
0
 def visit_image(self, node):
     self.body.append(
         self.starttag(node,
                       'div',
                       '',
                       CLASS='figure %s' % ' '.join(node['classes'])))
     HTMLTranslator.visit_image(self, node)
 def visit_image(self, node):
     olduri = node['uri']
     s = olduri.lower()
     go = True
     go = go and not Image is None
     go = go and not (s.endswith('svg') or
                      s.endswith('svgz') or
                      s.endswith('swf'))
     go = go and not (node.has_key('width') or
                      node.has_key('height') or
                      node.has_key('scale'))
     if go and node.has_key('classes'):
         go = go and not 'screenshot-detail' in node['classes']
     if go:
         # Try to figure out image height and width.  Docutils does that too,
         # but it tries the final file name, which does not necessarily exist
         # yet at the time the HTML file is written.
         try:
             im = Image.open(os.path.join(self.builder.srcdir, olduri))
         except (IOError, # Source image can't be found or opened
                 UnicodeError):  # PIL doesn't like Unicode paths.
             go = False # better warn?
         else:
             im_width = str(im.size[0])
             im_height = str(im.size[1])
             del im
     if go:
         # rewrite the URI if the environment knows about it
         if olduri in self.builder.images:
             node['uri'] = posixpath.join(self.builder.imgpath,
                                          self.builder.images[olduri])
         atts = {}
         atts['src'] = node['uri']
         if not node.has_key('classes'):
             node['classes'] = ['img-scaling']
         elif not 'img-scaling' in node['classes']:
             node['classes'].append('img-scaling')
         else:
             pass
         atts['style'] = 'max-width: %spx;' % im_width
         if node.has_key('alt'):
             atts['alt'] = node['alt']
         else:
             atts['alt'] = node['uri']
         if node.has_key('align'):
             self.body.append('<div align="%s" class="align-%s">' %
                              (node['align'], node['align']))
             self.context.append('</div>\n')
         else:
             self.context.append('')
         self.body.append(self.emptytag(node, 'img', '', **atts))
     else:
         del s, go
         HTMLTranslator.visit_image(self,node)
     return
Exemplo n.º 3
0
 def visit_image(self, node):
     olduri = node['uri']
     import pdb;pdb.set_trace()
     # rewrite the URI if the environment knows about it
     # if olduri in self.builder.images:
     #     node['uri'] = posixpath.join(self.builder.imgpath,
     #                                  self.builder.images[olduri])
     #                                  #import pdb; pdb.set_trace()
     print "IMAGE!!!", node, node['uri'], path.abspath(node['uri'])
     if path.abspath(olduri) != olduri:
         pass
         # # relative
         # dest = path.join(self.builder.outdir,olduri)
         # print "COPYING TO", dest
         # olduri = path.join(path.dirname(self.doc_path),
         #                    dest)
     self._images.add(path.abspath(olduri))
     self.builder.ebook.add_image(path.abspath(olduri), olduri, id='image_{0}'.format(len(self._images)))
     HTMLTranslator.visit_image(self, node)
Exemplo n.º 4
0
 def visit_image(self, node):
     print "IMAGE!!!", node, node['uri'], path.abspath(node['uri'])
     self._images.add(path.abspath(node['uri']))
     print "images", self._images
     HTMLTranslator.visit_image(self, node)