From df329341aa9c39d11e3e751e12abb5e0e63c2949 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=BCrgen=20Spitzm=C3=BCller?= Date: Sun, 29 Nov 2009 14:43:00 +0000 Subject: [PATCH] * 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 --- src/Buffer.cpp | 2 +- src/BufferParams.cpp | 22 ++- src/BufferParams.h | 6 +- src/frontends/qt4/GuiDocument.cpp | 42 ++++++ src/frontends/qt4/GuiDocument.h | 1 + src/frontends/qt4/ui/FontUi.ui | 240 ++++++++++++++++-------------- 6 files changed, 195 insertions(+), 118 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 4968d3cfc3..e3ab0d298e 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -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 DepClean; typedef map > RefCache; diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 656ba12ccf..8c62dcf4ab 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -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 << '['; diff --git a/src/BufferParams.h b/src/BufferParams.h index fefa91b90f..87b8713c2a 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -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 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 diff --git a/src/frontends/qt4/GuiDocument.cpp b/src/frontends/qt4/GuiDocument.cpp index ee3d4e8d6c..36e47a5145 100644 --- a/src/frontends/qt4/GuiDocument.cpp +++ b/src/frontends/qt4/GuiDocument.cpp @@ -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"); diff --git a/src/frontends/qt4/GuiDocument.h b/src/frontends/qt4/GuiDocument.h index ea9924effc..96e3433aed 100644 --- a/src/frontends/qt4/GuiDocument.h +++ b/src/frontends/qt4/GuiDocument.h @@ -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); diff --git a/src/frontends/qt4/ui/FontUi.ui b/src/frontends/qt4/ui/FontUi.ui index f3f46934cf..da45733d7f 100644 --- a/src/frontends/qt4/ui/FontUi.ui +++ b/src/frontends/qt4/ui/FontUi.ui @@ -6,7 +6,7 @@ 0 0 543 - 361 + 341 @@ -19,113 +19,147 @@ 6 - - - - Qt::Vertical - - - QSizePolicy::Expanding + + + + + + + LaTe&X font encoding: - - - 391 - 16 - + + fontencCO - + - - + + - Use old style instead of lining figures + Specify the font encoding (e.g., T1). + + + + - Use &Old Style Figures + &Default Family: + + + fontsDefaultCO - - + + - Use a real small caps shape, if the font provides one + Select the default family for the document + + + + + + + + + + + - Use true S&mall Caps + &Base Size: + + + fontsizeCO - + - Qt::Horizontal + Qt::Vertical + + + QSizePolicy::Expanding - 151 - 20 + 525 + 41 - - - - Input the font to be used for Chinese, Japanese or Korean (CJK) script + + + + Qt::Horizontal - + + + 182 + 16 + + + - - + + - C&JK: + &Roman: - cjkFontLE + fontsRomanCO - - + + - Scale the Typewriter font to match the base font's dimensions + Select the roman (serif) typeface - - 200 + + + + + + Qt::Horizontal - - 10 + + + 131 + 20 + - + - - + + - Sc&ale (%): + &Sans Serif: - scaleTypewriterSB + fontsSansCO - - + + - Select the typewriter (monospaced) typeface + Select the Sans Serif (grotesque) typeface - - + + - &Typewriter: + S&cale (%): - fontsTypewriterCO + scaleSansSB - + Scale the Sans Serif font to match the base font's dimensions @@ -138,107 +172,93 @@ - - + + - S&cale (%): + &Typewriter: - scaleSansSB + fontsTypewriterCO - - + + - Select the Sans Serif (grotesque) typeface + Select the typewriter (monospaced) typeface - - + + - &Sans Serif: + Sc&ale (%): - fontsSansCO + scaleTypewriterSB - - - - Qt::Horizontal + + + + Scale the Typewriter font to match the base font's dimensions - - - 131 - 20 - + + 200 - - - - - - Select the roman (serif) typeface + + 10 - - + + - &Roman: + C&JK: - fontsRomanCO + cjkFontLE - + + + + Input the font to be used for Chinese, Japanese or Korean (CJK) script + + + + Qt::Horizontal - 182 - 16 + 151 + 20 - - + + - + Use a real small caps shape, if the font provides one - - - - - &Base Size: - - - fontsizeCO + Use true S&mall Caps - - + + - Select the default family for the document + Use old style instead of lining figures - - - - - &Default Family: - - - fontsDefaultCO + Use &Old Style Figures -- 2.39.2