]> git.lyx.org Git - features.git/commitdiff
* Add support for per-document fontenc setting (bug 5730)
authorJürgen Spitzmüller <spitz@lyx.org>
Sun, 29 Nov 2009 14:43:00 +0000 (14:43 +0000)
committerJürgen Spitzmüller <spitz@lyx.org>
Sun, 29 Nov 2009 14:43:00 +0000 (14:43 +0000)
File format change.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32228 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/BufferParams.cpp
src/BufferParams.h
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/GuiDocument.h
src/frontends/qt4/ui/FontUi.ui

index 4968d3cfc33f0367e91c76f40644eca403b0ceba..e3ab0d298e9c8a4ba8f5159a91c56d3f4afeb0c9 100644 (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;
index 656ba12ccf9827a9781ea956c4c06a031894c0b6..8c62dcf4ab7710d97c983b640e05ba8ab7b294ec 100644 (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 << '[';
index fefa91b90f4ff3e0da390feb6b12fe8be9e43e50..87b8713c2aa88ca09b37788005ef99b7864acb92 100644 (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
index ee3d4e8d6ca9262e664b4dc7cd9cb70d3c62ea4d..36e47a514555946eeb2cb1358a9d402a43649580 100644 (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");
index ea9924effccaf172720296d881d87027d54ed42c..96e3433aed924e380a372b8cefeffb0b07e9c2e6 100644 (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);
index f3f46934cffd313b242fd65e2d17fe2f554d7d09..da45733d7fbfc7bf32862923f29a87072ebc2d71 100644 (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" >
    <property name="spacing" >
     <number>6</number>
    </property>
-   <item row="8" column="0" colspan="4" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Vertical</enum>
-     </property>
-     <property name="sizeType" >
-      <enum>QSizePolicy::Expanding</enum>
+   <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="sizeHint" >
-      <size>
-       <width>391</width>
-       <height>16</height>
-      </size>
+     <property name="buddy" >
+      <cstring>fontencCO</cstring>
      </property>
-    </spacer>
+    </widget>
    </item>
-   <item row="7" column="1" >
-    <widget class="QCheckBox" name="fontOsfCB" >
+   <item row="1" column="3" colspan="2" >
+    <widget class="QLineEdit" name="fontencLE" >
      <property name="toolTip" >
-      <string>Use old style instead of lining figures</string>
+      <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>Use &amp;Old Style Figures</string>
+      <string>&amp;Default Family:</string>
+     </property>
+     <property name="buddy" >
+      <cstring>fontsDefaultCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="6" column="1" >
-    <widget class="QCheckBox" name="fontScCB" >
+   <item row="0" column="1" colspan="2" >
+    <widget class="QComboBox" name="fontsDefaultCO" >
      <property name="toolTip" >
-      <string>Use a real small caps shape, if the font provides one</string>
+      <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>Use true S&amp;mall Caps</string>
+      <string>&amp;Base Size:</string>
+     </property>
+     <property name="buddy" >
+      <cstring>fontsizeCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="5" column="2" colspan="2" >
+   <item row="9" column="0" colspan="5" >
     <spacer>
      <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
+      <enum>Qt::Vertical</enum>
+     </property>
+     <property name="sizeType" >
+      <enum>QSizePolicy::Expanding</enum>
      </property>
      <property name="sizeHint" >
       <size>
-       <width>151</width>
-       <height>20</height>
+       <width>525</width>
+       <height>41</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>
+   <item row="2" column="1" colspan="2" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
      </property>
-    </widget>
+     <property name="sizeHint" >
+      <size>
+       <width>182</width>
+       <height>16</height>
+      </size>
+     </property>
+    </spacer>
    </item>
-   <item row="5" column="0" >
-    <widget class="QLabel" name="cjkFontLA" >
+   <item row="3" column="0" >
+    <widget class="QLabel" name="fontsRomanLA" >
      <property name="text" >
-      <string>C&amp;JK:</string>
+      <string>&amp;Roman:</string>
      </property>
      <property name="buddy" >
-      <cstring>cjkFontLE</cstring>
+      <cstring>fontsRomanCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="4" column="3" >
-    <widget class="QSpinBox" name="scaleTypewriterSB" >
+   <item row="3" column="1" colspan="2" >
+    <widget class="QComboBox" name="fontsRomanCO" >
      <property name="toolTip" >
-      <string>Scale the Typewriter font to match the base font's dimensions</string>
+      <string>Select the roman (serif) typeface</string>
      </property>
-     <property name="maximum" >
-      <number>200</number>
+    </widget>
+   </item>
+   <item row="3" column="3" colspan="2" >
+    <spacer>
+     <property name="orientation" >
+      <enum>Qt::Horizontal</enum>
      </property>
-     <property name="minimum" >
-      <number>10</number>
+     <property name="sizeHint" >
+      <size>
+       <width>131</width>
+       <height>20</height>
+      </size>
      </property>
-    </widget>
+    </spacer>
    </item>
-   <item row="4" column="2" >
-    <widget class="QLabel" name="scaleTypewriterLA" >
+   <item row="4" column="0" >
+    <widget class="QLabel" name="fontsSansLA" >
      <property name="text" >
-      <string>Sc&amp;ale (%):</string>
+      <string>&amp;Sans Serif:</string>
      </property>
      <property name="buddy" >
-      <cstring>scaleTypewriterSB</cstring>
+      <cstring>fontsSansCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="4" column="1" >
-    <widget class="QComboBox" name="fontsTypewriterCO" >
+   <item row="4" column="1" colspan="2" >
+    <widget class="QComboBox" name="fontsSansCO" >
      <property name="toolTip" >
-      <string>Select the typewriter (monospaced) typeface</string>
+      <string>Select the Sans Serif (grotesque) typeface</string>
      </property>
     </widget>
    </item>
-   <item row="4" column="0" >
-    <widget class="QLabel" name="fontsTypewriterLA" >
+   <item row="4" column="3" >
+    <widget class="QLabel" name="scaleSansLA" >
      <property name="text" >
-      <string>&amp;Typewriter:</string>
+      <string>S&amp;cale (%):</string>
      </property>
      <property name="buddy" >
-      <cstring>fontsTypewriterCO</cstring>
+      <cstring>scaleSansSB</cstring>
      </property>
     </widget>
    </item>
-   <item row="3" column="3" >
+   <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>
     </widget>
    </item>
-   <item row="3" column="2" >
-    <widget class="QLabel" name="scaleSansLA" >
+   <item row="5" column="0" >
+    <widget class="QLabel" name="fontsTypewriterLA" >
      <property name="text" >
-      <string>S&amp;cale (%):</string>
+      <string>&amp;Typewriter:</string>
      </property>
      <property name="buddy" >
-      <cstring>scaleSansSB</cstring>
+      <cstring>fontsTypewriterCO</cstring>
      </property>
     </widget>
    </item>
-   <item row="3" column="1" >
-    <widget class="QComboBox" name="fontsSansCO" >
+   <item row="5" column="1" colspan="2" >
+    <widget class="QComboBox" name="fontsTypewriterCO" >
      <property name="toolTip" >
-      <string>Select the Sans Serif (grotesque) typeface</string>
+      <string>Select the typewriter (monospaced) typeface</string>
      </property>
     </widget>
    </item>
-   <item row="3" column="0" >
-    <widget class="QLabel" name="fontsSansLA" >
+   <item row="5" column="3" >
+    <widget class="QLabel" name="scaleTypewriterLA" >
      <property name="text" >
-      <string>&amp;Sans Serif:</string>
+      <string>Sc&amp;ale (%):</string>
      </property>
      <property name="buddy" >
-      <cstring>fontsSansCO</cstring>
+      <cstring>scaleTypewriterSB</cstring>
      </property>
     </widget>
    </item>
-   <item row="2" column="2" colspan="2" >
-    <spacer>
-     <property name="orientation" >
-      <enum>Qt::Horizontal</enum>
+   <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="sizeHint" >
-      <size>
-       <width>131</width>
-       <height>20</height>
-      </size>
+     <property name="maximum" >
+      <number>200</number>
      </property>
-    </spacer>
-   </item>
-   <item row="2" column="1" >
-    <widget class="QComboBox" name="fontsRomanCO" >
-     <property name="toolTip" >
-      <string>Select the roman (serif) typeface</string>
+     <property name="minimum" >
+      <number>10</number>
      </property>
     </widget>
    </item>
-   <item row="2" column="0" >
-    <widget class="QLabel" name="fontsRomanLA" >
+   <item row="6" column="0" >
+    <widget class="QLabel" name="cjkFontLA" >
      <property name="text" >
-      <string>&amp;Roman:</string>
+      <string>C&amp;JK:</string>
      </property>
      <property name="buddy" >
-      <cstring>fontsRomanCO</cstring>
+      <cstring>cjkFontLE</cstring>
      </property>
     </widget>
    </item>
-   <item row="1" column="1" >
+   <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>182</width>
-       <height>16</height>
+       <width>151</width>
+       <height>20</height>
       </size>
      </property>
     </spacer>
    </item>
-   <item row="0" column="3" >
-    <widget class="QComboBox" name="fontsizeCO" >
+   <item row="7" column="1" colspan="2" >
+    <widget class="QCheckBox" name="fontScCB" >
      <property name="toolTip" >
-      <string/>
+      <string>Use a real small caps shape, if the font provides one</string>
      </property>
-    </widget>
-   </item>
-   <item row="0" column="2" >
-    <widget class="QLabel" name="TextLabel2_2" >
      <property name="text" >
-      <string>&amp;Base Size:</string>
-     </property>
-     <property name="buddy" >
-      <cstring>fontsizeCO</cstring>
+      <string>Use true S&amp;mall Caps</string>
      </property>
     </widget>
    </item>
-   <item row="0" column="1" >
-    <widget class="QComboBox" name="fontsDefaultCO" >
+   <item row="8" column="1" colspan="2" >
+    <widget class="QCheckBox" name="fontOsfCB" >
      <property name="toolTip" >
-      <string>Select the default family for the document</string>
+      <string>Use old style instead of lining figures</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>
+      <string>Use &amp;Old Style Figures</string>
      </property>
     </widget>
    </item>