Debian Codegraph @

src/lib/EPUBTableStyleManager.h

raw
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /*
3 * This file is part of the libepubgen 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 #ifndef INCLUDED_EPUBTABLESTYLEMANAGER_H
11 #define INCLUDED_EPUBTABLESTYLEMANAGER_H
12
13 #include <librevenge/librevenge.h>
14
15 #include <string>
16 #include <unordered_map>
17 #include <vector>
18
19 #include <boost/functional/hash.hpp>
20
21 #include "EPUBCSSProperties.h"
22
23 namespace libepubgen
24 {
25
26 class EPUBCSSContent;
27
28 /** Small class to manage the tables style */
29 class EPUBTableStyleManager
30 {
31 typedef std::unordered_map<EPUBCSSProperties, std::string, boost::hash<EPUBCSSProperties>> ContentNameMap_t;
32
33 public:
34 //! constructor
35 EPUBTableStyleManager() : m_cellContentNameMap(), m_rowContentNameMap(), m_tableContentNameMap(), m_columnWidthsStack(), m_relColumnWidthsStack()
36 {
37 }
38 //! destructor
39 ~EPUBTableStyleManager()
40 {
41 }
42 //! open a table
43 void openTable(librevenge::RVNGPropertyList const &propList);
44 //! close a table
45 void closeTable();
46 //! returns the class name corresponding to a propertylist
47 std::string getCellClass(librevenge::RVNGPropertyList const &pList);
48 //! returns the style string corresponding to a propertylist
49 std::string getCellStyle(librevenge::RVNGPropertyList const &pList);
50 //! returns the class name corresponding to a propertylist
51 std::string getRowClass(librevenge::RVNGPropertyList const &pList);
52 //! returns the style string corresponding to a propertylist
53 std::string getRowStyle(librevenge::RVNGPropertyList const &pList);
54 //! returns the class name corresponding to a propertylist
55 std::string getTableClass(librevenge::RVNGPropertyList const &pList);
56 //! returns the style string corresponding to a propertylist
57 std::string getTableStyle(librevenge::RVNGPropertyList const &pList);
58 //! send the data to the sink
59 void send(EPUBCSSContent &out);
60 private:
61 //! convert a property list into a CSS property map
62 void extractCellProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const;
63 //! convert a property list into a CSS property map
64 void extractRowProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const;
65 //! convert a property list into a CSS property map
66 void extractTableProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const;
67 //! try to return the col width
68 bool getColumnsWidth(int i, int numSpanned, double &w) const;
69 //! try to return the relative col width
70 bool getRelColumnsWidth(int i, int numSpanned, double &w) const;
71 //! a map cell content -> name
72 ContentNameMap_t m_cellContentNameMap;
73 //! a map row content -> name
74 ContentNameMap_t m_rowContentNameMap;
75 //! a map table content -> name
76 ContentNameMap_t m_tableContentNameMap;
77 //! a stack of column width (in inches )
78 std::vector<std::vector<double> > m_columnWidthsStack;
79 //! a stack of relative column width (in percents )
80 std::vector<std::vector<double> > m_relColumnWidthsStack;
81
82 EPUBTableStyleManager(EPUBTableStyleManager const &orig);
83 EPUBTableStyleManager operator=(EPUBTableStyleManager const &orig);
84 };
85
86 }
87
88 #endif
89
90 /* vim:set shiftwidth=2 softtabstop=2 expandtab: */