/src/libetonyek/src/lib/IWORKStyle.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libetonyek 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 "IWORKStyle.h" |
11 | | |
12 | | #include "libetonyek_utils.h" |
13 | | #include "IWORKStyleStack.h" |
14 | | |
15 | | #include "IWORKProperties.h" |
16 | | |
17 | | namespace libetonyek |
18 | | { |
19 | | |
20 | | IWORKStyle::IWORKStyle(const IWORKPropertyMap &props, const boost::optional<std::string> &ident, const boost::optional<std::string> &parentIdent) |
21 | 20.8k | : m_props(props) |
22 | 20.8k | , m_ident(ident) |
23 | 20.8k | , m_parentIdent(parentIdent) |
24 | 20.8k | , m_parent() |
25 | 20.8k | { |
26 | 20.8k | } |
27 | | |
28 | | IWORKStyle::IWORKStyle(const IWORKPropertyMap &props, const boost::optional<std::string> &ident, const IWORKStylePtr_t &parent) |
29 | 15.4k | : m_props(props) |
30 | 15.4k | , m_ident(ident) |
31 | 15.4k | , m_parentIdent() |
32 | 15.4k | , m_parent(parent) |
33 | 15.4k | { |
34 | 15.4k | if (m_parent) |
35 | 6.25k | m_props.setParent(&m_parent->getPropertyMap()); |
36 | 15.4k | } |
37 | | |
38 | | bool IWORKStyle::link(const IWORKStylesheetPtr_t &stylesheet) |
39 | 0 | { |
40 | 0 | if (m_parent || !m_parentIdent) |
41 | 0 | return true; |
42 | 0 | IWORKStylesheetPtr_t currentStylesheet = stylesheet; |
43 | |
|
44 | 0 | if (currentStylesheet && (m_ident == m_parentIdent)) |
45 | 0 | { |
46 | 0 | assert(currentStylesheet->parent != currentStylesheet); |
47 | 0 | currentStylesheet = currentStylesheet->parent; |
48 | 0 | } |
49 | |
|
50 | 0 | if (!currentStylesheet) |
51 | 0 | { |
52 | 0 | ETONYEK_DEBUG_MSG(("IWORKStyle::find: can not find parent %s\n", m_parentIdent.get().c_str())); |
53 | 0 | return false; |
54 | 0 | } |
55 | 0 | m_parent=currentStylesheet->find(m_parentIdent.get()); |
56 | 0 | if (m_parent) |
57 | 0 | m_props.setParent(&m_parent->getPropertyMap()); |
58 | |
|
59 | 0 | return bool(m_parent); |
60 | 0 | } |
61 | | |
62 | | void IWORKStyle::flatten() |
63 | 0 | { |
64 | | // TODO: implement me |
65 | 0 | } |
66 | | |
67 | | const IWORKPropertyMap &IWORKStyle::getPropertyMap() const |
68 | 0 | { |
69 | 0 | return m_props; |
70 | 0 | } |
71 | | |
72 | | IWORKPropertyMap &IWORKStyle::getPropertyMap() |
73 | 3.11M | { |
74 | 3.11M | return m_props; |
75 | 3.11M | } |
76 | | |
77 | | const boost::optional<std::string> &IWORKStyle::getIdent() const |
78 | 0 | { |
79 | 0 | return m_ident; |
80 | 0 | } |
81 | | |
82 | | const boost::optional<std::string> &IWORKStyle::getParentIdent() const |
83 | 0 | { |
84 | 0 | return m_parentIdent; |
85 | 0 | } |
86 | | |
87 | | const IWORKStylePtr_t IWORKStyle::getParent() const |
88 | 0 | { |
89 | 0 | return m_parent; |
90 | 0 | } |
91 | | |
92 | | void IWORKStyle::setParent(const IWORKStylePtr_t parent) |
93 | 0 | { |
94 | 0 | m_parent=parent; |
95 | 0 | if (m_parent) |
96 | 0 | m_props.setParent(&m_parent->getPropertyMap()); |
97 | 0 | } |
98 | | |
99 | | void IWORKStyle::createListLevelStyles() |
100 | 1.16k | { |
101 | 1.16k | using namespace property; |
102 | 1.16k | if (m_props.has<ListLevelStyles>(false)) |
103 | 1.16k | return; |
104 | 0 | std::deque<IWORKListLabelGeometry> const emptyLabelGeometries; |
105 | 0 | std::deque<IWORKListLabelTypeInfo_t> const emptyTypeInfos; |
106 | 0 | std::deque<double> const emptyDoubleQue; |
107 | 0 | std::deque<IWORKListLabelGeometry> const &labelGeometries= |
108 | 0 | has<ListLabelGeometries>() ? get<ListLabelGeometries>() : emptyLabelGeometries; |
109 | 0 | std::deque<double> const &labelIndents= |
110 | 0 | has<ListLabelIndents>() ? get<ListLabelIndents>() : emptyDoubleQue; |
111 | 0 | std::deque<double> const &textIndents= |
112 | 0 | has<ListTextIndents>() ? get<ListTextIndents>() : emptyDoubleQue; |
113 | 0 | std::deque<IWORKListLabelTypeInfo_t> const &typeInfos= |
114 | 0 | has<ListLabelTypes>() ? get<ListLabelTypes>() : emptyTypeInfos; |
115 | 0 | using std::max; |
116 | |
|
117 | 0 | const std::size_t levels = (max)((max)(labelGeometries.size(), typeInfos.size()), |
118 | 0 | (max)(labelIndents.size(), textIndents.size())); |
119 | 0 | std::deque<IWORKPropertyMap> levelProps(levels); |
120 | 0 | for (std::size_t i = 0; i != levels; ++i) |
121 | 0 | { |
122 | 0 | if (i < labelGeometries.size()) |
123 | 0 | levelProps[i].put<ListLabelGeometry>(labelGeometries[i]); |
124 | 0 | if (i < typeInfos.size()) |
125 | 0 | levelProps[i].put<ListLabelTypeInfo>(typeInfos[i]); |
126 | 0 | if (i < labelIndents.size()) |
127 | 0 | levelProps[i].put<ListLabelIndent>(labelIndents[i]); |
128 | 0 | if (i < textIndents.size()) |
129 | 0 | levelProps[i].put<ListTextIndent>(textIndents[i]); |
130 | 0 | } |
131 | 0 | IWORKListLevels_t levelsStyle; |
132 | 0 | for (std::size_t i = 0; i != levels; ++i) |
133 | 0 | levelsStyle[unsigned(i)] = std::make_shared<IWORKStyle>(levelProps[i], boost::none, boost::none); |
134 | 0 | m_props.put<ListLevelStyles>(levelsStyle); |
135 | 0 | } |
136 | | |
137 | | } |
138 | | |
139 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |