]> git.lyx.org Git - lyx.git/blob - src/Floating.cpp
Update Russian localization
[lyx.git] / src / Floating.cpp
1 /**
2  * \file Floating.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Lars Gullik Bjønnes
7  * \author Jean-Marc Lasgouttes
8  * \author Angus Leeming
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #include <config.h>
14
15 #include "Floating.h"
16
17 #include "support/debug.h"
18 #include "support/lstrings.h"
19 #include "support/textutils.h"
20
21 using namespace std;
22
23
24 namespace lyx {
25
26
27 Floating::Floating(string const & type, string const & placement,
28                    string const & ext, string const & within,
29                    string const & style, string const & name,
30                    string const & listName, std::string const & listCmd,
31                    string const & refPrefix, std::string const & allowedplacement,
32                    string const & htmlTag, string const & htmlAttrib,
33                    docstring const & htmlStyle,
34                    string const & docbookAttr, string const & docbookTagType,
35            string const & required, bool usesfloat, bool ispredefined,
36                    bool allowswide, bool allowssideways)
37         : floattype_(type), placement_(placement), ext_(ext), within_(within),
38           style_(style), name_(name), listname_(listName), listcommand_(listCmd),
39           refprefix_(refPrefix), allowedplacement_(allowedplacement), required_(required),
40           usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
41           allowswide_(allowswide), allowssideways_(allowssideways),
42           html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
43           docbook_attr_(docbookAttr), docbook_tag_type_(docbookTagType)
44 {}
45
46
47 std::string Floating::docbookFloatType() const
48 {
49         // TODO: configure this in the layouts?
50         if (floattype_ == "figure") {
51                 return "figure";
52         } else if (floattype_ == "table" || floattype_ == "tableau") {
53                 return "table";
54         } else if (floattype_ == "algorithm") {
55                 return "algorithm";
56         } else {
57                 // If nothing matches, return something that will not be valid.
58                 LYXERR0("Unrecognised float type: " + floattype_);
59                 return "unknown";
60         }
61 }
62
63
64 string const & Floating::htmlAttrib() const
65 {
66         if (html_attrib_.empty())
67                 html_attrib_ = "class='" + defaultCSSClass() + "'";
68         return html_attrib_;
69 }
70
71
72 string const & Floating::htmlTag() const
73 {
74         if (html_tag_.empty())
75                 html_tag_ = "div";
76         return html_tag_;
77 }
78
79
80 string Floating::defaultCSSClass() const
81 {
82         if (!defaultcssclass_.empty())
83                 return defaultcssclass_;
84         string d;
85         string n = floattype_;
86         string::const_iterator it = n.begin();
87         string::const_iterator en = n.end();
88         for (; it != en; ++it) {
89                 if (!isAlphaASCII(*it))
90                         d += "_";
91                 else if (isLower(*it))
92                         d += *it;
93                 else
94                         d += support::lowercase(*it);
95         }
96         // are there other characters we need to remove?
97         defaultcssclass_ = "float-" + d;
98         return defaultcssclass_;
99 }
100
101
102 string Floating::docbookAttr() const
103 {
104         // For algorithms, a type attribute must be mentioned, if not already present in docbook_attr_.
105         if (docbookFloatType() == "algorithm" && docbook_attr_.find("type=") != std::string::npos)
106                 return docbook_attr_ + " type='algorithm'";
107         else
108                 return docbook_attr_;
109 }
110
111
112 string Floating::docbookTag(bool hasTitle) const
113 {
114         // TODO: configure this in the layouts?
115         if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm") {
116                 return hasTitle ? "figure" : "informalfigure";
117         } else if (docbookFloatType() == "table") {
118                 return hasTitle ? "table" : "informaltable";
119         } else {
120                 // If nothing matches, return something that will not be valid.
121                 LYXERR0("Unrecognised float type: " + floattype());
122                 return "float";
123         }
124 }
125
126
127 string const & Floating::docbookTagType() const
128 {
129         if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
130                 docbook_tag_type_ = "block";
131         return docbook_tag_type_;
132 }
133
134
135 string const & Floating::docbookCaption() const
136 {
137         docbook_caption_ = "";
138         if (floattype_ == "figure" || floattype_ == "algorithm")
139                 docbook_caption_ = "title";
140         else if (floattype_ == "table" || floattype_ == "tableau")
141                 docbook_caption_ = "caption";
142         return docbook_caption_;
143 }
144
145
146 } // namespace lyx