#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"
InsetSpace::InsetSpace(InsetSpaceParams const & params)
- : params_(params)
+ : Inset(0), params_(params)
{}
}
-Length InsetSpace::length() const
+GlueLength InsetSpace::length() const
{
return params_.length;
}
-InsetSpace::~InsetSpace()
-{
- hideDialogs("space", this);
-}
-
-
docstring InsetSpace::toolTip(BufferView const &, int, int) const
{
docstring message;
case InsetSpaceParams::PROTECTED:
message = _("Protected Space");
break;
+ case InsetSpaceParams::VISIBLE:
+ message = _("Visible Space");
+ break;
case InsetSpaceParams::THIN:
message = _("Thin Space");
break;
message = _("Quad Space");
break;
case InsetSpaceParams::QQUAD:
- message = _("QQuad Space");
+ message = _("Double Quad Space");
break;
case InsetSpaceParams::ENSPACE:
message = _("Enspace");
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;
void InsetSpace::doDispatch(Cursor & cur, FuncRequest & cmd)
{
- switch (cmd.action) {
+ switch (cmd.action()) {
case LFUN_INSET_MODIFY:
+ cur.recordUndo();
string2params(to_utf8(cmd.argument()), params_);
break;
bool InsetSpace::getStatus(Cursor & cur, FuncRequest const & cmd,
FuncStatus & status) const
{
- switch (cmd.action) {
+ switch (cmd.action()) {
// we handle these
case LFUN_INSET_MODIFY:
if (cmd.getArg(0) == "space") {
InsetSpaceParams params;
string2params(to_utf8(cmd.argument()), params);
status.setOnOff(params_.kind == params.kind);
- }
- // fall through
- case LFUN_INSET_SETTINGS:
+ status.setEnabled(true);
+ } else
+ status.setEnabled(false);
+ return true;
+
case LFUN_INSET_DIALOG_UPDATE:
status.setEnabled(true);
return true;
}
-bool InsetSpace::showInsetDialog(BufferView * bv) const
-{
- bv->showDialog("space", params2string(params()),
- const_cast<InsetSpace *>(this));
- return true;
-}
-
-
namespace {
int const arrow_size = 8;
}
dim.wid = fm.width(char_type('M')) / 2;
break;
case InsetSpaceParams::PROTECTED:
+ case InsetSpaceParams::VISIBLE:
case InsetSpaceParams::NORMAL:
dim.wid = fm.width(char_type(' '));
break;
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));
{
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:
xp[0] = x;
yp[0] = y - max(h / 4, 1);
if (params_.kind == InsetSpaceParams::NORMAL ||
- params_.kind == InsetSpaceParams::PROTECTED) {
+ params_.kind == InsetSpaceParams::PROTECTED ||
+ params_.kind == InsetSpaceParams::VISIBLE) {
xp[1] = x; yp[1] = y;
xp[2] = x + w; yp[2] = y;
} else {
xp[3] = x + w;
yp[3] = y - max(h / 4, 1);
+ Color col = Color_special;
if (params_.kind == InsetSpaceParams::PROTECTED ||
params_.kind == InsetSpaceParams::ENSPACE ||
params_.kind == InsetSpaceParams::NEGTHIN ||
params_.kind == InsetSpaceParams::NEGMEDIUM ||
params_.kind == InsetSpaceParams::NEGTHICK ||
params_.kind == InsetSpaceParams::CUSTOM_PROTECTED)
- pi.pain.lines(xp, yp, 4, Color_latex);
- else
- pi.pain.lines(xp, yp, 4, Color_special);
+ col = Color_latex;
+ else if (params_.kind == InsetSpaceParams::VISIBLE)
+ col = Color_foreground;
+
+ pi.pain.lines(xp, yp, 4, col);
}
case InsetSpaceParams::PROTECTED:
os << "~";
break;
+ case InsetSpaceParams::VISIBLE:
+ os << "\\textvisiblespace{}";
+ break;
case InsetSpaceParams::THIN:
os << "\\thinspace{}";
break;
break;
}
- if (!length.empty())
+ if (!length.len().empty())
os << "\n\\length " << length.asString();
}
kind = InsetSpaceParams::NORMAL;
else if (command == "~")
kind = InsetSpaceParams::PROTECTED;
+ else if (command == "\\textvisiblespace{}")
+ kind = InsetSpaceParams::VISIBLE;
else if (command == "\\thinspace{}")
kind = InsetSpaceParams::THIN;
else if (math && command == "\\medspace{}")
kind = InsetSpaceParams::ENSKIP;
else if (command == "\\negthinspace{}")
kind = InsetSpaceParams::NEGTHIN;
- else if (math && command == "\\negmedspace{}")
+ else if (command == "\\negmedspace{}")
kind = InsetSpaceParams::NEGMEDIUM;
- else if (math && command == "\\negthickspace{}")
+ else if (command == "\\negthickspace{}")
kind = InsetSpaceParams::NEGTHICK;
else if (command == "\\hfill{}")
kind = InsetSpaceParams::HFILL;
}
-int InsetSpace::latex(odocstream & os, OutputParams const & runparams) const
+void InsetSpace::latex(otexstream & os, OutputParams const & runparams) const
{
switch (params_.kind) {
case InsetSpaceParams::NORMAL:
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::VISIBLE:
+ os << (runparams.free_spacing ? " " : "\\textvisiblespace{}");
break;
case InsetSpaceParams::THIN:
os << (runparams.free_spacing ? " " : "\\,");
os << "\\hspace*{" << from_ascii(params_.length.asLatexString()) << "}";
break;
}
- return 0;
}
case InsetSpaceParams::ENSKIP:
os << " ";
break;
+ // FIXME For spaces and dashes look here:
+ // http://oreilly.com/catalog/docbook/book2/iso-pub.html
case InsetSpaceParams::PROTECTED:
+ // FIXME ␣ ?
+ case InsetSpaceParams::VISIBLE:
case InsetSpaceParams::ENSPACE:
+ // FIXME   ?
case InsetSpaceParams::THIN:
case InsetSpaceParams::MEDIUM:
case InsetSpaceParams::THICK:
}
+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 =" ";
+ break;
+ case InsetSpaceParams::QQUAD:
+ output =" ";
+ case InsetSpaceParams::THICK:
+ case InsetSpaceParams::QUAD:
+ output =" ";
+ break;
+ case InsetSpaceParams::THIN:
+ output =" ";
+ break;
+ case InsetSpaceParams::PROTECTED:
+ case InsetSpaceParams::MEDIUM:
+ case InsetSpaceParams::NEGTHIN:
+ case InsetSpaceParams::NEGMEDIUM:
+ case InsetSpaceParams::NEGTHICK:
+ output =" ";
+ break;
+ // no XHTML entity, only unicode code for space character exists
+ case InsetSpaceParams::VISIBLE:
+ output ="␣";
+ 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::ESCAPE_NONE << from_ascii(output);
+ return docstring();
+}
+
+
void InsetSpace::validate(LaTeXFeatures & features) const
{
if (params_.kind == InsetSpaceParams::NEGMEDIUM ||
}
-void InsetSpace::tocString(odocstream & os) const
+void InsetSpace::toString(odocstream & os) const
{
plaintext(os, OutputParams(0));
}
+void InsetSpace::forToc(docstring & os, size_t) const
+{
+ // There's no need to be cute here.
+ os += " ";
+}
+
+
bool InsetSpace::isStretchableSpace() const
{
return params_.kind == InsetSpaceParams::HFILL
}
-docstring InsetSpace::contextMenu(BufferView const &, int, int) const
+docstring InsetSpace::contextMenuName() const
{
return from_ascii("context-space");
}