]> git.lyx.org Git - features.git/commitdiff
Transfer current_font and real_current_font from Text to Cursor.
authorAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 13:35:48 +0000 (13:35 +0000)
committerAbdelrazak Younes <younes@lyx.org>
Sun, 2 Sep 2007 13:35:48 +0000 (13:35 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19999 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/Buffer.cpp
src/BufferView.cpp
src/Cursor.cpp
src/Cursor.h
src/Paragraph.cpp
src/Text.cpp
src/Text.h
src/Text2.cpp
src/Text3.cpp
src/TextMetrics.cpp
src/frontends/WorkArea.cpp
src/insets/InsetERT.cpp
src/insets/InsetListings.cpp
src/insets/InsetText.cpp

index 75fd9e024ae33a42367724ab2d7e96c304f7d4a4..42a602b169a3edc5582742be6c4e7157cfb67dea 100644 (file)
@@ -1530,9 +1530,6 @@ void Buffer::changeLanguage(Language const * from, Language const * to)
        for_each(par_iterator_begin(),
                 par_iterator_end(),
                 bind(&Paragraph::changeLanguage, _1, params(), from, to));
-
-       text().current_font.setLanguage(to);
-       text().real_current_font.setLanguage(to);
 }
 
 
index 97e8d694cb39b6c6cf99054cd0ca0b23c627c3ab..7fbd7187be614a96428e28cd8da0884345738d13 100644 (file)
@@ -134,7 +134,7 @@ BufferView::BufferView(Buffer & buf)
 
        cursor_.push(buffer_.inset());
        cursor_.resetAnchor();
-       buffer_.text().setCurrentFont(cursor_);
+       cursor_.setCurrentFont();
 
        if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
                graphics::Previews::get().generateBufferPreviews(buffer_);
@@ -457,7 +457,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
                // Note: only bottom (document) level pit is set.
                setCursor(doc_it);
                // set the current font.
-               buffer_.text().setCurrentFont(cursor_);
+               cursor_.setCurrentFont();
                // center the screen on this new position.
                center();
        }
