From: Thibaut Cuvelier Date: Fri, 11 Sep 2020 01:14:41 +0000 (+0200) Subject: DocBook: handle other cases of subfigures. X-Git-Tag: lyx-2.4.0dev-acb2ca7b~181^2~16 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=d0a5ba4859702c78fb70ae30fe1f39818c98b102;p=features.git DocBook: handle other cases of subfigures. --- diff --git a/src/insets/InsetFloat.cpp b/src/insets/InsetFloat.cpp index 981ba40427..d68001366b 100644 --- a/src/insets/InsetFloat.cpp +++ b/src/insets/InsetFloat.cpp @@ -492,19 +492,22 @@ int InsetFloat::plaintext(odocstringstream & os, OutputParams const & runparams, } -std::vector findSubfiguresInParagraph(const Paragraph &par) +std::vector findSubfiguresInParagraph(const Paragraph &par) { // Don't make the hypothesis that all subfigures are in the same paragraph. // Similarly, there may be several subfigures in the same paragraph (most likely case, based on the documentation). // Any box is considered as a subfigure, even though the most likely case is \minipage. - std::vector subfigures; + // Boxes are not required to make subfigures. The common root between InsetBox and InsetFLoat is InsetCollapsible. + std::vector subfigures; for (pos_type pos = 0; pos < par.size(); ++pos) { const Inset *inset = par.getInset(pos); if (!inset) continue; if (const auto box = dynamic_cast(inset)) subfigures.push_back(box); + else if (const auto fl = dynamic_cast(inset)) + subfigures.push_back(fl); } return subfigures; } @@ -564,7 +567,7 @@ const InsetCaption* findCaptionInParagraph(const Paragraph &par) void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const InsetCaption * caption, - const InsetLabel * label, std::vector & subfigures) + const InsetLabel * label, std::vector & subfigures) { // Ensure there is no label output, it is supposed to be handled as xml:id. OutputParams rpNoLabel = runparams; @@ -592,20 +595,29 @@ void docbookSubfigures(XMLStream & xs, OutputParams const & runparams, const Ins // Deal with each subfigure individually. This should also deal with their caption and their label. // This should be a recursive call to InsetFloat. - for (const InsetBox *subfigure: subfigures) { + // An item in subfigure should either be an InsetBox containing an InsetFloat or directly an InsetFloat. + for (const InsetCollapsible *subfigure: subfigures) { // If there is no InsetFloat in the paragraphs, output a warning. bool foundInsetFloat = false; - for (const auto & it : subfigure->paragraphs()) { - for (pos_type posIn = 0; posIn < it.size(); ++posIn) { - const Inset *inset = it.getInset(posIn); - if (inset && dynamic_cast(inset)) { - foundInsetFloat = true; - break; + + // The collapsible may already be a float (InsetFloat). + if (subfigure && dynamic_cast(subfigure)) + foundInsetFloat = true; + + // Subfigures are in boxes. + if (!foundInsetFloat) { + for (const auto &it : subfigure->paragraphs()) { + for (pos_type posIn = 0; posIn < it.size(); ++posIn) { + const Inset *inset = it.getInset(posIn); + if (inset && dynamic_cast(inset)) { + foundInsetFloat = true; + break; + } } - } - if (foundInsetFloat) - break; + if (foundInsetFloat) + break; + } } if (!foundInsetFloat) @@ -673,11 +685,11 @@ void InsetFloat::docbook(XMLStream & xs, OutputParams const & runparams) const // The caption and the label for each subfigure is handled by recursive calls. const InsetCaption* caption = nullptr; const InsetLabel* label = nullptr; - std::vector subfigures; + std::vector subfigures; auto end = paragraphs().end(); for (auto it = paragraphs().begin(); it != end; ++it) { - std::vector foundSubfigures = findSubfiguresInParagraph(*it); + std::vector foundSubfigures = findSubfiguresInParagraph(*it); if (!foundSubfigures.empty()) { subfigures.reserve(subfigures.size() + foundSubfigures.size()); subfigures.insert(subfigures.end(), foundSubfigures.begin(), foundSubfigures.end());