mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 21:21:32 +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.
|
// inside it.
|
||||||
doInsertInset(cur, this, cmd, true, true);
|
doInsertInset(cur, this, cmd, true, true);
|
||||||
cur.posForward();
|
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
|
// Some insets are numbered, others are shown in the outline pane so
|
||||||
// let's update the labels and the toc backend.
|
// let's update the labels and the toc backend.
|
||||||
cur.forceBufferUpdate();
|
cur.forceBufferUpdate();
|
||||||
|
@ -160,6 +160,8 @@ Inset::DisplayType InsetScript::display() const
|
|||||||
void InsetScript::metrics(MetricsInfo & mi, Dimension & dim) const
|
void InsetScript::metrics(MetricsInfo & mi, Dimension & dim) const
|
||||||
{
|
{
|
||||||
int const shift = params_.shift(mi.base.font);
|
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();
|
Changer dummy = mi.base.changeScript();
|
||||||
InsetText::metrics(mi, dim);
|
InsetText::metrics(mi, dim);
|
||||||
dim.asc -= shift;
|
dim.asc -= shift;
|
||||||
@ -178,8 +180,7 @@ void InsetScript::draw(PainterInfo & pi, int x, int y) const
|
|||||||
void InsetScript::cursorPos(BufferView const & bv,
|
void InsetScript::cursorPos(BufferView const & bv,
|
||||||
CursorSlice const & sl, bool boundary, int & x, int & y) const
|
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(outer_font_);
|
||||||
int const shift = params_.shift(font.fontInfo());
|
|
||||||
InsetText::cursorPos(bv, sl, boundary, x, y);
|
InsetText::cursorPos(bv, sl, boundary, x, y);
|
||||||
y += shift;
|
y += shift;
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ public:
|
|||||||
///
|
///
|
||||||
bool neverIndent() const { return true; }
|
bool neverIndent() const { return true; }
|
||||||
///
|
///
|
||||||
bool inheritFont() const { return false; }
|
bool inheritFont() const { return true; }
|
||||||
///
|
///
|
||||||
int plaintext(odocstringstream & ods, OutputParams const & op,
|
int plaintext(odocstringstream & ods, OutputParams const & op,
|
||||||
size_t max_length = INT_MAX) const;
|
size_t max_length = INT_MAX) const;
|
||||||
@ -129,6 +129,8 @@ private:
|
|||||||
friend class InsetScriptParams;
|
friend class InsetScriptParams;
|
||||||
///
|
///
|
||||||
InsetScriptParams params_;
|
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