#include "MetricsInfo.h"
#include "OutputParams.h"
#include "RenderPreview.h"
+#include "texstream.h"
#include "frontends/Painter.h"
namespace lyx {
-InsetPreview::InsetPreview(Buffer * buf)
- : InsetText(buf),
- preview_(new RenderPreview(this)), use_preview_(true)
+InsetPreview::InsetPreview(Buffer * buf)
+ : InsetText(buf), preview_(new RenderPreview(this))
{
setDrawFrame(true);
setFrameColor(Color_previewframe);
}
-InsetPreview::~InsetPreview()
+InsetPreview::~InsetPreview()
{}
}
-void InsetPreview::preparePreview(DocIterator const & pos) const
+void InsetPreview::preparePreview(DocIterator const & pos) const
{
- TexRow texrow;
odocstringstream str;
- otexstream os(str, texrow);
+ otexstream os(str);
OutputParams runparams(&pos.buffer()->params().encoding());
latex(os, runparams);
dit.forwardInset();
for (; dit != dend; dit.forwardInset()) {
InsetMath * im = dit.nextInset()->asInsetMath();
- InsetMathHull * hull = im ? im->asHullInset() : 0;
+ InsetMathHull * hull = im ? im->asHullInset() : nullptr;
if (!hull)
continue;
for (idx_type idx = 0; idx < hull->nargs(); ++idx)
void InsetPreview::draw(PainterInfo & pi, int x, int y) const
{
- use_preview_ = previewState(pi.base.bv);
-
- if (use_preview_) {
+ if (previewState(pi.base.bv)) {
// one pixel gap in front
- preview_->draw(pi, x + 1 + TEXT_TO_INSET_OFFSET, y);
- setPosCache(pi, x, y);
- return;
- }
- InsetText::draw(pi, x, y);
+ preview_->draw(pi, x + 1, y);
+ } else
+ InsetText::draw(pi, x, y);
}
Inset * InsetPreview::editXY(Cursor & cur, int x, int y)
{
- if (use_preview_) {
+ if (previewState(&cur.bv())) {
edit(cur, true, ENTRY_DIRECTION_IGNORE);
return this;
}
{
if (previewState(mi.base.bv)) {
preview_->metrics(mi, dim);
- mi.base.textwidth += 2 * TEXT_TO_INSET_OFFSET;
-
+
dim.wid = max(dim.wid, 4);
dim.asc = max(dim.asc, 4);
-
- dim.asc += TEXT_TO_INSET_OFFSET;
- dim.des += TEXT_TO_INSET_OFFSET;
- dim.wid += TEXT_TO_INSET_OFFSET;
- dim_ = dim;
- dim.wid += TEXT_TO_INSET_OFFSET;
+
+ dim.asc += topOffset(mi.base.bv);
+ dim.des += bottomOffset(mi.base.bv);
// insert a one pixel gap
dim.wid += 1;
- // Cache the inset dimension.
- setDimCache(mi, dim);
Dimension dim_dummy;
MetricsInfo mi_dummy = mi;
InsetText::metrics(mi_dummy, dim_dummy);