Attached is what I have done to start XeTeX support in LyX. What it currently 
does, is:

* check and configure xetex.
* provide a basic xetex backend (with its own output flavor XETEX)
* provide a simple checkbox "use XeTeX" in Document>Settings
* if this is selected,
        - set the correct encoding (utf-8)
        - load the fundamental XeTeX packages
        - provide the proper output and export formats (i.e., only "PDF (XeTeX)"
          if XeTeX is chosen, and no "PDF (XeTeX)", if XeTeX isn't selected)
        - let you chose system fonts in Document>Settings>Fonts. OSF is 
supported.

From my tests, it appears to work at least for medio-complex documents. I 
could process the Tutorial with several system fonts, including "Manuskript 
Gotisch", a blackletter font that made the Tutorial look "interesting".

What is (yet) missing:

* more fine-grained XeTeX support. For instance, I did not implement support 
for polyglossia, XeTeX's babel successor. The XeTeX documents work with babel, 
but polyglossia support should probably be added eventually. I'm sure there 
are more packages that need to be considered.

* lyx2lyx. I have bumped the file version, but reversion does not do anything 
yet. I guess it should set the encoding to utf8-plain and insert the packages 
to the preamble. Probably easy to implement

* some of my system fonts make XeTeX fail. I guess we cannot do anything about 
that, but maybe we could implement some kind of helpful error message in that 
case

* font properties such as OSF ("old style figures") are currently always 
enabled, even if a font does not include this feature (with the result that, 
for instance, not the desired figures appear in the output). I don't know if 
there is a way to detect whether a font supports a given feature (maybe the Qt 
font database helps).

* toolbar support. Currently, there's no xetex button (only a menu item). I 
think we should show it only if xetex is selected and hide the other buttons 
then. Or even better, implement one button for the "default" output format.

* better UI

* much testing ...

Since I do not use (nor intend to use) XeTeX myself (and consequently, I am 
only superficially familiar with XeTeX) and since my time is limited, I 
propose to put this to trunk, provided that someone volunteers to test and 
polish the feature. XeTeX is frequently requested nowadays, so I think it 
would be a valuable feature of 2.0. However, as said, I am not very interested 
in it personally, so I won't put too much time in it.

Opinions?

Jürgen

Index: development/FORMAT
===================================================================
--- development/FORMAT	(Revision 29100)
+++ development/FORMAT	(Arbeitskopie)
@@ -1,6 +1,9 @@
 LyX file-format changes
 -----------------------
 
+2009-04-05 Jürgen Spitzmüller <sp...@lyx.org>
+	* Format incremented to 349: initial support for XeTeX.
+
 2009-01-30 Uwe Stöhr <uwesto...@web.de>
 	* Format incremented to 348: support for \*phantom.
 
Index: lib/lyx2lyx/lyx_2_0.py
===================================================================
--- lib/lyx2lyx/lyx_2_0.py	(Revision 29100)
+++ lib/lyx2lyx/lyx_2_0.py	(Arbeitskopie)
@@ -186,10 +186,12 @@
 supported_versions = ["2.0.0","2.0"]
 convert = [[346, []],
            [347, []],
-           [348, []]
+           [348, []],
+           [349, []]
           ]
 
-revert =  [[347, [revert_phantom, revert_hphantom, revert_vphantom]],
+revert =  [[348, []],
+           [347, [revert_phantom, revert_hphantom, revert_vphantom]],
            [346, [revert_tabularvalign]],
            [345, [revert_swiss]]
           ]
Index: lib/configure.py
===================================================================
--- lib/configure.py	(Revision 29100)
+++ lib/configure.py	(Arbeitskopie)
@@ -291,6 +291,7 @@
 \Format lilypond   ly     "LilyPond music"        "" ""	"%%"	"vector"
 \Format latex      tex    "LaTeX (plain)"         L  ""	"%%"	"document"
 \Format pdflatex   tex    "LaTeX (pdflatex)"      "" ""	"%%"	"document"
+\Format xetex      tex    "LaTeX (XeTeX)"         "" ""	"%%"	"document"
 \Format text       txt    "Plain text"            a  ""	"%%"	"document"
 \Format text2      txt    "Plain text (pstotext)" "" ""	"%%"	"document"
 \Format text3      txt    "Plain text (ps2ascii)" "" ""	"%%"	"document"
@@ -314,7 +315,8 @@
 		    'gv', 'ghostview'],
         rc_entry = [r'''\Format pdf        pdf    "PDF (ps2pdf)"          P  "%%"	""	"document,vector"
 \Format pdf2       pdf    "PDF (pdflatex)"        F  "%%"	""	"document,vector"
-\Format pdf3       pdf    "PDF (dvipdfm)"         m  "%%"	""	"document,vector"'''])
+\Format pdf3       pdf    "PDF (dvipdfm)"         m  "%%"	""	"document,vector"
+\Format pdf4       pdf    "PDF (XeTeX)"           X  "%%"	""	"document,vector"'''])
     #
     checkViewer('a DVI previewer', ['xdvi', 'kdvi'],
         rc_entry = [r'\Format dvi        dvi     DVI                    D  "%%"	""	"document,vector"'])
@@ -361,6 +363,9 @@
     ''' Check all converters (\converter entries) '''
     checkProg('the pdflatex program', ['pdflatex $$i'],
         rc_entry = [ r'\converter pdflatex   pdf2       "%%"	"latex"' ])
+
+    checkProg('XeTeX', ['xelatex $$i'],
+        rc_entry = [ r'\converter xetex      pdf4       "%%"	"latex"' ])
     
     ''' If we're running LyX in-place then tex2lyx will be found in
             ../src/tex2lyx. Add this directory to the PATH temporarily and
