differential code coverage report with master
Current view: top level - source/worksheet - header_footer.cpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 42.6 % 141 60 81 60
Current Date: 2025-12-15 23:01:28 Functions: 43.8 % 48 21 27 21
Baseline: coverage_master.info Branches: 31.8 % 66 21 90 42
Baseline Date: 2025-12-15 23:01:27

             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/worksheet/header_footer.hpp>
      27                 :                : 
      28                 :                : namespace xlnt {
      29                 :                : 
      30                 :UBC           0 : bool header_footer::has_header() const
      31                 :                : {
      32   [ #  #  #  #  :              0 :     return !odd_headers_.empty() || !even_headers_.empty() || has_first_page_header();
                   #  # ]
      33                 :                : }
      34                 :                : 
      35                 :              0 : bool header_footer::has_footer() const
      36                 :                : {
      37   [ #  #  #  #  :              0 :     return !odd_headers_.empty() || !even_headers_.empty() || has_first_page_footer();
                   #  # ]
      38                 :                : }
      39                 :                : 
      40                 :CBC           1 : bool header_footer::align_with_margins() const
      41                 :                : {
      42                 :              1 :     return align_with_margins_;
      43                 :                : }
      44                 :                : 
      45                 :             29 : header_footer &header_footer::align_with_margins(bool align)
      46                 :                : {
      47                 :             29 :     align_with_margins_ = align;
      48                 :             29 :     return *this;
      49                 :                : }
      50                 :                : 
      51                 :             28 : bool header_footer::different_odd_even() const
      52                 :                : {
      53                 :             28 :     return different_odd_even_;
      54                 :                : }
      55                 :                : 
      56                 :             22 : bool header_footer::different_first() const
      57                 :                : {
      58   [ +  -  -  + ]:             22 :     return !first_headers_.empty() || !first_footers_.empty();
      59                 :                : }
      60                 :                : 
      61                 :              1 : bool header_footer::scale_with_doc() const
      62                 :                : {
      63                 :              1 :     return scale_with_doc_;
      64                 :                : }
      65                 :                : 
      66                 :             29 : header_footer &header_footer::scale_with_doc(bool scale)
      67                 :                : {
      68                 :             29 :     scale_with_doc_ = scale;
      69                 :             29 :     return *this;
      70                 :                : }
      71                 :                : 
      72                 :                : // Normal Header
      73                 :                : 
      74                 :             27 : bool header_footer::has_header(location where) const
      75                 :                : {
      76   [ +  +  -  + ]:             27 :     return odd_headers_.count(where) > 0 || has_first_page_header(where);
      77                 :                : }
      78                 :                : 
      79                 :UBC           0 : void header_footer::clear_header()
      80                 :                : {
      81                 :              0 :     odd_headers_.clear();
      82                 :              0 :     even_headers_.clear();
      83                 :              0 :     first_headers_.clear();
      84                 :              0 : }
      85                 :                : 
      86                 :CBC           3 : void header_footer::clear_header(location where)
      87                 :                : {
      88                 :              3 :     odd_headers_.erase(where);
      89                 :              3 :     even_headers_.erase(where);
      90                 :              3 :     first_headers_.erase(where);
      91                 :              3 : }
      92                 :                : 
      93                 :              3 : header_footer &header_footer::header(location where, const std::string &text)
      94                 :                : {
      95         [ +  + ]:              3 :     return header(where, rich_text(text));
      96                 :                : }
      97                 :                : 
      98                 :             27 : header_footer &header_footer::header(location where, const rich_text &text)
      99                 :                : {
     100                 :             27 :     odd_headers_[where] = text;
     101                 :             27 :     return *this;
     102                 :                : }
     103                 :                : 
     104                 :             14 : rich_text header_footer::header(location where) const
     105                 :                : {
     106                 :             14 :     return odd_headers_.at(where);
     107                 :                : }
     108                 :                : 
     109                 :                : // First Page Header
     110                 :                : 
     111                 :UBC           0 : bool header_footer::has_first_page_header() const
     112                 :                : {
     113                 :              0 :     return !first_headers_.empty();
     114                 :                : }
     115                 :                : 
     116                 :CBC          19 : bool header_footer::has_first_page_header(location where) const
     117                 :                : {
     118                 :             19 :     return first_headers_.count(where) > 0;
     119                 :                : }
     120                 :                : 
     121                 :UBC           0 : void header_footer::clear_first_page_header()
     122                 :                : {
     123                 :              0 :     first_headers_.clear();
     124                 :              0 : }
     125                 :                : 
     126                 :              0 : void header_footer::clear_first_page_header(location where)
     127                 :                : {
     128                 :              0 :     first_headers_.erase(where);
     129                 :              0 : }
     130                 :                : 
     131                 :              0 : header_footer &header_footer::first_page_header(location where, const rich_text &text)
     132                 :                : {
     133                 :              0 :     first_headers_[where] = text;
     134                 :              0 :     return *this;
     135                 :                : }
     136                 :                : 
     137                 :              0 : rich_text header_footer::first_page_header(location where) const
     138                 :                : {
     139                 :              0 :     return first_headers_.at(where);
     140                 :                : }
     141                 :                : 
     142                 :                : // Odd/Even Header
     143                 :                : 
     144                 :              0 : bool header_footer::has_odd_even_header() const
     145                 :                : {
     146   [ #  #  #  # ]:              0 :     return different_odd_even() && !odd_headers_.empty();
     147                 :                : }
     148                 :                : 
     149                 :CBC           6 : bool header_footer::has_odd_even_header(location where) const
     150                 :                : {
     151   [ -  +  -  - ]:              6 :     return different_odd_even() && odd_headers_.count(where) > 0;
     152                 :                : }
     153                 :                : 
     154                 :UBC           0 : void header_footer::clear_odd_even_header()
     155                 :                : {
     156                 :              0 :     odd_headers_.clear();
     157                 :              0 :     even_headers_.clear();
     158                 :              0 :     different_odd_even_ = false;
     159                 :              0 : }
     160                 :                : 
     161                 :              0 : void header_footer::clear_odd_even_header(location where)
     162                 :                : {
     163                 :              0 :     odd_headers_.erase(where);
     164                 :              0 :     even_headers_.erase(where);
     165                 :              0 : }
     166                 :                : 
     167                 :              0 : header_footer &header_footer::odd_even_header(location where, const rich_text &odd, const rich_text &even)
     168                 :                : {
     169                 :              0 :     odd_headers_[where] = odd;
     170                 :              0 :     even_headers_[where] = even;
     171                 :              0 :     different_odd_even_ = true;
     172                 :                : 
     173                 :              0 :     return *this;
     174                 :                : }
     175                 :                : 
     176                 :              0 : rich_text header_footer::odd_header(location where) const
     177                 :                : {
     178                 :              0 :     return odd_headers_.at(where);
     179                 :                : }
     180                 :                : 
     181                 :              0 : rich_text header_footer::even_header(location where) const
     182                 :                : {
     183                 :              0 :     return even_headers_.at(where);
     184                 :                : }
     185                 :                : 
     186                 :                : // Normal Footer
     187                 :                : 
     188                 :CBC          27 : bool header_footer::has_footer(location where) const
     189                 :                : {
     190                 :             27 :     return odd_footers_.count(where) > 0;
     191                 :                : }
     192                 :                : 
     193                 :UBC           0 : void header_footer::clear_footer()
     194                 :                : {
     195                 :              0 :     odd_footers_.clear();
     196                 :              0 :     even_footers_.clear();
     197                 :              0 :     first_footers_.clear();
     198                 :              0 : }
     199                 :                : 
     200                 :CBC           3 : void header_footer::clear_footer(location where)
     201                 :                : {
     202                 :              3 :     odd_footers_.erase(where);
     203                 :              3 :     even_footers_.erase(where);
     204                 :              3 :     first_footers_.erase(where);
     205                 :              3 : }
     206                 :                : 
     207                 :              3 : header_footer &header_footer::footer(location where, const std::string &text)
     208                 :                : {
     209         [ +  + ]:              3 :     return footer(where, rich_text(text));
     210                 :                : }
     211                 :                : 
     212                 :             29 : header_footer &header_footer::footer(location where, const rich_text &text)
     213                 :                : {
     214                 :             29 :     odd_footers_[where] = text;
     215                 :             29 :     return *this;
     216                 :                : }
     217                 :                : 
     218                 :             15 : rich_text header_footer::footer(location where) const
     219                 :                : {
     220                 :             15 :     return odd_footers_.at(where);
     221                 :                : }
     222                 :                : 
     223                 :                : // First Page footer
     224                 :                : 
     225                 :UBC           0 : bool header_footer::has_first_page_footer() const
     226                 :                : {
     227   [ #  #  #  # ]:              0 :     return different_first() && !first_footers_.empty();
     228                 :                : }
     229                 :                : 
     230                 :CBC           6 : bool header_footer::has_first_page_footer(location where) const
     231                 :                : {
     232   [ -  +  -  - ]:              6 :     return different_first() && first_footers_.count(where) > 0;
     233                 :                : }
     234                 :                : 
     235                 :UBC           0 : void header_footer::clear_first_page_footer()
     236                 :                : {
     237                 :              0 :     first_footers_.clear();
     238                 :              0 : }
     239                 :                : 
     240                 :              0 : void header_footer::clear_first_page_footer(location where)
     241                 :                : {
     242                 :              0 :     first_footers_.erase(where);
     243                 :              0 : }
     244                 :                : 
     245                 :              0 : header_footer &header_footer::first_page_footer(location where, const rich_text &text)
     246                 :                : {
     247                 :              0 :     first_footers_[where] = text;
     248                 :              0 :     return *this;
     249                 :                : }
     250                 :                : 
     251                 :              0 : rich_text header_footer::first_page_footer(location where) const
     252                 :                : {
     253                 :              0 :     return first_footers_.at(where);
     254                 :                : }
     255                 :                : 
     256                 :                : // Odd/Even Footer
     257                 :                : 
     258                 :              0 : bool header_footer::has_odd_even_footer() const
     259                 :                : {
     260   [ #  #  #  # ]:              0 :     return different_odd_even() && !even_footers_.empty();
     261                 :                : }
     262                 :                : 
     263                 :CBC           6 : bool header_footer::has_odd_even_footer(location where) const
     264                 :                : {
     265   [ -  +  -  - ]:              6 :     return different_odd_even() && even_footers_.count(where) > 0;
     266                 :                : }
     267                 :                : 
     268                 :UBC           0 : void header_footer::clear_odd_even_footer()
     269                 :                : {
     270                 :              0 :     odd_footers_.clear();
     271                 :              0 :     even_footers_.clear();
     272                 :              0 : }
     273                 :                : 
     274                 :              0 : void header_footer::clear_odd_even_footer(location where)
     275                 :                : {
     276                 :              0 :     odd_footers_.erase(where);
     277                 :              0 :     even_footers_.erase(where);
     278                 :              0 : }
     279                 :                : 
     280                 :              0 : header_footer &header_footer::odd_even_footer(location where, const rich_text &odd, const rich_text &even)
     281                 :                : {
     282                 :              0 :     odd_footers_[where] = odd;
     283                 :              0 :     even_footers_[where] = even;
     284                 :              0 :     different_odd_even_ = true;
     285                 :                : 
     286                 :              0 :     return *this;
     287                 :                : }
     288                 :                : 
     289                 :              0 : rich_text header_footer::odd_footer(location where) const
     290                 :                : {
     291                 :              0 :     return odd_footers_.at(where);
     292                 :                : }
     293                 :                : 
     294                 :              0 : rich_text header_footer::even_footer(location where) const
     295                 :                : {
     296                 :              0 :     return even_footers_.at(where);
     297                 :                : }
     298                 :                : 
     299                 :CBC           6 : bool header_footer::operator==(const header_footer &rhs) const
     300                 :                : {
     301                 :              6 :     return align_with_margins_ == rhs.align_with_margins_
     302         [ +  - ]:              6 :         && different_odd_even_ == rhs.different_odd_even_
     303         [ +  - ]:              6 :         && scale_with_doc_ == rhs.scale_with_doc_
     304         [ +  - ]:              6 :         && odd_headers_ == rhs.odd_headers_
     305         [ +  - ]:              6 :         && even_headers_ == rhs.even_headers_
     306         [ +  - ]:              6 :         && first_headers_ == rhs.first_headers_
     307         [ +  - ]:              6 :         && odd_footers_ == rhs.odd_footers_
     308         [ +  - ]:              6 :         && even_footers_ == rhs.even_footers_
     309   [ +  -  +  - ]:             12 :         && first_footers_ == rhs.first_footers_;
     310                 :                : }
     311                 :                : 
     312                 :UBC           0 : bool header_footer::operator!=(const header_footer &rhs) const
     313                 :                : {
     314                 :              0 :     return !(*this == rhs);
     315                 :                : }
     316                 :                : 
     317                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta