From d52e04a9b308c0cb72c93e416a4bd59d9e8f9b39 Mon Sep 17 00:00:00 2001 From: Jean-Marc Lasgouttes Date: Fri, 22 Mar 2019 16:13:30 +0100 Subject: [PATCH] Fix fonts used by sub/superscript in text 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 | 10 ++++++++++ src/insets/InsetScript.cpp | 5 +++-- src/insets/InsetScript.h | 4 +++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/Text3.cpp b/src/Text3.cpp index 6db9c2b8d5..e8c3dee124 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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(); diff --git a/src/insets/InsetScript.cpp b/src/insets/InsetScript.cpp index 918492fb55..c7bdd4279d 100644 --- a/src/insets/InsetScript.cpp +++ b/src/insets/InsetScript.cpp @@ -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; } diff --git a/src/insets/InsetScript.h b/src/insets/InsetScript.h index 3107b6255d..1aee8e8dd0 100644 --- a/src/insets/InsetScript.h +++ b/src/insets/InsetScript.h @@ -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_; }; -- 2.39.5