mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
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.
This commit is contained in:
parent
6c4afc1ccb
commit
65b03c7c72
@ -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)
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
@ -79,13 +79,19 @@ public:
|
||||
/// cache. Related to BufferView::updatePosCache.
|
||||
void updatePosCache(pit_type pit) const;
|
||||
|
||||
/// Gets the fully instantiated font at a given position in a paragraph
|
||||
/// Gets the fully instantiated font at a given position in a paragraph.
|
||||
/// Basically the same routine as Paragraph::getFont() in Paragraph.cpp.
|
||||
/// The difference is that this one is used for displaying, and thus we
|
||||
/// are allowed to make cosmetic improvements. For instance make footnotes
|
||||
/// smaller. (Asger)
|
||||
Font displayFont(pit_type pit, pos_type pos) const;
|
||||
|
||||
/// Gets the fully instantiated label font of a paragraph.
|
||||
/// Basically the same routine as displayFont, but specialized for
|
||||
/// a layout font.
|
||||
Font labelDisplayFont(pit_type pit) const;
|
||||
|
||||
|
||||
/// There are currently two font mechanisms in LyX:
|
||||
/// 1. The font attributes in a lyxtext, and
|
||||
/// 2. The inset-specific font properties, defined in an inset's
|
||||
|
Loading…
Reference in New Issue
Block a user