2003-08-22 09:44:59 +00:00
|
|
|
/**
|
2007-04-26 04:41:58 +00:00
|
|
|
* \file Floating.cpp
|
2003-08-22 09:44:59 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:27:08 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2003-08-22 09:44:59 +00:00
|
|
|
* \author Jean-Marc Lasgouttes
|
2003-08-23 00:17:00 +00:00
|
|
|
* \author Angus Leeming
|
2000-12-31 05:32:33 +00:00
|
|
|
*
|
2003-08-22 09:44:59 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2000-12-31 05:32:33 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2020-11-12 02:18:03 +00:00
|
|
|
#include <set>
|
2000-12-31 05:32:33 +00:00
|
|
|
|
|
|
|
#include "Floating.h"
|
|
|
|
|
2010-03-05 22:58:29 +00:00
|
|
|
#include "support/debug.h"
|
2010-01-07 17:32:04 +00:00
|
|
|
#include "support/lstrings.h"
|
2012-04-26 14:31:42 +00:00
|
|
|
#include "support/textutils.h"
|
2010-01-07 17:32:04 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2007-07-17 17:46:54 +00:00
|
|
|
namespace lyx {
|
2003-10-06 15:43:21 +00:00
|
|
|
|
2000-12-31 05:32:33 +00:00
|
|
|
|
|
|
|
Floating::Floating(string const & type, string const & placement,
|
|
|
|
string const & ext, string const & within,
|
|
|
|
string const & style, string const & name,
|
2015-05-22 08:37:14 +00:00
|
|
|
string const & listName, std::string const & listCmd,
|
|
|
|
string const & refPrefix, std::string const & allowedplacement,
|
|
|
|
string const & htmlTag, string const & htmlAttrib,
|
2020-09-02 22:23:31 +00:00
|
|
|
docstring const & htmlStyle,
|
2020-08-17 21:06:26 +00:00
|
|
|
string const & docbookAttr, string const & docbookTagType,
|
|
|
|
string const & required, bool usesfloat, bool ispredefined,
|
2015-05-22 16:59:17 +00:00
|
|
|
bool allowswide, bool allowssideways)
|
2010-03-04 13:42:05 +00:00
|
|
|
: floattype_(type), placement_(placement), ext_(ext), within_(within),
|
2010-03-05 22:58:29 +00:00
|
|
|
style_(style), name_(name), listname_(listName), listcommand_(listCmd),
|
2020-02-29 05:21:00 +00:00
|
|
|
refprefix_(refPrefix), allowedplacement_(allowedplacement), required_(required),
|
2015-05-22 08:37:14 +00:00
|
|
|
usesfloatpkg_(usesfloat), ispredefined_(ispredefined),
|
2015-05-22 16:59:17 +00:00
|
|
|
allowswide_(allowswide), allowssideways_(allowssideways),
|
2020-06-08 21:27:49 +00:00
|
|
|
html_tag_(htmlTag), html_attrib_(htmlAttrib), html_style_(htmlStyle),
|
2020-08-29 20:58:23 +00:00
|
|
|
docbook_attr_(docbookAttr), docbook_tag_type_(docbookTagType)
|
2000-12-31 05:32:33 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2020-09-02 22:48:55 +00:00
|
|
|
std::string Floating::docbookFloatType() const
|
|
|
|
{
|
|
|
|
// TODO: configure this in the layouts?
|
2020-11-12 02:18:03 +00:00
|
|
|
if (floattype_ == "figure" || floattype_ == "graph" ||
|
|
|
|
floattype_ == "chart" || floattype_ == "scheme") {
|
2020-09-02 22:48:55 +00:00
|
|
|
return "figure";
|
|
|
|
} else if (floattype_ == "table" || floattype_ == "tableau") {
|
|
|
|
return "table";
|
|
|
|
} else if (floattype_ == "algorithm") {
|
|
|
|
return "algorithm";
|
|
|
|
} else {
|
|
|
|
// If nothing matches, return something that will not be valid.
|
|
|
|
LYXERR0("Unrecognised float type: " + floattype_);
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-07 17:32:04 +00:00
|
|
|
string const & Floating::htmlAttrib() const
|
2009-06-19 12:49:08 +00:00
|
|
|
{
|
2010-01-07 17:32:04 +00:00
|
|
|
if (html_attrib_.empty())
|
2016-07-30 04:03:35 +00:00
|
|
|
html_attrib_ = "class='" + defaultCSSClass() + "'";
|
2010-01-07 17:32:04 +00:00
|
|
|
return html_attrib_;
|
2009-06-19 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-11-30 17:08:56 +00:00
|
|
|
string const & Floating::htmlTag() const
|
2009-06-19 12:49:08 +00:00
|
|
|
{
|
2009-11-30 20:17:55 +00:00
|
|
|
if (html_tag_.empty())
|
|
|
|
html_tag_ = "div";
|
|
|
|
return html_tag_;
|
2009-06-19 12:49:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-07 17:32:04 +00:00
|
|
|
string Floating::defaultCSSClass() const
|
2017-07-03 17:53:14 +00:00
|
|
|
{
|
2010-01-07 17:32:04 +00:00
|
|
|
if (!defaultcssclass_.empty())
|
|
|
|
return defaultcssclass_;
|
|
|
|
string d;
|
2010-03-04 13:42:05 +00:00
|
|
|
string n = floattype_;
|
2010-01-07 17:32:04 +00:00
|
|
|
string::const_iterator it = n.begin();
|
|
|
|
string::const_iterator en = n.end();
|
|
|
|
for (; it != en; ++it) {
|
2012-04-26 14:31:42 +00:00
|
|
|
if (!isAlphaASCII(*it))
|
2010-01-07 17:32:04 +00:00
|
|
|
d += "_";
|
2012-04-26 14:31:42 +00:00
|
|
|
else if (isLower(*it))
|
2010-01-07 17:32:04 +00:00
|
|
|
d += *it;
|
|
|
|
else
|
|
|
|
d += support::lowercase(*it);
|
|
|
|
}
|
|
|
|
// are there other characters we need to remove?
|
|
|
|
defaultcssclass_ = "float-" + d;
|
|
|
|
return defaultcssclass_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-25 14:38:08 +00:00
|
|
|
string Floating::docbookAttr() const
|
2020-06-08 21:27:49 +00:00
|
|
|
{
|
2020-11-12 02:18:03 +00:00
|
|
|
std::set<std::string> achemso = { "chart", "graph", "scheme" };
|
2020-10-25 14:38:08 +00:00
|
|
|
// For algorithms, a type attribute must be mentioned, if not already present in docbook_attr_.
|
|
|
|
if (docbookFloatType() == "algorithm" && docbook_attr_.find("type=") != std::string::npos)
|
|
|
|
return docbook_attr_ + " type='algorithm'";
|
2020-11-12 02:18:03 +00:00
|
|
|
// Specific floats for achemso.
|
|
|
|
else if (docbookFloatType() == "figure" && achemso.find(floattype_) != achemso.end())
|
|
|
|
return docbook_attr_ + " type='" + floattype_ + "'";
|
2020-10-25 14:38:08 +00:00
|
|
|
else
|
|
|
|
return docbook_attr_;
|
2020-06-08 21:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-29 20:58:23 +00:00
|
|
|
string Floating::docbookTag(bool hasTitle) const
|
2020-06-08 21:27:49 +00:00
|
|
|
{
|
2020-09-01 22:46:08 +00:00
|
|
|
// TODO: configure this in the layouts?
|
2020-10-25 14:38:08 +00:00
|
|
|
if (docbookFloatType() == "figure" || docbookFloatType() == "algorithm") {
|
2020-08-29 20:58:23 +00:00
|
|
|
return hasTitle ? "figure" : "informalfigure";
|
2020-09-02 22:48:55 +00:00
|
|
|
} else if (docbookFloatType() == "table") {
|
2020-08-29 20:58:23 +00:00
|
|
|
return hasTitle ? "table" : "informaltable";
|
2020-09-01 22:36:46 +00:00
|
|
|
} else {
|
|
|
|
// If nothing matches, return something that will not be valid.
|
2020-09-02 22:48:55 +00:00
|
|
|
LYXERR0("Unrecognised float type: " + floattype());
|
2020-09-01 22:36:46 +00:00
|
|
|
return "float";
|
2020-06-08 21:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-17 21:06:26 +00:00
|
|
|
string const & Floating::docbookTagType() const
|
|
|
|
{
|
|
|
|
if (docbook_tag_type_ != "block" && docbook_tag_type_ != "paragraph" && docbook_tag_type_ != "inline")
|
|
|
|
docbook_tag_type_ = "block";
|
|
|
|
return docbook_tag_type_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-08 21:27:49 +00:00
|
|
|
string const & Floating::docbookCaption() const
|
|
|
|
{
|
|
|
|
docbook_caption_ = "";
|
2020-10-25 14:38:08 +00:00
|
|
|
if (floattype_ == "figure" || floattype_ == "algorithm")
|
2020-06-08 21:27:49 +00:00
|
|
|
docbook_caption_ = "title";
|
2020-10-25 14:38:08 +00:00
|
|
|
else if (floattype_ == "table" || floattype_ == "tableau")
|
2020-06-08 21:27:49 +00:00
|
|
|
docbook_caption_ = "caption";
|
|
|
|
return docbook_caption_;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|