From e995414917937e1fd8bdf108c8269777cf215719 Mon Sep 17 00:00:00 2001 From: Thibaut Cuvelier Date: Mon, 31 Aug 2020 00:18:35 +0200 Subject: [PATCH] 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 6812230064..ce2d9701d1 100644 --- a/autotests/export/docbook/lists.xml +++ b/autotests/export/docbook/lists.xml @@ -125,7 +125,7 @@ LyX: - + lyx16 diff --git a/autotests/export/docbook/math_in_font.xml b/autotests/export/docbook/math_in_font.xml index 0758a2e0e6..45bb5442a2 100644 --- a/autotests/export/docbook/math_in_font.xml +++ b/autotests/export/docbook/math_in_font.xml @@ -4,7 +4,8 @@
LyX Some text before. -\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C} + +\cfrac[l]{A}{B+C}\,,\,\cfrac{A}{B+C}\,,\,\cfrac[r]{A}{B+C} @@ -35,6 +36,7 @@ - Some text after. - + + +Some text after.
\ No newline at end of file diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index b88c381c9d..9dea24b1e7 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -3333,7 +3333,8 @@ std::vector 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 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::const_iterator cit = tagsToClose.begin(); - vector::const_iterator cen = tagsToClose.end(); - for (; cit != cen; ++cit) - *xs << *cit; + vector::const_iterator cit = tagsToClose.begin(); + vector::const_iterator cen = tagsToClose.end(); + for (; cit != cen; ++cit) + *xs << *cit; - vector::const_iterator sit = tagsToOpen.begin(); - vector::const_iterator sen = tagsToOpen.end(); - for (; sit != sen; ++sit) - *xs << *sit; + vector::const_iterator sit = tagsToOpen.begin(); + vector::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 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 96c19c0f49..597a10b764 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 808b4cf66c..c80988b492 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)