| 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_EPUBLISTSTYLEMANAGER_H |
| 11 |
#define INCLUDED_EPUBLISTSTYLEMANAGER_H |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <map> |
| 15 |
#include <unordered_map> |
| 16 |
#include <vector> |
| 17 |
|
| 18 |
#include <boost/functional/hash.hpp> |
| 19 |
|
| 20 |
#include <librevenge/librevenge.h> |
| 21 |
|
| 22 |
#include "EPUBCSSProperties.h" |
| 23 |
#include "EPUBParagraphStyleManager.h" |
| 24 |
|
| 25 |
namespace libepubgen |
| 26 |
{ |
| 27 |
|
| 28 |
class EPUBCSSContent; |
| 29 |
|
| 30 |
/** Small class to manage the list style */ |
| 31 |
class EPUBListStyleManager : public EPUBParagraphStyleManager |
| 32 |
{ |
| 33 |
public: |
| 34 |
struct List |
| 35 |
{ |
| 36 |
typedef std::unordered_map<EPUBCSSProperties, std::string, boost::hash<EPUBCSSProperties>> ContentNameMap_t; |
| 37 |
|
| 38 |
//! constructor |
| 39 |
List() : m_contentsList(), m_level(0) |
| 40 |
{ |
| 41 |
} |
| 42 |
//! destructor |
| 43 |
~List() |
| 44 |
{ |
| 45 |
} |
| 46 |
//! set the property correspond to a level |
| 47 |
void setLevel(int lvl, librevenge::RVNGPropertyList const &property, bool ordered); |
| 48 |
//! open a new level |
| 49 |
void openLevel() const |
| 50 |
{ |
| 51 |
m_level++; |
| 52 |
} |
| 53 |
//! open a new level |
| 54 |
void closeLevel() const |
| 55 |
{ |
| 56 |
if (m_level <= 0) |
| 57 |
return; |
| 58 |
m_level--; |
| 59 |
} |
| 60 |
|
| 61 |
//! return the properties of the current level |
| 62 |
const EPUBCSSProperties &getCurrentProperties() const; |
| 63 |
|
| 64 |
protected: |
| 65 |
//! the properties |
| 66 |
std::vector<EPUBCSSProperties> m_contentsList; |
| 67 |
//! the actual list level |
| 68 |
mutable int m_level; |
| 69 |
}; |
| 70 |
//! constructor |
| 71 |
EPUBListStyleManager() : EPUBParagraphStyleManager(), m_levelNameMap(), |
| 72 |
m_idListMap(), m_actualIdStack() |
| 73 |
{ |
| 74 |
} |
| 75 |
//! destructor |
| 76 |
~EPUBListStyleManager() override |
| 77 |
{ |
| 78 |
} |
| 79 |
//! add a level to the corresponding list |
| 80 |
void defineLevel(librevenge::RVNGPropertyList const &property, bool ordered); |
| 81 |
//! returns the class name corresponding to a propertylist |
| 82 |
std::string openLevel(librevenge::RVNGPropertyList const &pList, bool ordered); |
| 83 |
//! close a level |
| 84 |
void closeLevel(); |
| 85 |
//! returns the classname corresponding to a list element |
| 86 |
std::string getClass(librevenge::RVNGPropertyList const &pList); |
| 87 |
|
| 88 |
//! send the data to the sink |
| 89 |
void send(EPUBCSSContent &out); |
| 90 |
protected: |
| 91 |
//! a map content -> list level name |
| 92 |
List::ContentNameMap_t m_levelNameMap; |
| 93 |
//! a map listId -> list |
| 94 |
std::map<int, List> m_idListMap; |
| 95 |
//! the actual list id |
| 96 |
std::vector<int> m_actualIdStack; |
| 97 |
private: |
| 98 |
EPUBListStyleManager(EPUBListStyleManager const &orig); |
| 99 |
EPUBListStyleManager operator=(EPUBListStyleManager const &orig); |
| 100 |
}; |
| 101 |
|
| 102 |
} |
| 103 |
|
| 104 |
#endif |
| 105 |
|
| 106 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |