commit 890b9a53cb1866c8271f1580b1392cedf9e28a6f
Author: Enrico Forestieri <[email protected]>
Date: Sun Apr 26 19:08:16 2015 +0200
Fix bug #7850 (Preview of inline math misaligned)
diff --git a/lib/scripts/legacy_lyxpreview2ppm.py
b/lib/scripts/legacy_lyxpreview2ppm.py
index d16e867..e6d5371 100644
--- a/lib/scripts/legacy_lyxpreview2ppm.py
+++ b/lib/scripts/legacy_lyxpreview2ppm.py
@@ -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}
diff --git a/lib/scripts/lyxpreview2bitmap.py b/lib/scripts/lyxpreview2bitmap.py
index ace46d2..5655bf3 100755
--- a/lib/scripts/lyxpreview2bitmap.py
+++ b/lib/scripts/lyxpreview2bitmap.py
@@ -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)
diff --git a/src/graphics/PreviewImage.cpp b/src/graphics/PreviewImage.cpp
index 5eecfcc..8c3f31d 100644
--- a/src/graphics/PreviewImage.cpp
+++ b/src/graphics/PreviewImage.cpp
@@ -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;
diff --git a/src/graphics/PreviewLoader.cpp b/src/graphics/PreviewLoader.cpp
index 649f460..3fd8fef 100644
--- a/src/graphics/PreviewLoader.cpp
+++ b/src/graphics/PreviewLoader.cpp
@@ -734,7 +734,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;