[LyX/master] DocBook: avoid generating fonts for "special cases" like equations.
Thibaut Cuvelier
tcuvelier at lyx.org
Sat Sep 19 18:18:56 UTC 2020
commit e995414917937e1fd8bdf108c8269777cf215719
Author: Thibaut Cuvelier <tcuvelier at lyx.org>
Date: Mon Aug 31 00:18:35 2020 +0200
DocBook: avoid generating fonts for "special cases" like equations.
---
autotests/export/docbook/lists.xml | 2 +-
autotests/export/docbook/math_in_font.xml | 8 +++--
src/Paragraph.cpp | 42 ++++++++++++++++------------
src/Paragraph.h | 3 +-
src/output_docbook.cpp | 2 +-
5 files changed, 33 insertions(+), 24 deletions(-)
diff --git a/autotests/export/docbook/lists.xml b/autotests/export/docbook/lists.xml
index 6812230..ce2d970 100644
--- a/autotests/export/docbook/lists.xml
+++ b/autotests/export/docbook/lists.xml
@@ -125,7 +125,7 @@
<varlistentry>
<term>LyX:</term>
<listitem>
-
+<para />
<variablelist>
<varlistentry>
<term>lyx16</term>
diff --git a/autotests/export/docbook/math_in_font.xml b/autotests/export/docbook/math_in_font.xml
index 0758a2e..45bb544 100644
--- a/autotests/export/docbook/math_in_font.xml
+++ b/autotests/export/docbook/math_in_font.xml
@@ -4,7 +4,8 @@
<article xml:lang="en_US" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:xi="http://www.w3.org/2001/XInclude" version="5.2">
<title>LyX</title>
<para>Some text before.</para>
-<informalequation><alt role='tex'>\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C}</alt>
+<informalequation>
+<alt role='tex'>\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C}</alt>
<m:math>
<m:mrow>
@@ -35,6 +36,7 @@
</m:mfrac>
</m:mrow>
</m:mrow>
- </m:math></informalequation><para>Some text after.</para>
-
+ </m:math>
+</informalequation>
+<para>Some text after.</para>
</article>
\ No newline at end of file
diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp
index b88c381..9dea24b 100644
--- a/src/Paragraph.cpp
+++ b/src/Paragraph.cpp
@@ -3333,7 +3333,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
OutputParams const & runparams,
Font const & outerfont,
pos_type initial,
- bool is_last_par) const
+ bool is_last_par,
+ bool ignore_fonts) const
{
// Track whether we have opened these tags
DocBookFontState fs;
@@ -3362,33 +3363,37 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
// If this is an InsetNewline, generate a new paragraph. Also reset the fonts, so that tags are closed in
// this paragraph.
if (getInset(i) != nullptr && getInset(i)->lyxCode() == NEWLINE_CODE) {
- xs->closeFontTags();
+ if (!ignore_fonts)
+ xs->closeFontTags();
generatedParagraphs.push_back(os.str());
os = odocstringstream();
delete xs;
xs = new XMLStream(os);
- font_old = outerfont.fontInfo();
+ if (!ignore_fonts)
+ font_old = outerfont.fontInfo();
}
- // Determine which tags should be opened or closed.
+ // Determine which tags should be opened or closed regarding fonts.
Font const font = getFont(buf.masterBuffer()->params(), i, outerfont);
- tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
+ if (!ignore_fonts) {
+ tie(tagsToOpen, tagsToClose) = computeDocBookFontSwitch(font_old, font, default_family, fs);
- // FIXME XHTML
- // Other such tags? What about the other text ranges?
+ // FIXME XHTML
+ // Other such tags? What about the other text ranges?
- vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
- vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
- for (; cit != cen; ++cit)
- *xs << *cit;
+ vector<xml::EndFontTag>::const_iterator cit = tagsToClose.begin();
+ vector<xml::EndFontTag>::const_iterator cen = tagsToClose.end();
+ for (; cit != cen; ++cit)
+ *xs << *cit;
- vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
- vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
- for (; sit != sen; ++sit)
- *xs << *sit;
+ vector<xml::FontTag>::const_iterator sit = tagsToOpen.begin();
+ vector<xml::FontTag>::const_iterator sen = tagsToOpen.end();
+ for (; sit != sen; ++sit)
+ *xs << *sit;
- tagsToClose.clear();
- tagsToOpen.clear();
+ tagsToClose.clear();
+ tagsToOpen.clear();
+ }
if (Inset const * inset = getInset(i)) {
if (!runparams.for_toc || inset->isInToc()) {
@@ -3409,7 +3414,8 @@ std::vector<docstring> Paragraph::simpleDocBookOnePar(Buffer const & buf,
// FIXME, this code is just imported from XHTML
// I'm worried about what happens if a branch, say, is itself
// wrapped in some font stuff. I think that will not work.
- xs->closeFontTags();
+ if (!ignore_fonts)
+ xs->closeFontTags();
// In listings, new lines are very important. Avoid generating one for the last line.
if (runparams.docbook_in_listing && !is_last_par)
diff --git a/src/Paragraph.h b/src/Paragraph.h
index 96c19c0..597a10b 100644
--- a/src/Paragraph.h
+++ b/src/Paragraph.h
@@ -214,7 +214,8 @@ public:
OutputParams const & runparams,
Font const & outerfont,
pos_type initial = 0,
- bool is_last_par = false) const;
+ bool is_last_par = false,
+ bool ignore_fonts = false) const;
/// \return any material that has had to be deferred until after the
/// paragraph has closed.
diff --git a/src/output_docbook.cpp b/src/output_docbook.cpp
index 808b4cf..c80988b 100644
--- a/src/output_docbook.cpp
+++ b/src/output_docbook.cpp
@@ -513,7 +513,7 @@ void makeParagraph(
// Open and close tags around each contained paragraph.
auto nextpar = par;
++nextpar;
- auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end);
+ auto pars = par->simpleDocBookOnePar(buf, runparams, text.outerFont(distance(begin, par)), 0, nextpar == end, special_case);
for (auto & parXML : pars) {
if (!std::all_of(parXML.begin(), parXML.end(), ::isspace)) {
if (open_par)
More information about the lyx-cvs
mailing list