]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
SCons: msvc does not need this /TP option any more after we rename .C => .cpp. Also...
[lyx.git] / src / Text.cpp
index abd71961a68822cd04248846a84cafc51042a880..61467dc207a7a05a84927a0efafa8c14912c714e 100644 (file)
@@ -361,41 +361,6 @@ double Text::spacing(Buffer const & buffer,
 }
 
 
-int Text::singleWidth(Buffer const & buffer, Paragraph const & par,
-               pos_type pos) const
-{
-       return singleWidth(par, pos, par.getChar(pos),
-               getFont(buffer, par, pos));
-}
-
-
-int Text::singleWidth(Paragraph const & par,
-                        pos_type pos, char_type c, Font const & font) const
-{
-       // The most common case is handled first (Asger)
-       if (isPrintable(c)) {
-               Language const * language = font.language();
-               if (language->rightToLeft()) {
-                       if (language->lang() == "arabic_arabtex" ||
-                               language->lang() == "arabic_arabi" ||
-                           language->lang() == "farsi") {
-                               if (Encodings::isComposeChar_arabic(c))
-                                       return 0;
-                               c = par.transformChar(c, pos);
-                       } else if (language->lang() == "hebrew" &&
-                                  Encodings::isComposeChar_hebrew(c))
-                               return 0;
-               }
-               return theFontMetrics(font).width(c);
-       }
-
-       if (c == Paragraph::META_INSET)
-               return par.getInset(pos)->width();
-
-       return theFontMetrics(font).width(c);
-}
-
-
 int Text::leftMargin(Buffer const & buffer, int max_width, pit_type pit) const
 {
        BOOST_ASSERT(pit >= 0);
@@ -416,16 +381,15 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
        TextClass const & tclass = buffer.params().getTextClass();
        Layout_ptr const & layout = par.layout();
 
-       string parindent = layout->parindent;
+       docstring parindent = layout->parindent;
 
        int l_margin = 0;
 
        if (isMainText(buffer))
                l_margin += changebarMargin();
 
-       // FIXME UNICODE
-       docstring leftm = from_utf8(tclass.leftmargin());
-       l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
+       l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
+               tclass.leftmargin());
 
        if (par.getDepth() != 0) {
                // find the next level paragraph
@@ -456,55 +420,41 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
        switch (layout->margintype) {
        case MARGIN_DYNAMIC:
                if (!layout->leftmargin.empty()) {
-                       // FIXME UNICODE
-                       docstring leftm = from_utf8(layout->leftmargin);
-                       l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm);
+                       l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
+                               layout->leftmargin);
                }
                if (!par.getLabelstring().empty()) {
-                       // FIXME UNICODE
-                       docstring labin = from_utf8(layout->labelindent);
-                       l_margin += labelfont_metrics.signedWidth(labin);
-                       docstring labstr = par.getLabelstring();
-                       l_margin += labelfont_metrics.width(labstr);
-                       docstring labsep = from_utf8(layout->labelsep);
-                       l_margin += labelfont_metrics.width(labsep);
+                       l_margin += labelfont_metrics.signedWidth(layout->labelindent);
+                       l_margin += labelfont_metrics.width(par.getLabelstring());
+                       l_margin += labelfont_metrics.width(layout->labelsep);
                }
                break;
 
        case MARGIN_MANUAL: {
-               // FIXME UNICODE
-               docstring labin = from_utf8(layout->labelindent);
-               l_margin += labelfont_metrics.signedWidth(labin);
+               l_margin += labelfont_metrics.signedWidth(layout->labelindent);
                // The width of an empty par, even with manual label, should be 0
                if (!par.empty() && pos >= par.beginOfBody()) {
                        if (!par.getLabelWidthString().empty()) {
                                docstring labstr = par.getLabelWidthString();
                                l_margin += labelfont_metrics.width(labstr);
-                               docstring labsep = from_utf8(layout->labelsep);
-                               l_margin += labelfont_metrics.width(labsep);
+                               l_margin += labelfont_metrics.width(layout->labelsep);
                        }
                }
                break;
        }
 
        case MARGIN_STATIC: {
-               // FIXME UNICODE
-               docstring leftm = from_utf8(layout->leftmargin);
-               l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(leftm)
-                       * 4     / (par.getDepth() + 4);
+               l_margin += theFontMetrics(buffer.params().getFont()).
+                       signedWidth(layout->leftmargin) * 4     / (par.getDepth() + 4);
                break;
        }
 
        case MARGIN_FIRST_DYNAMIC:
                if (layout->labeltype == LABEL_MANUAL) {
                        if (pos >= par.beginOfBody()) {
-                               // FIXME UNICODE
-                               l_margin += labelfont_metrics.signedWidth(
-                                       from_utf8(layout->leftmargin));
+                               l_margin += labelfont_metrics.signedWidth(layout->leftmargin);
                        } else {
-                               // FIXME UNICODE
-                               l_margin += labelfont_metrics.signedWidth(
-                                       from_utf8(layout->labelindent));
+                               l_margin += labelfont_metrics.signedWidth(layout->labelindent);
                        }
                } else if (pos != 0
                           // Special case to fix problems with
@@ -512,14 +462,13 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
                           || (layout->labeltype == LABEL_STATIC
                               && layout->latextype == LATEX_ENVIRONMENT
                               && !isFirstInSequence(pit, pars_))) {
-                       // FIXME UNICODE
-                       l_margin += labelfont_metrics.signedWidth(from_utf8(layout->leftmargin));
+                       l_margin += labelfont_metrics.signedWidth(layout->leftmargin);
                } else if (layout->labeltype != LABEL_TOP_ENVIRONMENT
                           && layout->labeltype != LABEL_BIBLIO
                           && layout->labeltype !=
                           LABEL_CENTERED_TOP_ENVIRONMENT) {
-                       l_margin += labelfont_metrics.signedWidth(from_utf8(layout->labelindent));
-                       l_margin += labelfont_metrics.width(from_utf8(layout->labelsep));
+                       l_margin += labelfont_metrics.signedWidth(layout->labelindent);
+                       l_margin += labelfont_metrics.width(layout->labelsep);
                        l_margin += labelfont_metrics.width(par.getLabelstring());
                }
                break;