Index: src/BufferParams.h
===================================================================
--- src/BufferParams.h	(Revision 29100)
+++ src/BufferParams.h	(Arbeitskopie)
@@ -189,6 +189,8 @@
 	std::string fontsTypewriter;
 	/// the default family (rm, sf, tt)
 	std::string fontsDefaultFamily;
+	/// use the XeTeX processor
+	bool useXetex;
 	/// use expert Small Caps
 	bool fontsSC;
 	/// use Old Style Figures
@@ -313,11 +315,14 @@
 	/// handle inputenc etc.
 	void writeEncodingPreamble(odocstream & os, LaTeXFeatures & features,
 					      TexRow & texrow) const;
+	///
+	std::string const parseFontName(std::string const & name) const;
 	/// set up the document fonts
 	std::string const loadFonts(std::string const & rm,
 				     std::string const & sf, std::string const & tt,
 				     bool const & sc, bool const & osf,
-				     int const & sfscale, int const & ttscale) const;
+				     int const & sfscale, int const & ttscale,
+				     bool const & xetex) const;
 
 	/// get the appropriate cite engine (natbib handling)
 	CiteEngine citeEngine() const;
Index: src/Converter.cpp
===================================================================
--- src/Converter.cpp	(Revision 29100)
+++ src/Converter.cpp	(Arbeitskopie)
@@ -256,6 +256,8 @@
 		if (conv.latex)
 			if (contains(conv.to, "pdf"))
 				return OutputParams::PDFLATEX;
+			else if (contains(conv.to, "XeTeX"))
+				return OutputParams::XETEX;
 		if (conv.xml)
 			return OutputParams::XML;
 	}
Index: src/OutputParams.h
===================================================================
--- src/OutputParams.h	(Revision 29100)
+++ src/OutputParams.h	(Arbeitskopie)
@@ -32,6 +32,7 @@
 	enum FLAVOR {
 		LATEX,
 		PDFLATEX,
+		XETEX,
 		XML
 	};
 
Index: src/frontends/qt4/GuiDocument.h
===================================================================
--- src/frontends/qt4/GuiDocument.h	(Revision 29100)
+++ src/frontends/qt4/GuiDocument.h	(Arbeitskopie)
@@ -69,6 +69,7 @@
 
 	void paramsToDialog();
 	void updateFontsize(std::string const &, std::string const &);
+	void updateFontlist();
 	void updatePagestyle(std::string const &, std::string const &);
 
 	void showPreamble();
@@ -97,7 +98,7 @@
 	void classChanged();
 	void updateModuleInfo();
 	void modulesChanged();
-
+	void xetexChanged(bool);
 private:
 	/// validate listings parameters and return an error message, if any
 	QString validateListingsParameters();
@@ -185,7 +186,7 @@
 	std::list<modInfoStruct> const & getModuleInfo();
 	/// Modules in use in current buffer
 	std::list<modInfoStruct> const getSelectedModules();
- 	///
+	///
 	std::list<modInfoStruct> const getProvidedModules();
 	///
 	std::list<modInfoStruct> const 
Index: src/frontends/qt4/GuiDocument.cpp
===================================================================
--- src/frontends/qt4/GuiDocument.cpp	(Revision 29100)
+++ src/frontends/qt4/GuiDocument.cpp	(Arbeitskopie)
@@ -54,6 +54,7 @@
 
 #include <QAbstractItemModel>
 #include <QCloseEvent>
+#include <QFontDatabase>
 #include <QScrollBar>
 #include <QTextCursor>
 
@@ -610,25 +611,12 @@
 		this, SLOT(change_adaptor()));
 	connect(fontModule->fontOsfCB, SIGNAL(clicked()),
 		this, SLOT(change_adaptor()));
+	connect(fontModule->xetexCB, SIGNAL(clicked()),
+		this, SLOT(change_adaptor()));
+	connect(fontModule->xetexCB, SIGNAL(toggled(bool)),
+		this, SLOT(xetexChanged(bool)));
 
