Branch data TLA Line data Source code
1 : : // Copyright (c) 2014-2022 Thomas Fussell
2 : : // Copyright (c) 2010-2015 openpyxl
3 : : // Copyright (c) 2024-2025 xlnt-community
4 : : //
5 : : // Permission is hereby granted, free of charge, to any person obtaining a copy
6 : : // of this software and associated documentation files (the "Software"), to deal
7 : : // in the Software without restriction, including without limitation the rights
8 : : // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 : : // copies of the Software, and to permit persons to whom the Software is
10 : : // furnished to do so, subject to the following conditions:
11 : : //
12 : : // The above copyright notice and this permission notice shall be included in
13 : : // all copies or substantial portions of the Software.
14 : : //
15 : : // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 : : // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 : : // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 : : // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 : : // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 : : // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 : : // THE SOFTWARE
22 : : //
23 : : // @license: http://www.opensource.org/licenses/mit-license.php
24 : : // @author: see AUTHORS file
25 : :
26 : : #include <xlnt/styles/border.hpp>
27 : : #include <xlnt/styles/conditional_format.hpp>
28 : : #include <xlnt/styles/fill.hpp>
29 : : #include <xlnt/styles/font.hpp>
30 : : #include <detail/implementations/conditional_format_impl.hpp>
31 : : #include <detail/implementations/stylesheet.hpp>
32 : :
33 : : namespace xlnt {
34 : :
35 :UBC 0 : condition condition::text_starts_with(const std::string &text)
36 : : {
37 : 0 : condition c;
38 : 0 : c.type_ = type::contains_text;
39 : 0 : c.operator_ = condition_operator::starts_with;
40 [ # ]: 0 : c.text_comparand_ = text;
41 : 0 : return c;
42 : 0 : }
43 : :
44 : 0 : condition condition::text_ends_with(const std::string &text)
45 : : {
46 : 0 : condition c;
47 : 0 : c.type_ = type::contains_text;
48 : 0 : c.operator_ = condition_operator::ends_with;
49 [ # ]: 0 : c.text_comparand_ = text;
50 : 0 : return c;
51 : 0 : }
52 : :
53 :CBC 1 : condition condition::text_contains(const std::string &text)
54 : : {
55 : 1 : condition c;
56 : 1 : c.type_ = type::contains_text;
57 : 1 : c.operator_ = condition_operator::contains;
58 [ + ]: 1 : c.text_comparand_ = text;
59 : 1 : return c;
60 :UBC 0 : }
61 : :
62 : 0 : condition condition::text_does_not_contain(const std::string &text)
63 : : {
64 : 0 : condition c;
65 : 0 : c.type_ = type::contains_text;
66 : 0 : c.operator_ = condition_operator::does_not_contain;
67 [ # ]: 0 : c.text_comparand_ = text;
68 : 0 : return c;
69 : 0 : }
70 : :
71 :CBC 1 : conditional_format::conditional_format(detail::conditional_format_impl *d)
72 : 1 : : d_(d)
73 : : {
74 : 1 : }
75 : :
76 : 1 : bool conditional_format::operator==(const conditional_format &other) const
77 : : {
78 : 1 : return d_ == other.d_;
79 : : }
80 : :
81 :UBC 0 : bool conditional_format::operator!=(const conditional_format &other) const
82 : : {
83 : 0 : return !(*this == other);
84 : : }
85 : :
86 :CBC 2 : bool conditional_format::has_border() const
87 : : {
88 : 2 : return d_->border_id.is_set();
89 : : }
90 : :
91 : 1 : xlnt::border conditional_format::border() const
92 : : {
93 : 1 : return d_->parent->borders.at(d_->border_id.get());
94 : : }
95 : :
96 : 1 : conditional_format conditional_format::border(const xlnt::border &new_border)
97 : : {
98 [ + ]: 1 : d_->border_id = d_->parent->find_or_add(d_->parent->borders, new_border);
99 : 1 : return *this;
100 : : }
101 : :
102 : 2 : bool conditional_format::has_fill() const
103 : : {
104 : 2 : return d_->fill_id.is_set();
105 : : }
106 : :
107 : 1 : xlnt::fill conditional_format::fill() const
108 : : {
109 : 1 : return d_->parent->fills.at(d_->fill_id.get());
110 : : }
111 : :
112 : 1 : conditional_format conditional_format::fill(const xlnt::fill &new_fill)
113 : : {
114 [ + ]: 1 : d_->fill_id = d_->parent->find_or_add(d_->parent->fills, new_fill);
115 : 1 : return *this;
116 : : }
117 : :
118 : 2 : bool conditional_format::has_font() const
119 : : {
120 : 2 : return d_->font_id.is_set();
121 : : }
122 : :
123 : 1 : xlnt::font conditional_format::font() const
124 : : {
125 : 1 : return d_->parent->fonts.at(d_->font_id.get());
126 : : }
127 : :
128 : 1 : conditional_format conditional_format::font(const xlnt::font &new_font)
129 : : {
130 [ + ]: 1 : d_->font_id = d_->parent->find_or_add(d_->parent->fonts, new_font);
131 : 1 : return *this;
132 : : }
133 : :
134 : : } // namespace xlnt
|