]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathSupport.C
Fix comment according to Enricos explanation
[lyx.git] / src / mathed / MathSupport.C
index 23ad7351b88fa130943e922fb97ca378f2ec7029..8ae02b12406a89b6ed51581617c48d353f58ffe3 100644 (file)
@@ -14,7 +14,7 @@
 #include "MathSupport.h"
 #include "MathData.h"
 #include "InsetMath.h"
-#include "MathMLStream.h"
+#include "MathStream.h"
 #include "MathParser.h"
 
 #include "debug.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;
 
 
 ///
@@ -336,7 +338,7 @@ named_deco_struct deco_table[] = {
 };
 
 
-std::map<string, deco_struct> deco_list;
+std::map<docstring, deco_struct> deco_list;
 
 // sort the table on startup
 class init_deco_table {
@@ -347,7 +349,7 @@ public:
                        deco_struct d;
                        d.data  = p->data;
                        d.angle = p->angle;
-                       deco_list[p->name]= d;
+                       deco_list[from_ascii(p->name)] = d;
                }
        }
 };
@@ -355,41 +357,45 @@ public:
 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, lyx::char_type c, Dimension & dim)
+void mathed_char_dim(LyXFont const & font, char_type c, Dimension & dim)
 {
-       lyx::frontend::FontMetrics const & fm = theFontMetrics(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, lyx::char_type c)
+int mathed_char_width(LyXFont const & font, char_type c)
 {
        return theFontMetrics(font).width(c);
 }
 
 
-void mathed_string_dim(LyXFont const & font, docstring const & s, Dimension & dim)
+void mathed_string_dim(LyXFont const & font,
+                      docstring const & s,
+                      Dimension & dim)
 {
-       lyx::frontend::FontMetrics const & fm = theFontMetrics(font);
+       frontend::FontMetrics const & fm = theFontMetrics(font);
        dim.asc = 0;
        dim.des = 0;
-       for (docstring::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));
        }
-       dim.wid = fm.width(s);
+       dim.wid = fm.width(&s[0], s.size());
 }
 
 
@@ -400,7 +406,7 @@ int mathed_string_width(LyXFont const & font, docstring const & 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,
@@ -411,7 +417,7 @@ void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int 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;
        }
 
@@ -487,14 +493,14 @@ void drawStrBlack(PainterInfo & pi, int x, int y, docstring const & str)
 
 void math_font_max_dim(LyXFont const & font, int & asc, int & des)
 {
-       lyx::frontend::FontMetrics const & fm = theFontMetrics(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_;
@@ -594,10 +600,11 @@ fontinfo fontinfos[] = {
 };
 
 
-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;
@@ -607,7 +614,7 @@ fontinfo * lookupFont(string const & name)
 }
 
 
-fontinfo * searchFont(string const & name)
+fontinfo * searchFont(docstring const & name)
 {
        fontinfo * f = lookupFont(name);
        return f ? f : fontinfos;
@@ -616,13 +623,13 @@ fontinfo * searchFont(string const & name)
 }
 
 
-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);
@@ -630,7 +637,7 @@ LyXFont getFont(string const & 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);
@@ -640,22 +647,22 @@ void fakeFont(string const & orig, string const & 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 (!theFontLoader().available(getFont("mathfrak")))
-                       fakeFont("mathfrak", "lyxfakefrak");
-               if (!theFontLoader().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)
@@ -669,37 +676,37 @@ void augmentFont(LyXFont & font, string const & name)
 }
 
 
-string asString(MathArray const & ar)
+docstring asString(MathArray const & ar)
 {
-       lyx::odocstringstream os;
+       odocstringstream os;
        WriteStream ws(os);
        ws << ar;
-       // FIXME UNICODE
-       return lyx::to_utf8(os.str());
+       return os.str();
 }
 
 
 void asArray(docstring const & str, MathArray & ar)
 {
-       mathed_parse_cell(ar, lyx::to_utf8(str));
+       mathed_parse_cell(ar, str);
 }
 
 
-string asString(InsetMath const & inset)
+docstring asString(InsetMath const & inset)
 {
-       lyx::odocstringstream os;
+       odocstringstream os;
        WriteStream ws(os);
        inset.write(ws);
-       // FIXME UNICODE
-       return lyx::to_utf8(os.str());
+       return os.str();
 }
 
 
-string asString(MathAtom const & at)
+docstring asString(MathAtom const & at)
 {
-       lyx::odocstringstream os;
+       odocstringstream os;
        WriteStream ws(os);
        at->write(ws);
-       // FIXME UNICODE
-       return lyx::to_utf8(os.str());
+       return os.str();
 }
+
+
+} // namespace lyx