-	for (int n = 0; tex_fonts_roman[n][0]; ++n) {
-		QString font = qt_(tex_fonts_roman_gui[n]);
-		if (!isFontAvailable(tex_fonts_roman[n]))
-			font += qt_(" (not installed)");
-		fontModule->fontsRomanCO->addItem(font);
-	}
-	for (int n = 0; tex_fonts_sans[n][0]; ++n) {
-		QString font = qt_(tex_fonts_sans_gui[n]);
-		if (!isFontAvailable(tex_fonts_sans[n]))
-			font += qt_(" (not installed)");
-		fontModule->fontsSansCO->addItem(font);
-	}
-	for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
-		QString font = qt_(tex_fonts_monospaced_gui[n]);
-		if (!isFontAvailable(tex_fonts_monospaced[n]))
-			font += qt_(" (not installed)");
-		fontModule->fontsTypewriterCO->addItem(font);
-	}
+	updateFontlist();
 
 	fontModule->fontsizeCO->addItem(qt_("Default"));
 	fontModule->fontsizeCO->addItem(qt_("10"));
@@ -1090,11 +1078,13 @@
 		setSkip(textLayoutModule->skipCO->currentIndex());
 }
 
+
 void GuiDocument::portraitChanged()
 {
 	setMargins(pageLayoutModule->papersizeCO->currentIndex());
 }
 
+
 void GuiDocument::setMargins(bool custom)
 {
 	bool const extern_geometry =
@@ -1168,6 +1158,16 @@
 }
 
 
+void GuiDocument::xetexChanged(bool xetex)
+{
+	updateFontlist();
+	langModule->encodingCO->setEnabled(!xetex &&
+		!langModule->defaultencodingRB->isChecked());
+	langModule->defaultencodingRB->setEnabled(!xetex);
+	langModule->otherencodingRB->setEnabled(!xetex);
+}
+
+
 void GuiDocument::updateFontsize(string const & items, string const & sel)
 {
 	fontModule->fontsizeCO->clear();
@@ -1186,8 +1186,55 @@
 }
 
 
