]> git.lyx.org Git - features.git/commitdiff
Fix fonts used by sub/superscript in text
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Fri, 22 Mar 2019 15:13:30 +0000 (16:13 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:19 +0000 (15:48 +0200)
Several changes are needed to get things right:
* nested supersripts only work with inheritFonts=true.

* to get caret position right, it is necessary to remember the outside
  font of the inset before computing metrics.

* to get the size right at insertion time, it is necessary to trigger
  a metrics computation just after inset insertion.

src/Text3.cpp
src/insets/InsetScript.cpp
src/insets/InsetScript.h

index 6db9c2b8d5d7337c044d16b366a6bc0b39dc67b3..e8c3dee124554b75be9d50996300a70053b85bca 100644 (file)
@@ -2030,6 +2030,16 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                // inside it.
                doInsertInset(cur, this, cmd, true, true);
                cur.posForward();
+               if (act == LFUN_SCRIPT_INSERT) {
+                       /* Script insets change the font style in metrics(), and
+                        * this is used to compute the height of the caret
+                        * (because the font is stored in TextMetrics::font_).
+                        * When we insert, we have to make sure that metrics are
+                        * computed so that the caret height is wrong. Arguably,
+                        * this is hackish.*/
+                       bv->processUpdateFlags(Update::SinglePar);
+               }
+               cur.setCurrentFont();
                // Some insets are numbered, others are shown in the outline pane so
                // let's update the labels and the toc backend.
                cur.forceBufferUpdate();
index 918492fb55493041b31edd34a5b00e0f5b092fd4..c7bdd4279d0ee7778ae7dc5ad7ca46ead262d8cd 100644 (file)
@@ -160,6 +160,8 @@ Inset::DisplayType InsetScript::display() const
 void InsetScript::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        int const shift = params_.shift(mi.base.font);
+       // Remember the value of the outser font, so that it can be used in cursorPos.
+       outer_font_ = mi.base.font;
        Changer dummy = mi.base.changeScript();
        InsetText::metrics(mi, dim);
        dim.asc -= shift;
@@ -178,8 +180,7 @@ void InsetScript::draw(PainterInfo & pi, int x, int y) const
 void InsetScript::cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       Font const font = bv.textMetrics(&text()).displayFont(sl.pit(), sl.pos());
-       int const shift = params_.shift(font.fontInfo());
+       int const shift = params_.shift(outer_font_);
        InsetText::cursorPos(bv, sl, boundary, x, y);
        y += shift;
 }
index 3107b6255dd24c28a837bd42dc5f7d463f875204..1aee8e8dd00852085b125e70cd4bc8c27c744d8d 100644 (file)
@@ -86,7 +86,7 @@ public:
        ///
        bool neverIndent() const { return true; }
        ///
-       bool inheritFont() const { return false; }
+       bool inheritFont() const { return true; }
        ///
        int plaintext(odocstringstream & ods, OutputParams const & op,
                      size_t max_length = INT_MAX) const;
@@ -129,6 +129,8 @@ private:
        friend class InsetScriptParams;
        ///
        InsetScriptParams params_;
+       /// The font of containing inset; this is necessary to compute shift
+       mutable FontInfo outer_font_;
 };