mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-27 19:59:46 +00:00
89662a6852
The goal of this patch is to be able to properly remove the space
needed for markers in the case of insets that are inside macros and do
not need these markers. This was attempted at 9a9a6a8
, but did not
work reliably.
To this end, the following simplifications are made:
* instead of drawing its own markers, each inset has a virtual method
marker() which prescribes either NO_MARKER, MARKER (normal bottom
marker) or MARKER2 (top and bottom marker). All explicit calls to
(draw|metrics)Markers(|2) are removed.
* the space necessary for the markers is now counted in the
before/above margins in the row structure. Therefore painting will
not happen at (x + 1, y), but just (x,y).
* the methods drawDecoration are removed.
* the helper methods InsetMath::(draw|metrics)Markers(|2) are removed
and replaced by a new function drawMarkers in MathRow.cpp.
Now the marker type is kept in the MathRow::Element object (and set to
NO_MARKER in not editable context) and the marker is accounted for in
MathRow::(metrics|draw).
Moreover, the extra pixel for the marker is taken on the before/After
space if possible. The marker will only require extra space when
before/after is 0.
See comment 168 of #8883 to understand what issues are fixed.
116 lines
2.5 KiB
C++
116 lines
2.5 KiB
C++
/**
|
|
* \file InsetMathFontOld.cpp
|
|
* This file is part of LyX, the document processor.
|
|
* Licence details can be found in the file COPYING.
|
|
*
|
|
* \author André Pönitz
|
|
*
|
|
* Full author contact details are available in file CREDITS.
|
|
*/
|
|
|
|
#include <config.h>
|
|
|
|
#include "InsetMathFontOld.h"
|
|
|
|
#include "MathData.h"
|
|
#include "MathParser.h"
|
|
#include "MathStream.h"
|
|
#include "MathSupport.h"
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "support/gettext.h"
|
|
#include "support/lassert.h"
|
|
#include "support/lstrings.h"
|
|
|
|
#include <ostream>
|
|
|
|
using namespace lyx::support;
|
|
|
|
namespace lyx {
|
|
|
|
InsetMathFontOld::InsetMathFontOld(Buffer * buf, latexkeys const * key)
|
|
: InsetMathNest(buf, 1), key_(key), current_mode_(TEXT_MODE)
|
|
{
|
|
//lock(true);
|
|
}
|
|
|
|
|
|
std::string InsetMathFontOld::font() const
|
|
{
|
|
LASSERT(isAscii(key_->name), return "mathnormal");
|
|
return to_ascii(key_->name);
|
|
}
|
|
|
|
|
|
Inset * InsetMathFontOld::clone() const
|
|
{
|
|
return new InsetMathFontOld(*this);
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
{
|
|
current_mode_ = isTextFont(mi.base.fontname)
|
|
? TEXT_MODE : MATH_MODE;
|
|
|
|
std::string const fontname = current_mode_ == MATH_MODE
|
|
? "math" + font() : "text" + font();// I doubt that this still works
|
|
|
|
// When \cal is used in text mode, the font is not changed
|
|
bool really_change_font = fontname != "textcal";
|
|
|
|
Changer dummy = really_change_font ? mi.base.changeFontSet(fontname)
|
|
: Changer();
|
|
cell(0).metrics(mi, dim);
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::draw(PainterInfo & pi, int x, int y) const
|
|
{
|
|
current_mode_ = isTextFont(pi.base.fontname)
|
|
? TEXT_MODE : MATH_MODE;
|
|
|
|
std::string const fontname = current_mode_ == MATH_MODE
|
|
? "math" + font() : "text" + font();// I doubt that this still works
|
|
|
|
// When \cal is used in text mode, the font is not changed
|
|
bool really_change_font = fontname != "textcal";
|
|
|
|
Changer dummy = really_change_font ? pi.base.changeFontSet(fontname)
|
|
: Changer();
|
|
cell(0).draw(pi, x, y);
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
|
|
{
|
|
cell(0).metricsT(mi, dim);
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::drawT(TextPainter & pain, int x, int y) const
|
|
{
|
|
cell(0).drawT(pain, x, y);
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::write(WriteStream & os) const
|
|
{
|
|
os << "{\\" << key_->name << ' ' << cell(0) << '}';
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::normalize(NormalStream & os) const
|
|
{
|
|
os << "[font " << key_->name << ' ' << cell(0) << ']';
|
|
}
|
|
|
|
|
|
void InsetMathFontOld::infoize(odocstream & os) const
|
|
{
|
|
os << bformat(_("Font: %1$s"), key_->name);
|
|
}
|
|
|
|
|
|
} // namespace lyx
|