+void GuiDocument::updateFontlist()
+{
+	fontModule->fontsRomanCO->clear();
+	fontModule->fontsSansCO->clear();
+	fontModule->fontsTypewriterCO->clear();
+
+	// With XeTeX, we have access to all system fonts, but not the LaTeX fonts
+	if (fontModule->xetexCB->isChecked()) {
+		fontModule->fontsRomanCO->addItem(qt_("Default"));
+		fontModule->fontsSansCO->addItem(qt_("Default"));
+		fontModule->fontsTypewriterCO->addItem(qt_("Default"));
+	
+		QFontDatabase fontdb;
+		QStringList families(fontdb.families());
+		for (QStringList::Iterator it = families.begin(); it != families.end(); ++it) {
+			fontModule->fontsRomanCO->addItem(*it);
+			fontModule->fontsSansCO->addItem(*it);
+			fontModule->fontsTypewriterCO->addItem(*it);
+		}
+		return;
+	}
+
+	for (int n = 0; tex_fonts_roman[n][0]; ++n) {
+		QString font = qt_(tex_fonts_roman_gui[n]);
+		if (!isFontAvailable(tex_fonts_roman[n]))
+			font += qt_(" (not installed)");
+		fontModule->fontsRomanCO->addItem(font);
+	}
+	for (int n = 0; tex_fonts_sans[n][0]; ++n) {
+		QString font = qt_(tex_fonts_sans_gui[n]);
+		if (!isFontAvailable(tex_fonts_sans[n]))
+			font += qt_(" (not installed)");
+		fontModule->fontsSansCO->addItem(font);
+	}
+	for (int n = 0; tex_fonts_monospaced[n][0]; ++n) {
+		QString font = qt_(tex_fonts_monospaced_gui[n]);
+		if (!isFontAvailable(tex_fonts_monospaced[n]))
+			font += qt_(" (not installed)");
+		fontModule->fontsTypewriterCO->addItem(font);
+	}
+}
+
+
 void GuiDocument::romanChanged(int item)
 {
+	if (fontModule->xetexCB->isChecked()) {
+		fontModule->fontScCB->setEnabled(false);
+		return;
+	}
 	string const font = tex_fonts_roman[item];
 	fontModule->fontScCB->setEnabled(providesSC(font));
 	fontModule->fontOsfCB->setEnabled(providesOSF(font));
@@ -1196,6 +1243,10 @@
 
 void GuiDocument::sansChanged(int item)
 {
+	if (fontModule->xetexCB->isChecked()) {
+		fontModule->fontScCB->setEnabled(false);
+		return;
+	}
 	string const font = tex_fonts_sans[item];
 	bool scaleable = providesScale(font);
 	fontModule->scaleSansSB->setEnabled(scaleable);
@@ -1205,6 +1256,10 @@
 
 void GuiDocument::ttChanged(int item)
 {
+	if (fontModule->xetexCB->isChecked()) {
+		fontModule->fontScCB->setEnabled(false);
+		return;
+	}
 	string const font = tex_fonts_monospaced[item];
 	bool scaleable = providesScale(font);
 	fontModule->scaleTypewriterSB->setEnabled(scaleable);
@@ -1741,15 +1796,38 @@
 	bp_.float_placement = floatModule->get();
 
 	// fonts
-	bp_.fontsRoman =
-		tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
+	bool const xetex = fontModule->xetexCB->isChecked();
+	bp_.useXetex = xetex;
 
-	bp_.fontsSans =
-		tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
+	if (xetex) {
+		if (fontModule->fontsRomanCO->currentIndex() == 0)
+			bp_.fontsRoman = "default";
+		else
+			bp_.fontsRoman =
+				fromqstr(fontModule->fontsRomanCO->currentText());
+	
+		if (fontModule->fontsSansCO->currentIndex() == 0)
+			bp_.fontsSans = "default";
+		else
+			bp_.fontsSans =
+				fromqstr(fontModule->fontsSansCO->currentText());
+	
+		if (fontModule->fontsTypewriterCO->currentIndex() == 0)
+			bp_.fontsTypewriter = "default";
+		else
+			bp_.fontsTypewriter =
+				fromqstr(fontModule->fontsTypewriterCO->currentText());
+	} else {
+		bp_.fontsRoman =
+			tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
+	
+		bp_.fontsSans =
+			tex_fonts_sans[fontModule->fontsSansCO->currentIndex()];
+	
+		bp_.fontsTypewriter =
+			tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
+	}
 
-	bp_.fontsTypewriter =
-		tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
-
 	bp_.fontsCJK =
 		fromqstr(fontModule->cjkFontLE->text());
 
@@ -2046,24 +2124,49 @@
 	updateFontsize(documentClass().opt_fontsize(),
 			bp_.fontsize);
 
-	int n = findToken(tex_fonts_roman, bp_.fontsRoman);
-	if (n >= 0) {
-		fontModule->fontsRomanCO->setCurrentIndex(n);
-		romanChanged(n);
-	}
+	fontModule->xetexCB->setChecked(bp_.useXetex);
 
-	n = findToken(tex_fonts_sans, bp_.fontsSans);
-	if (n >= 0)	{
-		fontModule->fontsSansCO->setCurrentIndex(n);
-		sansChanged(n);
+	if (bp_.useXetex) {
+		for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
+			if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
+				fontModule->fontsRomanCO->setCurrentIndex(i);
+				return;
+			}
+		}
+		
+		for (int i = 0; i < fontModule->fontsSansCO->count(); ++i) {
+			if (fontModule->fontsSansCO->itemText(i) == toqstr(bp_.fontsSans)) {
+				fontModule->fontsSansCO->setCurrentIndex(i);
+				return;
+			}
+		}
+		for (int i = 0; i < fontModule->fontsTypewriterCO->count(); ++i) {
+			if (fontModule->fontsTypewriterCO->itemText(i) == 
+				toqstr(bp_.fontsTypewriter)) {
+				fontModule->fontsTypewriterCO->setCurrentIndex(i);
+				return;
+			}
+		}
+	} else {
+		int n = findToken(tex_fonts_roman, bp_.fontsRoman);
+		if (n >= 0) {
+			fontModule->fontsRomanCO->setCurrentIndex(n);
+			romanChanged(n);
+		}
+	
+		n = findToken(tex_fonts_sans, bp_.fontsSans);
+		if (n >= 0) {
+			fontModule->fontsSansCO->setCurrentIndex(n);
+			sansChanged(n);
+		}
+	
+		n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
+		if (n >= 0) {
+			fontModule->fontsTypewriterCO->setCurrentIndex(n);
+			ttChanged(n);
+		}
 	}
 
-	n = findToken(tex_fonts_monospaced, bp_.fontsTypewriter);
-	if (n >= 0) {
-		fontModule->fontsTypewriterCO->setCurrentIndex(n);
-		ttChanged(n);
-	}
-
 	if (!bp_.fontsCJK.empty())
 		fontModule->cjkFontLE->setText(
 			toqstr(bp_.fontsCJK));
@@ -2074,10 +2177,11 @@
 	fontModule->fontOsfCB->setChecked(bp_.fontsOSF);
 	fontModule->scaleSansSB->setValue(bp_.fontsSansScale);
 	fontModule->scaleTypewriterSB->setValue(bp_.fontsTypewriterScale);
-	n = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
-	if (n >= 0)
-		fontModule->fontsDefaultCO->setCurrentIndex(n);
 
+	int nn = findToken(GuiDocument::fontfamilies, bp_.fontsDefaultFamily);
+	if (nn >= 0)
+		fontModule->fontsDefaultCO->setCurrentIndex(nn);
+
 	// paper
 	bool const extern_geometry =
 		documentClass().provides("geometry");
@@ -2153,9 +2257,9 @@
 	pdfSupportModule->pdfusetitleCB->setChecked(pdf.pdfusetitle);
 	pdfSupportModule->colorlinksCB->setChecked(pdf.colorlinks);
 
-	n = findToken(backref_opts, pdf.backref);
-	if (n >= 0)
-		pdfSupportModule->backrefCO->setCurrentIndex(n);
+	nn = findToken(backref_opts, pdf.backref);
+	if (nn >= 0)
+		pdfSupportModule->backrefCO->setCurrentIndex(nn);
 
 	pdfSupportModule->fullscreenCB->setChecked
 		(pdf.pagemode == pdf.pagemode_fullscreen);
Index: src/frontends/qt4/GuiSendto.cpp
===================================================================
--- src/frontends/qt4/GuiSendto.cpp	(Revision 29100)
+++ src/frontends/qt4/GuiSendto.cpp	(Arbeitskopie)
@@ -15,6 +15,7 @@
 #include "qt_helpers.h"
 
 #include "Buffer.h"
+#include "BufferParams.h"
 #include "Converter.h"
 #include "Format.h"
 #include "FuncRequest.h"
@@ -174,8 +175,12 @@
 	exports.push_back("text");
 
 	if (buffer().isLatex()) {
-		exports.push_back("latex");
-		exports.push_back("pdflatex");
+		if (buffer().params().useXetex)
+			exports.push_back("xetex");
+		else {
+			exports.push_back("latex");
+			exports.push_back("pdflatex");
+		}
 	}
 	else if (buffer().isDocBook())
 		exports.push_back("docbook");
Index: src/frontends/qt4/ui/FontUi.ui
===================================================================
--- src/frontends/qt4/ui/FontUi.ui	(Revision 29100)
+++ src/frontends/qt4/ui/FontUi.ui	(Arbeitskopie)
@@ -5,94 +5,49 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>414</width>
-    <height>268</height>
+    <width>543</width>
+    <height>361</height>
    </rect>
   </property>
   <property name="windowTitle" >
    <string>FontUi</string>
   </property>
-  <layout class="QGridLayout" >
-   <property name="margin" >
-    <number>9</number>
-   </property>
-   <property name="spacing" >
-    <number>6</number>
-   </property>
-   <item row="8" column="0" colspan="4" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
+  <layout class="QGridLayout" name="gridLayout" >
+   <item row="0" column="0" >
+    <widget class="QCheckBox" name="xetexCB" >
+     <property name="toolTip" >
+      <string>Use the XeTeX processor, which allows access to all system fonts</string>
      </property>
-     <property name="sizeType" >
-      <enum>QSizePolicy::Expanding</enum>
-     </property>
-     <property name="sizeHint" >
-      <size>
-       <width>391</width>
-       <height>16</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="5" column="0" >
-    <widget class="QLabel" name="cjkFontLA" >
      <property name="text" >
-      <string>C&amp;JK:</string>
+      <string>Use &amp;XeTeX</string>
      </property>
-     <property name="buddy" >
-      <cstring>cjkFontLE</cstring>
-     </property>
     </widget>
    </item>
-   <item row="5" column="1" >
-    <widget class="QLineEdit" name="cjkFontLE" >
-     <property name="toolTip" >
-      <string>Input the font to be used for Chinese, Japanese or Korean (CJK) script</string>
-     </property>
-    </widget>
-   </item>
-   <item row="5" column="2" colspan="2" >
-    <spacer>
+   <item row="1" column="0" colspan="4" >
+    <widget class="Line" name="line" >
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeHint" >
-      <size>
-       <width>151</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
+    </widget>
    </item>
-   <item row="7" column="1" >
-    <widget class="QCheckBox" name="fontOsfCB" >
-     <property name="toolTip" >
-      <string>Use old style instead of lining figures</string>
-     </property>
+   <item row="2" column="0" >
+    <widget class="QLabel" name="fontsDefaultLA" >
      <property name="text" >
-      <string>Use &amp;Old Style Figures</string>
+      <string>&amp;Default Family:</string>
      </property>
-    </widget>
-   </item>
-   <item row="6" column="1" >
-    <widget class="QCheckBox" name="fontScCB" >
-     <property name="toolTip" >
-      <string>Use a real small caps shape, if the font provides one</string>
+     <property name="buddy" >
+      <cstring>fontsDefaultCO</cstring>
      </property>
-     <property name="text" >
-      <string>Use true S&amp;mall Caps</string>
-     </property>
     </widget>
    </item>
-   <item row="0" column="1" >
+   <item row="2" column="1" >
     <widget class="QComboBox" name="fontsDefaultCO" >
      <property name="toolTip" >
       <string>Select the default family for the document</string>
      </property>
     </widget>
    </item>
-   <item row="0" column="2" >
+   <item row="2" column="2" >
     <widget class="QLabel" name="TextLabel2_2" >
      <property name="text" >
       <string>&amp;Base Size:</string>
@@ -102,37 +57,57 @@
      </property>
     </widget>
    </item>
-   <item row="0" column="3" >
+   <item row="2" column="3" >
     <widget class="QComboBox" name="fontsizeCO" >
      <property name="toolTip" >
       <string/>
      </property>
     </widget>
    </item>
-   <item row="0" column="0" >
-    <widget class="QLabel" name="fontsDefaultLA" >
+   <item row="3" column="1" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>182</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="4" column="0" >
+    <widget class="QLabel" name="fontsRomanLA" >
      <property name="text" >
-      <string>&amp;Default Family:</string>
+      <string>&amp;Roman:</string>
      </property>
      <property name="buddy" >
-      <cstring>fontsDefaultCO</cstring>
+      <cstring>fontsRomanCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="1" column="1" >
+   <item row="4" column="1" >
+    <widget class="QComboBox" name="fontsRomanCO" >
+     <property name="toolTip" >
+      <string>Select the roman (serif) typeface</string>
+     </property>
+    </widget>
+   </item>
+   <item row="4" column="2" colspan="2" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
-       <width>182</width>
-       <height>16</height>
+       <width>131</width>
+       <height>20</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="3" column="0" >
+   <item row="5" column="0" >
     <widget class="QLabel" name="fontsSansLA" >
      <property name="text" >
       <string>&amp;Sans Serif:</string>
@@ -142,14 +117,14 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="1" >
+   <item row="5" column="1" >
     <widget class="QComboBox" name="fontsSansCO" >
      <property name="toolTip" >
       <string>Select the Sans Serif (grotesque) typeface</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="2" >
+   <item row="5" column="2" >
     <widget class="QLabel" name="scaleSansLA" >
      <property name="text" >
       <string>S&amp;cale (%):</string>
@@ -159,37 +134,20 @@
      </property>
     </widget>
    </item>
-   <item row="3" column="3" >
+   <item row="5" column="3" >
     <widget class="QSpinBox" name="scaleSansSB" >
      <property name="toolTip" >
       <string>Scale the Sans Serif font to match the base font's dimensions</string>
      </property>
-     <property name="maximum" >
-      <number>200</number>
-     </property>
      <property name="minimum" >
       <number>10</number>
      </property>
-    </widget>
-   </item>
-   <item row="2" column="0" >
-    <widget class="QLabel" name="fontsRomanLA" >
-     <property name="text" >
-      <string>&amp;Roman:</string>
+     <property name="maximum" >
+      <number>200</number>
      </property>
-     <property name="buddy" >
-      <cstring>fontsRomanCO</cstring>
-     </property>
     </widget>
    </item>
-   <item row="2" column="1" >
-    <widget class="QComboBox" name="fontsRomanCO" >
-     <property name="toolTip" >
-      <string>Select the roman (serif) typeface</string>
-     </property>
-    </widget>
-   </item>
-   <item row="4" column="0" >
+   <item row="6" column="0" >
     <widget class="QLabel" name="fontsTypewriterLA" >
      <property name="text" >
       <string>&amp;Typewriter:</string>
@@ -199,14 +157,14 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="1" >
+   <item row="6" column="1" >
     <widget class="QComboBox" name="fontsTypewriterCO" >
      <property name="toolTip" >
       <string>Select the typewriter (monospaced) typeface</string>
      </property>
     </widget>
    </item>
-   <item row="4" column="2" >
+   <item row="6" column="2" >
     <widget class="QLabel" name="scaleTypewriterLA" >
      <property name="text" >
       <string>Sc&amp;ale (%):</string>
@@ -216,32 +174,85 @@
      </property>
     </widget>
    </item>
-   <item row="4" column="3" >
+   <item row="6" column="3" >
     <widget class="QSpinBox" name="scaleTypewriterSB" >
      <property name="toolTip" >
       <string>Scale the Typewriter font to match the base font's dimensions</string>
      </property>
+     <property name="minimum" >
+      <number>10</number>
+     </property>
      <property name="maximum" >
       <number>200</number>
      </property>
-     <property name="minimum" >
-      <number>10</number>
+    </widget>
+   </item>
+   <item row="7" column="0" >
+    <widget class="QLabel" name="cjkFontLA" >
+     <property name="text" >
+      <string>C&amp;JK:</string>
      </property>
+     <property name="buddy" >
+      <cstring>cjkFontLE</cstring>
+     </property>
     </widget>
    </item>
-   <item row="2" column="2" colspan="2" >
+   <item row="7" column="1" >
+    <widget class="QLineEdit" name="cjkFontLE" >
+     <property name="toolTip" >
+      <string>Input the font to be used for Chinese, Japanese or Korean (CJK) script</string>
+     </property>
+    </widget>
+   </item>
+   <item row="7" column="2" colspan="2" >
     <spacer>
      <property name="orientation" >
       <enum>Qt::Horizontal</enum>
      </property>
-     <property name="sizeHint" >
+     <property name="sizeHint" stdset="0" >
       <size>
-       <width>131</width>
+       <width>151</width>
        <height>20</height>
       </size>
      </property>
     </spacer>
    </item>
+   <item row="8" column="1" >
+    <widget class="QCheckBox" name="fontScCB" >
+     <property name="toolTip" >
+      <string>Use a real small caps shape, if the font provides one</string>
+     </property>
+     <property name="text" >
+      <string>Use true S&amp;mall Caps</string>
+     </property>
+    </widget>
+   </item>
+   <item row="9" column="1" >
+    <widget class="QCheckBox" name="fontOsfCB" >
+     <property name="toolTip" >
+      <string>Use old style instead of lining figures</string>
+     </property>
+     <property name="text" >
+      <string>Use &amp;Old Style Figures</string>
+     </property>
+    </widget>
+   </item>
+   <item row="10" column="0" colspan="4" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Expanding</enum>
+     </property>
+     <property name="sizeHint" stdset="0" >
+      <size>
+       <width>391</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11" />
Index: src/output_latex.cpp
===================================================================
--- src/output_latex.cpp	(Revision 29100)
+++ src/output_latex.cpp	(Arbeitskopie)
@@ -697,9 +697,11 @@
 	// If this is the last paragraph, and a local_font was set upon entering
 	// the inset, and we're using "auto" or "default" encoding, the encoding
 	// should be set back to that local_font's encoding.
+	// However, do not change the encoding when XeTeX is used.
 	if (nextpit == paragraphs.end() && runparams_in.local_font != 0
 	    && runparams_in.encoding != runparams_in.local_font->language()->encoding()
-	    && (bparams.inputenc == "auto" || bparams.inputenc == "default")) {
+	    && (bparams.inputenc == "auto" || bparams.inputenc == "default")
+	    && (!bparams.useXetex)) {
 		runparams_in.encoding = runparams_in.local_font->language()->encoding();
 		os << setEncoding(runparams_in.encoding->iconvName());
 	}
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 29100)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -121,7 +121,7 @@
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-int const LYX_FORMAT = 348;  // uwestoehr: add support for \*phantom
+int const LYX_FORMAT = 349;  // jspitzm: initial XeTeX support
 
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
@@ -1005,9 +1005,13 @@
 
 bool Buffer::makeLaTeXFile(FileName const & fname,
 			   string const & original_path,
-			   OutputParams const & runparams,
+			   OutputParams const & runparams_in,
 			   bool output_preamble, bool output_body) const
 {
+	OutputParams runparams = runparams_in;
+	if (params().useXetex)
+		runparams.flavor = OutputParams::XETEX;
+
 	string const encoding = runparams.encoding->iconvName();
 	LYXERR(Debug::LATEX, "makeLaTeXFile encoding: " << encoding << "...");
 
@@ -2232,7 +2236,8 @@
 {
 	OutputParams runparams(&params().encoding());
 	runparams.nice = true;
-	runparams.flavor = OutputParams::LATEX;
+	runparams.flavor = params().useXetex ? 
+		OutputParams::XETEX : OutputParams::LATEX;
 	runparams.linelen = lyxrc.plaintext_linelen;
 	// No side effect of file copying and image conversion
 	runparams.dryrun = true;
@@ -2467,6 +2472,8 @@
 		return "docbook";
 	if (isLiterate())
 		return "literate";
+	if (params().useXetex)
+		return "xetex";
 	if (params().encoding().package() == Encoding::japanese)
 		return "platex";
 	return "latex";
Index: src/BufferParams.cpp
===================================================================
--- src/BufferParams.cpp	(Revision 29100)
+++ src/BufferParams.cpp	(Arbeitskopie)
@@ -93,6 +93,7 @@
 };
 
 
+
 namespace lyx {
 
 // Local translators
@@ -270,7 +271,6 @@
 	return translator;
 }
 
-
 } // anon namespace
 
 
@@ -344,6 +344,7 @@
 	fontsSans = "default";
 	fontsTypewriter = "default";
 	fontsDefaultFamily = "default";
+	useXetex = false;
 	fontsSC = false;
 	fontsOSF = false;
 	fontsSansScale = 100;
@@ -509,13 +510,18 @@
 	} else if (token == "\\graphics") {
 		readGraphicsDriver(lex);
 	} else if (token == "\\font_roman") {
-		lex >> fontsRoman;
+		lex.eatLine();
+		fontsRoman = lex.getString();
 	} else if (token == "\\font_sans") {
-		lex >> fontsSans;
+		lex.eatLine();
+		fontsSans = lex.getString();
 	} else if (token == "\\font_typewriter") {
-		lex >> fontsTypewriter;
+		lex.eatLine();
+		fontsTypewriter = lex.getString();
 	} else if (token == "\\font_default_family") {
 		lex >> fontsDefaultFamily;
+	} else if (token == "\\use_xetex") {
+		lex >> useXetex;
 	} else if (token == "\\font_sc") {
 		lex >> fontsSC;
 	} else if (token == "\\font_osf") {
@@ -742,6 +748,7 @@
 	   << "\n\\font_sans " << fontsSans
 	   << "\n\\font_typewriter " << fontsTypewriter
 	   << "\n\\font_default_family " << fontsDefaultFamily
+	   << "\n\\use_xetex " << convert<string>(useXetex)
 	   << "\n\\font_sc " << convert<string>(fontsSC)
 	   << "\n\\font_osf " << convert<string>(fontsOSF)
 	   << "\n\\font_sf_scale " << fontsSansScale
@@ -876,6 +883,7 @@
 			}
 			break;
 		case OutputParams::PDFLATEX:
