#38: fix behavior with unitless image dimensions.

This commit is contained in:
Georg Brandl 2008-11-16 19:07:36 +01:00
parent 22cefe2114
commit 49858b41f3
3 changed files with 15 additions and 7 deletions

View File

@ -159,6 +159,8 @@ New features added
Bugs fixed
----------
* Fix "illegal unit" error when using pixel image widths/heights.
* Support table captions in LaTeX output.
* Work around a bug in Jinja that caused "<generator ...>" to be

View File

@ -217,6 +217,11 @@ to the source file, and Sphinx will automatically copy image files over to a
subdirectory of the output directory on building (e.g. the ``_static`` directory
for HTML output.)
Interpretation of image size options (``width`` and ``height``) is as follows:
if the size has no unit or the unit is pixels, the given size will only be
respected for output channels that support pixels (i.e. not in LaTeX output).
Other units (like ``pt`` for points) will be used for HTML and LaTeX output.
Sphinx extends the standard docutils behavior by allowing an asterisk for the
extension::

View File

@ -716,9 +716,9 @@ class LaTeXTranslator(nodes.NodeVisitor):
return width_str
res = width_str
amount, unit = match.groups()[:2]
if unit == "px":
# LaTeX does not know pixels but points
res = "%spt" % amount
if not unit or unit == "px":
# pixels: let LaTeX alone
return None
elif unit == "%":
res = "%.3f\\linewidth" % (float(amount) / 100.0)
return res
@ -735,11 +735,12 @@ class LaTeXTranslator(nodes.NodeVisitor):
pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
post.append('}')
if attrs.has_key('width'):
include_graphics_options.append('width=%s' % (
self.latex_image_length(attrs['width']), ))
w = self.latex_image_length(attrs['width'])
if w:
include_graphics_options.append('width=%s' % w)
if attrs.has_key('height'):
include_graphics_options.append('height=%s' % (
self.latex_image_length(attrs['height']), ))
h = self.latex_image_length(attrs['height'])
include_graphics_options.append('height=%s' % h)
if attrs.has_key('align'):
align_prepost = {
# By default latex aligns the top of an image.