1 /*
2  * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  */
19 
20 #ifndef __STYLESHEETTABLE_H__
21 #define __STYLESHEETTABLE_H__
22 
23 #include <string>
24 #include <map>
25 #include <vector>
26 
27 #include <shared_ptr.h>
28 
29 #include <ZLTextParagraph.h>
30 
31 class StyleSheetTable {
32 
33 public:
34 	typedef std::map<std::string,std::vector<std::string> > AttributeMap;
35 	static shared_ptr<ZLTextStyleEntry> createControl(const AttributeMap &map);
36 
37 private:
38 	void addMap(const std::string &tag, const std::string &aClass, const AttributeMap &map);
39 
40 	static void setLength(ZLTextStyleEntry &entry, ZLTextStyleEntry::Length name, const AttributeMap &map, const std::string &attributeName);
41 	static const std::vector<std::string> &values(const AttributeMap &map, const std::string &name);
42 
43 public:
44 	bool isEmpty() const;
45 	bool doBreakBefore(const std::string &tag, const std::string &aClass) const;
46 	bool doBreakAfter(const std::string &tag, const std::string &aClass) const;
47 	shared_ptr<ZLTextStyleEntry> control(const std::string &tag, const std::string &aClass) const;
48 
49 private:
50 	struct Key {
51 		Key(const std::string &tag, const std::string &aClass);
52 
53 		const std::string TagName;
54 		const std::string ClassName;
55 
56 		bool operator < (const Key &key) const;
57 	};
58 
59 	std::map<Key,shared_ptr<ZLTextStyleEntry> > myControlMap;
60 	std::map<Key,bool> myPageBreakBeforeMap;
61 	std::map<Key,bool> myPageBreakAfterMap;
62 
63 friend class StyleSheetTableParser;
64 };
65 
Key(const std::string & tag,const std::string & aClass)66 inline StyleSheetTable::Key::Key(const std::string &tag, const std::string &aClass) : TagName(tag), ClassName(aClass) {
67 }
68 
69 inline bool StyleSheetTable::Key::operator < (const StyleSheetTable::Key &key) const {
70 	return (TagName < key.TagName) || ((TagName == key.TagName) && (ClassName < key.ClassName));
71 }
72 
73 #endif /* __STYLESHEETTABLE_H__ */
74