Jean-Marc Lasgouttes wrote:

> I do not know actually. I do not have a good understanding of what
> 1.3.x did.
> 
> Setting the default font from the context just before computing
> metrics is reasonable, since the fonts contained in a paragraph are
> always relative to a base font. Therefore, it does not seem outrageous
> to me to set this value in the metrics call. However, as you point
> out, this is not valid for all insets. Would a good solution be to put
> this code in the metrics() method of InsetTabular (that is, set the
> font of all cells)?

Actually, I think it's a bit more complicated: even if we don't inherit, we
still have to alter the metricsinfo struct to pass down our own font
(because child insets that *do* inherit should inherit ours, not our parent
font).

What about the attached? It adds a bool inherit_font_ to InsetText and
change a couple of ctors, and use this flag on InsetText::metrics.

Alfredo
Index: tabular.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/tabular.C,v
retrieving revision 1.215
diff -u -p -u -r1.215 tabular.C
--- tabular.C	2 Nov 2004 11:25:17 -0000	1.215
+++ tabular.C	11 Nov 2004 09:57:20 -0000
@@ -296,7 +296,7 @@ void l_getline(istream & is, string & st
 /// Define a few methods for the inner structs
 
 LyXTabular::cellstruct::cellstruct(BufferParams const & bp)
-	: inset(bp)
+	: inset(bp, true)
 {
 	cellno = 0;
 	width_of_cell = 0;
Index: insets/insetbranch.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetbranch.C,v
retrieving revision 1.49
diff -u -p -u -r1.49 insetbranch.C
--- insets/insetbranch.C	5 Oct 2004 10:11:41 -0000	1.49
+++ insets/insetbranch.C	11 Nov 2004 09:57:20 -0000
@@ -41,7 +41,7 @@ void InsetBranch::init()
 
 InsetBranch::InsetBranch(BufferParams const & bp,
 			 InsetBranchParams const & params)
-	: InsetCollapsable(bp), params_(params)
+	: InsetCollapsable(bp, InsetCollapsable::Open, true), params_(params)
 {
 	init();
 }
Index: insets/insetcollapsable.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.C,v
retrieving revision 1.261
diff -u -p -u -r1.261 insetcollapsable.C
--- insets/insetcollapsable.C	11 Nov 2004 08:18:30 -0000	1.261
+++ insets/insetcollapsable.C	11 Nov 2004 09:57:20 -0000
@@ -51,8 +51,9 @@ void leaveInset(LCursor & cur, InsetBase
 
 
 InsetCollapsable::InsetCollapsable(BufferParams const & bp,
-	CollapseStatus status)
-	: InsetText(bp), label("Label"), status_(status), openinlined_(false)
+	CollapseStatus status, bool infont)
+	: InsetText(bp, infont), label("Label"),
+	  status_(status), openinlined_(false)
 {
 	setAutoBreakRows(true);
 	setDrawFrame(true);
Index: insets/insetcollapsable.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insetcollapsable.h,v
retrieving revision 1.177
diff -u -p -u -r1.177 insetcollapsable.h
--- insets/insetcollapsable.h	13 Aug 2004 19:14:14 -0000	1.177
+++ insets/insetcollapsable.h	11 Nov 2004 09:57:21 -0000
@@ -41,7 +41,8 @@ public:
 		Open
 	};
 	///
-	InsetCollapsable(BufferParams const &, CollapseStatus status = Open);
+	InsetCollapsable(BufferParams const &, CollapseStatus status = Open,
+			 bool inherit_font_ = true);
 	///
 	void read(Buffer const &, LyXLex &);
 	///
Index: insets/insettext.C
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.C,v
retrieving revision 1.598
diff -u -p -u -r1.598 insettext.C
--- insets/insettext.C	24 Oct 2004 00:02:39 -0000	1.598
+++ insets/insettext.C	11 Nov 2004 09:57:21 -0000
@@ -68,9 +68,10 @@ using std::ostream;
 using std::vector;
 
 
-InsetText::InsetText(BufferParams const & bp)
+InsetText::InsetText(BufferParams const & bp, bool infont)
 	: autoBreakRows_(false), drawFrame_(false),
-	  frame_color_(LColor::insetframe), text_(0)
+	  frame_color_(LColor::insetframe),
+	  inherit_font_(infont), text_(0)
 {
 	paragraphs().push_back(Paragraph());
 	paragraphs().back().layout(bp.getLyXTextClass().defaultLayout());
@@ -100,6 +101,7 @@ void InsetText::operator=(InsetText cons
 	frame_color_ = in.frame_color_;
 	text_ = LyXText(in.text_.bv_owner);
 	text_.paragraphs() = in.text_.paragraphs();
+	inherit_font_ = in.inherit_font_;
 	init();
 }
 
@@ -180,10 +182,16 @@ void InsetText::metrics(MetricsInfo & mi
 {
 	//lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
 	setViewCache(mi.base.bv);
-	text_.metrics(mi, dim);
+	if (inherit_font_) {
+		text_.font_ = mi.base.font;
+		text_.metrics(mi, dim);
+	} else {
+		LyXFont const f = mi.base.font;
+		mi.base.font = text_.font_;
+		text_.metrics(mi, dim);
+		mi.base.font = f;
+	}
 	dim_ = dim;
-	font_ = mi.base.font;
-	text_.font_ = mi.base.font;
 }
 
 
Index: insets/insettext.h
===================================================================
RCS file: /usr/local/lyx/cvsroot/lyx-devel/src/insets/insettext.h,v
retrieving revision 1.262
diff -u -p -u -r1.262 insettext.h
--- insets/insettext.h	16 Aug 2004 00:32:04 -0000	1.262
+++ insets/insettext.h	11 Nov 2004 09:57:21 -0000
@@ -39,7 +39,7 @@ class Row;
 class InsetText : public UpdatableInset {
 public:
 	///
-	explicit InsetText(BufferParams const &);
+	explicit InsetText(BufferParams const &, bool inherit_font = false);
 	///
 	explicit InsetText();
 	///
@@ -168,11 +168,11 @@ private:
 	 */
 	int frame_color_;
 	///
+	bool inherit_font_;
+	///
 	mutable lyx::par_type old_par;
 public:
 	///
 	mutable LyXText text_;
-	///
-	mutable LyXFont font_;
 };
 #endif

Reply via email to