Fix bug #7850 (Preview of inline math misaligned)

This commit is contained in:
Enrico Forestieri 2015-05-30 13:51:13 +02:00
parent 1ab1f071b5
commit 043cf5a700
5 changed files with 18 additions and 9 deletions

View File

@ -114,13 +114,16 @@ def legacy_extract_metrics_info(log_file):
error("Unexpected data in %s\n%s" % (log_file, line))
if snippet:
ascent = string.atoi(match.group(2))
descent = string.atoi(match.group(3))
ascent = string.atof(match.group(2))
descent = string.atof(match.group(3))
frac = 0.5
if ascent >= 0 and descent >= 0:
ascent = float(ascent) + tp_ascent
descent = float(descent) - tp_descent
if ascent == 0 and descent == 0:
# This is an empty image, forbid its display
frac = -1.0
elif ascent >= 0 or descent >= 0:
ascent = ascent + tp_ascent
descent = descent - tp_descent
if abs(ascent + descent) > 0.1:
frac = ascent / (ascent + descent)
@ -225,7 +228,7 @@ def legacy_latex_file(latex_file, fg_color, bg_color):
\definecolor{fg}{rgb}{%s}
\definecolor{bg}{rgb}{%s}
\pagecolor{bg}
\usepackage[%s,lyx,tightpage]{preview}
\usepackage[%s,tightpage]{preview}
\makeatletter
\g@addto@macro\preview{\begingroup\color{bg}\special{ps::clippath fill}\color{fg}}
\g@addto@macro\endpreview{\endgroup}

View File

@ -137,7 +137,10 @@ def extract_metrics_info(dvipng_stdout):
ascent = string.atof(match.group(2))
frac = 0.5
if ascent >= 0 or descent >= 0:
if ascent < 0:
# This is an empty image, forbid its display
frac = -1.0
elif ascent >= 0 or descent >= 0:
if abs(ascent + descent) > 0.1:
frac = ascent / (ascent + descent)

View File

@ -85,7 +85,7 @@ Dimension PreviewImage::dim() const
if (!image)
return dim;
dim.asc = int(pimpl_->ascent_frac_ * double(image->height()));
dim.asc = int(pimpl_->ascent_frac_ * double(image->height()) + 0.5);
dim.des = image->height() - dim.asc;
dim.wid = image->width();
return dim;

View File

@ -687,7 +687,8 @@ void PreviewLoader::Impl::finishedGenerating(pid_t pid, int retval)
double af = ascent_fractions[metrics_counter];
// Add the image to the cache only if it's actually present
if (file.isReadableFile()) {
// and not empty (an empty image is signaled by af < 0)
if (af >= 0 && file.isReadableFile()) {
PreviewImagePtr ptr(new PreviewImage(parent_, snip, file, af));
cache_[snip] = ptr;

View File

@ -221,6 +221,8 @@ What's new
- Fix button logic in table settings dialog (bug 9570).
- Fix alignment of inline previews occurring in some cases (bug 7850).
* INTERNALS