From: André Pönitz Date: Thu, 2 Oct 2003 13:41:00 +0000 (+0000) Subject: support for color in math X-Git-Tag: 1.6.10~16013 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=45d3b8c89c1489b02a744f4bce2aa20d1f64cac6;p=lyx.git support for color in math git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7851 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index 97cdf58834..3d70f1e480 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -35,6 +35,8 @@ libmathed_la_SOURCES = \ math_casesinset.h \ math_charinset.C \ math_charinset.h \ + math_colorinset.C \ + math_colorinset.h \ math_commentinset.C \ math_commentinset.h \ math_cursor.C \ diff --git a/src/mathed/formulabase.C b/src/mathed/formulabase.C index 75c1e3dc9b..1b7fc257b1 100644 --- a/src/mathed/formulabase.C +++ b/src/mathed/formulabase.C @@ -305,7 +305,7 @@ dispatch_result InsetFormulaBase::localDispatch(FuncRequest const & cmd) { lyxerr << "InsetFormulaBase::localDispatch: act: " << cmd.action << " arg: '" << cmd.argument - << " x: '" << cmd.x + << "' x: '" << cmd.x << " y: '" << cmd.y << "' button: " << cmd.button() << endl; diff --git a/src/mathed/math_charinset.C b/src/mathed/math_charinset.C index c1823681e8..b8aa90f030 100644 --- a/src/mathed/math_charinset.C +++ b/src/mathed/math_charinset.C @@ -64,8 +64,8 @@ void MathCharInset::metrics(MetricsInfo & mi, Dimension & dim) const } else if ((char_ == '>' || char_ == '<') && has_math_fonts) { FontSetChanger dummy(mi.base, "cmm"); mathed_char_dim(mi.base.font, char_, dim); - } else if (slanted(char_) && mi.base.fontname == "mathnormal") { - ShapeChanger dummy(mi.base.font, LyXFont::ITALIC_SHAPE); + } else if (!slanted(char_) && mi.base.fontname == "mathnormal") { + ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE); mathed_char_dim(mi.base.font, char_, dim); } else { mathed_char_dim(mi.base.font, char_, dim); @@ -100,8 +100,8 @@ void MathCharInset::draw(PainterInfo & pi, int x, int y) const } else if ((char_ == '>' || char_ == '<') && has_math_fonts) { FontSetChanger dummy(pi.base, "cmm"); pi.draw(x, y, char_); - } else if (slanted(char_) && pi.base.fontname == "mathnormal") { - ShapeChanger dummy(pi.base.font, LyXFont::ITALIC_SHAPE); + } else if (!slanted(char_) && pi.base.fontname == "mathnormal") { + ShapeChanger dummy(pi.base.font, LyXFont::UP_SHAPE); pi.draw(x, y, char_); } else { pi.draw(x, y, char_); diff --git a/src/mathed/math_colorinset.C b/src/mathed/math_colorinset.C new file mode 100644 index 0000000000..6c4bdf527d --- /dev/null +++ b/src/mathed/math_colorinset.C @@ -0,0 +1,88 @@ +/** + * \file math_colorinset.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_colorinset.h" +#include "math_data.h" +#include "math_mathmlstream.h" +#include "math_support.h" + +#include "LaTeXFeatures.h" + +#include "support/std_ostream.h" + +using std::auto_ptr; + + +MathColorInset::MathColorInset() + : MathNestInset(2) +{} + + +auto_ptr MathColorInset::clone() const +{ + return auto_ptr(new MathColorInset(*this)); +} + + +void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const +{ + FontSetChanger dummy(mi.base, "textnormal"); + w_ = mathed_char_width(mi.base.font, '['); + MathNestInset::metrics(mi); + dim_ = cell(0).dim(); + dim_ += cell(1).dim(); + dim_.wid += 2 * w_ + 4; + metricsMarkers(); + dim = dim_; +} + + +void MathColorInset::draw(PainterInfo & pi, int x, int y) const +{ + FontSetChanger dummy(pi.base, "textnormal"); + drawMarkers(pi, x, y); + + drawStrBlack(pi, x, y, "["); + x += w_; + cell(0).draw(pi, x, y); + x += cell(0).width(); + drawStrBlack(pi, x, y, "]"); + x += w_ + 2; + + ColorChanger dummy1(pi.base.font, asString(cell(0))); + cell(1).draw(pi, x, y); +} + + +void MathColorInset::validate(LaTeXFeatures & features) const +{ + MathNestInset::validate(features); + features.require("color"); +} + + +void MathColorInset::write(WriteStream & os) const +{ + os << "\\color" << '{' << cell(0) << '}' << '{' << cell(1) << '}'; +} + + +void MathColorInset::normalize(NormalStream & os) const +{ + os << "[color " << cell(0) << ' ' << cell(1) << ']'; +} + + +void MathColorInset::infoize(std::ostream & os) const +{ + os << "Color: " << cell(0); +} diff --git a/src/mathed/math_colorinset.h b/src/mathed/math_colorinset.h new file mode 100644 index 0000000000..f5ced87654 --- /dev/null +++ b/src/mathed/math_colorinset.h @@ -0,0 +1,42 @@ +// -*- C++ -*- +/** + * \file math_colorinset.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_COLORINSET_H +#define MATH_COLORINSET_H + +#include "math_nestinset.h" + +/// Change colours. + +class MathColorInset : public MathNestInset { +public: + /// + MathColorInset(); + /// + virtual std::auto_ptr clone() const; + /// + void metrics(MetricsInfo & mi, Dimension & dim) const; + /// + void draw(PainterInfo & pi, int x, int y) const; + /// we need package color + void validate(LaTeXFeatures & features) const; + /// + void write(WriteStream & os) const; + /// write normalized content + void normalize(NormalStream & ns) const; + /// + void infoize(std::ostream & os) const; +private: + /// width of '[' in current font + mutable int w_; +}; + +#endif diff --git a/src/mathed/math_factory.C b/src/mathed/math_factory.C index aafbd98609..446212aed1 100644 --- a/src/mathed/math_factory.C +++ b/src/mathed/math_factory.C @@ -18,6 +18,7 @@ #include "math_boxinset.h" #include "math_boldsymbolinset.h" #include "math_casesinset.h" +#include "math_colorinset.h" #include "math_decorationinset.h" #include "math_dotsinset.h" #include "math_ertinset.h" @@ -309,6 +310,8 @@ MathAtom createMathInset(string const & s) return MathAtom(new MathErtInset); if (s == "boldsymbol") return MathAtom(new MathBoldsymbolInset); + if (s == "color") + return MathAtom(new MathColorInset); if (MathMacroTable::has(s)) return MathAtom(new MathMacro(s)); diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 8d0b6b6202..05427f6554 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -175,6 +175,7 @@ char const * MathHullInset::standardFont() const { if (type_ == "none") return "lyxnochange"; + lyxerr << "standard font: mathnormal\n"; return "mathnormal"; } diff --git a/src/mathed/math_makeboxinset.C b/src/mathed/math_makeboxinset.C index 8d97d54ea6..cf3325b329 100644 --- a/src/mathed/math_makeboxinset.C +++ b/src/mathed/math_makeboxinset.C @@ -15,6 +15,8 @@ #include "math_mathmlstream.h" #include "math_support.h" +#include "support/std_ostream.h" + using std::auto_ptr; @@ -80,3 +82,10 @@ void MathMakeboxInset::normalize(NormalStream & os) const { os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']'; } + + +void MathMakeboxInset::infoize(std::ostream & os) const +{ + os << "Makebox (width: " << cell(0) + << " pos: " << cell(1) << ")"; +} diff --git a/src/mathed/math_makeboxinset.h b/src/mathed/math_makeboxinset.h index ee31ad239b..b6e8a8d582 100644 --- a/src/mathed/math_makeboxinset.h +++ b/src/mathed/math_makeboxinset.h @@ -33,6 +33,8 @@ public: void normalize(NormalStream & ns) const; /// mode_type currentMode() const { return TEXT_MODE; } + /// + void infoize(std::ostream & os) const; private: /// width of '[' in current font mutable int w_; diff --git a/src/mathed/math_support.C b/src/mathed/math_support.C index 9f127cce3e..b1844f1c30 100644 --- a/src/mathed/math_support.C +++ b/src/mathed/math_support.C @@ -534,7 +534,7 @@ LyXFont::FONT_SHAPE const inh_shape = LyXFont::INHERIT_SHAPE; fontinfo fontinfos[] = { // math fonts {"mathnormal", inh_family, LyXFont::MEDIUM_SERIES, - LyXFont::UP_SHAPE, LColor::math}, + LyXFont::ITALIC_SHAPE, LColor::math}, {"mathbf", inh_family, LyXFont::BOLD_SERIES, inh_shape, LColor::math}, {"mathcal", LyXFont::CMSY_FAMILY, inh_series,