]> git.lyx.org Git - features.git/commitdiff
Introduce basic support for microtype.sty.
authorPavel Sanda <sanda@lyx.org>
Fri, 3 Jun 2016 05:40:21 +0000 (22:40 -0700)
committerPavel Sanda <sanda@lyx.org>
Fri, 3 Jun 2016 05:48:58 +0000 (22:48 -0700)
https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg192743.html

12 files changed:
development/FORMAT
lib/lyx2lyx/LyX.py
lib/lyx2lyx/Makefile.am
lib/lyx2lyx/lyx_2_3.py [new file with mode: 0644]
src/BufferParams.cpp
src/BufferParams.h
src/LaTeXFeatures.cpp
src/frontends/qt4/GuiDocument.cpp
src/frontends/qt4/ui/FontUi.ui
src/tex2lyx/Preamble.cpp
src/tex2lyx/Preamble.h
src/version.h

index 01319dff51b5b713358ca75130f1a2d50434132b..f7bb30f08b4a0439d7a7f06c2547198cc1bd57af 100644 (file)
@@ -11,6 +11,11 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx.
 
 -----------------------
 
+2016-06-16 Pavel Sanda <sanda@lyx.org>
+       * Format incremented to 509.
+       New parameter "\use_microtype bool" for including microtype LaTeX
+       package into preamble.
+
 2016-04-05 Enrico Forestieri <forenr@lyx.org>
        * Format incremented to 508
          New kind of Separator inset (latexpar). The old parbreak separator
index 1e2147d54997b31bfd86fd4d5495eabe19b5aa62..fa2bbba6195a8b6010e07a2ac8459a29006e0f87 100644 (file)
@@ -33,7 +33,7 @@ try:
     import lyx2lyx_version
     version__ = lyx2lyx_version.version
 except: # we are running from build directory so assume the last version
-    version__ = '2.2'
+    version__ = '2.3'
 
 default_debug__ = 2
 
@@ -86,7 +86,8 @@ format_relation = [("0_06",    [200], minor_versions("0.6" , 4)),
                    ("1_6", list(range(277,346)), minor_versions("1.6" , 10)),
                    ("2_0", list(range(346,414)), minor_versions("2.0" , 8)),
                    ("2_1", list(range(414,475)), minor_versions("2.1" , 5)),
-                   ("2_2", list(range(475,509)), minor_versions("2.2" , 0))
+                   ("2_2", list(range(475,509)), minor_versions("2.2" , 0)),
+                   ("2_3", list(range(509,510)), minor_versions("2.3" , 0))
                   ]
 
 ####################################################################
index 4490cb72f30a8b9561afca672c32aa5afe59548b..89ba23b1f20a33f922fb11c8b46c5dc60ba38e4d 100644 (file)
@@ -33,6 +33,7 @@ dist_lyx2lyx_PYTHON = \
        lyx_2_0.py \
        lyx_2_1.py \
        lyx_2_2.py \
+       lyx_2_3.py \
        profiling.py \
        test_parser_tools.py
 
diff --git a/lib/lyx2lyx/lyx_2_3.py b/lib/lyx2lyx/lyx_2_3.py
new file mode 100644 (file)
index 0000000..08ca2f0
--- /dev/null
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# This file is part of lyx2lyx
+# -*- coding: utf-8 -*-
+# Copyright (C) 2016 The LyX team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+
+""" Convert files to the file format generated by lyx 2.3"""
+
+import re, string
+import unicodedata
+import sys, os
+
+# Uncomment only what you need to import, please.
+
+#from parser_tools import find_token, find_end_of, find_tokens, \
+#  find_token_exact, find_end_of_inset, find_end_of_layout, \
+#  find_token_backwards, is_in_inset, get_value, get_quoted_value, \
+#  del_token, check_token, get_option_value
+
+#from lyx2lyx_tools import add_to_preamble, put_cmd_in_ert, get_ert, lyx2latex, \
+#  lyx2verbatim, length_in_bp, convert_info_insets
+#  insert_to_preamble, latex_length, revert_flex_inset, \
+#  revert_font_attrs, hex2ratio, str2bool
+
+from parser_tools import find_token
+
+####################################################################
+# Private helper functions
+
+
+
+###############################################################################
+###
+### Conversion and reversion routines
+###
+###############################################################################
+
+def revert_microtype(document):
+    " Remove microtype settings. "
+    i = find_token(document.header, "\\use_microtype", 0)
+    if i == -1:
+        return
+    del document.header[i]
+
+
+
+##
+# Conversion hub
+#
+
+supported_versions = ["2.3.0", "2.3"]
+convert = [
+           [509, []]
+          ]
+
+revert =  [
+           [508, [revert_microtype]]
+          ]
+
+
+if __name__ == "__main__":
+    pass
index 9d121cb4f410dc3a322521ee58024de9e085558f..bcf8d6450330495a537ce0a5458bf84ceeed8a1e 100644 (file)
@@ -388,6 +388,7 @@ BufferParams::BufferParams()
        fonts_math[1] = "auto";
        fonts_default_family = "default";
        useNonTeXFonts = false;
