Fix InsetLine painting for exotic offset and heigth.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@35407 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Abdelrazak Younes 2010-09-16 07:36:20 +00:00
parent d441aeba3c
commit 08453ceba4
2 changed files with 23 additions and 16 deletions

View File

@ -104,8 +104,6 @@ bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd,
void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
{ {
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
int const max_width = mi.base.textwidth; int const max_width = mi.base.textwidth;
Length const width(to_ascii(getParam("width"))); Length const width(to_ascii(getParam("width")));
@ -120,6 +118,16 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const
int const minw = (dim.wid < 0) ? 24 : 4; int const minw = (dim.wid < 0) ? 24 : 4;
dim.wid = max(minw, max(dim.wid, -dim.wid)); dim.wid = max(minw, max(dim.wid, -dim.wid));
Length height = Length(to_ascii(getParam("height")));
height_ = height.inPixels(dim.height(), fm.width(char_type('M')));
// get the length of the parameters in pixels
Length offset = Length(to_ascii(getParam("offset")));
offset_ = offset.inPixels(max_width, fm.width(char_type('M')));
dim.asc = max(fm.maxAscent(), offset_ + height_/2);
dim.des = max(fm.maxDescent(), height_/2 - offset_);
// Cache the inset dimension // Cache the inset dimension
setDimCache(mi, dim); setDimCache(mi, dim);
} }
@ -136,27 +144,23 @@ Dimension const InsetLine::dimension(BufferView const & bv) const
void InsetLine::draw(PainterInfo & pi, int x, int y) const void InsetLine::draw(PainterInfo & pi, int x, int y) const
{ {
Dimension const dim = dimension(*pi.base.bv); Dimension const dim = dimension(*pi.base.bv);
int const max_width = dim.width();
frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
Length height = Length(to_ascii(getParam("height")));
int const h = height.inPixels(dim.height(), fm.width(char_type('M')));
// get the length of the parameters in pixels
Length offset = Length(to_ascii(getParam("offset")));
int o = offset.inPixels(max_width, fm.width(char_type('M')));
// check that it doesn't exceed the upper boundary // check that it doesn't exceed the upper boundary
if (y - o - h/2 < 0) // FIXME: not sure this should be done...
o = y - h/2 - 2; if (y - offset_ - height_/2 < 0)
offset_ = y - height_/2 - 2;
// get the surrounding text color // get the surrounding text color
Color Line_color = pi.base.font.realColor(); Color Line_color = pi.base.font.realColor();
// the offset is a vertical one // the offset is a vertical one
pi.pain.line(x + 1, y - o - h/2, x + dim.wid - 2, y - o - h/2, // the horizontal dimension must be corrected with the heigth because
Line_color, Painter::line_solid, float(h)); // of left and right border of the painted line for big heigth.
pi.pain.line(x + height_/2 + 1,
y - offset_ - height_/2,
x + dim.wid - height_/2 - 2,
y - offset_ - height_/2,
Line_color, Painter::line_solid, float(height_));
} }

View File

@ -60,6 +60,9 @@ private:
bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const; bool getStatus(Cursor & cur, FuncRequest const & cmd, FuncStatus &) const;
/// ///
Inset * clone() const { return new InsetLine(*this); } Inset * clone() const { return new InsetLine(*this); }
///
mutable int height_;
mutable int offset_;
}; };