]> git.lyx.org Git - features.git/blob - src/Floating.cpp
DocBook: fix float tags (was unduly overridden).
[features.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, string const & docbookTag,
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 string const & Floating::htmlAttrib() const
48 {
49         if (html_attrib_.empty())
50                 html_attrib_ = "class='" + defaultCSSClass() + "'";
51         return html_attrib_;
52 }
53
54
55 string const & Floating::htmlTag() const
56 {
57         if (html_tag_.empty())
58                 html_tag_ = "div";
59         return html_tag_;
60 }
61
62
63 string Floating::defaultCSSClass() const
64 {
65         if (!defaultcssclass_.empty())
66                 return defaultcssclass_;
67         string d;
68         string n = floattype_;
69         string::const_iterator it = n.begin();
70         string::const_iterator en = n.end();
71         for (; it != en; ++it) {
72                 if (!isAlphaASCII(*it))
73                         d += "_";
74                 else if (isLower(*it))
75                         d += *it;
76                 else
77                         d += support::lowercase(*it);
78         }
79         // are there other characters we need to remove?
80         defaultcssclass_ = "float-" + d;
81         return defaultcssclass_;
82 }
83
84
85 string const & Floating::docbookAttr() const
86 {
87         return docbook_attr_;
88 }
89
90
91 string Floating::docbookTag(bool hasTitle) const
92 {
93         if (floattype_ == "figure") {
94                 return hasTitle ? "figure" : "informalfigure";
95         } else if (floattype_ == "table") {
96                 return hasTitle ? "table" : "informaltable";
97         } else if (floattype_ == "algorithm") {
98                 // TODO: no good translation for now! Figures are the closest match, as they can contain text.
99                 // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
100                 return "figure";
101         }
102 }
103
104
105 string const & Floating::docbookTagType() const
106 {
107         if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
108                 docbook_tag_type_ = "block";
109         return docbook_tag_type_;
110 }
111
112
113 string const & Floating::docbookCaption() const
114 {
115         docbook_caption_ = "";
116         if (floattype_ == "figure") {
117                 docbook_caption_ = "title";
118         } else if (floattype_ == "table") {
119                 docbook_caption_ = "caption";
120         } else if (floattype_ == "algorithm") {
121                 // TODO: no good translation for now! Figures are the closest match, as they can contain text.
122                 // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
123                 docbook_caption_ = "title";
124         }
125         return docbook_caption_;
126 }
127
128
129 } // namespace lyx