+       use_microtype = false;
        fonts_expert_sc = false;
        fonts_old_figures = false;
        fonts_sans_scale[0] = 100;
@@ -771,6 +772,8 @@ string BufferParams::readToken(Lexer & lex, string const & token,
                lex >> fonts_typewriter_scale[1];
        } else if (token == "\\font_cjk") {
                lex >> fonts_cjk;
+       } else if (token == "\\use_microtype") {
+               lex >> use_microtype;
        } else if (token == "\\paragraph_separation") {
                string parsep;
                lex >> parsep;
@@ -1139,6 +1142,7 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const
        if (!fonts_cjk.empty()) {
                os << "\\font_cjk " << fonts_cjk << '\n';
        }
+       os << "\\use_microtype " << convert<string>(use_microtype) << '\n';
        os << "\\graphics " << graphics_driver << '\n';
        os << "\\default_output_format " << default_output_format << '\n';
        os << "\\output_sync " << output_sync << '\n';
@@ -1411,6 +1415,9 @@ void BufferParams::validate(LaTeXFeatures & features) const
 
        if (useNonTeXFonts && fontsMath() != "auto")
                features.require("unicode-math");
+       
+       if (use_microtype)
+               features.require("microtype");
 
        if (!language->requires().empty())
                features.require(language->requires());
index f62911c2626b4ad5ca889556bf1872a619283131..7314b421b2bc1d9340cbf9944738d4a645497fd7 100644 (file)
@@ -278,6 +278,8 @@ public:
        int fontsTypewriterScale() const { return fonts_typewriter_scale[useNonTeXFonts]; }
        /// the font used by the CJK command
        std::string fonts_cjk;
+       /// use LaTeX microtype package
+       bool use_microtype;
        ///
        Spacing & spacing();
        Spacing const & spacing() const;
index 4fa2c829412aee1bb826b189f0fa9a836d3dffe7..3a2e775316167c292de4e795d7bb2058a7ae2ae6 100644 (file)
@@ -1132,6 +1132,10 @@ string const LaTeXFeatures::getPackages() const
        if (mustProvide("footmisc"))
                packages << "\\PassOptionsToPackage{stable}{footmisc}\n";
 
+       if (mustProvide("microtype")){
+               packages << "\\usepackage{microtype}\n";
+       }
+
        return packages.str();
 }
 
index 15fb71958fdf6da052afab73767b667b5701775f..25356d921e02ee3722da597d134d635a3a807cfa 100644 (file)
@@ -809,6 +809,8 @@ GuiDocument::GuiDocument(GuiView & lv)
                this, SLOT(change_adaptor()));
        connect(fontModule->cjkFontLE, SIGNAL(textChanged(const QString &)),
                this, SLOT(change_adaptor()));
