[LyX/master] Improve label font computation in insets

2023-06-21 Thread Jean-Marc Lasgouttes
commit 65b03c7c72a9871e3f603f07204705e644dbc96c
Author: Jean-Marc Lasgouttes 
Date:   Wed Jun 21 16:58:19 2023 +0200

Improve label font computation in insets

This patch reuses the code of TextMetrics::displayFont() that handles
the label part of LABEL_MANUAL paragraphs to create a new
labelDisplayFont() method usable for things like Itemize labels.

To this end, and new magic value is used as position to force the
label case in displayFont(). The code is also factored a bit and
cleaned up.

Fixes bug #12810.
---
 src/RowPainter.cpp  |2 +-
 src/TextMetrics.cpp |   45 +++--
 src/TextMetrics.h   |8 +++-
 3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/src/RowPainter.cpp b/src/RowPainter.cpp
index 4f5593e..b8db1aa 100644
--- a/src/RowPainter.cpp
+++ b/src/RowPainter.cpp
@@ -67,7 +67,7 @@ RowPainter::RowPainter(PainterInfo & pi,
 
 FontInfo RowPainter::labelFont(bool end) const
 {
-   FontInfo f = text_.labelFont(par_);
+   FontInfo f = tm_.labelDisplayFont(row_.pit()).fontInfo();
// selected text?
if ((end ? row_.end_margin_sel : row_.begin_margin_sel)
|| pi_.selected)
diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp
index f424118..88c8e81 100644
--- a/src/TextMetrics.cpp
+++ b/src/TextMetrics.cpp
@@ -289,55 +289,64 @@ void TextMetrics::applyOuterFont(Font & font) const
 }
 
 
+// This is an arbitrary magic value
+static const pos_type force_label = -12345;
+
+// if pos == force_label, this function will return the label font instead.
+// This undocumented and only for use by labelDisplayFont()
 Font TextMetrics::displayFont(pit_type pit, pos_type pos) const
 {
-   LASSERT(pos >= 0, { static Font f; return f; });
+   LASSERT(pos >= 0 || pos == force_label, { static Font f; return f; });
 
ParagraphList const & pars = text_->paragraphs();
Paragraph const & par = pars[pit];
Layout const & layout = par.layout();
Buffer const & buffer = bv_->buffer();
// FIXME: broken?
-   BufferParams const & params = buffer.params();
-   pos_type const body_pos = par.beginOfBody();
+   BufferParams const & bparams = buffer.params();
+   bool const label = pos < par.beginOfBody() || pos == force_label;
+
+   Font f = (pos == force_label) ? Font(inherit_font, bparams.language)
+ : par.getFontSettings(bparams, pos);
+   FontInfo const & lf = label ? layout.labelfont : layout.font;
 
// We specialize the 95% common case:
if (!par.getDepth()) {
-   Font f = par.getFontSettings(params, pos);
if (!text_->isMainText())
applyOuterFont(f);
-   bool lab = layout.labeltype == LABEL_MANUAL && pos < body_pos;
 
-   FontInfo const & lf = lab ? layout.labelfont : layout.font;
-   FontInfo rlf = lab ? layout.reslabelfont : layout.resfont;
+   FontInfo rlf = label ? layout.reslabelfont : layout.resfont;
 
// In case the default family has been customized
if (lf.family() == INHERIT_FAMILY)
-   rlf.setFamily(params.getFont().fontInfo().family());
+   rlf.setFamily(bparams.getFont().fontInfo().family());
f.fontInfo().realize(rlf);
return f;
}
 
-   // The uncommon case need not be optimized as much
-   FontInfo const & layoutfont = pos < body_pos ?
-   layout.labelfont : layout.font;
-
-   Font font = par.getFontSettings(params, pos);
-   font.fontInfo().realize(layoutfont);
+   // The uncommon case need not be optimized as much.
+   // FIXME : the two code paths seem different in function.
+   f.fontInfo().realize(lf);
 
if (!text_->isMainText())
-   applyOuterFont(font);
+   applyOuterFont(f);
 
// Realize against environment font information
// NOTE: the cast to pit_type should be removed when pit_type
// changes to a unsigned integer.
if (pit < pit_type(pars.size()))
-   font.fontInfo().realize(text_->outerFont(pit).fontInfo());
+   f.fontInfo().realize(text_->outerFont(pit).fontInfo());
 
// Realize with the fonts of lesser depth.
-   font.fontInfo().realize(params.getFont().fontInfo());
+   f.fontInfo().realize(bparams.getFont().fontInfo());
 
-   return font;
+   return f;
+}
+
+
+Font TextMetrics::labelDisplayFont(pit_type pit) const
+{
+   return displayFont(pit, force_label);
 }
 
 
diff --git a/src/TextMetrics.h b/src/TextMetrics.h
index cf53faa..74eef5e 100644
--- a/src/TextMetrics.h
+++ b/src/TextMetrics.h
@@ -79,13 +79,19 @@ public:
/// cache. Related to BufferView::updatePosCache.
void updatePosCache(pit_type pit) const;
 
-   /// Gets the fully instantiated font at a given posi

[LyX/master] Update tex2lyx tests

2023-06-21 Thread Scott Kostyshak
commit f208f180223aa0418cdb7c86619cdf9fa8255962
Author: Scott Kostyshak 
Date:   Wed Jun 21 14:38:23 2023 -0400

Update tex2lyx tests

Update the test files after the last format change (c3f98d1f).
---
 src/tex2lyx/test/CJK.lyx.lyx   |2 +-
 src/tex2lyx/test/CJKutf8.lyx.lyx   |2 +-
 src/tex2lyx/test/DummyDocument.lyx.lyx |2 +-
 src/tex2lyx/test/Dummy~Document.lyx.lyx|2 +-
 src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx |2 +-
 src/tex2lyx/test/algo2e.lyx.lyx|2 +-
 src/tex2lyx/test/beamer.lyx.lyx|2 +-
 .../test/box-color-size-space-align.lyx.lyx|2 +-
 src/tex2lyx/test/listpreamble.lyx.lyx  |2 +-
 src/tex2lyx/test/tabular-x-test.lyx.lyx|2 +-
 src/tex2lyx/test/test-insets-basic.lyx.lyx |2 +-
 src/tex2lyx/test/test-insets.lyx.lyx   |2 +-
 src/tex2lyx/test/test-memoir.lyx.lyx   |2 +-
 src/tex2lyx/test/test-minted.lyx.lyx   |2 +-
 src/tex2lyx/test/test-modules.lyx.lyx  |2 +-
 src/tex2lyx/test/test-refstyle-theorems.lyx.lyx|2 +-
 src/tex2lyx/test/test-scr.lyx.lyx  |2 +-
 src/tex2lyx/test/test-structure.lyx.lyx|2 +-
 src/tex2lyx/test/test.lyx.lyx  |2 +-
 src/tex2lyx/test/verbatim.lyx.lyx  |2 +-
 20 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/src/tex2lyx/test/CJK.lyx.lyx b/src/tex2lyx/test/CJK.lyx.lyx
index 884553b..12fc913 100644
--- a/src/tex2lyx/test/CJK.lyx.lyx
+++ b/src/tex2lyx/test/CJK.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/CJKutf8.lyx.lyx b/src/tex2lyx/test/CJKutf8.lyx.lyx
index eac7f50..0e0155d 100644
--- a/src/tex2lyx/test/CJKutf8.lyx.lyx
+++ b/src/tex2lyx/test/CJKutf8.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/DummyDocument.lyx.lyx 
b/src/tex2lyx/test/DummyDocument.lyx.lyx
index 12be303..c335ab5 100644
--- a/src/tex2lyx/test/DummyDocument.lyx.lyx
+++ b/src/tex2lyx/test/DummyDocument.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/Dummy~Document.lyx.lyx 
b/src/tex2lyx/test/Dummy~Document.lyx.lyx
index 3ad3bfd..9110eb4 100644
--- a/src/tex2lyx/test/Dummy~Document.lyx.lyx
+++ b/src/tex2lyx/test/Dummy~Document.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx 
b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
index 47ba3a9..65a7384 100644
--- a/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
+++ b/src/tex2lyx/test/XeTeX-polyglossia.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/algo2e.lyx.lyx b/src/tex2lyx/test/algo2e.lyx.lyx
index c1fb6f2..abd1e0d 100644
--- a/src/tex2lyx/test/algo2e.lyx.lyx
+++ b/src/tex2lyx/test/algo2e.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/beamer.lyx.lyx b/src/tex2lyx/test/beamer.lyx.lyx
index b3fafa0..312e500 100644
--- a/src/tex2lyx/test/beamer.lyx.lyx
+++ b/src/tex2lyx/test/beamer.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx 
b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
index 9e0d06e..b51e65e 100644
--- a/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
+++ b/src/tex2lyx/test/box-color-size-space-align.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/listpreamble.lyx.lyx 
b/src/tex2lyx/test/listpreamble.lyx.lyx
index c36e285..e3c62fb 100644
--- a/src/tex2lyx/test/listpreamble.lyx.lyx
+++ b/src/tex2lyx/test/listpreamble.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 616
 \begin_document
 \begin_header
 \save_transient_properties true
diff --git a/src/tex2lyx/test/tabular-x-test.lyx.lyx 
b/src/tex2lyx/test/tabular-x-test.lyx.lyx
index d592af3..e8c6795 100644
--- a/src/tex2lyx/test/tabular-x-test.lyx.lyx
+++ b/src/tex2lyx/test/tabular-x-test.lyx.lyx
@@ -1,5 +1,5 @@
 #LyX file created by tex2lyx 2.4
-\lyxformat 615
+\lyxformat 61