@@ -469,7 +469,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
 void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur)
 {
        if (lyxrc.rtl_support) {
-               if (cursor_.innerText()->real_current_font.isRightToLeft()) {
+               if (cursor_.real_current_font.isRightToLeft()) {
                        if (intl_->keymap == Intl::PRIMARY)
                                intl_->keyMapSec();
                } else {
index 2dd33f2af14d6d6f98b12dc34ff6fb648904c331..7b4bc6a4e361434490f2eb8b7bf7fabc73561cc3 100644 (file)
@@ -266,7 +266,7 @@ namespace {
 // bv functions are not yet available!
 Cursor::Cursor(BufferView & bv)
        : DocIterator(), bv_(&bv), anchor_(), x_target_(-1), textTargetOffset_(0),
-         selection_(false), mark_(false), logicalpos_(false)
+         selection_(false), mark_(false), logicalpos_(false), current_font(Font::ALL_INHERIT)
 {}
 
 
@@ -1437,7 +1437,7 @@ void Cursor::noUpdate()
 
 Font Cursor::getFont() const
 {
-       // The logic here should more or less match to the Text::setCurrentFont
+       // The logic here should more or less match to the Cursor::setCurrentFont
        // logic, i.e. the cursor height should give a hint what will happen
        // if a character is entered.
        
@@ -1504,4 +1504,46 @@ bool notifyCursorLeaves(DocIterator const & old, Cursor & cur)
 }
 
 
+void Cursor::setCurrentFont()
+{
+       pos_type cpos = pos();
+       Paragraph & par = paragraph();
+       Text const & ctext = *text();
+
+       // are we behind previous char in fact? -> go to that char
+       if (cpos > 0 && boundary())
+               --cpos;
+
+       // find position to take the font from
+       if (cpos != 0) {
+               // paragraph end? -> font of last char
+               if (cpos == lastpos())
+                       --cpos;
+               // on space? -> look at the words in front of space
+               else if (cpos > 0 && par.isSeparator(cpos))     {
+                       // abc| def -> font of c
+                       // abc |[WERBEH], i.e. boundary==true -> font of c
+                       // abc [WERBEH]| def, font of the space
+                       if (!ctext.isRTLBoundary(buffer(), par, cpos))
+                               --cpos;
+               }
+       }
+
+       // get font
+       BufferParams const & bufparams = buffer().params();
+       current_font = par.getFontSettings(bufparams, cpos);
+       real_current_font = ctext.getFont(buffer(), par, cpos);
+
+       // special case for paragraph end
+       if (pos() == lastpos()
+           && ctext.isRTLBoundary(buffer(), par, pos())
+           && !boundary()) {
+               Language const * lang = par.getParLanguage(bufparams);
+               current_font.setLanguage(lang);
+               current_font.setNumber(Font::OFF);
+               real_current_font.setLanguage(lang);
+               real_current_font.setNumber(Font::OFF);
+       }
+}
+
 } // namespace lyx
index c56538a2df84148e8c6506c2fe08d8f1359f823e..27f2174d3c4dafade8277518d98e9a0121423ba8 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "DispatchResult.h"
 #include "DocIterator.h"
+#include "Font.h"
 
 #include <iosfwd>
 #include <vector>
@@ -25,7 +26,6 @@ class Buffer;
 class BufferView;
 class FuncStatus;
 class FuncRequest;
-class Font;
 class Row;
 
 // these should go
@@ -61,6 +61,9 @@ public:
        /// sets cursor part
        void setCursor(DocIterator const & it);
 
+       ///
+       void setCurrentFont();
+
        //
        // selection
        //
@@ -230,6 +233,13 @@ private:
        /// position before dispatch started
        DocIterator beforeDispatchCursor_;
 
+// FIXME: make them private.
+public:
+       /// the current font settings
+       Font current_font;
+       /// the current font
+       Font real_current_font;
+
 private:
 
        //
index fc606dca47a23768c7c4df7f71ae2aee2166c44d..fc416bae2d18ba756d00d2c51e8a2a266240b8f5 100644 (file)
@@ -1284,17 +1284,6 @@ void Paragraph::insertInset(pos_type pos, Inset * inset,
        pimpl_->insertInset(pos, inset, change);
        // Set the font/language of the inset...
        setFont(pos, font);
-       // ... as well as the font/language of the text inside the inset
-       // FIXME: This is far from perfect. It basically overrides work being done
-       // in the InsetText constructor. Also, it doesn't work for Tables 
-       // (precisely because each cell's font/language is set in the Table's 
-       // constructor, so by now it's too late). The long-term solution should
-       // be moving current_font into Cursor, and getting rid of all this...
-       // (see http://thread.gmane.org/gmane.editors.lyx.devel/88869/focus=88944)
-       if (inset->asTextInset()) {
-               inset->asTextInset()->text_.current_font = font;
-               inset->asTextInset()->text_.real_current_font = font;
-       }
 }
 
 
index b86de4cdb7ae954e363e24ef5c7d0b7fff9228ac..35912086a85f0619a227f5a27fd3e8d65b5135a2 100644 (file)
@@ -459,7 +459,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                static docstring const number_unary_operators = from_ascii("+-");
                static docstring const number_seperators = from_ascii(".,:");
 
-               if (current_font.number() == Font::ON) {
+               if (cur.current_font.number() == Font::ON) {
                        if (!isDigit(c) && !contains(number_operators, c) &&
                            !(contains(number_seperators, c) &&
                              cur.pos() != 0 &&
@@ -469,7 +469,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                           )
                                number(cur); // Set current_font.number to OFF
                } else if (isDigit(c) &&
-                          real_current_font.isVisibleRightToLeft()) {
+                          cur.real_current_font.isVisibleRightToLeft()) {
                        number(cur); // Set current_font.number to ON
 
                        if (cur.pos() != 0) {
@@ -479,11 +479,11 @@ void Text::insertChar(Cursor & cur, char_type c)
                                     || par.isSeparator(cur.pos() - 2)
                                     || par.isNewline(cur.pos() - 2))
                                  ) {
-                                       setCharFont(buffer, pit, cur.pos() - 1, current_font);
+                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font);
                                } else if (contains(number_seperators, c)
                                     && cur.pos() >= 2
                                     && getFont(buffer, par, cur.pos() - 2).number() == Font::ON) {
-                                       setCharFont(buffer, pit, cur.pos() - 1, current_font);
+                                       setCharFont(buffer, pit, cur.pos() - 1, cur.current_font);
                                }
                        }
                }
@@ -515,7 +515,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                // get font in front and behind the space in question. But do NOT 
                // use getFont(cur.pos()) because the character c is not inserted yet
                Font const & pre_space_font  = getFont(buffer, par, cur.pos() - 2);
-               Font const & post_space_font = real_current_font;
+               Font const & post_space_font = cur.real_current_font;
                bool pre_space_rtl  = pre_space_font.isVisibleRightToLeft();
                bool post_space_rtl = post_space_font.isVisibleRightToLeft();
                
@@ -564,7 +564,7 @@ void Text::insertChar(Cursor & cur, char_type c)
                }
        }
 
-       par.insertChar(cur.pos(), c, current_font, cur.buffer().params().trackChanges);
+       par.insertChar(cur.pos(), c, cur.current_font, cur.buffer().params().trackChanges);
        checkBufferStructure(cur.buffer(), cur);
 
 //             cur.updateFlags(Update::Force);
@@ -1100,7 +1100,7 @@ bool Text::backspace(Cursor & cur)
        }
 
        if (cur.pos() == cur.lastpos())
