#include <config.h>
-#include <map>
-
#include "math_support.h"
#include "lyxfont.h"
-#include "frontends/font_loader.h"
-#include "frontends/font_metrics.h"
-#include "math_cursor.h"
-#include "math_defs.h"
#include "math_inset.h"
#include "math_parser.h"
+#include "metricsinfo.h"
+#include "math_data.h"
#include "frontends/Painter.h"
+#include "frontends/font_metrics.h"
+#include "frontends/lyx_gui.h"
#include "debug.h"
-#include "commandtags.h"
+#include "lfuns.h"
+#include "dimension.h"
+#include "Lsstream.h"
+#include "math_mathmlstream.h"
+
+#include <map>
-using std::map;
-using std::endl;
using std::max;
+using std::endl;
///
/*
* Internal struct of a drawing: code n x1 y1 ... xn yn, where code is:
- * 0 = end, 1 = line, 2 = polyline, 3 = square line, 4= square polyline
+ * 0 = end, 1 = line, 2 = polyline, 3 = square line, 4 = square polyline
*/
double const tilde[] = {
2, 4,
- 0.05, 0.8, 0.25, 0.2, 0.75, 0.8, 0.95, 0.2,
+ 0.00, 0.8, 0.25, 0.2, 0.75, 0.8, 1.00, 0.2,
0
};
{"check", angle, 1 },
{"breve", parenth, 1 },
{"vec", arrow, 3 },
- {"not", slash, 0 },
{"mathring", ring, 0 },
// Dots
+ {"dots", hline3, 0 },
{"ldots", hline3, 0 },
{"cdots", hline3, 0 },
{"vdots", hline3, 1 },
};
-map<string, deco_struct> deco_list;
+std::map<string, deco_struct> deco_list;
// sort the table on startup
struct init_deco_table {
deco_struct const * search_deco(string const & name)
{
- map<string, deco_struct>::const_iterator p = deco_list.find(name);
+ std::map<string, deco_struct>::const_iterator p = deco_list.find(name);
return (p == deco_list.end()) ? 0 : &(p->second);
}
} // namespace anon
-void mathed_char_dim(LyXFont const & font,
- unsigned char c, int & asc, int & des, int & wid)
+void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
{
- des = font_metrics::descent(c, font);
- asc = font_metrics::ascent(c, font);
- wid = mathed_char_width(font, c);
+ dim.des = font_metrics::descent(c, font);
+ dim.asc = font_metrics::ascent(c, font);
+ dim.wid = mathed_char_width(font, c);
}
}
-void mathed_string_dim(LyXFont const & font,
- string const & s, int & asc, int & des, int & wid)
+void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
{
- asc = des = 0;
+#if 1
+ dim.asc = 0;
+ dim.des = 0;
for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
- des = max(des, font_metrics::descent(*it, font));
- asc = max(asc, font_metrics::ascent(*it, font));
+ dim.asc = max(dim.asc, font_metrics::ascent(*it, font));
+ dim.des = max(dim.des, font_metrics::descent(*it, font));
}
- wid = font_metrics::width(s, font);
+#else
+ dim.asc = font_metrics::maxAscent(font);
+ dim.des = font_metrics::maxDescent(font);
+#endif
+ dim.wid = font_metrics::width(s, font);
}
}
-int mathed_string_ascent(LyXFont const & font, string const & s)
-{
- int asc = 0;
- for (string::const_iterator it = s.begin(); it != s.end(); ++it)
- asc = max(asc, font_metrics::ascent(*it, font));
- return asc;
-}
-
-
-int mathed_string_descent(LyXFont const & font, string const & s)
-{
- int des = 0;
- for (string::const_iterator it = s.begin(); it != s.end(); ++it)
- des = max(des, font_metrics::descent(*it, font));
- return des;
-}
-
-
-
-void mathed_draw_deco(MathPainterInfo & pi, int x, int y, int w, int h,
- const string & name)
+void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
+ string const & name)
{
if (name == ".") {
pi.pain.line(x + w/2, y, x + w/2, y + h,
- LColor::mathcursor, Painter::line_onoffdash);
+ LColor::cursor, Painter::line_onoffdash);
return;
}
deco_struct const * mds = search_deco(name);
if (!mds) {
- lyxerr << "Deco was not found. Programming error?\n";
- lyxerr << "name: '" << name << "'\n";
+ lyxerr << "Deco was not found. Programming error?" << endl;
+ lyxerr << "name: '" << name << "'" << endl;
return;
}
mt.transform(xx, yy);
mt.transform(x2, y2);
pi.pain.line(
- x + int(xx + 0.5), y + int(yy + 0.5),
- x + int(x2 + 0.5), y + int(y2 + 0.5),
+ int(x + xx + 0.5), int(y + yy + 0.5),
+ int(x + x2 + 0.5), int(y + y2 + 0.5),
LColor::math);
} else {
int xp[32];
for (int j = 0; j < n; ++j) {
double xx = d[i++];
double yy = d[i++];
-// lyxerr << " " << xx << " " << yy << " ";
+// lyxerr << ' ' << xx << ' ' << yy << ' ';
if (code == 4)
sqmt.transform(xx, yy);
else
mt.transform(xx, yy);
- xp[j] = x + int(xx + 0.5);
- yp[j] = y + int(yy + 0.5);
- // lyxerr << "P[" << j " " << xx << " " << yy << " " << x << " " << y << "]";
+ xp[j] = int(x + xx + 0.5);
+ yp[j] = int(y + yy + 0.5);
+ // lyxerr << "P[" << j ' ' << xx << ' ' << yy << ' ' << x << ' ' << y << ']';
}
pi.pain.lines(xp, yp, n, LColor::math);
}
}
-void mathed_draw_framebox(MathPainterInfo & pi, int x, int y, MathInset const * p)
-{
- if (mathcursor && mathcursor->isInside(p))
- pi.pain.rectangle(x, y - p->ascent(), p->width(), p->height(),
- LColor::mathframe);
-}
-
-
// In the future maybe we use a better fonts renderer
-void drawStr(MathPainterInfo & pi, LyXFont const & font,
+void drawStr(PainterInfo & pi, LyXFont const & font,
int x, int y, string const & str)
{
pi.pain.text(x, y, str, font);
}
-void drawStrRed(MathPainterInfo & pi, int x, int y, string const & str)
+void drawStrRed(PainterInfo & pi, int x, int y, string const & str)
{
LyXFont f = pi.base.font;
f.setColor(LColor::latex);
}
-void drawStrBlack(MathPainterInfo & pi, int x, int y, string const & str)
+void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
{
LyXFont f = pi.base.font;
- f.setColor(LColor::black);
+ f.setColor(LColor::foreground);
pi.pain.text(x, y, str, f);
}
-void drawChar(MathPainterInfo & pi, LyXFont const & font, int x, int y, char c)
+void drawChar(PainterInfo & pi, LyXFont const & font, int x, int y, char c)
{
pi.pain.text(x, y, c, font);
}
}
-string convertDelimToLatexName(string const & name)
-{
- if (name == "(")
- return name;
- if (name == "[")
- return name;
- if (name == ".")
- return name;
- if (name == ")")
- return name;
- if (name == "]")
- return name;
- if (name == "/")
- return name;
- if (name == "|")
- return name;
- return "\\" + name + " ";
-}
-
-
-
-
struct fontinfo {
string cmd_;
LyXFont::FONT_FAMILY family_;
};
-LyXFont::FONT_FAMILY const def_family = LyXFont::INHERIT_FAMILY;
-LyXFont::FONT_SERIES const def_series = LyXFont::INHERIT_SERIES;
-LyXFont::FONT_SHAPE const def_shape = LyXFont::INHERIT_SHAPE;
-
+LyXFont::FONT_FAMILY const inh_family = LyXFont::INHERIT_FAMILY;
+LyXFont::FONT_SERIES const inh_series = LyXFont::INHERIT_SERIES;
+LyXFont::FONT_SHAPE const inh_shape = LyXFont::INHERIT_SHAPE;
+// mathnormal should be the first, otherwise the fallback further down
+// does not work
fontinfo fontinfos[] = {
- {"cmex", LyXFont::CMEX_FAMILY, def_series, def_shape, LColor::math},
- {"cmm", LyXFont::CMM_FAMILY, def_series, def_shape, LColor::math},
- {"cmr", LyXFont::CMR_FAMILY, def_series, def_shape, LColor::math},
- {"cmsy", LyXFont::CMSY_FAMILY, def_series, def_shape, LColor::math},
- {"eufrak", LyXFont::EUFRAK_FAMILY, def_series, def_shape, LColor::math},
- {"mathbf", def_family, LyXFont::BOLD_SERIES, def_shape, LColor::math},
- {"mathcal",LyXFont::CMSY_FAMILY, def_series, def_shape, LColor::math},
- {"mathnormal", def_family,def_series, LyXFont::UP_SHAPE, LColor::math},
- {"mathrm", LyXFont::ROMAN_FAMILY, def_series, def_shape, LColor::math},
- {"mathsf", LyXFont::SANS_FAMILY, def_series, def_shape, LColor::math},
- {"msa", LyXFont::MSA_FAMILY, def_series, def_shape, LColor::math},
- {"msb", LyXFont::MSB_FAMILY, def_series, def_shape, LColor::math},
- {"textbf", def_family, LyXFont::BOLD_SERIES, def_shape, LColor::black},
- {"textit", def_family, def_series, LyXFont::ITALIC_SHAPE, LColor::black},
- {"textmd", def_family, LyXFont::MEDIUM_SERIES, def_shape, LColor::black},
- {"textnormal", def_family, def_series, LyXFont::UP_SHAPE, LColor::black},
- {"textrm", LyXFont::ROMAN_FAMILY, def_series,LyXFont::UP_SHAPE,LColor::black},
- {"textsc", def_family, def_series, LyXFont::SMALLCAPS_SHAPE, LColor::black},
- {"textsf", LyXFont::SANS_FAMILY, def_series, def_shape, LColor::black},
- {"textsl", def_family, def_series, LyXFont::SLANTED_SHAPE, LColor::black},
- {"texttt", LyXFont::TYPEWRITER_FAMILY, def_series, def_shape, LColor::black},
- {"textup", def_family, def_series, LyXFont::UP_SHAPE, LColor::black},
-
- {"lyxtex", def_family, def_series, def_shape, LColor::latex},
- {"lyxsymbol", LyXFont::SYMBOL_FAMILY, def_series, def_shape, LColor::math},
- {"lyxitsymbol", LyXFont::SYMBOL_FAMILY, def_series, LyXFont::ITALIC_SHAPE, LColor::math},
+ // math fonts
+ {"mathnormal", inh_family, LyXFont::MEDIUM_SERIES,
+ LyXFont::UP_SHAPE, LColor::math},
+ {"mathbf", inh_family, LyXFont::BOLD_SERIES,
+ inh_shape, LColor::math},
+ {"mathcal", LyXFont::CMSY_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"mathfrak", LyXFont::EUFRAK_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"mathrm", LyXFont::ROMAN_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"mathsf", LyXFont::SANS_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"mathbb", LyXFont::MSB_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"mathtt", LyXFont::TYPEWRITER_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"cmex", LyXFont::CMEX_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"cmm", LyXFont::CMM_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"cmr", LyXFont::CMR_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"cmsy", LyXFont::CMSY_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"eufrak", LyXFont::EUFRAK_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"msa", LyXFont::MSA_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"msb", LyXFont::MSB_FAMILY, inh_series,
+ inh_shape, LColor::none},
+ {"wasy", LyXFont::WASY_FAMILY, inh_series,
+ inh_shape, LColor::none},
+
+ // Text fonts
+ {"text", inh_family, inh_series,
+ inh_shape, LColor::foreground},
+ {"textbf", inh_family, LyXFont::BOLD_SERIES,
+ inh_shape, LColor::foreground},
+ {"textit", inh_family, inh_series,
+ LyXFont::ITALIC_SHAPE, LColor::foreground},
+ {"textmd", inh_family, LyXFont::MEDIUM_SERIES,
+ inh_shape, LColor::foreground},
+ {"textnormal", inh_family, inh_series,
+ LyXFont::UP_SHAPE, LColor::foreground},
+ {"textrm", LyXFont::ROMAN_FAMILY,
+ inh_series,LyXFont::UP_SHAPE,LColor::foreground},
+ {"textsc", inh_family, inh_series,
+ LyXFont::SMALLCAPS_SHAPE, LColor::foreground},
+ {"textsf", LyXFont::SANS_FAMILY, inh_series,
+ inh_shape, LColor::foreground},
+ {"textsl", inh_family, inh_series,
+ LyXFont::SLANTED_SHAPE, LColor::foreground},
+ {"texttt", LyXFont::TYPEWRITER_FAMILY, inh_series,
+ inh_shape, LColor::foreground},
+ {"textup", inh_family, inh_series,
+ LyXFont::UP_SHAPE, LColor::foreground},
+
+ // TIPA support
+ {"textipa", inh_family, inh_series,
+ inh_shape, LColor::foreground},
+
+ // LyX internal usage
+ {"lyxtex", inh_family, inh_series,
+ inh_shape, LColor::latex},
+ {"lyxert", LyXFont::TYPEWRITER_FAMILY, inh_series,
+ inh_shape, LColor::latex},
+ {"lyxsymbol", LyXFont::SYMBOL_FAMILY, inh_series,
+ inh_shape, LColor::math},
+ {"lyxboldsymbol", LyXFont::SYMBOL_FAMILY, LyXFont::BOLD_SERIES,
+ inh_shape, LColor::math},
+ {"lyxitsymbol", LyXFont::SYMBOL_FAMILY, inh_series,
+ LyXFont::ITALIC_SHAPE, LColor::math},
+ {"lyxblacktext", LyXFont::ROMAN_FAMILY, LyXFont::MEDIUM_SERIES,
+ LyXFont::UP_SHAPE, LColor::foreground},
+ {"lyxnochange", inh_family, inh_series,
+ inh_shape, LColor::foreground},
+ {"lyxfakebb", LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES,
+ LyXFont::UP_SHAPE, LColor::math},
+ {"lyxfakecal", LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES,
+ LyXFont::ITALIC_SHAPE, LColor::math},
+ {"lyxfakefrak", LyXFont::ROMAN_FAMILY, LyXFont::BOLD_SERIES,
+ LyXFont::ITALIC_SHAPE, LColor::math}
};
-fontinfo * searchFont(string const & name)
+fontinfo * lookupFont(string const & name)
{
+ //lyxerr << "searching font '" << name << "'" << endl;
int const n = sizeof(fontinfos) / sizeof(fontinfo);
- //lyxerr << "searching font '" << name << "'\n";
for (int i = 0; i < n; ++i)
if (fontinfos[i].cmd_ == name) {
- //lyxerr << "found '" << i << "'\n";
+ //lyxerr << "found '" << i << "'" << endl;
return fontinfos + i;
}
- return searchFont("mathnormal");
+ return 0;
}
-void augmentFont(LyXFont & font, string const & name)
+fontinfo * searchFont(string const & name)
{
- static bool initialized = false;
-
- if (!initialized) {
- initialized = true;
+ fontinfo * f = lookupFont(name);
+ return f ? f : fontinfos;
+ // this should be mathnormal
+ //return searchFont("mathnormal");
+}
- LyXFont f1;
- augmentFont(f1, "msb");
- if (!fontloader.available(f1)) {
- lyxerr << "faking msb\n";
- fontinfo * info = searchFont("msb");
- info->family_ = LyXFont::TYPEWRITER_FAMILY;
- info->series_ = LyXFont::BOLD_SERIES;
- }
- LyXFont f2;
- augmentFont(f2, "msex");
- if (!fontloader.available(f2)) {
- lyxerr << "faking msex\n";
- fontinfo * info = searchFont("msex");
- info->family_ = LyXFont::SANS_FAMILY;
- info->series_ = LyXFont::BOLD_SERIES;
- info->shape_ = LyXFont::ITALIC_SHAPE;
- }
+bool isFontName(string const & name)
+{
+ return lookupFont(name);
+}
- //{"fakebb", LyXFont::TYPEWRITER_FAMILY, LyXFont::BOLD_SERIES,
- // LyXFont::UP_SHAPE, LColor::math},
- //{"fakecal", LyXFont::SANS_FAMILY, LyXFont::MEDIUM_SERIES,
- // LyXFont::ITALIC_SHAPE, LColor::math},
- //{"fakefrak", LyXFont::SANS_FAMILY, LyXFont::BOLD_SERIES,
- // LyXFont::ITALIC_SHAPE, LColor::math}
+LyXFont getFont(string const & name)
+{
+ LyXFont font;
+ augmentFont(font, name);
+ return font;
+}
+
+
+void fakeFont(string const & orig, string const & fake)
+{
+ fontinfo * forig = searchFont(orig);
+ fontinfo * ffake = searchFont(fake);
+ if (forig && ffake) {
+ forig->family_ = ffake->family_;
+ forig->series_ = ffake->series_;
+ forig->shape_ = ffake->shape_;
+ forig->color_ = ffake->color_;
+ } else {
+ lyxerr << "Can't fake font '" << orig << "' with '"
+ << fake << "'" << endl;
}
+}
+void augmentFont(LyXFont & font, string const & name)
+{
+ static bool initialized = false;
+ if (!initialized) {
+ initialized = true;
+ // fake fonts if necessary
+ if (!lyx_gui::font_available(getFont("mathfrak")))
+ fakeFont("mathfrak", "lyxfakefrak");
+ if (!lyx_gui::font_available(getFont("mathcal")))
+ fakeFont("mathcal", "lyxfakecal");
+ }
fontinfo * info = searchFont(name);
- if (info->family_ != def_family)
+ if (info->family_ != inh_family)
font.setFamily(info->family_);
-
- if (info->series_ != def_series)
+ if (info->series_ != inh_series)
font.setSeries(info->series_);
-
- if (info->shape_ != def_shape)
+ if (info->shape_ != inh_shape)
font.setShape(info->shape_);
-
if (info->color_ != LColor::none)
font.setColor(info->color_);
}
-bool math_font_available(string const & /*name*/)
+string asString(MathArray const & ar)
+{
+ std::ostringstream os;
+ WriteStream ws(os);
+ ws << ar;
+ return STRCONV(os.str());
+}
+
+
+void asArray(string const & str, MathArray & ar)
{
- return true;
+ mathed_parse_cell(ar, str);
}