mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge branch '1.8'
Resolved Conflicts: sphinx/writers/latex.py
This commit is contained in:
commit
ff5031c96e
1
CHANGES
1
CHANGES
@ -218,6 +218,7 @@ Bugs fixed
|
|||||||
* #5936: LaTeX: PDF build broken by inclusion of image taller than page height
|
* #5936: LaTeX: PDF build broken by inclusion of image taller than page height
|
||||||
in an admonition
|
in an admonition
|
||||||
* #5231: "make html" does not read and build "po" files in "locale" dir
|
* #5231: "make html" does not read and build "po" files in "locale" dir
|
||||||
|
* #5954: ``:scale:`` image option may break PDF build if image in an admonition
|
||||||
|
|
||||||
Testing
|
Testing
|
||||||
--------
|
--------
|
||||||
|
@ -421,14 +421,15 @@ def escape_abbr(text):
|
|||||||
return re.sub(r'\.(?=\s|$)', r'.\@', text)
|
return re.sub(r'\.(?=\s|$)', r'.\@', text)
|
||||||
|
|
||||||
|
|
||||||
def rstdim_to_latexdim(width_str):
|
def rstdim_to_latexdim(width_str, scale = 100):
|
||||||
# type: (str) -> str
|
# type: (str, int) -> str
|
||||||
"""Convert `width_str` with rst length to LaTeX length."""
|
"""Convert `width_str` with rst length to LaTeX length."""
|
||||||
match = re.match(r'^(\d*\.?\d*)\s*(\S*)$', width_str)
|
match = re.match(r'^(\d*\.?\d*)\s*(\S*)$', width_str)
|
||||||
if not match:
|
if not match:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
res = width_str
|
res = width_str
|
||||||
amount, unit = match.groups()[:2]
|
amount, unit = match.groups()[:2]
|
||||||
|
if scale == 100:
|
||||||
float(amount) # validate amount is float
|
float(amount) # validate amount is float
|
||||||
if unit in ('', "px"):
|
if unit in ('', "px"):
|
||||||
res = "%s\\sphinxpxdimen" % amount
|
res = "%s\\sphinxpxdimen" % amount
|
||||||
@ -436,6 +437,16 @@ def rstdim_to_latexdim(width_str):
|
|||||||
res = '%sbp' % amount # convert to 'bp'
|
res = '%sbp' % amount # convert to 'bp'
|
||||||
elif unit == "%":
|
elif unit == "%":
|
||||||
res = "%.3f\\linewidth" % (float(amount) / 100.0)
|
res = "%.3f\\linewidth" % (float(amount) / 100.0)
|
||||||
|
else:
|
||||||
|
amount_float = float(amount) * scale / 100.0
|
||||||
|
if unit in ('', "px"):
|
||||||
|
res = "%.5f\\sphinxpxdimen" % amount_float
|
||||||
|
elif unit == 'pt':
|
||||||
|
res = '%.5fbp' % amount_float
|
||||||
|
elif unit == "%":
|
||||||
|
res = "%.5f\\linewidth" % (amount_float / 100.0)
|
||||||
|
else:
|
||||||
|
res = "%.5f%s" % (amount_float, unit)
|
||||||
return res
|
return res
|
||||||
|
|
||||||
|
|
||||||
@ -1502,10 +1513,10 @@ class LaTeXTranslator(SphinxTranslator):
|
|||||||
# type: (nodes.Element) -> None
|
# type: (nodes.Element) -> None
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def latex_image_length(self, width_str):
|
def latex_image_length(self, width_str, scale = 100):
|
||||||
# type: (str) -> str
|
# type: (str, int) -> str
|
||||||
try:
|
try:
|
||||||
return rstdim_to_latexdim(width_str)
|
return rstdim_to_latexdim(width_str, scale)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
logger.warning(__('dimension unit %s is invalid. Ignored.'), width_str)
|
logger.warning(__('dimension unit %s is invalid. Ignored.'), width_str)
|
||||||
return None
|
return None
|
||||||
@ -1524,20 +1535,21 @@ class LaTeXTranslator(SphinxTranslator):
|
|||||||
include_graphics_options = []
|
include_graphics_options = []
|
||||||
is_inline = self.is_inline(node)
|
is_inline = self.is_inline(node)
|
||||||
if 'width' in attrs:
|
if 'width' in attrs:
|
||||||
|
if 'scale' in attrs:
|
||||||
|
w = self.latex_image_length(attrs['width'], attrs['scale'])
|
||||||
|
else:
|
||||||
w = self.latex_image_length(attrs['width'])
|
w = self.latex_image_length(attrs['width'])
|
||||||
if w:
|
if w:
|
||||||
include_graphics_options.append('width=%s' % w)
|
include_graphics_options.append('width=%s' % w)
|
||||||
if 'height' in attrs:
|
if 'height' in attrs:
|
||||||
|
if 'scale' in attrs:
|
||||||
|
h = self.latex_image_length(attrs['height'], attrs['scale'])
|
||||||
|
else:
|
||||||
h = self.latex_image_length(attrs['height'])
|
h = self.latex_image_length(attrs['height'])
|
||||||
if h:
|
if h:
|
||||||
include_graphics_options.append('height=%s' % h)
|
include_graphics_options.append('height=%s' % h)
|
||||||
if 'scale' in attrs:
|
if 'scale' in attrs:
|
||||||
if include_graphics_options:
|
if not include_graphics_options:
|
||||||
# unfortunately passing "height=1cm,scale=2.0" to \includegraphics
|
|
||||||
# does not result in a height of 2cm. We must scale afterwards.
|
|
||||||
pre.append('\\scalebox{%f}{' % (attrs['scale'] / 100.0,))
|
|
||||||
post.append('}')
|
|
||||||
else:
|
|
||||||
# if no "width" nor "height", \sphinxincludegraphics will fit
|
# if no "width" nor "height", \sphinxincludegraphics will fit
|
||||||
# to the available text width if oversized after rescaling.
|
# to the available text width if oversized after rescaling.
|
||||||
include_graphics_options.append('scale=%s'
|
include_graphics_options.append('scale=%s'
|
||||||
|
@ -1260,7 +1260,7 @@ def test_latex_image_in_parsed_literal(app, status, warning):
|
|||||||
|
|
||||||
result = (app.outdir / 'python.tex').text(encoding='utf8')
|
result = (app.outdir / 'python.tex').text(encoding='utf8')
|
||||||
assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
|
assert ('{\\sphinxunactivateextrasandspace \\raisebox{-0.5\\height}'
|
||||||
'{\\scalebox{2.000000}{\\sphinxincludegraphics[height=1cm]{{pic}.png}}}'
|
'{\\sphinxincludegraphics[height=2.00000cm]{{pic}.png}}'
|
||||||
'}AFTER') in result
|
'}AFTER') in result
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user