mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-06 11:23:45 +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.
124 lines
2.2 KiB
C++
124 lines
2.2 KiB
C++
/**
|
|
* \file InsetMathBrace.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 "InsetMathBrace.h"
|
|
|
|
#include "MathData.h"
|
|
#include "MathStream.h"
|
|
#include "MathSupport.h"
|
|
#include "MetricsInfo.h"
|
|
|
|
#include "frontends/FontMetrics.h"
|
|
#include "frontends/Painter.h"
|
|
|
|
#include <ostream>
|
|
#include <algorithm>
|
|
|
|
using namespace std;
|
|
|
|
namespace lyx {
|
|
|
|
InsetMathBrace::InsetMathBrace(Buffer * buf)
|
|
: InsetMathNest(buf, 1)
|
|
{}
|
|
|
|
|
|
InsetMathBrace::InsetMathBrace(MathData const & ar)
|
|
: InsetMathNest(const_cast<Buffer *>(ar.buffer()), 1)
|
|
{
|
|
cell(0) = ar;
|
|
}
|
|
|
|
|
|
Inset * InsetMathBrace::clone() const
|
|
{
|
|
return new InsetMathBrace(*this);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::metrics(MetricsInfo & mi, Dimension & dim) const
|
|
{
|
|
Dimension dim0;
|
|
cell(0).metrics(mi, dim0);
|
|
FontInfo font = mi.base.font;
|
|
augmentFont(font, "mathnormal");
|
|
Dimension t = theFontMetrics(font).dimension('{');
|
|
dim.asc = max(dim0.asc, t.asc);
|
|
dim.des = max(dim0.des, t.des);
|
|
dim.wid = dim0.width() + 2 * t.wid;
|
|
}
|
|
|
|
|
|
void InsetMathBrace::draw(PainterInfo & pi, int x, int y) const
|
|
{
|
|
FontInfo font = pi.base.font;
|
|
augmentFont(font, "mathnormal");
|
|
font.setShape(UP_SHAPE);
|
|
font.setColor(Color_latex);
|
|
Dimension t = theFontMetrics(font).dimension('{');
|
|
pi.pain.text(x, y, '{', font);
|
|
cell(0).draw(pi, x + t.wid, y);
|
|
Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
|
|
pi.pain.text(x + t.wid + dim0.width(), y, '}', font);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::write(WriteStream & os) const
|
|
{
|
|
os << '{' << cell(0) << '}';
|
|
}
|
|
|
|
|
|
void InsetMathBrace::normalize(NormalStream & os) const
|
|
{
|
|
os << "[block " << cell(0) << ']';
|
|
}
|
|
|
|
|
|
void InsetMathBrace::maple(MapleStream & os) const
|
|
{
|
|
os << cell(0);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::octave(OctaveStream & os) const
|
|
{
|
|
os << cell(0);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::mathmlize(MathStream & os) const
|
|
{
|
|
os << MTag("mrow") << cell(0) << ETag("mrow");
|
|
}
|
|
|
|
|
|
void InsetMathBrace::htmlize(HtmlStream & os) const
|
|
{
|
|
os << cell(0);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::mathematica(MathematicaStream & os) const
|
|
{
|
|
os << cell(0);
|
|
}
|
|
|
|
|
|
void InsetMathBrace::infoize(odocstream & os) const
|
|
{
|
|
os << "Nested Block: ";
|
|
}
|
|
|
|
|
|
} // namespace lyx
|