mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
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.
This commit is contained in:
parent
cfb8b214d1
commit
d52e04a9b3
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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_;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user