Replace hardcoded hack with InsetLayout tag

This commit is contained in:
Georg Baum 2015-01-11 20:00:45 +01:00
parent 6e519e7727
commit eb121f9993
7 changed files with 129 additions and 38 deletions

View File

@ -1,5 +1,5 @@
#LyX 2.2 created this file. For more info see http://www.lyx.org/ #LyX 2.2 created this file. For more info see http://www.lyx.org/
\lyxformat 479 \lyxformat 480
\begin_document \begin_document
\begin_header \begin_header
\textclass scrbook \textclass scrbook
@ -151,6 +151,7 @@ End
\html_css_as_file 0 \html_css_as_file 0
\html_be_strict true \html_be_strict true
\author -712698321 "Jürgen Spitzmüller" \author -712698321 "Jürgen Spitzmüller"
\author -195340706 "Georg Baum"
\author 274215730 "scott" \author 274215730 "scott"
\end_header \end_header
@ -16901,6 +16902,86 @@ LabelFont
\end_inset \end_inset
later if you want them to be different. later if you want them to be different.
\change_inserted -195340706 1421002157
\end_layout
\begin_layout Description
\change_inserted -195340706 1421002157
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -195340706 1421002157
FixedWidthPreambleEncoding
\end_layout
\end_inset
[
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -195340706 1421002157
\emph on
0
\end_layout
\end_inset
,
\begin_inset space \thinspace{}
\end_inset
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -195340706 1421002157
1
\end_layout
\end_inset
] Force a fixed width encoding for the translated contents of
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -195340706 1421002157
BabelPreamble
\end_layout
\end_inset
and
\begin_inset Flex Code
status collapsed
\begin_layout Plain Layout
\change_inserted -195340706 1421002157
LangPreamble
\end_layout
\end_inset
code generated by this layout.
This is needed for special packages like the listings package that do not
work with variable width encodings such as utf8.
Default is false.
This setting is ignored if fully unicode aware LaTeX backends such as XeLaTeX
are used.
\change_unchanged
\end_layout \end_layout
\begin_layout Description \begin_layout Description

View File

