differential code coverage report with master
Current view: top level - source/styles - style.cpp (source / functions) Coverage Total Hit UBC CBC
Current: coverage.info Lines: 54.6 % 108 59 49 59
Current Date: 2025-12-07 02:01:22 Functions: 52.9 % 34 18 16 18
Baseline: coverage_master.info Branches: 55.8 % 43 24 38 48
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 <xlnt/styles/alignment.hpp>
      27                 :                : #include <xlnt/styles/border.hpp>
      28                 :                : #include <xlnt/styles/fill.hpp>
      29                 :                : #include <xlnt/styles/font.hpp>
      30                 :                : #include <xlnt/styles/number_format.hpp>
      31                 :                : #include <xlnt/styles/protection.hpp>
      32                 :                : #include <xlnt/styles/style.hpp>
      33                 :                : #include <detail/implementations/style_impl.hpp>
      34                 :                : #include <detail/implementations/stylesheet.hpp>
      35                 :                : 
      36                 :                : namespace {
      37                 :                : 
      38                 :CBC         270 : std::vector<xlnt::number_format>::iterator find_number_format(
      39                 :                :     std::vector<xlnt::number_format> &number_formats, std::size_t id)
      40                 :                : {
      41                 :            270 :     return std::find_if(number_formats.begin(), number_formats.end(),
      42                 :            305 :         [=](const xlnt::number_format &nf) { return nf.id() == id; });
      43                 :                : }
      44                 :                : 
      45                 :                : } // namespace
      46                 :                : 
      47                 :                : namespace xlnt {
      48                 :                : 
      49                 :            954 : style::style(detail::style_impl *d)
      50                 :            954 :     : d_(d)
      51                 :                : {
      52                 :            954 : }
      53                 :                : 
      54                 :UBC           0 : bool style::hidden() const
      55                 :                : {
      56                 :              0 :     return d_->hidden_style;
      57                 :                : }
      58                 :                : 
      59                 :              0 : style style::hidden(bool value)
      60                 :                : {
      61                 :              0 :     d_->hidden_style = value;
      62                 :              0 :     return style(d_);
      63                 :                : }
      64                 :                : 
      65                 :              0 : std::size_t style::builtin_id() const
      66                 :                : {
      67                 :              0 :     return d_->builtin_id.get();
      68                 :                : }
      69                 :                : 
      70                 :              0 : bool style::builtin() const
      71                 :                : {
      72                 :              0 :     return d_->builtin_id.is_set();
      73                 :                : }
      74                 :                : 
      75                 :CBC          14 : std::string style::name() const
      76                 :                : {
      77                 :             14 :     return d_->name;
      78                 :                : }
      79                 :                : 
      80                 :UBC           0 : style style::name(const std::string &name)
      81                 :                : {
      82                 :              0 :     d_->name = name;
      83                 :              0 :     return *this;
      84                 :                : }
      85                 :                : 
      86                 :              0 : bool style::custom_builtin() const
      87                 :                : {
      88   [ #  #  #  # ]:              0 :     return d_->builtin_id.is_set() && d_->custom_builtin;
      89                 :                : }
      90                 :                : 
      91                 :CBC           4 : bool style::operator==(const style &other) const
      92                 :                : {
      93         [ +  + ]:              4 :     return name() == other.name();
      94                 :                : }
      95                 :                : 
      96                 :UBC           0 : bool style::operator!=(const style &other) const
      97                 :                : {
      98                 :              0 :     return !operator==(other);
      99                 :                : }
     100                 :                : 
     101                 :              0 : xlnt::alignment style::alignment() const
     102                 :                : {
     103                 :              0 :     return d_->parent->alignments.at(d_->alignment_id.get());
     104                 :                : }
     105                 :                : 
     106                 :              0 : style style::alignment(const xlnt::alignment &new_alignment, optional<bool> applied)
     107                 :                : {
     108            [ # ]:              0 :     d_->alignment_id = d_->parent->find_or_add(d_->parent->alignments, new_alignment);
     109                 :              0 :     d_->alignment_applied = applied;
     110                 :                : 
     111                 :              0 :     return *this;
     112                 :                : }
     113                 :                : 
     114                 :CBC           5 : xlnt::border style::border() const
     115                 :                : {
     116                 :              5 :     return d_->parent->borders.at(d_->border_id.get());
     117                 :                : }
     118                 :                : 
     119                 :            257 : style style::border(const xlnt::border &new_border, optional<bool> applied)
     120                 :                : {
     121            [ + ]:            257 :     d_->border_id = d_->parent->find_or_add(d_->parent->borders, new_border);
     122                 :            257 :     d_->border_applied = applied;
     123                 :                : 
     124                 :            257 :     return *this;
     125                 :                : }
     126                 :                : 
     127                 :              5 : xlnt::fill style::fill() const
     128                 :                : {
     129                 :              5 :     return d_->parent->fills.at(d_->fill_id.get());
     130                 :                : }
     131                 :                : 
     132                 :            257 : style style::fill(const xlnt::fill &new_fill, optional<bool> applied)
     133                 :                : {
     134            [ + ]:            257 :     d_->fill_id = d_->parent->find_or_add(d_->parent->fills, new_fill);
     135                 :            257 :     d_->fill_applied = applied;
     136                 :                : 
     137                 :            257 :     return *this;
     138                 :                : }
     139                 :                : 
     140                 :              4 : xlnt::font style::font() const
     141                 :                : {
     142                 :              4 :     return d_->parent->fonts.at(d_->font_id.get());
     143                 :                : }
     144                 :                : 
     145                 :            257 : style style::font(const xlnt::font &new_font, optional<bool> applied)
     146                 :                : {
     147            [ + ]:            257 :     d_->font_id = d_->parent->find_or_add(d_->parent->fonts, new_font);
     148                 :            257 :     d_->font_applied = applied;
     149                 :                : 
     150                 :            257 :     return *this;
     151                 :                : }
     152                 :                : 
     153                 :             11 : xlnt::number_format style::number_format() const
     154                 :                : {
     155                 :             11 :     auto match = find_number_format(d_->parent->number_formats,
     156         [ +  + ]:             11 :         d_->number_format_id.get());
     157                 :                : 
     158         [ -  + ]:             11 :     if (match == d_->parent->number_formats.end())
     159                 :                :     {
     160            [ # ]:UBC           0 :         throw invalid_attribute();
     161                 :                :     }
     162                 :                : 
     163            [ + ]:CBC          22 :     return *match;
     164                 :                : }
     165                 :                : 
     166                 :            263 : style style::number_format(const xlnt::number_format &new_number_format, optional<bool> applied)
     167                 :                : {
     168            [ + ]:            263 :     auto copy = new_number_format;
     169                 :                : 
     170      [ +  +  + ]:            263 :     if (!copy.has_id())
     171                 :                :     {
     172         [ +  + ]:              4 :         copy.id(d_->parent->next_custom_number_format_id());
     173            [ + ]:              4 :         d_->parent->number_formats.push_back(copy);
     174                 :                :     }
     175         [ +  + ]:            259 :     else if (find_number_format(d_->parent->number_formats, copy.id())
     176         [ +  + ]:            518 :         == d_->parent->number_formats.end())
     177                 :                :     {
     178            [ + ]:            258 :         d_->parent->number_formats.push_back(copy);
     179                 :                :     }
     180                 :                : 
     181            [ + ]:            263 :     d_->number_format_id = copy.id();
     182            [ + ]:            263 :     d_->number_format_applied = applied;
     183                 :                : 
     184                 :            263 :     return *this;
     185                 :            263 : }
     186                 :                : 
     187                 :UBC           0 : xlnt::protection style::protection() const
     188                 :                : {
     189                 :              0 :     return d_->parent->protections.at(d_->protection_id.get());
     190                 :                : }
     191                 :                : 
     192                 :              0 : style style::protection(const xlnt::protection &new_protection, optional<bool> applied)
     193                 :                : {
     194            [ # ]:              0 :     d_->protection_id = d_->parent->find_or_add(d_->parent->protections, new_protection);
     195                 :              0 :     d_->protection_applied = applied;
     196                 :                : 
     197                 :              0 :     return *this;
     198                 :                : }
     199                 :                : 
     200                 :              0 : bool style::alignment_applied() const
     201                 :                : {
     202                 :              0 :     return d_->alignment_applied.is_set()
     203         [ #  # ]:              0 :         ? d_->alignment_applied.get()
     204                 :              0 :         : d_->alignment_id.is_set();
     205                 :                : }
     206                 :                : 
     207                 :              0 : bool style::border_applied() const
     208                 :                : {
     209                 :              0 :     return d_->border_applied.is_set()
     210         [ #  # ]:              0 :         ? d_->border_applied.get()
     211                 :              0 :         : d_->border_id.is_set();
     212                 :                : }
     213                 :                : 
     214                 :              0 : bool style::fill_applied() const
     215                 :                : {
     216                 :              0 :     return d_->fill_applied.is_set()
     217         [ #  # ]:              0 :         ? d_->fill_applied.get()
     218                 :              0 :         : d_->fill_id.is_set();
     219                 :                : }
     220                 :                : 
     221                 :              0 : bool style::font_applied() const
     222                 :                : {
     223                 :              0 :     return d_->font_applied.is_set()
     224         [ #  # ]:              0 :         ? d_->font_applied.get()
     225                 :              0 :         : d_->font_id.is_set();
     226                 :                : }
     227                 :                : 
     228                 :CBC           2 : bool style::number_format_applied() const
     229                 :                : {
     230                 :              2 :     return d_->number_format_applied.is_set()
     231         [ +  - ]:              2 :         ? d_->number_format_applied.get()
     232                 :              2 :         : d_->number_format_id.is_set();
     233                 :                : }
     234                 :                : 
     235                 :UBC           0 : bool style::protection_applied() const
     236                 :                : {
     237                 :              0 :     return d_->protection_applied.is_set()
     238         [ #  # ]:              0 :         ? d_->protection_applied.get()
     239                 :              0 :         : d_->protection_id.is_set();
     240                 :                : }
     241                 :                : 
     242                 :CBC           2 : bool style::pivot_button() const
     243                 :                : {
     244                 :              2 :     return d_->pivot_button_;
     245                 :                : }
     246                 :                : 
     247                 :              1 : void style::pivot_button(bool show)
     248                 :                : {
     249                 :              1 :     d_->pivot_button_ = show;
     250                 :              1 : }
     251                 :                : 
     252                 :              2 : bool style::quote_prefix() const
     253                 :                : {
     254                 :              2 :     return d_->quote_prefix_;
     255                 :                : }
     256                 :                : 
     257                 :              1 : void style::quote_prefix(bool quote)
     258                 :                : {
     259                 :              1 :     d_->quote_prefix_ = quote;
     260                 :              1 : }
     261                 :                : 
     262                 :                : } // namespace xlnt
        

Generated by: LCOV version 2.3.1-beta