+		case OutputParams::XETEX:
 			if (xcolorulem) {
 				features.require("ct-xcolor-ulem");
 				features.require("ulem");
@@ -937,6 +945,9 @@
 			features.require("color");
 	}
 
+	if (useXetex)
+		features.require("xetex");
+
 	if (language->lang() == "vietnamese")
 		features.require("vietnamese");
 	else if (language->lang() == "japanese")
@@ -1075,11 +1086,20 @@
 	texrow.newline();
 	// end of \documentclass defs
 
+	if (useXetex) {
+		os << "\\usepackage{fontspec}\n";
+		texrow.newline();
+		os << "\\usepackage{xunicode}\n";
+		texrow.newline();
+		os << "\\usepackage{xltxtra}\n";
+		texrow.newline();
+	}
+
 	// font selection must be done before loading fontenc.sty
 	string const fonts =
 		loadFonts(fontsRoman, fontsSans,
 			  fontsTypewriter, fontsSC, fontsOSF,
-			  fontsSansScale, fontsTypewriterScale);
+			  fontsSansScale, fontsTypewriterScale, useXetex);
 	if (!fonts.empty()) {
 		os << from_ascii(fonts);
 		texrow.newline();
@@ -1092,7 +1112,9 @@
 	// this one is not per buffer
 	// for arabic_arabi and farsi we also need to load the LAE and
 	// LFE encoding
-	if (lyxrc.fontenc != "default" && language->lang() != "japanese") {
+	// XeteX works without fontenc
+	if (lyxrc.fontenc != "default" && language->lang() != "japanese"
+	    && !useXetex) {
 		if (language->lang() == "arabic_arabi"
 		    || language->lang() == "farsi") {
 			os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
@@ -1863,6 +1885,8 @@
 void BufferParams::writeEncodingPreamble(odocstream & os,
 		LaTeXFeatures & features, TexRow & texrow) const
 {
+	if (useXetex)
+		return;
 	if (inputenc == "auto") {
 		string const doc_encoding =
 			language->encoding()->latexName();
@@ -1941,10 +1965,22 @@
 }
 
 
+string const BufferParams::parseFontName(string const & name) const
+{
+	string mangled = name;
+	size_t const idx = mangled.find('[');
+	if (idx == string::npos || idx == 0)
+		return mangled;
+	else
+		return mangled.substr(0, idx - 1);
+}
+
+
 string const BufferParams::loadFonts(string const & rm,
 				     string const & sf, string const & tt,
 				     bool const & sc, bool const & osf,
-				     int const & sfscale, int const & ttscale) const
+				     int const & sfscale, int const & ttscale,
+				     bool const & xetex) const
 {
 	/* The LaTeX font world is in a flux. In the PSNFSS font interface,
 	   several packages have been replaced by others, that might not
@@ -1964,6 +2000,37 @@
 
 	ostringstream os;
 
+	if (xetex) {
+		if (rm != "default")
+			os << "\\setmainfont[Mapping=tex-text]{"
+			   << parseFontName(rm) << "}\n";
+		if (sf != "default") {
+			string const sans = parseFontName(sf);
+			if (sfscale != 100)
+				os << "\\setsansfont[Scale=" 
+				   << float(sfscale) / 100 
+				   << ",Mapping=tex-text]{"
+				   << sans << "}\n";
+			else
+				os << "\\setsansfont[Mapping=tex-text]{"
+				   << sans << "}\n";
+		}
+		if (tt != "default") {
+			string const mono = parseFontName(tt);
+			if (ttscale != 100)
+				os << "\\setmonofont[Scale=" 
+				   << float(sfscale) / 100 
+				   << "]{"
+				   << mono << "}\n";
+			else
+				os << "\\setmonofont[Mapping=tex-text]{"
+				   << mono << "}\n";
+		}
+		if (osf)
+			os << "\\defaultfontfeatures{Numbers=OldStyle}\n";
+		return os.str();
+	}
+
 	// ROMAN FONTS
 	// Computer Modern (must be explicitely selectable -- there might be classes
 	// that define a different default font!
@@ -2080,6 +2147,8 @@
 
 Encoding const & BufferParams::encoding() const
 {
+	if (useXetex)
+		return *(encodings.fromLaTeXName("utf8-plain"));
 	if (inputenc == "auto" || inputenc == "default")
 		return *language->encoding();
 	Encoding const * const enc = encodings.fromLaTeXName(inputenc);

Reply via email to