-               setCurrentFont(cur);
+               cur.setCurrentFont();
 
        needsUpdate |= handleBibitems(cur);
 
@@ -1287,7 +1287,7 @@ docstring Text::currentState(Cursor & cur)
        // I think we should only show changes from the default
        // font. (Asger)
        // No, from the document font (MV)
-       Font font = real_current_font;
+       Font font = cur.real_current_font;
        font.reduce(buf.params().getFont());
 
        os << bformat(_("Font: %1$s"), font.stateText(&buf.params()));
index b5db10f07e5ac04e0915d81cce14b03c721898c4..b7764d7d8081cf27a65e617d1085c362cbf15938 100644 (file)
@@ -168,8 +168,6 @@ public:
        ///
        void setCursorIntern(Cursor & cur, pit_type par,
                 pos_type pos, bool setfont = true, bool boundary = false);
-       ///
-       void setCurrentFont(Cursor & cur);
 
        ///
        void recUndo(Cursor & cur, pit_type first, pit_type last) const;
@@ -291,10 +289,6 @@ public:
        void deleteEmptyParagraphMechanism(pit_type first, pit_type last, bool trackChanges);
 
 public:
-       /// the current font settings
-       Font current_font;
-       /// the current font
-       Font real_current_font;
        ///
        int background_color_;
 
