* Add support for per-document fontenc setting (bug 5730)

File format change.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32228 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Jürgen Spitzmüller 2009-11-29 14:43:00 +00:00
parent 2d0195723d
commit df329341aa
6 changed files with 268 additions and 191 deletions

View File

@ -127,7 +127,7 @@ namespace {
// Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own.
int const LYX_FORMAT = 371; // uwestoehr: option to turn off mhchem
int const LYX_FORMAT = 372; // jspitzm: buffer param fontenc
typedef map<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

@ -346,6 +346,7 @@ BufferParams::BufferParams()
secnumdepth = 3;
tocdepth = 3;
language = default_language;
fontenc = "global";
fontsRoman = "default";
fontsSans = "default";
fontsTypewriter = "default";
@ -557,6 +558,9 @@ string BufferParams::readToken(Lexer & lex, string const & token,
} else if (token == "\\index_command") {
lex.eatLine();
index_command = lex.getString();
} else if (token == "\\fontencoding") {
lex.eatLine();
fontenc = lex.getString();
} else if (token == "\\font_roman") {
lex.eatLine();
fontsRoman = lex.getString();
@ -838,6 +842,7 @@ void BufferParams::writeFile(ostream & os) const
if (language != ignore_language)
os << "\\language " << language->lang() << '\n';
os << "\\inputencoding " << inputenc
<< "\n\\fontencoding " << fontenc
<< "\n\\font_roman " << fontsRoman
<< "\n\\font_sans " << fontsSans
<< "\n\\font_typewriter " << fontsTypewriter
@ -1216,19 +1221,18 @@ bool BufferParams::writeLaTeX(odocstream & os, LaTeXFeatures & features,
<< from_ascii(fontsDefaultFamily) << "}\n";
// set font encoding
// this one is not per buffer
// for arabic_arabi and farsi we also need to load the LAE and
// LFE encoding
// XeTeX works without fontenc
if (lyxrc.fontenc != "default" && language->lang() != "japanese"
if (font_encoding() != "default" && language->lang() != "japanese"
&& !useXetex) {
if (language->lang() == "arabic_arabi"
|| language->lang() == "farsi") {
os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
os << "\\usepackage[" << from_ascii(font_encoding())
<< ",LFE,LAE]{fontenc}\n";
texrow.newline();
} else {
os << "\\usepackage[" << from_ascii(lyxrc.fontenc)
os << "\\usepackage[" << from_ascii(font_encoding())
<< "]{fontenc}\n";
texrow.newline();
}
@ -1983,6 +1987,12 @@ string const BufferParams::dvips_options() const
}
string const BufferParams::font_encoding() const
{
return (fontenc == "global") ? lyxrc.fontenc : fontenc;
}
string BufferParams::babelCall(string const & lang_opts) const
{
string lang_pack = lyxrc.language_package;
@ -2198,7 +2208,7 @@ string const BufferParams::loadFonts(string const & rm,
// AE
else if (rm == "ae") {
// not needed when using OT1 font encoding.
if (lyxrc.fontenc != "default")
if (font_encoding() != "default")
os << "\\usepackage{ae,aecompl}\n";
}
// Times
@ -2237,7 +2247,7 @@ string const BufferParams::loadFonts(string const & rm,
// fourier supersedes utopia.sty, but does
// not work with OT1 encoding.
if (LaTeXFeatures::isAvailable("fourier")
&& lyxrc.fontenc != "default") {
&& font_encoding() != "default") {
os << "\\usepackage";
if (osf || sc) {
os << '[';

View File

@ -157,7 +157,7 @@ public:
/// returns the main font for the buffer (document)
Font const getFont() const;
/* this are for the PaperLayout */
/* these are for the PaperLayout */
/// the papersize
PAPER_SIZE papersize;
///
@ -194,6 +194,8 @@ public:
std::string bibtex_command;
/// customized index processor
std::string index_command;
/// font encoding
std::string fontenc;
/// the rm font
std::string fontsRoman;
/// the sf font
@ -316,6 +318,8 @@ public:
/// map of the file's author IDs to AuthorList indexes
std::map<unsigned int, int> author_map;
/// the buffer's font encoding
std::string const font_encoding() const;
///
std::string const dvips_options() const;
/** The return value of paperSizeName() depends on the

View File

@ -643,6 +643,12 @@ GuiDocument::GuiDocument(GuiView & lv)
this, SLOT(ttChanged(int)));
connect(fontModule->fontsDefaultCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
connect(fontModule->fontencCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
connect(fontModule->fontencCO, SIGNAL(activated(int)),
this, SLOT(fontencChanged(int)));
connect(fontModule->fontencLE, SIGNAL(textChanged(const QString &)),
this, SLOT(change_adaptor()));
connect(fontModule->fontsizeCO, SIGNAL(activated(int)),
this, SLOT(change_adaptor()));
connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
@ -663,6 +669,10 @@ GuiDocument::GuiDocument(GuiView & lv)
fontModule->fontsizeCO->addItem(qt_("11"));
fontModule->fontsizeCO->addItem(qt_("12"));
fontModule->fontencCO->addItem(qt_("Default"));
fontModule->fontencCO->addItem(qt_("Custom"));
fontModule->fontencCO->addItem(qt_("None (no fontenc)"));
for (int n = 0; GuiDocument::fontfamilies_gui[n][0]; ++n)
fontModule->fontsDefaultCO->addItem(
qt_(GuiDocument::fontfamilies_gui[n]));
@ -1324,6 +1334,10 @@ void GuiDocument::xetexChanged(bool xetex)
font = tex_fonts_roman[fontModule->fontsRomanCO->currentIndex()];
fontModule->fontScCB->setEnabled(providesSC(font));
fontModule->fontOsfCB->setEnabled(providesOSF(font));
fontModule->fontencLA->setEnabled(!xetex);
fontModule->fontencCO->setEnabled(!xetex);
fontModule->fontencLE->setEnabled(!xetex);
}
@ -1388,6 +1402,12 @@ void GuiDocument::updateFontlist()
}
void GuiDocument::fontencChanged(int item)
{
fontModule->fontencLE->setEnabled(item == 1);
}
void GuiDocument::romanChanged(int item)
{
if (outputModule->xetexCB->isChecked())
@ -2067,6 +2087,13 @@ void GuiDocument::applyView()
tex_fonts_monospaced[fontModule->fontsTypewriterCO->currentIndex()];
}
if (fontModule->fontencCO->currentIndex() == 0)
bp_.fontenc = "global";
else if (fontModule->fontencCO->currentIndex() == 1)
bp_.fontenc = fromqstr(fontModule->fontencLE->text());
else if (fontModule->fontencCO->currentIndex() == 2)
bp_.fontenc = "default";
bp_.fontsCJK =
fromqstr(fontModule->cjkFontLE->text());
@ -2421,6 +2448,9 @@ void GuiDocument::paramsToDialog()
bp_.fontsize);
if (bp_.useXetex) {
fontModule->fontencLA->setEnabled(false);
fontModule->fontencCO->setEnabled(false);
fontModule->fontencLE->setEnabled(false);
for (int i = 0; i < fontModule->fontsRomanCO->count(); ++i) {
if (fontModule->fontsRomanCO->itemText(i) == toqstr(bp_.fontsRoman)) {
fontModule->fontsRomanCO->setCurrentIndex(i);
@ -2442,6 +2472,9 @@ void GuiDocument::paramsToDialog()
}
}
} else {
fontModule->fontencLA->setEnabled(true);
fontModule->fontencCO->setEnabled(true);
fontModule->fontencLE->setEnabled(true);
int n = findToken(tex_fonts_roman, bp_.fontsRoman);
if (n >= 0) {
fontModule->fontsRomanCO->setCurrentIndex(n);
@ -2476,6 +2509,15 @@ void GuiDocument::paramsToDialog()
if (nn >= 0)
fontModule->fontsDefaultCO->setCurrentIndex(nn);
if (bp_.fontenc == "global")
fontModule->fontencCO->setCurrentIndex(0);
else if (bp_.fontenc == "default")
fontModule->fontencCO->setCurrentIndex(2);
else {
fontModule->fontencCO->setCurrentIndex(1);
fontModule->fontencLE->setText(toqstr(bp_.fontenc));
}
// paper
bool const extern_geometry =
documentClass().provides("geometry");

View File

@ -91,6 +91,7 @@ private Q_SLOTS:
void papersizeChanged(int);
void setColSep();
void setCustomMargins(bool);
void fontencChanged(int);
void romanChanged(int);
void sansChanged(int);
void ttChanged(int);

View File

@ -6,7 +6,7 @@
<x>0</x>
<y>0</y>
<width>543</width>
<height>361</height>
<height>341</height>
</rect>
</property>
<property name="windowTitle" >
@ -19,7 +19,61 @@
<property name="spacing" >
<number>6</number>
</property>
<item row="8" column="0" colspan="4" >
<item row="1" column="2" >
<widget class="QComboBox" name="fontencCO" />
</item>
<item row="1" column="0" colspan="2" >
<widget class="QLabel" name="fontencLA" >
<property name="text" >
<string>LaTe&amp;X font encoding:</string>
</property>
<property name="buddy" >
<cstring>fontencCO</cstring>
</property>
</widget>
</item>
<item row="1" column="3" colspan="2" >
<widget class="QLineEdit" name="fontencLE" >
<property name="toolTip" >
<string>Specify the font encoding (e.g., T1).</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="fontsDefaultLA" >
<property name="text" >
<string>&amp;Default Family:</string>
</property>
<property name="buddy" >
<cstring>fontsDefaultCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2" >
<widget class="QComboBox" name="fontsDefaultCO" >
<property name="toolTip" >
<string>Select the default family for the document</string>
</property>
</widget>
</item>
<item row="0" column="4" >
<widget class="QComboBox" name="fontsizeCO" >
<property name="toolTip" >
<string/>
</property>
</widget>
</item>
<item row="0" column="3" >
<widget class="QLabel" name="TextLabel2_2" >
<property name="text" >
<string>&amp;Base Size:</string>
</property>
<property name="buddy" >
<cstring>fontsizeCO</cstring>
</property>
</widget>
</item>
<item row="9" column="0" colspan="5" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
@ -29,173 +83,13 @@
</property>
<property name="sizeHint" >
<size>
<width>391</width>
<height>16</height>
<width>525</width>
<height>41</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1" >
<widget class="QCheckBox" name="fontOsfCB" >
<property name="toolTip" >
<string>Use old style instead of lining figures</string>
</property>
<property name="text" >
<string>Use &amp;Old Style Figures</string>
</property>
</widget>
</item>
<item row="6" column="1" >
<widget class="QCheckBox" name="fontScCB" >
<property name="toolTip" >
<string>Use a real small caps shape, if the font provides one</string>
</property>
<property name="text" >
<string>Use true S&amp;mall Caps</string>
</property>
</widget>
</item>
<item row="5" column="2" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>151</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="5" column="1" >
<widget class="QLineEdit" name="cjkFontLE" >
<property name="toolTip" >
<string>Input the font to be used for Chinese, Japanese or Korean (CJK) script</string>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QLabel" name="cjkFontLA" >
<property name="text" >
<string>C&amp;JK:</string>
</property>
<property name="buddy" >
<cstring>cjkFontLE</cstring>
</property>
</widget>
</item>
<item row="4" column="3" >
<widget class="QSpinBox" name="scaleTypewriterSB" >
<property name="toolTip" >
<string>Scale the Typewriter font to match the base font's dimensions</string>
</property>
<property name="maximum" >
<number>200</number>
</property>
<property name="minimum" >
<number>10</number>
</property>
</widget>
</item>
<item row="4" column="2" >
<widget class="QLabel" name="scaleTypewriterLA" >
<property name="text" >
<string>Sc&amp;ale (%):</string>
</property>
<property name="buddy" >
<cstring>scaleTypewriterSB</cstring>
</property>
</widget>
</item>
<item row="4" column="1" >
<widget class="QComboBox" name="fontsTypewriterCO" >
<property name="toolTip" >
<string>Select the typewriter (monospaced) typeface</string>
</property>
</widget>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="fontsTypewriterLA" >
<property name="text" >
<string>&amp;Typewriter:</string>
</property>
<property name="buddy" >
<cstring>fontsTypewriterCO</cstring>
</property>
</widget>
</item>
<item row="3" column="3" >
<widget class="QSpinBox" name="scaleSansSB" >
<property name="toolTip" >
<string>Scale the Sans Serif font to match the base font's dimensions</string>
</property>
<property name="maximum" >
<number>200</number>
</property>
<property name="minimum" >
<number>10</number>
</property>
</widget>
</item>
<item row="3" column="2" >
<widget class="QLabel" name="scaleSansLA" >
<property name="text" >
<string>S&amp;cale (%):</string>
</property>
<property name="buddy" >
<cstring>scaleSansSB</cstring>
</property>
</widget>
</item>
<item row="3" column="1" >
<widget class="QComboBox" name="fontsSansCO" >
<property name="toolTip" >
<string>Select the Sans Serif (grotesque) typeface</string>
</property>
</widget>
</item>
<item row="3" column="0" >
<widget class="QLabel" name="fontsSansLA" >
<property name="text" >
<string>&amp;Sans Serif:</string>
</property>
<property name="buddy" >
<cstring>fontsSansCO</cstring>
</property>
</widget>
</item>
<item row="2" column="2" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>131</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" >
<widget class="QComboBox" name="fontsRomanCO" >
<property name="toolTip" >
<string>Select the roman (serif) typeface</string>
</property>
</widget>
</item>
<item row="2" column="0" >
<widget class="QLabel" name="fontsRomanLA" >
<property name="text" >
<string>&amp;Roman:</string>
</property>
<property name="buddy" >
<cstring>fontsRomanCO</cstring>
</property>
</widget>
</item>
<item row="1" column="1" >
<item row="2" column="1" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
@ -208,37 +102,163 @@
</property>
</spacer>
</item>
<item row="0" column="3" >
<widget class="QComboBox" name="fontsizeCO" >
<property name="toolTip" >
<string/>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="TextLabel2_2" >
<item row="3" column="0" >
<widget class="QLabel" name="fontsRomanLA" >
<property name="text" >
<string>&amp;Base Size:</string>
<string>&amp;Roman:</string>
</property>
<property name="buddy" >
<cstring>fontsizeCO</cstring>
<cstring>fontsRomanCO</cstring>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QComboBox" name="fontsDefaultCO" >
<item row="3" column="1" colspan="2" >
<widget class="QComboBox" name="fontsRomanCO" >
<property name="toolTip" >
<string>Select the default family for the document</string>
<string>Select the roman (serif) typeface</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QLabel" name="fontsDefaultLA" >
<item row="3" column="3" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>131</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="4" column="0" >
<widget class="QLabel" name="fontsSansLA" >
<property name="text" >
<string>&amp;Default Family:</string>
<string>&amp;Sans Serif:</string>
</property>
<property name="buddy" >
<cstring>fontsDefaultCO</cstring>
<cstring>fontsSansCO</cstring>
</property>
</widget>
</item>
<item row="4" column="1" colspan="2" >
<widget class="QComboBox" name="fontsSansCO" >
<property name="toolTip" >
<string>Select the Sans Serif (grotesque) typeface</string>
</property>
</widget>
</item>
<item row="4" column="3" >
<widget class="QLabel" name="scaleSansLA" >
<property name="text" >
<string>S&amp;cale (%):</string>
</property>
<property name="buddy" >
<cstring>scaleSansSB</cstring>
</property>
</widget>
</item>
<item row="4" column="4" >
<widget class="QSpinBox" name="scaleSansSB" >
<property name="toolTip" >
<string>Scale the Sans Serif font to match the base font's dimensions</string>
</property>
<property name="maximum" >
<number>200</number>
</property>
<property name="minimum" >
<number>10</number>
</property>
</widget>
</item>
<item row="5" column="0" >
<widget class="QLabel" name="fontsTypewriterLA" >
<property name="text" >
<string>&amp;Typewriter:</string>
</property>
<property name="buddy" >
<cstring>fontsTypewriterCO</cstring>
</property>
</widget>
</item>
<item row="5" column="1" colspan="2" >
<widget class="QComboBox" name="fontsTypewriterCO" >
<property name="toolTip" >
<string>Select the typewriter (monospaced) typeface</string>
</property>
</widget>
</item>
<item row="5" column="3" >
<widget class="QLabel" name="scaleTypewriterLA" >
<property name="text" >
<string>Sc&amp;ale (%):</string>
</property>
<property name="buddy" >
<cstring>scaleTypewriterSB</cstring>
</property>
</widget>
</item>
<item row="5" column="4" >
<widget class="QSpinBox" name="scaleTypewriterSB" >
<property name="toolTip" >
<string>Scale the Typewriter font to match the base font's dimensions</string>
</property>
<property name="maximum" >
<number>200</number>
</property>
<property name="minimum" >
<number>10</number>
</property>
</widget>
</item>
<item row="6" column="0" >
<widget class="QLabel" name="cjkFontLA" >
<property name="text" >
<string>C&amp;JK:</string>
</property>
<property name="buddy" >
<cstring>cjkFontLE</cstring>
</property>
</widget>
</item>
<item row="6" column="1" colspan="2" >
<widget class="QLineEdit" name="cjkFontLE" >
<property name="toolTip" >
<string>Input the font to be used for Chinese, Japanese or Korean (CJK) script</string>
</property>
</widget>
</item>
<item row="6" column="3" colspan="2" >
<spacer>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" >
<size>
<width>151</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="7" column="1" colspan="2" >
<widget class="QCheckBox" name="fontScCB" >
<property name="toolTip" >
<string>Use a real small caps shape, if the font provides one</string>
</property>
<property name="text" >
<string>Use true S&amp;mall Caps</string>
</property>
</widget>
</item>
<item row="8" column="1" colspan="2" >
<widget class="QCheckBox" name="fontOsfCB" >
<property name="toolTip" >
<string>Use old style instead of lining figures</string>
</property>
<property name="text" >
<string>Use &amp;Old Style Figures</string>
</property>
</widget>
</item>