]> git.lyx.org Git - features.git/commitdiff
Account for real width of nucleus when positioning superscripts in mathed
authorEnrico Forestieri <forenr@lyx.org>
Wed, 21 Mar 2007 17:21:59 +0000 (17:21 +0000)
committerEnrico Forestieri <forenr@lyx.org>
Wed, 21 Mar 2007 17:21:59 +0000 (17:21 +0000)
* src/mathed/MathSupport.[Ch]
(mathed_char_kerning): New. Compute right kerning for the given
font and character as the difference between right bearing and
logical width.

* src/mathed/InsetMathScript.[Ch]
(InsetMathScript::dx1, InsetMathScript::metrics): Account for
nucleus right kerning.
(InsetMathScript::nker): New. Return the nucleus right kerning
if positive, zero otherwise.

* src/mathed/MathData.[Ch]
(MathArray::metrics): Cache the nucleus right kerning value.
(MathArray::kerning): New. Return cached right kerning.

* src/mathed/InsetMathChar.[Ch]
(InsetMathChar::metrics): Cache the character right kerning.
(InsetMathChar::kerning): New. Return cached right kerning.

* src/mathed/InsetMath.h
(InsetMath::kerning): New virtual method.

* src/mathed/InsetMathSymbol.[Ch]
(InsetMathSymbol::metrics): Cache the symbol right kerning.
(InsetMathSymbol::kerning): New. Return cached right kerning.

* src/mathed/InsetMathFont.[Ch]
(InsetMathFont::kerning): New. Return cached right kerning.

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

12 files changed:
src/mathed/InsetMath.h
src/mathed/InsetMathChar.C
src/mathed/InsetMathChar.h
src/mathed/InsetMathFont.h
src/mathed/InsetMathScript.C
src/mathed/InsetMathScript.h
src/mathed/InsetMathSymbol.C
src/mathed/InsetMathSymbol.h
src/mathed/MathData.C
src/mathed/MathData.h
src/mathed/MathSupport.C
src/mathed/MathSupport.h

index 90b8aabb09443e16ddb42564fce220fe2f07aa4c..6602d98b9caaf8f4ed946ab7eb948a39f5aca571 100644 (file)
@@ -200,6 +200,9 @@ public:
 
        /// math stuff usually isn't allowed in text mode
        virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
+
+       /// superscript kerning
+       virtual int kerning() const { return 0; }
 };
 
 ///
index 3557d2efc450fd0058921e7e40cb6e0aa197ff1b..192ff94be94133e81039695c1feaa9b27cfbb09e 100644 (file)
@@ -46,7 +46,7 @@ namespace {
 
 
 InsetMathChar::InsetMathChar(char_type c)
-       : char_(c)
+       : char_(c), kerning_(0)
 {}
 
 
@@ -70,7 +70,9 @@ bool InsetMathChar::metrics(MetricsInfo & mi, Dimension & dim) const
                ShapeChanger dummy(mi.base.font, LyXFont::UP_SHAPE);
                dim = theFontMetrics(mi.base.font).dimension(char_);
        } else {
-               dim = theFontMetrics(mi.base.font).dimension(char_);
+               frontend::FontMetrics const & fm = theFontMetrics(mi.base.font);
+               dim = fm.dimension(char_);
+               kerning_ = fm.rbearing(char_) - dim.wid;
        }
        int const em = mathed_char_width(mi.base.font, 'M');
        if (isBinaryOp(char_))
index 8ee4e9c5cc0c84809776637be2511bea210b6ef4..91bd1599394d4b3290b1fe870c22b37f6cc14961 100644 (file)
@@ -32,6 +32,8 @@ public:
        void drawT(TextPainter &, int x, int y) const;
        ///
        int width() const { return width_; }
+       ///
+       int kerning() const { return kerning_; }
 
        ///
        void write(WriteStream & os) const;
@@ -54,6 +56,8 @@ private:
        char_type char_;
        /// cached width
        mutable int width_;
+       /// cached kerning for superscript
+       mutable int kerning_;
 };
 
 } // namespace lyx
index 085ca65b566e6c8a38feee60d49b8c68e2956dca..72a0728a6a81c57039b83adfde4ec3264a5a5246 100644 (file)
@@ -45,6 +45,8 @@ public:
        void validate(LaTeXFeatures & features) const;
        ///
        void infoize(odocstream & os) const;
+       ///
+       int kerning() const { return cell(0).kerning(); }
 
 private:
        virtual std::auto_ptr<InsetBase> doClone() const;
index d7e1d879bc0d1ea040ac96b5ea2f514eb4cf9e85..e65d9c74a494c43d44b46d19c1698f8f9e5317cd 100644 (file)
@@ -225,7 +225,7 @@ int InsetMathScript::dx0() const
 int InsetMathScript::dx1() const
 {
        BOOST_ASSERT(hasUp());
-       return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid();
+       return hasLimits() ? (dim_.wid - up().width()) / 2 : nwid() + nker();
 }
 
 
