commit 59e49ab8beb316f3f74c010e3b8ebdc50ccf4318
Author: Juergen Spitzmueller <[email protected]>
Date: Sat Jul 26 14:23:16 2025 +0200
Fix XHTML output and prettyFormat of xref to subfloat (#9206)
---
src/insets/Inset.h | 3 +++
src/insets/InsetCaption.cpp | 17 ++++++++---------
src/insets/InsetCaption.h | 4 ++++
src/insets/InsetCaptionable.h | 3 +--
src/insets/InsetFloat.h | 2 ++
src/insets/InsetLabel.cpp | 36 ++++++++++++++++++++++++++++++++++++
6 files changed, 54 insertions(+), 11 deletions(-)
diff --git a/src/insets/Inset.h b/src/insets/Inset.h
index 2033ffd204..b18f13fe34 100644
--- a/src/insets/Inset.h
+++ b/src/insets/Inset.h
@@ -45,6 +45,7 @@ class FuncStatus;
class InsetArgument;
class InsetCollapsible;
class InsetCommand;
+class InsetFloat;
class InsetGraphics;
class InsetIndex;
class InsetIterator;
@@ -161,6 +162,8 @@ public:
virtual InsetGraphics * asInsetGraphics() { return nullptr; }
/// is this inset based on the InsetGraphics class?
virtual InsetGraphics const * asInsetGraphics() const { return nullptr;
}
+ /// is this inset based on the InsetFloat class?
+ virtual InsetFloat const * asInsetFloat() const { return nullptr; }
/// the real dispatcher
void dispatch(Cursor & cur, FuncRequest & cmd);
diff --git a/src/insets/InsetCaption.cpp b/src/insets/InsetCaption.cpp
index b215cab10d..c7f576aa6d 100644
--- a/src/insets/InsetCaption.cpp
+++ b/src/insets/InsetCaption.cpp
@@ -426,28 +426,27 @@ void InsetCaption::updateBuffer(ParIterator const & it,
UpdateType utype, bool c
name = bformat(_("Sub-%1$s"),
master.B_(tclass.floats().getType(type).name()));
}
- docstring sec;
docstring const lstring = getLayout().labelstring();
docstring const labelstring = isAscii(lstring) ?
master.B_(to_ascii(lstring)) : lstring;
if (cnts.hasCounter(counter)) {
- int val = cnts.value(counter);
+ int const val = cnts.value(counter);
// for longtables, we step the counter upstream
if (!cnts.isLongtable())
cnts.step(counter, utype);
- sec = cnts.theCounter(counter, lang);
+ val_ = cnts.theCounter(counter, lang);
if (deleted && !cnts.isLongtable())
// un-step after deleted counter
cnts.set(counter, val);
}
if (labelstring != master.B_("standard")) {
- if (!sec.empty())
- sec += from_ascii(" ");
- sec += bformat(from_ascii("(%1$s)"), labelstring);
+ if (!val_.empty())
+ val_ += from_ascii(" ");
+ val_ += bformat(from_ascii("(%1$s)"), labelstring);
}
- if (sec.empty())
- sec = from_ascii("#");
- full_label_ = bformat(master.B_("%1$s %2$s: [[Caption label
(ex. Figure 1: )]]"), name, sec);
+ if (val_.empty())
+ val_ = from_ascii("#");
+ full_label_ = bformat(master.B_("%1$s %2$s: [[Caption label
(ex. Figure 1: )]]"), name, val_);
non_float_ = false;
}
diff --git a/src/insets/InsetCaption.h b/src/insets/InsetCaption.h
index 4f5fa8524b..eb21503b83 100644
--- a/src/insets/InsetCaption.h
+++ b/src/insets/InsetCaption.h
@@ -36,6 +36,8 @@ public:
void writeCaptionAsHTML(XMLStream & os, OutputParams const &) const;
///
std::string contextMenuName() const override;
+ ///
+ docstring counterValue() const { return val_; }
private:
///
void write(std::ostream & os) const override;
@@ -108,6 +110,8 @@ private:
///
bool non_float_ = false;
///
+ docstring val_;
+ ///
std::string type_;
};
diff --git a/src/insets/InsetCaptionable.h b/src/insets/InsetCaptionable.h
index ac11f55ca2..aa063256e1 100644
--- a/src/insets/InsetCaptionable.h
+++ b/src/insets/InsetCaptionable.h
@@ -33,9 +33,8 @@ public:
///
docstring floatName(std::string const & type) const;
///
-protected:
- ///
InsetCaption const * getCaptionInset() const;
+protected:
///
InsetLabel const * getLabelInset() const;
///
diff --git a/src/insets/InsetFloat.h b/src/insets/InsetFloat.h
index ada6add04a..e9e6c79a3b 100644
--- a/src/insets/InsetFloat.h
+++ b/src/insets/InsetFloat.h
@@ -78,6 +78,8 @@ public:
LyXAlignment contentAlignment() const override;
///
bool forceParDirectionSwitch() const override { return true; }
+ ///
+ InsetFloat const * asInsetFloat() const override { return this; }
private:
///
void setCaptionType(std::string const & type) override;
diff --git a/src/insets/InsetLabel.cpp b/src/insets/InsetLabel.cpp
index 8ab9b58c62..74ac080028 100644
--- a/src/insets/InsetLabel.cpp
+++ b/src/insets/InsetLabel.cpp
@@ -13,6 +13,8 @@
#include "InsetLabel.h"
#include "InsetRef.h"
+#include "InsetFloat.h"
+#include "InsetCaption.h"
#include "Buffer.h"
#include "BufferParams.h"
@@ -199,6 +201,7 @@ void InsetLabel::updateBuffer(ParIterator const & it,
UpdateType, bool const /*d
Counters & cnts =
buffer().masterBuffer()->params().documentClass().counters();
active_counter_ = cnts.currentCounter();
+ docstring const parent = (cnts.isSubfloat()) ?
cnts.currentParentCounter() : docstring();
Language const * lang = it->getParLanguage(buffer().params());
if (lang && !active_counter_.empty()) {
bool const equation = active_counter_ == from_ascii("equation");
@@ -222,6 +225,39 @@ void InsetLabel::updateBuffer(ParIterator const & it,
UpdateType, bool const /*d
formatted_counter_lc_ =
cnts.formattedCounter(active_counter_, prex, lang->code(), true);
formatted_counter_lc_pl_ =
cnts.formattedCounter(active_counter_, prex, lang->code(), true, true);
}
+ // handle subfloat references
+ if (!parent.empty()) {
+ docstring pc;
+ // The parent counter value might well be set
after
+ // the child (if the main caption comes at the
bottom
+ // of the float). So try to get that:
+ ParIterator nit = it;
+ for (size_type sl = 0 ; sl < it.depth() ; ++sl)
{
+ Paragraph const & outer_par =
it[sl].paragraph();
+ if (outer_par.inInset().lyxCode() !=
FLOAT_CODE)
+ continue;
+ InsetFloat const * fl =
outer_par.inInset().asInsetFloat();
+ if (fl) {
+ InsetCaption const * cap =
fl->getCaptionInset();
+ if (cap) {
+ if
(cap->counterValue().empty())
+ // the caption
has not been handled yet,
+ // so we need
another pass
+
buffer().masterBuffer()->forceUpdate(true);
+ else
+ pc =
cap->counterValue();
+ break;
+ }
+ }
+ break;
+ }
+ docstring const plain_value = counter_value_;
+ counter_value_ = pc + "(" + counter_value_ +
")";
+ formatted_counter_ = subst(formatted_counter_,
plain_value, counter_value_);
+ formatted_counter_pl_ =
subst(formatted_counter_pl_, plain_value, counter_value_);
+ formatted_counter_lc_ =
subst(formatted_counter_lc_, plain_value, counter_value_);
+ formatted_counter_lc_pl_ =
subst(formatted_counter_lc_pl_, plain_value, counter_value_);
+ }
if (equation) {
// FIXME: special code just for the
subequations module (#13199)
// replace with a genuine solution
long-term!
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs