]> git.lyx.org Git - features.git/commitdiff
* merge InsetMathMakebox and InsetMathFramebox
authorStefan Schimanski <sts@lyx.org>
Thu, 28 Feb 2008 12:46:32 +0000 (12:46 +0000)
committerStefan Schimanski <sts@lyx.org>
Thu, 28 Feb 2008 12:46:32 +0000 (12:46 +0000)
* only output second parameter if the first is available. That's how LaTeX defines make/framebox.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@23320 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/InsetMathBox.cpp
src/mathed/InsetMathBox.h
src/mathed/MathFactory.cpp

index e8fed0dd53b0259c25c46df8353c9b8487f8d05c..c5272c20e00ba2cba6b3bbfb35cdb36a33ed29b6 100644 (file)
@@ -125,17 +125,17 @@ void InsetMathFBox::infoize(odocstream & os) const
 
 /////////////////////////////////////////////////////////////////////
 //
-// InsetMathFrameBox
+// InsetMathMakebox
 //
 /////////////////////////////////////////////////////////////////////
 
 
-InsetMathFrameBox::InsetMathFrameBox()
-       : InsetMathNest(3)
+InsetMathMakebox::InsetMathMakebox(bool framebox)
+       : InsetMathNest(3), framebox_(framebox)
 {}
 
 
-void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
+void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        FontSetChanger dummy(mi.base, "textnormal");
        
@@ -151,64 +151,82 @@ void InsetMathFrameBox::metrics(MetricsInfo & mi, Dimension & dim) const
        cell(1).metrics(mi, dim1);
        cell(2).metrics(mi, dim2);
        
-       dim.wid = 5 + w + dim0.wid + w + 4 + w + dim1.wid + w + 4 + dim2.wid + 5;
+       dim.wid = w + dim0.wid + w + w + dim1.wid + w + 2 + dim2.wid;
        dim.asc = std::max(std::max(wdim.asc, dim0.asc), std::max(dim1.asc, dim2.asc)); 
        dim.des = std::max(std::max(wdim.des, dim0.des), std::max(dim1.des, dim2.des));
-       dim.asc += 3;
-       dim.des += 3;
+       
+       if (framebox_) {
+               dim.wid += 4;
+               dim.asc += 3;
+               dim.des += 2;
+       } else {
+               dim.asc += 1;
+               dim.des += 1;
+       }
        
        metricsMarkers(dim);
 }
 
 
-void InsetMathFrameBox::draw(PainterInfo & pi, int x, int y) const
+void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
 {
        drawMarkers(pi, x, y);
        
        FontSetChanger dummy(pi.base, "textnormal");
-       Dimension const dim = dimension(*pi.base.bv);
+       BufferView const & bv = *pi.base.bv;
        int w = mathed_char_width(pi.base.font, '[');
        
-       pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
-               dim.width() - 2, dim.height() - 2, Color_foreground);
+       if (framebox_) {
+               Dimension const dim = dimension(*pi.base.bv);
+               pi.pain.rectangle(x + 1, y - dim.ascent() + 1,
+                                 dim.width() - 2, dim.height() - 2, Color_foreground);
+               x += 2;
+       }
        
-       x += 5;
-       BufferView const & bv = *pi.base.bv;
-
        drawStrBlack(pi, x, y, from_ascii("["));
        x += w;
        cell(0).draw(pi, x, y);
        x += cell(0).dimension(bv).wid;
        drawStrBlack(pi, x, y, from_ascii("]"));
-       x += w + 4;
+       x += w;
 
        drawStrBlack(pi, x, y, from_ascii("["));
        x += w;
        cell(1).draw(pi, x, y);
        x += cell(1).dimension(bv).wid;
        drawStrBlack(pi, x, y, from_ascii("]"));
-       x += w + 4;
+       x += w + 2;
 
        cell(2).draw(pi, x, y);
 }
 
 
-void InsetMathFrameBox::write(WriteStream & os) const
+void InsetMathMakebox::write(WriteStream & os) const
 {
-       os << "\\framebox";
-       os << '[' << cell(0) << ']';
-       if (cell(1).size())
-               os << '[' << cell(1) << ']';
+       os << (framebox_ ? "\\framebox" : "\\makebox");
+       if (cell(0).size() || !os.latex()) {
+               os << '[' << cell(0) << ']';
+               if (cell(1).size() || !os.latex())
+                       os << '[' << cell(1) << ']';
+       }
        os << '{' << cell(2) << '}';
 }
 
 
-void InsetMathFrameBox::normalize(NormalStream & os) const
+void InsetMathMakebox::normalize(NormalStream & os) const
 {
-       os << "[framebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
+       os << (framebox_ ? "[framebox " : "[makebox ")
+          << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
 }
 
 
+void InsetMathMakebox::infoize(odocstream & os) const
+{
+       os << (framebox_ ? "Framebox" : "Makebox") 
+          << " (width: " << cell(0)
+          << " pos: " << cell(1) << ")";
+}
+
 
 /////////////////////////////////////////////////////////////////////
 //
