]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/InsetMathChar.cpp
* zh_TW.po: Update from Mingyi Wu
[lyx.git] / src / mathed / InsetMathChar.cpp
index e1d64ec866c2c94dc25a1c68825f48bb6c85413d..03bda07cf60475c4ebaae4584ea401c613fccc12 100644 (file)
@@ -18,7 +18,7 @@
 #include "MetricsInfo.h"
 
 #include "Dimension.h"
-#include "Encoding.h"
+#include "BufferEncodings.h"
 #include "LaTeXFeatures.h"
 #include "TextPainter.h"
 
@@ -140,8 +140,8 @@ void InsetMathChar::write(WriteStream & os) const
 
 void InsetMathChar::validate(LaTeXFeatures & features) const
 {
-       if (char_ >= 0x80)
-               encodings.validate(char_, features, true);
+       if (!isASCII(char_))
+               BufferEncodings::validate(char_, features, true);
 }
 
 
@@ -172,35 +172,70 @@ void InsetMathChar::mathmlize(MathStream & ms) const
                case '<': entity = "&lt;"; break;
                case '>': entity = "&gt;"; break;
                case '&': entity = "&amp;"; break;
-               case ' ': 
-                       if (!ms.inText())
-                               break;
-                       entity = "&ThinSpace;";
-                       break;
+               case ' ': {
+                       ms << from_ascii("&nbsp;");
+                       return;
+               }
                default: break;
        }
        
        if (ms.inText()) {
                if (entity.empty())
-                       ms << char_type(char_);
+                       ms.os().put(char_);
                else 
                        ms << from_ascii(entity);
                return;
        }
-       
+
        if (!entity.empty()) {
                ms << "<mo>" << from_ascii(entity) << "</mo>";
                return;
        }               
 
        char const * type = 
-               (isalpha(char_) || Encodings::isMathAlpha(char_))
+               (isAlphaASCII(char_) || Encodings::isMathAlpha(char_))
                        ? "mi" : "mo";
        // we don't use MTag and ETag because we do not want the spacing
        ms << "<" << type << ">" << char_type(char_) << "</" << type << ">";    
 }
 
 
+void InsetMathChar::htmlize(HtmlStream & ms) const
+{
+       std::string entity;
+       switch (char_) {
+               case '<': entity = "&lt;"; break;
+               case '>': entity = "&gt;"; break;
+               case '&': entity = "&amp;"; break;
+               case ' ': entity = "&nbsp;"; break;
+               default: break;
+       }
+       
+       bool have_entity = !entity.empty();
+       
+       if (ms.inText()) {
+               if (have_entity)
+                       ms << from_ascii(entity);
+               else
+                       ms.os().put(char_);
+               return;
+       }
+       
+       if (have_entity) {
+               // an operator, so give some space
+               ms << ' ' << from_ascii(entity) << ' ';
+               return;
+       }               
+
+       if (isAlphaASCII(char_) || Encodings::isMathAlpha(char_))
+               // we don't use MTag and ETag because we do not want the spacing
+               ms << MTag("i") << char_type(char_) << ETag("i");
+       else
+               // an operator, so give some space
+               ms << " " << char_type(char_) << " ";
+}
+
+
 bool InsetMathChar::isRelOp() const
 {
        return char_ == '=' || char_ == '<' || char_ == '>';