+2005-06-16 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * LColor.[Ch] (getFromLaTeXName): new
+
2005-06-16 Martin Vermeer <martin.vermeer@hut.fi>
* text.C (readParagraph): fix bug 1904 (GUI affects LaTeX)
namespace {
struct ColorEntry {
- int lcolor;
+ LColor::color lcolor;
char const * guiname;
char const * latexname;
char const * x11name;
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;
};
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";
}
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);
}
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;
}
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];
}
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;
+2005-06-16 Georg Baum <Georg.Baum@post.rwth-aachen.de>
+
+ * 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 <lasgouttes@lyx.org>
* math_hullinset.C (label): avoid warning when assertions are
#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)
{}
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_;
}
#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;
mutable int w_;
///
bool oldstyle_;
+ /// Our color. Only valid LaTeX colors are allowed.
+ std::string color_;
};
#endif
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));
#include <config.h>
#include "math_charinset.h"
+#include "math_colorinset.h"
#include "math_data.h"
#include "math_extern.h"
#include "math_hullinset.h"
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);
}
}
#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"
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);
}
}
#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"
}
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;
}