| 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_EPUBIMAGEMANAGER_H |
| 11 |
#define INCLUDED_EPUBIMAGEMANAGER_H |
| 12 |
|
| 13 |
#include <string> |
| 14 |
#include <unordered_map> |
| 15 |
#include <unordered_set> |
| 16 |
|
| 17 |
#include <boost/functional/hash.hpp> |
| 18 |
|
| 19 |
#include <librevenge/librevenge.h> |
| 20 |
|
| 21 |
#include "EPUBCSSProperties.h" |
| 22 |
#include "EPUBCounter.h" |
| 23 |
#include "EPUBPath.h" |
| 24 |
|
| 25 |
namespace libepubgen |
| 26 |
{ |
| 27 |
|
| 28 |
class EPUBManifest; |
| 29 |
class EPUBPackage; |
| 30 |
class EPUBCSSContent; |
| 31 |
|
| 32 |
class EPUBImageManager |
| 33 |
{ |
| 34 |
// disable copying |
| 35 |
EPUBImageManager(const EPUBImageManager &); |
| 36 |
EPUBImageManager &operator=(const EPUBImageManager &); |
| 37 |
|
| 38 |
struct BinaryDataHash // : public std::unary_function<librevenge::RVNGBinaryData, std::size_t> |
| 39 |
{ |
| 40 |
std::size_t operator()(const librevenge::RVNGBinaryData &data) const; |
| 41 |
}; |
| 42 |
|
| 43 |
struct BinaryDataEqual // : public std::binary_function<librevenge::RVNGBinaryData, librevenge::RVNGBinaryData, bool> |
| 44 |
{ |
| 45 |
bool operator()(const librevenge::RVNGBinaryData &left, const librevenge::RVNGBinaryData &right) const; |
| 46 |
}; |
| 47 |
|
| 48 |
typedef std::unordered_map<librevenge::RVNGBinaryData, EPUBPath, BinaryDataHash, BinaryDataEqual> MapType_t; |
| 49 |
typedef std::unordered_map<EPUBCSSProperties, std::string, boost::hash<EPUBCSSProperties>> ContentNameMap_t; |
| 50 |
|
| 51 |
public: |
| 52 |
explicit EPUBImageManager(EPUBManifest &manifest); |
| 53 |
|
| 54 |
const EPUBPath &insert(const librevenge::RVNGBinaryData &data, const librevenge::RVNGString &mimetype, const librevenge::RVNGString &properties=""); |
| 55 |
|
| 56 |
void writeTo(EPUBPackage &package); |
| 57 |
|
| 58 |
//! returns the class name corresponding to a propertylist |
| 59 |
std::string getFrameClass(librevenge::RVNGPropertyList const &pList); |
| 60 |
//! returns the style string corresponding to a propertylist |
| 61 |
std::string getFrameStyle(librevenge::RVNGPropertyList const &pList); |
| 62 |
//! returns the style for a follow-up <br> element, based on wrapping properties. |
| 63 |
static std::string getWrapStyle(librevenge::RVNGPropertyList const &pList); |
| 64 |
//! send the data to the sink |
| 65 |
void send(EPUBCSSContent &out); |
| 66 |
|
| 67 |
private: |
| 68 |
//! convert a property list into a CSS property map |
| 69 |
void extractImageProperties(librevenge::RVNGPropertyList const &pList, EPUBCSSProperties &cssProps) const; |
| 70 |
|
| 71 |
EPUBManifest &m_manifest; |
| 72 |
MapType_t m_map; |
| 73 |
EPUBCounter m_number; |
| 74 |
//! a map image content -> name |
| 75 |
ContentNameMap_t m_imageContentNameMap; |
| 76 |
}; |
| 77 |
|
| 78 |
} |
| 79 |
|
| 80 |
#endif // INCLUDED_EPUBIMAGEMANAGER |
| 81 |
|
| 82 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |