From: Abdelrazak Younes Date: Sun, 2 Sep 2007 13:35:48 +0000 (+0000) Subject: Transfer current_font and real_current_font from Text to Cursor. X-Git-Tag: 1.6.10~8546 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=af06ed5ff1aa10021480da9c393a4ddb6b182933;p=features.git Transfer current_font and real_current_font from Text to Cursor. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19999 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 75fd9e024a..42a602b169 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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); } diff --git a/src/BufferView.cpp b/src/BufferView.cpp index 97e8d694cb..7fbd7187be 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -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 { diff --git a/src/Cursor.cpp b/src/Cursor.cpp index 2dd33f2af1..7b4bc6a4e3 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -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 diff --git a/src/Cursor.h b/src/Cursor.h index c56538a2df..27f2174d3c 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -14,6 +14,7 @@ #include "DispatchResult.h" #include "DocIterator.h" +#include "Font.h" #include #include @@ -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: // diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index fc606dca47..fc416bae2d 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -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; - } } diff --git a/src/Text.cpp b/src/Text.cpp index b86de4cdb7..35912086a8 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -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())); diff --git a/src/Text.h b/src/Text.h index b5db10f07e..b7764d7d80 100644 --- a/src/Text.h +++ b/src/Text.h @@ -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_; diff --git a/src/Text2.cpp b/src/Text2.cpp index b55827be5f..14afb1a49b 100644 --- a/src/Text2.cpp +++ b/src/Text2.cpp @@ -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(); } diff --git a/src/Text3.cpp b/src/Text3.cpp index 1a69796261..438f059939 100644 --- a/src/Text3.cpp +++ b/src/Text3.cpp @@ -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; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index cde93d0cfb..cb59462668 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -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; } diff --git a/src/frontends/WorkArea.cpp b/src/frontends/WorkArea.cpp index ee77b6d4b0..553377cf80 100644 --- a/src/frontends/WorkArea.cpp +++ b/src/frontends/WorkArea.cpp @@ -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(); diff --git a/src/insets/InsetERT.cpp b/src/insets/InsetERT.cpp index a2f602e566..9a3e4eb320 100644 --- a/src/insets/InsetERT.cpp +++ b/src/insets/InsetERT.cpp @@ -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; diff --git a/src/insets/InsetListings.cpp b/src/insets/InsetListings.cpp index 5a15bbb54c..082c1a6de8 100644 --- a/src/insets/InsetListings.cpp +++ b/src/insets/InsetListings.cpp @@ -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); } diff --git a/src/insets/InsetText.cpp b/src/insets/InsetText.cpp index eb62b8a1f6..bddc386e86 100644 --- a/src/insets/InsetText.cpp +++ b/src/insets/InsetText.cpp @@ -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(); }