Jürgen Spitzmüller wrote:
> Jürgen Spitzmüller wrote:
> > A patch along this line is attached. We still have to hardcode xhtml,
> > since  there's no dedicated converter where we could derive a xhtml flag
> > from.
> 
> I committed the backend=flavor part, since this is a step forward anyway
> and  removes some bad hardcoding.

I come back to this. Attached is a reworked version of the view source part. I 
have added a cache for the default flavor, since it is overkill to recheck for 
the flavor on each key stroke.

Typing with full source on the UG is slow. But it is as slow without the 
patch.

Objections?

Jürgen
Index: src/Buffer.h
===================================================================
--- src/Buffer.h	(Revision 36713)
+++ src/Buffer.h	(Arbeitskopie)
@@ -13,12 +13,14 @@
 #define BUFFER_H
 
 #include "OutputEnums.h"
+#include "OutputParams.h"
 
 #include "insets/InsetCode.h"
 
 #include "support/strfwd.h"
 #include "support/types.h"
 
+#include <map>
 #include <list>
 #include <set>
 #include <string>
@@ -552,7 +554,7 @@
 	/// get source code (latex/docbook) for some paragraphs, or all paragraphs
 	/// including preamble
 	void getSourceCode(odocstream & os, pit_type par_begin, pit_type par_end,
-		bool full_source) const;
+		bool full_source);
 
 	/// Access to error list.
 	/// This method is used only for GUI visualisation of Buffer related
@@ -600,6 +602,8 @@
 	std::string bufferFormat() const;
 	/// return the default output format of the current backend
 	std::string getDefaultOutputFormat() const;
+	/// return the default output flavor
+	OutputParams::FLAVOR getDefaultOutputFlavor();
 
 	///
 	bool doExport(std::string const & format, bool put_in_tempdir,
@@ -662,7 +666,11 @@
 	void setFileName(support::FileName const & fname);
 	///
 	std::vector<std::string> backends() const;
+	/// A cache for the default flavors
+	typedef std::map<std::string, OutputParams::FLAVOR> DefaultFlavorCache;
 	///
+	DefaultFlavorCache default_flavors_;
+	///
 	void getLanguages(std::set<Language const *> &) const;
 	/// Checks whether any of the referenced bibfiles have changed since the
 	/// last time we loaded the cache. Note that this does NOT update the
Index: src/frontends/qt4/GuiViewSource.cpp
===================================================================
--- src/frontends/qt4/GuiViewSource.cpp	(Revision 36713)
+++ src/frontends/qt4/GuiViewSource.cpp	(Arbeitskopie)
@@ -102,7 +102,8 @@
 	if (par_begin > par_end)
 		swap(par_begin, par_end);
 	odocstringstream ostr;
-	view->buffer().getSourceCode(ostr, par_begin, par_end + 1, fullSource);
+	const_cast<BufferView *>(view)->buffer().getSourceCode(
+		ostr, par_begin, par_end + 1, fullSource);
 	docstring s = ostr.str();
 	static size_t crc = 0;
 	size_t newcrc = crcCheck(s);
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp	(Revision 36713)
+++ src/Buffer.cpp	(Arbeitskopie)
@@ -3072,12 +3072,11 @@
 
 
 void Buffer::getSourceCode(odocstream & os, pit_type par_begin,
-	pit_type par_end, bool full_source) const
+	pit_type par_end, bool full_source)
 {
 	OutputParams runparams(&params().encoding());
 	runparams.nice = true;
-	runparams.flavor = params().useNonTeXFonts ? 
-		OutputParams::XETEX : OutputParams::LATEX;
+	runparams.flavor = getDefaultOutputFlavor();
 	runparams.linelen = lyxrc.plaintext_linelen;
 	// No side effect of file copying and image conversion
 	runparams.dryrun = true;
@@ -3089,6 +3088,8 @@
 		d->texrow.newline();
 		if (isDocBook())
 			writeDocBookSource(os, absFileName(), runparams, false);
+		else if (runparams.flavor == OutputParams::HTML)
+			writeLyXHTMLSource(os, runparams, false);
 		else
 			// latex or literate
 			writeLaTeXSource(os, string(), runparams, true, true);
@@ -3113,7 +3114,10 @@
 		// output paragraphs
 		if (isDocBook())
 			docbookParagraphs(text(), *this, os, runparams);
-		else 
+		else if (runparams.flavor == OutputParams::HTML) {
+			XHTMLStream xs(os);
+			xhtmlParagraphs(text(), *this, xs, runparams);
+		} else 
 			// latex or literate
 			latexParagraphs(*this, text(), os, texrow, runparams);
 	}
@@ -3384,6 +3388,42 @@
 }
 
 
+OutputParams::FLAVOR Buffer::getDefaultOutputFlavor()
+{
+	string const dformat = getDefaultOutputFormat();
+	DefaultFlavorCache::const_iterator it =
+		default_flavors_.find(dformat);
+
+	if (it != default_flavors_.end())
+		return it->second;
+
+	OutputParams::FLAVOR result = OutputParams::LATEX;
+	
+	if (dformat == "xhtml")
+		result = OutputParams::HTML;
+	else {
+		// Try to determine flavor of default output format
+		vector<string> backs = backends();
+		if (find(backs.begin(), backs.end(), dformat) == backs.end()) {
+			// Get shortest path to format
+			Graph::EdgePath path;
+			for (vector<string>::const_iterator it = backs.begin();
+			    it != backs.end(); ++it) {
+				Graph::EdgePath p = theConverters().getPath(*it, dformat);
+				if (!p.empty() && (path.empty() || p.size() < path.size())) {
+					path = p;
+				}
+			}
+			if (!path.empty())
+				result = theConverters().getFlavor(path);
+		}
+	}
+	// cache this flavor
+	default_flavors_[dformat] = result;
+	return result;
+}
+
+
 namespace {
 	// helper class, to guarantee this gets reset properly
 	class MarkAsExporting	{

Reply via email to