@@ -574,8 +523,8 @@ int Text::leftMargin(Buffer const & buffer, int max_width,
                || buffer.params().paragraph_separation ==
                   BufferParams::PARSEP_INDENT))
        {
-               docstring din = from_utf8(parindent);
-               l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(din);
+               l_margin += theFontMetrics(buffer.params().getFont()).signedWidth(
+                       parindent);
        }
 
        return l_margin;
@@ -1364,7 +1313,7 @@ bool Text::backspace(Cursor & cur)
 bool Text::dissolveInset(Cursor & cur) {
        BOOST_ASSERT(this == cur.text());
 
-       if (isMainText(*cur.bv().buffer()) || cur.inset().nargs() != 1)
+       if (isMainText(cur.bv().buffer()) || cur.inset().nargs() != 1)
                return false;
 
        recordUndoInset(cur);
@@ -1500,7 +1449,7 @@ void Text::drawRowSelection(PainterInfo & pi, int x, Row const & row,
                                                                                                                bool drawOnBegMargin, bool drawOnEndMargin) const
 {
        BufferView & bv = *pi.base.bv;
-       Buffer & buffer = *bv.buffer();
+       Buffer & buffer = bv.buffer();
        TextMetrics const & tm = bv.textMetrics(this);
        DocIterator cur = beg;
        int x1 = cursorX(bv, beg.top(), beg.boundary());
@@ -1713,7 +1662,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
 
        pos_type cursor_vpos = 0;
 
-       Buffer const & buffer = *bv.buffer();
+       Buffer const & buffer = bv.buffer();
        RowMetrics const m = tm.computeRowMetrics(pit, row);
        double x = m.x;
        Bidi bidi;
@@ -1749,8 +1698,6 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
        // Use font span to speed things up, see below
        FontSpan font_span;
        Font font;
-       FontMetrics const & labelfm = theFontMetrics(
-               getLabelFont(buffer, par));
 
        // If the last logical character is a separator, skip it, unless
        // it's in the last row of a paragraph; see skipped_sep_vpos declaration
@@ -1763,11 +1710,11 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
                        continue;
                pos_type pos = bidi.vis2log(vpos);
                if (body_pos > 0 && pos == body_pos - 1) {
-                       // FIXME UNICODE
-                       docstring const lsep = from_utf8(par.layout()->labelsep);
-                       x += m.label_hfill + labelfm.width(lsep);
+                       FontMetrics const & labelfm = theFontMetrics(
+                               getLabelFont(buffer, par));
+                       x += m.label_hfill + labelfm.width(par.layout()->labelsep);
                        if (par.isLineSeparator(body_pos - 1))
-                               x -= singleWidth(buffer, par, body_pos - 1);
+                               x -= tm.singleWidth(pit, body_pos - 1);
                }
 
                // Use font span to speed things up, see above
@@ -1776,7 +1723,7 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
                        font = getFont(buffer, par, pos);
                }
 
-               x += singleWidth(par, pos, par.getChar(pos), font);
+               x += pm.singleWidth(pos, font);
 
                if (par.hfillExpansion(row, pos))
                        x += (pos >= body_pos) ? m.hfill : m.label_hfill;
@@ -1787,9 +1734,9 @@ int Text::cursorX(BufferView const & bv, CursorSlice const & sl,
        // see correction above
        if (boundary_correction) {
                if (isRTL(buffer, sl, boundary))
-                       x -= singleWidth(buffer, par, ppos);
+                       x -= tm.singleWidth(pit, ppos);
                else
-                       x += singleWidth(buffer, par, ppos);
+                       x += tm.singleWidth(pit, ppos);
        }
 
        return int(x);