@@ -253,6 +253,16 @@ int InsetMathScript::ndes() const
 }
 
 
+int InsetMathScript::nker() const
+{
+       if (nuc().size()) {
+               int kerning = nuc().kerning();
+               return kerning > 0 ? kerning : 0;
+       }
+       return 0;
+}
+
+
 bool InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        cell(0).metrics(mi);
@@ -270,7 +280,7 @@ bool InsetMathScript::metrics(MetricsInfo & mi, Dimension & dim) const
                        dim.wid = max(dim.wid, down().width());
        } else {
                if (hasUp())
-                       dim.wid = max(dim.wid, up().width());
+                       dim.wid = max(dim.wid, nker() + up().width());
                if (hasDown())
                        dim.wid = max(dim.wid, down().width());
                dim.wid += nwid();
index 1a631b3ba8f1ede3b702f8f7969365ee5e29a42b..9f346e21c0690c829f8481926144f44b94a5298c 100644 (file)
@@ -124,6 +124,8 @@ private:
        int nasc() const;
        /// returns descent of nucleus if any
        int ndes() const;
+       /// returns superscript kerning of nucleus if any
+       int nker() const;
        /// where do we have to draw the scripts?
        bool hasLimits() const;
        /// clean up empty cells and return true if a cell has been deleted.
index 1a5176b66667077bf8e41cc59271365955981416..15ef723034d614bd608246d93b36bce1e162150a 100644 (file)
@@ -64,6 +64,8 @@ bool InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
        int const em = mathed_char_width(mi.base.font, 'M');
        FontSetChanger dummy(mi.base, sym_->inset);
        mathed_string_dim(mi.base.font, sym_->draw, dim);
+       docstring::const_reverse_iterator rit = sym_->draw.rbegin();
+       kerning_ = mathed_char_kerning(mi.base.font, *rit);
        // correct height for broken cmex and wasy font
        if (sym_->inset == "cmex" || sym_->inset == "wasy") {
                h_ = 4 * dim.des / 5;
index c34d30c696789a76298cb9e8bfdc221a0c606968..5ac141724c2fe3062dce4ab56c29e44fd2ed451b 100644 (file)
@@ -37,6 +37,8 @@ public:
        void draw(PainterInfo &, int x, int y) const;
        ///
        int width() const { return width_; }
+       ///
+       int kerning() const { return kerning_; }
 
        ///
        bool isRelOp() const;
@@ -76,6 +78,8 @@ private:
        mutable int h_;
        /// cached width
        mutable int width_;
+       /// cached superscript kerning
+       mutable int kerning_;
        ///
        mutable bool scriptable_;
 };
index 2509dae423def97ed325ae696b937c3b8f8a1d61..babbef64b80b61cb317ab24646f124a97d5db3d1 100644 (file)
@@ -282,6 +282,8 @@ void MathArray::metrics(MetricsInfo & mi) const
 #endif
                at->metrics(mi, d);
                dim_ += d;
+               if (i == n - 1)
+                       kerning_ = at->kerning();
        }
 }
 
index db7b28024e644896495a00a69691363d104c2043..1fdac721e838b7c0ae7db0492fce751cd5a93091 100644 (file)
@@ -158,6 +158,8 @@ public:
        int slevel() const { return slevel_; }
        /// additional super/subscript shift
        int sshift() const { return sshift_; }
+       /// superscript kerning
+       int kerning() const { return kerning_; }
 
 protected:
        /// cached dimensions of cell
@@ -167,6 +169,7 @@ protected:
        mutable int mindes_;
        mutable int slevel_;
        mutable int sshift_;
+       mutable int kerning_;
 
 private:
        /// is this an exact match at this position?
index 44a5393d09fcab81618bd0dff4de1ea0b387529b..f338e08c4939830bebac2ba21d3a6933dc3f9251 100644 (file)
@@ -373,6 +373,13 @@ int mathed_char_width(LyXFont const & font, char_type c)
 }
 
 
+int mathed_char_kerning(LyXFont const & font, char_type c)
+{
+       frontend::FontMetrics const & fm = theFontMetrics(font);
+       return fm.rbearing(c) - fm.width(c);
+}
+
+
 void mathed_string_dim(LyXFont const & font,
                       docstring const & s,
                       Dimension & dim)
index d872b371f90ce7716e4832b51fdb135c756b3d7c..b37d42bc33a01f47685c2fe0210c0a3c38ded029 100644 (file)
@@ -30,6 +30,8 @@ class InsetMath;
 
 int mathed_char_width(LyXFont const &, char_type c);
 
+int mathed_char_kerning(LyXFont const &, char_type c);
+
 void mathed_draw_deco(PainterInfo & pi, int x, int y, int w, int h,
        docstring const & name);