Georg Baum wrote:
> Am Donnerstag, 15. Juni 2006 17:34 schrieb Juergen Spitzmueller:
> > Georg Baum wrote:
> > > You mean to change the default screen font family?
> >
> > Yes.
>
> I believe that you could simply change the family in
> BufferParams::getFont() (and maybe auditing all direct uses of
> LyXTextClass::defaultfont())

It's not as simple as that, but it's the right direction. Finally I found the 
solution, which works perfectly. It boils down to the attached changes (be 
aware: the patch won't apply, let alone compile. I stripped it down to the 
default font selection changes for your information).

> > LyX2Lyx probably needs another update to remove the scale param, if that 
> > will be implemented. I'll tell you then.
>
> I would be surprised if you were not able to do that yourself, since the
> code would be very similar to the existing conversion.

I think so, too :-)
However, I'll appreciate a quick review nevertheless.

Expect a complete, final patch soon.

Jürgen

> Georg
Index: src/buffer.C
===================================================================
--- src/buffer.C	(Revision 14117)
+++ src/buffer.C	(Arbeitskopie)
@@ -487,6 +487,7 @@ bool Buffer::readDocument(LyXLex & lex)
 	for_each(text().paragraphs().begin(),
 		 text().paragraphs().end(),
 		 bind(&Paragraph::setInsetOwner, _1, &inset()));
+	params().setDefaultFont();
 	updateBibfilesCache();
 	return res;
 }
