LCOV - code coverage report
Current view: top level - src/engraving/dom - text.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 70.5 % 44 31
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : 
      23              : #include "text.h"
      24              : 
      25              : #include "rw/rwregister.h"
      26              : #include "score.h"
      27              : 
      28              : #include "log.h"
      29              : 
      30              : using namespace mu;
      31              : using namespace mu::engraving;
      32              : 
      33              : namespace mu::engraving {
      34              : //---------------------------------------------------------
      35              : //   defaultStyle
      36              : //---------------------------------------------------------
      37              : 
      38              : static const ElementStyle defaultStyle {
      39              :     { Sid::defaultSystemFlag, Pid::SYSTEM_FLAG },
      40              : };
      41              : 
      42        15383 : static bool styleIsSelectable(TextStyleType style)
      43              : {
      44        15383 :     switch (style) {
      45        10586 :     case TextStyleType::HEADER:
      46              :     case TextStyleType::FOOTER:
      47              :     case TextStyleType::COPYRIGHT:
      48              :     case TextStyleType::PAGE_NUMBER:
      49              :     case TextStyleType::GROUP_BRACKET:
      50        10586 :         return false;
      51         4797 :     default: break;
      52              :     }
      53         4797 :     return true;
      54              : }
      55              : 
      56              : //---------------------------------------------------------
      57              : //   Text
      58              : //---------------------------------------------------------
      59              : 
      60        15383 : Text::Text(DummyParentOr<EngravingItem> parent, TextStyleType tid)
      61        15383 :     : TextBase(ElementType::TEXT, parent, tid, styleIsSelectable(tid) ? ElementFlag::NOTHING : ElementFlag::NOT_SELECTABLE)
      62              : {
      63        15383 :     initElementStyle(&defaultStyle);
      64        15383 : }
      65              : 
      66        95280 : EngravingObject* Text::propertyDelegate(Pid id) const
      67              : {
      68        95280 :     if (id == Pid::TEXT_STYLE && parent() && parent()->isTextLineBaseSegment()) {
      69            0 :         return parent();
      70              :     }
      71              : 
      72        95280 :     return nullptr;
      73              : }
      74              : 
      75              : //---------------------------------------------------------
      76              : //   propertyDefault
      77              : //---------------------------------------------------------
      78              : 
      79        34487 : engraving::PropertyValue Text::propertyDefault(Pid id) const
      80              : {
      81        34487 :     if (EngravingObject* item = propertyDelegate(id)) {
      82            0 :         return item->propertyDefault(id);
      83              :     }
      84              : 
      85        34487 :     switch (id) {
      86         1606 :     case Pid::TEXT_STYLE:
      87         1606 :         return TextStyleType::DEFAULT;
      88        32881 :     default:
      89        32881 :         return TextBase::propertyDefault(id);
      90              :     }
      91              : }
      92              : 
      93        12384 : PropertyValue Text::getProperty(Pid id) const
      94              : {
      95        12384 :     switch (id) {
      96            0 :     case Pid::VOICE_ASSIGNMENT:
      97            0 :         if (hasVoiceAssignmentProperties()) {
      98            0 :             return ownershipParent()->getProperty(id);
      99              :         }
     100              :     // fallthrough
     101              :     default:
     102        12384 :         return TextBase::getProperty(id);
     103              :     }
     104              : }
     105              : 
     106            0 : String Text::readXmlText(XmlReader& xml, Score* score)
     107              : {
     108            0 :     Text t(score->dummy());
     109            0 :     rw::RWRegister::reader()->readItem(&t, xml);
     110            0 :     return t.xmlText();
     111            0 : }
     112              : 
     113         2037 : bool Text::hasVoiceAssignmentProperties() const
     114              : {
     115         2037 :     const EngravingItem* parent = ownershipParentItem();
     116         2037 :     if (parent && parent->isTextLineBaseSegment()) {
     117            0 :         return parent->hasVoiceAssignmentProperties();
     118              :     }
     119         2037 :     return false;
     120              : }
     121              : 
     122            0 : bool mu::engraving::Text::collectForDrawing() const
     123              : {
     124            0 :     return !(parent() && parent()->isTuplet());
     125              : }
     126              : 
     127         4368 : bool Text::positionRelativeToNoteheadRest() const
     128              : {
     129         4368 :     if (parent()->isBox() || parent()->isTuplet() || parent()->isSpannerSegment() || parent()->isBracket()) {
     130         4297 :         return false;
     131              :     }
     132              : 
     133           71 :     return true;
     134              : }
     135              : }
        

Generated by: LCOV version 2.0-1