differential code coverage report with master
Current view: top level - source/styles - fill.cpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 74.6 % 126 94 32 94
Current Date: 2025-12-07 02:01:22 Functions: 77.8 % 36 28 8 28
Baseline: coverage_master.info Branches: 80.0 % 60 48 24 96
Baseline Date: 2025-12-07 02:01:21

             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 <cmath> // for std::fabs
      27                 :                : 
      28                 :                : #include <xlnt/styles/fill.hpp>
      29                 :                : 
      30                 :                : namespace xlnt {
      31                 :                : 
      32                 :                : // pattern_fill
      33                 :                : 
      34                 :CBC        1515 : pattern_fill::pattern_fill()
      35                 :                : {
      36                 :           1515 : }
      37                 :                : 
      38                 :           1292 : pattern_fill_type pattern_fill::type() const
      39                 :                : {
      40                 :           1292 :     return type_;
      41                 :                : }
      42                 :                : 
      43                 :           1003 : pattern_fill &pattern_fill::type(pattern_fill_type type)
      44                 :                : {
      45                 :           1003 :     type_ = type;
      46                 :           1003 :     return *this;
      47                 :                : }
      48                 :                : 
      49                 :           1973 : optional<color> pattern_fill::foreground() const
      50                 :                : {
      51                 :           1973 :     return foreground_;
      52                 :                : }
      53                 :                : 
      54                 :            323 : pattern_fill &pattern_fill::foreground(const color &new_foreground)
      55                 :                : {
      56                 :            323 :     foreground_ = new_foreground;
      57                 :                : 
      58         [ +  - ]:            323 :     if (!background_.is_set())
      59                 :                :     {
      60         [ +  + ]:            323 :         background_.set(indexed_color(64));
      61                 :                :     }
      62                 :                : 
      63                 :            323 :     return *this;
      64                 :                : }
      65                 :                : 
      66                 :           1985 : optional<color> pattern_fill::background() const
      67                 :                : {
      68                 :           1985 :     return background_;
      69                 :                : }
      70                 :                : 
      71                 :            242 : pattern_fill &pattern_fill::background(const color &new_background)
      72                 :                : {
      73                 :            242 :     background_ = new_background;
      74                 :            242 :     return *this;
      75                 :                : }
      76                 :                : 
      77                 :            548 : bool pattern_fill::operator==(const pattern_fill &other) const
      78                 :                : {
      79         [ +  + ]:            548 :     if (background().is_set() != other.background().is_set())
      80                 :                :     {
      81                 :              6 :         return false;
      82                 :                :     }
      83                 :                : 
      84         [ +  + ]:            542 :     if (background().is_set())
      85                 :                :     {
      86   [ +  +  +  -  :              4 :         if (background().get() != other.background().get())
                      + ]
      87                 :                :         {
      88                 :UBC           0 :             return false;
      89                 :                :         }
      90                 :                :     }
      91                 :                : 
      92         [ -  + ]:CBC         542 :     if (foreground().is_set() != other.foreground().is_set())
      93                 :                :     {
      94                 :UBC           0 :         return false;
      95                 :                :     }
      96                 :                : 
      97         [ +  + ]:CBC         542 :     if (foreground().is_set())
      98                 :                :     {
      99   [ +  +  +  +  :              4 :         if (foreground().get() != other.foreground().get())
                      + ]
     100                 :                :         {
     101                 :              1 :             return false;
     102                 :                :         }
     103                 :                :     }
     104                 :                : 
     105         [ -  + ]:            541 :     if (type() != other.type())
     106                 :                :     {
     107                 :UBC           0 :         return false;
     108                 :                :     }
     109                 :                : 
     110                 :CBC         541 :     return true;
     111                 :                : }
     112                 :                : 
     113                 :UBC           0 : bool pattern_fill::operator!=(const pattern_fill &other) const
     114                 :                : {
     115                 :              0 :     return !(*this == other);
     116                 :                : }
     117                 :                : 
     118                 :                : // gradient_fill
     119                 :                : 
     120                 :CBC        1516 : gradient_fill::gradient_fill()
     121                 :           1516 :     : type_(gradient_fill_type::linear)
     122                 :                : {
     123                 :           1516 : }
     124                 :                : 
     125                 :             16 : gradient_fill_type gradient_fill::type() const
     126                 :                : {
     127                 :             16 :     return type_;
     128                 :                : }
     129                 :                : 
     130                 :              4 : gradient_fill &gradient_fill::type(gradient_fill_type t)
     131                 :                : {
     132                 :              4 :     type_ = t;
     133                 :              4 :     return *this;
     134                 :                : }
     135                 :                : 
     136                 :              1 : gradient_fill &gradient_fill::degree(double degree)
     137                 :                : {
     138                 :              1 :     degree_ = degree;
     139                 :              1 :     return *this;
     140                 :                : }
     141                 :                : 
     142                 :             15 : double gradient_fill::degree() const
     143                 :                : {
     144                 :             15 :     return degree_;
     145                 :                : }
     146                 :                : 
     147                 :             14 : double gradient_fill::left() const
     148                 :                : {
     149                 :             14 :     return left_;
     150                 :                : }
     151                 :                : 
     152                 :UBC           0 : gradient_fill &gradient_fill::left(double value)
     153                 :                : {
     154                 :              0 :     left_ = value;
     155                 :              0 :     return *this;
     156                 :                : }
     157                 :                : 
     158                 :CBC          14 : double gradient_fill::right() const
     159                 :                : {
     160                 :             14 :     return right_;
     161                 :                : }
     162                 :                : 
     163                 :UBC           0 : gradient_fill &gradient_fill::right(double value)
     164                 :                : {
     165                 :              0 :     right_ = value;
     166                 :              0 :     return *this;
     167                 :                : }
     168                 :                : 
     169                 :CBC          14 : double gradient_fill::top() const
     170                 :                : {
     171                 :             14 :     return top_;
     172                 :                : }
     173                 :                : 
     174                 :UBC           0 : gradient_fill &gradient_fill::top(double value)
     175                 :                : {
     176                 :              0 :     top_ = value;
     177                 :              0 :     return *this;
     178                 :                : }
     179                 :                : 
     180                 :CBC          14 : double gradient_fill::bottom() const
     181                 :                : {
     182                 :             14 :     return bottom_;
     183                 :                : }
     184                 :                : 
     185                 :UBC           0 : gradient_fill &gradient_fill::bottom(double value)
     186                 :                : {
     187                 :              0 :     bottom_ = value;
     188                 :              0 :     return *this;
     189                 :                : }
     190                 :                : 
     191                 :              0 : gradient_fill &gradient_fill::add_stop(double position, const color& stop_color)
     192                 :                : {
     193                 :              0 :     stops_[position] = stop_color;
     194                 :              0 :     return *this;
     195                 :                : }
     196                 :                : 
     197                 :              0 : gradient_fill &gradient_fill::clear_stops()
     198                 :                : {
     199                 :              0 :     stops_.clear();
     200                 :              0 :     return *this;
     201                 :                : }
     202                 :                : 
     203                 :CBC          13 : std::unordered_map<double, color> gradient_fill::stops() const
     204                 :                : {
     205                 :             13 :     return stops_;
     206                 :                : }
     207                 :                : 
     208                 :              7 : bool gradient_fill::operator==(const gradient_fill &other) const
     209                 :                : {
     210         [ +  + ]:              7 :     if (type() != other.type())
     211                 :                :     {
     212                 :              1 :         return false;
     213                 :                :     }
     214                 :                : 
     215         [ -  + ]:              6 :     if (std::fabs(degree() - other.degree()) != 0.)
     216                 :                :     {
     217                 :UBC           0 :         return false;
     218                 :                :     }
     219                 :                : 
     220         [ -  + ]:CBC           6 :     if (std::fabs(bottom() - other.bottom()) != 0.)
     221                 :                :     {
     222                 :UBC           0 :         return false;
     223                 :                :     }
     224                 :                : 
     225         [ -  + ]:CBC           6 :     if (std::fabs(right() - other.right()) != 0.)
     226                 :                :     {
     227                 :UBC           0 :         return false;
     228                 :                :     }
     229                 :                : 
     230         [ -  + ]:CBC           6 :     if (std::fabs(top() - other.top()) != 0.)
     231                 :                :     {
     232                 :UBC           0 :         return false;
     233                 :                :     }
     234                 :                : 
     235         [ -  + ]:CBC           6 :     if (std::fabs(left() - other.left()) != 0.)
     236                 :                :     {
     237                 :UBC           0 :         return false;
     238                 :                :     }
     239                 :                : 
     240   [ +  +  +  -  :CBC           6 :     if (stops() != other.stops())
                      + ]
     241                 :                :     {
     242                 :UBC           0 :         return false;
     243                 :                :     }
     244                 :                : 
     245                 :CBC           6 :     return true;
     246                 :                : }
     247                 :                : 
     248                 :UBC           0 : bool gradient_fill::operator!=(const gradient_fill &other) const
     249                 :                : {
     250                 :              0 :     return !(*this == other);
     251                 :                : }
     252                 :                : 
     253                 :                : // fill
     254                 :                : 
     255                 :CBC           4 : fill fill::solid(const color &fill_color)
     256                 :                : {
     257                 :              8 :     return fill(xlnt::pattern_fill()
     258                 :              4 :                     .type(xlnt::pattern_fill_type::solid)
     259            [ + ]:              4 :                     .foreground(fill_color)
     260         [ +  + ]:              8 :                     .background(indexed_color(64)));
     261                 :                : }
     262                 :                : 
     263                 :            490 : fill::fill()
     264                 :            490 :     : type_(fill_type::pattern)
     265                 :                : {
     266                 :            490 : }
     267                 :                : 
     268                 :           1014 : fill::fill(const xlnt::pattern_fill &pattern)
     269                 :           1014 :     : type_(fill_type::pattern), pattern_(pattern)
     270                 :                : {
     271                 :           1014 : }
     272                 :                : 
     273                 :             13 : fill::fill(const xlnt::gradient_fill &gradient)
     274                 :             13 :     : type_(fill_type::gradient), gradient_(gradient)
     275                 :                : {
     276                 :             13 : }
     277                 :                : 
     278                 :           1907 : fill_type fill::type() const
     279                 :                : {
     280                 :           1907 :     return type_;
     281                 :                : }
     282                 :                : 
     283                 :             23 : gradient_fill fill::gradient_fill() const
     284                 :                : {
     285         [ -  + ]:             23 :     if (type_ != fill_type::gradient)
     286                 :                :     {
     287            [ # ]:UBC           0 :         throw invalid_attribute();
     288                 :                :     }
     289                 :                : 
     290                 :CBC          23 :     return gradient_;
     291                 :                : }
     292                 :                : 
     293                 :           1315 : pattern_fill fill::pattern_fill() const
     294                 :                : {
     295         [ +  + ]:           1315 :     if (type_ != fill_type::pattern)
     296                 :                :     {
     297            [ + ]:              1 :         throw invalid_attribute();
     298                 :                :     }
     299                 :                : 
     300                 :           1314 :     return pattern_;
     301                 :                : }
     302                 :                : 
     303                 :            569 : bool fill::operator==(const fill &other) const
     304                 :                : {
     305         [ +  + ]:            569 :     if (type() != other.type())
     306                 :                :     {
     307                 :             14 :         return false;
     308                 :                :     }
     309                 :                : 
     310         [ +  + ]:            555 :     if (type() == fill_type::gradient)
     311                 :                :     {
     312      [ +  +  + ]:              7 :         return gradient_fill() == other.gradient_fill();
     313                 :                :     }
     314                 :                : 
     315      [ +  +  + ]:            548 :     return pattern_fill() == other.pattern_fill();
     316                 :                : }
     317                 :                : 
     318                 :              3 : bool fill::operator!=(const fill &other) const
     319                 :                : {
     320                 :              3 :     return !(*this == other);
     321                 :                : }
     322                 :                : 
     323                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta