]> git.lyx.org Git - lyx.git/commitdiff
tex2lyx: support font settings -> move fileformat to 247
authorUwe Stöhr <uwestoehr@web.de>
Wed, 5 Dec 2007 20:02:49 +0000 (20:02 +0000)
committerUwe Stöhr <uwestoehr@web.de>
Wed, 5 Dec 2007 20:02:49 +0000 (20:02 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21970 a592a061-630c-0410-9148-cb99ea01b6c8

src/tex2lyx/Context.h
src/tex2lyx/preamble.cpp
src/tex2lyx/text.cpp

index 1af64330238a48702503f156ca388dd14bf2e7f8..564b3327133a3632249a0c4d75a2866b704582cd 100644 (file)
@@ -36,7 +36,7 @@ public:
        }
        void init()
        {
-               size = "normal";
+               size = "default";
                family = "default";
                series = "default";
                shape = "default";
index 3b4e15b4e82dc6a4f9fa8853d3d6480489e0c884..803d637e2126d82880054a855bd9beee3b66e298 100644 (file)
@@ -68,13 +68,30 @@ const char * const known_french_languages[] = {"french", "frenchb", "francais",
                                               "frenchle", "frenchpro", 0};
 char const * const known_fontsizes[] = { "10pt", "11pt", "12pt", 0 };
 
+const char * const known_roman_fonts[] = { "ae", "bookman", "charter",
+"cmr", "fourier", "lmodern", "mathpazo", "mathptmx", "newcent", 0};
+
+const char * const known_sans_fonts[] = { "avant", "berasans", "cmbr", "cmss",
+"helvet", "lmss", 0};
+
+const char * const known_typewriter_fonts[] = { "beramono", "cmtl", "cmtt",
+"courier", "lmtt", "luximono", "fourier", "lmodern", "mathpazo", "mathptmx",
+"newcent", 0};
+
 // some ugly stuff
 ostringstream h_preamble;
 string h_textclass               = "article";
 string h_options                 = string();
 string h_language                = "english";
 string h_inputencoding           = "auto";
-string h_fontscheme              = "default";
+string h_font_roman              = "default";
+string h_font_sans               = "default";
+string h_font_typewriter         = "default";
+string h_font_default_family     = "default";
+string h_font_sc                 = "false";
+string h_font_osf                = "false";
+string h_font_sf_scale           = "100";
+string h_font_tt_scale           = "100";
 string h_graphics                = "default";
 string h_paperfontsize           = "default";
 string h_spacing                 = "single";
@@ -180,15 +197,38 @@ void handle_package(string const & name, string const & opts)
 {
        vector<string> options = split_options(opts);
        add_package(name, options);
+       size_t pos;
+       string scale;
+
+       // roman fonts
+       if (is_known(name, known_roman_fonts))
+               h_font_roman = name;
+       if (name == "fourier")
+               h_font_roman = "utopia";
+       if (name == "mathpazo")
+               h_font_roman = "palatino";
+       if (name == "mathptmx")
+               h_font_roman = "times";
+       // sansserif fonts
+       if (is_known(name, known_sans_fonts)) {
+               h_font_sans = name;
+               if (!opts.empty()) {
+                       scale = opts;
+                       pos = scale.find(".", 0);
+                       h_font_sf_scale = scale.erase(0, pos + 1);
+               }
+       }
+       // typewriter fonts
+       if (is_known(name, known_typewriter_fonts)) {
+               h_font_typewriter = name;
+               if (!opts.empty()) {
+                       scale = opts;
+                       pos = scale.find(".", 0);
+                       h_font_tt_scale = scale.erase(0, pos + 1);
+               }
+       }
 
-       //cerr << "handle_package: '" << name << "'\n";
-       if (name == "ae")
-               h_fontscheme = "ae";
-       else if (name == "aecompl")
-               h_fontscheme = "ae";
-       else if (name == "amsmath")
-               h_use_amsmath = "1";
-       else if (name == "amssymb")
+       else if (name == "amsmath" || name == "amssymb")
                h_use_amsmath = "1";
        else if (name == "babel")
                ; // ignore this
@@ -248,7 +288,7 @@ void handle_package(string const & name, string const & opts)
 void end_preamble(ostream & os, TextClass const & /*textclass*/)
 {
        os << "#LyX file created by tex2lyx " << PACKAGE_VERSION << "\n"
-          << "\\lyxformat 246\n"
+          << "\\lyxformat 247\n"
           << "\\begin_document\n"
           << "\\begin_header\n"
           << "\\textclass " << h_textclass << "\n";
@@ -258,7 +298,14 @@ void end_preamble(ostream & os, TextClass const & /*textclass*/)
                os << "\\options " << h_options << "\n";
        os << "\\language " << h_language << "\n"
           << "\\inputencoding " << h_inputencoding << "\n"
-          << "\\fontscheme " << h_fontscheme << "\n"
+          << "\\font_roman " << h_font_roman << "\n"
+          << "\\font_sans " << h_font_sans << "\n"
+          << "\\font_typewriter " << h_font_typewriter << "\n"
+          << "\\font_default_family " << h_font_default_family << "\n"
+          << "\\font_sc " << h_font_sc << "\n"
+          << "\\font_osf " << h_font_osf << "\n"
+          << "\\font_sf_scale " << h_font_sf_scale << "\n"
+          << "\\font_tt_scale " << h_font_tt_scale << "\n"
           << "\\graphics " << h_graphics << "\n"
           << "\\paperfontsize " << h_paperfontsize << "\n"
           << "\\spacing " << h_spacing << "\n"
@@ -355,6 +402,24 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
                        string const opt1 = p.getOpt();
                        string const opt2 = p.getFullOpt();
                        string const body = p.verbatim_item();
+                       // font settings
+                       if (name == "\\rmdefault")
+                               if (is_known(body, known_roman_fonts))
+                                       h_font_roman = body;
+
+                       if (name == "\\sfdefault")
+                               if (is_known(body, known_sans_fonts))
+                                       h_font_sans = body;
+
+                       if (name == "\\ttdefault")
+                               if (is_known(body, known_typewriter_fonts))
+                                       h_font_typewriter = body;
+
+                       if (name == "\\familydefault") {
+                               string family = body;
+                               // remove leading "\"
+                               h_font_default_family = family.erase(0,1);
+                       }
                        // only non-lyxspecific stuff
                        if (   name != "\\noun"
                            && name != "\\tabularnewline"
@@ -364,7 +429,11 @@ TextClass const parse_preamble(Parser & p, ostream & os, string const & forcecla
                            && name != "\\lyxrightaddress"
                            && name != "\\lyxdot"
                            && name != "\\boldsymbol"
-                           && name != "\\lyxarrow") {
+                           && name != "\\lyxarrow"
+                           && name != "\\rmdefault"
+                           && name != "\\sfdefault"
+                           && name != "\\ttdefault"
+                           && name != "\\familydefault") {
                                ostringstream ss;
                                ss << '\\' << t.cs();
                                if (star)
index c1ee6f764cda9e734d6e7d5fc7f2438f6d6dbb81..eefee3192cf3e1bfda59a4091194d7fbaf771a4e 100644 (file)
@@ -144,7 +144,7 @@ char const * const known_sizes[] = { "tiny", "scriptsize", "footnotesize",
 "small", "normalsize", "large", "Large", "LARGE", "huge", "Huge", 0};
 
 /// the same as known_sizes with .lyx names
-char const * const known_coded_sizes[] = { "tiny", "scriptsize", "footnotesize",
+char const * const known_coded_sizes[] = { "default", "tiny", "scriptsize", "footnotesize",
 "small", "normal", "large", "larger", "largest",  "huge", "giant", 0};
 
 /// LaTeX 2.09 names for font families