+       connect(fontModule->microtypeCB, SIGNAL(clicked()),
+               this, SLOT(change_adaptor()));
        connect(fontModule->scaleSansSB, SIGNAL(valueChanged(int)),
                this, SLOT(change_adaptor()));
        connect(fontModule->scaleTypewriterSB, SIGNAL(valueChanged(int)),
@@ -2889,6 +2891,8 @@ void GuiDocument::applyView()
        bp_.fonts_cjk =
                fromqstr(fontModule->cjkFontLE->text());
 
+       bp_.use_microtype = fontModule->microtypeCB->isChecked();
+
        bp_.fonts_sans_scale[nontexfonts] = fontModule->scaleSansSB->value();
        bp_.fonts_sans_scale[!nontexfonts] = fontModule->font_sf_scale;
 
@@ -3368,6 +3372,8 @@ void GuiDocument::paramsToDialog()
                        toqstr(bp_.fonts_cjk));
        else
                fontModule->cjkFontLE->setText(QString());
+       
+       fontModule->microtypeCB->setChecked(bp_.use_microtype);
 
        fontModule->fontScCB->setChecked(bp_.fonts_expert_sc);
        fontModule->fontOsfCB->setChecked(bp_.fonts_old_figures);
index ba7a5ea76b72a16f2b1d3db4d3f9e724d86f0186..3c0e14c094127f1659b1edf0593ba67909687c75 100644 (file)
@@ -6,47 +6,14 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>407</width>
-    <height>285</height>
+    <width>541</width>
+    <height>319</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>FontUi</string>
   </property>
   <layout class="QGridLayout" name="gridLayout">
-   <item row="0" column="0" colspan="2">
-    <widget class="QCheckBox" name="osFontsCB">
-     <property name="toolTip">
-      <string>Use OpenType and TrueType fonts with the fontspec package (requires XeTeX or LuaTeX)</string>
-     </property>
-     <property name="text">
-      <string>&amp;Use non-TeX fonts (via XeTeX/LuaTeX)</string>
-     </property>
-    </widget>
-   </item>
-   <item row="0" column="2">
-    <spacer name="horizontalSpacer">
-     <property name="orientation">
-      <enum>Qt::Horizontal</enum>
-     </property>
-     <property name="sizeHint" stdset="0">
-      <size>
-       <width>59</width>
-       <height>20</height>
-      </size>
-     </property>
-    </spacer>
-   </item>
-   <item row="1" 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="1" column="1">
     <widget class="QComboBox" name="fontsDefaultCO">
      <property name="toolTip">
      </property>
     </widget>
    </item>
+   <item row="0" column="0" colspan="2">
+    <widget class="QCheckBox" name="osFontsCB">
+     <property name="toolTip">
+      <string>Use OpenType and TrueType fonts with the fontspec package (requires XeTeX or LuaTeX)</string>
+     </property>
+     <property name="text">
+      <string>&amp;Use non-TeX fonts (via XeTeX/LuaTeX)</string>
+     </property>
+    </widget>
+   </item>
+   <item row="0" column="2">
+    <spacer name="horizontalSpacer">
+     <property name="orientation">
+      <enum>Qt::Horizontal</enum>
+     </property>
+     <property name="sizeHint" stdset="0">
+      <size>
+       <width>59</width>
+       <height>20</height>
+      </size>
+     </property>
+    </spacer>
+   </item>
+   <item row="1" 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="3" column="1">
     <widget class="QComboBox" name="fontsRomanCO">
      <property name="toolTip">
      </property>
     </widget>
    </item>
+   <item row="5" column="1">
+    <widget class="QComboBox" name="fontsTypewriterCO">
+     <property name="toolTip">
+      <string>Select the typewriter (monospaced) typeface</string>
+     </property>
+    </widget>
+   </item>
    <item row="4" column="3">
     <widget class="QSpinBox" name="scaleSansSB">
      <property name="toolTip">
      </property>
     </widget>
    </item>
-   <item row="5" column="1">
-    <widget class="QComboBox" name="fontsTypewriterCO">
-     <property name="toolTip">
-      <string>Select the typewriter (monospaced) typeface</string>
-     </property>
-    </widget>
-   </item>
    <item row="5" column="2">
     <widget class="QLabel" name="scaleTypewriterLA">
      <property name="text">
      </property>
     </widget>
    </item>
+   <item row="6" column="1">
+    <widget class="QComboBox" name="fontsMathCO">
+     <property name="toolTip">
+      <string>Select the math typeface</string>
+     </property>
+    </widget>
+   </item>
    <item row="5" column="3">
     <widget class="QSpinBox" name="scaleTypewriterSB">
      <property name="toolTip">
      </property>
     </widget>
    </item>
-   <item row="6" column="1">
-    <widget class="QComboBox" name="fontsMathCO">
-     <property name="toolTip">
-      <string>Select the math typeface</string>
-     </property>
-    </widget>
-   </item>
    <item row="7" column="0">
     <widget class="QLabel" name="cjkFontLA">
      <property name="text">
      </property>
     </widget>
    </item>
-   <item row="10" column="1">
+   <item row="11" column="1">
     <spacer name="verticalSpacer">
      <property name="orientation">
       <enum>Qt::Vertical</enum>
      </property>
     </spacer>
    </item>
+   <item row="10" column="1">
+    <widget class="QCheckBox" name="microtypeCB">
+     <property name="toolTip">
+      <string>Activate extensions such as character protusion and font expansion via the microtype package</string>
+     </property>
+     <property name="text">
+      <string>Enable micr&amp;o-typographic extensions</string>
+     </property>
+    </widget>
+   </item>
   </layout>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
index 24c403d23ee770431d048e4b88c9856c2357933b..2481a41db5ac31daa12e121595383b550150a775 100644 (file)
@@ -457,7 +457,8 @@ string remove_braces(string const & value)
 
 
 Preamble::Preamble() : one_language(true), explicit_babel(false),
-       title_layout_found(false), index_number(0), h_font_cjk_set(false)
+       title_layout_found(false), index_number(0), h_font_cjk_set(false),
+       h_use_microtype(false)
 {
        //h_backgroundcolor;
        //h_boxbgcolor;
@@ -543,6 +544,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false),
        h_use_geometry            = "false";
        h_use_default_options     = "false";
        h_use_hyperref            = "false";
+       h_use_microtype           = false;
        h_use_refstyle            = false;
        h_use_packages["amsmath"]    = "1";
        h_use_packages["amssymb"]    = "0";
@@ -1013,6 +1015,13 @@ void Preamble::handle_package(Parser &p, string const & name,
                                h_options += ',' + join(options, ",");
                }
        }
+       else if (name == "microtype") {
+               //we internally support only microtype without params
+               if (options.empty())
+                       h_use_microtype = true;
+               else
+                       h_preamble << "\\usepackage[" << opts << "]{microtype}";
+       }
 
        else if (!in_lyx_preamble) {
                if (options.empty())
@@ -1162,7 +1171,8 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled
           << ' ' << h_font_tt_scale[1] << '\n';
        if (!h_font_cjk.empty())
                os << "\\font_cjk " << h_font_cjk << '\n';
-       os << "\\graphics " << h_graphics << '\n'
+       os << "\\use_microtype " << h_use_microtype << '\n'
+          << "\\graphics " << h_graphics << '\n'
           << "\\default_output_format " << h_default_output_format << "\n"
           << "\\output_sync " << h_output_sync << "\n";
        if (h_output_sync == "1")
index f9342efca2a2ba6678ab2c0ca84b4112339ac4b4..350644d3057c0e04556085c2dd459c56d0e31466 100644 (file)
@@ -151,6 +151,7 @@ private:
        std::string h_font_tt_scale[2];
        bool h_font_cjk_set;
        std::string h_font_cjk;
+       bool h_use_microtype;
        std::string h_graphics;
        std::string h_default_output_format;
        std::string h_html_be_strict;
index 757f43f3c1dfffe864a9c49a5b9636a8387cec92..d8aecddd332f053a8c480eef2c7f59d2933b9a7b 100644 (file)
@@ -32,8 +32,8 @@ extern char const * const lyx_version_info;
 
 // Do not remove the comment below, so we get merge conflict in
 // independent branches. Instead add your own.
-#define LYX_FORMAT_LYX 508 // forenr: convert parbreak to latexpar
-#define LYX_FORMAT_TEX2LYX 508
+#define LYX_FORMAT_LYX 509 // ps: microtype
+#define LYX_FORMAT_TEX2LYX 509
 
 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX
 #ifndef _MSC_VER