From cb5af90a1b8636405b89f5808fb3c4fb12cd3d21 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 22 Aug 2003 16:01:13 +0000 Subject: [PATCH] support for \overset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7594 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 2 ++ src/mathed/math_factory.C | 3 ++ src/mathed/math_oversetinset.C | 63 ++++++++++++++++++++++++++++++++++ src/mathed/math_oversetinset.h | 36 +++++++++++++++++++ src/rowpainter.C | 2 +- src/text.C | 6 ++-- src/text2.C | 1 + 7 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 src/mathed/math_oversetinset.C create mode 100644 src/mathed/math_oversetinset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 0f0efffca6..b39f933fe5 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -106,6 +106,8 @@ libmathed_la_SOURCES = \ math_nestinset.h \ math_numberinset.C \ math_numberinset.h \ + math_oversetinset.C \ + math_oversetinset.h \ math_parboxinset.C \ math_parboxinset.h \ math_parinset.C \ diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index b4e6418d60..eaa9be204b 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -31,6 +31,7 @@ #include "math_macrotemplate.h" #include "math_macroarg.h" #include "math_makeboxinset.h" +#include "math_oversetinset.h" #include "math_parboxinset.h" #include "math_rootinset.h" #include "math_sizeinset.h" @@ -237,6 +238,8 @@ MathAtom createMathInset(string const & s) inset << '\'' << endl; if (inset == "ref") return MathAtom(new RefInset(l->name)); + if (inset == "overset") + return MathAtom(new MathOversetInset); if (inset == "underset") return MathAtom(new MathUndersetInset); if (inset == "decoration") diff --git a/src/mathed/math_oversetinset.C b/src/mathed/math_oversetinset.C new file mode 100644 index 0000000000..a3beef89cb --- /dev/null +++ b/src/mathed/math_oversetinset.C @@ -0,0 +1,63 @@ +/** + * \file math_oversetinset.C + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#include + +#include "math_oversetinset.h" +#include "math_mathmlstream.h" +#include "math_support.h" + + +using std::max; +using std::auto_ptr; + + +MathOversetInset::MathOversetInset() +{} + + +auto_ptr MathOversetInset::clone() const +{ + return auto_ptr(new MathOversetInset(*this)); +} + + +void MathOversetInset::metrics(MetricsInfo & mi, Dimension & dim) const +{ + cell(1).metrics(mi); + FracChanger dummy(mi.base); + cell(0).metrics(mi); + dim_.wid = max(cell(0).width(), cell(1).width()) + 4; + dim_.asc = cell(1).ascent() + cell(0).height() + 4; + dim_.des = cell(1).descent(); + dim = dim_; +} + + +void MathOversetInset::draw(PainterInfo & pi, int x, int y) const +{ + int m = x + pi.width / 2; + int yo = y - cell(1).ascent() + cell(0).descent() + 1; + cell(1).draw(pi, m - cell(1).width() / 2, y); + FracChanger dummy(pi.base); + cell(0).draw(pi, m - cell(0).width() / 2, yo); +} + + +void MathOversetInset::write(WriteStream & os) const +{ + os << "\\overset{" << cell(0) << "}{" << cell(1) << '}'; +} + + +void MathOversetInset::normalize(NormalStream & os) const +{ + os << "[overset " << cell(0) << ' ' << cell(1) << ']'; +} diff --git a/src/mathed/math_oversetinset.h b/src/mathed/math_oversetinset.h new file mode 100644 index 0000000000..5327339cef --- /dev/null +++ b/src/mathed/math_oversetinset.h @@ -0,0 +1,36 @@ +// -*- C++ -*- +/** + * \file math_oversetinset.h + * This file is part of LyX, the document processor. + * Licence details can be found in the file COPYING. + * + * \author André Pönitz + * + * Full author contact details are available in file CREDITS. + */ + +#ifndef MATH_OVERSETINSET_H +#define MATH_OVERSETINSET_H + + +#include "math_fracbase.h" + +/// Inset for overset +class MathOversetInset : public MathFracbaseInset { +public: + /// + MathOversetInset(); + /// + virtual std::auto_ptr clone() const; + /// + void metrics(MetricsInfo & mi, Dimension & dim) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + + /// + void write(WriteStream & os) const; + /// + void normalize(NormalStream &) const; +}; + +#endif diff --git a/src/rowpainter.C b/src/rowpainter.C index 199ffd05aa..ca819fb2e6 100644 --- a/src/rowpainter.C +++ b/src/rowpainter.C @@ -1047,7 +1047,7 @@ int paintRows(BufferView const & bv, LyXText const & text, int xo, int y, int yf, int yo) { lyxerr << " paintRows: rit: " << &*rit << endl; - const_cast(text).updateRowPositions(); + //const_cast(text).updateRowPositions(); int const yy = yf - y; int const y2 = bv.painter().paperHeight(); diff --git a/src/text.C b/src/text.C index 95526633e3..ea7c612912 100644 --- a/src/text.C +++ b/src/text.C @@ -84,12 +84,12 @@ void LyXText::updateRowPositions() { ParagraphList::iterator pit = ownerParagraphs().begin(); ParagraphList::iterator end = ownerParagraphs().end(); - for (int y = 0; pit != end; ++pit) { + for (height = 0; pit != end; ++pit) { RowList::iterator rit = pit->rows.begin(); RowList::iterator rend = pit->rows.end(); for ( ; rit != rend ; rit = ++rit) { - rit->y(y); - y += rit->height(); + rit->y(height); + height += rit->height(); } } } diff --git a/src/text2.C b/src/text2.C index aa00774ce1..ff18daf87a 100644 --- a/src/text2.C +++ b/src/text2.C @@ -604,6 +604,7 @@ void LyXText::metrics(MetricsInfo & mi, Dimension & dim) //anchor_y_ = 0; redoParagraphs(ownerParagraphs().begin(), ownerParagraphs().end()); + updateRowPositions(); // final dimension dim.asc = firstRow()->ascent_of_text(); -- 2.39.2