#include "MathSupport.h"
#include "MathData.h"
#include "InsetMath.h"
-#include "MathMLStream.h"
+#include "MathStream.h"
#include "MathParser.h"
#include "debug.h"
#include "LColor.h"
-#include "frontends/Application.h"
#include "frontends/FontLoader.h"
#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
#include <map>
#include <sstream>
-using lyx::docstring;
-using lyx::frontend::Painter;
-using std::string;
+namespace lyx {
+
+using frontend::Painter;
+
using std::max;
using std::endl;
+using std::vector;
///
};
-std::map<string, deco_struct> deco_list;
+std::map<docstring, deco_struct> deco_list;
// sort the table on startup
class init_deco_table {
deco_struct d;
d.data = p->data;
d.angle = p->angle;
- deco_list[p->name]= d;
+ deco_list[from_ascii(p->name)] = d;
}
}
};
static init_deco_table dummy;
-deco_struct const * search_deco(string const & name)
+deco_struct const * search_deco(docstring const & name)
{
- std::map<string, deco_struct>::const_iterator p = deco_list.find(name);
- return (p == deco_list.end()) ? 0 : &(p->second);
+ std::map<docstring, 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, Dimension & dim)
+void mathed_char_dim(LyXFont const & font, char_type c, Dimension & dim)
{
- lyx::frontend::FontMetrics const & fm =
- theApp->fontLoader().metrics(font);
+ frontend::FontMetrics const & fm = theFontMetrics(font);
dim.des = fm.descent(c);
dim.asc = fm.ascent(c);
dim.wid = fm.width(c);
}
-int mathed_char_width(LyXFont const & font, unsigned char c)
+int mathed_char_width(LyXFont const & font, char_type c)
{
- return theApp->fontLoader().metrics(font).width(c);
+ return theFontMetrics(font).width(c);
}
-void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
+void mathed_string_dim(LyXFont const & font,
+ docstring const & s,
+ Dimension & dim)
{
- lyx::frontend::FontMetrics const & fm =
- theApp->fontLoader().metrics(font);
-#if 1
+ frontend::FontMetrics const & fm = theFontMetrics(font);
dim.asc = 0;
dim.des = 0;
- for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
+ for (docstring::const_iterator it = s.begin();
+ it != s.end();
+ ++it) {
dim.asc = max(dim.asc, fm.ascent(*it));
dim.des = max(dim.des, fm.descent(*it));
}
-#else
- dim.asc = fm.maxAscent();
- dim.des = fm.maxDescent();
-#endif
- docstring ds(s.begin(), s.end());
- dim.wid = fm.width(ds);
+ dim.wid = fm.width(&s[0], s.size());
}
-int mathed_string_width(LyXFont const & font, string const & s)
+int mathed_string_width(LyXFont const & font, docstring const & s)
{
- docstring ds(s.begin(), s.end());
- return theApp->fontLoader().metrics(font).width(ds);
+ return theFontMetrics(font).width(s);
}
void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
- string const & name)
+ docstring const & name)
{
if (name == ".") {
pi.pain.line(x + w/2, y, x + w/2, y + h,
deco_struct const * mds = search_deco(name);
if (!mds) {
lyxerr << "Deco was not found. Programming error?" << endl;
- lyxerr << "name: '" << name << "'" << endl;
+ lyxerr << "name: '" << to_utf8(name) << "'" << endl;
return;
}
}
-void drawStrRed(PainterInfo & pi, int x, int y, string const & str)
+void drawStrRed(PainterInfo & pi, int x, int y, docstring const & str)
{
LyXFont f = pi.base.font;
f.setColor(LColor::latex);
- docstring dstr(str.begin(), str.end());
- pi.pain.text(x, y, dstr, f);
+ pi.pain.text(x, y, str, f);
}
-void drawStrBlack(PainterInfo & pi, int x, int y, string const & str)
+void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str)
{
LyXFont f = pi.base.font;
f.setColor(LColor::foreground);
- docstring dstr(str.begin(), str.end());
- pi.pain.text(x, y, dstr, f);
+ pi.pain.text(x, y, str, f);
}
void math_font_max_dim(LyXFont const & font, int & asc, int & des)
{
- lyx::frontend::FontMetrics const & fm =
- theApp->fontLoader().metrics(font);
+ frontend::FontMetrics const & fm = theFontMetrics(font);
asc = fm.maxAscent();
des = fm.maxDescent();
}
struct fontinfo {
- string cmd_;
+ std::string cmd_;
LyXFont::FONT_FAMILY family_;
LyXFont::FONT_SERIES series_;
LyXFont::FONT_SHAPE shape_;
};
-fontinfo * lookupFont(string const & name)
+fontinfo * lookupFont(docstring const & name0)
{
//lyxerr << "searching font '" << name << "'" << endl;
int const n = sizeof(fontinfos) / sizeof(fontinfo);
+ std::string name = to_utf8(name0);
for (int i = 0; i < n; ++i)
if (fontinfos[i].cmd_ == name) {
//lyxerr << "found '" << i << "'" << endl;
}
-fontinfo * searchFont(string const & name)
+fontinfo * searchFont(docstring const & name)
{
fontinfo * f = lookupFont(name);
return f ? f : fontinfos;
}
-bool isFontName(string const & name)
+bool isFontName(docstring const & name)
{
return lookupFont(name);
}
-LyXFont getFont(string const & name)
+LyXFont getFont(docstring const & name)
{
LyXFont font;
augmentFont(font, name);
}
-void fakeFont(string const & orig, string const & fake)
+void fakeFont(docstring const & orig, docstring const & fake)
{
fontinfo * forig = searchFont(orig);
fontinfo * ffake = searchFont(fake);
forig->shape_ = ffake->shape_;
forig->color_ = ffake->color_;
} else {
- lyxerr << "Can't fake font '" << orig << "' with '"
- << fake << "'" << endl;
+ lyxerr << "Can't fake font '" << to_utf8(orig) << "' with '"
+ << to_utf8(fake) << "'" << endl;
}
}
-void augmentFont(LyXFont & font, string const & name)
+void augmentFont(LyXFont & font, docstring const & name)
{
static bool initialized = false;
if (!initialized) {
initialized = true;
// fake fonts if necessary
- if (!theApp->fontLoader().available(getFont("mathfrak")))
- fakeFont("mathfrak", "lyxfakefrak");
- if (!theApp->fontLoader().available(getFont("mathcal")))
- fakeFont("mathcal", "lyxfakecal");
+ if (!theFontLoader().available(getFont(from_ascii("mathfrak"))))
+ fakeFont(from_ascii("mathfrak"), from_ascii("lyxfakefrak"));
+ if (!theFontLoader().available(getFont(from_ascii("mathcal"))))
+ fakeFont(from_ascii("mathcal"), from_ascii("lyxfakecal"));
}
fontinfo * info = searchFont(name);
if (info->family_ != inh_family)
}
-string asString(MathArray const & ar)
+docstring asString(MathArray const & ar)
{
- std::ostringstream os;
+ odocstringstream os;
WriteStream ws(os);
ws << ar;
return os.str();
}
-void asArray(string const & str, MathArray & ar)
+void asArray(docstring const & str, MathArray & ar)
{
mathed_parse_cell(ar, str);
}
-string asString(InsetMath const & inset)
+docstring asString(InsetMath const & inset)
{
- std::ostringstream os;
+ odocstringstream os;
WriteStream ws(os);
inset.write(ws);
return os.str();
}
-string asString(MathAtom const & at)
+docstring asString(MathAtom const & at)
{
- std::ostringstream os;
+ odocstringstream os;
WriteStream ws(os);
at->write(ws);
return os.str();
}
+
+
+} // namespace lyx