#include "FuncStatus.h"
#include "Lexer.h"
#include "MetricsInfo.h"
-#include "OutputParams.h"
+#include "output_docbook.h"
#include "output_xhtml.h"
+#include "texstream.h"
#include "frontends/Application.h"
#include "frontends/FontMetrics.h"
#include "support/docstring.h"
using namespace std;
+using namespace lyx::frontend;
namespace lyx {
-InsetSeparator::InsetSeparator() : Inset(0)
+InsetSeparator::InsetSeparator() : Inset(nullptr)
{}
InsetSeparator::InsetSeparator(InsetSeparatorParams const & params)
- : Inset(0), params_(params)
+ : Inset(nullptr), params_(params)
{}
void InsetSeparatorParams::write(ostream & os) const
{
- string command;
switch (kind) {
case InsetSeparatorParams::PLAIN:
os << "plain";
case InsetSeparatorParams::PARBREAK:
os << "parbreak";
break;
+ case InsetSeparatorParams::LATEXPAR:
+ os << "latexpar";
+ break;
}
}
{
string token;
lex.setContext("InsetSeparatorParams::read");
- lex >> token;
+ lex >> token;
if (token == "plain")
kind = InsetSeparatorParams::PLAIN;
else if (token == "parbreak")
kind = InsetSeparatorParams::PARBREAK;
+ else if (token == "latexpar")
+ kind = InsetSeparatorParams::LATEXPAR;
else
lex.printError("Unknown kind: `$$Token'");
}
{
switch (cmd.action()) {
// we handle these
- case LFUN_INSET_MODIFY:
- if (cmd.getArg(0) == "plain") {
- InsetSeparatorParams params;
- string2params(to_utf8(cmd.argument()), params);
- status.setOnOff(params_.kind == params.kind);
- }
+ case LFUN_INSET_MODIFY: {
+ if (cmd.getArg(0) != "separator")
+ break;
+ InsetSeparatorParams params;
+ string2params(to_utf8(cmd.argument()), params);
+ status.setOnOff(params_.kind == params.kind);
status.setEnabled(true);
return true;
+ }
default:
return Inset::getStatus(cur, cmd, status);
}
+ return false;
}
ColorCode InsetSeparator::ColorName() const
{
- switch (params_.kind) {
- case InsetSeparatorParams::PLAIN:
- return Color_latex;
- break;
- case InsetSeparatorParams::PARBREAK:
- return Color_pagebreak;
- break;
- }
- // not really useful, but to avoids gcc complaints
return Color_latex;
}
-void InsetSeparator::latex(otexstream & os, OutputParams const &) const
+void InsetSeparator::latex(otexstream & os, OutputParams const & runparams) const
{
- switch (params_.kind) {
- case InsetSeparatorParams::PLAIN:
- os << breakln << "%\n";
- break;
- case InsetSeparatorParams::PARBREAK:
- os << breakln << "\n";
- break;
- default:
- os << breakln << "%\n";
- break;
+ // Do nothing if a paragraph break was just output
+ if (!os.afterParbreak()) {
+ switch (params_.kind) {
+ case InsetSeparatorParams::PLAIN:
+ os << breakln << "%\n";
+ break;
+ case InsetSeparatorParams::PARBREAK:
+ case InsetSeparatorParams::LATEXPAR:
+ if (runparams.inDeletedInset)
+ os << breakln << "}\n\n{";
+ else
+ os << breakln << "\n";
+ break;
+ default:
+ os << breakln << "%\n";
+ break;
+ }
}
}
}
-int InsetSeparator::docbook(odocstream & os, OutputParams const &) const
+void InsetSeparator::docbook(XMLStream & xs, OutputParams const &) const
{
- os << '\n';
- return 0;
+ xs << xml::CR();
}
-docstring InsetSeparator::xhtml(XHTMLStream & xs, OutputParams const &) const
+docstring InsetSeparator::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << html::CR() << html::CompTag("br") << html::CR();
+ xs << xml::CR() << xml::CompTag("br") << xml::CR();
return docstring();
}
frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
dim.asc = fm.maxAscent();
dim.des = fm.maxDescent();
- dim.wid = fm.width('m');
- if (params_.kind == InsetSeparatorParams::PLAIN)
- dim.wid *= 5;
+ dim.wid = fm.width('n');
+ if (params_.kind != InsetSeparatorParams::LATEXPAR)
+ dim.wid *= 8;
}
font.setColor(ColorName());
frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
- int const wid = fm.width('m');
+ int const wid = fm.width('n');
int const asc = fm.maxAscent();
- int xp[3];
- int yp[3];
+ int xp[7];
+ int yp[7];
- if (params_.kind == InsetSeparatorParams::PLAIN) {
+ if (params_.kind != InsetSeparatorParams::LATEXPAR) {
yp[0] = int(y - 0.500 * asc * 0.75);
- yp[1] = int(y - 0.500 * asc * 0.75);
+ yp[1] = yp[0];
xp[0] = int(x);
- xp[1] = int(x + wid * 5);
+ xp[1] = int(x + wid * 8);
pi.pain.lines(xp, yp, 2, ColorName());
+
+ if (params_.kind == InsetSeparatorParams::PARBREAK) {
+ yp[0] += int(0.25 * asc * 0.75);
+ yp[1] = yp[0];
+ pi.pain.lines(xp, yp, 2, ColorName());
+ }
} else {
- yp[0] = int(y - 0.875 * asc * 0.75);
- yp[1] = int(y - 0.500 * asc * 0.75);
- yp[2] = int(y - 0.125 * asc * 0.75);
+ yp[0] = int(y - 0.500 * asc * 0.5);
+ yp[1] = int(y - 0.250 * asc * 0.5);
+ yp[2] = int(y);
if (pi.ltr_pos) {
- xp[0] = int(x + wid * 0.375);
- xp[1] = int(x);
- xp[2] = int(x + wid * 0.375);
+ xp[0] = int(x + 1 + wid * 0.375);
+ xp[1] = int(x + 1);
} else {
- xp[0] = int(x + wid * 0.625);
- xp[1] = int(x + wid);
- xp[2] = int(x + wid * 0.625);
+ xp[0] = int(x - 1 + wid * 0.625);
+ xp[1] = int(x - 1 + wid);
}
+ xp[2] = xp[0];
- pi.pain.lines(xp, yp, 3, ColorName());
+ pi.pain.lines(xp, yp, 3, ColorName(), Painter::fill_oddeven);
- yp[0] = int(y - 0.500 * asc * 0.75);
- yp[1] = int(y - 0.500 * asc * 0.75);
- yp[2] = int(y - asc * 0.75);
+ yp[0] = yp[1];
+ yp[2] = int(y - 0.850 * asc * 0.5);
+ yp[3] = int(y - 1.250 * asc * 0.5);
+ yp[4] = yp[3];
+ yp[5] = yp[2];
+ yp[6] = yp[5];
+ xp[0] = xp[1];
if (pi.ltr_pos) {
- xp[0] = int(x);
- xp[1] = int(x + wid);
+ xp[1] = int(x + 1 + wid * 0.50);
xp[2] = int(x + wid);
+ xp[3] = xp[2];
+ xp[4] = int(x + wid * 0.75);
} else {
- xp[0] = int(x + wid);
- xp[1] = int(x);
+ xp[1] = int(x + wid * 0.50);
xp[2] = int(x);
+ xp[3] = xp[2];
+ xp[4] = int(x + wid * 0.25);
+ }
+ xp[5] = xp[4];
+ xp[6] = xp[2];
+
+ int c1x[7];
+ int c1y[7];
+ int c2x[7];
+ int c2y[7];
+
+ for (int i = 1; i < 7; ++i) {
+ c1x[i] = xp[i - 1];
+ c1y[i] = yp[i - 1];
+ c2x[i] = xp[i];
+ c2y[i] = yp[i];
}
- pi.pain.lines(xp, yp, 3, ColorName());
+ int d = pi.ltr_pos ? yp[4] - yp[5] : yp[5] - yp[4];
+
+ c1x[2] = xp[2];
+ c2y[2] = int(y - 0.500 * asc * 0.5);
+ c1x[5] += d;
+ c2x[5] += d;
+
+ pi.pain.path(xp, yp, c1x, c1y, c2x, c2y, 7, ColorName());
}
}
string InsetSeparator::contextMenuName() const
{
+ if (params_.kind == InsetSeparatorParams::LATEXPAR)
+ return string();
+
return "context-separator";
}