@@ -262,76 +280,4 @@ void InsetMathBoxed::validate(LaTeXFeatures & features) const
 }
 
 
-/////////////////////////////////////////////////////////////////////
-//
-// InsetMathMakebox
-//
-/////////////////////////////////////////////////////////////////////
-
-
-InsetMathMakebox::InsetMathMakebox()
-       : InsetMathNest(3)
-{}
-
-
-void InsetMathMakebox::metrics(MetricsInfo & mi, Dimension & dim) const
-{
-       FontSetChanger dummy(mi.base, from_ascii("textnormal"));
-       w_ = mathed_char_width(mi.base.font, '[');
-       InsetMathNest::metrics(mi);
-       dim   = cell(0).dimension(*mi.base.bv);
-       dim  += cell(1).dimension(*mi.base.bv);
-       dim  += cell(2).dimension(*mi.base.bv);
-       dim.wid += 4 * w_ + 4;
-       metricsMarkers(dim);
-}
-
-
-void InsetMathMakebox::draw(PainterInfo & pi, int x, int y) const
-{
-       FontSetChanger dummy(pi.base, from_ascii("textnormal"));
-       drawMarkers(pi, x, y);
-
-       drawStrBlack(pi, x, y, from_ascii("["));
-       x += w_;
-       cell(0).draw(pi, x, y);
-       x += cell(0).dimension(*pi.base.bv).width();
-       drawStrBlack(pi, x, y, from_ascii("]"));
-       x += w_ + 2;
-
-       drawStrBlack(pi, x, y, from_ascii("["));
-       x += w_;
-       cell(1).draw(pi, x, y);
-       x += cell(1).dimension(*pi.base.bv).wid;
-       drawStrBlack(pi, x, y, from_ascii("]"));
-       x += w_ + 2;
-
-       cell(2).draw(pi, x, y);
-       setPosCache(pi, x, y);
-}
-
-
-void InsetMathMakebox::write(WriteStream & os) const
-{
-       os << "\\makebox";
-       os << '[' << cell(0) << ']';
-       if (cell(1).size())
-               os << '[' << cell(1) << ']';
-       os << '{' << cell(2) << '}';
-}
-
-
-void InsetMathMakebox::normalize(NormalStream & os) const
-{
-       os << "[makebox " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']';
-}
-
-
-void InsetMathMakebox::infoize(odocstream & os) const
-{
-       os << "Makebox (width: " << cell(0)
-           << " pos: " << cell(1) << ")";
-}
-
-
 } // namespace lyx
index b68280aaacf7ae60e3d9d2a8e5f8f16f9228d5bf..b2525aa8d1fcb0f9da865133b7eb0d770549276e 100644 (file)
@@ -67,32 +67,11 @@ private:
 };
 
 
-/// Extra nesting
-class InsetMathFrameBox : public InsetMathNest {
-public:
-       ///
-       InsetMathFrameBox();
-       ///
-       void metrics(MetricsInfo & mi, Dimension & dim) const;
-       ///
-       void draw(PainterInfo & pi, int x, int y) const;
-       ///
-       void write(WriteStream & os) const;
-       /// write normalized content
-       void normalize(NormalStream & ns) const;
-       ///
-       mode_type currentMode() const { return TEXT_MODE; }
-private:
-       Inset * clone() const { return new InsetMathFrameBox(*this); }
-};
-
-
-/// Extra nesting: \\makebox.
-// consolidate with InsetMathFrameBox?
+/// Extra nesting: \\makebox or \\framebox.
 class InsetMathMakebox : public InsetMathNest {
 public:
        ///
-       InsetMathMakebox();
+       InsetMathMakebox(bool framebox);
        ///
        void metrics(MetricsInfo & mi, Dimension & dim) const;
        ///
@@ -107,8 +86,8 @@ public:
        void infoize(odocstream & os) const;
 private:
        Inset * clone() const { return new InsetMathMakebox(*this); }
-       /// width of '[' in current font
-       mutable int w_;
+       ///
+       bool framebox_;
 };
 
 
index 7f84c9536af8f2901a97ef50aa02e0647c00974d..dbeb6d61f0d016e370eba4cecdb945e5cbd86de2 100644 (file)
@@ -302,9 +302,9 @@ MathAtom createInsetMath(docstring const & s)
        if (s == "fbox")
                return MathAtom(new InsetMathFBox());
        if (s == "framebox")
-               return MathAtom(new InsetMathFrameBox);
+               return MathAtom(new InsetMathMakebox(true));
        if (s == "makebox")
-               return MathAtom(new InsetMathMakebox);
+               return MathAtom(new InsetMathMakebox(false));
        if (s == "kern")
                return MathAtom(new InsetMathKern);
        if (s.substr(0, 8) == "xymatrix") {