3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Lars Gullik Bjønnes
7 * \author Jean-Marc Lasgouttes
8 * \author Angus Leeming
10 * Full author contact details are available in file CREDITS.
18 #include "support/debug.h"
19 #include "support/lstrings.h"
20 #include "support/textutils.h"
28 Floating::Floating(string const & type, string const & placement,
29 string const & ext, string const & within,
30 string const & style, string const & name,
31 string const & listName, std::string const & listCmd,
32 string const & refPrefix, std::string const & allowedplacement,
33 string const & htmlTag, string const & htmlAttrib,
34 docstring const & htmlStyle, std::string const & docbookTag,
35 string const & docbookAttr, string const & docbookTagType,
36 std::string const & docbookFloatType, std::string const & docbookCaption,
37 string const & required, bool usesfloat, bool ispredefined,
38 bool allowswide, bool allowssideways)
39 : floattype_(type), placement_(placement), ext_(ext), within_(within),
40 style_(style), name_(name), listname_(listName), listcommand_(listCmd),
41 refprefix_(refPrefix), allowedplacement_(allowedplacement), required_(required),
42 usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
43 allowswide_(allowswide), allowssideways_(allowssideways),
44 html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
45 docbook_tag_(docbookTag), docbook_tag_type_(docbookTagType),
46 docbook_caption_(docbookCaption)
48 // Implement some edge cases for DocBook. Both docbook_float_type_ and docbook_attr_ must be computed
49 // based on the given value of docbookFloatType; docbook_tag_ can still be guessed without correlation.
51 // Determine the value of docbook_float_type_.
53 // These are the allowed values for docbook_float_type_. Both docbook_attr_ and docbook_tag_type_
54 // depend on this list.
55 static std::set<std::string> allowedFloatTypes{"figure", "table", "algorithm", "video", "example"};
57 // If some type is predetermined in the layout, use it.
58 if (!docbookFloatType.empty() && allowedFloatTypes.find(docbookFloatType) != allowedFloatTypes.end())
59 docbook_float_type_ = docbookFloatType;
60 // Otherwise, try to guess the type.
61 else if (floattype_ == "figure" || floattype_ == "graph" ||
62 floattype_ == "chart" || floattype_ == "scheme") {
63 docbook_float_type_ = "figure";
64 } else if (floattype_ == "table" || floattype_ == "tableau") {
65 docbook_float_type_ = "table";
66 } else if (floattype_ == "algorithm") {
67 docbook_float_type_ = "algorithm";
68 } else if (floattype_ == "video") {
69 docbook_float_type_ = "video";
71 // If nothing matches, return something that will not be valid.
72 LYXERR0("Unrecognised float type: " + floattype_);
73 docbook_float_type_ = "unknown";
77 // Determine the value of docbook_attr_.
79 std::set<std::string> achemso = {"chart", "graph", "scheme"};
80 bool hasType = docbook_attr_.find("type=") != std::string::npos;
82 // For algorithms, a type attribute must be mentioned, if not already present in docbook_attr_.
83 if (docbook_float_type_ == "algorithm" && !hasType)
84 docbook_attr_ += " type='algorithm'";
85 // Specific floats for achemso.
86 else if (docbook_float_type_ == "figure" && achemso.find(floattype_) != achemso.end())
87 docbook_attr_ += " type='" + floattype_ + "'";
92 string const & Floating::htmlAttrib() const
94 if (html_attrib_.empty())
95 html_attrib_ = "class='" + defaultCSSClass() + "'";
100 string const & Floating::htmlTag() const
102 if (html_tag_.empty())
108 string Floating::defaultCSSClass() const
110 if (!defaultcssclass_.empty())
111 return defaultcssclass_;
113 string n = floattype_;
114 string::const_iterator it = n.begin();
115 string::const_iterator en = n.end();
116 for (; it != en; ++it) {
117 if (!isAlphaASCII(*it))
119 else if (isLower(*it))
122 d += support::lowercase(*it);
124 // are there other characters we need to remove?
125 defaultcssclass_ = "float-" + d;
126 return defaultcssclass_;
130 std::string Floating::docbookFloatType() const
132 // All the work is done in the constructor.
133 return docbook_float_type_;
137 string Floating::docbookAttr() const
139 return docbook_attr_;
143 string Floating::docbookTag(bool hasTitle) const
145 // If there is a preconfigured tag, use it.
146 if (!docbook_tag_.empty())
149 // Otherwise, guess it.
150 if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm" || docbookFloatType() == "video") {
151 return hasTitle ? "figure" : "informalfigure";
152 } else if (docbookFloatType() == "example") {
153 return hasTitle ? "example" : "informalexample";
154 } else if (docbookFloatType() == "table") {
155 return hasTitle ? "table" : "informaltable";
157 // If nothing matches, return something that will not be valid.
158 LYXERR0("Unrecognised float type: " + floattype());
164 string const & Floating::docbookTagType() const
166 if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
167 docbook_tag_type_ = "block";
168 return docbook_tag_type_;
172 string const & Floating::docbookCaption() const
174 if (!docbook_caption_.empty())
175 return docbook_caption_;
177 if (docbook_float_type_ == "figure" || docbook_float_type_ == "video" ||
178 docbook_float_type_ == "algorithm" || docbook_float_type_ == "example")
179 docbook_caption_ = "title";
180 else if (floattype_ == "table" || floattype_ == "tableau")
181 docbook_caption_ = "caption";
182 return docbook_caption_;