]> git.lyx.org Git - lyx.git/commitdiff
support for color in math
authorAndré Pönitz <poenitz@gmx.net>
Thu, 2 Oct 2003 13:41:00 +0000 (13:41 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Thu, 2 Oct 2003 13:41:00 +0000 (13:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7851 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/formulabase.C
src/mathed/math_charinset.C
src/mathed/math_colorinset.C [new file with mode: 0644]
src/mathed/math_colorinset.h [new file with mode: 0644]
src/mathed/math_factory.C
src/mathed/math_hullinset.C
src/mathed/math_makeboxinset.C
src/mathed/math_makeboxinset.h
src/mathed/math_support.C

index 97cdf588345d30adb71f40e6eb89da2dd1ad23c7..3d70f1e480421eb9d96aa20247c5ffdb4b9e878c 100644 (file)
@@ -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 \
index 75c1e3dc9b9207a1f5be0b3d1da29f0ecd6e9000..1b7fc257b1da3766f2f9a43a2c375229ccc15aab 100644 (file)
@@ -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;
 
index c1823681e84897dfa90e211d6064149973668843..b8aa90f030cec6ce639b90538a8e77c8ffdbc985 100644 (file)
@@ -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 (file)
index 0000000..6c4bdf5
--- /dev/null
@@ -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 <config.h>
+
+#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<InsetBase> MathColorInset::clone() const
+{
+       return auto_ptr<InsetBase>(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 (file)
index 0000000..f5ced87
--- /dev/null
@@ -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<InsetBase> 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
index aafbd98609718e9971f71dcc40b7ad175c76c01c..446212aed13b53b5b55b5ee84b263f6d21f93bc4 100644 (file)
@@ -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));
index 8d0b6b62020a97ab7bd29688a5d5627a9a410441..05427f6554ee21ca8b9470c9cec934b3dabd590d 100644 (file)
@@ -175,6 +175,7 @@ char const * MathHullInset::standardFont() const
 {
        if (type_ == "none")
                return "lyxnochange";
+       lyxerr << "standard font: mathnormal\n";
        return "mathnormal";
 }
 
index 8d97d54ea6c14a079e9aed4940795bac4dcbf7e9..cf3325b329be3920507d5dcc0101eefc85c27f60 100644 (file)
@@ -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) << ")";
+}
index ee31ad239b5e82a2db62da6511170c142dc718fa..b6e8a8d58266e432797f521a5ae3b12193974e2b 100644 (file)
@@ -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_;
index 9f127cce3e7cbe020826383c917781bf6b264b36..b1844f1c3040c47ee4c27ab2a4f515b864fc452a 100644 (file)
@@ -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,