index b55827be5fbb026213c60d1e3454f939e75088a8..14afb1a49b933991d4bf1c422391a626205a4feb 100644 (file)
@@ -71,8 +71,7 @@ using std::istringstream;
 namespace lyx {
 
 Text::Text()
-       : current_font(Font::ALL_INHERIT),
-         background_color_(Color::background),
+       : background_color_(Color::background),
          autoBreakRows_(false)
 {}
 
@@ -410,15 +409,15 @@ void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
                layoutfont = getLayoutFont(cur.buffer(), pit);
 
        // Update current font
-       real_current_font.update(font,
+       cur.real_current_font.update(font,
                                        cur.buffer().params().language,
                                        toggleall);
 
        // Reduce to implicit settings
-       current_font = real_current_font;
-       current_font.reduce(layoutfont);
+       cur.current_font = cur.real_current_font;
+       cur.current_font.reduce(layoutfont);
        // And resolve it completely
-       real_current_font.realize(layoutfont);
+       cur.real_current_font.realize(layoutfont);
 
        // if there is no selection that's all we need to do
        if (!cur.selection())
@@ -574,7 +573,7 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 {
        BOOST_ASSERT(this == cur.text());
        BOOST_ASSERT(inset);
-       cur.paragraph().insertInset(cur.pos(), inset, current_font,
+       cur.paragraph().insertInset(cur.pos(), inset, cur.current_font,
                                    Change(cur.buffer().params().trackChanges ?
                                           Change::INSERTED : Change::UNCHANGED));
 }
@@ -584,7 +583,7 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 void Text::insertStringAsLines(Cursor & cur, docstring const & str)
 {
        cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
-                                        current_font, str, autoBreakRows_);
+                                        cur.current_font, str, autoBreakRows_);
 }
 
 
@@ -655,50 +654,7 @@ void Text::setCursorIntern(Cursor & cur,
        cur.boundary(boundary);
        setCursor(cur.top(), par, pos);
        if (setfont)
-               setCurrentFont(cur);
-}
-
-
-void Text::setCurrentFont(Cursor & cur)
-{
-       BOOST_ASSERT(this == cur.text());
-       pos_type pos = cur.pos();
-       Paragraph & par = cur.paragraph();
-
-       // are we behind previous char in fact? -> go to that char
-       if (pos > 0 && cur.boundary())
-               --pos;
-
-       // find position to take the font from
-       if (pos != 0) {
-               // paragraph end? -> font of last char
-               if (pos == cur.lastpos())
-                       --pos;
-               // on space? -> look at the words in front of space
-               else if (pos > 0 && par.isSeparator(pos))       {
-                       // abc| def -> font of c
-                       // abc |[WERBEH], i.e. boundary==true -> font of c
-                       // abc [WERBEH]| def, font of the space
-                       if (!isRTLBoundary(cur.buffer(), par, pos))
-                               --pos;
-               }
-       }
-
-       // get font
-       BufferParams const & bufparams = cur.buffer().params();
-       current_font = par.getFontSettings(bufparams, pos);
-       real_current_font = getFont(cur.buffer(), par, pos);
-
-       // special case for paragraph end
-       if (cur.pos() == cur.lastpos()
-           && isRTLBoundary(cur.buffer(), par, cur.pos())
-           && !cur.boundary()) {
-               Language const * lang = par.getParLanguage(bufparams);
-               current_font.setLanguage(lang);
-               current_font.setNumber(Font::OFF);
-               real_current_font.setLanguage(lang);
-               real_current_font.setNumber(Font::OFF);
-       }
+               cur.setCurrentFont();
 }
 
 
index 1a69796261af50e39dc4fce21b9e14c48db6cb97..438f0599390437643cd89e732509ee4ab9ee5472 100644 (file)
@@ -104,7 +104,7 @@ namespace {
                                font.number() != Font::IGNORE) {
                        Paragraph & par = cur.paragraph();
                        if (cur.boundary() != text->isRTLBoundary(cur.buffer(), par,
-                                               cur.pos(), text->real_current_font))
+                                               cur.pos(), cur.real_current_font))
                                text->setCursor(cur, cur.pit(), cur.pos(),
                                                false, !cur.boundary());
                }
@@ -824,9 +824,9 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
        }
 
        case LFUN_SERVER_GET_FONT:
-               if (current_font.shape() == Font::ITALIC_SHAPE)
+               if (cur.current_font.shape() == Font::ITALIC_SHAPE)
                        cur.message(from_ascii("E"));
-               else if (current_font.shape() == Font::SMALLCAPS_SHAPE)
+               else if (cur.current_font.shape() == Font::SMALLCAPS_SHAPE)
                        cur.message(from_ascii("N"));
                else
                        cur.message(from_ascii("0"));
@@ -1096,7 +1096,7 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                }
 
                cur.clearSelection();
-               Font const old_font = real_current_font;
+               Font const old_font = cur.real_current_font;
 
                docstring::const_iterator cit = cmd.argument().begin();
                docstring::const_iterator end = cmd.argument().end();
@@ -1625,7 +1625,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        BOOST_ASSERT(cur.text() == this);
 
-       Font const & font = real_current_font;
+       Font const & font = cur.real_current_font;
        bool enable = true;
        Inset::Code code = Inset::NO_CODE;
 
