#include "debug.h"
#include "LColor.h"
+#include "frontends/FontLoader.h"
+#include "frontends/FontMetrics.h"
#include "frontends/Painter.h"
-#include "frontends/font_metrics.h"
-#include "frontends/lyx_gui.h"
#include <map>
#include <sstream>
} // namespace anon
-void mathed_char_dim(LyXFont const & font, unsigned char c, Dimension & dim)
+void mathed_char_dim(LyXFont const & font, lyx::char_type c, Dimension & dim)
{
- dim.des = font_metrics::descent(c, font);
- dim.asc = font_metrics::ascent(c, font);
- dim.wid = mathed_char_width(font, c);
+ lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
+ dim.des = fm.descent(c);
+ dim.asc = fm.ascent(c);
+ dim.wid = fm.width(c);
}
-int mathed_char_ascent(LyXFont const & font, unsigned char c)
+int mathed_char_width(LyXFont const & font, lyx::char_type c)
{
- return font_metrics::ascent(c, font);
+ return theFontMetrics(font).width(c);
}
-int mathed_char_descent(LyXFont const & font, unsigned char c)
+void mathed_string_dim(LyXFont const & font, docstring const & s, Dimension & dim)
{
- return font_metrics::descent(c, font);
-}
-
-
-int mathed_char_width(LyXFont const & font, unsigned char c)
-{
- return font_metrics::width(c, font);
-}
-
-
-void mathed_string_dim(LyXFont const & font, string const & s, Dimension & dim)
-{
-#if 1
+ lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
dim.asc = 0;
dim.des = 0;
- for (string::const_iterator it = s.begin(); it != s.end(); ++it) {
- dim.asc = max(dim.asc, font_metrics::ascent(*it, font));
- dim.des = max(dim.des, font_metrics::descent(*it, font));
+ 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 = font_metrics::maxAscent(font);
- dim.des = font_metrics::maxDescent(font);
-#endif
- docstring ds(s.begin(), s.end());
- dim.wid = font_metrics::width(ds, font);
+ dim.wid = fm.width(s);
}
-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 font_metrics::width(ds, font);
+ return theFontMetrics(font).width(s);
}
}
-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)
{
- asc = font_metrics::maxAscent(font);
- des = font_metrics::maxDescent(font);
+ lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
+ asc = fm.maxAscent();
+ des = fm.maxDescent();
}
if (!initialized) {
initialized = true;
// fake fonts if necessary
- if (!lyx_gui::font_available(getFont("mathfrak")))
+ if (!theFontLoader().available(getFont("mathfrak")))
fakeFont("mathfrak", "lyxfakefrak");
- if (!lyx_gui::font_available(getFont("mathcal")))
+ if (!theFontLoader().available(getFont("mathcal")))
fakeFont("mathcal", "lyxfakecal");
}
fontinfo * info = searchFont(name);
string asString(MathArray const & ar)
{
- std::ostringstream os;
+ lyx::odocstringstream os;
WriteStream ws(os);
ws << ar;
- return os.str();
+ // FIXME UNICODE
+ return lyx::to_utf8(os.str());
}
-void asArray(string const & str, MathArray & ar)
+void asArray(docstring const & str, MathArray & ar)
{
- mathed_parse_cell(ar, str);
+ mathed_parse_cell(ar, lyx::to_utf8(str));
}
string asString(InsetMath const & inset)
{
- std::ostringstream os;
+ lyx::odocstringstream os;
WriteStream ws(os);
inset.write(ws);
- return os.str();
+ // FIXME UNICODE
+ return lyx::to_utf8(os.str());
}
string asString(MathAtom const & at)
{
- std::ostringstream os;
+ lyx::odocstringstream os;
WriteStream ws(os);
at->write(ws);
- return os.str();
+ // FIXME UNICODE
+ return lyx::to_utf8(os.str());
}