On Mon, Jan 30, 2006 at 08:03:35PM +0100, Georg Baum wrote:
> Am Montag, 30. Januar 2006 17:20 schrieb Martin Vermeer:
 
> If I understand you correctly the workaround is to explicitly set the 
> language in the inset (and you seem to do it in the patch), so I don't 
> see this as a big problem.

Precisely.
 
> > It appears that that is not easily possible, for the above reason. I
> > would prefer 1.4 to fully honour existing 1.3 files, even if that means
> > that the user-visible behaviour changes slightly. It's illusory, after
> > the major rewriting that has happened, to precisely duplicate 1.3
> > behaviour anyway.
> 
> I agree. If you ask me, your latest patch should go in.
> 

For reference, here is the latest... only, I simplified the paragraph
stuff still a little by only adding a language argument instead of a
full bufferparams, which was overkill. And inlined the outerFontApply
method.

Lars, Jean-Marc: can this go in?

- Martin

Index: buffer.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/buffer.C,v
retrieving revision 1.630
diff -u -p -r1.630 buffer.C
--- buffer.C    29 Nov 2005 15:08:34 -0000      1.630
+++ buffer.C    26 Jan 2006 16:38:53 -0000
@@ -1307,6 +1307,9 @@ void Buffer::changeLanguage(Language con
        for_each(par_iterator_begin(),
                 par_iterator_end(),
                 bind(&Paragraph::changeLanguage, _1, params(), from, to));
+
+       text().current_font.setLanguage(to);
+       text().real_current_font.setLanguage(to);
 }
 
 
Index: lyxtext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/lyxtext.h,v
retrieving revision 1.334
diff -u -p -r1.334 lyxtext.h
--- lyxtext.h   1 Jan 2006 20:28:03 -0000       1.334
+++ lyxtext.h   26 Jan 2006 16:38:54 -0000
@@ -53,7 +53,7 @@ public:
        typedef lyx::pit_type pit_type;
 
        /// constructor
-       explicit LyXText(BufferView *);
+       explicit LyXText(BufferView *, Language const * bp = 0);
        ///
        void init(BufferView *);
 
@@ -329,6 +329,9 @@ public:
        /// delete double space or empty paragraphs around old cursor
        bool deleteEmptyParagraphMechanism(LCursor & cur, LCursor & old);
 
+       /// Get buffer's font from textclass, language from buffer parms
+       LyXFont bufferFont() const;
+
        ///
        friend class LyXScreen;
 
@@ -341,10 +344,6 @@ public:
        LyXFont current_font;
        /// the current font
        LyXFont real_current_font;
-       /// our buffer's default layout font. This is textclass specific
-       /* This is actually never initialized! Should be replaced by a
-        * defaultfont() method that looks at the textclass (easy). [JMarc]*/
-       LyXFont defaultfont_;
        ///
        int background_color_;

