diff --git a/src/ChangeLog b/src/ChangeLog index 805793496e..c69e281f37 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2003-05-30 André Pönitz + + * rowpainter.C: unify second drawing phase + 2003-05-29 Lars Gullik Bjřnnes * trans_mgr.C: remove one case of current_view diff --git a/src/insets/ChangeLog b/src/insets/ChangeLog index cf73cf8d44..c09097b85c 100644 --- a/src/insets/ChangeLog +++ b/src/insets/ChangeLog @@ -1,3 +1,24 @@ + +2003-05-30 André Pönitz + + * inset.h: + * insetbase.h: + * insetbutton.[Ch]: + * insetcaption.[Ch]: + * insetcollapsable.[Ch]: + * inseterror.[Ch]: + * insetert.[Ch]: + * insetgraphics.[Ch]: + * insetinclude.[Ch]: + * insetlatexaccent.[Ch]: + * insetnewline.[Ch]: + * insetquotes.[Ch]: + * insetspace.[Ch]: + * insetspecialchar.[Ch]: + * insettabular.[Ch]: + * insettext.[Ch]: + * updatableinset.[Ch]: unify second drawing phase + 2003-05-30 John Levon * insetgraphics.C: fix a bformat diff --git a/src/insets/inset.h b/src/insets/inset.h index 4cbf3e4719..b4f82328bb 100644 --- a/src/insets/inset.h +++ b/src/insets/inset.h @@ -167,8 +167,6 @@ public: int descent(BufferView *, LyXFont const &) const; /// int width(BufferView *, LyXFont const &) const; - /// - virtual void draw(BufferView *, LyXFont const &, int baseline, float & x) const = 0; /// update the inset representation virtual void update(BufferView *, bool = false) {} diff --git a/src/insets/insetbase.h b/src/insets/insetbase.h index c6dc34894e..52b5ec824b 100644 --- a/src/insets/insetbase.h +++ b/src/insets/insetbase.h @@ -16,6 +16,8 @@ class BufferView; class FuncRequest; +class MetricsInfo; +class PainterInfo; /** Dispatch result codes DISPATCHED = the inset catched the action @@ -62,6 +64,8 @@ public: /// small wrapper for the time being virtual dispatch_result localDispatch(FuncRequest const & cmd); + /// + virtual void draw(PainterInfo & pi, int x, int y) const = 0; /// virtual ~InsetBase() {} diff --git a/src/insets/insetbutton.C b/src/insets/insetbutton.C index bac1e65c34..5310940d6c 100644 --- a/src/insets/insetbutton.C +++ b/src/insets/insetbutton.C @@ -21,6 +21,7 @@ #include "frontends/Painter.h" #include "support/LAssert.h" #include "lyxfont.h" +#include "metricsinfo.h" #include "frontends/font_metrics.h" using std::ostream; @@ -46,27 +47,23 @@ void InsetButton::dimension(BufferView * bv, LyXFont const &, } -void InsetButton::draw(BufferView * bv, LyXFont const &, - int baseline, float & x) const +void InsetButton::draw(PainterInfo & pi, int x, int y) const { - lyx::Assert(bv); - cache(bv); + lyx::Assert(pi.base.bv); + cache(pi.base.bv); - Painter & pain = bv->painter(); // Draw it as a box with the LaTeX text LyXFont font(LyXFont::ALL_SANE); font.setColor(LColor::command).decSize(); - string const s = getScreenLabel(bv->buffer()); + string const s = getScreenLabel(pi.base.bv->buffer()); if (editable()) { - pain.buttonText(int(x) + 2, baseline, s, font); + pi.pain.buttonText(x + 2, y, s, font); } else { - pain.rectText(int(x) + 2, baseline, s, font, + pi.pain.rectText(x + 2, y, s, font, LColor::commandbg, LColor::commandframe); } - - x += width(bv, font); } diff --git a/src/insets/insetbutton.h b/src/insets/insetbutton.h index 821d868377..beb127761c 100644 --- a/src/insets/insetbutton.h +++ b/src/insets/insetbutton.h @@ -25,7 +25,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// dispatch_result localDispatch(FuncRequest const & cmd); diff --git a/src/insets/insetcaption.C b/src/insets/insetcaption.C index da5afffce7..0da530552d 100644 --- a/src/insets/insetcaption.C +++ b/src/insets/insetcaption.C @@ -21,6 +21,7 @@ #include "debug.h" #include "gettext.h" #include "Lsstream.h" +#include "metricsinfo.h" #include "support/lstrings.h" #include "support/LAssert.h" #include "support/BoostFormat.h" @@ -66,8 +67,7 @@ string const InsetCaption::editMessage() const } -void InsetCaption::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetCaption::draw(PainterInfo & pi, int x, int y) const { // We must draw the label, we should get the label string // from the enclosing float inset. @@ -88,7 +88,7 @@ void InsetCaption::draw(BufferView * bv, LyXFont const & f, lyx::Assert(0); FloatList const & floats = - bv->buffer()->params.getLyXTextClass().floats(); + pi.base.bv->buffer()->params.getLyXTextClass().floats(); string const fl = i2 ? floats.getType(type).name() : N_("Float"); // Discover the number... @@ -96,12 +96,9 @@ void InsetCaption::draw(BufferView * bv, LyXFont const & f, // Generate the label string const label = bformat("%1$s %2$s:", _(fl), num); - Painter & pain = bv->painter(); - int const w = font_metrics::width(label, f); - pain.text(int(x), baseline, label, f); - x += w; - - InsetText::draw(bv, f, baseline, x); + int const w = font_metrics::width(label, pi.base.font); + pi.pain.text(x, y, label, pi.base.font); + InsetText::draw(pi, x + w, y); } diff --git a/src/insets/insetcaption.h b/src/insets/insetcaption.h index af616f6628..83da8b22b1 100644 --- a/src/insets/insetcaption.h +++ b/src/insets/insetcaption.h @@ -34,8 +34,7 @@ public: /// virtual string const editMessage() const; /// - virtual void draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const; + virtual void draw(PainterInfo & pi, int x, int y) const; /// virtual int latex(Buffer const * buf, std::ostream & os, LatexRunParams const &) const; diff --git a/src/insets/insetcollapsable.C b/src/insets/insetcollapsable.C index 8d62008e08..b6cae4d6e2 100644 --- a/src/insets/insetcollapsable.C +++ b/src/insets/insetcollapsable.C @@ -25,6 +25,7 @@ #include "WordLangTuple.h" #include "funcrequest.h" #include "buffer.h" +#include "metricsinfo.h" #include "frontends/font_metrics.h" #include "frontends/Painter.h" @@ -136,22 +137,16 @@ void InsetCollapsable::dimension(BufferView * bv, LyXFont const & font, } -void InsetCollapsable::draw_collapsed(Painter & pain, - int baseline, float & x) const +void InsetCollapsable::draw_collapsed(PainterInfo & pi, int x, int y) const { - pain.buttonText(int(x) + TEXT_TO_INSET_OFFSET, - baseline, label, labelfont); - Dimension dim; - dimension_collapsed(dim); - x += dim.wid; + pi.pain.buttonText(x + TEXT_TO_INSET_OFFSET, y, label, labelfont); } -void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x, bool inlined) const +void InsetCollapsable::draw(PainterInfo & pi, int x, int y, bool inlined) const { - lyx::Assert(bv); - cache(bv); + lyx::Assert(pi.base.bv); + cache(pi.base.bv); if (nodraw()) return; @@ -159,45 +154,41 @@ void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, Dimension dim_collapsed; dimension_collapsed(dim_collapsed); - Painter & pain = bv->painter(); - + int const aa = ascent(pi.base.bv, pi.base.font); button_length = dim_collapsed.width(); - button_top_y = -ascent(bv, f); - button_bottom_y = -ascent(bv, f) + dim_collapsed.height(); + button_top_y = -aa; + button_bottom_y = -aa + dim_collapsed.height(); if (!isOpen()) { - draw_collapsed(pain, baseline, x); + draw_collapsed(pi, x, y); return; } - float old_x = x; + int old_x = x; if (!owner()) x += scroll(); - top_x = int(x); - top_baseline = baseline; + top_x = x; + top_baseline = y; - int const bl = baseline - ascent(bv, f) + dim_collapsed.ascent(); + int const bl = y - aa + dim_collapsed.ascent(); if (inlined) { - inset.draw(bv, f, baseline, x); + inset.draw(pi, x, y); } else { - draw_collapsed(pain, bl, old_x); - int const yy = bl + dim_collapsed.descent() + inset.ascent(bv, f); - inset.draw(bv, f, yy, x); - // contained inset may be shorter than the button - if (x < top_x + button_length + TEXT_TO_INSET_OFFSET) - x = top_x + button_length + TEXT_TO_INSET_OFFSET; + draw_collapsed(pi, old_x, bl); + int const yy = bl + dim_collapsed.descent() + + inset.ascent(pi.base.bv, pi.base.font); + inset.draw(pi, x, yy); } } -void InsetCollapsable::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetCollapsable::draw(PainterInfo & pi, int x, int y) const { // by default, we are not inlined-drawing - draw(bv, f, baseline, x, false); + draw(pi, x, y, false); } diff --git a/src/insets/insetcollapsable.h b/src/insets/insetcollapsable.h index b733d9ec6d..e7dc0cbaa7 100644 --- a/src/insets/insetcollapsable.h +++ b/src/insets/insetcollapsable.h @@ -47,10 +47,9 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, const LyXFont &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// draw, either inlined (no button) or collapsed/open - void draw(BufferView * bv, LyXFont const & f, - int baseline, float & x, bool inlined) const; + void draw(PainterInfo & pi, int x, int y, bool inlined) const; /// void update(BufferView *, bool = false); /// @@ -181,7 +180,7 @@ protected: /// int height_collapsed() const; /// - void draw_collapsed(Painter & pain, int, float &) const; + void draw_collapsed(PainterInfo & pi, int x, int y) const; /// int getMaxTextWidth(Painter & pain, UpdatableInset const *) const; diff --git a/src/insets/inseterror.C b/src/insets/inseterror.C index a0dd7e9a64..8bc8a7e5bb 100644 --- a/src/insets/inseterror.C +++ b/src/insets/inseterror.C @@ -17,6 +17,7 @@ #include "funcrequest.h" #include "gettext.h" #include "lyxfont.h" +#include "metricsinfo.h" #include "frontends/Dialogs.h" #include "frontends/font_metrics.h" @@ -71,30 +72,24 @@ void InsetError::dimension(BufferView *, LyXFont const & font, } -void InsetError::draw(BufferView * bv, LyXFont const & font, - int baseline, float & x) const +void InsetError::draw(PainterInfo & pi, int x, int y) const { - lyx::Assert(bv); - cache(bv); + lyx::Assert(pi.base.bv); + cache(pi.base.bv); - Painter & pain = bv->painter(); LyXFont efont; - efont.setSize(font.size()).decSize(); + efont.setSize(pi.base.font.size()).decSize(); efont.setColor(LColor::error); // Draw as "Error" in a framed box x += 1; - pain.fillRectangle(int(x), baseline - ascent(bv, font) + 1, - width(bv, font) - 2, - ascent(bv, font) + descent(bv, font) - 2, - LColor::insetbg); - pain.rectangle(int(x), baseline - ascent(bv, font) + 1, - width(bv, font) - 2, - ascent(bv, font) + descent(bv, font) - 2, - LColor::error); - pain.text(int(x + 2), baseline, _("Error"), efont); - - x += width(bv, font) - 1; + Dimension dim; + dimension(pi.base.bv, pi.base.font, dim); + pi.pain.fillRectangle(x, y - dim.asc + 1, + dim.wid - 2, dim.asc + dim.des - 2, LColor::insetbg); + pi.pain.rectangle(x, y - dim.asc + 1, + dim.wid - 2, dim.asc + dim.des - 2, LColor::error); + pi.pain.text(x + 2, y, _("Error"), efont); } diff --git a/src/insets/inseterror.h b/src/insets/inseterror.h index 9dadbee3a3..919f6b0cd6 100644 --- a/src/insets/inseterror.h +++ b/src/insets/inseterror.h @@ -32,7 +32,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void write(Buffer const *, std::ostream &) const {} /// diff --git a/src/insets/insetert.C b/src/insets/insetert.C index c0fa754a42..c4141894f0 100644 --- a/src/insets/insetert.C +++ b/src/insets/insetert.C @@ -562,10 +562,9 @@ void InsetERT::dimension(BufferView * bv, LyXFont const & font, } -void InsetERT::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetERT::draw(PainterInfo & pi, int x, int y) const { - InsetCollapsable::draw(bv, f, baseline, x, inlined()); + InsetCollapsable::draw(pi, x, y, inlined()); } diff --git a/src/insets/insetert.h b/src/insets/insetert.h index 786c6aacb3..3483cbd2e0 100644 --- a/src/insets/insetert.h +++ b/src/insets/insetert.h @@ -101,7 +101,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, const LyXFont &, int , float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// set the status of the inset void status(BufferView *, ERTStatus const st) const; /// diff --git a/src/insets/insetgraphics.C b/src/insets/insetgraphics.C index b250a80fc1..c92b5b12ff 100644 --- a/src/insets/insetgraphics.C +++ b/src/insets/insetgraphics.C @@ -73,7 +73,7 @@ TODO #include "Lsstream.h" #include "lyxlex.h" #include "lyxrc.h" -#include "Lsstream.h" +#include "metricsinfo.h" #include "frontends/lyx_gui.h" #include "frontends/Alert.h" @@ -324,9 +324,9 @@ BufferView * InsetGraphics::view() const } -void InsetGraphics::draw(BufferView * bv, LyXFont const & font, - int baseline, float & x) const +void InsetGraphics::draw(PainterInfo & pi, int x, int y) const { + BufferView * bv = pi.base.bv; // MakeAbsPath returns params().filename unchanged if it absolute // already. string const file_with_path = @@ -342,22 +342,18 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, cache_->view = bv->owner()->view(); int oasc = cache_->old_ascent; - int ldescent = descent(bv, font); - int lascent = ascent(bv, font); - int lwidth = width(bv, font); + Dimension dim; + dimension(bv, pi.base.font, dim); // we may have changed while someone other was drawing us so better // to not draw anything as we surely call to redraw ourself soon. // This is not a nice thing to do and should be fixed properly somehow. // But I still don't know the best way to go. So let's do this like this // for now (Jug 20020311) - if (lascent != oasc) + if (dim.asc != oasc) return; // Make sure now that x is updated upon exit from this routine - int old_x = int(x); - x += lwidth; - grfx::Params const & gparams = params().as_grfxParams(); if (gparams.display != grfx::NoDisplay && @@ -369,26 +365,25 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, // This will draw the graphics. If the graphics has not been loaded yet, // we draw just a rectangle. - Painter & paint = bv->painter(); if (imageIsDrawable()) { - paint.image(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent, - lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent, + pi.pain.image(x + TEXT_TO_INSET_OFFSET, y - dim.asc, + dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des, *cache_->loader.image()); } else { - paint.rectangle(old_x + TEXT_TO_INSET_OFFSET, baseline - lascent, - lwidth - 2 * TEXT_TO_INSET_OFFSET, lascent + ldescent); + pi.pain.rectangle(x + TEXT_TO_INSET_OFFSET, y - dim.asc, + dim.wid - 2 * TEXT_TO_INSET_OFFSET, dim.asc + dim.des); // Print the file name. - LyXFont msgFont(font); + LyXFont msgFont = pi.base.font; msgFont.setFamily(LyXFont::SANS_FAMILY); string const justname = OnlyFilename (params().filename); if (!justname.empty()) { msgFont.setSize(LyXFont::SIZE_FOOTNOTE); - paint.text(old_x + TEXT_TO_INSET_OFFSET + 6, - baseline - font_metrics::maxAscent(msgFont) - 4, + pi.pain.text(x + TEXT_TO_INSET_OFFSET + 6, + y - font_metrics::maxAscent(msgFont) - 4, justname, msgFont); } @@ -396,7 +391,7 @@ void InsetGraphics::draw(BufferView * bv, LyXFont const & font, string const msg = statusMessage(); if (!msg.empty()) { msgFont.setSize(LyXFont::SIZE_TINY); - paint.text(old_x + TEXT_TO_INSET_OFFSET + 6, baseline - 4, msg, msgFont); + pi.pain.text(x + TEXT_TO_INSET_OFFSET + 6, y - 4, msg, msgFont); } } } diff --git a/src/insets/insetgraphics.h b/src/insets/insetgraphics.h index 7a070d1ca9..958dbc64b0 100644 --- a/src/insets/insetgraphics.h +++ b/src/insets/insetgraphics.h @@ -36,7 +36,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// EDITABLE editable() const; /// diff --git a/src/insets/insetinclude.C b/src/insets/insetinclude.C index 75a1ca5b43..5f492c0745 100644 --- a/src/insets/insetinclude.C +++ b/src/insets/insetinclude.C @@ -22,7 +22,8 @@ #include "Lsstream.h" #include "lyxlex.h" #include "lyxrc.h" -#include "Lsstream.h" +#include "metricsinfo.h" +#include "dimension.h" #include "frontends/Dialogs.h" #include "frontends/LyXView.h" @@ -532,28 +533,22 @@ int InsetInclude::width(BufferView * bv, LyXFont const & font) const } -void InsetInclude::draw(BufferView * bv, LyXFont const & font, int y, - float & xx) const +void InsetInclude::draw(PainterInfo & pi, int x, int y) const { - cache(bv); + cache(pi.base.bv); if (!preview_->previewReady()) { - InsetButton::draw(bv, font, y, xx); + InsetButton::draw(pi, x, y); return; } if (!preview_->monitoring()) preview_->startMonitoring(); - int const x = int(xx); - int const w = width(bv, font); - int const d = descent(bv, font); - int const a = ascent(bv, font); - int const h = a + d; + Dimension dim; + dimension(pi.base.bv, pi.base.font, dim); - bv->painter().image(x, y - a, w, h, + pi.pain.image(x, y - dim.asc, dim.wid, dim.height(), *(preview_->pimage()->image())); - - xx += w; } diff --git a/src/insets/insetinclude.h b/src/insets/insetinclude.h index a6d197952b..b81e9df26c 100644 --- a/src/insets/insetinclude.h +++ b/src/insets/insetinclude.h @@ -66,7 +66,7 @@ public: /// int width(BufferView *, LyXFont const &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// get the parameters Params const & params(void) const; diff --git a/src/insets/insetlatexaccent.C b/src/insets/insetlatexaccent.C index b5e51eb57b..791269e73e 100644 --- a/src/insets/insetlatexaccent.C +++ b/src/insets/insetlatexaccent.C @@ -21,6 +21,7 @@ #include "frontends/font_metrics.h" #include "language.h" #include "lyxlex.h" +#include "metricsinfo.h" using std::ostream; using std::endl; @@ -306,9 +307,7 @@ int InsetLatexAccent::rbearing(LyXFont const & font) const } -bool InsetLatexAccent::displayISO8859_9(BufferView * bv, LyXFont const & font, - int baseline, - float & x) const +bool InsetLatexAccent::displayISO8859_9(PainterInfo & pi, int x, int y) const { unsigned char tmpic = ic; @@ -339,9 +338,7 @@ bool InsetLatexAccent::displayISO8859_9(BufferView * bv, LyXFont const & font, default: return false; } if (tmpic != ic) { - char ch = char(tmpic); - bv->painter().text(int(x), baseline, ch, font); - x += width(bv, font); + pi.pain.text(x, y, char(tmpic), pi.base.font); return true; } else @@ -349,13 +346,10 @@ bool InsetLatexAccent::displayISO8859_9(BufferView * bv, LyXFont const & font, } -void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, - int baseline, float & x) const +void InsetLatexAccent::draw(PainterInfo & pi, int x, int baseline) const { - Painter & pain = bv->painter(); - if (lyxrc.font_norm_type == LyXRC::ISO_8859_9) - if (displayISO8859_9(bv, font0, baseline, x)) + if (displayISO8859_9(pi, x, baseline)) return; /* draw it! */ @@ -363,27 +357,28 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, // overhaul. Different ways of drawing (what metrics to use) // should also be considered. - LyXFont font(font0); + BufferView * bv = pi.base.bv; + LyXFont font = pi.base.font; if (lyxrc.font_norm_type == LyXRC::ISO_10646_1) font.setLanguage(english_language); + Dimension dim; + dimension(bv, font, dim); + if (candisp) { - int asc = ascent(bv, font); - int desc = descent(bv, font); - int wid = width(bv, font); float x2 = x + (rbearing(font) - lbearing(font)) / 2.0; float hg; int y; if (plusasc) { // mark at the top hg = font_metrics::maxDescent(font); - y = baseline - asc; + y = baseline - dim.asc; if (font.shape() == LyXFont::ITALIC_SHAPE) x2 += (4.0 * hg) / 5.0; // italic } else { // at the bottom - hg = desc; + hg = dim.des; y = baseline; } @@ -391,18 +386,18 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, // display with proper accent mark // first the letter - pain.text(int(x), baseline, ic, font); + pi.pain.text(x, baseline, ic, font); if (remdot) { int tmpvar = baseline - font_metrics::ascent('i', font); - float tmpx = 0; + int tmpx = 0; if (font.shape() == LyXFont::ITALIC_SHAPE) - tmpx += (8.0 * hg) / 10.0; // italic + tmpx += int(0.8 * hg); // italic lyxerr[Debug::KEY] << "Removing dot." << endl; // remove the dot first - pain.fillRectangle(int(x + tmpx), tmpvar, wid, - font_metrics::ascent('i', font) - - font_metrics::ascent('x', font) - 1, + pi.pain.fillRectangle(x + tmpx, tmpvar, dim.wid, + font_metrics::ascent('i', pi.base.font) - + font_metrics::ascent('x', pi.base.font) - 1, backgroundColor()); // the five lines below is a simple hack to // make the display of accent 'i' and 'j' @@ -410,7 +405,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, // closer to the top of the dot-less 'i' or 'j'. char tmpic = ic; // store the ic when we ic = 'x'; // calculates the ascent of - asc = ascent(bv, font); // the dot-less version (here: 'x') + int asc = ascent(bv, font); // the dot-less version (here: 'x') ic = tmpic; // set the orig ic back y = baseline - asc; // update to new y coord. } @@ -418,48 +413,52 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, switch (modtype) { case ACUTE: // acute 0xB4 { - pain.text(int(x2 - (font_metrics::rbearing(0xB4, font) - font_metrics::lbearing(0xB4, font)) / 2), - baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xB4, font) - (font_metrics::ascent(0xB4, font) + font_metrics::descent(0xB4, font)) / 2, + pi.pain.text(int(x2 - (font_metrics::rbearing(0xB4, font) + - font_metrics::lbearing(0xB4, font)) / 2), + baseline - font_metrics::ascent(ic, font) + - font_metrics::descent(0xB4, font) + - (font_metrics::ascent(0xB4, font) + + font_metrics::descent(0xB4, font)) / 2, char(0xB4), font); break; } case GRAVE: // grave 0x60 { - pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - font_metrics::lbearing(0x60, font)) / 2), + pi.pain.text(int(x2 - (font_metrics::rbearing(0x60, font) - font_metrics::lbearing(0x60, font)) / 2), int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x60, font) - (font_metrics::ascent(0x60, font) + font_metrics::descent(0x60, font)) / 2.0), char(0x60), font); break; } case MACRON: // macron { - pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - font_metrics::lbearing(0xAF, font)) / 2), + pi.pain.text(int(x2 - (font_metrics::rbearing(0xAF, font) - font_metrics::lbearing(0xAF, font)) / 2), baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xAF, font) - (font_metrics::ascent(0xAF, font) + font_metrics::descent(0xAF, font)), char(0xAF), font); break; } case TILDE: // tilde { - pain.text(int(x2 - (font_metrics::rbearing('~', font) - font_metrics::lbearing('~', font)) / 2), + pi.pain.text(int(x2 - (font_metrics::rbearing('~', font) - font_metrics::lbearing('~', font)) / 2), baseline - font_metrics::ascent(ic, font) - font_metrics::descent('~', font) - (font_metrics::ascent('~', font) + font_metrics::descent('~', font)) / 2, '~', font); break; } case UNDERBAR: // underbar 0x5F { - pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - font_metrics::lbearing(0x5F, font)) / 2), baseline, + pi.pain.text(int(x2 - (font_metrics::rbearing(0x5F, font) - font_metrics::lbearing(0x5F, font)) / 2), baseline, char(0x5F), font); break; } case CEDILLA: // cedilla { - pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - font_metrics::lbearing(0xB8, font)) / 2), baseline, + pi.pain.text(int(x2 - (font_metrics::rbearing(0xB8, font) - font_metrics::lbearing(0xB8, font)) / 2), baseline, char(0xB8), font); break; } case UNDERDOT: // underdot { - pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0), + pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0), int(baseline + 3.0 / 2.0 * (font_metrics::ascent('.', font) + font_metrics::descent('.', font))), '.', font); break; @@ -467,7 +466,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, case DOT: // dot { - pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0), + pi.pain.text(int(x2 - (font_metrics::rbearing('.', font) - font_metrics::lbearing('.', font)) / 2.0), baseline - font_metrics::ascent(ic, font) - font_metrics::descent('.', font) - (font_metrics::ascent('.', font) + font_metrics::descent('.', font)) / 2, '.', font); break; @@ -477,20 +476,20 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, { LyXFont tmpf(font); tmpf.decSize().decSize(); - pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - font_metrics::lbearing(0xB0, tmpf)) / 2.0), + pi.pain.text(int(x2 - (font_metrics::rbearing(0xB0, tmpf) - font_metrics::lbearing(0xB0, tmpf)) / 2.0), int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0xB0, tmpf) - (font_metrics::ascent(0xB0, tmpf) + font_metrics::descent(0xB0, tmpf)) / 3.0), char(0xB0), tmpf); break; } case TIE: // tie { - pain.arc(int(x2 + hg35), int(y + hg / 2.0), + pi.pain.arc(int(x2 + hg35), int(y + hg / 2.0), int(2 * hg), int(hg), 0, 360 * 32); break; } case BREVE: // breve { - pain.arc(int(x2 - (hg / 2.0)), y, + pi.pain.arc(int(x2 - (hg / 2.0)), y, int(hg), int(hg), 0, -360*32); break; } @@ -501,41 +500,41 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, xp[0] = int(x2 - hg35); yp[0] = int(y + hg35); xp[1] = int(x2); yp[1] = int(y + hg); xp[2] = int(x2 + hg35); yp[2] = int(y + hg35); - pain.lines(xp, yp, 3); + pi.pain.lines(xp, yp, 3); break; } case SPECIAL_CARON: // special caron { switch (ic) { - case 'L': wid = int(4.0 * wid / 5.0); break; + case 'L': dim.wid = int(4.0 * dim.wid / 5.0); break; case 't': y -= int(hg35 / 2.0); break; } int xp[3], yp[3]; - xp[0] = int(x + wid); + xp[0] = int(x + dim.wid); yp[0] = int(y + hg35 + hg); - xp[1] = int(x + wid + (hg35 / 2.0)); + xp[1] = int(x + dim.wid + (hg35 / 2.0)); yp[1] = int(y + hg + (hg35 / 2.0)); - xp[2] = int(x + wid + (hg35 / 2.0)); + xp[2] = int(x + dim.wid + (hg35 / 2.0)); yp[2] = y + int(hg); - pain.lines(xp, yp, 3); + pi.pain.lines(xp, yp, 3); break; } case HUNGARIAN_UMLAUT: // hung. umlaut { - pain.text(int(x2 - (font_metrics::rbearing('´', font) - font_metrics::lbearing('´', font))), + pi.pain.text(int(x2 - (font_metrics::rbearing('´', font) - font_metrics::lbearing('´', font))), baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2, '´', font); - pain.text(int(x2), + pi.pain.text(int(x2), baseline - font_metrics::ascent(ic, font) - font_metrics::descent('´', font) - (font_metrics::ascent('´', font) + font_metrics::descent('´', font)) / 2, '´', font); break; } case UMLAUT: // umlaut { - pain.text(int(x2 - (font_metrics::rbearing('¨', font) - font_metrics::lbearing('¨', font)) / 2), + pi.pain.text(int(x2 - (font_metrics::rbearing('¨', font) - font_metrics::lbearing('¨', font)) / 2), baseline - font_metrics::ascent(ic, font) - font_metrics::descent('¨', font) - (font_metrics::ascent('¨', font) + font_metrics::descent('¨', font)) / 2, '¨', font); break; @@ -544,7 +543,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, { LyXFont tmpf(font); tmpf.decSize().decSize().decSize(); - pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - font_metrics::lbearing(0x5E, tmpf)) / 2), + pi.pain.text(int(x2 - (font_metrics::rbearing(0x5E, tmpf) - font_metrics::lbearing(0x5E, tmpf)) / 2), int(baseline - font_metrics::ascent(ic, font) - font_metrics::descent(0x5E, tmpf) - (font_metrics::ascent(0x5E, tmpf) + font_metrics::descent(0x5E, tmpf)) / 3.0), char(0x5E), tmpf); break; @@ -567,7 +566,7 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, xp[3] = int(x2 + hg / 4.0); yp[3] = y + int(hg); - pain.lines(xp, yp, 4); + pi.pain.lines(xp, yp, 4); break; } case lSLASH: @@ -578,10 +577,10 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, xp[0] = int(x); yp[0] = y + int(3.0 * hg); - xp[1] = int(x + float(wid) * 0.75); + xp[1] = int(x + float(dim.wid) * 0.75); yp[1] = y + int(hg); - pain.lines(xp, yp, 2); + pi.pain.lines(xp, yp, 2); break; } case DOT_LESS_I: // dotless-i @@ -592,18 +591,13 @@ void InsetLatexAccent::draw(BufferView * bv, LyXFont const & font0, } } } else { - pain.fillRectangle(int(x + 1), - baseline - ascent(bv, font) + 1, - width(bv, font) - 2, - ascent(bv, font) - + descent(bv, font) - 2, - backgroundColor()); - pain.rectangle(int(x + 1), baseline - ascent(bv, font) + 1, - width(bv, font) - 2, - ascent(bv, font) + descent(bv, font) - 2); - pain.text(int(x + 2), baseline, contents, font); + pi.pain.fillRectangle(x + 1, + baseline - dim.asc + 1, dim.wid - 2, + dim.asc + dim.des - 2, backgroundColor()); + pi.pain.rectangle(x + 1, baseline - dim.asc + 1, + dim.wid - 2, dim.asc + dim.des - 2); + pi.pain.text(x + 2, baseline, contents, font); } - x += width(bv, font); } diff --git a/src/insets/insetlatexaccent.h b/src/insets/insetlatexaccent.h index 0fe5f86273..414369a5a9 100644 --- a/src/insets/insetlatexaccent.h +++ b/src/insets/insetlatexaccent.h @@ -36,14 +36,13 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// int lbearing(LyXFont const & font) const; /// int rbearing(LyXFont const & font) const; /// - bool displayISO8859_9(BufferView *, LyXFont const & font, - int baseline, float & x) const; + bool displayISO8859_9(PainterInfo & pi, int x, int y) const; /// void write(Buffer const *, std::ostream &) const; /// diff --git a/src/insets/insetnewline.C b/src/insets/insetnewline.C index dd38c7490d..0ac4e9a442 100644 --- a/src/insets/insetnewline.C +++ b/src/insets/insetnewline.C @@ -17,6 +17,7 @@ #include "dimension.h" #include "paragraph.h" #include "lyxtext.h" +#include "metricsinfo.h" #include "support/LOstream.h" #include "frontends/Painter.h" #include "frontends/font_metrics.h" @@ -75,18 +76,14 @@ int InsetNewline::docbook(Buffer const *, std::ostream &, bool) const } -void InsetNewline::draw(BufferView * bv, LyXFont const & font, - int baseline, float & x) const +void InsetNewline::draw(PainterInfo & pi, int x, int y) const { - Painter & pain(bv->painter()); - - int const wid = font_metrics::width('n', font); - int const asc = font_metrics::maxAscent(font); - int const y = baseline; + int const wid = font_metrics::width('n', pi.base.font); + int const asc = font_metrics::maxAscent(pi.base.font); // hack, and highly dubious lyx::pos_type pos = parOwner()->getPositionOfInset(this); - bool const ltr_pos = (bv->text->bidi_level(pos) % 2 == 0); + bool const ltr_pos = (pi.base.bv->text->bidi_level(pos) % 2 == 0); int xp[3]; int yp[3]; @@ -105,7 +102,7 @@ void InsetNewline::draw(BufferView * bv, LyXFont const & font, xp[2] = int(x + wid * 0.625); } - pain.lines(xp, yp, 3, LColor::eolmarker); + pi.pain.lines(xp, yp, 3, LColor::eolmarker); yp[0] = int(y - 0.500 * asc * 0.75); yp[1] = int(y - 0.500 * asc * 0.75); @@ -121,7 +118,5 @@ void InsetNewline::draw(BufferView * bv, LyXFont const & font, xp[2] = int(x); } - pain.lines(xp, yp, 3, LColor::eolmarker); - - x += wid; + pi.pain.lines(xp, yp, 3, LColor::eolmarker); } diff --git a/src/insets/insetnewline.h b/src/insets/insetnewline.h index 60de3b6140..7b4188f402 100644 --- a/src/insets/insetnewline.h +++ b/src/insets/insetnewline.h @@ -28,8 +28,7 @@ public: void dimension(BufferView *, LyXFont const &, Dimension &) const; - virtual void draw(BufferView *, LyXFont const &, - int baseline, float & x) const; + virtual void draw(PainterInfo & pi, int x, int y) const; virtual int latex(Buffer const *, std::ostream &, LatexRunParams const &) const; diff --git a/src/insets/insetquotes.C b/src/insets/insetquotes.C index 3a336968f3..24f44ff444 100644 --- a/src/insets/insetquotes.C +++ b/src/insets/insetquotes.C @@ -23,6 +23,7 @@ #include "lyxlex.h" #include "lyxrc.h" #include "paragraph.h" +#include "metricsinfo.h" #include "frontends/font_metrics.h" #include "frontends/Painter.h" #include "support/LAssert.h" @@ -202,18 +203,17 @@ LyXFont const InsetQuotes::convertFont(LyXFont const & f) const #endif -void InsetQuotes::draw(BufferView * bv, LyXFont const & font, - int baseline, float & x) const +void InsetQuotes::draw(PainterInfo & pi, int x, int y) const { - string const text = dispString(font.language()); + string const text = dispString(pi.base.font.language()); if (text.length() == 2 && text[0] == text[1]) { - bv->painter().text(int(x), baseline, text[0], font); - int x2 = int(x + font_metrics::width(',', font)); - bv->painter().text(x2, baseline, text[0], font); - } else - bv->painter().text(int(x), baseline, text, font); - x += width(bv, font); + pi.pain.text(x, y, text[0], pi.base.font); + int const t = font_metrics::width(',', pi.base.font); + pi.pain.text(x + t, y, text[0], pi.base.font); + } else { + pi.pain.text(x, y, text, pi.base.font); + } } diff --git a/src/insets/insetquotes.h b/src/insets/insetquotes.h index 29875c70a6..5816a1e86c 100644 --- a/src/insets/insetquotes.h +++ b/src/insets/insetquotes.h @@ -72,7 +72,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; #if 0 /// LyXFont const convertFont(LyXFont const & font) const; diff --git a/src/insets/insetspace.C b/src/insets/insetspace.C index 3ef75086d5..05f6beca52 100644 --- a/src/insets/insetspace.C +++ b/src/insets/insetspace.C @@ -24,6 +24,7 @@ #include "frontends/font_metrics.h" #include "lyxlex.h" #include "lyxfont.h" +#include "metricsinfo.h" using std::ostream; using std::max; @@ -73,31 +74,28 @@ void InsetSpace::dimension(BufferView *, LyXFont const & font, } -void InsetSpace::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetSpace::draw(PainterInfo & pi, int x, int y) const { - Painter & pain = bv->painter(); - LyXFont font(f); - - float w = width(bv, font); - int h = font_metrics::ascent('x', font); + int const w = width(pi.base.bv, pi.base.font); + int const h = font_metrics::ascent('x', pi.base.font); int xp[4], yp[4]; - xp[0] = int(x); yp[0] = baseline - max(h / 4, 1); + xp[0] = x; + yp[0] = y - max(h / 4, 1); if (kind_ == NORMAL) { - xp[1] = int(x); yp[1] = baseline; - xp[2] = int(x + w); yp[2] = baseline; + xp[1] = x; yp[1] = y; + xp[2] = x + w; yp[2] = y; } else { - xp[1] = int(x); yp[1] = baseline + max(h / 4, 1); - xp[2] = int(x + w); yp[2] = baseline + max(h / 4, 1); + xp[1] = x; yp[1] = y + max(h / 4, 1); + xp[2] = x + w; yp[2] = y + max(h / 4, 1); } - xp[3] = int(x + w); yp[3] = baseline - max(h / 4, 1); + xp[3] = x + w; + yp[3] = y - max(h / 4, 1); if (kind_ == PROTECTED || kind_ == ENSPACE || kind_ == NEGTHIN) - pain.lines(xp, yp, 4, LColor::latex); + pi.pain.lines(xp, yp, 4, LColor::latex); else - pain.lines(xp, yp, 4, LColor::special); - x += w; + pi.pain.lines(xp, yp, 4, LColor::special); } diff --git a/src/insets/insetspace.h b/src/insets/insetspace.h index 9a1a872e11..a124a670f2 100644 --- a/src/insets/insetspace.h +++ b/src/insets/insetspace.h @@ -56,7 +56,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void write(Buffer const *, std::ostream &) const; /// Will not be used when lyxf3 diff --git a/src/insets/insetspecialchar.C b/src/insets/insetspecialchar.C index 31e8c0a9ca..8a67a62141 100644 --- a/src/insets/insetspecialchar.C +++ b/src/insets/insetspecialchar.C @@ -22,6 +22,7 @@ #include "frontends/font_metrics.h" #include "lyxlex.h" #include "lyxfont.h" +#include "metricsinfo.h" using std::ostream; using std::max; @@ -58,56 +59,49 @@ void InsetSpecialChar::dimension(BufferView *, LyXFont const & font, } -void InsetSpecialChar::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetSpecialChar::draw(PainterInfo & pi, int x, int y) const { - Painter & pain = bv->painter(); - LyXFont font(f); + LyXFont font = pi.base.font; switch (kind_) { case HYPHENATION: { font.setColor(LColor::special); - pain.text(int(x), baseline, '-', font); - x += width(bv, font); + pi.pain.text(x, y, '-', font); break; } case LIGATURE_BREAK: { font.setColor(LColor::special); - pain.text(int(x), baseline, '|', font); - x += width(bv, font); + pi.pain.text(x, y, '|', font); break; } case END_OF_SENTENCE: { font.setColor(LColor::special); - pain.text(int(x), baseline, '.', font); - x += width(bv, font); + pi.pain.text(x, y, '.', font); break; } case LDOTS: { font.setColor(LColor::special); - pain.text(int(x), baseline, ". . .", font); - x += width(bv, font); + pi.pain.text(x, y, ". . .", font); break; } case MENU_SEPARATOR: { // A triangle the width and height of an 'x' int w = font_metrics::width('x', font); - int ox = font_metrics::width(' ', font) + int(x); + int ox = font_metrics::width(' ', font) + x; int h = font_metrics::ascent('x', font); int xp[4], yp[4]; - xp[0] = ox; yp[0] = baseline; - xp[1] = ox; yp[1] = baseline - h; - xp[2] = ox + w; yp[2] = baseline - h/2; - xp[3] = ox; yp[3] = baseline; + xp[0] = ox; yp[0] = y; + xp[1] = ox; yp[1] = y - h; + xp[2] = ox + w; yp[2] = y - h/2; + xp[3] = ox; yp[3] = y; - pain.lines(xp, yp, 4, LColor::special); - x += width(bv, font); + pi.pain.lines(xp, yp, 4, LColor::special); break; } } diff --git a/src/insets/insetspecialchar.h b/src/insets/insetspecialchar.h index bcca7aeab2..69264a4e82 100644 --- a/src/insets/insetspecialchar.h +++ b/src/insets/insetspecialchar.h @@ -48,7 +48,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void write(Buffer const *, std::ostream &) const; /// Will not be used when lyxf3 diff --git a/src/insets/insettabular.C b/src/insets/insettabular.C index c5096ba1e3..cf36af15f0 100644 --- a/src/insets/insettabular.C +++ b/src/insets/insettabular.C @@ -31,7 +31,7 @@ #include "ParagraphParameters.h" #include "undo_funcs.h" #include "WordLangTuple.h" -#include "Lsstream.h" +#include "metricsinfo.h" #include "frontends/Alert.h" #include "frontends/Dialogs.h" @@ -252,40 +252,39 @@ void InsetTabular::dimension(BufferView *, LyXFont const &, } -void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, - float & x) const +void InsetTabular::draw(PainterInfo & pi, int x, int y) const { if (nodraw()) { need_update = FULL; return; } - Painter & pain = bv->painter(); + BufferView * bv = pi.base.bv; int i; int j; int nx; #if 0 - UpdatableInset::draw(bv, font, baseline, x); + UpdatableInset::draw(pi, x, y); #else if (!owner()) - x += static_cast(scroll()); + x += scroll(); #endif - top_x = int(x); - top_baseline = baseline; + top_x = x; + top_baseline = y; x += ADD_TO_TABULAR_WIDTH; int cell = 0; - float cx; + int cx; first_visible_cell = -1; for (i = 0; i < tabular->rows(); ++i) { - nx = int(x); + nx = x; cell = tabular->GetCellNumber(i, 0); - if (!((baseline + tabular->GetDescentOfRow(i)) > 0) && - (baseline - tabular->GetAscentOfRow(i))GetDescentOfRow(i)) > 0) && + (y - tabular->GetAscentOfRow(i)) < pi.pain.paperHeight()) { - baseline += tabular->GetDescentOfRow(i) + + y += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i + 1) + tabular->GetAdditionalHeight(i + 1); continue; @@ -299,32 +298,30 @@ void InsetTabular::draw(BufferView * bv, LyXFont const & font, int baseline, if (first_visible_cell < 0) first_visible_cell = cell; if (hasSelection()) { - drawCellSelection(pain, nx, baseline, i, j, cell); + drawCellSelection(pi.pain, nx, y, i, j, cell); } - tabular->GetCellInset(cell)->draw(bv, font, baseline, cx); - drawCellLines(pain, nx, baseline, i, cell); + tabular->GetCellInset(cell)->draw(pi, cx, y); + drawCellLines(pi.pain, nx, y, i, cell); nx += tabular->GetWidthOfColumn(cell); ++cell; } // avoiding drawing the rest of a long table is // a pretty big speedup - if (baseline > bv->workHeight()) + if (y > bv->workHeight()) break; - baseline += tabular->GetDescentOfRow(i) + + y += tabular->GetDescentOfRow(i) + tabular->GetAscentOfRow(i + 1) + tabular->GetAdditionalHeight(i + 1); } - x -= ADD_TO_TABULAR_WIDTH; - x += width(bv, font); need_update = NONE; } -void InsetTabular::drawCellLines(Painter & pain, int x, int baseline, +void InsetTabular::drawCellLines(Painter & pain, int x, int y, int row, int cell) const { int x2 = x + tabular->GetWidthOfColumn(cell); @@ -332,34 +329,34 @@ void InsetTabular::drawCellLines(Painter & pain, int x, int baseline, if (!tabular->topAlreadyDrawn(cell)) { on_off = !tabular->TopLine(cell); - pain.line(x, baseline - tabular->GetAscentOfRow(row), - x2, baseline - tabular->GetAscentOfRow(row), + pain.line(x, y - tabular->GetAscentOfRow(row), + x2, y - tabular->GetAscentOfRow(row), on_off ? LColor::tabularonoffline : LColor::tabularline, on_off ? Painter::line_onoffdash : Painter::line_solid); } on_off = !tabular->BottomLine(cell); - pain.line(x, baseline + tabular->GetDescentOfRow(row), - x2, baseline + tabular->GetDescentOfRow(row), + pain.line(x, y + tabular->GetDescentOfRow(row), + x2, y + tabular->GetDescentOfRow(row), on_off ? LColor::tabularonoffline : LColor::tabularline, on_off ? Painter::line_onoffdash : Painter::line_solid); if (!tabular->leftAlreadyDrawn(cell)) { on_off = !tabular->LeftLine(cell); - pain.line(x, baseline - tabular->GetAscentOfRow(row), - x, baseline + tabular->GetDescentOfRow(row), + pain.line(x, y - tabular->GetAscentOfRow(row), + x, y + tabular->GetDescentOfRow(row), on_off ? LColor::tabularonoffline : LColor::tabularline, on_off ? Painter::line_onoffdash : Painter::line_solid); } on_off = !tabular->RightLine(cell); pain.line(x2 - tabular->GetAdditionalWidth(cell), - baseline - tabular->GetAscentOfRow(row), + y - tabular->GetAscentOfRow(row), x2 - tabular->GetAdditionalWidth(cell), - baseline + tabular->GetDescentOfRow(row), + y + tabular->GetDescentOfRow(row), on_off ? LColor::tabularonoffline : LColor::tabularline, on_off ? Painter::line_onoffdash : Painter::line_solid); } -void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline, +void InsetTabular::drawCellSelection(Painter & pain, int x, int y, int row, int column, int cell) const { lyx::Assert(hasSelection()); @@ -380,7 +377,7 @@ void InsetTabular::drawCellSelection(Painter & pain, int x, int baseline, if ((column >= cs) && (column <= ce) && (row >= rs) && (row <= re)) { int w = tabular->GetWidthOfColumn(cell); int h = tabular->GetAscentOfRow(row) + tabular->GetDescentOfRow(row)-1; - pain.fillRectangle(x, baseline - tabular->GetAscentOfRow(row) + 1, + pain.fillRectangle(x, y - tabular->GetAscentOfRow(row) + 1, w, h, LColor::selection); } } diff --git a/src/insets/insettabular.h b/src/insets/insettabular.h index dd7a91265b..93a9ef6f5c 100644 --- a/src/insets/insettabular.h +++ b/src/insets/insettabular.h @@ -88,7 +88,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, const LyXFont &, int , float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void update(BufferView *, bool = false); /// diff --git a/src/insets/insettext.C b/src/insets/insettext.C index c2e92f51d6..c7c3b74f28 100644 --- a/src/insets/insettext.C +++ b/src/insets/insettext.C @@ -39,7 +39,7 @@ #include "sgml.h" #include "rowpainter.h" #include "insetnewline.h" -#include "Lsstream.h" +#include "metricsinfo.h" #include "frontends/Alert.h" #include "frontends/Dialogs.h" @@ -321,38 +321,37 @@ int InsetText::textWidth(BufferView * bv, bool fordraw) const } -void InsetText::draw(BufferView * bv, LyXFont const & f, - int baseline, float & x) const +void InsetText::draw(PainterInfo & pi, int x, int baseline) const { if (nodraw()) return; // update our idea of where we are. Clearly, we should // not have to know this information. - if (top_x != int(x)) - top_x = int(x); + if (top_x != x) + top_x = x; - int const start_x = int(x); + int const start_x = x; - Painter & pain = bv->painter(); + BufferView * bv = pi.base.bv; + Painter & pain = pi.pain; // call this method so that dim_ has the right value - dimension(bv, f, dim_); + dimension(bv, pi.base.font, dim_); // repaint the background if needed if (backgroundColor() != LColor::background) clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline); // no draw is necessary !!! - if ((drawFrame_ == LOCKED) && !locked && paragraphs.begin()->empty()) { + if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) { top_baseline = baseline; - x += width(bv, f); need_update = NONE; return; } if (!owner()) - x += static_cast(scroll()); + x += scroll(); top_baseline = baseline; top_y = baseline - dim_.asc; diff --git a/src/insets/insettext.h b/src/insets/insettext.h index c37a5588f6..e1ad8a8788 100644 --- a/src/insets/insettext.h +++ b/src/insets/insettext.h @@ -91,7 +91,7 @@ public: /// int textWidth(BufferView *, bool fordraw = false) const; /// - void draw(BufferView *, LyXFont const &, int , float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void update(BufferView *, bool = false); /// diff --git a/src/insets/updatableinset.C b/src/insets/updatableinset.C index a01ec0f3bc..ec6fa2ba81 100644 --- a/src/insets/updatableinset.C +++ b/src/insets/updatableinset.C @@ -52,13 +52,11 @@ void UpdatableInset::fitInsetCursor(BufferView *) const {} -void UpdatableInset::draw(BufferView *, LyXFont const &, - int /* baseline */, float & x) const +void UpdatableInset::draw(PainterInfo &, int, int) const { - x += float(scx); // ATTENTION: don't do the following here!!! - // top_x = int(x); - // top_baseline = baseline; + // top_x = x; + // top_baseline = y; } diff --git a/src/insets/updatableinset.h b/src/insets/updatableinset.h index f41c02387b..77046dc1df 100644 --- a/src/insets/updatableinset.h +++ b/src/insets/updatableinset.h @@ -66,8 +66,7 @@ public: /// virtual void insetUnlock(BufferView *); /// - virtual void draw(BufferView *, LyXFont const &, - int baseline, float & x) const; + virtual void draw(PainterInfo & pi, int x, int y) const; /// virtual bool insertInset(BufferView *, Inset *) { return false; } /// diff --git a/src/mathed/formula.C b/src/mathed/formula.C index 5b1c8cc997..6ebf101eac 100644 --- a/src/mathed/formula.C +++ b/src/mathed/formula.C @@ -212,44 +212,42 @@ void InsetFormula::read(Buffer const *, LyXLex & lex) //} -void InsetFormula::draw(BufferView * bv, LyXFont const & font, - int y, float & xx) const +void InsetFormula::draw(PainterInfo & pi, int x, int y) const { - cache(bv); + cache(pi.base.bv); // This initiates the loading of the preview, so should come // before the metrics are computed. bool const use_preview = preview_->previewReady(); - int const x = int(xx); - int const w = width(bv, font); - int const d = descent(bv, font); - int const a = ascent(bv, font); + Dimension dim; + dimension(pi.base.bv, pi.base.font, dim); + int const w = dim.wid; + int const d = dim.des; + int const a = dim.asc; int const h = a + d; - PainterInfo pi(bv); - if (use_preview) { pi.pain.image(x + 1, y - a, w, h, // one pixel gap in front *(preview_->pimage()->image())); } else { - pi.base.style = LM_ST_TEXT; - pi.base.font = font; - pi.base.font.setColor(LColor::math); + PainterInfo p(pi.base.bv); + p.base.style = LM_ST_TEXT; + p.base.font = pi.base.font; + p.base.font.setColor(LColor::math); if (lcolor.getX11Name(LColor::mathbg) != lcolor.getX11Name(LColor::background)) - pi.pain.fillRectangle(x, y - a, w, h, LColor::mathbg); + p.pain.fillRectangle(x, y - a, w, h, LColor::mathbg); if (mathcursor && const_cast(mathcursor->formula()) == this) { mathcursor->drawSelection(pi); - //pi.pain.rectangle(x, y - a, w, h, LColor::mathframe); + //p.pain.rectangle(x, y - a, w, h, LColor::mathframe); } - par_->draw(pi, x, y); + par_->draw(p, x, y); } - xx += w; xo_ = x; yo_ = y; } diff --git a/src/mathed/formula.h b/src/mathed/formula.h index bab0e55c3b..201b71027a 100644 --- a/src/mathed/formula.h +++ b/src/mathed/formula.h @@ -37,7 +37,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void write(Buffer const *, std::ostream &) const; diff --git a/src/mathed/formulabase.h b/src/mathed/formulabase.h index 4482822ef7..691b8205f7 100644 --- a/src/mathed/formulabase.h +++ b/src/mathed/formulabase.h @@ -31,8 +31,6 @@ public: InsetFormulaBase(); /// Inset * clone(Buffer const &) const = 0; - /// - virtual void draw(BufferView *,LyXFont const &, int, float &) const = 0; /// lowest x coordinate virtual int xlow() const; /// highest x coordinate diff --git a/src/mathed/formulamacro.C b/src/mathed/formulamacro.C index d75a398617..6eeb17968f 100644 --- a/src/mathed/formulamacro.C +++ b/src/mathed/formulamacro.C @@ -171,20 +171,18 @@ Inset::Code InsetFormulaMacro::lyxCode() const } -void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, - int y, float & xx) const +void InsetFormulaMacro::draw(PainterInfo & p, int x, int y) const { // label - LyXFont font(f); + LyXFont font = p.base.font; font.setColor(LColor::math); - PainterInfo pi(bv); + PainterInfo pi(p.base.bv); pi.base.style = LM_ST_TEXT; pi.base.font = font; Dimension dim; - dimension(bv, font, dim); - int const x = int(xx); + dimension(pi.base.bv, font, dim); int const a = y - dim.asc + 1; int const w = dim.wid - 2; int const h = dim.height() - 2; @@ -200,8 +198,7 @@ void InsetFormulaMacro::draw(BufferView * bv, LyXFont const & f, pi.pain.text(x + 2, y, prefix(), font); // formula - par()->draw(pi, x + font_metrics::width(prefix(), f) + 5, y); - xx += w + 2; + par()->draw(pi, x + font_metrics::width(prefix(), p.base.font) + 5, y); xo_ = x; yo_ = y; } diff --git a/src/mathed/formulamacro.h b/src/mathed/formulamacro.h index 1d8f03027b..27f56c5920 100644 --- a/src/mathed/formulamacro.h +++ b/src/mathed/formulamacro.h @@ -35,7 +35,7 @@ public: /// void dimension(BufferView *, LyXFont const &, Dimension &) const; /// - void draw(BufferView *, LyXFont const &, int, float &) const; + void draw(PainterInfo & pi, int x, int y) const; /// void read(Buffer const *, LyXLex & lex); diff --git a/src/rowpainter.C b/src/rowpainter.C index 8a738fdc41..39745f1ecf 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -33,6 +33,7 @@ #include "rowpainter.h" #include "lyxrc.h" #include "lyxrow_funcs.h" +#include "metricsinfo.h" using std::max; using lyx::pos_type; @@ -103,12 +104,14 @@ void RowPainter::paintInset(pos_type const pos) lyx::Assert(inset); - LyXFont const & font = getFont(pos); - #warning inset->update FIXME inset->update(perv(bv_), false); - inset->draw(perv(bv_), font, yo_ + row_->baseline(), x_); + PainterInfo pi(perv(bv_)); + pi.base.font = getFont(pos); + int const w = inset->width(perv(bv_), pi.base.font); + inset->draw(pi, int(x_), yo_ + row_->baseline()); + x_ += w; }