Index: src/bufferparams.C
===================================================================
--- src/bufferparams.C	(Revision 14117)
+++ src/bufferparams.C	(Arbeitskopie)
@@ -786,16 +808,16 @@ bool BufferParams::writeLaTeX(ostream & 
 	// end of \documentclass defs
 
 	// font selection must be done before loading fontenc.sty
-	// The ae package is not needed when using OT1 font encoding.
-	if (fonts != "default" &&
-	    (fonts != "ae" || lyxrc.fontenc != "default")) {
-		os << "\\usepackage{" << fonts << "}\n";
+	string const fonts = 
+		loadFonts(features, fontsRoman, fontsSans,
+			  fontsTypewriter, fontsSC, fontsOSF);
+	if (!fonts.empty()) {
+		os << fonts;
 		texrow.newline();
-		if (fonts == "ae") {
-			os << "\\usepackage{aecompl}\n";
-			texrow.newline();
-		}
 	}
+	if (fontsDefaultFamily != "default")
+		os << "\\renewcommand{\\familydefault}{\\" 
+		   << fontsDefaultFamily << "}\n";
 	// this one is not per buffer
 	if (lyxrc.fontenc != "default") {
 		os << "\\usepackage[" << lyxrc.fontenc
@@ -1111,10 +1133,33 @@ LyXFont const BufferParams::getFont() co
 {
 	LyXFont f = getLyXTextClass().defaultfont();
 	f.setLanguage(language);
+	if (fontsDefaultFamily == "rmdefault")
+		f.setFamily(LyXFont::ROMAN_FAMILY);
+	else if (fontsDefaultFamily == "sfdefault")
+		f.setFamily(LyXFont::SANS_FAMILY);
+	else if (fontsDefaultFamily == "ttdefault")
+		f.setFamily(LyXFont::TYPEWRITER_FAMILY);
 	return f;
 }
 
 
+void BufferParams::setDefaultFont()
+{
+	//FIXME: broken
+	LyXFont f = getFont();
+
+	for (LyXTextClass::LayoutList::const_iterator it = getLyXTextClass().begin();
+			 it != getLyXTextClass().end(); ++it) {
+		LyXLayout & lay = *it->get();
+		// Resolve fonts
+		lay.resfont = lay.font;
+		lay.resfont.realize(f);
+		lay.reslabelfont = lay.labelfont;
+		lay.reslabelfont.realize(f);
+	}
+}
+
+
 void BufferParams::readPreamble(LyXLex & lex)
 {
 	if (lex.getString() != "\\begin_preamble")
Index: src/frontends/controllers/ControlDocument.C
===================================================================
--- src/frontends/controllers/ControlDocument.C	(Revision 14117)
+++ src/frontends/controllers/ControlDocument.C	(Arbeitskopie)
@@ -101,6 +104,9 @@ void ControlDocument::dispatchParams()
 
 	// Apply the BufferParams.
 	dispatch_bufferparams(kernel(), params(), LFUN_BUFFER_PARAMS_APPLY);
+	
+	// set the default Font
+	params().setDefaultFont();
 
 	// redo the numbering if necessary
 	if (new_secnumdepth != old_secnumdepth)
Index: src/bufferparams.h
===================================================================
--- src/bufferparams.h	(Revision 14117)
+++ src/bufferparams.h	(Arbeitskopie)
@@ -117,6 +117,8 @@ public:
 
 	/// returns the main font for the buffer (document)
 	LyXFont const getFont() const;
+	/// sets the main font for the buffer (document)
+	void setDefaultFont();
 
 	/* this are for the PaperLayout */
 	/// the papersize
Index: src/paragraph.C
===================================================================
--- src/paragraph.C	(Revision 14117)
+++ src/paragraph.C	(Arbeitskopie)
@@ -378,7 +378,7 @@ LyXFont const Paragraph::getFont(BufferP
 	LyXFont font = getFontSettings(bparams, pos);
 	font.realize(layoutfont);
 	font.realize(outerfont);
-	font.realize(bparams.getLyXTextClass().defaultfont());
+	font.realize(bparams.getFont());
 
 	return font;
 }
@@ -390,7 +390,7 @@ LyXFont const Paragraph::getLabelFont
 	LyXFont tmpfont = layout()->labelfont;
 	tmpfont.setLanguage(getParLanguage(bparams));
 	tmpfont.realize(outerfont);
-	tmpfont.realize(bparams.getLyXTextClass().defaultfont());
+	tmpfont.realize(bparams.getFont());
 	return tmpfont;
 }
 
@@ -401,7 +401,7 @@ LyXFont const Paragraph::getLayoutFont
 	LyXFont tmpfont = layout()->font;
 	tmpfont.setLanguage(getParLanguage(bparams));
 	tmpfont.realize(outerfont);
-	tmpfont.realize(bparams.getLyXTextClass().defaultfont());
+	tmpfont.realize(bparams.getFont());
 	return tmpfont;
 }
 
Index: src/text.C
===================================================================
--- src/text.C	(Revision 14117)
+++ src/text.C	(Arbeitskopie)
@@ -481,8 +481,8 @@ int LyXText::leftMargin(pit_type const p
 	BOOST_ASSERT(pos >= 0);
 	BOOST_ASSERT(pos <= par.size());
 	//lyxerr << "LyXText::leftMargin: pit: " << pit << " pos: " << pos << endl;
-	LyXTextClass const & tclass =
-		bv()->buffer()->params().getLyXTextClass();
+	BufferParams const & params = bv()->buffer()->params();
+	LyXTextClass const & tclass = params.getLyXTextClass();
 	LyXLayout_ptr const & layout = par.layout();
 
 	string parindent = layout->parindent;
@@ -492,7 +492,7 @@ int LyXText::leftMargin(pit_type const p
 	if (isMainText())
 		l_margin += changebarMargin();
 
-	l_margin += font_metrics::signedWidth(tclass.leftmargin(), tclass.defaultfont());
+	l_margin += font_metrics::signedWidth(tclass.leftmargin(), params.getFont());
 
 	if (par.getDepth() != 0) {
 		// find the next level paragraph
@@ -521,8 +521,8 @@ int LyXText::leftMargin(pit_type const p
 	switch (layout->margintype) {
 	case MARGIN_DYNAMIC:
 		if (!layout->leftmargin.empty())
-			l_margin += font_metrics::signedWidth(layout->leftmargin,
-						  tclass.defaultfont());
+			l_margin += font_metrics::signedWidth(layout->leftmargin, 
+					params.getFont());
 		if (!par.getLabelstring().empty()) {
 			l_margin += font_metrics::signedWidth(layout->labelindent,
 						  labelfont);
@@ -545,7 +545,7 @@ int LyXText::leftMargin(pit_type const p
 		break;
 
 	case MARGIN_STATIC:
-		l_margin += font_metrics::signedWidth(layout->leftmargin, tclass.defaultfont()) * 4
+		l_margin += font_metrics::signedWidth(layout->leftmargin, params.getFont()) * 4
 			/ (par.getDepth() + 4);
 		break;
 
@@ -592,7 +592,7 @@ int LyXText::leftMargin(pit_type const p
 			if (rit->fill() < minfill)
 				minfill = rit->fill();
 		l_margin += font_metrics::signedWidth(layout->leftmargin,
-			tclass.defaultfont());
+			params.getFont());
 		l_margin += minfill;
 #endif
 		// also wrong, but much shorter.
@@ -631,7 +631,7 @@ int LyXText::leftMargin(pit_type const p
 		|| bv()->buffer()->params().paragraph_separation ==
 		   BufferParams::PARSEP_INDENT))
 	{
-		l_margin += font_metrics::signedWidth(parindent, tclass.defaultfont());
+		l_margin += font_metrics::signedWidth(parindent, params.getFont());
 	}
 
 	return l_margin;
@@ -644,13 +644,14 @@ int LyXText::rightMargin(Paragraph const
 	if (bv()->text() != this)
 		return 0;
 
-	LyXTextClass const & tclass = bv()->buffer()->params().getLyXTextClass();
+	BufferParams const & params = bv()->buffer()->params();
+	LyXTextClass const & tclass = params.getLyXTextClass();
 	int const r_margin =
 		::rightMargin()
 		+ font_metrics::signedWidth(tclass.rightmargin(),
-					    tclass.defaultfont())
+					    params.getFont())
 		+ font_metrics::signedWidth(par.layout()->rightmargin,
-					    tclass.defaultfont())
+					    params.getFont())
 		* 4 / (par.getDepth() + 4);
 
 	return r_margin;

Reply via email to