Index: paragraph.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.C,v
retrieving revision 1.418
diff -u -p -r1.418 paragraph.C
--- paragraph.C 30 Dec 2005 19:02:52 -0000      1.418
+++ paragraph.C 30 Jan 2006 19:54:03 -0000
@@ -356,12 +356,12 @@ FontSpan Paragraph::fontSpan(lyx::pos_ty
 
 
 // Gets uninstantiated font setting at position 0
-LyXFont const Paragraph::getFirstFontSettings() const
+LyXFont const Paragraph::getFirstFontSettings(Language const * lang) const
 {
        if (!empty() && !pimpl_->fontlist.empty())
                return pimpl_->fontlist[0].font();
 
-       return LyXFont(LyXFont::ALL_INHERIT);
+       return LyXFont(LyXFont::ALL_INHERIT, lang);
 }
 
 
@@ -1494,7 +1494,7 @@ Language const *
 Paragraph::getParLanguage(BufferParams const & bparams) const
 {
        if (!empty())
-               return getFirstFontSettings().language();
+               return getFirstFontSettings(bparams.language).language();
 #ifdef WITH_WARNINGS
 #warning FIXME we should check the prev par as well (Lgb)
 #endif
@@ -1513,7 +1513,8 @@ bool Paragraph::isRightToLeftPar(BufferP
 void Paragraph::changeLanguage(BufferParams const & bparams,
                               Language const * from, Language const * to)
 {
-       for (pos_type i = 0; i < size(); ++i) {
+       // <= to catch the dummy font change at end
+       for (pos_type i = 0; i <= size(); ++i) {
                LyXFont font = getFontSettings(bparams, i);
                if (font.language() == from) {
                        font.setLanguage(to);
@@ -1532,7 +1533,8 @@ bool Paragraph::isMultiLingual(BufferPar
        for (; cit != end; ++cit)
                if (cit->font().language() != ignore_language &&
                    cit->font().language() != latex_language &&
-                   cit->font().language() != doc_language)
+                   cit->font().language() != doc_language &&
+                   cit->font().language() != default_language)
                        return true;
        return false;
 }
Index: paragraph.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph.h,v
retrieving revision 1.159
diff -u -p -r1.159 paragraph.h
--- paragraph.h 1 Jan 2006 20:28:03 -0000       1.159
+++ paragraph.h 30 Jan 2006 19:53:07 -0000
@@ -273,7 +273,7 @@ public:
        LyXFont const
        getFontSettings(BufferParams const &, lyx::pos_type pos) const;
        ///
-       LyXFont const getFirstFontSettings() const;
+       LyXFont const getFirstFontSettings(Language const * lang) const;
 
        /** Get fully instantiated font. If pos == -1, use the layout
            font attached to this paragraph.
Index: paragraph_funcs.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/paragraph_funcs.C,v
retrieving revision 1.117
diff -u -p -r1.117 paragraph_funcs.C
--- paragraph_funcs.C   16 Jul 2005 12:02:30 -0000      1.117
+++ paragraph_funcs.C   30 Jan 2006 19:55:11 -0000
@@ -157,7 +157,8 @@ void breakParagraph(BufferParams const &
                // Make sure that we keep the language when
                // breaking paragrpah.
                if (tmp->empty()) {
-                       LyXFont changed = tmp->getFirstFontSettings();
+                       LyXFont changed =
+                           tmp->getFirstFontSettings(bparams.language);
                        LyXFont old = par.getFontSettings(bparams, par.size());
                        changed.setLanguage(old.language());
                        tmp->setFont(0, changed);
Index: rowpainter.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/rowpainter.C,v
retrieving revision 1.163
diff -u -p -r1.163 rowpainter.C
--- rowpainter.C        16 Jan 2006 15:17:17 -0000      1.163
+++ rowpainter.C        30 Jan 2006 14:21:19 -0000
@@ -306,14 +322,14 @@ void RowPainter::paintFromPos(pos_type &
 {
        pos_type const pos = text_.bidi.vis2log(vpos);
        LyXFont orig_font = text_.getFont(par_, pos);
-       text_.applyOuterFont(orig_font);
 
        double const orig_x = x_;
 
        if (par_.isInset(pos)) {
                paintInset(pos, orig_font);
                ++vpos;
-               paintForeignMark(orig_x, orig_font);
+               // Better not; confusing over insets
+               //paintForeignMark(orig_x, orig_font);
                return;
        }
 
@@ -657,7 +673,7 @@ void RowPainter::paintText()
                if (running_strikeout && (highly_editable_inset || 
!is_struckout)) {
                        // Calculate 1/3 height of the buffer's default font
                        int const middle =
-                               yo_ - 
font_metrics::maxAscent(text_.defaultfont_) / 3;
+                               yo_ - 
font_metrics::maxAscent(text_.bufferFont()) / 3;
                        pain_.line(last_strikeout_x, middle, int(x_), middle,
                                LColor::strikeout, Painter::line_solid, 
Painter::line_thin);
                        running_strikeout = false;
@@ -710,7 +726,7 @@ void RowPainter::paintText()
        if (running_strikeout) {
                // calculate 1/3 height of the buffer's default font
                int const middle =
-                       yo_ - font_metrics::maxAscent(text_.defaultfont_) / 3;
+                       yo_ - font_metrics::maxAscent(text_.bufferFont()) / 3;
                pain_.line(last_strikeout_x, middle, int(x_), middle,
                        LColor::strikeout, Painter::line_solid, 
Painter::line_thin);
                running_strikeout = false;

Index: text.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text.C,v
retrieving revision 1.639
diff -u -p -r1.639 text.C
--- text.C      19 Dec 2005 12:30:33 -0000      1.639
+++ text.C      26 Jan 2006 16:38:58 -0000
@@ -1692,16 +1692,13 @@ bool LyXText::redoParagraph(pit_type con
        // redo insets
        // FIXME: We should always use getFont(), see documentation of
        // noFontChange() in insetbase.h.
-       LyXFont const tclassfont =
-               bv()->buffer()->params().getLyXTextClass().defaultfont();
        InsetList::iterator ii = par.insetlist.begin();
        InsetList::iterator iend = par.insetlist.end();
        for (; ii != iend; ++ii) {
                Dimension dim;
                int const w = maxwidth_ - leftMargin(pit, ii->pos) - 
rightMargin(par);
                LyXFont const & font = ii->inset->noFontChange() ?
-                       tclassfont :
-                       getFont(par, ii->pos);
+                       bufferFont() : getFont(par, ii->pos);
                MetricsInfo mi(bv(), font, w);
                ii->inset->metrics(mi, dim);
        }
@@ -2201,8 +2198,9 @@ string LyXText::currentState(LCursor & c
 
        // I think we should only show changes from the default
        // font. (Asger)
+       // No, from the document font (MV)
        LyXFont font = real_current_font;
-       font.reduce(buf.params().getLyXTextClass().defaultfont());
+       font.reduce(bufferFont());
 
        // avoid _(...) re-entrance problem
        string const s = font.stateText(&buf.params());
Index: text2.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text2.C,v
retrieving revision 1.639
diff -u -p -r1.639 text2.C
--- text2.C     28 Jan 2006 12:39:22 -0000      1.639
+++ text2.C     30 Jan 2006 18:28:09 -0000
@@ -66,9 +66,11 @@ using std::string;
 using std::min;
 
 
-LyXText::LyXText(BufferView * bv)
+LyXText::LyXText(BufferView * bv, Language const * lang)
        : maxwidth_(bv ? bv->workWidth() : 100),
-         current_font(LyXFont::ALL_INHERIT),
+         current_font(LyXFont::ALL_INHERIT,
+               ( bv ? bv->buffer()->params().language 
+                       : (lang ? lang : default_language))),
          background_color_(LColor::background),
          bv_owner(bv),
          autoBreakRows_(false)
@@ -170,8 +172,9 @@ LyXFont LyXText::getFont(Paragraph const
        // We specialize the 95% common case:
        if (!par.getDepth()) {
                LyXFont f = par.getFontSettings(params, pos);
+               // Here the external font of an inset is brought in:
                if (!isMainText())
-                       applyOuterFont(f);
+                       f.realize(font_);
                if (layout->labeltype == LABEL_MANUAL && pos < body_pos)
                        return f.realize(layout->reslabelfont);
                else
@@ -188,8 +191,9 @@ LyXFont LyXText::getFont(Paragraph const
        LyXFont font = par.getFontSettings(params, pos);
        font.realize(layoutfont);
 
+       // Here the external font of an inset is brought in:
        if (!isMainText())
-               applyOuterFont(font);
+               font.realize(font_);
 
        // Find the pit value belonging to paragraph. This will not break 
        // even if pars_ would not be a vector anymore.
@@ -206,26 +210,11 @@ LyXFont LyXText::getFont(Paragraph const
                font.realize(outerFont(pit, pars_));
 
        // Realize with the fonts of lesser depth.
-       font.realize(defaultfont_);
+       font.realize(bufferFont());
 
        return font;
 }
 
-// There are currently two font mechanisms in LyX:
-// 1. The font attributes in a lyxtext, and
-// 2. The inset-specific font properties, defined in an inset's
-// metrics() and draw() methods and handed down the inset chain through
-// the pi/mi parameters, and stored locally in a lyxtext in font_.
-// This is where the two are integrated in the final fully realized
-// font.
-void LyXText::applyOuterFont(LyXFont & font) const {
-       LyXFont lf(font_);
-       lf.reduce(defaultfont_);
-       lf.realize(font);
-       lf.setLanguage(font.language());
-       font = lf;
-}
-
 
 LyXFont LyXText::getLayoutFont(pit_type const pit) const
 {
@@ -237,7 +226,7 @@ LyXFont LyXText::getLayoutFont(pit_type 
        LyXFont font = layout->font;
        // Realize with the fonts of lesser depth.
        //font.realize(outerFont(pit, paragraphs()));
-       font.realize(defaultfont_);
+       font.realize(bufferFont());
 
        return font;
 }
@@ -252,7 +241,7 @@ LyXFont LyXText::getLabelFont(Paragraph 
 
        LyXFont font = layout->labelfont;
        // Realize with the fonts of lesser depth.
-       font.realize(defaultfont_);
+       font.realize(bufferFont());
 
        return font;
 }
@@ -288,7 +277,7 @@ void LyXText::setCharFont(pit_type pit, 
        if (!isMainText())
                layoutfont.realize(font_);
 
-       layoutfont.realize(defaultfont_);
+       layoutfont.realize(bufferFont());
 
        // Now, reduce font against full layout font
        font.reduce(layoutfont);
@@ -1281,6 +1275,16 @@ bool LyXText::deleteEmptyParagraphMechan
 
        return false;
 }
+
+
+LyXFont LyXText::bufferFont() const
+{
+       LyXFont font =
+               bv()->buffer()->params().getLyXTextClass().defaultfont();
+       font.setLanguage(bv()->buffer()->params().language);
+       return font;
+}
+
 
 
 void LyXText::recUndo(pit_type first, pit_type last) const
Index: text3.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/text3.C,v
retrieving revision 1.323
diff -u -p -r1.323 text3.C
--- text3.C     31 Dec 2005 11:40:32 -0000      1.323
+++ text3.C     26 Jan 2006 16:39:00 -0000
@@ -1114,12 +1122,6 @@ void LyXText::dispatch(LCursor & cur, Fu
                cur.clearSelection();
                LyXFont const old_font = real_current_font;
 
-               // Prevents language turds in new lyxtexts under non-english
-               BufferParams const & bufparams = cur.buffer().params();
-               Language const * lang = 
cur.paragraph().getParLanguage(bufparams);
-               current_font.setLanguage(lang);
-               real_current_font.setLanguage(lang);
-
                string::const_iterator cit = cmd.argument.begin();
                string::const_iterator end = cmd.argument.end();
                for (; cit != end; ++cit)
Index: insets/insetcharstyle.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcharstyle.C,v
retrieving revision 1.39
diff -u -p -r1.39 insetcharstyle.C
--- insets/insetcharstyle.C     25 Nov 2005 14:40:32 -0000      1.39
+++ insets/insetcharstyle.C     26 Jan 2006 16:39:01 -0000
@@ -135,8 +136,9 @@ void InsetCharStyle::metrics(MetricsInfo
 {
        LyXFont tmpfont = mi.base.font;
        getDrawFont(mi.base.font);
-       mi.base.font.reduce(LyXFont(LyXFont::ALL_SANE));
        mi.base.font.realize(tmpfont);
+       // Needed to propagate doc language (infamous blueline)
+       mi.base.font.setLanguage(tmpfont.language());
        mi.base.textwidth -= 2 * TEXT_TO_INSET_OFFSET;
        InsetText::metrics(mi, dim);
        mi.base.font = tmpfont;
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.623
diff -u -p -r1.623 insettext.C
--- insets/insettext.C  11 Jan 2006 14:22:10 -0000      1.623
+++ insets/insettext.C  26 Jan 2006 16:39:03 -0000
@@ -74,12 +74,16 @@ int InsetText::border_ = 2;
 
 
 InsetText::InsetText(BufferParams const & bp)
-       : drawFrame_(false), frame_color_(LColor::insetframe), text_(0)
+       : drawFrame_(false), frame_color_(LColor::insetframe), 
+               text_(0, bp.language)
 {
        paragraphs().push_back(Paragraph());
        paragraphs().back().layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
                paragraphs().back().trackChanges();
+       // Dispose of the infamous L-shaped cursor.
+       text_.current_font.setLanguage(bp.language);
+       text_.real_current_font.setLanguage(bp.language);
        init();
 }
 
@@ -91,6 +95,10 @@ InsetText::InsetText(InsetText const & i
        drawFrame_ = in.drawFrame_;
        frame_color_ = in.frame_color_;
        text_.paragraphs() = in.text_.paragraphs();
+       // Hand current buffer language down to "cloned" textinsets 
+       // e.g. tabular cells
+       text_.current_font = in.text_.current_font;
+       text_.real_current_font = in.text_.real_current_font;
        init();
 }
 

Attachment: pgpNkMo7jy13z.pgp
Description: PGP signature

Reply via email to