mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-11 13:46:43 +00:00
Improve metrics of equations. More work remains to be done.
Use proper value for above/below skip (12pt) instead of the hardcoded 12 pixels. Add forgotten skip before display math preview. Make "too small preview" size dpi-dependent. Make gap in front of equation (what is it good for, BTW?) dpi-dependent.
This commit is contained in:
parent
5b331b1466
commit
56e012be83
@ -525,22 +525,37 @@ bool InsetMathHull::previewState(const BufferView *const bv) const
|
|||||||
|
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
static const int ERROR_FRAME_WIDTH = 2;
|
const int ERROR_FRAME_WIDTH = 2;
|
||||||
|
|
||||||
|
bool previewTooSmall(MetricsBase const & mb, Dimension const & dim)
|
||||||
|
{
|
||||||
|
// Value was hardcoded to 10 pixels
|
||||||
|
int const minval = mb.bv->zoomedPixels(10);
|
||||||
|
return dim.width() <= minval && dim.height() <= minval;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
|
// true value in LaTeX is 12pt plus 3pt minus 9pt
|
||||||
|
// FIXME: even better would be to handle the short skip case.
|
||||||
|
int const display_margin = display() ? mi.base.inPixels(Length(12, Length::PT)) : 0;
|
||||||
|
|
||||||
if (previewState(mi.base.bv)) {
|
if (previewState(mi.base.bv)) {
|
||||||
preview_->metrics(mi, dim);
|
preview_->metrics(mi, dim);
|
||||||
if (previewTooSmall(dim)) {
|
if (previewTooSmall(mi.base, dim)) {
|
||||||
// preview image is too small
|
// preview image is too small
|
||||||
dim.wid += 2 * ERROR_FRAME_WIDTH;
|
dim.wid += 2 * ERROR_FRAME_WIDTH;
|
||||||
dim.asc += 2 * ERROR_FRAME_WIDTH;
|
dim.asc += 2 * ERROR_FRAME_WIDTH;
|
||||||
} else {
|
} else {
|
||||||
// insert a one pixel gap in front of the formula
|
// insert a gap in front of the formula
|
||||||
dim.wid += 1;
|
// value was hardcoded to 1 pixel
|
||||||
if (display())
|
dim.wid += mi.base.bv->zoomedPixels(1) ;
|
||||||
dim.des += displayMargin();
|
if (display()) {
|
||||||
|
dim.asc += display_margin;
|
||||||
|
dim.des += display_margin;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -553,8 +568,8 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
InsetMathGrid::metrics(mi, dim);
|
InsetMathGrid::metrics(mi, dim);
|
||||||
|
|
||||||
if (display()) {
|
if (display()) {
|
||||||
dim.asc += displayMargin();
|
dim.asc += display_margin;
|
||||||
dim.des += displayMargin();
|
dim.des += display_margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (numberedType()) {
|
if (numberedType()) {
|
||||||
@ -580,18 +595,12 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool InsetMathHull::previewTooSmall(Dimension const & dim) const
|
|
||||||
{
|
|
||||||
return dim.width() <= 10 && dim.height() <= 10;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
|
ColorCode InsetMathHull::backgroundColor(PainterInfo const & pi) const
|
||||||
{
|
{
|
||||||
BufferView const * const bv = pi.base.bv;
|
BufferView const * const bv = pi.base.bv;
|
||||||
if (previewState(bv)) {
|
if (previewState(bv)) {
|
||||||
Dimension const dim = dimension(*pi.base.bv);
|
Dimension const dim = dimension(*pi.base.bv);
|
||||||
if (previewTooSmall(dim))
|
if (previewTooSmall(pi.base, dim))
|
||||||
return Color_error;
|
return Color_error;
|
||||||
return graphics::PreviewLoader::backgroundColor();
|
return graphics::PreviewLoader::backgroundColor();
|
||||||
}
|
}
|
||||||
@ -621,7 +630,7 @@ void InsetMathHull::drawMarkers(PainterInfo & pi, int x, int y) const
|
|||||||
void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
|
void InsetMathHull::drawBackground(PainterInfo & pi, int x, int y) const
|
||||||
{
|
{
|
||||||
Dimension const dim = dimension(*pi.base.bv);
|
Dimension const dim = dimension(*pi.base.bv);
|
||||||
if (previewTooSmall(dim)) {
|
if (previewTooSmall(pi.base, dim)) {
|
||||||
pi.pain.fillRectangle(x, y - 2 * ERROR_FRAME_WIDTH,
|
pi.pain.fillRectangle(x, y - 2 * ERROR_FRAME_WIDTH,
|
||||||
dim.wid, dim.asc + dim.des, backgroundColor(pi));
|
dim.wid, dim.asc + dim.des, backgroundColor(pi));
|
||||||
return;
|
return;
|
||||||
@ -645,12 +654,14 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
|
|||||||
// already.
|
// already.
|
||||||
Changer dummy = !canPaintChange(*bv) ? make_change(pi.change_, Change())
|
Changer dummy = !canPaintChange(*bv) ? make_change(pi.change_, Change())
|
||||||
: Changer();
|
: Changer();
|
||||||
if (previewTooSmall(dim)) {
|
if (previewTooSmall(pi.base, dim)) {
|
||||||
// we have an extra frame
|
// we have an extra frame
|
||||||
preview_->draw(pi, x + ERROR_FRAME_WIDTH, y);
|
preview_->draw(pi, x + ERROR_FRAME_WIDTH, y);
|
||||||
} else {
|
} else {
|
||||||
// one pixel gap in front
|
// one pixel gap in front
|
||||||
preview_->draw(pi, x + 1, y);
|
// value was hardcoded to 1 pixel
|
||||||
|
int const gap = pi.base.bv->zoomedPixels(1) ;
|
||||||
|
preview_->draw(pi, x + gap, y);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -175,9 +175,6 @@ public:
|
|||||||
///
|
///
|
||||||
void initUnicodeMath() const;
|
void initUnicodeMath() const;
|
||||||
|
|
||||||
///
|
|
||||||
static int displayMargin() { return 12; }
|
|
||||||
|
|
||||||
/// Force inset into LTR environment if surroundings are RTL
|
/// Force inset into LTR environment if surroundings are RTL
|
||||||
virtual bool forceLTR() const { return true; }
|
virtual bool forceLTR() const { return true; }
|
||||||
///
|
///
|
||||||
@ -305,8 +302,6 @@ protected:
|
|||||||
void handleFont2(Cursor & cur, docstring const & arg);
|
void handleFont2(Cursor & cur, docstring const & arg);
|
||||||
///
|
///
|
||||||
bool previewState(BufferView const * const bv) const;
|
bool previewState(BufferView const * const bv) const;
|
||||||
///
|
|
||||||
bool previewTooSmall(Dimension const & dim) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user