]> git.lyx.org Git - lyx.git/blobdiff - src/TextMetrics.cpp
Turn an error message into a Debug::LOCALE warning
[lyx.git] / src / TextMetrics.cpp
index 12b560760e6091199bd57c94f9f59a24eb77dd26..52e815acc532df8b711f940159410db4b5b6aa63 100644 (file)
@@ -129,7 +129,7 @@ static int numberOfHfills(Paragraph const & par, Row const & row)
 TextMetrics::TextMetrics(BufferView * bv, Text * text)
        : bv_(bv), text_(text)
 {
-       LBUFERR(bv_, _("Text metrics error."));
+       LBUFERR(bv_);
        max_width_ = bv_->workWidth();
        dim_.wid = max_width_;
        dim_.asc = 10;
@@ -159,7 +159,7 @@ pair<pit_type, ParagraphMetrics const *> TextMetrics::first() const
 
 pair<pit_type, ParagraphMetrics const *> TextMetrics::last() const
 {
-       LBUFERR(!par_metrics_.empty(), _("Text metrics error."));
+       LBUFERR(!par_metrics_.empty());
        ParMetricsCache::const_reverse_iterator it = par_metrics_.rbegin();
        return make_pair(it->first, &it->second);
 }
@@ -180,7 +180,7 @@ ParagraphMetrics & TextMetrics::parMetrics(pit_type pit, bool redo)
 
 bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width)
 {
-       LBUFERR(mi.base.textwidth > 0, _("Text metrics error."));
+       LBUFERR(mi.base.textwidth > 0);
        max_width_ = mi.base.textwidth;
        // backup old dimension.
        Dimension const old_dim = dim_;
@@ -234,7 +234,7 @@ void TextMetrics::applyOuterFont(Font & font) const
 {
        FontInfo lf(font_.fontInfo());
        lf.reduce(bv_->buffer().params().getFont().fontInfo());
-       font.fontInfo().realize(lf); 
+       font.fontInfo().realize(lf);
 }
 
 
@@ -346,19 +346,19 @@ bool TextMetrics::isRTLBoundary(pit_type pit, pos_type pos,
        // no RTL boundary at line break:
        // abc|\n    -> move right ->   abc\n       (and not:    abc\n|
        // FED                          FED|                     FED     )
-       if (startpos == pos && endpos == pos && endpos != par.size() 
-               && (par.isNewline(pos - 1) 
-                       || par.isLineSeparator(pos - 1) 
+       if (startpos == pos && endpos == pos && endpos != par.size()
+               && (par.isNewline(pos - 1)
+                       || par.isLineSeparator(pos - 1)
                        || par.isSeparator(pos - 1)))
                return false;
-       
+
        bool left = font.isVisibleRightToLeft();
        bool right;
        if (pos == par.size())
                right = par.isRTL(bv_->buffer().params());
        else
                right = displayFont(pit, pos).isVisibleRightToLeft();
-       
+
        return left != right;
 }
 
@@ -417,7 +417,7 @@ bool TextMetrics::redoParagraph(pit_type const pit)
                // should be.
                bv_->buffer().updateBuffer();
                parPos = text_->macrocontextPosition();
-               LBUFERR(!parPos.empty(), _("Text metrics error."));
+               LBUFERR(!parPos.empty());
                parPos.pit() = pit;
        }
 
@@ -581,7 +581,7 @@ void TextMetrics::computeRowMetrics(pit_type const pit,
                        case LYX_ALIGN_CENTER:
                        case LYX_ALIGN_LEFT:
                        case LYX_ALIGN_RIGHT:
-                               if (align == LYX_ALIGN_NONE 
+                               if (align == LYX_ALIGN_NONE
                                    || align == LYX_ALIGN_BLOCK)
                                        align = owner.contentAlignment();
                                break;
@@ -693,7 +693,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
        Paragraph const & par = text_->getPar(pit);
 
        pos_type last = par.beginOfBody();
-       LBUFERR(last > 0, _("Text metrics error."));
+       LBUFERR(last > 0);
 
        // -1 because a label ends with a space that is in the label
        --last;
@@ -718,7 +718,7 @@ int TextMetrics::labelFill(pit_type const pit, Row const & row) const
 
 
 #if 0
-// Not used, see TextMetrics::rowBreakPoint. 
+// Not used, see TextMetrics::rowBreakPoint.
 // this needs special handling - only newlines count as a break point
 static pos_type addressBreakPoint(pos_type i, Paragraph const & par)
 {
@@ -771,7 +771,7 @@ public:
        FontIterator & operator++()
        {
                ++pos_;
-               if (pos_ > endspan_ || pos_ == bodypos_) {
+               if (pos_ < par_.size() && (pos_ > endspan_ || pos_ == bodypos_)) {
                        font_ = tm_.displayFont(pit_, pos_);
                        endspan_ = par_.fontSpan(pos_).last;
                }
@@ -812,7 +812,7 @@ pos_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
        Layout const & layout = par.layout();
 
 #if 0
-       //FIXME: As long as leftMargin() is not correctly implemented for 
+       //FIXME: As long as leftMargin() is not correctly implemented for
        // MARGIN_RIGHT_ADDRESS_BOX, we should also not do this here.
        // Otherwise, long rows will be painted off the screen.
        if (layout.margintype == MARGIN_RIGHT_ADDRESS_BOX)
@@ -853,10 +853,10 @@ pos_type TextMetrics::rowBreakPoint(int width, pit_type const pit,
        ParagraphList const & pars_ = text_->paragraphs();
        bool const draw_par_end_marker = lyxrc.paragraph_markers
                && size_type(pit + 1) < pars_.size();
-                               
+
        for ( ; i < end; ++i, ++fi) {
                int thiswidth = pm.singleWidth(i, *fi);
-               
+
                if (draw_par_end_marker && i == end - 1)
                        // enlarge the last character to hold the end-of-par marker
                        thiswidth += par_marker_width;
@@ -973,8 +973,8 @@ int TextMetrics::rowWidth(int right_margin, pit_type const pit,
                                        w -= singleWidth(pit, i - 1);
                                w = max(w, label_end);
                        }
-                       
-                       // a line separator at the end of a line (but not at the end of a 
+
+                       // a line separator at the end of a line (but not at the end of a
                        // paragraph) will not be drawn and should therefore not count for
                        // the row width.
                        if (!par.isLineSeparator(i) || i != end - 1 || end == par.size())
@@ -1152,11 +1152,10 @@ Dimension TextMetrics::rowHeight(pit_type const pit, pos_type const first,
                pit_type nextpit = pit + 1;
                if (nextpit != pit_type(pars.size())) {
                        pit_type cpit = pit;
-                       double usual = 0;
-                       double unusual = 0;
 
                        if (pars[cpit].getDepth() > pars[nextpit].getDepth()) {
-                               usual = pars[cpit].layout().bottomsep * dh;
+                               double usual = pars[cpit].layout().bottomsep * dh;
+                               double unusual = 0;
                                cpit = text_->depthHook(cpit, pars[nextpit].getDepth());
                                if (pars[cpit].layout() != pars[nextpit].layout()
                                        || pars[nextpit].getLabelWidthString() != pars[cpit].getLabelWidthString())
@@ -1240,13 +1239,6 @@ pos_type TextMetrics::getColumnNearX(pit_type const pit,
        // the value of rtl.
        bool const rtl_on_lastrow = lastrow ? text_->isRTL(par) : false;
 
-       // if the first character is a separator, and we are in RTL
-       // text, this character will not be painted on screen
-       // and thus we should not count it and skip to the next. Only
-       // in freespacing paragraphs, this first character is painted.
-       if (!par.isFreeSpacing() && par.isSeparator(bidi.vis2log(vc)))
-               ++vc;
-
        while (vc < end && tmpx <= x) {
                c = bidi.vis2log(vc);
                last_tmpx = tmpx;
@@ -1343,7 +1335,7 @@ pos_type TextMetrics::x2pos(pit_type pit, int row, int x) const
        // upDownInText() while in selection mode.
        ParagraphMetrics const & pm = parMetrics(pit);
 
-       LBUFERR(row < int(pm.rows().size()), _("Text metrics error."));
+       LBUFERR(row < int(pm.rows().size()));
        bool bound = false;
        Row const & r = pm.rows()[row];
        return r.pos() + getColumnNearX(pit, r, x, bound);
@@ -1446,7 +1438,7 @@ Row const & TextMetrics::getPitAndRowNearY(int & y, pit_type & pit,
        ParagraphMetrics const & pm = par_metrics_[pit];
 
        int yy = pm.position() - pm.ascent();
-       LBUFERR(!pm.rows().empty(), _("Text metrics error."));
+       LBUFERR(!pm.rows().empty());
        RowList::const_iterator rit = pm.rows().begin();
        RowList::const_iterator rlast = pm.rows().end();
        --rlast;
@@ -1495,7 +1487,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
        }
        pit_type pit = getPitNearY(y);
        LASSERT(pit != -1, return 0);
-       
+
        int yy = y; // is modified by getPitAndRowNearY
        Row const & row = getPitAndRowNearY(yy, pit, assert_in_view, up);
 
@@ -1512,10 +1504,6 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
        Inset * inset = checkInsetHit(x, yy);
        //lyxerr << "inset " << inset << " hit at x: " << x << " y: " << y << endl;
        if (!inset) {
-               // Either we deconst editXY or better we move current_font
-               // and real_current_font to Cursor
-               // FIXME: what is needed now that current_font and real_current_font
-               // are transferred?
                cur.setCurrentFont();
                return 0;
        }
@@ -1525,7 +1513,7 @@ Inset * TextMetrics::editXY(Cursor & cur, int x, int y,
 
        // This should be just before or just behind the
        // cursor position set above.
-       LASSERT(inset == inset_before 
+       LASSERT(inset == inset_before
                || inset == pars[pit].getInset(pos), return 0);
 
        // Make sure the cursor points to the position before
@@ -1557,7 +1545,7 @@ void TextMetrics::setCursorFromCoordinates(Cursor & cur, int const x, int const
                " pit: " << pit << " yy: " << yy);
 
        int r = 0;
-       LBUFERR(pm.rows().size(), _("Text metrics error."));
+       LBUFERR(pm.rows().size());
        for (; r < int(pm.rows().size()) - 1; ++r) {
                Row const & row = pm.rows()[r];
                if (int(yy + row.height()) > y)
@@ -1982,7 +1970,7 @@ int TextMetrics::leftMargin(int max_width,
                // The left margin depends on the widest row in this paragraph.
                // This code is wrong because it depends on the rows, but at the
                // same time this function is used in redoParagraph to construct
-               // the rows. 
+               // the rows.
                ParagraphMetrics const & pm = par_metrics_[pit];
                RowList::const_iterator rit = pm.rows().begin();
                RowList::const_iterator end = pm.rows().end();
@@ -2027,7 +2015,7 @@ int TextMetrics::leftMargin(int max_width,
                    && par.getInset(pos)->display())
                        && (!(tclass.isDefaultLayout(par.layout())
                 || tclass.isPlainLayout(par.layout()))
-               || buffer.params().paragraph_separation 
+               || buffer.params().paragraph_separation
                                == BufferParams::ParagraphIndentSeparation)
            )
                {
@@ -2039,7 +2027,7 @@ int TextMetrics::leftMargin(int max_width,
                        else
                                l_margin += buffer.params().getIndentation().inPixels(*bv_);
                }
-       
+
        return l_margin;
 }
 
@@ -2100,7 +2088,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
        // We store the begin and end pos of the selection relative to this par
        DocIterator sel_beg_par = cur.selectionBegin();
        DocIterator sel_end_par = cur.selectionEnd();
-       
+
        // We care only about visible selection.
        if (selection) {
                if (pit != sel_beg.pit()) {
@@ -2129,7 +2117,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
                        row.setSelectionAndMargins(sel_beg_par, sel_end_par);
                else
                        row.setSelection(-1, -1);
-               
+
                // The row knows nothing about the paragraph, so we have to check
                // whether this row is the first or last and update the margins.
                if (row.selection()) {
@@ -2164,7 +2152,7 @@ void TextMetrics::drawParagraph(PainterInfo & pi, pit_type pit, int x, int y) co
                        pi.pain.fillRectangle(x, y - row.ascent(),
                                width(), row.height(), pi.background_color);
                }
-               
+
                // Instrumentation for testing row cache (see also
                // 12 lines lower):
                if (lyxerr.debugging(Debug::PAINTING) && inside