Debian Codegraph @

src/lib/ABWCollector.cpp

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libabw project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
10 #include <boost/algorithm/string.hpp>
11 #include <boost/optional.hpp>
12 #include <boost/spirit/include/qi.hpp>
13
14 #include "ABWCollector.h"
15
16 bool libabw::findInt(const std::string &str, int &res)
17 {
18 using namespace boost::spirit::qi;
19
20 if (str.empty())
21 return false;
22
23 auto it = str.cbegin();
24 return phrase_parse(it, str.cend(), int_, space, res) && it == str.cend();
25 }
26
27 void libabw::parsePropString(const std::string &str, ABWPropertyMap &props)
28 {
29 if (str.empty())
30 return;
31
32 std::string propString(boost::trim_copy(str));
33 std::vector<std::string> strVec;
34 boost::algorithm::split(strVec, propString, boost::is_any_of(";"), boost::token_compress_on);
35 for (auto &i : strVec)
36 {
37 boost::algorithm::trim(i);
38 std::vector<std::string> tmpVec;
39 boost::algorithm::split(tmpVec, i, boost::is_any_of(":"), boost::token_compress_on);
40 if (tmpVec.size() == 2)
41 props[tmpVec[0]] = tmpVec[1];
42 }
43 }
44
45 bool libabw::findDouble(const std::string &str, double &res, ABWUnit &unit)
46 {
47 using namespace boost::spirit::qi;
48
49 if (str.empty())
50 return false;
51
52 symbols<char, std::pair<ABWUnit, double>> units;
53 units.add
54 ("cm", {ABW_IN, 2.54})
55 ("inch", {ABW_IN, 1.0})
56 ("in", {ABW_IN, 1.0})
57 ("mm", {ABW_IN, 25.4})
58 ("pi", {ABW_IN, 6.0})
59 ("pt", {ABW_IN, 72.0})
60 ("px", {ABW_IN, 72.0})
61 ("%", {ABW_PERCENT, 100.0})
62 ;
63
64 boost::optional<std::pair<ABWUnit, double>> u;
65
66 auto it = str.cbegin();
67 if (!phrase_parse(it, str.cend(), double_ >> -units, space, res, u) || it != str.cend())
68 return false;
69
70 if (u)
71 {
72 unit = get(u).first;
73 res /= get(u).second;
74 }
75 else
76 {
77 unit = ABW_PERCENT;
78 }
79
80 return true;
81 }
82
83 void libabw::ABWListElement::writeOut(librevenge::RVNGPropertyList &propList) const
84 {
85 if (m_listLevel > 0)
86 propList.insert("librevenge:level", m_listLevel);
87 propList.insert("text:min-label-width", m_minLabelWidth);
88 propList.insert("text:space-before", m_spaceBefore);
89 }
90
91 void libabw::ABWOrderedListElement::writeOut(librevenge::RVNGPropertyList &propList) const
92 {
93 libabw::ABWListElement::writeOut(propList);
94 propList.insert("style:num-format", m_numFormat);
95 if (!m_numPrefix.empty())
96 propList.insert("style:num-prefix", m_numPrefix);
97 if (!m_numSuffix.empty())
98 propList.insert("style:num-suffix", m_numSuffix);
99 if (m_startValue >= 0)
100 propList.insert("text:start-value", m_startValue);
101 }
102
103 void libabw::ABWUnorderedListElement::writeOut(librevenge::RVNGPropertyList &propList) const
104 {
105 libabw::ABWListElement::writeOut(propList);
106 propList.insert("text:bullet-char", m_bulletChar);
107 }
108
109 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */