New inset for \nopagebreak
Pavel Sanda
sanda at lyx.org
Fri Oct 9 21:34:56 UTC 2020
On Thu, Oct 08, 2020 at 09:57:00PM -0400, Richard Kimberly Heck wrote:
> > Implementation-wise it could be just variant of page-break inset when you look
> > at the semantics, painting-wise it would belong to the newline inset. Or it
> > could be completely standalone inset. The semantic version seem most appropriate
> > to me. Opinions?
>
> No objection. I'd add it to InsetPageBreak.
That would be like the attached. First iteration without format changes yet.
Pavel
-------------- next part --------------
diff --git a/lib/ui/stdcontext.inc b/lib/ui/stdcontext.inc
index fe6f269973..45bb578de0 100644
--- a/lib/ui/stdcontext.inc
+++ b/lib/ui/stdcontext.inc
@@ -322,6 +322,7 @@ Menuset
Menu "context-newpage"
Item "New Page|N" "inset-modify newpage newpage"
Item "Page Break|a" "inset-modify newpage pagebreak"
+ Item "No Page Break|g" "inset-modify newpage nopagebreak"
Item "Clear Page|C" "inset-modify newpage clearpage"
Item "Clear Double Page|D" "inset-modify newpage cleardoublepage"
End
diff --git a/lib/ui/stdmenus.inc b/lib/ui/stdmenus.inc
index e958178a7e..7a21069e20 100644
--- a/lib/ui/stdmenus.inc
+++ b/lib/ui/stdmenus.inc
@@ -467,6 +467,7 @@ Menuset
Separator
Item "New Page|N" "newpage-insert newpage"
Item "Page Break|a" "newpage-insert pagebreak"
+ Item "No Page Break|g" "newpage-insert nopagebreak"
Item "Clear Page|C" "newpage-insert clearpage"
Item "Clear Double Page|D" "newpage-insert cleardoublepage"
End
diff --git a/src/factory.cpp b/src/factory.cpp
index f255ef2540..0cd3a4ca0a 100644
--- a/src/factory.cpp
+++ b/src/factory.cpp
@@ -99,6 +99,8 @@ Inset * createInsetHelper(Buffer * buf, FuncRequest const & cmd)
inp.kind = InsetNewpageParams::CLEARPAGE;
else if (name == "cleardoublepage")
inp.kind = InsetNewpageParams::CLEARDOUBLEPAGE;
+ else if (name == "nopagebreak")
+ inp.kind = InsetNewpageParams::NOPAGEBREAK;
return new InsetNewpage(inp);
}
diff --git a/src/insets/InsetNewpage.cpp b/src/insets/InsetNewpage.cpp
index 6f89eac03b..040ebdf282 100644
--- a/src/insets/InsetNewpage.cpp
+++ b/src/insets/InsetNewpage.cpp
@@ -61,6 +61,9 @@ void InsetNewpageParams::write(ostream & os) const
case InsetNewpageParams::CLEARDOUBLEPAGE:
os << "cleardoublepage";
break;
+ case InsetNewpageParams::NOPAGEBREAK:
+ os << "nopagebreak";
+ break;
}
}
@@ -79,6 +82,8 @@ void InsetNewpageParams::read(Lexer & lex)
kind = InsetNewpageParams::CLEARPAGE;
else if (token == "cleardoublepage")
kind = InsetNewpageParams::CLEARDOUBLEPAGE;
+ else if (token == "nopagebreak")
+ kind = InsetNewpageParams::NOPAGEBREAK;
else
lex.printError("Unknown kind");
}
@@ -100,6 +105,14 @@ void InsetNewpage::read(Lexer & lex)
void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const
{
+ if (params_.kind == InsetNewpageParams::NOPAGEBREAK) {
+ frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
+ dim.asc = fm.maxAscent();
+ dim.des = fm.maxDescent();
+ dim.wid = 3 * fm.width('n');
+ return;
+ }
+
dim.asc = defaultRowHeight();
dim.des = defaultRowHeight();
dim.wid = mi.base.textwidth;
@@ -108,6 +121,53 @@ void InsetNewpage::metrics(MetricsInfo & mi, Dimension & dim) const
void InsetNewpage::draw(PainterInfo & pi, int x, int y) const
{
+ if (params_.kind == InsetNewpageParams::NOPAGEBREAK) {
+
+ FontInfo font;
+ font.setColor(ColorName());
+
+ frontend::FontMetrics const & fm = theFontMetrics(pi.base.font);
+ int const wid = 3 * fm.width('n');
+ int const asc = fm.maxAscent();
+
+ int xp[3];
+ int yp[3];
+
+ //left side arrow
+ 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);
+ xp[0] = int(x + wid * 0.25);
+ xp[1] = int(x + wid * 0.4);
+ xp[2] = int(x + wid * 0.25);
+ pi.pain.lines(xp, yp, 3, ColorName());
+
+ yp[0] = yp[1] = int(y - 0.500 * asc * 0.75);
+ xp[0] = int(x + wid * 0.03);
+ xp[1] = int(x + wid * 0.4);
+ pi.pain.lines(xp, yp, 2, ColorName());
+
+ //right side arrow
+ 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);
+ xp[0] = int(x + wid * 0.75);
+ xp[1] = int(x + wid * 0.6);
+ xp[2] = int(x + wid * 0.75);
+ pi.pain.lines(xp, yp, 3, ColorName());
+
+ yp[0] = yp[1] = int(y - 0.500 * asc * 0.75);
+ xp[0] = int(x + wid * 0.97);
+ xp[1] = int(x + wid * 0.6);
+ pi.pain.lines(xp, yp, 2, ColorName());
+
+ //mid-rule
+ xp[0] = xp[1] = int(x + wid * 0.5);;
+ yp[0] = int(y - 0.875 * asc * 0.75);
+ yp[1] = int(y - 0.125 * asc * 0.75);
+ pi.pain.lines(xp, yp, 2, ColorName());
+ }
+
using frontend::Painter;
FontInfo font;
@@ -187,6 +247,9 @@ docstring InsetNewpage::insetLabel() const
case InsetNewpageParams::CLEARDOUBLEPAGE:
return _("Clear Double Page");
break;
+ case InsetNewpageParams::NOPAGEBREAK:
+ return _("No Page Break");
+ break;
default:
return _("New Page");
break;
@@ -198,6 +261,7 @@ ColorCode InsetNewpage::ColorName() const
{
switch (params_.kind) {
case InsetNewpageParams::PAGEBREAK:
+ case InsetNewpageParams::NOPAGEBREAK:
return Color_pagebreak;
break;
case InsetNewpageParams::NEWPAGE:
@@ -232,6 +296,9 @@ void InsetNewpage::latex(otexstream & os, OutputParams const & runparams) const
case InsetNewpageParams::CLEARDOUBLEPAGE:
os << "\\cleardoublepage" << termcmd;
break;
+ case InsetNewpageParams::NOPAGEBREAK:
+ os << "\\nopagebreak" << termcmd;
+ break;
default:
os << "\\newpage" << termcmd;
break;
@@ -243,6 +310,8 @@ void InsetNewpage::latex(otexstream & os, OutputParams const & runparams) const
int InsetNewpage::plaintext(odocstringstream & os,
OutputParams const &, size_t) const
{
+ if (params_.kind == InsetNewpageParams::NOPAGEBREAK)
+ return 0;
os << '\n';
return PLAINTEXT_NEWLINE;
}
@@ -250,13 +319,15 @@ int InsetNewpage::plaintext(odocstringstream & os,
void InsetNewpage::docbook(XMLStream & os, OutputParams const &) const
{
- os << xml::CR();
+ if (params_.kind != InsetNewpageParams::NOPAGEBREAK)
+ os << xml::CR();
}
docstring InsetNewpage::xhtml(XMLStream & xs, OutputParams const &) const
{
- xs << xml::CompTag("br");
+ if (params_.kind != InsetNewpageParams::NOPAGEBREAK)
+ xs << xml::CompTag("br");
return docstring();
}
diff --git a/src/insets/InsetNewpage.h b/src/insets/InsetNewpage.h
index e7f1126a8a..f02048804d 100644
--- a/src/insets/InsetNewpage.h
+++ b/src/insets/InsetNewpage.h
@@ -29,7 +29,9 @@ public:
///
CLEARPAGE,
///
- CLEARDOUBLEPAGE
+ CLEARDOUBLEPAGE,
+ ///
+ NOPAGEBREAK
};
///
InsetNewpageParams() : kind(NEWPAGE) {}
@@ -74,7 +76,7 @@ private:
///
void write(std::ostream & os) const override;
///
- RowFlags rowFlags() const override { return Display; }
+ RowFlags rowFlags() const override { return (params_.kind == InsetNewpageParams::NOPAGEBREAK) ? Inline : Display; }
///
docstring insetLabel() const;
///
More information about the lyx-devel
mailing list