X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Finsets%2FInsetLine.cpp;h=5c12d37e09539a23430ffc21be0020fd3d4eaf9d;hb=a3c84666b2dbfc75c9a80cf4f94612149cb2b570;hp=255e6a99bfe5cf4eaa77f5d09c1605d7ff92f80a;hpb=15679c3e8203f71a38f9be82e689ddfb4ecfe432;p=lyx.git diff --git a/src/insets/InsetLine.cpp b/src/insets/InsetLine.cpp index 255e6a99bf..5c12d37e09 100644 --- a/src/insets/InsetLine.cpp +++ b/src/insets/InsetLine.cpp @@ -3,6 +3,7 @@ * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * + * \author Abdelrazak Younes * \author André Pönitz * \author Uwe Stöhr * @@ -14,8 +15,7 @@ #include "InsetLine.h" #include "Buffer.h" -#include "BufferView.h" -#include "CoordCache.h" +#include "Cursor.h" #include "Dimension.h" #include "DispatchResult.h" #include "FuncRequest.h" @@ -43,7 +43,7 @@ using frontend::Painter; InsetLine::InsetLine(Buffer * buf, InsetCommandParams const & p) - : InsetCommand(buf, p, "line") + : InsetCommand(buf, p) {} @@ -72,8 +72,7 @@ void InsetLine::doDispatch(Cursor & cur, FuncRequest & cmd) case LFUN_INSET_MODIFY: { InsetCommandParams p(LINE_CODE); // FIXME UNICODE - InsetCommand::string2params("line", - to_utf8(cmd.argument()), p); + InsetCommand::string2params(to_utf8(cmd.argument()), p); if (p.getCmdName().empty()) { cur.noScreenUpdate(); break; @@ -106,8 +105,6 @@ bool InsetLine::getStatus(Cursor & cur, FuncRequest const & cmd, void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const { frontend::FontMetrics const & fm = theFontMetrics(mi.base.font); - dim.asc = fm.maxAscent(); - dim.des = fm.maxDescent(); int const max_width = mi.base.textwidth; Length const width(to_ascii(getParam("width"))); @@ -122,38 +119,44 @@ void InsetLine::metrics(MetricsInfo & mi, Dimension & dim) const int const minw = (dim.wid < 0) ? 24 : 4; 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_); + dim.des = max(fm.maxDescent(), - offset_); + // Cache the inset dimension setDimCache(mi, dim); } -void InsetLine::draw(PainterInfo & pi, int x, int y) const +Dimension const InsetLine::dimension(BufferView const & bv) const { - // FIXME: We cannot use InsetCommand::dimension() as this returns the dimension - // of the button, which is not used here! - Dimension const dim = pi.base.bv->coordCache().getInsets().dim(this); - int const max_width = dim.width(); - - frontend::FontMetrics const & fm = theFontMetrics(pi.base.font); - - // get the surrounding text color - FontInfo f = pi.base.font; - Color Line_color = f.realColor(); + // We cannot use InsetCommand::dimension() as this returns the dimension + // of the button, which is not used here. + return Inset::dimension(bv); +} - 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'))); +void InsetLine::draw(PainterInfo & pi, int x, int y) const +{ + Dimension const dim = dimension(*pi.base.bv); - // check that it doesn't exceed the upper boundary - if (y - o - h/2 < 0) - o = y - h/2 - 2; + // get the surrounding text color + Color Line_color = pi.base.font.realColor(); // the offset is a vertical one - pi.pain.line(x + 1, y - o - h/2, x + dim.wid - 2, y - o - h/2, - Line_color, Painter::line_solid, float(h)); + // the horizontal dimension must be corrected with the heigth because + // 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_)); }