diff --git a/ChangeLog b/ChangeLog index 9ee7fe29a1..d8f19193e6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2000-04-11 Lars Gullik Bjרnnes + + * src/LaTeXFeatures.h: add a const reference to BufferParams, to + avoid some uses of current_view. Added also a bufferParams() + mathod to get at this. + + * src/lyxtext.h: changed params->buffer and paramters->bparams. + +2000-04-10 Lars Gullik Bjרnnes + + * src/lyxparagraph.[Ch]: removed + operator<(LyXParagraph::InsetTabe..., added a struct matchIT + with operators used by lower_bound and + upper_bound in InsetTable's + Make struct InsetTable private again. Used matchpos. + +2000-04-08 Dekel Tsur + + * src/lyx_cb.C (DocumentApplyCB): When changing the language of the + document, the language of existing text is changed (unless the + document is multi-lingual) + + * src/buffer.C (ChangeLanguage,isMultiLingual) New methods. + + * src/paragraph.C (ChangeLanguage,isMultiLingual) New methods. + + * A lot of files: A rewrite of the Right-to-Left support. + 2000-04-10 Juergen Vigna * src/BufferView2.C (showLockedInsetCursor): small bugfix for diff --git a/src/BufferView2.C b/src/BufferView2.C index 267d88a0aa..bd3c8e4201 100644 --- a/src/BufferView2.C +++ b/src/BufferView2.C @@ -244,10 +244,10 @@ void BufferView::insertInset(Inset * inset, string const & lout, // and cannot do this as the cursor is behind the inset and GetInset // does not return the inset! if (inset->IsTextInset()) { - if (text->cursor.par->getParDirection()==LYX_DIR_LEFT_TO_RIGHT) - text->CursorLeft(); - else + if (text->cursor.par->isRightToLeftPar()) text->CursorRight(); + else + text->CursorLeft(); } #endif update(-1); diff --git a/src/BufferView_pimpl.C b/src/BufferView_pimpl.C index d82dc16d50..962a9090b8 100644 --- a/src/BufferView_pimpl.C +++ b/src/BufferView_pimpl.C @@ -1359,7 +1359,8 @@ void BufferView::Pimpl::setState() if (!lyxrc.rtl_support) return; - if (bv_->text->real_current_font.isVisibleRightToLeft()) { + if (bv_->text->real_current_font.isRightToLeft() && + bv_->text->real_current_font.latex() != LyXFont::ON) { if (owner_->getIntl()->primarykeymap) owner_->getIntl()->KeyMapSec(); } else { diff --git a/src/CutAndPaste.C b/src/CutAndPaste.C index 006f3fc1cf..e167fa9a44 100644 --- a/src/CutAndPaste.C +++ b/src/CutAndPaste.C @@ -18,6 +18,8 @@ #pragma implementation #endif +using std::pair; + static LyXParagraph * buf = 0; CutAndPaste::CutAndPaste() diff --git a/src/LaTeXFeatures.C b/src/LaTeXFeatures.C index fb141546b7..5cd875fce6 100644 --- a/src/LaTeXFeatures.C +++ b/src/LaTeXFeatures.C @@ -25,8 +25,8 @@ using std::endl; -LaTeXFeatures::LaTeXFeatures(int n) - : layout(n, false) +LaTeXFeatures::LaTeXFeatures(BufferParams const & p, int n) + : layout(n, false), params(p) { // packages color = false; @@ -70,10 +70,11 @@ LaTeXFeatures::LaTeXFeatures(int n) } -string LaTeXFeatures::getPackages(BufferParams const & params) +string LaTeXFeatures::getPackages() { string packages; - LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = + textclasslist.TextClass(params.textclass); // color.sty if (color) { @@ -127,8 +128,6 @@ string LaTeXFeatures::getPackages(BufferParams const & params) packages += "\\doublespacing\n"; break; case Spacing::Other: - //char value[30]; - //sprintf(value, "%.2f", params.spacing.getValue()); #ifdef HAVE_SSTREAM std::ostringstream value; #else @@ -185,7 +184,7 @@ string LaTeXFeatures::getPackages(BufferParams const & params) } -string LaTeXFeatures::getMacros(BufferParams const & /* params */) +string LaTeXFeatures::getMacros() { string macros; @@ -236,10 +235,11 @@ string LaTeXFeatures::getMacros(BufferParams const & /* params */) } -string LaTeXFeatures::getTClassPreamble(BufferParams const & params) +string LaTeXFeatures::getTClassPreamble() { // the text class specific preamble - LyXTextClass const & tclass = textclasslist.TextClass(params.textclass); + LyXTextClass const & tclass = + textclasslist.TextClass(params.textclass); string tcpreamble = tclass.preamble(); for (unsigned int i = 0; i < tclass.numLayouts(); ++i) { @@ -252,11 +252,16 @@ string LaTeXFeatures::getTClassPreamble(BufferParams const & params) } -void LaTeXFeatures::showStruct(BufferParams const & params) { +void LaTeXFeatures::showStruct() { lyxerr << "LyX needs the following commands when LaTeXing:" - // packs - << "\n***** Packages:" << getPackages(params) - << "\n***** Macros:" << getMacros(params) - << "\n***** Textclass stuff:" << getTClassPreamble(params) + << "\n***** Packages:" << getPackages() + << "\n***** Macros:" << getMacros() + << "\n***** Textclass stuff:" << getTClassPreamble() << "\n***** done." << endl; } + + +BufferParams const & LaTeXFeatures::bufferParams() const +{ + return params; +} diff --git a/src/LaTeXFeatures.h b/src/LaTeXFeatures.h index 64b7c2eac4..d3daa6e0e2 100644 --- a/src/LaTeXFeatures.h +++ b/src/LaTeXFeatures.h @@ -33,16 +33,16 @@ struct Language; in buffer.C and paragraph.C when you do so. */ struct LaTeXFeatures { /// - explicit LaTeXFeatures(int n) ; + LaTeXFeatures(BufferParams const &, int n) ; /// The packaes needed by the document - string getPackages(BufferParams const & params); + string getPackages(); /// The macros definitions needed by the document - string getMacros(BufferParams const & params); + string getMacros(); /// The definitions needed by the document's textclass - string getTClassPreamble(BufferParams const & params); + string getTClassPreamble(); /// - void showStruct(BufferParams const & params); + void showStruct(); //@Man: Packages //@{ @@ -137,6 +137,9 @@ struct LaTeXFeatures { /// LanguageList UsedLanguages; //@} + BufferParams const & bufferParams() const; +private: + BufferParams const & params; }; #endif diff --git a/src/TextCache.C b/src/TextCache.C index 0b5be6340e..db2141dbf5 100644 --- a/src/TextCache.C +++ b/src/TextCache.C @@ -35,7 +35,7 @@ public: text_fits(Buffer * b, unsigned short p) : buf(b), pw(p) {} bool operator()(TextCache::value_type & vt) { - if (vt->params == buf && vt->paperWidth() == pw) return true; + if (vt->buffer == buf && vt->paperWidth() == pw) return true; return false; } private: @@ -61,7 +61,7 @@ class show_text { public: show_text(ostream & o) : os(o) {} void operator()(TextCache::value_type & vt) { - os << "\tBuffer: " << vt->params + os << "\tBuffer: " << vt->buffer << "\tWidth: " << vt->paperWidth() << endl; } private: @@ -85,7 +85,7 @@ void TextCache::show(ostream & os, LyXText * lt) void TextCache::add(LyXText * text) { lyxerr.debug() << "TextCache::add " << text; - if (bufferlist.isLoaded(text->params)) { + if (bufferlist.isLoaded(text->buffer)) { cache.push_back(text); lyxerr.debug() << " added" << endl; } else { @@ -115,7 +115,7 @@ public: has_buffer(Buffer * b) : buf(b) {} bool operator()(TextCache::value_type & vt) { - if (vt->params == buf) return true; + if (vt->buffer == buf) return true; return false; } private: diff --git a/src/buffer.C b/src/buffer.C index 93ce39b729..b5e5d99dc2 100644 --- a/src/buffer.C +++ b/src/buffer.C @@ -1653,7 +1653,7 @@ void Buffer::makeLaTeXFile(string const & fname, // validate the buffer. lyxerr[Debug::LATEX] << " Validating buffer..." << endl; - LaTeXFeatures features(tclass.numLayouts()); + LaTeXFeatures features(params, tclass.numLayouts()); validate(features); lyxerr[Debug::LATEX] << " Buffer validation done." << endl; @@ -1973,13 +1973,13 @@ void Buffer::makeLaTeXFile(string const & fname, string preamble, tmppreamble; // The optional packages; - preamble = features.getPackages(params); + preamble = features.getPackages(); // this might be useful... preamble += "\n\\makeatletter\n\n"; // Some macros LyX will need - tmppreamble = features.getMacros(params); + tmppreamble = features.getMacros(); if (!tmppreamble.empty()) { preamble += "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " @@ -1988,7 +1988,7 @@ void Buffer::makeLaTeXFile(string const & fname, } // the text class specific preamble - tmppreamble = features.getTClassPreamble(params); + tmppreamble = features.getTClassPreamble(); if (!tmppreamble.empty()) { preamble += "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% " "Textclass specific LaTeX commands.\n" @@ -3721,7 +3721,7 @@ void Buffer::validate(LaTeXFeatures & features) const } if (lyxerr.debugging(Debug::LATEX)) { - features.showStruct(params); + features.showStruct(); } } @@ -3925,3 +3925,25 @@ void Buffer::Dispatch(int action, string const & argument) } // end of switch } + +void Buffer::ChangeLanguage(Language const * from, Language const * to) +{ + + LyXParagraph * par = paragraph; + while (par) { + par->ChangeLanguage(from,to); + par = par->next; + } +} + +bool Buffer::isMultiLingual() +{ + + LyXParagraph * par = paragraph; + while (par) { + if (par->isMultiLingual()) + return true; + par = par->next; + } + return false; +} diff --git a/src/buffer.h b/src/buffer.h index 3d0d8a2c3e..94507e04e4 100644 --- a/src/buffer.h +++ b/src/buffer.h @@ -291,6 +291,11 @@ public: than one user per buffer. */ BufferView * getUser() const { return users; } + /// + void ChangeLanguage(Language const * from, Language const * to); + /// + bool isMultiLingual(); + //@} /// Does this mean that this is buffer local? diff --git a/src/lyx_cb.C b/src/lyx_cb.C index 2a54f1128f..f0ce205194 100644 --- a/src/lyx_cb.C +++ b/src/lyx_cb.C @@ -1378,7 +1378,8 @@ int RunLinuxDoc(BufferView * bv, int flag, string const & filename) #ifdef WITH_WARNINGS #warning remove this once we have a proper geometry class #endif - BufferParams::PAPER_SIZE ps = static_cast(bv->buffer()->params.papersize); + BufferParams::PAPER_SIZE ps = + static_cast(bv->buffer()->params.papersize); switch (ps) { case BufferParams::PAPER_A4PAPER: add_flags = "-p a4"; @@ -2665,12 +2666,25 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) bool redo = false; BufferParams * params = &(current_view->buffer()->params); + Language const * old_language = params->language_info; + Language const * new_language; params->language = combo_language->getline(); Languages::iterator lit = languages.find(params->language); if (lit != languages.end()) - params->language_info = &(*lit).second; + new_language = &(*lit).second; else - params->language_info = default_language; + new_language = default_language; + + if (current_view->available()) { + if (old_language != new_language && + old_language->RightToLeft == new_language->RightToLeft && + ! current_view->buffer()->isMultiLingual() ) { + current_view->buffer()->ChangeLanguage(old_language, + new_language); + current_view->buffer()->redraw(); + } + } + params->language_info = new_language; // If default skip is a "Length" but there's no text in the // input field, reset the kind to "Medskip", which is the default. @@ -2699,9 +2713,10 @@ extern "C" void DocumentApplyCB(FL_OBJECT *, long) if (!current_view->available()) return; - current_view->text->SetCursor(current_view->text->cursor.par, - current_view->text->cursor.pos); - current_view->setState(); + + current_view->text->SetCursor(current_view->text->cursor.par, + current_view->text->cursor.pos); + current_view->setState(); LyXTextClassList::ClassList::size_type new_class = fl_get_choice(fd_form_document->choice_class) - 1; diff --git a/src/lyxfunc.C b/src/lyxfunc.C index 9706810415..31d3f28c03 100644 --- a/src/lyxfunc.C +++ b/src/lyxfunc.C @@ -572,8 +572,6 @@ string LyXFunc::Dispatch(int ac, return string(); else { setMessage(N_("Text mode")); - LyXDirection direction = owner->view()->text-> - cursor.par->getParDirection(); switch(action) { case LFUN_UNKNOWN_ACTION: case LFUN_BREAKPARAGRAPH: @@ -583,7 +581,7 @@ string LyXFunc::Dispatch(int ac, owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_RIGHT: - if (direction == LYX_DIR_LEFT_TO_RIGHT) { + if (!owner->view()->text->cursor.par->isRightToLeftPar()) { owner->view()->text->CursorRight(); moveCursorUpdate(false); owner->getMiniBuffer()-> @@ -591,7 +589,7 @@ string LyXFunc::Dispatch(int ac, } return string(); case LFUN_LEFT: - if (direction == LYX_DIR_RIGHT_TO_LEFT) { + if (owner->view()->text->cursor.par->isRightToLeftPar()) { owner->view()->text->CursorRight(); moveCursorUpdate(false); owner->getMiniBuffer()-> @@ -1111,7 +1109,7 @@ string LyXFunc::Dispatch(int ac, // Pretend we got the name instead. Dispatch(int(LFUN_LAYOUT), textclasslist.NameOfLayout(owner->view()-> - text->parameters-> + text->bparams-> textclass, sel).c_str()); return string(); @@ -1125,7 +1123,7 @@ string LyXFunc::Dispatch(int ac, // Derive layout number from given argument (string) // and current buffer's textclass (number). */ LyXTextClassList::ClassList::size_type tclass = - owner->view()->text->parameters->textclass; + owner->view()->text->bparams->textclass; pair layout = textclasslist.NumberOfLayout(tclass, argument); @@ -1211,38 +1209,47 @@ string LyXFunc::Dispatch(int ac, case LFUN_EMPH: Emph(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_BOLD: Bold(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_NOUN: Noun(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_CODE: Code(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_SANS: Sans(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_ROMAN: Roman(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_DEFAULT: StyleReset(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_UNDERLINE: Underline(); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_FONT_SIZE: FontSize(argument); + owner->getMiniBuffer()->Set(CurrentState()); break; case LFUN_FONT_STATE: @@ -1333,12 +1340,11 @@ string LyXFunc::Dispatch(int ac, case LFUN_RIGHT: { LyXText * tmptext = owner->view()->text; - LyXDirection direction = - tmptext->cursor.par->getParDirection(); + bool is_rtl = tmptext->cursor.par->isRightToLeftPar(); if(!tmptext->mark_set) owner->view()->beforeChange(); owner->view()->update(-2); - if (direction == LYX_DIR_RIGHT_TO_LEFT) + if (is_rtl) tmptext->CursorLeft(); if (tmptext->cursor.pos < tmptext->cursor.par->Last() && tmptext->cursor.par->GetChar(tmptext->cursor.pos) @@ -1350,7 +1356,7 @@ string LyXFunc::Dispatch(int ac, tmpinset->Edit(owner->view(), 0, 0, 0); break; } - if (direction == LYX_DIR_LEFT_TO_RIGHT) + if (!is_rtl) tmptext->CursorRight(); owner->view()->text->FinishUndo(); moveCursorUpdate(false); @@ -1363,10 +1369,10 @@ string LyXFunc::Dispatch(int ac, // This is soooo ugly. Isn`t it possible to make // it simpler? (Lgb) LyXText * txt = owner->view()->text; - LyXDirection direction = txt->cursor.par->getParDirection(); + bool is_rtl = txt->cursor.par->isRightToLeftPar(); if(!txt->mark_set) owner->view()->beforeChange(); owner->view()->update(-2); - if (direction == LYX_DIR_LEFT_TO_RIGHT) + if (!is_rtl) txt->CursorLeft(); if (txt->cursor.pos < txt->cursor.par->Last() && txt->cursor.par->GetChar(txt->cursor.pos) @@ -1382,7 +1388,7 @@ string LyXFunc::Dispatch(int ac, 0, 0); break; } - if (direction == LYX_DIR_RIGHT_TO_LEFT) + if (is_rtl) txt->CursorRight(); owner->view()->text->FinishUndo(); @@ -1484,11 +1490,10 @@ string LyXFunc::Dispatch(int ac, if(!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorRightOneWord(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorLeftOneWord(); + else + owner->view()->text->CursorRightOneWord(); owner->view()->text->FinishUndo(); moveCursorUpdate(false); owner->getMiniBuffer()->Set(CurrentState()); @@ -1498,11 +1503,10 @@ string LyXFunc::Dispatch(int ac, if(!owner->view()->text->mark_set) owner->view()->beforeChange(); owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorLeftOneWord(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorRightOneWord(); + else + owner->view()->text->CursorLeftOneWord(); owner->view()->text->FinishUndo(); moveCursorUpdate(false); owner->getMiniBuffer()->Set(CurrentState()); @@ -1532,11 +1536,10 @@ string LyXFunc::Dispatch(int ac, /* cursor selection ---------------------------- */ case LFUN_RIGHTSEL: owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorRight(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorLeft(); + else + owner->view()->text->CursorRight(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); owner->getMiniBuffer()->Set(CurrentState()); @@ -1544,11 +1547,10 @@ string LyXFunc::Dispatch(int ac, case LFUN_LEFTSEL: owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorLeft(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorRight(); + else + owner->view()->text->CursorLeft(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); owner->getMiniBuffer()->Set(CurrentState()); @@ -1620,11 +1622,10 @@ string LyXFunc::Dispatch(int ac, case LFUN_WORDRIGHTSEL: owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorRightOneWord(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorLeftOneWord(); + else + owner->view()->text->CursorRightOneWord(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); owner->getMiniBuffer()->Set(CurrentState()); @@ -1632,11 +1633,10 @@ string LyXFunc::Dispatch(int ac, case LFUN_WORDLEFTSEL: owner->view()->update(-2); - if (owner->view()->text->cursor.par->getParDirection() - == LYX_DIR_LEFT_TO_RIGHT) - owner->view()->text->CursorLeftOneWord(); - else + if (owner->view()->text->cursor.par->isRightToLeftPar()) owner->view()->text->CursorRightOneWord(); + else + owner->view()->text->CursorLeftOneWord(); owner->view()->text->FinishUndo(); moveCursorUpdate(true); owner->getMiniBuffer()->Set(CurrentState()); diff --git a/src/lyxparagraph.h b/src/lyxparagraph.h index 52c08a0f14..1d59375921 100644 --- a/src/lyxparagraph.h +++ b/src/lyxparagraph.h @@ -24,7 +24,6 @@ #include "vspace.h" #include "layout.h" #include "support/block.h" -#include "direction.h" #include "language.h" class BufferParams; @@ -128,12 +127,11 @@ public: /// Language const * getParLanguage() const; /// - Language const * getLetterLanguage(size_type pos) const; - + bool isRightToLeftPar() const; /// - LyXDirection getParDirection() const; + void ChangeLanguage(Language const * from, Language const * to); /// - LyXDirection getLetterDirection(size_type pos) const; + bool isMultiLingual(); /// void writeFile(std::ostream &, BufferParams const &, char, char) const; @@ -183,10 +181,10 @@ public: /** Check if the current paragraph is the last paragraph in a proof environment */ int GetEndLabel() const; - + /// Inset * InInset() { return inset_owner; } - void SetInsetOwner(Inset *i) { inset_owner = i; } - + /// + void SetInsetOwner(Inset * i) { inset_owner = i; } private: /// TextContainer text; @@ -510,6 +508,7 @@ public: /// void SimpleDocBookOneTablePar(std::ostream &, string & extra, int & desc_on, int depth); +private: /// struct InsetTable { /// @@ -519,7 +518,21 @@ public: /// InsetTable(size_type p, Inset * i) { pos = p; inset = i;} }; -private: + /// + struct matchIT { + /// used by lower_bound + inline + int operator()(LyXParagraph::InsetTable const & a, + LyXParagraph::size_type pos) const { + return a.pos < pos; + } + /// used by upper_bound + inline + int operator()(LyXParagraph::size_type pos, + LyXParagraph::InsetTable const & a) const { + return pos < a.pos; + } + }; /** A font entry covers a range of positions. Notice that the entries in the list are inserted in random order. I don't think it's worth the effort to implement a more effective @@ -558,7 +571,7 @@ private: LyXParagraph * TeXFootnote(std::ostream &, TexRow & texrow, std::ostream & foot, TexRow & foot_texrow, int & foot_count, - LyXDirection par_direction); + bool parent_is_rtl); /// bool SimpleTeXOneTablePar(std::ostream &, TexRow & texrow); /// @@ -583,10 +596,4 @@ private: static unsigned int paragraph_id; }; -inline bool operator<(LyXParagraph::InsetTable const & a, - LyXParagraph::InsetTable const & b) -{ - return a.pos < b.pos; -} - #endif diff --git a/src/lyxrc.C b/src/lyxrc.C index ccb0d42fb7..0a2ac6e5c5 100644 --- a/src/lyxrc.C +++ b/src/lyxrc.C @@ -135,7 +135,7 @@ enum LyXRCTags { RC_MAKE_BACKUP, RC_BACKUPDIR_PATH, RC_RTL_SUPPORT, - RC_NUMBER_INSET, + RC_AUTO_NUMBER, RC_LANGUAGE_PACKAGE, RC_LANGUAGE_AUTO_BEGIN, RC_LANGUAGE_AUTO_END, @@ -165,6 +165,7 @@ keyword_item lyxrcTags[] = { { "\\alternate_language", RC_ALT_LANG }, { "\\ascii_linelen", RC_ASCII_LINELEN }, { "\\ascii_roff_command", RC_ASCIIROFF_COMMAND }, + { "\\auto_number", RC_AUTO_NUMBER }, { "\\auto_region_delete", RC_AUTOREGIONDELETE }, { "\\autosave", RC_AUTOSAVE }, { "\\background_color", RC_BACKGROUND_COLOR }, @@ -212,7 +213,6 @@ keyword_item lyxrcTags[] = { { "\\literate_extension", RC_LITERATE_EXTENSION }, { "\\make_backup", RC_MAKE_BACKUP }, { "\\num_lastfiles", RC_NUMLASTFILES }, - { "\\number_inset", RC_NUMBER_INSET }, { "\\pdf_mode", RC_PDF_MODE }, { "\\pdf_to_ps_command", RC_PDF_TO_PS_COMMAND }, { "\\pdflatex_command", RC_PDFLATEX_COMMAND }, @@ -363,7 +363,7 @@ void LyXRC::setDefaults() { use_kbmap = false; hasBindFile = false; rtl_support = false; - number_inset = "rtl"; + auto_number = true; language_package = "\\usepackage{babel}"; language_auto_begin = true; language_auto_end = true; @@ -1002,9 +1002,9 @@ int LyXRC::read(string const & filename) if (lexrc.next()) rtl_support = lexrc.GetBool(); break; - case RC_NUMBER_INSET: + case RC_AUTO_NUMBER: if (lexrc.next()) - number_inset = lowercase(lexrc.GetString()); + auto_number = lexrc.GetBool(); break; case RC_SHOW_BANNER: if (lexrc.next()) @@ -1327,8 +1327,8 @@ void LyXRC::output(ostream & os) const os << "\\escape_chars \"" << isp_esc_chars << "\"\n"; case RC_RTL_SUPPORT: os << "\\rtl " << tostr(rtl_support) << "\n"; - case RC_NUMBER_INSET: - os << "\\number_inset " << number_inset << "\n"; + case RC_AUTO_NUMBER: + os << "\\auto_number" << tostr(auto_number) << "\n"; case RC_LANGUAGE_AUTO_BEGIN: os << "\\language_auto_begin " << tostr(language_auto_begin) << "\n"; diff --git a/src/lyxrc.h b/src/lyxrc.h index bc724a465a..ede04f7055 100644 --- a/src/lyxrc.h +++ b/src/lyxrc.h @@ -219,7 +219,7 @@ public: /// bool rtl_support; /// - string number_inset; + bool auto_number; /// bool show_banner; /// Do we have to use a GUI? diff --git a/src/lyxtext.h b/src/lyxtext.h index 6683824104..01967e686e 100644 --- a/src/lyxtext.h +++ b/src/lyxtext.h @@ -51,10 +51,16 @@ public: FORM_FINAL }; + /// Constructor + LyXText(BufferView *, int paperwidth, Buffer *); + + /// Destructor + ~LyXText(); + /// points to Buffer.params - BufferParams * parameters; + BufferParams * bparams; /// points to Buffer - Buffer * params; + Buffer * buffer; /// mutable int number_of_rows; /// @@ -64,12 +70,6 @@ public: /// the current font mutable LyXFont real_current_font; - /// Constructor - LyXText(BufferView *, int paperwidth, Buffer *); - - /// Destructor - ~LyXText(); - /// void owner(BufferView *); @@ -601,6 +601,9 @@ private: /// mutable std::vector vis2log_list; + /// + mutable std::vector bidi_levels; + /// mutable LyXParagraph::size_type bidi_start; @@ -610,12 +613,6 @@ private: /// void ComputeBidiTables(Row *row) const; - /// - void ComputeBidiTablesFromTo(Row *row, - LyXParagraph::size_type from, - LyXParagraph::size_type to, - LyXParagraph::size_type offset) const; - /// Maps positions in the visual string to positions in logical string. inline LyXParagraph::size_type log2vis(LyXParagraph::size_type pos) const { @@ -634,6 +631,14 @@ private: return vis2log_list[pos-bidi_start]; } + inline + int bidi_level(LyXParagraph::size_type pos) const { + if (bidi_start == -1) + return 0; + else + return bidi_levels[pos-bidi_start]; + } + /// unsigned char TransformChar(unsigned char c, Letter_Form form) const; @@ -645,6 +650,9 @@ private: specified row */ LyXParagraph::size_type RowLast(Row const * row) const; + /// + LyXParagraph::size_type RowLastPrintable(Row const * row) const; + /// void charInserted(); }; diff --git a/src/paragraph.C b/src/paragraph.C index 28faee543a..c79c185caa 100644 --- a/src/paragraph.C +++ b/src/paragraph.C @@ -327,9 +327,11 @@ void LyXParagraph::writeFile(ostream & os, BufferParams const & params, void LyXParagraph::validate(LaTeXFeatures & features) const { + BufferParams const & params = features.bufferParams(); + // this will be useful later LyXLayout const & layout = - textclasslist.Style(current_view->buffer()->params.textclass, + textclasslist.Style(params.textclass, GetLayout()); // check the params. @@ -340,7 +342,8 @@ void LyXParagraph::validate(LaTeXFeatures & features) const features.layout[GetLayout()] = true; // then the fonts - Language const * doc_language = current_view->buffer()->params.language_info; + Language const * doc_language = params.language_info; + for (FontList::const_iterator cit = fontlist.begin(); cit != fontlist.end(); ++cit) { if ((*cit).font.noun() == LyXFont::ON) { @@ -387,8 +390,8 @@ void LyXParagraph::validate(LaTeXFeatures & features) const if (layout.needprotect && next && next->footnoteflag != LyXParagraph::NO_FOOTNOTE) features.NeedLyXFootnoteCode = true; - if ((current_view->buffer()->params.paragraph_separation == BufferParams::PARSEP_INDENT) && - (pextra_type == LyXParagraph::PEXTRA_MINIPAGE)) + if (params.paragraph_separation == BufferParams::PARSEP_INDENT + && pextra_type == LyXParagraph::PEXTRA_MINIPAGE) features.NeedLyXMinipageIndent = true; if (table && table->NeedRotating()) features.rotating = true; @@ -429,7 +432,7 @@ void LyXParagraph::CutIntoMinibuffer(LyXParagraph::size_type pos) // find the entry InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); if (it != insetlist.end() && (*it).pos == pos) (*it).inset = 0; } else { @@ -510,6 +513,9 @@ LyXParagraph::~LyXParagraph() // ale970302 delete bibkey; + // + lyxerr << "LyXParagraph::paragraph_id = " + << LyXParagraph::paragraph_id << endl; } @@ -531,7 +537,7 @@ void LyXParagraph::Erase(LyXParagraph::size_type pos) // find the entry InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); if (it != insetlist.end() && (*it).pos == pos) { delete (*it).inset; insetlist.erase(it); @@ -564,7 +570,7 @@ void LyXParagraph::Erase(LyXParagraph::size_type pos) // Update the inset table. for (InsetList::iterator it = upper_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); it != insetlist.end(); ++it) --(*it).pos; } else { @@ -601,7 +607,7 @@ void LyXParagraph::InsertChar(LyXParagraph::size_type pos, char c) // Update the inset table. for (InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); it != insetlist.end(); ++it) ++(*it).pos; } @@ -632,12 +638,12 @@ void LyXParagraph::InsertInset(LyXParagraph::size_type pos, // Add a new entry in the inset table. InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); if (it != insetlist.end() && (*it).pos == pos) lyxerr << "ERROR (LyXParagraph::InsertInset): " "there is an inset in position: " << pos << endl; else - insetlist.insert(it,InsetTable(pos,inset)); + insetlist.insert(it, InsetTable(pos,inset)); } } @@ -668,7 +674,7 @@ Inset * LyXParagraph::GetInset(LyXParagraph::size_type pos) // Find the inset. InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); if (it != insetlist.end() && (*it).pos == pos) return (*it).inset; @@ -700,7 +706,7 @@ Inset const * LyXParagraph::GetInset(LyXParagraph::size_type pos) const // Find the inset. InsetList::const_iterator cit = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos,0)); + pos, matchIT()); if (cit != insetlist.end() && (*cit).pos == pos) return (*cit).inset; @@ -1391,9 +1397,6 @@ void LyXParagraph::BreakParagraph(LyXParagraph::size_type pos, ++pos_first; pos_end = pos_first + par->text.size() - 1; - // The constructor has already reserved 500 elements - //if (pos_end > pos) - // tmp->text.reserve(pos_end - pos); for (i = j = pos; i <= pos_end; ++i) { par->CutIntoMinibuffer(i - pos_first); @@ -1559,15 +1562,6 @@ void LyXParagraph::BreakParagraphConservative(LyXParagraph::size_type pos) while (ParFromPos(pos_first) != par) ++pos_first; size_type pos_end = pos_first + par->text.size() - 1; - // make sure there is enough memory for the now larger - // paragraph. This is not neccessary, because - // InsertFromMinibuffer will enlarge the memory (it uses - // InsertChar of course). But doing it by hand - // is MUCH faster! (only one time, not thousend times!!) - // Not needed since the constructor aleady have - // reserved 500 elements in text. - //if (pos_end > pos) - // tmp->text.reserve(pos_end - pos); size_type i, j; for (i = j = pos; i <= pos_end; ++i) { @@ -1668,6 +1662,7 @@ int LyXParagraph::GetEndLabel() const return END_LABEL_NO_LABEL; } + LyXTextClass::size_type LyXParagraph::GetLayout() const { return FirstPhysicalPar()->layout; @@ -1900,15 +1895,15 @@ LyXParagraph const * LyXParagraph::DepthHook(int deth) const int LyXParagraph::AutoDeleteInsets() { int count = 0; - unsigned int i = 0; - while (i < insetlist.size()) { - if (insetlist[i].inset && insetlist[i].inset->AutoDelete()) { - Erase(insetlist[i].pos); - // Erase() calls to insetlist.erase(&insetlist[i]) - // so i shouldn't be increased. + InsetList::size_type index = 0; + while (index < insetlist.size()) { + if (insetlist[index].inset && insetlist[index].inset->AutoDelete()) { + Erase(insetlist[index].pos); + // Erase() calls to insetlist.erase(&insetlist[index]) + // so index shouldn't be increased. ++count; } else - ++i; + ++index; } return count; } @@ -1918,7 +1913,7 @@ Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos) { InsetList::iterator it = lower_bound(insetlist.begin(), insetlist.end(), - InsetTable(pos, 0)); + pos, matchIT()); if (it != insetlist.end()) { pos = (*it).pos; return (*it).inset; @@ -1931,6 +1926,15 @@ Inset * LyXParagraph::ReturnNextInsetPointer(LyXParagraph::size_type & pos) int LyXParagraph::GetPositionOfInset(Inset * inset) const { // Find the entry. + // We could use lower_bound here too, we just need to add + // the approp. operator() to matchIT (and change the name + // of that struct). Code would then be: + // InsetList::const_iterator cit = lower_bound(insetlist.begin(), + // insetlist.end(), + // inset, matchIT()); + // if ((*cit).inset == inset) { + // return (*cit).pos; + // } for (InsetList::const_iterator cit = insetlist.begin(); cit != insetlist.end(); ++cit) { if ((*cit).inset == inset) { @@ -2036,12 +2040,9 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow, while (par && par->footnoteflag != LyXParagraph::NO_FOOTNOTE && par->footnoteflag != footnoteflag) { - LyXDirection dir = (is_rtl) - ? LYX_DIR_RIGHT_TO_LEFT - : LYX_DIR_LEFT_TO_RIGHT; par = par->TeXFootnote(os, texrow, foot, foot_texrow, foot_count, - dir); + is_rtl); par->SimpleTeXOnePar(os, texrow); is_rtl = par->GetFontSettings(par->size()-1).isRightToLeft(); if (par->next && @@ -2057,7 +2058,7 @@ LyXParagraph * LyXParagraph::TeXOnePar(ostream & os, TexRow & texrow, && par->footnoteflag != footnoteflag) { par = par->TeXFootnote(os, texrow, foot, foot_texrow, foot_count, - LYX_DIR_LEFT_TO_RIGHT); + false); par->SimpleTeXOnePar(os, texrow); par = par->next; } @@ -2423,6 +2424,9 @@ bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow) texrow.start(this, 0); + bool is_rtl = getParLanguage()->RightToLeft; + bool first_in_cell = true; + for (size_type i = 0; i < size(); ++i) { char c = GetChar(i); if (table->IsContRow(current_cell_number + 1)) { @@ -2431,7 +2435,13 @@ bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow) continue; } ++column; - + + if (first_in_cell && is_rtl) { + os << "\\R{"; + column += 3; + first_in_cell = false; + } + // Fully instantiated font LyXFont font = getFont(i); last_font = running_font; @@ -2491,6 +2501,11 @@ bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow) current_cell_number, column, texrow); } + if (is_rtl && !first_in_cell) { + os << "}"; + first_in_cell = true; + } + // if this cell follow only ContRows till end don't // put the EndOfCell because it is put after the // for(...) @@ -2521,6 +2536,8 @@ bool LyXParagraph::SimpleTeXOneTablePar(ostream & os, TexRow & texrow) running_font.latexWriteEndChanges(os, basefont, basefont); } ++current_cell_number; + if (is_rtl && !first_in_cell) + os << "}"; tmp = table->TexEndOfCell(os, current_cell_number); for (; tmp > 0; --tmp) texrow.newline(); @@ -3773,7 +3790,7 @@ LyXParagraph * LyXParagraph::TeXEnvironment(ostream & os, TexRow & texrow, LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow, ostream & foot, TexRow & foot_texrow, int & foot_count, - LyXDirection parent_direction) + bool parent_is_rtl) { lyxerr[Debug::LATEX] << "TeXFootnote... " << this << endl; if (footnoteflag == LyXParagraph::NO_FOOTNOTE) @@ -3812,12 +3829,12 @@ LyXParagraph * LyXParagraph::TeXFootnote(ostream & os, TexRow & texrow, } bool need_closing = false; - LyXDirection direction = getParDirection(); - if (direction != parent_direction) { - if (direction == LYX_DIR_LEFT_TO_RIGHT) - os << "\\L{"; - else + bool is_rtl = isRightToLeftPar(); + if (is_rtl != parent_is_rtl) { + if (is_rtl) os << "\\R{"; + else + os << "\\L{"; need_closing = true; } @@ -4194,47 +4211,52 @@ bool LyXParagraph::IsWord(size_type pos ) const return IsWordChar(GetChar(pos)) ; } + Language const * LyXParagraph::getParLanguage() const { - if (!table && size() > 0) - return FirstPhysicalPar()->GetFirstFontSettings().language(); + if (size() > 0) + if (!table) + return FirstPhysicalPar()->GetFirstFontSettings() + .language(); + else { + for (size_type pos = 0; pos < size(); ++pos) + if (IsNewline(pos)) + return GetFontSettings(pos).language(); + return GetFirstFontSettings().language(); + } else if (previous) return previous->getParLanguage(); else return current_view->buffer()->params.language_info; } -Language const * LyXParagraph::getLetterLanguage(size_type pos) const + +bool LyXParagraph::isRightToLeftPar() const { - return GetFontSettings(pos).language(); + return lyxrc.rtl_support && !table && getParLanguage()->RightToLeft; } -LyXDirection LyXParagraph::getParDirection() const + +void LyXParagraph::ChangeLanguage(Language const * from, Language const * to) { - if (!lyxrc.rtl_support || table) - return LYX_DIR_LEFT_TO_RIGHT; - else if (getParLanguage()->RightToLeft) - return LYX_DIR_RIGHT_TO_LEFT; - else - return LYX_DIR_LEFT_TO_RIGHT; + for(size_type i = 0; i < size(); ++i) { + LyXFont font = GetFontSettings(i); + if (font.language() == from) { + font.setLanguage(to); + SetFont(i,font); + } + } } -LyXDirection -LyXParagraph::getLetterDirection(LyXParagraph::size_type pos) const -{ - if (!lyxrc.rtl_support) - return LYX_DIR_LEFT_TO_RIGHT; - else if (table && IsNewline(pos)) - return LYX_DIR_LEFT_TO_RIGHT; - bool is_rtl = GetFontSettings(pos).isVisibleRightToLeft(); - if (IsLineSeparator(pos) && 0 < pos && pos < Last() - 1 - && !IsLineSeparator(pos + 1) - && !(table && IsNewline(pos + 1)) - && ( GetFontSettings(pos - 1).isVisibleRightToLeft() != is_rtl - || GetFontSettings(pos + 1).isVisibleRightToLeft() != is_rtl)) - return getParDirection(); - else - return (is_rtl) ? LYX_DIR_RIGHT_TO_LEFT - : LYX_DIR_LEFT_TO_RIGHT; +bool LyXParagraph::isMultiLingual() +{ + Language const * doc_language = + current_view->buffer()->params.language_info; + for(size_type i = 0; i < size(); ++i) { + LyXFont font = GetFontSettings(i); + if (font.language() != doc_language) + return true; + } + return false; } diff --git a/src/screen.C b/src/screen.C index e6aef59c5d..43ea434d39 100644 --- a/src/screen.C +++ b/src/screen.C @@ -190,9 +190,9 @@ void LyXScreen::ShowCursor() if (!cursor_visible) { Cursor_Shape shape = BAR_SHAPE; if (text->real_current_font.language() != - text->parameters->language_info + text->bparams->language_info || text->real_current_font.isVisibleRightToLeft() - != text->parameters->language_info->RightToLeft) + != text->bparams->language_info->RightToLeft) shape = (text->real_current_font.isVisibleRightToLeft()) ? REVERSED_L_SHAPE : L_SHAPE; ShowManualCursor(text->cursor.x, text->cursor.y, diff --git a/src/text.C b/src/text.C index 73e47c30ff..2bfd912b83 100644 --- a/src/text.C +++ b/src/text.C @@ -102,11 +102,13 @@ static int iso885968x[] = { 0xfe // 0xea = ya }; + bool is_arabic(unsigned char c) { return 0xa8 <= c && c <= 0xea && iso885968x[c-0xa8]; } + unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const { if (is_arabic(c) && @@ -116,11 +118,15 @@ unsigned char LyXText::TransformChar(unsigned char c, Letter_Form form) const return c; } + unsigned char LyXText::TransformChar(unsigned char c, LyXParagraph * par, LyXParagraph::size_type pos) const { if (!is_arabic(c)) - return c; + if (isdigit(c)) + return c + (0xb0 - '0'); + else + return c; bool not_first = (pos > 0 && is_arabic(par->GetChar(pos-1))); if (pos < par->Last()-1 && is_arabic(par->GetChar(pos+1))) @@ -175,7 +181,8 @@ int LyXText::SingleWidth(LyXParagraph * par, // The most common case is handled first (Asger) if (IsPrintable(c)) { - if (lyxrc.rtl_support && lyxrc.font_norm == "iso8859-6.8x") + if (font.language()->lang == "arabic" && + lyxrc.font_norm == "iso8859-6.8x") c = TransformChar(c, par, pos); return lyxfont::width(c, font); @@ -244,7 +251,15 @@ LyXParagraph::size_type LyXText::RowLast(Row const * row) const } - +LyXParagraph::size_type LyXText::RowLastPrintable(Row const * row) const +{ + LyXParagraph::size_type last = RowLast(row); + if (last >= row->pos && row->next && row->next->par == row->par && + row->par->IsSeparator(last)) + return last - 1; + else + return last; +} void LyXText::ComputeBidiTables(Row * row) const @@ -254,7 +269,7 @@ void LyXText::ComputeBidiTables(Row * row) const bidi_start = -1; return; } - LyXParagraph::size_type last = RowLast(row); + LyXParagraph::size_type last = RowLastPrintable(row); bidi_start = row->pos; if (bidi_start > last) { @@ -269,90 +284,86 @@ void LyXText::ComputeBidiTables(Row * row) const 500 : 2 * (last + 2 - bidi_start); log2vis_list.resize(new_size); vis2log_list.resize(new_size); + bidi_levels.resize(new_size); } vis2log_list[last + 1 - bidi_start] = -1; log2vis_list[last + 1 - bidi_start] = -1; - LyXParagraph::size_type main_body = BeginningOfMainBody(row->par); - if (main_body > 0 && row->pos < main_body - 1 && main_body - 1 <= last - && row->par->IsLineSeparator(main_body - 1)) { - // This is needed in case there is a direction change in - // the label which is continued into the main body - if (row->par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) { - ComputeBidiTablesFromTo(row, bidi_start, - main_body - 2, 0); - log2vis_list[main_body - 1 - bidi_start] = - main_body - 1; - vis2log_list[main_body - 1 - bidi_start] = - main_body - 1; - if (main_body <= last) - ComputeBidiTablesFromTo(row, - main_body,last, 0); - } else { - ComputeBidiTablesFromTo(row, bidi_start, - main_body - 2, - last - main_body + 2); - log2vis_list[main_body - 1 - bidi_start] = - last - main_body + 1 + bidi_start; - vis2log_list[last - main_body + 1 - bidi_start] = - main_body - 1; - if (main_body <= last) - ComputeBidiTablesFromTo(row, main_body, - last, -main_body); - } - } else - ComputeBidiTablesFromTo(row, bidi_start, last, 0); -} - - -void LyXText::ComputeBidiTablesFromTo(Row * row, - LyXParagraph::size_type from, - LyXParagraph::size_type to, - LyXParagraph::size_type offset) const -{ - LyXParagraph::size_type vpos, old_lpos, stack[2]; - LyXDirection par_direction = row->par->getParDirection(); - LyXDirection direction = par_direction; - LyXParagraph::size_type lpos = from; + LyXParagraph::size_type stack[2]; + bool rtl_par = row->par->getParLanguage()->RightToLeft; int level = 0; + bool rtl = false; + bool rtl0 = false; + LyXParagraph::size_type main_body = BeginningOfMainBody(row->par); - while (lpos <= to) { - if (row->par->getLetterDirection(lpos) == direction) { - log2vis_list[lpos - bidi_start] = direction; - ++lpos; - } else { - if (level == 0 || - (level == 1 && direction == LYX_DIR_RIGHT_TO_LEFT - && row->par->getFont(lpos).isRightToLeft() - && row->par->getFont(lpos).latex() == LyXFont::ON - ) ) { - // The last check is needed when the - // char is a space - stack[level++] = lpos; - } else { - old_lpos = stack[--level]; - log2vis_list[old_lpos - bidi_start] = - log2vis_list[lpos - bidi_start] = - (old_lpos - lpos) * direction; - ++lpos; - } - direction = static_cast(-direction); - bidi_same_direction = false; + for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) { + bool is_space = row->par->IsLineSeparator(lpos); + LyXParagraph::size_type pos = + (is_space && lpos+1 <= last && + (!row->par->table || !row->par->IsNewline(lpos+1)) ) + ? lpos + 1 : lpos; + LyXFont font = row->par->GetFontSettings(pos); + bool new_rtl = font.isVisibleRightToLeft(); + bool new_rtl0 = font.isRightToLeft(); + int new_level; + + if (row->par->table && row->par->IsNewline(lpos)) { + new_level = 0; + new_rtl = new_rtl0 = false; + } else if (lpos == main_body - 1 && row->pos < main_body - 1 && + row->par->IsLineSeparator(lpos)) { + new_level = (rtl_par) ? 1 : 0; + new_rtl = new_rtl0 = rtl_par; + } else if (new_rtl0) + new_level = (new_rtl) ? 1 : 2; + else + new_level = (rtl_par) ? 2 : 0; + + if (is_space && new_level >= level) { + new_level = level; + new_rtl = rtl; + new_rtl0 = rtl0; } + + int new_level2 = new_level; + + if (level == new_level && rtl0 != new_rtl0) { + --new_level2; + log2vis_list[lpos - bidi_start] = (rtl) ? 1 : -1; + } else if (level < new_level) { + log2vis_list[lpos - bidi_start] = (rtl) ? -1 : 1; + if (new_level > rtl_par) + bidi_same_direction = false; + } else + log2vis_list[lpos - bidi_start] = (new_rtl) ? -1 : 1; + rtl = new_rtl; + rtl0 = new_rtl0; + bidi_levels[lpos - bidi_start] = new_level; + + while (level > new_level2) { + LyXParagraph::size_type old_lpos = + stack[--level]; + int delta = lpos - old_lpos - 1; + if (level % 2) + delta = -delta; + log2vis_list[lpos - bidi_start] += delta; + log2vis_list[old_lpos - bidi_start] += delta; + } + while (level < new_level) + stack[level++] = lpos; } while (level > 0) { - old_lpos = stack[--level]; - log2vis_list[old_lpos - bidi_start] = - (old_lpos - (to + 1)) * direction; - direction = static_cast(-direction); + LyXParagraph::size_type old_lpos = stack[--level]; + int delta = last - old_lpos; + if (level % 2) + delta = -delta; + log2vis_list[old_lpos - bidi_start] += delta; } - vpos = (par_direction == LYX_DIR_LEFT_TO_RIGHT) - ? from - 1 : to + 1; - vpos += offset; - for (lpos = from; lpos <= to; ++lpos) { + LyXParagraph::size_type vpos = bidi_start - 1; + for (LyXParagraph::size_type lpos = bidi_start; lpos <= last; ++lpos) { vpos += log2vis_list[lpos - bidi_start]; vis2log_list[vpos - bidi_start] = lpos; log2vis_list[lpos - bidi_start] = vpos; @@ -378,7 +389,7 @@ void LyXText::draw(Row const * row, int y = offset + row->baseline; int xp[3], yp[3]; - if (row->par->getLetterDirection(pos) == LYX_DIR_LEFT_TO_RIGHT) { + if (bidi_level(pos) % 2 == 0) { xp[0] = int(x + wid * 0.375); yp[0] = int(y - 0.875 * asc * 0.75); @@ -509,14 +520,16 @@ void LyXText::draw(Row const * row, // So IMHO we should go with the easier and clearer implementation. // And even if 1024 is a large number here it might overflow, string // will only overflow if the machine is out of memory... - bool do_transform = (lyxrc.rtl_support && lyxrc.font_norm == "iso8859-6.8x"); + bool do_transform = + font2.language()->lang == "arabic" && + lyxrc.font_norm == "iso8859-6.8x"; if (do_transform) c = TransformChar(c, row->par, pos); static string textstring; textstring = c; ++vpos; - LyXParagraph::size_type last = RowLast(row); + LyXParagraph::size_type last = RowLastPrintable(row); while (vpos <= last && (pos = vis2log(vpos)) >= 0 @@ -552,7 +565,7 @@ void LyXText::draw(Row const * row, // exactly the label-width. int LyXText::LeftMargin(Row const * row) const { - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, row->par->GetLayout()); string parindent = layout.parindent; @@ -565,10 +578,10 @@ int LyXText::LeftMargin(Row const * row) const int x = LYX_PAPER_MARGIN; x += lyxfont::signedWidth(textclasslist - .TextClass(parameters->textclass) + .TextClass(bparams->textclass) .leftmargin(), textclasslist - .TextClass(parameters->textclass) + .TextClass(bparams->textclass) .defaultfont()); if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { @@ -588,7 +601,7 @@ int LyXText::LeftMargin(Row const * row) const LyXParagraph * newpar = row->par ->DepthHook(row->par->GetDepth()); if (newpar && - textclasslist.Style(parameters->textclass, + textclasslist.Style(bparams->textclass, newpar->GetLayout()) .nextnoindent) parindent.clear(); @@ -604,7 +617,7 @@ int LyXText::LeftMargin(Row const * row) const // check wether it is a sufficent paragraph if (newpar && newpar->footnoteflag == row->par->footnoteflag && textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, newpar->GetLayout()).isEnvironment()) { Row dummyrow; dummyrow.par = newpar; @@ -623,7 +636,7 @@ int LyXText::LeftMargin(Row const * row) const parindent.clear(); else parindent = textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, newpar->GetLayout()).parindent; } @@ -635,7 +648,7 @@ int LyXText::LeftMargin(Row const * row) const if (!layout.leftmargin.empty()) { x += lyxfont::signedWidth(layout.leftmargin, textclasslist - .TextClass(parameters-> + .TextClass(bparams-> textclass) .defaultfont()); } @@ -657,7 +670,7 @@ int LyXText::LeftMargin(Row const * row) const } break; case MARGIN_STATIC: - x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(parameters->textclass).defaultfont()) * 4 + x += lyxfont::signedWidth(layout.leftmargin, textclasslist.TextClass(bparams->textclass).defaultfont()) * 4 / (row->par->GetDepth() + 4); break; case MARGIN_FIRST_DYNAMIC: @@ -705,7 +718,7 @@ int LyXText::LeftMargin(Row const * row) const x += lyxfont::signedWidth(layout.leftmargin, textclasslist - .TextClass(parameters->textclass) + .TextClass(bparams->textclass) .defaultfont()); x += minfill; } @@ -745,18 +758,18 @@ int LyXText::LeftMargin(Row const * row) const && align == LYX_ALIGN_BLOCK && !row->par->noindent && (row->par->layout || - parameters->paragraph_separation == + bparams->paragraph_separation == BufferParams::PARSEP_INDENT)) x += lyxfont::signedWidth(parindent, textclasslist - .TextClass(parameters + .TextClass(bparams ->textclass) .defaultfont()); else if (layout.labeltype == LABEL_BIBLIO) { // ale970405 Right width for bibitems x += bibitemMaxWidth(owner_->painter(), textclasslist - .TextClass(parameters + .TextClass(bparams ->textclass) .defaultfont()); } @@ -768,15 +781,15 @@ int LyXText::LeftMargin(Row const * row) const int LyXText::RightMargin(Row const * row) const { LyXLayout const & layout = - textclasslist.Style(parameters->textclass, + textclasslist.Style(bparams->textclass, row->par->GetLayout()); int x = LYX_PAPER_MARGIN + lyxfont::signedWidth(textclasslist - .TextClass(parameters->textclass) + .TextClass(bparams->textclass) .rightmargin(), textclasslist - .TextClass(parameters->textclass) + .TextClass(bparams->textclass) .defaultfont()); if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { @@ -802,7 +815,7 @@ int LyXText::RightMargin(Row const * row) const // check wether it is a sufficent paragraph if (newpar && newpar->footnoteflag == row->par->footnoteflag - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, newpar->GetLayout()) .isEnvironment()) { Row dummyrow; @@ -819,7 +832,7 @@ int LyXText::RightMargin(Row const * row) const } //lyxerr << "rightmargin: " << layout->rightmargin << endl; - x += lyxfont::signedWidth(layout.rightmargin, textclasslist.TextClass(parameters->textclass).defaultfont()) * 4 + x += lyxfont::signedWidth(layout.rightmargin, textclasslist.TextClass(bparams->textclass).defaultfont()) * 4 / (row->par->GetDepth() + 4); return x; } @@ -827,7 +840,7 @@ int LyXText::RightMargin(Row const * row) const int LyXText::LabelEnd (Row const * row) const { - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, row->par->GetLayout()).margintype == MARGIN_MANUAL) { Row tmprow; @@ -922,7 +935,7 @@ LyXText::NextBreakPoint(Row const * row, int width) const LyXParagraph::size_type main_body = BeginningOfMainBody(par); LyXLayout const & layout = - textclasslist.Style(parameters->textclass, par->GetLayout()); + textclasslist.Style(bparams->textclass, par->GetLayout()); LyXParagraph::size_type i = pos; if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX) { @@ -1013,7 +1026,7 @@ int LyXText::Fill(Row const * row, int paper_width) const { int w, fill; // get the pure distance - LyXParagraph::size_type last = RowLast(row); + LyXParagraph::size_type last = RowLastPrintable(row); /* table stuff -- begin */ if (row->par->table) { // for tables FILL does calculate the widthes of each cell in @@ -1038,17 +1051,9 @@ int LyXText::Fill(Row const * row, int paper_width) const * this point. */ } /* table stuff -- end*/ - - // if the row ends with newline, this newline will not be relevant - //if (last >= 0 && row->par->IsNewline(last)) - // --last; - - // if the row ends with a space, this space will not be relevant - if (last >= 0 && row->par->IsLineSeparator(last)) - --last; - + // special handling of the right address boxes - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, row->par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { int tmpfill = row->fill; @@ -1058,7 +1063,7 @@ int LyXText::Fill(Row const * row, int paper_width) const } else w = LeftMargin(row); - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, row->par->GetLayout()); LyXParagraph::size_type main_body = BeginningOfMainBody(row->par); @@ -1208,7 +1213,7 @@ bool LyXText::HfillExpansion(Row const * row_ptr, return true; // in some labels it does not count - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, row_ptr->par->GetLayout()).margintype != MARGIN_MANUAL && pos < BeginningOfMainBody(row_ptr->par)) @@ -1252,7 +1257,7 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const LyXParagraph * par = row_ptr->par->LastPhysicalPar(); LyXParagraph * firstpar = row_ptr->par->FirstPhysicalPar(); - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, firstpar->GetLayout()); LyXFont font = GetFont(par, par->Last()-1); @@ -1264,10 +1269,10 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const int maxasc = int(lyxfont::maxAscent(font) * layout.spacing.getValue() * - parameters->spacing.getValue()); + bparams->spacing.getValue()); int maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * - parameters->spacing.getValue()); + bparams->spacing.getValue()); int pos_end = RowLast(row_ptr); @@ -1324,17 +1329,17 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const && row_ptr->par == firstpar) { /* some parksips VERY EASY IMPLEMENTATION */ - if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) { + if (bparams->paragraph_separation == BufferParams::PARSEP_SKIP) { if (layout.isParagraph() && firstpar->GetDepth() == 0 && firstpar->Previous()) - maxasc += parameters->getDefSkip().inPixels(owner_); + maxasc += bparams->getDefSkip().inPixels(owner_); else if (firstpar->Previous() - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, firstpar->Previous()->GetLayout()).isParagraph() && firstpar->Previous()->GetDepth() == 0) // is it right to use defskip here too? (AS) - maxasc += parameters->getDefSkip().inPixels(owner_); + maxasc += bparams->getDefSkip().inPixels(owner_); } /* the paper margins */ @@ -1357,13 +1362,13 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const /* this is special code for the chapter, since the label of this * layout is printed in an extra row */ if (layout.labeltype == LABEL_COUNTER_CHAPTER - && parameters->secnumdepth>= 0) { + && bparams->secnumdepth>= 0) { labeladdon = int(lyxfont::maxDescent(labelfont) * layout.spacing.getValue() * - parameters->spacing.getValue()) + bparams->spacing.getValue()) + int(lyxfont::maxAscent(labelfont) * layout.spacing.getValue() * - parameters->spacing.getValue()); + bparams->spacing.getValue()); } /* special code for the top label */ @@ -1375,10 +1380,10 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const labeladdon = int( (lyxfont::maxAscent(labelfont) * layout.spacing.getValue() * - parameters->spacing.getValue()) + bparams->spacing.getValue()) +(lyxfont::maxDescent(labelfont) * layout.spacing.getValue() * - parameters->spacing.getValue()) + bparams->spacing.getValue()) + layout.topsep * DefaultHeight() + layout.labelbottomsep * DefaultHeight()); } @@ -1400,7 +1405,7 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const tmptop = layout.topsep; if (row_ptr->previous->par->GetDepth() >= row_ptr->par->GetDepth()) - tmptop-= textclasslist.Style(parameters->textclass, row_ptr->previous->par->GetLayout()).bottomsep; + tmptop-= textclasslist.Style(bparams->textclass, row_ptr->previous->par->GetLayout()).bottomsep; if (tmptop > 0) layoutasc = (tmptop * DefaultHeight()); @@ -1414,7 +1419,7 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const prev = row_ptr->par->DepthHook(row_ptr->par->GetDepth()-1); if (prev) { - maxasc += int(textclasslist.Style(parameters->textclass, + maxasc += int(textclasslist.Style(bparams->textclass, prev->GetLayout()).parsep * DefaultHeight()); } else { @@ -1460,12 +1465,12 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const float unusual = 0; if (comparepar->GetDepth() > nextpar->GetDepth()) { - usual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); + usual = (textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); comparepar = comparepar->DepthHook(nextpar->GetDepth()); if (comparepar->GetLayout()!= nextpar->GetLayout() || nextpar->GetLabelWidthString() != comparepar->GetLabelWidthString()) - unusual = (textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); + unusual = (textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); if (unusual > usual) layoutdesc = unusual; @@ -1477,7 +1482,7 @@ void LyXText::SetHeightOfRow(Row * row_ptr) const if (comparepar->GetLayout()!= nextpar->GetLayout() || nextpar->GetLabelWidthString() != comparepar->GetLabelWidthString()) - layoutdesc = int(textclasslist.Style(parameters->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); + layoutdesc = int(textclasslist.Style(bparams->textclass, comparepar->GetLayout()).bottomsep * DefaultHeight()); } } } @@ -1627,7 +1632,7 @@ void LyXText::BreakAgainOneRow(Row * row) void LyXText::BreakParagraph(char keep_layout) { - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, cursor.par->GetLayout()); /* table stuff -- begin */ @@ -2521,7 +2526,7 @@ void LyXText::InsertChar(char c) * disable the double-space checking */ bool freeSpacing = - textclasslist.Style(parameters->textclass, + textclasslist.Style(bparams->textclass, cursor.row->par->GetLayout()).free_spacing; /* table stuff -- begin*/ @@ -2734,7 +2739,7 @@ void LyXText::InsertChar(char c) RedoHeightOfParagraph(cursor); } else { /* now the special right address boxes */ - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { RedoDrawingOfParagraph(cursor); @@ -2772,23 +2777,22 @@ void LyXText::PrepareToPrint(Row * row, float & x, fill_separator = 0; fill_label_hfill = 0; - LyXDirection direction = row->par->getParDirection(); + bool is_rtl = row->par->isRightToLeftPar(); - if (direction == LYX_DIR_RIGHT_TO_LEFT) { + if (is_rtl) { x = RightMargin(row); if (row->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { LyXFont font(LyXFont::ALL_SANE); font.setSize(LyXFont::SIZE_SMALL); x += lyxfont::width("Mwide-figM", font); } - } - else + } else x = LeftMargin(row); /* is there a manual margin with a manual label */ - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, row->par->GetLayout()).margintype == MARGIN_MANUAL - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, row->par->GetLayout()).labeltype == LABEL_MANUAL) { nlh = NumberOfLabelHfills(row) + 1; /* one more since labels @@ -2816,7 +2820,7 @@ void LyXText::PrepareToPrint(Row * row, float & x, * set x how you need it */ int align; if (row->par->FirstPhysicalPar()->align == LYX_ALIGN_LAYOUT) - align = textclasslist.Style(parameters->textclass, row->par->GetLayout()).align; + align = textclasslist.Style(bparams->textclass, row->par->GetLayout()).align; else align = row->par->FirstPhysicalPar()->align; @@ -2836,7 +2840,7 @@ void LyXText::PrepareToPrint(Row * row, float & x, && row->next->par->GetInset(row->next->pos)->display()) ) fill_separator = w / ns; - else if (direction == LYX_DIR_RIGHT_TO_LEFT) + else if (is_rtl) x += w; break; case LYX_ALIGN_RIGHT: @@ -2851,24 +2855,15 @@ void LyXText::PrepareToPrint(Row * row, float & x, return; ComputeBidiTables(row); - if (direction == LYX_DIR_RIGHT_TO_LEFT) { + if (is_rtl) { LyXParagraph::size_type main_body = BeginningOfMainBody(row->par); LyXParagraph::size_type last = RowLast(row); - if (row->pos <= last - && !row->par->table - && last != vis2log(last) - && row->par->IsLineSeparator(last)) { - if ((main_body = 0 || main_body-1 != last) && - (!row->next || row->next->par != row->par || - row->par->getLetterDirection(last) == - LYX_DIR_RIGHT_TO_LEFT)) - x -= fill_separator+SingleWidth(row->par,last); - } else if (main_body > 0 && - (main_body-1 > last || - !row->par->IsLineSeparator(main_body-1))) { - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + if (main_body > 0 && + (main_body-1 > last || + !row->par->IsLineSeparator(main_body-1))) { + LyXLayout const & layout = textclasslist.Style(bparams->textclass, row->par->GetLayout()); x += lyxfont::width(layout.labelsep, GetFont(row->par, -2)); @@ -3646,7 +3641,7 @@ void LyXText::Backspace() RedoHeightOfParagraph(cursor); } else { // now the special right address boxes - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, cursor.par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { RedoDrawingOfParagraph(cursor); } @@ -3659,8 +3654,8 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) /* returns a printed row */ Painter & pain = owner_->painter(); - LyXDirection direction = row_ptr->par->getParDirection(); - LyXParagraph::size_type last = RowLast(row_ptr); + bool is_rtl = row_ptr->par->isRightToLeftPar(); + LyXParagraph::size_type last = RowLastPrintable(row_ptr); LyXParagraph::size_type vpos, pos; float x, tmpx; @@ -3696,25 +3691,25 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) row_ptr->height, LColor::selection); } else if (sel_start_cursor.row == row_ptr) { - if (direction == LYX_DIR_LEFT_TO_RIGHT) - pain.fillRectangle(sel_start_cursor.x, offset, - paperwidth - sel_start_cursor.x, - row_ptr->height, - LColor::selection); - else + if (is_rtl) pain.fillRectangle(0, offset, sel_start_cursor.x, row_ptr->height, LColor::selection); + else + pain.fillRectangle(sel_start_cursor.x, offset, + paperwidth - sel_start_cursor.x, + row_ptr->height, + LColor::selection); } else if (sel_end_cursor.row == row_ptr) { - if (direction == LYX_DIR_LEFT_TO_RIGHT) - pain.fillRectangle(0, offset, - sel_end_cursor.x, + if (is_rtl) + pain.fillRectangle(sel_end_cursor.x, offset, + paperwidth - sel_end_cursor.x, row_ptr->height, LColor::selection); else - pain.fillRectangle(sel_end_cursor.x, offset, - paperwidth - sel_end_cursor.x, + pain.fillRectangle(0, offset, + sel_end_cursor.x, row_ptr->height, LColor::selection); } else if (y > sel_start_cursor.y && y < sel_end_cursor.y) { @@ -3736,10 +3731,8 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) cell = NumberOfCell(row_ptr->par, row_ptr->pos); tmpx += row_ptr->par->table->GetBeginningOfTextInCell(cell); } - if ( (sel_start_cursor.row != row_ptr && - direction == LYX_DIR_LEFT_TO_RIGHT) || - (sel_end_cursor.row != row_ptr && - direction == LYX_DIR_RIGHT_TO_LEFT)) + if ( (sel_start_cursor.row != row_ptr && !is_rtl) || + (sel_end_cursor.row != row_ptr && is_rtl)) pain.fillRectangle(0, offset, tmpx, row_ptr->height, LColor::selection); @@ -3774,7 +3767,7 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) float old_tmpx = tmpx; if (main_body > 0 && pos == main_body-1) { tmpx += fill_label_hfill + - lyxfont::width(textclasslist.Style(parameters->textclass, + lyxfont::width(textclasslist.Style(bparams->textclass, row_ptr->par->GetLayout()).labelsep, GetFont(row_ptr->par, -2)); if (row_ptr->par->IsLineSeparator(main_body-1)) @@ -3788,13 +3781,9 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) tmpx += fill_label_hfill; } else if (row_ptr->par->IsSeparator(pos)) { - if (pos != last || !row_ptr->next || - row_ptr->next->par != row_ptr->par || - direction == row_ptr->par->getLetterDirection(last)) { - tmpx += SingleWidth(row_ptr->par, pos); - if (pos >= main_body) - tmpx += fill_separator; - } + tmpx += SingleWidth(row_ptr->par, pos); + if (pos >= main_body) + tmpx += fill_separator; } else tmpx += SingleWidth(row_ptr->par, pos); @@ -3808,10 +3797,8 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) LColor::selection); } } - if ( (sel_start_cursor.row != row_ptr && - direction == LYX_DIR_RIGHT_TO_LEFT) || - (sel_end_cursor.row != row_ptr && - direction == LYX_DIR_LEFT_TO_RIGHT) ) + if ( (sel_start_cursor.row != row_ptr && is_rtl) || + (sel_end_cursor.row != row_ptr && !is_rtl) ) pain.fillRectangle(tmpx, offset, paperwidth - tmpx, row_ptr->height, @@ -3927,7 +3914,7 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) } LyXLayout const & layout = - textclasslist.Style(parameters->textclass, + textclasslist.Style(bparams->textclass, row_ptr->par->GetLayout()); firstpar = row_ptr->par->FirstPhysicalPar(); @@ -4004,17 +3991,17 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) /* think about the parskip */ /* some parskips VERY EASY IMPLEMENTATION */ - if (parameters->paragraph_separation == BufferParams::PARSEP_SKIP) { + if (bparams->paragraph_separation == BufferParams::PARSEP_SKIP) { if (layout.latextype == LATEX_PARAGRAPH && firstpar->GetDepth() == 0 && firstpar->Previous()) - y_top += parameters->getDefSkip().inPixels(owner_); + y_top += bparams->getDefSkip().inPixels(owner_); else if (firstpar->Previous() - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, firstpar->Previous()->GetLayout()).latextype == LATEX_PARAGRAPH && firstpar->Previous()->GetDepth() == 0) // is it right to use defskip here, too? (AS) - y_top += parameters->getDefSkip().inPixels(owner_); + y_top += bparams->getDefSkip().inPixels(owner_); } if (row_ptr->par->line_top) { /* draw a top line */ @@ -4040,12 +4027,12 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) string tmpstring = row_ptr->par->GetLabelstring(); if (layout.labeltype == LABEL_COUNTER_CHAPTER) { - if (parameters->secnumdepth >= 0){ + if (bparams->secnumdepth >= 0){ /* this is special code for the chapter layout. This is printed in * an extra row and has a pagebreak at the top. */ - maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * parameters->spacing.getValue()) + maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * bparams->spacing.getValue()) + int(layout.parsep) * DefaultHeight(); - if (direction == LYX_DIR_RIGHT_TO_LEFT) + if (is_rtl) tmpx = paperwidth - LeftMargin(row_ptr) - lyxfont::width(tmpstring, font); pain.text(int(tmpx), @@ -4053,10 +4040,7 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) tmpstring, font); } } else { - if (direction == LYX_DIR_LEFT_TO_RIGHT) - tmpx = x - lyxfont::width(layout.labelsep, font) - - lyxfont::width(tmpstring, font); - else { + if (is_rtl) { tmpx = paperwidth - LeftMargin(row_ptr) + lyxfont::width(layout.labelsep, font); if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) { @@ -4064,7 +4048,10 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) font.setSize(LyXFont::SIZE_SMALL); tmpx += lyxfont::width("Mwide-fixM", font); } - } + } else + tmpx = x - lyxfont::width(layout.labelsep, font) + - lyxfont::width(tmpstring, font); + /* draw it! */ pain.text(int(tmpx), offset + row_ptr->baseline, @@ -4080,16 +4067,15 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) if (!row_ptr->par->GetLabelstring().empty()) { string tmpstring = row_ptr->par->GetLabelstring(); - maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * parameters->spacing.getValue() + maxdesc = int(lyxfont::maxDescent(font) * layout.spacing.getValue() * bparams->spacing.getValue() + (layout.labelbottomsep * DefaultHeight())); tmpx = x; if (layout.labeltype == LABEL_CENTERED_TOP_ENVIRONMENT){ - tmpx = ( ((direction == LYX_DIR_LEFT_TO_RIGHT) - ? x : LeftMargin(row_ptr) ) + tmpx = ( (is_rtl ? LeftMargin(row_ptr) : x) + paperwidth - RightMargin(row_ptr) ) / 2; tmpx -= lyxfont::width(tmpstring, font) / 2; - } else if (direction == LYX_DIR_RIGHT_TO_LEFT) + } else if (is_rtl) tmpx = paperwidth - LeftMargin(row_ptr) - lyxfont::width(tmpstring, font); pain.text(int(tmpx), @@ -4102,12 +4088,12 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) } if (layout.labeltype == LABEL_BIBLIO && row_ptr->par->bibkey) { font = GetFont(row_ptr->par, -1); - if (direction == LYX_DIR_LEFT_TO_RIGHT) - tmpx = x - lyxfont::width(layout.labelsep, font) - - row_ptr->par->bibkey->width(owner_->painter(), font); - else + if (is_rtl) tmpx = paperwidth - LeftMargin(row_ptr) + lyxfont::width(layout.labelsep, font); + else + tmpx = x - lyxfont::width(layout.labelsep, font) + - row_ptr->par->bibkey->width(owner_->painter(), font); row_ptr->par->bibkey->draw(pain, font, offset + row_ptr->baseline, @@ -4195,19 +4181,17 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) LyXFont font = GetFont(row_ptr->par, last); int size = int(0.75 * lyxfont::maxAscent(font)); int y = (offset + row_ptr->baseline) - size; - int x = (direction == LYX_DIR_LEFT_TO_RIGHT) - ? paperwidth - LYX_PAPER_MARGIN - size - : LYX_PAPER_MARGIN; + int x = is_rtl ? LYX_PAPER_MARGIN + : paperwidth - LYX_PAPER_MARGIN - size; if (row_ptr->par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE) - if (direction == LYX_DIR_LEFT_TO_RIGHT) - x -= LYX_PAPER_MARGIN/2; - else { + if (is_rtl) { LyXFont font(LyXFont::ALL_SANE); font.setSize(LyXFont::SIZE_SMALL); x += lyxfont::width("Mwide-figM", font); - } + } else + x -= LYX_PAPER_MARGIN/2; if (row_ptr->fill <= size) - x += (size - row_ptr->fill + 1) * direction; + x += (size - row_ptr->fill + 1) * (is_rtl ? -1 : 1); if (endlabel == END_LABEL_BOX) { pain.line(x, y, x, y + size, LColor::eolmarker); @@ -4436,16 +4420,12 @@ void LyXText::GetVisibleRow(int offset, Row * row_ptr, long y) x += 2; ++vpos; } else if (row_ptr->par->IsSeparator(pos)) { - if (pos != last || !row_ptr->next || - row_ptr->next->par != row_ptr->par || - direction == row_ptr->par->getLetterDirection(last)) { #if 0 - tmpx = x; + tmpx = x; #endif - x += SingleWidth(row_ptr->par, pos); - if (pos >= main_body) - x += fill_separator; - } + x += SingleWidth(row_ptr->par, pos); + if (pos >= main_body) + x += fill_separator; #warning Think about this #if 0 /* -------> Only draw protected spaces when @@ -4506,16 +4486,15 @@ int LyXText::GetColumnNearX(Row * row, int & x) const PrepareToPrint(row, tmpx, fill_separator, fill_hfill, fill_label_hfill); - LyXDirection direction = row->par->getParDirection(); LyXParagraph::size_type vc = row->pos; - LyXParagraph::size_type last = RowLast(row); + LyXParagraph::size_type last = RowLastPrintable(row); LyXParagraph::size_type c = 0; - - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, row->par->GetLayout()); /* table stuff -- begin */ if (row->par->table) { - if (row->next && row->next->par == row->par //the last row doesn't need a newline at the end + //the last row doesn't need a newline at the end + if (row->next && row->next->par == row->par && row->par->IsNewline(last)) last--; int cell = NumberOfCell(row->par, row->pos); @@ -4569,14 +4548,9 @@ int LyXText::GetColumnNearX(Row * row, int & x) const tmpx += fill_label_hfill; } else if (row->par->IsSeparator(c)) { - if (c != last || - !row->next || - row->next->par != row->par || - direction == row->par->getLetterDirection(last)) { - tmpx += SingleWidth(row->par, c); - if (c >= main_body) - tmpx+= fill_separator; - } + tmpx += SingleWidth(row->par, c); + if (c >= main_body) + tmpx+= fill_separator; } else tmpx += SingleWidth(row->par, c); ++vc; @@ -4587,40 +4561,29 @@ int LyXText::GetColumnNearX(Row * row, int & x) const tmpx = last_tmpx; } } - /* make sure that a last space in a row doesnt count */ - if (row->pos <= last - && !(!row->next || row->next->par != row->par)) - if (direction == LYX_DIR_LEFT_TO_RIGHT && vc > last - && row->par->IsLineSeparator(vis2log(last)) ) { - vc = last; - tmpx -= fill_separator+SingleWidth(row->par, vis2log(last)); - } else if (direction == LYX_DIR_RIGHT_TO_LEFT - && vc == row->pos - && row->par->IsLineSeparator(vis2log(row->pos)) ) { - vc = row->pos+1; - tmpx += fill_separator+SingleWidth(row->par, vis2log(row->pos)); - } + + if (vc > last + 1) // This shouldn't happen. + vc = last+1; + if (row->pos > last) // Row is empty? c = row->pos; else if (vc > last || - (row->par->table && vc > row->pos && row->par->IsNewline(vc)) ){ - int pos = (vc > last+1) ? last : vc - 1; - c = vis2log(pos); - if (row->par->getLetterDirection(c) == LYX_DIR_LEFT_TO_RIGHT) + (vc - 1 >= row->pos && + ( (row->par->IsSeparator(vis2log(vc)) && vis2log(vc) != last) + || (row->par->table && row->par->IsNewline(vc) ) + ))) { + c = vis2log(vc - 1); + if (bidi_level(c) % 2 == 0) ++c; } else { c = vis2log(vc); - LyXDirection direction = row->par->getLetterDirection(c); - if (vc > row->pos && row->par->IsLineSeparator(c) - && row->par->getLetterDirection(vis2log(vc - 1)) != direction) - c = vis2log(vc-1); - if (direction == LYX_DIR_RIGHT_TO_LEFT) + if (bidi_level(c) % 2 == 1) ++c; } if (!row->par->table && row->pos <= last && c > last && row->par->IsNewline(last)) { - if (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT) + if (bidi_level(last) % 2 == 0) tmpx -= SingleWidth(row->par, last); else tmpx += SingleWidth(row->par, last); @@ -4736,7 +4699,7 @@ void LyXText::InsertFootnoteEnvironment(LyXParagraph::footnote_kind kind) || kind == LyXParagraph::WIDE_FIG || kind == LyXParagraph::ALGORITHM) { pair lres = - textclasslist.NumberOfLayout(parameters->textclass, + textclasslist.NumberOfLayout(bparams->textclass, "Caption"); LyXTextClass::size_type lay; if (lres.first) { diff --git a/src/text2.C b/src/text2.C index 13774a60d5..7962111347 100644 --- a/src/text2.C +++ b/src/text2.C @@ -55,8 +55,8 @@ LyXText::LyXText(BufferView * bv, int pw, Buffer * p) currentrow = 0; currentrow_y = 0; paperwidth = pw; - parameters = &p->params; - params = p; + bparams = &p->params; + buffer = p; number_of_rows = 0; refresh_y = 0; status = LyXText::UNCHANGED; @@ -120,7 +120,7 @@ LyXFont LyXText::GetFont(LyXParagraph * par, LyXParagraph::size_type pos) const { LyXLayout const & layout = - textclasslist.Style(parameters->textclass, par->GetLayout()); + textclasslist.Style(bparams->textclass, par->GetLayout()); char par_depth = par->GetDepth(); // We specialize the 95% common case: @@ -174,13 +174,13 @@ LyXFont LyXText::GetFont(LyXParagraph * par, par = par->DepthHook(par_depth - 1); if (par) { tmpfont.realize(textclasslist. - Style(parameters->textclass, + Style(bparams->textclass, par->GetLayout()).font); par_depth = par->GetDepth(); } } - tmpfont.realize(textclasslist.TextClass(parameters->textclass).defaultfont()); + tmpfont.realize(textclasslist.TextClass(bparams->textclass).defaultfont()); // Cosmetic improvement: If this is an open footnote, make the font // smaller. @@ -204,7 +204,7 @@ void LyXText::SetCharFont(LyXParagraph * par, font = par->GetInset(pos)->ConvertFont(font); } - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, par->GetLayout()); // Get concrete layout font to reduce against @@ -222,12 +222,12 @@ void LyXText::SetCharFont(LyXParagraph * par, tp = tp->DepthHook(tp->GetDepth()-1); if (tp) layoutfont.realize(textclasslist. - Style(parameters->textclass, + Style(bparams->textclass, tp->GetLayout()).font); } } - layoutfont.realize(textclasslist.TextClass(parameters->textclass).defaultfont()); + layoutfont.realize(textclasslist.TextClass(bparams->textclass).defaultfont()); if (par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE && par->footnotekind == LyXParagraph::FOOTNOTE) { @@ -448,7 +448,7 @@ void LyXText::MakeFontEntriesLayoutSpecific(LyXParagraph * par) { LyXLayout const & layout = - textclasslist.Style(parameters->textclass, par->GetLayout()); + textclasslist.Style(bparams->textclass, par->GetLayout()); LyXFont layoutfont, tmpfont; for (LyXParagraph::size_type pos = 0; @@ -501,7 +501,7 @@ void LyXText::SetLayout(LyXTextClass::size_type layout) cursor = sel_start_cursor; LyXLayout const & lyxlayout = - textclasslist.Style(parameters->textclass, layout); + textclasslist.Style(bparams->textclass, layout); while (cursor.par != sel_end_cursor.par) { if (cursor.par->footnoteflag == @@ -596,7 +596,7 @@ void LyXText::IncDepth() // NOTE: you can't change the depth of a bibliography entry if (cursor.par->footnoteflag == sel_start_cursor.par->footnoteflag - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, cursor.par->GetLayout() ).labeltype != LABEL_BIBLIO) { LyXParagraph * prev = @@ -604,7 +604,7 @@ void LyXText::IncDepth() if (prev && (prev->GetDepth() - cursor.par->GetDepth() > 0 || (prev->GetDepth() == cursor.par->GetDepth() - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, prev->GetLayout()).isEnvironment()))) { cursor.par->FirstPhysicalPar()->depth++; anything_changed = true; @@ -712,7 +712,7 @@ void LyXText::SetFont(LyXFont const & font, bool toggleall) else layoutfont = GetFont(cursor.par, -1); // Update current font - real_current_font.update(font, parameters->language_info, toggleall); + real_current_font.update(font, bparams->language_info, toggleall); // Reduce to implicit settings current_font = real_current_font; @@ -741,7 +741,7 @@ void LyXText::SetFont(LyXFont const & font, bool toggleall) // an open footnote should behave // like a closed one LyXFont newfont = GetFont(cursor.par, cursor.pos); - newfont.update(font, parameters->language_info, toggleall); + newfont.update(font, bparams->language_info, toggleall); SetCharFont(cursor.par, cursor.pos, newfont); cursor.pos++; } else { @@ -1099,7 +1099,7 @@ void LyXText::ToggleFree(LyXFont const & font, bool toggleall) LyXParagraph::size_type LyXText::BeginningOfMainBody(LyXParagraph * par) const { - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, par->GetLayout()).labeltype != LABEL_MANUAL) return 0; else @@ -1146,7 +1146,7 @@ void LyXText::MeltFootnoteEnvironment() tmppar->footnoteflag = LyXParagraph::NO_FOOTNOTE; /* remember the captions and empty paragraphs */ - if ((textclasslist.Style(parameters->textclass, + if ((textclasslist.Style(bparams->textclass, tmppar->GetLayout()) .labeltype == LABEL_SENSITIVE) || !tmppar->Last()) @@ -1260,13 +1260,13 @@ void LyXText::SetParagraph(bool line_top, bool line_bottom, // does the layout allow the new alignment? if (align == LYX_ALIGN_LAYOUT) align = textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, cursor.par->GetLayout()).align; if (align & textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, cursor.par->GetLayout()).alignpossible) { if (align == textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, cursor.par->GetLayout()).align) cursor.par->align = LYX_ALIGN_LAYOUT; else @@ -1403,11 +1403,11 @@ void LyXText::SetCounter(LyXParagraph * par) const // this is only relevant for the beginning of paragraph par = par->FirstPhysicalPar(); - LyXLayout const & layout = textclasslist.Style(parameters->textclass, + LyXLayout const & layout = textclasslist.Style(bparams->textclass, par->GetLayout()); LyXTextClass const & textclass = - textclasslist.TextClass(parameters->textclass); + textclasslist.TextClass(bparams->textclass); /* copy the prev-counters to this one, unless this is the start of a footnote or of a bibliography or the very first paragraph */ @@ -1415,7 +1415,7 @@ void LyXText::SetCounter(LyXParagraph * par) const && !(par->Previous()->footnoteflag == LyXParagraph::NO_FOOTNOTE && par->footnoteflag == LyXParagraph::OPEN_FOOTNOTE && par->footnotekind == LyXParagraph::FOOTNOTE) - && !(textclasslist.Style(parameters->textclass, + && !(textclasslist.Style(bparams->textclass, par->Previous()->GetLayout() ).labeltype != LABEL_BIBLIO && layout.labeltype == LABEL_BIBLIO)) { @@ -1450,7 +1450,7 @@ void LyXText::SetCounter(LyXParagraph * par) const && par->Previous() && par->Previous()->footnoteflag != LyXParagraph::OPEN_FOOTNOTE && (par->PreviousBeforeFootnote() - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, par->PreviousBeforeFootnote()->GetLayout() ).labeltype >= LABEL_COUNTER_ENUMI)) { // Any itemize or enumerate environment in a marginnote @@ -1472,7 +1472,7 @@ void LyXText::SetCounter(LyXParagraph * par) const */ if (par->Previous() && par->Previous()->GetDepth() < par->GetDepth() - && textclasslist.Style(parameters->textclass, + && textclasslist.Style(bparams->textclass, par->Previous()->GetLayout() ).labeltype == LABEL_COUNTER_ENUMI && par->enumdepth < 3 @@ -1516,7 +1516,7 @@ void LyXText::SetCounter(LyXParagraph * par) const if (layout.labeltype >= LABEL_FIRST_COUNTER) { int i = layout.labeltype - LABEL_FIRST_COUNTER; - if (i >= 0 && i<= parameters->secnumdepth) { + if (i >= 0 && i<= bparams->secnumdepth) { par->incCounter(i); // increment the counter // Is there a label? Useful for Chapter layout @@ -1582,26 +1582,26 @@ void LyXText::SetCounter(LyXParagraph * par) const } else { // appendix switch (2 * LABEL_FIRST_COUNTER - textclass.maxcounter() + i) { case LABEL_COUNTER_CHAPTER: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i)); + else + s << alphaCounter(par->getCounter(i)); break; case LABEL_COUNTER_SECTION: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i - 1)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i - 1)); + else + s << alphaCounter(par->getCounter(i - 1)); s << '.' << par->getCounter(i); break; case LABEL_COUNTER_SUBSECTION: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i - 2)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i - 2)); + else + s << alphaCounter(par->getCounter(i - 2)); s << '.' << par->getCounter(i-1) << '.' @@ -1609,10 +1609,10 @@ void LyXText::SetCounter(LyXParagraph * par) const break; case LABEL_COUNTER_SUBSUBSECTION: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i-3)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i-3)); + else + s << alphaCounter(par->getCounter(i-3)); s << '.' << par->getCounter(i-2) << '.' @@ -1621,10 +1621,10 @@ void LyXText::SetCounter(LyXParagraph * par) const break; case LABEL_COUNTER_PARAGRAPH: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i-4)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i-4)); + else + s << alphaCounter(par->getCounter(i-4)); s << '.' << par->getCounter(i-3) << '.' @@ -1634,10 +1634,10 @@ void LyXText::SetCounter(LyXParagraph * par) const break; case LABEL_COUNTER_SUBPARAGRAPH: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(par->getCounter(i-5)); - else + if (par->isRightToLeftPar()) s << hebrewCounter(par->getCounter(i-5)); + else + s << alphaCounter(par->getCounter(i-5)); s << '.' << par->getCounter(i-4) << '.' @@ -1687,34 +1687,34 @@ void LyXText::SetCounter(LyXParagraph * par) const #endif switch (par->enumdepth) { case 1: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << '(' - << loweralphaCounter(number) - << ')'; - else + if (par->isRightToLeftPar()) s << '(' << hebrewCounter(number) << ')'; + else + s << '(' + << loweralphaCounter(number) + << ')'; break; case 2: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << romanCounter(number) << '.'; - else + if (par->isRightToLeftPar()) s << '.' << romanCounter(number); + else + s << romanCounter(number) << '.'; break; case 3: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << alphaCounter(number) - << '.'; - else + if (par->isRightToLeftPar()) s << '.' << alphaCounter(number); + else + s << alphaCounter(number) + << '.'; break; default: - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s << number << '.'; - else + if (par->isRightToLeftPar()) s << '.' << number; + else + s << number << '.'; break; } #ifdef HAVE_SSTREAM @@ -1750,31 +1750,22 @@ void LyXText::SetCounter(LyXParagraph * par) const if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && (par->footnotekind == LyXParagraph::FIG || par->footnotekind == LyXParagraph::WIDE_FIG)) - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s = "Figure:"; - else - s = ":רויא"; + s = (par->getParLanguage()->lang == "hebrew") + ? ":רויא" : "Figure:"; else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && (par->footnotekind == LyXParagraph::TAB || par->footnotekind == LyXParagraph::WIDE_TAB)) - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s = "Table:"; - else - s = ":הלבט"; + s = (par->getParLanguage()->lang == "hebrew") + ? ":הלבט" : "Table:"; else if (par->footnoteflag != LyXParagraph::NO_FOOTNOTE && par->footnotekind == LyXParagraph::ALGORITHM) - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s = "Algorithm:"; - else - s = ":םתירוגלא"; + s = (par->getParLanguage()->lang == "hebrew") + ? ":םתירוגלא" : "Algorithm:"; else { /* par->SetLayout(0); s = layout->labelstring; */ - if (par->getParDirection() == LYX_DIR_LEFT_TO_RIGHT) - s = "Senseless: "; - else - s = " :תועמשמ רסח"; - + s = (par->getParLanguage()->lang == "hebrew") + ? " :תועמשמ רסח" : "Senseless: "; } } par->labelstring = s; @@ -1814,8 +1805,8 @@ void LyXText::UpdateCounters(Row * row) const /* now check for the headline layouts. remember that they * have a dynamic left margin */ if (!par->IsDummy() - && ( textclasslist.Style(parameters->textclass, par->layout).margintype == MARGIN_DYNAMIC - || textclasslist.Style(parameters->textclass, par->layout).labeltype == LABEL_SENSITIVE) + && ( textclasslist.Style(bparams->textclass, par->layout).margintype == MARGIN_DYNAMIC + || textclasslist.Style(bparams->textclass, par->layout).labeltype == LABEL_SENSITIVE) ){ /* Rebreak the paragraph */ @@ -1949,7 +1940,7 @@ void LyXText::CutSelection(bool doclear) DeleteSimpleCutBuffer(); // set the textclass - simple_cut_buffer_textclass = parameters->textclass; + simple_cut_buffer_textclass = bparams->textclass; #ifdef WITH_WARNINGS #warning Asger: Make cut more intelligent here. @@ -2210,13 +2201,13 @@ void LyXText::CutSelection(bool doclear) endpar = sel_start_cursor.par; cap.cutSelection(sel_start_cursor.par, &endpar, sel_start_cursor.pos, sel_end_cursor.pos, - parameters->textclass, doclear); + bparams->textclass, doclear); } else { endpar = sel_end_cursor.par; cap.cutSelection(sel_start_cursor.par, &endpar, sel_start_cursor.pos, sel_end_cursor.pos, - parameters->textclass, doclear); + bparams->textclass, doclear); cursor.par = sel_end_cursor.par = endpar; cursor.pos = sel_end_cursor.pos; } @@ -2279,7 +2270,7 @@ void LyXText::CopySelection() DeleteSimpleCutBuffer(); // set the textclass - simple_cut_buffer_textclass = parameters->textclass; + simple_cut_buffer_textclass = bparams->textclass; #ifdef FIX_DOUBLE_SPACE // copy behind a space if there is one @@ -2395,7 +2386,7 @@ void LyXText::CopySelection() cap.copySelection(sel_start_cursor.par, sel_end_cursor.par, sel_start_cursor.pos, sel_end_cursor.pos, - parameters->textclass); + bparams->textclass); } #endif @@ -2549,7 +2540,7 @@ void LyXText::PasteSelection() // make sure there is no class difference cap.SwitchLayoutsBetweenClasses(simple_cut_buffer_textclass, - parameters->textclass, + bparams->textclass, simple_cut_buffer); // make the simple_cut_buffer exactly the same layout than @@ -2685,7 +2676,7 @@ void LyXText::PasteSelection() LyXParagraph *actpar = cursor.par; int endpos = cursor.pos; - cap.pasteSelection(&actpar, &endpar, endpos, parameters->textclass); + cap.pasteSelection(&actpar, &endpar, endpos, bparams->textclass); RedoParagraphs(cursor, endpar); @@ -2702,7 +2693,7 @@ void LyXText::PasteSelection() // returns a pointer to the very first LyXParagraph LyXParagraph * LyXText::FirstParagraph() const { - return params->paragraph; + return buffer->paragraph; } @@ -2824,7 +2815,7 @@ void LyXText::InsertStringA(string const & str) SetCursorParUndo(); bool flag = - textclasslist.Style(parameters->textclass, + textclasslist.Style(bparams->textclass, cursor.par->GetLayout()).isEnvironment(); // only to be sure, should not be neccessary ClearSelection(); @@ -3085,7 +3076,7 @@ void LyXText::CheckParagraph(LyXParagraph * par, status = LyXText::NEED_MORE_REFRESH; // check the special right address boxes - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, par->GetLayout()).margintype == MARGIN_RIGHT_ADDRESS_BOX) { tmpcursor.par = par; @@ -3187,8 +3178,6 @@ void LyXText::SetCursorIntern(LyXParagraph * par, if (setfont) if (cursor.pos && (cursor.pos == cursor.par->Last() || cursor.par->IsSeparator(cursor.pos) - || (cursor.pos && cursor.pos == BeginningOfMainBody(cursor.par) - && !cursor.par->IsSeparator(cursor.pos)) || (cursor.par->table && cursor.par->IsNewline(cursor.pos)) )) { current_font = cursor.par->GetFontSettings(cursor.pos - 1); @@ -3211,28 +3200,26 @@ void LyXText::SetCursorIntern(LyXParagraph * par, float fill_separator, fill_hfill, fill_label_hfill; PrepareToPrint(row, x, fill_separator, fill_hfill, fill_label_hfill); LyXParagraph::size_type cursor_vpos; - LyXParagraph::size_type last = RowLast(row); - if (row->pos > last) - cursor_vpos = 0; - else if (pos > last) - cursor_vpos = (row->par->getLetterDirection(last) == LYX_DIR_LEFT_TO_RIGHT) - ? log2vis(last)+1 : log2vis(last); - else { - LyXDirection letter_direction = - row->par->getLetterDirection(pos); - LyXDirection font_direction = - (real_current_font.isVisibleRightToLeft()) - ? LYX_DIR_RIGHT_TO_LEFT : LYX_DIR_LEFT_TO_RIGHT; - if (letter_direction == font_direction - || pos <= row->pos - || (row->par->table && row->par->IsNewline(pos-1))) - cursor_vpos = (letter_direction == LYX_DIR_LEFT_TO_RIGHT) - ? log2vis(pos) : log2vis(pos) + 1; - else - cursor_vpos = (font_direction == LYX_DIR_LEFT_TO_RIGHT) - ? log2vis(pos-1) + 1 : log2vis(pos - 1); - } - + LyXParagraph::size_type last = RowLastPrintable(row); + + if (pos > last + 1) // This shouldn't happen. + pos = last+1; + + if (last < row->pos) + cursor_vpos = 0; + else if (pos > last || + (pos - 1 >= row->pos && + (row->par->IsSeparator(pos) || + (row->par->table && row->par->IsNewline(pos)) + ))) + /// Place cursor after char at (logical) position pos-1 + cursor_vpos = (bidi_level(pos-1) % 2 == 0) + ? log2vis(pos-1) + 1 : log2vis(pos-1); + else + /// Place cursor before char at (logical) position pos + cursor_vpos = (bidi_level(pos) % 2 == 0) + ? log2vis(pos) : log2vis(pos) + 1; + /* table stuff -- begin*/ if (row->par->table) { int cell = NumberOfCell(row->par, row->pos); @@ -3263,7 +3250,7 @@ void LyXText::SetCursorIntern(LyXParagraph * par, if (main_body > 0 && pos == main_body-1) { x += fill_label_hfill + lyxfont::width(textclasslist - .Style(parameters->textclass, + .Style(bparams->textclass, row->par->GetLayout()) .labelsep, GetFont(row->par, -2)); @@ -3278,15 +3265,9 @@ void LyXText::SetCursorIntern(LyXParagraph * par, x += fill_label_hfill; } else if (row->par->IsSeparator(pos)) { - if (pos != last || - !row->next || - row->next->par != row->par || - row->par->getParDirection() == - row->par->getLetterDirection(last)) { - x += SingleWidth(row->par, pos); - if (pos >= main_body) - x += fill_separator; - } + x += SingleWidth(row->par, pos); + if (pos >= main_body) + x += fill_separator; } else x += SingleWidth(row->par, pos); } @@ -3464,7 +3445,7 @@ void LyXText::DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const if (selection) return; // We allow all kinds of "mumbo-jumbo" when freespacing. - if (textclasslist.Style(parameters->textclass, + if (textclasslist.Style(bparams->textclass, old_cursor.par->GetLayout()).free_spacing) return; @@ -3514,7 +3495,7 @@ void LyXText::DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const #endif #if 1 // Do not delete empty paragraphs with keepempty set. - if ((textclasslist.Style(parameters->textclass, + if ((textclasslist.Style(bparams->textclass, old_cursor.par->GetLayout())).keepempty) return; @@ -3561,8 +3542,8 @@ void LyXText::DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const // delete old row RemoveRow(old_cursor.row); - if (params->paragraph == old_cursor.par) { - params->paragraph = params->paragraph->next; + if (buffer->paragraph == old_cursor.par) { + buffer->paragraph = buffer->paragraph->next; } // delete old par delete old_cursor.par; @@ -3597,8 +3578,8 @@ void LyXText::DeleteEmptyParagraphMechanism(LyXCursor const & old_cursor) const // delete old row RemoveRow(old_cursor.row); // delete old par - if (params->paragraph == old_cursor.par) { - params->paragraph = params->paragraph->next; + if (buffer->paragraph == old_cursor.par) { + buffer->paragraph = buffer->paragraph->next; } delete old_cursor.par; @@ -3660,11 +3641,11 @@ LyXParagraph * LyXText::GetParFromID(int id) bool LyXText::TextUndo() { // returns false if no undo possible - Undo * undo = params->undostack.pop(); + Undo * undo = buffer->undostack.pop(); if (undo) { FinishUndo(); if (!undo_frozen) - params->redostack + buffer->redostack .push(CreateUndo(undo->kind, GetParFromID(undo->number_of_before_par), GetParFromID(undo->number_of_behind_par))); @@ -3676,11 +3657,11 @@ bool LyXText::TextUndo() bool LyXText::TextRedo() { // returns false if no redo possible - Undo * undo = params->redostack.pop(); + Undo * undo = buffer->redostack.pop(); if (undo) { FinishUndo(); if (!undo_frozen) - params->undostack + buffer->undostack .push(CreateUndo(undo->kind, GetParFromID(undo->number_of_before_par), GetParFromID(undo->number_of_behind_par))); @@ -3723,7 +3704,7 @@ bool LyXText::TextHandleUndo(Undo * undo) if (before) tmppar5 = before->next; else - tmppar5 = params->paragraph; + tmppar5 = buffer->paragraph; tmppar2 = tmppar3; while (tmppar5 && tmppar5 != behind){ tmppar = tmppar5; @@ -3752,12 +3733,12 @@ bool LyXText::TextHandleUndo(Undo * undo) if (before) before->next = tmppar3; else - params->paragraph = tmppar3; + buffer->paragraph = tmppar3; tmppar3->previous = before; } else { if (!before) - params->paragraph = behind; + buffer->paragraph = behind; } if (tmppar4) { tmppar4->next = behind; @@ -3842,15 +3823,15 @@ void LyXText::SetUndo(Undo::undo_kind kind, LyXParagraph const * before, LyXParagraph const * behind) const { if (!undo_frozen) - params->undostack.push(CreateUndo(kind, before, behind)); - params->redostack.clear(); + buffer->undostack.push(CreateUndo(kind, before, behind)); + buffer->redostack.clear(); } void LyXText::SetRedo(Undo::undo_kind kind, LyXParagraph const * before, LyXParagraph const * behind) { - params->redostack.push(CreateUndo(kind, before, behind)); + buffer->redostack.push(CreateUndo(kind, before, behind)); } @@ -3873,10 +3854,10 @@ Undo * LyXText::CreateUndo(Undo::undo_kind kind, LyXParagraph const * before, if (!undo_finished && kind != Undo::EDIT && kind != Undo::FINISH){ // check wether storing is needed - if (!params->undostack.empty() && - params->undostack.top()->kind == kind && - params->undostack.top()->number_of_before_par == before_number && - params->undostack.top()->number_of_behind_par == behind_number ){ + if (!buffer->undostack.empty() && + buffer->undostack.top()->kind == kind && + buffer->undostack.top()->number_of_before_par == before_number && + buffer->undostack.top()->number_of_behind_par == behind_number ){ // no undo needed return 0; }