]> git.lyx.org Git - features.git/commitdiff
Partial merge of CharStyle and InsetLayout stuff, first part
authorMartin Vermeer <martin.vermeer@hut.fi>
Fri, 17 Aug 2007 15:38:58 +0000 (15:38 +0000)
committerMartin Vermeer <martin.vermeer@hut.fi>
Fri, 17 Aug 2007 15:38:58 +0000 (15:38 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@19621 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp
src/TextClass.cpp
src/TextClass.h
src/insets/InsetCharStyle.cpp

index ed969f83034bb6ecb5320d2f591a3bf0d12bfd0f..2b0286a16ca699385143186f1bf335da1a6e0348 100644 (file)
@@ -137,7 +137,7 @@ namespace fs = boost::filesystem;
 
 namespace {
 
-int const LYX_FORMAT = 278;
+int const LYX_FORMAT = 279;
 
 } // namespace anon
 
index 77348f28195423cb21c8e52f181cc95f413939ae..12349d402efcdc5fbfc0765dbdb19416a46441a3 100644 (file)
@@ -149,7 +149,6 @@ enum TextClassTags {
        TC_INPUT,
        TC_STYLE,
        TC_DEFAULTSTYLE,
-       TC_CHARSTYLE,
        TC_INSETLAYOUT,
        TC_ENVIRONMENT,
        TC_NOSTYLE,
@@ -183,7 +182,6 @@ bool TextClass::read(FileName const & filename, bool merge)
        }
 
        keyword_item textClassTags[] = {
-               { "charstyle",       TC_CHARSTYLE },
                { "classoptions",    TC_CLASSOPTIONS },
                { "columns",         TC_COLUMNS },
                { "counter",         TC_COUNTER },
@@ -407,12 +405,6 @@ bool TextClass::read(FileName const & filename, bool merge)
                        if (lexrc.next())
                                rightmargin_ = lexrc.getString();
                        break;
-               case TC_CHARSTYLE:
-                       if (lexrc.next()) {
-                               string const name = subst(lexrc.getString(), '_', ' ');
-                               readCharStyle(lexrc, name);
-                       }
-                       break;
                case TC_INSETLAYOUT:
                        if (lexrc.next()) {
                                docstring const name = subst(lexrc.getDocString(), '_', ' ');
@@ -603,19 +595,10 @@ void TextClass::readClassOptions(Lexer & lexrc)
        lexrc.popTable();
 }
 
-enum CharStyleTags {
-       CS_FONT = 1,
-       CS_LABELFONT,
-       CS_LATEXTYPE,
-       CS_LATEXNAME,
-       CS_LATEXPARAM,
-       CS_PREAMBLE,
-       CS_END
-};
-
 
 enum InsetLayoutTags {
        IL_FONT = 1,
+       IL_LYXTYPE,
        IL_LABELFONT,
        IL_LABELSTRING,
        IL_LATEXTYPE,
@@ -626,84 +609,6 @@ enum InsetLayoutTags {
 };
 
 
-
-void TextClass::readCharStyle(Lexer & lexrc, string const & name)
-{
-       keyword_item elementTags[] = {
-               { "end", CS_END },
-               { "font", CS_FONT },
-               { "labelfont", CS_LABELFONT },
-               { "latexname", CS_LATEXNAME },
-               { "latexparam", CS_LATEXPARAM },
-               { "latextype", CS_LATEXTYPE },
-               { "preamble", CS_PREAMBLE}
-       };
-
-       lexrc.pushTable(elementTags, CS_END);
-
-       string latextype;
-       string latexname;
-       string latexparam;
-       Font font(Font::ALL_INHERIT);
-       Font labelfont(Font::ALL_INHERIT);
-       string preamble;
-
-       bool getout = false;
-       while (!getout && lexrc.isOK()) {
-               int le = lexrc.lex();
-               switch (le) {
-               case Lexer::LEX_UNDEF:
-                       lexrc.printError("Unknown ClassOption tag `$$Token'");
-                       continue;
-               default: break;
-               }
-               switch (static_cast<CharStyleTags>(le)) {
-               case CS_LATEXTYPE:
-                       lexrc.next();
-                       latextype = lexrc.getString();
-                       break;
-               case CS_LATEXNAME:
-                       lexrc.next();
-                       latexname = lexrc.getString();
-                       break;
-               case CS_LATEXPARAM:
-                       lexrc.next();
-                       latexparam = subst(lexrc.getString(), "&quot;", "\"");
-                       break;
-               case CS_LABELFONT:
-                       labelfont.lyxRead(lexrc);
-                       break;
-               case CS_FONT:
-                       font.lyxRead(lexrc);
-                       labelfont = font;
-                       break;
-               case CS_PREAMBLE:
-                       preamble = lexrc.getLongString("EndPreamble");
-                       break;
-               case CS_END:
-                       getout = true;
-                       break;
-               }
-       }
-
-       //
-       // Here add element to list if getout == true
-       if (getout) {
-               CharStyle cs;
-               cs.name = name;
-               cs.latextype = latextype;
-               cs.latexname = latexname;
-               cs.latexparam = latexparam;
-               cs.font = font;
-               cs.labelfont = labelfont;
-               cs.preamble = from_utf8(preamble);
-               charstyles().push_back(cs);
-       }
-
-       lexrc.popTable();
-}
-
-
 void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
 {
        keyword_item elementTags[] = {
@@ -714,11 +619,13 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                { "latexname", IL_LATEXNAME },
                { "latexparam", IL_LATEXPARAM },
                { "latextype", IL_LATEXTYPE },
+               { "lyxtype", IL_LYXTYPE },
                { "preamble", IL_PREAMBLE}
        };
 
        lexrc.pushTable(elementTags, IL_END);
 
+       string lyxtype;
        docstring labelstring;
        string latextype;
        string latexname;
@@ -737,6 +644,10 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                default: break;
                }
                switch (static_cast<InsetLayoutTags>(le)) {
+               case IL_LYXTYPE:
+                       lexrc.next();
+                       lyxtype = lexrc.getString();
+                       break;
                case IL_LATEXTYPE:
                        lexrc.next();
                        latextype = lexrc.getString();
@@ -775,6 +686,8 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
        // Here add element to list if getout == true
        if (getout) {
                InsetLayout il;
+               il.name = to_ascii(name);
+               il.lyxtype = lyxtype;
                il.labelstring = labelstring;
                il.latextype = latextype;
                il.latexname = latexname;
@@ -783,6 +696,11 @@ void TextClass::readInsetLayout(Lexer & lexrc, docstring const & name)
                il.labelfont = labelfont;
                il.preamble = from_utf8(preamble);
                insetlayoutlist_[name] = il;
+
+               // test name for CS:
+               if (il.lyxtype == "charstyle") {
+                       charstyles().push_back(il);
+               }
        }
 
        lexrc.popTable();
@@ -1095,7 +1013,17 @@ Counters & TextClass::counters() const
 
 InsetLayout const & TextClass::insetlayout(docstring const & name) const 
 {
-       return insetlayoutlist_[name]; 
+       docstring n = name;
+       while (!n.empty()) {
+               if (!insetlayoutlist_.count(n) > 0)
+                       return insetlayoutlist_[n];
+               docstring::size_type i = n.find(':');
+               if (i == string::npos)
+                       break;
+               n = n.substr(0,i);
+       }
+       static const InsetLayout empty;
+       return empty;
 }
 
 
index 64716c1741e87cc4553196e705310e8149d3610a..a4a4449923dbe16032f472ab0e5fc15b74ce7112 100644 (file)
@@ -29,20 +29,10 @@ class FloatList;
 
 
 ///
-class CharStyle {
-public:
-       std::string name;
-       std::string latextype;
-       std::string latexname;
-       std::string latexparam;
-       Font font;
-       Font labelfont;
-       docstring preamble;
-};
-
-
 class InsetLayout {
 public:
+       std::string name;
+       std::string lyxtype;
        docstring labelstring;
        std::string latextype;
        std::string latexname;
@@ -54,7 +44,7 @@ public:
 
 
 /// List of semantically defined character style insets
-typedef std::vector<CharStyle> CharStyles;
+typedef std::vector<InsetLayout> CharStyles;
 
 /// List of inset layouts
 typedef std::map<docstring, InsetLayout> InsetLayouts;
index 955d335e34c4dcf3166c04e4e9718a87c9bba04f..77d5fd8af62e2436449ade8f4255be64bbb3ff8a 100644 (file)
@@ -158,6 +158,9 @@ bool InsetCharStyle::metrics(MetricsInfo & mi, Dimension & dim) const
                docstring s(from_utf8(params_.type));
                if (undefined())
                        s = _("Undef: ") + s;
+               // Chop off prefix:
+               if (s.find(':') != string::npos)
+                       s = s.substr(s.find(':'));
                theFontMetrics(font).rectText(s, w, a, d);
                dim.wid = max(dim.wid, w);
        }
@@ -207,6 +210,9 @@ void InsetCharStyle::draw(PainterInfo & pi, int x, int y) const
                docstring s(from_utf8(params_.type));
                if (undefined())
                        s = _("Undef: ") + s;
+               // Chop off prefix:
+               if (s.find(':') != string::npos)
+                       s = s.substr(s.find(':'));
                theFontMetrics(font).rectText(s, w, a, d);
                pi.pain.rectText(x + (dim_.wid - w) / 2, y + desc + a,
                        s, font, Color::none, Color::none);