index cde93d0cfb4cb899901575ce0df79285cbc3ea76..cb5946266832028daa23517cadf5e5a92fb5b783 100644 (file)
@@ -1112,7 +1112,9 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
        if (!inset) {
                // Either we deconst editXY or better we move current_font
                // and real_current_font to Cursor
-               text_->setCurrentFont(cur);
+               // FIXME: what is needed now that current_font and real_current_font
+               // are transferred?
+               cur.setCurrentFont();
                return 0;
        }
 
@@ -1136,7 +1138,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y)
        inset = inset->editXY(cur, x, y);
 
        if (cur.top().text() == text_)
-               text_->setCurrentFont(cur);
+               cur.setCurrentFont();
        return inset;
 }
 
index ee77b6d4b0eb24f805cb2ad01596638bd4697f1e..553377cf8069b59b1402f79b9d54bff1c56b357a 100644 (file)
@@ -32,7 +32,6 @@
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "MetricsInfo.h"
-#include "Text.h"
 
 #include "gettext.h"
 #include "support/ForkedcallsController.h"
@@ -277,8 +276,7 @@ void WorkArea::showCursor()
 
        CursorShape shape = BAR_SHAPE;
 
-       Text const & text = *buffer_view_->cursor().innerText();
-       Font const & realfont = text.real_current_font;
+       Font const & realfont = buffer_view_->cursor().real_current_font;
        BufferParams const & bp = buffer_view_->buffer().params();
        bool const samelang = realfont.language() == bp.language;
        bool const isrtl = realfont.isVisibleRightToLeft();
index a2f602e566004bb0e97e6d071a2557776fd7fc43..9a3e4eb320ac9537c62a2d62267b287376b0202c 100644 (file)
@@ -53,8 +53,9 @@ void InsetERT::init()
 {
        setButtonLabel();
        setLabelFont(layout_.labelfont);
-       text_.current_font.setLanguage(latex_language);
-       text_.real_current_font.setLanguage(latex_language);
+       // FIXME: what to do with those?
+       //text_.current_font.setLanguage(latex_language);
+       //text_.real_current_font.setLanguage(latex_language);
 }
 
 
@@ -254,8 +255,9 @@ void InsetERT::doDispatch(Cursor & cur, FuncRequest & cmd)
                // start of an existing paragraph get the buffer language
                // and not latex_language, so we take this brute force
                // approach.
-               text_.current_font.setLanguage(latex_language);
-               text_.real_current_font.setLanguage(latex_language);
+               // FIXME: what to do with those?
+               //text_.current_font.setLanguage(latex_language);
+               //text_.real_current_font.setLanguage(latex_language);
 
                InsetCollapsable::doDispatch(cur, cmd);
                break;
index 5a15bbb54c210fe56f494789e7b370f0493f27c1..082c1a6de8b656e944acd83f346538a766e3a2f8 100644 (file)
@@ -50,8 +50,9 @@ void InsetListings::init()
        font.decSize();
        font.setColor(Color::none);
        setLabelFont(font);
-       text_.current_font.setLanguage(latex_language);
-       text_.real_current_font.setLanguage(latex_language);
+       // FIXME: what to do with those?
+       //text_.current_font.setLanguage(latex_language);
+       //text_.real_current_font.setLanguage(latex_language);
 }
 
 
index eb62b8a1f60f4ada79eb97cadbd87053ef5d7bb5..bddc386e8691d27bffaa0fe2e5c5ae01e1f2ee77 100644 (file)
@@ -82,9 +82,6 @@ InsetText::InsetText(BufferParams const & bp)
 {
        paragraphs().push_back(Paragraph());
        paragraphs().back().layout(bp.getTextClass().defaultLayout());
-       // Dispose of the infamous L-shaped cursor.
-       text_.current_font.setLanguage(bp.language);
-       text_.real_current_font.setLanguage(bp.language);
        init();
 }
 
@@ -96,10 +93,6 @@ InsetText::InsetText(InsetText const & in)
        drawFrame_ = in.drawFrame_;
        frame_color_ = in.frame_color_;
        text_.paragraphs() = in.text_.paragraphs();
-       // Hand current buffer language down to "cloned" textinsets
-       // e.g. tabular cells
-       text_.current_font = in.text_.current_font;
-       text_.real_current_font = in.text_.real_current_font;
        init();
 }