diff --git a/lib/scripts/legacy_lyxpreview2ppm.py b/lib/scripts/legacy_lyxpreview2ppm.py index d16e86788f..e6d5371de2 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 ace46d21c6..5655bf36ca 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 5eecfcc48a..8c3f31d44f 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 649f4602f2..3fd8fef029 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;