Juergen Spitzmueller wrote: > Georg, I lost track in my mailbox. Can you please post again the final > version for testing?
Here it is. Georg
Index: src/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/ChangeLog,v retrieving revision 1.2199 diff -u -p -r1.2199 ChangeLog --- src/ChangeLog 9 Jun 2005 15:19:06 -0000 1.2199 +++ src/ChangeLog 14 Jun 2005 09:58:47 -0000 @@ -1,3 +1,7 @@ +2005-06-14 Georg Baum <[EMAIL PROTECTED]> + + * LColor.[Ch] (getFromLaTeXName): new + 2005-06-11 Georg Baum <[EMAIL PROTECTED]> * LaTeXFeatures.C (getPackages): solve amsmath-wasysym conflict Index: src/LColor.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LColor.h,v retrieving revision 1.44 diff -u -p -r1.44 LColor.h --- src/LColor.h 19 Jan 2005 15:03:27 -0000 1.44 +++ src/LColor.h 15 Jun 2005 14:39:58 -0000 @@ -218,6 +218,8 @@ public: LColor::color getFromGUIName(std::string const & guiname) const; /// \returns the LColor::color associated with the LyX name. LColor::color getFromLyXName(std::string const & lyxname) const; + /// \returns the LColor::color associated with the LaTeX name. + LColor::color getFromLaTeXName(std::string const & latexname) const; private: /// void addColor(LColor::color c, std::string const & lyxname) const; Index: src/LColor.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/LColor.C,v retrieving revision 1.55 diff -u -p -r1.55 LColor.C --- src/LColor.C 19 Jan 2005 15:03:27 -0000 1.55 +++ src/LColor.C 15 Jun 2005 14:40:03 -0000 @@ -33,7 +33,7 @@ using std::string; namespace { struct ColorEntry { - int lcolor; + LColor::color lcolor; char const * guiname; char const * latexname; char const * x11name; @@ -61,22 +61,25 @@ public: void fill(ColorEntry const & entry) { information in; - in.lyxname = string(entry.lyxname); - in.latexname = string(entry.latexname); - in.x11name = string(entry.x11name); - in.guiname = string(entry.guiname); + in.lyxname = entry.lyxname; + in.latexname = entry.latexname; + in.x11name = entry.x11name; + in.guiname = entry.guiname; infotab[entry.lcolor] = in; - transform[string(entry.lyxname)] = int(entry.lcolor); + lyxcolors[entry.lyxname] = entry.lcolor; + latexcolors[entry.latexname] = entry.lcolor; } /// - typedef std::map<int, information> InfoTab; + typedef std::map<LColor::color, information> InfoTab; /// the table of color information InfoTab infotab; - typedef std::map<string, int> Transform; - /// the transform between colour name string and integer code. - Transform transform; + typedef std::map<string, LColor::color> Transform; + /// the transform between LyX color name string and integer code. + Transform lyxcolors; + /// the transform between LaTeX color name string and integer code. + Transform latexcolors; }; @@ -185,7 +188,7 @@ string const LColor::getX11Name(LColor:: return it->second.x11name; lyxerr << "LyX internal error: Missing color" - " entry in LColor.C for " << int(c) << '\n' + " entry in LColor.C for " << c << '\n' << "Using black." << endl; return "black"; } @@ -234,15 +237,14 @@ bool LColor::setColor(LColor::color col, bool LColor::setColor(string const & lyxname, string const &x11name) { string const lcname = ascii_lowercase(lyxname); - if (pimpl_->transform.find(lcname) == pimpl_->transform.end()) { + if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) { lyxerr[Debug::GUI] << "LColor::setColor: Unknown color \"" << lyxname << '"' << endl; addColor(static_cast<color>(pimpl_->infotab.size()), lcname); } - return setColor(static_cast<LColor::color>(pimpl_->transform[lcname]), - x11name); + return setColor(pimpl_->lyxcolors[lcname], x11name); } @@ -252,7 +254,7 @@ LColor::color LColor::getFromGUIName(str Pimpl::InfoTab::const_iterator end = pimpl_->infotab.end(); for (; it != end; ++it) { if (!compare_ascii_no_case(_(it->second.guiname), guiname)) - return static_cast<LColor::color>(it->first); + return it->first; } return LColor::inherit; } @@ -268,13 +270,25 @@ void LColor::addColor(LColor::color c, s LColor::color LColor::getFromLyXName(string const & lyxname) const { string const lcname = ascii_lowercase(lyxname); - if (pimpl_->transform.find(lcname) == pimpl_->transform.end()) { + if (pimpl_->lyxcolors.find(lcname) == pimpl_->lyxcolors.end()) { lyxerr << "LColor::getFromLyXName: Unknown color \"" << lyxname << '"' << endl; return none; } - return static_cast<LColor::color>(pimpl_->transform[lcname]); + return pimpl_->lyxcolors[lcname]; +} + + +LColor::color LColor::getFromLaTeXName(string const & latexname) const +{ + if (pimpl_->latexcolors.find(latexname) == pimpl_->latexcolors.end()) { + lyxerr << "LColor::getFromLaTeXName: Unknown color \"" + << latexname << '"' << endl; + return none; + } + + return pimpl_->latexcolors[latexname]; } Index: src/mathed/ChangeLog =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/ChangeLog,v retrieving revision 1.499 diff -u -p -r1.499 ChangeLog --- src/mathed/ChangeLog 9 Jun 2005 12:17:50 -0000 1.499 +++ src/mathed/ChangeLog 14 Jun 2005 10:00:07 -0000 @@ -1,3 +1,23 @@ +2005-06-14 Georg Baum <[EMAIL PROTECTED]> + + * math_colorinset.C (normalcolor): remove ... + * math_colorinset.C (latexcolor): ... and use this new function instead + * math_colorinset.C (metrics, draw): Don't draw cell(0), because it + is horrible UI + * math_colorinset.C (write): Don't write invalid colors + * math_colorinset.C: Store always the LaTeXName in cell(0) + * math_hullinset.C (handleFont2): adjust to the change above + * math_nestinset.C (handleFont2): ditto + * math_parser.C (parse): handle \textcolor and \normalcolor + * math_factory.C (createMathInset): ditto + 2005-06-08 Jean-Marc Lasgouttes <[EMAIL PROTECTED]> * math_hullinset.C (label): avoid warning when assertions are Index: src/mathed/math_colorinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_colorinset.C,v retrieving revision 1.12 diff -u -p -r1.12 math_colorinset.C --- src/mathed/math_colorinset.C 9 Apr 2005 11:13:21 -0000 1.12 +++ src/mathed/math_colorinset.C 15 Jun 2005 09:22:45 -0000 @@ -13,29 +13,36 @@ #include "math_colorinset.h" #include "math_data.h" #include "math_mathmlstream.h" +#include "math_streamstr.h" #include "math_support.h" #include "LaTeXFeatures.h" -#include "LColor.h" #include "support/std_ostream.h" using std::auto_ptr; +using std::string; namespace { -// color "none" (reset to default) needs special treatment -bool normalcolor(MathArray const & ar) +/// color "none" (reset to default) needs special treatment +bool normalcolor(string const & color) { - return (asString(ar) == "none"); + return color == "none"; } } // namespace anon -MathColorInset::MathColorInset(bool oldstyle) - : MathNestInset(2), oldstyle_(oldstyle) +MathColorInset::MathColorInset(bool oldstyle, LColor_color const & color) + : MathNestInset(1), oldstyle_(oldstyle), + color_(lcolor.getLaTeXName(color)) +{} + + +MathColorInset::MathColorInset(bool oldstyle, string const & color) + : MathNestInset(1), oldstyle_(oldstyle), color_(color) {} @@ -47,70 +54,50 @@ auto_ptr<InsetBase> MathColorInset::doCl void MathColorInset::metrics(MetricsInfo & mi, Dimension & dim) const { - cell(1).metrics(mi, dim); - if (editing(mi.base.bv)) { - FontSetChanger dummy(mi.base, "textnormal"); - cell(0).metrics(mi); - dim += cell(0).dim(); - w_ = mathed_char_width(mi.base.font, '['); - dim.asc += 4; - dim.des += 4; - dim.wid += 2 * w_ + 4; - metricsMarkers(dim); - } + cell(0).metrics(mi, dim); + metricsMarkers(dim); dim_ = dim; } void MathColorInset::draw(PainterInfo & pi, int x, int y) const { - int const x0(x); - if (editing(pi.base.bv)) { - 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; - } - LColor_color origcol = pi.base.font.color(); - pi.base.font.setColor(lcolor.getFromGUIName(asString(cell(0)))); - cell(1).draw(pi, x, y); + pi.base.font.setColor(lcolor.getFromLaTeXName(color_)); + cell(0).draw(pi, x + 1, y); pi.base.font.setColor(origcol); - if (editing(pi.base.bv)) - setPosCache(pi, x0, y); + drawMarkers(pi, x, y); + setPosCache(pi, x, y); } void MathColorInset::validate(LaTeXFeatures & features) const { MathNestInset::validate(features); - if (!normalcolor(cell(0))) + if (!normalcolor(color_)) features.require("color"); } void MathColorInset::write(WriteStream & os) const { - if (normalcolor(cell(0))) - os << "{\\normalcolor " << cell(1) << '}'; + if (normalcolor(color_)) + // reset to default color inside another color inset + os << "{\\normalcolor " << cell(0) << '}'; else if (oldstyle_) - os << "{\\color" << '{' << cell(0) << '}' << cell(1) << '}'; + os << "{\\color" << '{' << color_ << '}' << cell(0) << '}'; else - os << "\\textcolor" << '{' << cell(0) << "}{" << cell(1) << '}'; + os << "\\textcolor" << '{' << color_ << "}{" << cell(0) << '}'; } void MathColorInset::normalize(NormalStream & os) const { - os << "[color " << cell(0) << ' ' << cell(1) << ']'; + os << "[color " << color_ << ' ' << cell(0) << ']'; } void MathColorInset::infoize(std::ostream & os) const { - os << "Color: " << cell(0); + os << "Color: " << color_; } Index: src/mathed/math_colorinset.h =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_colorinset.h,v retrieving revision 1.4 diff -u -p -r1.4 math_colorinset.h --- src/mathed/math_colorinset.h 23 Nov 2004 23:04:50 -0000 1.4 +++ src/mathed/math_colorinset.h 15 Jun 2005 09:22:45 -0000 @@ -12,17 +12,23 @@ #ifndef MATH_COLORINSET_H #define MATH_COLORINSET_H +#include "LColor.h" + #include "math_nestinset.h" /// Change colours. class MathColorInset : public MathNestInset { public: - /// - explicit MathColorInset(bool oldstyle); + /// Create a color inset from LyX color number + explicit MathColorInset(bool oldstyle, + LColor_color const & color = LColor::none); + /// Create a color inset from LaTeX color name + explicit MathColorInset(bool oldstyle, std::string const & color); /// void metrics(MetricsInfo & mi, Dimension & dim) const; /// we write extra braces in any case... + /// FIXME Why? Are they necessary if oldstyle_ == false? bool extraBraces() const { return true; } /// void draw(PainterInfo & pi, int x, int y) const; @@ -40,6 +46,8 @@ private: mutable int w_; /// bool oldstyle_; + /// Our color. Only valid LaTeX colors are allowed. + std::string color_; }; #endif Index: src/mathed/math_factory.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_factory.C,v retrieving revision 1.111 diff -u -p -r1.111 math_factory.C --- src/mathed/math_factory.C 7 Jun 2005 17:21:51 -0000 1.111 +++ src/mathed/math_factory.C 14 Jun 2005 10:00:07 -0000 @@ -323,7 +328,7 @@ MathAtom createMathInset(string const & return MathAtom(new MathLefteqnInset); if (s == "boldsymbol") return MathAtom(new MathBoldsymbolInset); - if (s == "color") + if (s == "color" || s == "normalcolor") return MathAtom(new MathColorInset(true)); if (s == "textcolor") return MathAtom(new MathColorInset(false)); Index: src/mathed/math_hullinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_hullinset.C,v retrieving revision 1.166 diff -u -p -r1.166 math_hullinset.C --- src/mathed/math_hullinset.C 9 Jun 2005 12:17:50 -0000 1.166 +++ src/mathed/math_hullinset.C 14 Jun 2005 10:00:08 -0000 @@ -11,6 +11,7 @@ #include <config.h> #include "math_charinset.h" +#include "math_colorinset.h" #include "math_data.h" #include "math_extern.h" #include "math_hullinset.h" @@ -1214,9 +1303,8 @@ void MathHullInset::handleFont2(LCursor bool b; bv_funcs::string2font(arg, font, b); if (font.color() != LColor::inherit) { - MathAtom at = createMathInset("color"); - asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0)); - cur.handleNest(at, 1); + MathAtom at = MathAtom(new MathColorInset(true, font.color())); + cur.handleNest(at, 0); } } Index: src/mathed/math_nestinset.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_nestinset.C,v retrieving revision 1.155 diff -u -p -r1.155 math_nestinset.C --- src/mathed/math_nestinset.C 9 Jun 2005 09:58:07 -0000 1.155 +++ src/mathed/math_nestinset.C 14 Jun 2005 10:00:08 -0000 @@ -15,6 +15,7 @@ #include "math_arrayinset.h" #include "math_boxinset.h" #include "math_braceinset.h" +#include "math_colorinset.h" #include "math_commentinset.h" #include "math_data.h" #include "math_deliminset.h" @@ -394,9 +396,8 @@ void MathNestInset::handleFont2(LCursor bool b; bv_funcs::string2font(arg, font, b); if (font.color() != LColor::inherit) { - MathAtom at = createMathInset("color"); - asArray(lcolor.getGUIName(font.color()), at.nucleus()->cell(0)); - cur.handleNest(at, 1); + MathAtom at = MathAtom(new MathColorInset(true, font.color())); + cur.handleNest(at, 0); } } Index: src/mathed/math_parser.C =================================================================== RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/mathed/math_parser.C,v retrieving revision 1.312 diff -u -p -r1.312 math_parser.C --- src/mathed/math_parser.C 2 Mar 2005 14:26:12 -0000 1.312 +++ src/mathed/math_parser.C 14 Jun 2005 10:00:08 -0000 @@ -42,6 +42,7 @@ following hack as starting point to writ #include "math_arrayinset.h" #include "math_braceinset.h" #include "math_charinset.h" +#include "math_colorinset.h" #include "math_commentinset.h" #include "math_deliminset.h" #include "math_envinset.h" @@ -1207,10 +1224,21 @@ void Parser::parse1(MathGridInset & grid } else if (t.cs() == "color") { - MathAtom at = createMathInset(t.cs()); - parse(at.nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE); - parse(at.nucleus()->cell(1), flags, mode); - cell->push_back(at); + string const color = parse_verbatim_item(); + cell->push_back(MathAtom(new MathColorInset(true, color))); + parse(cell->back().nucleus()->cell(0), flags, mode); + return; + } + + else if (t.cs() == "textcolor") { + string const color = parse_verbatim_item(); + cell->push_back(MathAtom(new MathColorInset(false, color))); + parse(cell->back().nucleus()->cell(0), FLAG_ITEM, MathInset::TEXT_MODE); + } + + else if (t.cs() == "normalcolor") { + cell->push_back(createMathInset(t.cs())); + parse(cell->back().nucleus()->cell(0), flags, mode); return; }