]> git.lyx.org Git - lyx.git/blobdiff - src/insets/InsetSpace.cpp
Restore XHTML output for InsetListings.
[lyx.git] / src / insets / InsetSpace.cpp
index a9ffe812ac04d42d6a4b090dace107474193dc4a..5cd30542ddd158a5a666c501968bd58662f52996 100644 (file)
 #include "Dimension.h"
 #include "FuncRequest.h"
 #include "FuncStatus.h"
+#include "Language.h"
 #include "LaTeXFeatures.h"
 #include "Length.h"
 #include "Lexer.h"
 #include "MetricsInfo.h"
 #include "OutputParams.h"
+#include "output_xhtml.h"
 
 #include "support/debug.h"
 #include "support/docstream.h"
@@ -42,7 +44,7 @@ namespace lyx {
 
 
 InsetSpace::InsetSpace(InsetSpaceParams const & params)
-       : params_(params)
+       : Inset(0), params_(params)
 {}
 
 
@@ -52,7 +54,7 @@ InsetSpaceParams::Kind InsetSpace::kind() const
 }
 
 
-Length InsetSpace::length() const
+GlueLength InsetSpace::length() const
 {
        return params_.length;
 }
@@ -129,12 +131,14 @@ docstring InsetSpace::toolTip(BufferView const &, int, int) const
                message = _("Horizontal Fill (Down Brace)");
                break;
        case InsetSpaceParams::CUSTOM:
+               // FIXME unicode
                message = support::bformat(_("Horizontal Space (%1$s)"),
-                               params_.length.asDocstring());
+                               from_ascii(params_.length.asString()));
                break;
        case InsetSpaceParams::CUSTOM_PROTECTED:
+               // FIXME unicode
                message = support::bformat(_("Protected Horizontal Space (%1$s)"),
-                               params_.length.asDocstring());
+                               from_ascii(params_.length.asString()));
                break;
        }
        return message;
@@ -237,7 +241,7 @@ void InsetSpace::metrics(MetricsInfo & mi, Dimension & dim) const
                case InsetSpaceParams::CUSTOM:
                case InsetSpaceParams::CUSTOM_PROTECTED: {
                        int const w = 
-                               params_.length.inPixels(mi.base.textwidth,
+                               params_.length.len().inPixels(mi.base.textwidth,
                                                        fm.width(char_type('M')));
                        int const minw = (w < 0) ? 3 * arrow_size : 4;
                        dim.wid = max(minw, abs(w));
@@ -263,7 +267,7 @@ void InsetSpace::draw(PainterInfo & pi, int x, int y) const
 {
        Dimension const dim = dimension(*pi.base.bv);
 
-       if (isStretchableSpace() || params_.length.value() < 0) {
+       if (isStretchableSpace() || params_.length.len().value() < 0) {
                int const asc = theFontMetrics(pi.base.font).ascent('M');
                int const desc = theFontMetrics(pi.base.font).descent('M');
                // Pixel height divisible by 2 for prettier fill graphics:
@@ -449,7 +453,7 @@ void InsetSpaceParams::write(ostream & os) const
                break;
        }
        
-       if (!length.empty())
+       if (!length.len().empty())
                os << "\n\\length " << length.asString();
 }
 
@@ -534,7 +538,12 @@ int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
                os << (runparams.free_spacing ? " " : "\\ ");
                break;
        case InsetSpaceParams::PROTECTED:
-               os << (runparams.free_spacing ? ' ' : '~');
+               if (runparams.local_font &&
+                   runparams.local_font->language()->lang() == "polutonikogreek")
+                       // in babel's polutonikogreek, ~ is active
+                       os << (runparams.free_spacing ? " " : "\\nobreakspace{}");
+               else
+                       os << (runparams.free_spacing ? ' ' : '~');
                break;
        case InsetSpaceParams::THIN:
                os << (runparams.free_spacing ? " " : "\\,");
@@ -680,6 +689,56 @@ int InsetSpace::docbook(odocstream & os, OutputParams const &) const
 }
 
 
+docstring InsetSpace::xhtml(XHTMLStream & xs, OutputParams const &) const
+{
+       string output;
+       switch (params_.kind) {
+       case InsetSpaceParams::NORMAL:
+               output = " ";
+               break;
+       case InsetSpaceParams::ENSKIP:
+       case InsetSpaceParams::ENSPACE:
+               output ="&ensp;";
+               break;
+       case InsetSpaceParams::QQUAD:
+               output ="&emsp;";
+       case InsetSpaceParams::THICK:
+       case InsetSpaceParams::QUAD:
+               output ="&emsp;";
+               break;
+       case InsetSpaceParams::THIN:
+               output ="&thinsp;";
+               break;
+       case InsetSpaceParams::PROTECTED:
+       case InsetSpaceParams::MEDIUM:
+       case InsetSpaceParams::NEGTHIN:
+       case InsetSpaceParams::NEGMEDIUM:
+       case InsetSpaceParams::NEGTHICK:
+               output ="&nbsp;";
+               break;
+       case InsetSpaceParams::HFILL:
+       case InsetSpaceParams::HFILL_PROTECTED:
+       case InsetSpaceParams::DOTFILL:
+       case InsetSpaceParams::HRULEFILL:
+       case InsetSpaceParams::LEFTARROWFILL:
+       case InsetSpaceParams::RIGHTARROWFILL:
+       case InsetSpaceParams::UPBRACEFILL:
+       case InsetSpaceParams::DOWNBRACEFILL:
+               // FIXME XHTML
+               // Can we do anything with those in HTML?
+               break;
+       case InsetSpaceParams::CUSTOM:
+       case InsetSpaceParams::CUSTOM_PROTECTED:
+               // FIXME XHTML
+               // Probably we could do some sort of blank span?
+               break;
+       }
+       // don't escape the entities!
+       xs << XHTMLStream::NextRaw() << from_ascii(output);
+       return docstring();
+}
+
+
 void InsetSpace::validate(LaTeXFeatures & features) const
 {
        if (params_.kind == InsetSpaceParams::NEGMEDIUM ||