X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2FBufferParams.cpp;h=9d45d80d1034738d704496c9b275829dbbe652e1;hb=5887601f6836ebf6f2b16cc7587a98cc3aa6c391;hp=44847a9bdb7e2ed62239817092d4e8bc211a3f6e;hpb=7a66c9326586ff5b0cf9fc2092d67b1bf6a4b8d1;p=lyx.git diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 44847a9bdb..9d45d80d10 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -21,19 +21,17 @@ #include "LayoutFile.h" #include "BranchList.h" #include "Buffer.h" -#include "buffer_funcs.h" #include "Bullet.h" #include "CiteEnginesList.h" #include "Color.h" #include "ColorSet.h" #include "Converter.h" #include "Encoding.h" +#include "Format.h" #include "IndicesList.h" #include "Language.h" #include "LaTeXFeatures.h" #include "LaTeXFonts.h" -#include "Length.h" -#include "ModuleList.h" #include "Font.h" #include "Lexer.h" #include "LyXRC.h" @@ -50,10 +48,10 @@ #include "support/convert.h" #include "support/debug.h" -#include "support/docstream.h" #include "support/FileName.h" #include "support/filetools.h" #include "support/gettext.h" +#include "support/Length.h" #include "support/Messages.h" #include "support/mutex.h" #include "support/Package.h" @@ -413,7 +411,7 @@ BufferParams::BufferParams() change_bars = false; postpone_fragile_content = true; use_default_options = true; - maintain_unincluded_children = false; + maintain_unincluded_children = CM_None; secnumdepth = 3; tocdepth = 3; language = default_language; @@ -449,6 +447,8 @@ BufferParams::BufferParams() listings_params = string(); pagestyle = "default"; tablestyle = "default"; + float_alignment = "class"; + float_placement = "class"; suppress_date = false; justification = true; // no color is the default (white) @@ -471,6 +471,7 @@ BufferParams::BufferParams() html_math_output = MathML; html_math_img_scale = 1.0; html_css_as_file = false; + docbook_table_output = HTMLTable; display_pixel_ratio = 1.0; shell_escape = false; @@ -564,7 +565,7 @@ AuthorList const & BufferParams::authors() const } -void BufferParams::addAuthor(Author a) +void BufferParams::addAuthor(Author const & a) { author_map_[a.bufferId()] = pimpl_->authorlist.record(a); } @@ -782,7 +783,14 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\begin_includeonly") { readIncludeonly(lex); } else if (token == "\\maintain_unincluded_children") { - lex >> maintain_unincluded_children; + string tmp; + lex >> tmp; + if (tmp == "no") + maintain_unincluded_children = CM_None; + else if (tmp == "mostly") + maintain_unincluded_children = CM_Mostly; + else if (tmp == "strict") + maintain_unincluded_children = CM_Strict; } else if (token == "\\options") { lex.eatLine(); options = lex.getString(); @@ -984,7 +992,7 @@ string BufferParams::readToken(Lexer & lex, string const & token, branch_ptr->setColor(color); // Update also the Color table: if (color == "none") - color = lcolor.getX11Name(Color_background); + color = lcolor.getX11HexName(Color_background); // FIXME UNICODE lcolor.setColor(to_utf8(branch), color); } @@ -1013,7 +1021,7 @@ string BufferParams::readToken(Lexer & lex, string const & token, index_ptr->setColor(color); // Update also the Color table: if (color == "none") - color = lcolor.getX11Name(Color_background); + color = lcolor.getX11HexName(Color_background); // FIXME UNICODE if (!shortcut.empty()) lcolor.setColor(to_utf8(shortcut), color); @@ -1127,6 +1135,10 @@ string BufferParams::readToken(Lexer & lex, string const & token, } else if (token == "\\html_latex_end") { lex.eatLine(); html_latex_end = lex.getString(); + } else if (token == "\\docbook_table_output") { + int temp; + lex >> temp; + docbook_table_output = static_cast(temp); } else if (token == "\\output_sync") { lex >> output_sync; } else if (token == "\\output_sync_macro") { @@ -1235,8 +1247,19 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const os << c << '\n'; os << "\\end_includeonly" << '\n'; } - os << "\\maintain_unincluded_children " - << convert(maintain_unincluded_children) << '\n'; + string muc = "no"; + switch (maintain_unincluded_children) { + case CM_Mostly: + muc = "mostly"; + break; + case CM_Strict: + muc = "strict"; + break; + case CM_None: + default: + break; + } + os << "\\maintain_unincluded_children " << muc << '\n'; // local layout information docstring const local_layout = getLocalLayout(false); @@ -1348,9 +1371,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const if (!lineno_opts.empty()) os << "\\lineno_options " << lineno_opts << '\n'; - if (isbackgroundcolor == true) + if (isbackgroundcolor) os << "\\backgroundcolor " << lyx::X11hexname(backgroundcolor) << '\n'; - if (isfontcolor == true) + if (isfontcolor) os << "\\fontcolor " << lyx::X11hexname(fontcolor) << '\n'; if (notefontcolor != lyx::rgbFromHexName("#cccccc")) os << "\\notefontcolor " << lyx::X11hexname(notefontcolor) << '\n'; @@ -1473,6 +1496,8 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const << "\\html_css_as_file " << html_css_as_file << '\n' << "\\html_be_strict " << convert(html_be_strict) << '\n'; + os << "\\docbook_table_output " << docbook_table_output << '\n'; + if (html_math_img_scale != 1.0) os << "\\html_math_img_scale " << convert(html_math_img_scale) << '\n'; if (!html_latex_start.empty()) @@ -1706,17 +1731,59 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (!options.empty()) { clsoptions << options << ','; } - - string strOptions(clsoptions.str()); + + docstring const strOptions = from_utf8(clsoptions.str()); if (!strOptions.empty()) { - strOptions = rtrim(strOptions, ","); - // FIXME UNICODE - os << '[' << from_utf8(strOptions) << ']'; + // Check if class options contain uncodable glyphs + docstring uncodable_glyphs; + docstring options_encodable; + Encoding const * const enc = features.runparams().encoding; + if (enc) { + for (char_type c : strOptions) { + if (!enc->encodable(c)) { + docstring const glyph(1, c); + LYXERR0("Uncodable character '" + << glyph + << "' in class options!"); + uncodable_glyphs += glyph; + if (features.runparams().dryrun) { + options_encodable += "<" + _("LyX Warning: ") + + _("uncodable character") + " '"; + options_encodable += c; + options_encodable += "'>"; + } + } else + options_encodable += c; + } + } else + options_encodable = strOptions; + + // On BUFFER_VIEW|UPDATE, warn user if we found uncodable glyphs + if (!features.runparams().dryrun && !uncodable_glyphs.empty()) { + frontend::Alert::warning( + _("Uncodable character in class options"), + support::bformat( + _("The class options of your document contain glyphs " + "that are unknown in the current document encoding " + "(namely %1$s).\nThese glyphs are omitted " + " from the output, which may result in " + "incomplete output." + "\n\nPlease select an appropriate " + "document encoding\n" + "(such as utf8) or change the " + "class options accordingly."), + uncodable_glyphs)); + } + options_encodable = rtrim(options_encodable, ","); + os << '[' << options_encodable << ']'; } os << '{' << from_ascii(tclass.latexname()) << "}\n"; // end of \documentclass defs + // The package options (via \PassOptionsToPackage) + os << from_ascii(features.getPackageOptions()); + // if we use fontspec or newtxmath, we have to load the AMS packages here string const ams = features.loadAMSPackages(); bool const ot1 = (main_font_encoding() == "default" || main_font_encoding() == "OT1"); @@ -1909,7 +1976,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, } // only output when the background color is not default - if (isbackgroundcolor == true) { + if (isbackgroundcolor) { // only require color here, the background color will be defined // in LaTeXFeatures.cpp to avoid interferences with the LaTeX // package pdfpages @@ -1918,7 +1985,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, } // only output when the font color is not default - if (isfontcolor == true) { + if (isfontcolor) { // only require color here, the font color will be defined // in LaTeXFeatures.cpp to avoid interferences with the LaTeX // package pdfpages @@ -1942,26 +2009,36 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, if (paragraph_separation) { // when skip separation + string psopt; switch (getDefSkip().kind()) { case VSpace::SMALLSKIP: - os << "\\setlength{\\parskip}{\\smallskipamount}\n"; + psopt = "\\smallskipamount"; break; case VSpace::MEDSKIP: - os << "\\setlength{\\parskip}{\\medskipamount}\n"; + psopt = "\\medskipamount"; break; case VSpace::BIGSKIP: - os << "\\setlength{\\parskip}{\\bigskipamount}\n"; + psopt = "\\bigskipamount"; + break; + case VSpace::HALFLINE: + // default (no option) + break; + case VSpace::FULLLINE: + psopt = "\\baselineskip"; break; case VSpace::LENGTH: - os << "\\setlength{\\parskip}{" - << from_utf8(getDefSkip().length().asLatexString()) - << "}\n"; + psopt = getDefSkip().length().asLatexString(); break; - default: // should never happen // Then delete it. - os << "\\setlength{\\parskip}{\\medskipamount}\n"; + default: break; } - os << "\\setlength{\\parindent}{0pt}\n"; + if (!features.isProvided("parskip")) { + if (!psopt.empty()) + psopt = "[skip=" + psopt + "]"; + os << "\\usepackage" + psopt + "{parskip}\n"; + } else { + os << "\\setlength{\\parskip}{" + psopt + "}\n"; + } } else { // when separation by indentation // only output something when a width is given @@ -1995,9 +2072,6 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, os << "\\synctex=-1\n"; } - // The package options (via \PassOptionsToPackage) - os << from_ascii(features.getPackageOptions()); - // due to interferences with babel and hyperref, the color package has to // be loaded (when it is not already loaded) before babel when hyperref // is used with the colorlinks option, see @@ -2107,8 +2181,7 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features, docstring uncodable_glyphs; Encoding const * const enc = features.runparams().encoding; if (enc) { - for (size_t n = 0; n < preamble.size(); ++n) { - char_type c = preamble[n]; + for (char_type c : preamble) { if (!enc->encodable(c)) { docstring const glyph(1, c); LYXERR0("Uncodable character '" @@ -2580,11 +2653,13 @@ FormatList const & BufferParams::exportableFormats(bool only_viewable) const if (useNonTeXFonts) { excludes.insert("latex"); excludes.insert("pdflatex"); - } else if (inputenc != "ascii" && inputenc != "utf8-plain") + } else if (inputenc != "ascii" && inputenc != "utf8-plain") { // XeTeX with TeX fonts requires input encoding ascii (#10600). excludes.insert("xetex"); - FormatList result = theConverters().getReachable(backs[0], only_viewable, - true, excludes); + } + + FormatList result = + theConverters().getReachable(backs[0], only_viewable, true, excludes); vector::const_iterator it = backs.begin() + 1; for (; it != backs.end(); ++it) { FormatList r = theConverters().getReachable(*it, only_viewable, @@ -2630,6 +2705,7 @@ vector BufferParams::backends() const } v.push_back("xhtml"); + v.push_back("docbook5"); v.push_back("text"); v.push_back("lyx"); return v; @@ -2652,6 +2728,8 @@ OutputParams::FLAVOR BufferParams::getOutputFlavor(string const & format) const // something with formats. if (dformat == "xhtml") result = OutputParams::HTML; + else if (dformat == "docbook5") + result = OutputParams::DOCBOOK5; else if (dformat == "text") result = OutputParams::TEXT; else if (dformat == "lyx") @@ -2691,13 +2769,6 @@ string BufferParams::getDefaultOutputFormat() const if (!default_output_format.empty() && default_output_format != "default") return default_output_format; - if (isDocBook()) { - FormatList const & formats = exportableFormats(true); - if (formats.empty()) - return string(); - // return the first we find - return formats.front()->name(); - } if (encoding().package() == Encoding::japanese) return lyxrc.default_platex_view_format; if (useNonTeXFonts) @@ -2736,12 +2807,6 @@ bool BufferParams::isLiterate() const } -bool BufferParams::isDocBook() const -{ - return documentClass().outputType() == DOCBOOK; -} - - void BufferParams::readPreamble(Lexer & lex) { if (lex.getString() != "\\begin_preamble") @@ -3442,7 +3507,7 @@ string const & BufferParams::defaultBiblioStyle() const } -bool const & BufferParams::fullAuthorList() const +bool BufferParams::fullAuthorList() const { return documentClass().fullAuthorList(); }