mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #6985 from tk0miya/6696_scale_not_working_for_SVG
Fix #6696: html: scale option of image/figure directive not working for SVG
This commit is contained in:
commit
2f7823e1a6
2
CHANGES
2
CHANGES
@ -30,6 +30,8 @@ Features added
|
|||||||
down the build
|
down the build
|
||||||
* #6837: LaTeX: Support a nested table
|
* #6837: LaTeX: Support a nested table
|
||||||
* #6966: graphviz: Support ``:class:`` option
|
* #6966: graphviz: Support ``:class:`` option
|
||||||
|
* #6696: html: ``:scale:`` option of image/figure directive not working for SVG
|
||||||
|
images (imagesize-1.2.0 or above is required)
|
||||||
|
|
||||||
Bugs fixed
|
Bugs fixed
|
||||||
----------
|
----------
|
||||||
|
@ -579,23 +579,6 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
node['uri'] = posixpath.join(self.builder.imgpath,
|
node['uri'] = posixpath.join(self.builder.imgpath,
|
||||||
self.builder.images[olduri])
|
self.builder.images[olduri])
|
||||||
|
|
||||||
uri = node['uri']
|
|
||||||
if uri.lower().endswith(('svg', 'svgz')):
|
|
||||||
atts = {'src': uri}
|
|
||||||
if 'width' in node:
|
|
||||||
atts['width'] = node['width']
|
|
||||||
if 'height' in node:
|
|
||||||
atts['height'] = node['height']
|
|
||||||
atts['alt'] = node.get('alt', uri)
|
|
||||||
if 'align' in node:
|
|
||||||
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))
|
|
||||||
return
|
|
||||||
|
|
||||||
if 'scale' in node:
|
if 'scale' in node:
|
||||||
# Try to figure out image height and width. Docutils does that too,
|
# Try to figure out image height and width. Docutils does that too,
|
||||||
# but it tries the final file name, which does not necessarily exist
|
# but it tries the final file name, which does not necessarily exist
|
||||||
@ -610,6 +593,30 @@ class HTMLTranslator(SphinxTranslator, BaseTranslator):
|
|||||||
node['width'] = str(size[0])
|
node['width'] = str(size[0])
|
||||||
if 'height' not in node:
|
if 'height' not in node:
|
||||||
node['height'] = str(size[1])
|
node['height'] = str(size[1])
|
||||||
|
|
||||||
|
uri = node['uri']
|
||||||
|
if uri.lower().endswith(('svg', 'svgz')):
|
||||||
|
atts = {'src': uri}
|
||||||
|
if 'width' in node:
|
||||||
|
atts['width'] = node['width']
|
||||||
|
if 'height' in node:
|
||||||
|
atts['height'] = node['height']
|
||||||
|
if 'scale' in node:
|
||||||
|
scale = node['scale'] / 100.0
|
||||||
|
if 'width' in atts:
|
||||||
|
atts['width'] = int(atts['width']) * scale
|
||||||
|
if 'height' in atts:
|
||||||
|
atts['height'] = int(atts['height']) * scale
|
||||||
|
atts['alt'] = node.get('alt', uri)
|
||||||
|
if 'align' in node:
|
||||||
|
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))
|
||||||
|
return
|
||||||
|
|
||||||
super().visit_image(node)
|
super().visit_image(node)
|
||||||
|
|
||||||
# overwritten
|
# overwritten
|
||||||
|
@ -520,23 +520,6 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
|||||||
node['uri'] = posixpath.join(self.builder.imgpath,
|
node['uri'] = posixpath.join(self.builder.imgpath,
|
||||||
self.builder.images[olduri])
|
self.builder.images[olduri])
|
||||||
|
|
||||||
uri = node['uri']
|
|
||||||
if uri.lower().endswith(('svg', 'svgz')):
|
|
||||||
atts = {'src': uri}
|
|
||||||
if 'width' in node:
|
|
||||||
atts['width'] = node['width']
|
|
||||||
if 'height' in node:
|
|
||||||
atts['height'] = node['height']
|
|
||||||
atts['alt'] = node.get('alt', uri)
|
|
||||||
if 'align' in node:
|
|
||||||
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))
|
|
||||||
return
|
|
||||||
|
|
||||||
if 'scale' in node:
|
if 'scale' in node:
|
||||||
# Try to figure out image height and width. Docutils does that too,
|
# Try to figure out image height and width. Docutils does that too,
|
||||||
# but it tries the final file name, which does not necessarily exist
|
# but it tries the final file name, which does not necessarily exist
|
||||||
@ -551,6 +534,30 @@ class HTML5Translator(SphinxTranslator, BaseTranslator):
|
|||||||
node['width'] = str(size[0])
|
node['width'] = str(size[0])
|
||||||
if 'height' not in node:
|
if 'height' not in node:
|
||||||
node['height'] = str(size[1])
|
node['height'] = str(size[1])
|
||||||
|
|
||||||
|
uri = node['uri']
|
||||||
|
if uri.lower().endswith(('svg', 'svgz')):
|
||||||
|
atts = {'src': uri}
|
||||||
|
if 'width' in node:
|
||||||
|
atts['width'] = node['width']
|
||||||
|
if 'height' in node:
|
||||||
|
atts['height'] = node['height']
|
||||||
|
if 'scale' in node:
|
||||||
|
scale = node['scale'] / 100.0
|
||||||
|
if 'width' in atts:
|
||||||
|
atts['width'] = int(atts['width']) * scale
|
||||||
|
if 'height' in atts:
|
||||||
|
atts['height'] = int(atts['height']) * scale
|
||||||
|
atts['alt'] = node.get('alt', uri)
|
||||||
|
if 'align' in node:
|
||||||
|
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))
|
||||||
|
return
|
||||||
|
|
||||||
super().visit_image(node)
|
super().visit_image(node)
|
||||||
|
|
||||||
# overwritten
|
# overwritten
|
||||||
|
Loading…
Reference in New Issue
Block a user