]> git.lyx.org Git - lyx.git/blobdiff - src/Font.cpp
adjust
[lyx.git] / src / Font.cpp
index 74f45e5230b27c3f0927440d15cb18fb41b8b3dd..f4e9bd053bf35362bf2064901361f10cb47d41e9 100644 (file)
 #include "output_latex.h"
 #include "OutputParams.h"
 
+#include "support/convert.h"
 #include "support/lstrings.h"
 
-
-namespace lyx {
-
-using support::ascii_lowercase;
-using support::bformat;
-using support::rtrim;
-using support::subst;
-
 using std::endl;
 using std::string;
 using std::ostream;
+using std::ostringstream;
+using std::istringstream;
+using std::pair;
 
 #ifndef CXX_GLOBAL_CSTD
 using std::strlen;
 #endif
 
+
+namespace lyx {
+
+using support::ascii_lowercase;
+using support::bformat;
+using support::rtrim;
+using support::subst;
+
 //
 // Names for the GUI
 //
@@ -785,12 +789,12 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
        }
 
        if (language()->encoding()->package() == Encoding::CJK) {
-               int const c = switchEncoding(os, bparams,
+               pair<bool, int> const c = switchEncoding(os, bparams,
                                runparams.moving_arg, *(runparams.encoding),
                                *(language()->encoding()));
-               if (c > 0) {
+               if (c.first) {
                        open_encoding_ = true;
-                       count += c;
+                       count += c.second;
                        runparams.encoding = language()->encoding();
                }
        }
@@ -801,7 +805,8 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
        // for Hebrew and Farsi (Arabi) do not.
        if (number() == ON && prev.number() != ON
                && (language()->lang() == "hebrew"
-                       || language()->lang() == "farsi")) {
+                       || language()->lang() == "farsi" 
+                       || language()->lang() == "arabic_arabi")) {
                os << "{\\beginL ";
                count += 9;
        }
@@ -874,7 +879,8 @@ int Font::latexWriteStartChanges(odocstream & os, BufferParams const & bparams,
 int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
                                  OutputParams const & runparams,
                                  Font const & base,
-                                 Font const & next) const
+                                 Font const & next,
+                                 bool const & closeLanguage) const
 {
        int count = 0;
        bool env = false;
@@ -934,7 +940,8 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
        // for Hebrew and Farsi (Arabi) do not.
        if (number() == ON && next.number() != ON
                && (language()->lang() == "hebrew"
-                       || language()->lang() == "farsi")) {
+                       || language()->lang() == "farsi"
+                       || language()->lang() == "arabic_arabi")) {
                os << "\\endL}";
                count += 6;
        }
@@ -943,16 +950,17 @@ int Font::latexWriteEndChanges(odocstream & os, BufferParams const & bparams,
                // We need to close the encoding even if it does not change
                // to do correct environment nesting
                Encoding const * const ascii = encodings.getFromLyXName("ascii");
-               int const c = switchEncoding(os, bparams,
+               pair<bool, int> const c = switchEncoding(os, bparams,
                                runparams.moving_arg, *(runparams.encoding),
                                *ascii);
-               BOOST_ASSERT(c > 0);
-               count += c;
+               BOOST_ASSERT(c.first);
+               count += c.second;
                runparams.encoding = ascii;
                open_encoding_ = false;
        }
 
-       if (language() != base.language() && language() != next.language()) {
+       if (closeLanguage &&
+                       language() != base.language() && language() != next.language()) {
                os << '}';
                ++count;
        }
@@ -969,6 +977,99 @@ Color_color Font::realColor() const
 }
 
 
+std::string Font::toString(bool const toggle) const
+{
+       string lang = "ignore";
+       if (language())
+               lang = language()->lang();
+
+       ostringstream os;
+       os << "family " << family() << '\n'
+          << "series " << series() << '\n'
+          << "shape " << shape() << '\n'
+          << "size " << size() << '\n'
+          << "emph " << emph() << '\n'
+          << "underbar " << underbar() << '\n'
+          << "noun " << noun() << '\n'
+          << "number " << number() << '\n'
+          << "color " << color() << '\n'
+          << "language " << lang << '\n'
+          << "toggleall " << convert<string>(toggle);
+       return os.str();
+}
+
+
+bool Font::fromString(string const & data, bool & toggle)
+{
+       istringstream is(data);
+       Lexer lex(0,0);
+       lex.setStream(is);
+
+       int nset = 0;
+       while (lex.isOK()) {
+               string token;
+               if (lex.next())
+                       token = lex.getString();
+
+               if (token.empty() || !lex.next())
+                       break;
+
+               if (token == "family") {
+                       int const next = lex.getInteger();
+                       setFamily(FONT_FAMILY(next));
+
+               } else if (token == "series") {
+                       int const next = lex.getInteger();
+                       setSeries(FONT_SERIES(next));
+
+               } else if (token == "shape") {
+                       int const next = lex.getInteger();
+                       setShape(FONT_SHAPE(next));
+
+               } else if (token == "size") {
+                       int const next = lex.getInteger();
+                       setSize(FONT_SIZE(next));
+
+               } else if (token == "emph" || token == "underbar" ||
+                          token == "noun" || token == "number") {
+
+                       int const next = lex.getInteger();
+                       FONT_MISC_STATE const misc = FONT_MISC_STATE(next);
+
+                       if (token == "emph")
+                         setEmph(misc);
+                       else if (token == "underbar")
+                               setUnderbar(misc);
+                       else if (token == "noun")
+                               setNoun(misc);
+                       else if (token == "number")
+                               setNumber(misc);
+
+               } else if (token == "color") {
+                       int const next = lex.getInteger();
+                       setColor(Color::color(next));
+
+               } else if (token == "language") {
+                       string const next = lex.getString();
+                       if (next == "ignore")
+                               setLanguage(ignore_language);
+                       else
+                               setLanguage(languages.getLanguage(next));
+
+               } else if (token == "toggleall") {
+                       toggle = lex.getBool();
+
+               } else {
+                       // Unrecognised token
+                       break;
+               }
+
+               ++nset;
+       }
+       return (nset > 0);
+}
+
+
 ostream & operator<<(ostream & os, Font::FONT_MISC_STATE fms)
 {
        return os << int(fms);