@ -4,7 +4,7 @@
# #
# Detailed format description is available in the customization manual # Detailed format description is available in the customization manual
Format 53 Format 54
Provides stdinsets 1 Provides stdinsets 1
@ -267,6 +267,7 @@ InsetLayout TOC:Listings
LangPreamble LangPreamble
\renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])} \renewcommand{\lstlistlistingname}{_(Listings[[List of Listings]])}
EndLangPreamble EndLangPreamble
FixedWidthPreambleEncoding true
HTMLTag h2 HTMLTag h2
HTMLStyle HTMLStyle
div.lyxtoc-flat { div.lyxtoc-flat {
@ -287,6 +288,7 @@ InsetLayout Include:Listings
LangPreamble LangPreamble
\renewcommand{\lstlistingname}{_(Listing)} \renewcommand{\lstlistingname}{_(Listing)}
EndLangPreamble EndLangPreamble
FixedWidthPreambleEncoding true
End End
InsetLayout Listings InsetLayout Listings

View File

@ -177,6 +177,9 @@ import os, re, string, sys
# Incremented to format 53, 7 December 2014 by spitz # Incremented to format 53, 7 December 2014 by spitz
# New InsetLayout tag "ObsoletedBy" # New InsetLayout tag "ObsoletedBy"
# Incremented to format 54, 11 Jan 2014 by gb
# New InsetLayout tag "FixedWidthPreambleEncoding"
# Do not forget to document format change in Customization # Do not forget to document format change in Customization
# Manual (section "Declaring a new text class"). # Manual (section "Declaring a new text class").
@ -184,7 +187,7 @@ import os, re, string, sys
# development/tools/updatelayouts.py script to update all # development/tools/updatelayouts.py script to update all
# layout files to the new format. # layout files to the new format.
currentFormat = 53 currentFormat = 54
def usage(prog_name): def usage(prog_name):
@ -408,7 +411,7 @@ def convert(lines):
i += 1 i += 1
continue continue
if format >= 50 and format <= 52: if format >= 50 and format <= 53:
# nothing to do. # nothing to do.
i += 1 i += 1
continue continue

View File

@ -1569,11 +1569,7 @@ docstring const LaTeXFeatures::getTClassI18nPreamble(bool use_babel, bool use_po
// need to force a fixed width encoding for // need to force a fixed width encoding for
// \lstlistlistingname and \lstlistingname (bug 9382). // \lstlistlistingname and \lstlistingname (bug 9382).
// This needs to be consistent with InsetListings::latex(). // This needs to be consistent with InsetListings::latex().
docstring const ilname = it->second.name(); bool const need_fixedwidth = it->second.fixedwidthpreambleencoding();
bool const need_fixedwidth = !runparams_.isFullUnicode() &&
(ilname == "Listings" ||
ilname == "Include:Listings" ||
ilname == "TOC:Listings");
// language dependent commands (once per document) // language dependent commands (once per document)
snippets.insert(i18npreamble(it->second.langpreamble(), snippets.insert(i18npreamble(it->second.langpreamble(),
buffer().language(), buffer().language(),

View File

@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script, // You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files. // to update the format of all of our layout files.
// //
int const LAYOUT_FORMAT = 53; //spitz: add ObsoletedBy tag for InsetLayouts int const LAYOUT_FORMAT = 54; //gb: add FixedWidthPreambleEncoding tag for InsetLayouts
namespace { namespace {

View File

@ -34,20 +34,21 @@ namespace lyx {
InsetLayout::InsetLayout() : InsetLayout::InsetLayout() :
name_(from_ascii("undefined")), lyxtype_(STANDARD), name_(from_ascii("undefined")), lyxtype_(STANDARD),
labelstring_(from_ascii("UNDEFINED")), contentaslabel_(false), labelstring_(from_ascii("UNDEFINED")), contentaslabel_(false),
decoration_(DEFAULT), latextype_(NOLATEXTYPE), font_(inherit_font), decoration_(DEFAULT), latextype_(NOLATEXTYPE), font_(inherit_font),
labelfont_(sane_font), bgcolor_(Color_error), labelfont_(sane_font), bgcolor_(Color_error),
htmlforcecss_ (false), htmlisblock_(true), fixedwidthpreambleencoding_(false), htmlforcecss_ (false),
multipar_(true), custompars_(true), forceplain_(false), htmlisblock_(true), multipar_(true), custompars_(true),
passthru_(false), parbreakisnewline_(false), freespacing_(false), forceplain_(false), passthru_(false), parbreakisnewline_(false),
keepempty_(false), forceltr_(false), forceownlines_(false), freespacing_(false), keepempty_(false), forceltr_(false),
needprotect_(false), intoc_(false), spellcheck_(true), forceownlines_(false), needprotect_(false), intoc_(false),
resetsfont_(false), display_(true), forcelocalfontswitch_(false) spellcheck_(true), resetsfont_(false), display_(true),
forcelocalfontswitch_(false)
{ {
labelfont_.setColor(Color_error); labelfont_.setColor(Color_error);
} }
InsetLayout::InsetDecoration translateDecoration(std::string const & str) InsetLayout::InsetDecoration translateDecoration(std::string const & str)
{ {
if (support::compare_ascii_no_case(str, "classic") == 0) if (support::compare_ascii_no_case(str, "classic") == 0)
return InsetLayout::CLASSIC; return InsetLayout::CLASSIC;
@ -86,6 +87,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
IL_CUSTOMPARS, IL_CUSTOMPARS,
IL_DECORATION, IL_DECORATION,
IL_DISPLAY, IL_DISPLAY,
IL_FIXEDWIDTH_PREAMBLE_ENCODING,
IL_FONT, IL_FONT,
IL_FORCE_LOCAL_FONT_SWITCH, IL_FORCE_LOCAL_FONT_SWITCH,
IL_FORCELTR, IL_FORCELTR,
@ -132,12 +134,13 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
{ "babelpreamble", IL_BABELPREAMBLE }, { "babelpreamble", IL_BABELPREAMBLE },
{ "bgcolor", IL_BGCOLOR }, { "bgcolor", IL_BGCOLOR },
{ "contentaslabel", IL_CONTENTASLABEL }, { "contentaslabel", IL_CONTENTASLABEL },
{ "copystyle", IL_COPYSTYLE }, { "copystyle", IL_COPYSTYLE },
{ "counter", IL_COUNTER}, { "counter", IL_COUNTER},
{ "custompars", IL_CUSTOMPARS }, { "custompars", IL_CUSTOMPARS },
{ "decoration", IL_DECORATION }, { "decoration", IL_DECORATION },
{ "display", IL_DISPLAY }, { "display", IL_DISPLAY },
{ "end", IL_END }, { "end", IL_END },
{ "fixedwidthpreambleencoding", IL_FIXEDWIDTH_PREAMBLE_ENCODING },
{ "font", IL_FONT }, { "font", IL_FONT },
{ "forcelocalfontswitch", IL_FORCE_LOCAL_FONT_SWITCH }, { "forcelocalfontswitch", IL_FORCE_LOCAL_FONT_SWITCH },
{ "forceltr", IL_FORCELTR }, { "forceltr", IL_FORCELTR },
@ -186,7 +189,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
// for issuing a warning in case MultiPars comes later // for issuing a warning in case MultiPars comes later
bool readCustomOrPlain = false; bool readCustomOrPlain = false;
string tmp; string tmp;
while (!getout && lex.isOK()) { while (!getout && lex.isOK()) {
int le = lex.lex(); int le = lex.lex();
switch (le) { switch (le) {
@ -246,6 +249,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"), leftdelim_ = support::subst(leftdelim_, from_ascii("<br/>"),
from_ascii("\n")); from_ascii("\n"));
break; break;
case IL_FIXEDWIDTH_PREAMBLE_ENCODING:
lex >> fixedwidthpreambleencoding_;
break;
case IL_FORCE_LOCAL_FONT_SWITCH: case IL_FORCE_LOCAL_FONT_SWITCH:
lex >> forcelocalfontswitch_; lex >> forcelocalfontswitch_;
break; break;
@ -313,7 +319,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
// We don't want to apply the algorithm in DocumentClass::insetLayout() // We don't want to apply the algorithm in DocumentClass::insetLayout()
// here. So we do it the long way. // here. So we do it the long way.
TextClass::InsetLayouts::const_iterator it = TextClass::InsetLayouts::const_iterator it =
tclass.insetLayouts().find(style); tclass.insetLayouts().find(style);
if (it != tclass.insetLayouts().end()) { if (it != tclass.insetLayouts().end()) {
docstring const tmpname = name_; docstring const tmpname = name_;
@ -324,9 +330,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
<< style << "' to InsetLayout `" << style << "' to InsetLayout `"
<< name() << "'\n" << name() << "'\n"
<< "All InsetLayouts so far:"); << "All InsetLayouts so far:");
TextClass::InsetLayouts::const_iterator lit = TextClass::InsetLayouts::const_iterator lit =
tclass.insetLayouts().begin(); tclass.insetLayouts().begin();
TextClass::InsetLayouts::const_iterator len = TextClass::InsetLayouts::const_iterator len =
tclass.insetLayouts().end(); tclass.insetLayouts().end();
for (; lit != len; ++lit) for (; lit != len; ++lit)
lyxerr << lit->second.name() << "\n"; lyxerr << lit->second.name() << "\n";
@ -354,9 +360,9 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
<< "' with unknown InsetLayout `" << "' with unknown InsetLayout `"
<< style << "'\n" << style << "'\n"
<< "All InsetLayouts so far:"); << "All InsetLayouts so far:");
TextClass::InsetLayouts::const_iterator lit = TextClass::InsetLayouts::const_iterator lit =
tclass.insetLayouts().begin(); tclass.insetLayouts().begin();
TextClass::InsetLayouts::const_iterator len = TextClass::InsetLayouts::const_iterator len =
tclass.insetLayouts().end(); tclass.insetLayouts().end();
for (; lit != len; ++lit) for (; lit != len; ++lit)
lyxerr << lit->second.name() << "\n"; lyxerr << lit->second.name() << "\n";
@ -427,7 +433,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
break; break;
case IL_REQUIRES: { case IL_REQUIRES: {
lex.eatLine(); lex.eatLine();
vector<string> const req vector<string> const req
= support::getVectorFromString(lex.getString()); = support::getVectorFromString(lex.getString());
requires_.insert(req.begin(), req.end()); requires_.insert(req.begin(), req.end());
break; break;
@ -450,7 +456,7 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
// Here add element to list if getout == true // Here add element to list if getout == true
if (!getout) if (!getout)
return false; return false;
// The label font is generally used as-is without // The label font is generally used as-is without
// any realization against a given context. // any realization against a given context.
labelfont_.realize(sane_font); labelfont_.realize(sane_font);
@ -460,9 +466,8 @@ bool InsetLayout::read(Lexer & lex, TextClass const & tclass)
} }
InsetLayout::InsetLyXType translateLyXType(std::string const & str) InsetLayout::InsetLyXType translateLyXType(std::string const & str)
{ {
if (support::compare_ascii_no_case(str, "charstyle") == 0) if (support::compare_ascii_no_case(str, "charstyle") == 0)
return InsetLayout::CHARSTYLE; return InsetLayout::CHARSTYLE;
if (support::compare_ascii_no_case(str, "custom") == 0) if (support::compare_ascii_no_case(str, "custom") == 0)
@ -481,7 +486,7 @@ string const & InsetLayout::htmltag() const
{ {
if (htmltag_.empty()) if (htmltag_.empty())
htmltag_ = multipar_ ? "div" : "span"; htmltag_ = multipar_ ? "div" : "span";
return htmltag_; return htmltag_;
} }
@ -489,7 +494,7 @@ string const & InsetLayout::htmlattr() const
{ {
if (htmlattr_.empty()) if (htmlattr_.empty())
htmlattr_ = "class=\"" + defaultCSSClass() + "\""; htmlattr_ = "class=\"" + defaultCSSClass() + "\"";
return htmlattr_; return htmlattr_;
} }
@ -497,12 +502,12 @@ string const & InsetLayout::htmlinnerattr() const
{ {
if (htmlinnerattr_.empty()) if (htmlinnerattr_.empty())
htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\""; htmlinnerattr_ = "class=\"" + defaultCSSClass() + "_inner\"";
return htmlinnerattr_; return htmlinnerattr_;
} }
string InsetLayout::defaultCSSClass() const string InsetLayout::defaultCSSClass() const
{ {
if (!defaultcssclass_.empty()) if (!defaultcssclass_.empty())
return defaultcssclass_; return defaultcssclass_;
string d; string d;
@ -525,18 +530,18 @@ string InsetLayout::defaultCSSClass() const
void InsetLayout::makeDefaultCSS() const void InsetLayout::makeDefaultCSS() const
{ {
if (!htmldefaultstyle_.empty()) if (!htmldefaultstyle_.empty())
return; return;
docstring const mainfontCSS = font_.asCSS(); docstring const mainfontCSS = font_.asCSS();
if (!mainfontCSS.empty()) if (!mainfontCSS.empty())
htmldefaultstyle_ = htmldefaultstyle_ =
from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") + from_ascii(htmltag() + "." + defaultCSSClass() + " {\n") +
mainfontCSS + from_ascii("\n}\n"); mainfontCSS + from_ascii("\n}\n");
} }
docstring InsetLayout::htmlstyle() const docstring InsetLayout::htmlstyle() const
{ {
if (!htmlstyle_.empty() && !htmlforcecss_) if (!htmlstyle_.empty() && !htmlforcecss_)
return htmlstyle_; return htmlstyle_;
if (htmldefaultstyle_.empty()) if (htmldefaultstyle_.empty())

View File

@ -108,6 +108,8 @@ public:
/// this inset /// this inset
docstring const babelpreamble() const { return babelpreamble_; } docstring const babelpreamble() const { return babelpreamble_; }
/// ///
bool fixedwidthpreambleencoding() const { return fixedwidthpreambleencoding_; }
///
docstring counter() const { return counter_; } docstring counter() const { return counter_; }
/// ///
docstring refprefix() const { return refprefix_; } docstring refprefix() const { return refprefix_; }
@ -223,6 +225,8 @@ private:
/// Language and babel dependent macro definitions needed for this inset /// Language and babel dependent macro definitions needed for this inset
docstring babelpreamble_; docstring babelpreamble_;
/// ///
bool fixedwidthpreambleencoding_;
///
docstring refprefix_; docstring refprefix_;
/// ///
mutable std::string htmltag_; mutable std::string htmltag_;