- os << "\n<!-- Text Class Preamble -->\n"
- << features.getTClassHTMLPreamble()
- << "\n<!-- Premable Snippets -->\n"
- << from_utf8(features.getPreambleSnippets());
-
- os << "\n<!-- Layout-provided Styles -->\n";
- docstring const styleinfo = features.getTClassHTMLStyles();
- if (!styleinfo.empty()) {
- os << "<style type='text/css'>\n"
- << styleinfo
- << "</style>\n";
+ docstring styles = features.getTClassHTMLPreamble();
+ if (!styles.empty())
+ os << "\n<!-- Text Class Preamble -->\n" << styles << '\n';
+
+ styles = from_utf8(features.getPreambleSnippets());
+ if (!styles.empty())
+ os << "\n<!-- Preamble Snippets -->\n" << styles << '\n';
+
+ // we will collect CSS information in a stream, and then output it
+ // either here, as part of the header, or else in a separate file.
+ odocstringstream css;
+ styles = from_utf8(features.getCSSSnippets());
+ if (!styles.empty())
+ css << "/* LyX Provided Styles */\n" << styles << '\n';
+
+ styles = features.getTClassHTMLStyles();
+ if (!styles.empty())
+ css << "/* Layout-provided Styles */\n" << styles << '\n';
+
+ bool const needfg = params().fontcolor != RGBColor(0, 0, 0);
+ bool const needbg = params().backgroundcolor != RGBColor(0xFF, 0xFF, 0xFF);
+ if (needfg || needbg) {
+ css << "\nbody {\n";
+ if (needfg)
+ css << " color: "
+ << from_ascii(X11hexname(params().fontcolor))
+ << ";\n";
+ if (needbg)
+ css << " background-color: "
+ << from_ascii(X11hexname(params().backgroundcolor))
+ << ";\n";
+ css << "}\n";
+ }
+
+ docstring const dstyles = css.str();
+ if (!dstyles.empty()) {
+ bool written = false;
+ if (params().html_css_as_file) {
+ // open a file for CSS info
+ ofdocstream ocss;
+ string const fcssname = addName(temppath(), "docstyle.css");
+ FileName const fcssfile = FileName(fcssname);
+ if (openFileWrite(ocss, fcssfile)) {
+ ocss << dstyles;
+ ocss.close();
+ written = true;
+ // write link to header
+ os << "<link rel='stylesheet' href='docstyle.css' type='text/css' />\n";
+ // register file
+ runparams.exportdata->addExternalFile("xhtml", fcssfile);
+ }
+ }
+ // we are here if the CSS is supposed to be written to the header
+ // or if we failed to write it to an external file.
+ if (!written) {
+ os << "<style type='text/css'>\n"
+ << dstyles
+ << "\n</style>\n";
+ }