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