From 7d97e555fc9bc2be2d55e4c5fc61e1a7010dec5d Mon Sep 17 00:00:00 2001 From: Abdelrazak Younes Date: Fri, 31 Aug 2007 14:46:13 +0000 Subject: [PATCH] Transfer Paragraph::hfillExpansion() to ParagraphMetrics. This also reduce the dependency to Row.h which is probably going to change in the near future. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19951 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Paragraph.cpp | 36 ------------------------------------ src/Paragraph.h | 4 ---- src/ParagraphMetrics.cpp | 35 +++++++++++++++++++++++++++++++++++ src/ParagraphMetrics.h | 6 ++++++ src/Text.cpp | 2 +- src/TextMetrics.cpp | 5 +++-- src/rowpainter.cpp | 2 +- 7 files changed, 46 insertions(+), 44 deletions(-) diff --git a/src/Paragraph.cpp b/src/Paragraph.cpp index 7a56557750..7a987dc559 100644 --- a/src/Paragraph.cpp +++ b/src/Paragraph.cpp @@ -2624,42 +2624,6 @@ char_type Paragraph::transformChar(char_type c, pos_type pos) const } -bool Paragraph::hfillExpansion(Row const & row, pos_type pos) const -{ - if (!isHfill(pos)) - return false; - - BOOST_ASSERT(pos >= row.pos() && pos < row.endpos()); - - // expand at the end of a row only if there is another hfill on the same row - if (pos == row.endpos() - 1) { - for (pos_type i = row.pos(); i < pos; i++) { - if (isHfill(i)) - return true; - } - return false; - } - - // expand at the beginning of a row only if it is the first row of a paragraph - if (pos == row.pos()) { - return pos == 0; - } - - // do not expand in some labels - if (layout()->margintype != MARGIN_MANUAL && pos < beginOfBody()) - return false; - - // if there is anything between the first char of the row and - // the specified position that is neither a newline nor an hfill, - // the hfill will be expanded, otherwise it won't - for (pos_type i = row.pos(); i < pos; i++) { - if (!isNewline(i) && !isHfill(i)) - return true; - } - return false; -} - - int Paragraph::checkBiblio(bool track_changes) { //FIXME From JS: diff --git a/src/Paragraph.h b/src/Paragraph.h index cd43609321..21a96719c9 100644 --- a/src/Paragraph.h +++ b/src/Paragraph.h @@ -17,10 +17,8 @@ #define PARAGRAPH_H #include "Changes.h" -#include "Dimension.h" #include "InsetList.h" #include "lyxlayout_ptr_fwd.h" -#include "Row.h" #include "insets/Inset.h" // only for Inset::Code @@ -356,8 +354,6 @@ public: ParagraphParameters & params(); /// ParagraphParameters const & params() const; - /// - bool hfillExpansion(Row const & row, pos_type pos) const; /// Check if we are in a Biblio environment and insert or /// delete InsetBibitems as necessary. diff --git a/src/ParagraphMetrics.cpp b/src/ParagraphMetrics.cpp index 65aedd2c1c..d9272f2255 100644 --- a/src/ParagraphMetrics.cpp +++ b/src/ParagraphMetrics.cpp @@ -213,4 +213,39 @@ int ParagraphMetrics::singleWidth(pos_type pos, Font const & font) const } +bool ParagraphMetrics::hfillExpansion(Row const & row, pos_type pos) const +{ + if (!par_->isHfill(pos)) + return false; + + BOOST_ASSERT(pos >= row.pos() && pos < row.endpos()); + + // expand at the end of a row only if there is another hfill on the same row + if (pos == row.endpos() - 1) { + for (pos_type i = row.pos(); i < pos; i++) { + if (par_->isHfill(i)) + return true; + } + return false; + } + + // expand at the beginning of a row only if it is the first row of a paragraph + if (pos == row.pos()) { + return pos == 0; + } + + // do not expand in some labels + if (par_->layout()->margintype != MARGIN_MANUAL && pos < par_->beginOfBody()) + return false; + + // if there is anything between the first char of the row and + // the specified position that is neither a newline nor an hfill, + // the hfill will be expanded, otherwise it won't + for (pos_type i = row.pos(); i < pos; i++) { + if (!par_->isNewline(i) && !par_->isHfill(i)) + return true; + } + return false; +} + } // namespace lyx diff --git a/src/ParagraphMetrics.h b/src/ParagraphMetrics.h index 759c346b01..42f6d87204 100644 --- a/src/ParagraphMetrics.h +++ b/src/ParagraphMetrics.h @@ -17,7 +17,9 @@ #ifndef PARAGRAPH_METRICS_H #define PARAGRAPH_METRICS_H +#include "Dimension.h" #include "Paragraph.h" +#include "Row.h" namespace lyx { @@ -73,6 +75,10 @@ public: /// dump some information to lyxerr void dump() const; + + /// + bool hfillExpansion(Row const & row, pos_type pos) const; + /// void computeRowSignature(Row &, BufferParams const & bparams); diff --git a/src/Text.cpp b/src/Text.cpp index 09606366ac..7b16ed0c72 100644 --- a/src/Text.cpp +++ b/src/Text.cpp @@ -1553,7 +1553,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl, x += pm.singleWidth(pos, font); - if (par.hfillExpansion(row, pos)) + if (pm.hfillExpansion(row, pos)) x += (pos >= body_pos) ? row.hfill : row.label_hfill; else if (par.isSeparator(pos) && pos >= body_pos) x += row.separator; diff --git a/src/TextMetrics.cpp b/src/TextMetrics.cpp index 8f3f993816..81a9626966 100644 --- a/src/TextMetrics.cpp +++ b/src/TextMetrics.cpp @@ -820,6 +820,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, int const xo = main_text_? 0 : bv_->coordCache().get(text_, pit).x_; x -= xo; Paragraph const & par = text_->getPar(pit); + ParagraphMetrics const & pm = par_metrics_[pit]; Bidi bidi; bidi.computeTables(par, buffer, row); @@ -856,7 +857,7 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit, tmpx -= singleWidth(pit, body_pos - 1); } - if (par.hfillExpansion(row, c)) { + if (pm.hfillExpansion(row, c)) { tmpx += singleWidth(pit, c); if (c >= body_pos) tmpx += row.hfill; @@ -1054,7 +1055,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co // Re-enable screen drawing for future use of the painter. pi.pain.setDrawingEnabled(true); - LYXERR(Debug::PAINTING) << "." << endl; + //LYXERR(Debug::PAINTING) << "." << endl; } diff --git a/src/rowpainter.cpp b/src/rowpainter.cpp index d20c644ca4..d8b05eb1c1 100644 --- a/src/rowpainter.cpp +++ b/src/rowpainter.cpp @@ -96,7 +96,7 @@ void RowPainter::paintHfill(pos_type const pos, pos_type const body_pos) pi_.pain.line(int(x_), y1, int(x_), y0, Color::added_space); - if (par_.hfillExpansion(row_, pos)) { + if (pm_.hfillExpansion(row_, pos)) { int const y2 = (y0 + y1) / 2; if (pos >= body_pos) { -- 2.39.2