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/
\lyxformat 479
\lyxformat 480
\begin_document
\begin_header
\textclass scrbook
@ -151,6 +151,7 @@ End
\html_css_as_file 0
\html_be_strict true
\author -712698321 "Jürgen Spitzmüller"
\author -195340706 "Georg Baum"
\author 274215730 "scott"
\end_header
@ -16901,6 +16902,86 @@ LabelFont
\end_inset
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
\begin_layout Description

View File

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

View File

@ -177,6 +177,9 @@ import os, re, string, sys
# Incremented to format 53, 7 December 2014 by spitz
# 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
# Manual (section "Declaring a new text class").
@ -184,7 +187,7 @@ import os, re, string, sys
# development/tools/updatelayouts.py script to update all
# layout files to the new format.
currentFormat = 53
currentFormat = 54
def usage(prog_name):
@ -408,7 +411,7 @@ def convert(lines):
i += 1
continue
if format >= 50 and format <= 52:
if format >= 50 and format <= 53:
# nothing to do.
i += 1
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
// \lstlistlistingname and \lstlistingname (bug 9382).
// This needs to be consistent with InsetListings::latex().
docstring const ilname = it->second.name();
bool const need_fixedwidth = !runparams_.isFullUnicode() &&
(ilname == "Listings" ||
ilname == "Include:Listings" ||
ilname == "TOC:Listings");
bool const need_fixedwidth = it->second.fixedwidthpreambleencoding();
// language dependent commands (once per document)
snippets.insert(i18npreamble(it->second.langpreamble(),
buffer().language(),

View File

@ -61,7 +61,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script,
// 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 {

View File

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

View File

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