]> git.lyx.org Git - lyx.git/blob - src/Floating.cpp
DocBook: fix file inclusion.
[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                 // TODO: no good translation for now! Figures are the closest match, as they can contain text.
56                 // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
57                 return "algorithm";
58         } else {
59                 // If nothing matches, return something that will not be valid.
60                 LYXERR0("Unrecognised float type: " + floattype_);
61                 return "unknown";
62         }
63 }
64
65
66 string const & Floating::htmlAttrib() const
67 {
68         if (html_attrib_.empty())
69                 html_attrib_ = "class='" + defaultCSSClass() + "'";
70         return html_attrib_;
71 }
72
73
74 string const & Floating::htmlTag() const
75 {
76         if (html_tag_.empty())
77                 html_tag_ = "div";
78         return html_tag_;
79 }
80
81
82 string Floating::defaultCSSClass() const
83 {
84         if (!defaultcssclass_.empty())
85                 return defaultcssclass_;
86         string d;
87         string n = floattype_;
88         string::const_iterator it = n.begin();
89         string::const_iterator en = n.end();
90         for (; it != en; ++it) {
91                 if (!isAlphaASCII(*it))
92                         d += "_";
93                 else if (isLower(*it))
94                         d += *it;
95                 else
96                         d += support::lowercase(*it);
97         }
98         // are there other characters we need to remove?
99         defaultcssclass_ = "float-" + d;
100         return defaultcssclass_;
101 }
102
103
104 string const & Floating::docbookAttr() const
105 {
106         return docbook_attr_;
107 }
108
109
110 string Floating::docbookTag(bool hasTitle) const
111 {
112         // TODO: configure this in the layouts?
113         if (docbookFloatType() == "figure") {
114                 return hasTitle ? "figure" : "informalfigure";
115         } else if (docbookFloatType() == "table") {
116                 return hasTitle ? "table" : "informaltable";
117         } else if (docbookFloatType() == "algorithm") {
118                 // TODO: no good translation for now! Figures are the closest match, as they can contain text.
119                 // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
120                 return "figure";
121         } else {
122                 // If nothing matches, return something that will not be valid.
123                 LYXERR0("Unrecognised float type: " + floattype());
124                 return "float";
125         }
126 }
127
128
129 string const & Floating::docbookTagType() const
130 {
131         if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
132                 docbook_tag_type_ = "block";
133         return docbook_tag_type_;
134 }
135
136
137 string const & Floating::docbookCaption() const
138 {
139         docbook_caption_ = "";
140         if (floattype_ == "figure") {
141                 docbook_caption_ = "title";
142         } else if (floattype_ == "table" || floattype_ == "tableau") {
143                 docbook_caption_ = "caption";
144         } else if (floattype_ == "algorithm") {
145                 // TODO: no good translation for now! Figures are the closest match, as they can contain text.
146                 // Solvable as soon as https://github.com/docbook/docbook/issues/157 has a definitive answer.
147                 docbook_caption_ = "title";
148         }
149         return docbook_caption_;
150 }
151
152
153 } // namespace lyx