* 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 // Do not remove the comment below, so we get merge conflict in
// independent branches. Instead add your own. // 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<string, bool> DepClean;
typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache; typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>543</width> <width>543</width>
<height>361</height> <height>341</height>
</rect> </rect>
</property> </property>
<property name="windowTitle" > <property name="windowTitle" >
@ -19,7 +19,61 @@
<property name="spacing" > <property name="spacing" >
<number>6</number> <number>6</number>
</property> </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> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Vertical</enum> <enum>Qt::Vertical</enum>
@ -29,173 +83,13 @@
</property> </property>
<property name="sizeHint" > <property name="sizeHint" >
<size> <size>
<width>391</width> <width>525</width>
<height>16</height> <height>41</height>
</size> </size>
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="7" column="1" > <item row="2" 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>
<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" >
<spacer> <spacer>
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
@ -208,37 +102,163 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item row="0" column="3" > <item row="3" column="0" >
<widget class="QComboBox" name="fontsizeCO" > <widget class="QLabel" name="fontsRomanLA" >
<property name="toolTip" >
<string/>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QLabel" name="TextLabel2_2" >
<property name="text" > <property name="text" >
<string>&amp;Base Size:</string> <string>&amp;Roman:</string>
</property> </property>
<property name="buddy" > <property name="buddy" >
<cstring>fontsizeCO</cstring> <cstring>fontsRomanCO</cstring>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1" > <item row="3" column="1" colspan="2" >
<widget class="QComboBox" name="fontsDefaultCO" > <widget class="QComboBox" name="fontsRomanCO" >
<property name="toolTip" > <property name="toolTip" >
<string>Select the default family for the document</string> <string>Select the roman (serif) typeface</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="0" > <item row="3" column="3" colspan="2" >
<widget class="QLabel" name="fontsDefaultLA" > <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" > <property name="text" >
<string>&amp;Default Family:</string> <string>&amp;Sans Serif:</string>
</property> </property>
<property name="buddy" > <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> </property>
</widget> </widget>
</item> </item>