LCOV - code coverage report
Current view: top level - muse/framework/draw/internal - fontfacedu.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 80.6 % 62 50
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2024 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              : #include "fontfacedu.h"
      23              : 
      24              : using namespace muse::draw;
      25              : 
      26              : struct DummyGlyph {
      27              :     FBBox textBbox;
      28              :     f26dot6_t textAdvance = 0;
      29              :     FBBox symBbox;
      30              :     f26dot6_t symAdvance = 0;
      31              : };
      32              : 
      33            2 : static const DummyGlyph& dummyGlyph()
      34              : {
      35              :     static DummyGlyph g;
      36            2 :     if (g.textAdvance == 0) {
      37            1 :         g.textBbox = FBBox(0, -8064, 4160, 9728);
      38            1 :         g.textAdvance = 4160;
      39            1 :         g.symBbox = FBBox(0, -4011, 2079, 4817);
      40            1 :         g.symAdvance = 2080;
      41              :     }
      42              : 
      43            2 :     return g;
      44              : }
      45              : 
      46          104 : FontFaceDU::FontFaceDU(IFontFace* origin)
      47          104 :     : m_origin(origin)
      48              : {
      49          104 : }
      50              : 
      51          208 : FontFaceDU::~FontFaceDU()
      52              : {
      53          104 :     delete m_origin;
      54          208 : }
      55              : 
      56          104 : bool FontFaceDU::load(const FaceKey& key, const FontData& fontData, bool isSymbolMode)
      57              : {
      58          104 :     return m_origin->load(key, fontData, isSymbolMode);
      59              : }
      60              : 
      61         1512 : const FaceKey& FontFaceDU::key() const
      62              : {
      63         1512 :     return m_origin->key();
      64              : }
      65              : 
      66          682 : bool FontFaceDU::isSymbolMode() const
      67              : {
      68          682 :     return m_origin->isSymbolMode();
      69              : }
      70              : 
      71            6 : f26dot6_t FontFaceDU::leading() const
      72              : {
      73            6 :     return m_origin->leading();
      74              : }
      75              : 
      76          120 : f26dot6_t FontFaceDU::ascent() const
      77              : {
      78          120 :     return m_origin->ascent();
      79              : }
      80              : 
      81           66 : f26dot6_t FontFaceDU::descent() const
      82              : {
      83           66 :     return m_origin->descent();
      84              : }
      85              : 
      86            6 : f26dot6_t FontFaceDU::xHeight() const
      87              : {
      88            6 :     return m_origin->xHeight();
      89              : }
      90              : 
      91            0 : f26dot6_t FontFaceDU::capHeight() const
      92              : {
      93            0 :     return m_origin->capHeight();
      94              : }
      95              : 
      96            6 : f26dot6_t FontFaceDU::underlinePos() const
      97              : {
      98            6 :     return m_origin->underlinePos();
      99              : }
     100              : 
     101            6 : f26dot6_t FontFaceDU::lineWidth() const
     102              : {
     103            6 :     return m_origin->lineWidth();
     104              : }
     105              : 
     106          289 : std::vector<ShapedGlyph> FontFaceDU::glyphs(const char32_t* text, int text_length) const
     107              : {
     108          289 :     std::vector<ShapedGlyph> glyphs = m_origin->glyphs(text, text_length);
     109          289 :     std::vector<ShapedGlyph> ret;
     110          289 :     ret.reserve(glyphs.size());
     111         1430 :     for (ShapedGlyph& gp : glyphs) {
     112         1141 :         if (gp.idx == 0) {
     113            2 :             gp.x_advance = glyphAdvance(0); // dummy
     114              :         }
     115         1141 :         ret.push_back(gp);
     116              :     }
     117          289 :     return ret;
     118          289 : }
     119              : 
     120         1626 : glyph_idx_t FontFaceDU::glyphIndex(char32_t ucs4) const
     121              : {
     122         1626 :     return m_origin->glyphIndex(ucs4);
     123              : }
     124              : 
     125            0 : glyph_idx_t FontFaceDU::glyphIndex(const std::string& glyphName) const
     126              : {
     127            0 :     return m_origin->glyphIndex(glyphName);
     128              : }
     129              : 
     130            0 : char32_t FontFaceDU::findCharCode(glyph_idx_t idx) const
     131              : {
     132            0 :     return m_origin->findCharCode(idx);
     133              : }
     134              : 
     135          878 : FBBox FontFaceDU::glyphBbox(glyph_idx_t idx) const
     136              : {
     137          878 :     if (idx == 0) {
     138            0 :         return m_origin->isSymbolMode() ? dummyGlyph().symBbox : dummyGlyph().textBbox;
     139              :     }
     140          878 :     return m_origin->glyphBbox(idx);
     141              : }
     142              : 
     143          668 : f26dot6_t FontFaceDU::glyphAdvance(glyph_idx_t idx) const
     144              : {
     145          668 :     if (idx == 0) {
     146            2 :         return m_origin->isSymbolMode() ? dummyGlyph().symAdvance : dummyGlyph().textAdvance;
     147              :     }
     148          666 :     return m_origin->glyphAdvance(idx);
     149              : }
     150              : 
     151            0 : const GlyphImage& FontFaceDU::glyphImage(glyph_idx_t idx) const
     152              : {
     153            0 :     if (idx == 0) {
     154            0 :         static const GlyphImage emptyImage;
     155            0 :         return emptyImage;
     156              :     }
     157              : 
     158            0 :     return m_origin->glyphImage(idx);
     159              : }
        

Generated by: LCOV version 2.0-1