]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
* src/LyXRC.{cpp,h}:
[lyx.git] / src / TextMetrics.cpp
index 5c68b70230f510a633a75bcf3e09ed5108bf9acb..e7639c84cc01f2c566a3713172a919d64369fea5 100644 (file)
@@ -40,6 +40,9 @@
 #include "Text.h"
 #include "VSpace.h"
 
+#include "mathed/MacroTable.h"
+#include "mathed/MathMacroTemplate.h"
+
 #include "frontends/FontMetrics.h"
 #include "frontends/Painter.h"
 
@@ -382,15 +385,40 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        // FIXME: We should always use getFont(), see documentation of
        // noFontChange() in Inset.h.
        Font const bufferfont = buffer.params().getFont();
+       MacroContext mc(buffer, par);
        InsetList::const_iterator ii = par.insetList().begin();
        InsetList::const_iterator iend = par.insetList().end();
        for (; ii != iend; ++ii) {
+               // the macro must come here, _before_ the metric call, because
+               // the macro should see itself to detect recursions. To find out
+               // whether the macro definition is a redefinition it will look
+               // at the MacroData::redefinition_. So it doesn't get confused
+               // by the already existing macro definition of itself in the 
+               // macro context.
+               if (ii->inset->lyxCode() == MATHMACRO_CODE) {
+                       // get macro data
+                       MathMacroTemplate const & macroTemplate
+                       = static_cast<MathMacroTemplate const &>(*ii->inset);
+
+                       // valid?
+                       if (macroTemplate.validMacro()) {
+                               MacroData macro = macroTemplate.asMacroData();
+
+                               // redefinition?
+                               macro.setRedefinition(mc.has(macroTemplate.name()));
+
+                               // register macro (possibly overwrite the previous one of this paragraph)
+                               mc.insert(macroTemplate.name(), macro);
+                       }
+               }
+
+               // do the metric calculation
                Dimension dim;
                int const w = max_width_ - leftMargin(max_width_, pit, ii->pos)
                        - right_margin;
                Font const & font = ii->inset->noFontChange() ?
                        bufferfont : getDisplayFont(pit, ii->pos);
-               MetricsInfo mi(bv_, font.fontInfo(), w);
+               MetricsInfo mi(bv_, font.fontInfo(), w, mc);
                ii->inset->metrics(mi, dim);
                Dimension const old_dim = pm.insetDimension(ii->inset);
                pm.setInsetDimension(ii->inset, dim);