LCOV - code coverage report
Current view: top level - muse/framework/draw/internal - fontfacext.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 3 3
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) 2026 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              : #pragma once
      23              : 
      24              : #include <map>
      25              : #include <memory>
      26              : #include <string>
      27              : #include <unordered_map>
      28              : #include <vector>
      29              : 
      30              : #include "global/io/iodevice.h"
      31              : #include "global/io/buffer.h"
      32              : 
      33              : #include "ifontface.h"
      34              : 
      35              : namespace muse {
      36              : class ZipReader;
      37              : }
      38              : 
      39              : namespace muse::draw {
      40              : class AtlasTexture
      41              : {
      42              : public:
      43            6 :     AtlasTexture() = default;
      44              :     AtlasTexture(AtlasTexture&& o) = default;
      45              : 
      46              :     bool loadAtlas(const muse::ByteArray& atlas);
      47              :     void loadAtlasMetaInfo(const muse::ByteArray& atlas);
      48              :     Sdf getGlyphImage(glyph_idx_t idx);
      49              : 
      50              : private:
      51              :     struct GlyphInfo {
      52              :         glyph_idx_t gidx;
      53              :         muse::Rect rect;
      54              :         bool rotated = false;
      55              :     };
      56              : 
      57              :     std::map<glyph_idx_t, GlyphInfo> m_glyphInfos;
      58              :     std::vector<uint8_t> m_atlas;
      59              :     uint32_t m_atlasWidth = 0;
      60              :     uint32_t m_atlasHeight = 0;
      61              : };
      62              : 
      63              : class FontFaceXT : public IFontFace
      64              : {
      65              : public:
      66              :     static bool isFtx(const ByteArray& data);
      67              : 
      68              :     FontFaceXT();
      69              :     ~FontFaceXT();
      70              : 
      71              :     struct GlyphData {
      72           89 :         GlyphData() = default;
      73           89 :         GlyphData(GlyphData&& o) = default;
      74              :         FBBox textBbox;
      75              :         f26dot6_t textAdvance = 0;
      76              :         FBBox symBbox;
      77              :         f26dot6_t symAdvance = 0;
      78              :         GlyphImage glyphImage;
      79              : 
      80              :         void write(muse::io::IODevice* d) const;
      81              :         void read(muse::io::IODevice* d);
      82              :     };
      83              : 
      84              :     bool load(const FaceKey& key, const FontData& fontData, bool isSymbolMode) override;
      85              : 
      86              :     const FaceKey& key() const override;
      87              :     bool isSymbolMode() const override;
      88              : 
      89              :     f26dot6_t leading() const override;
      90              :     f26dot6_t ascent() const override;
      91              :     f26dot6_t descent() const override;
      92              :     f26dot6_t xHeight() const override;
      93              :     f26dot6_t capHeight() const override;
      94              : 
      95              :     f26dot6_t underlinePos() const override;
      96              :     f26dot6_t lineWidth() const override;
      97              : 
      98              :     std::vector<ShapedGlyph> glyphs(const char32_t* text, int text_length) const override;
      99              :     glyph_idx_t glyphIndex(char32_t ucs4) const override;
     100              :     glyph_idx_t glyphIndex(const std::string& glyphName) const override;
     101              :     char32_t findCharCode(glyph_idx_t idx) const override;
     102              : 
     103              :     FBBox glyphBbox(glyph_idx_t idx) const override;
     104              :     f26dot6_t glyphAdvance(glyph_idx_t idx) const override;
     105              :     const GlyphImage& glyphImage(glyph_idx_t idx) const override;
     106              : 
     107              :     using Ligature = std::pair<glyph_idx_t, std::vector<glyph_idx_t> >;
     108              :     using Ligatures = std::vector<Ligature>;
     109              : 
     110              :     using Kernings = std::map<std::pair<glyph_idx_t, glyph_idx_t>, f26dot6_t>;
     111              : 
     112              :     static void applyLigatures(std::vector<ShapedGlyph>& glyphs, const Ligatures& ls);
     113              : 
     114              : private:
     115              : 
     116              :     const GlyphData& glyphData(glyph_idx_t idx) const;
     117              :     f26dot6_t glyphAdvance(glyph_idx_t idx, glyph_idx_t nextIdx) const;
     118              : 
     119              :     FaceKey m_key;
     120              :     bool m_isSymbolMode = false;
     121              : 
     122              :     std::unique_ptr<muse::io::Buffer> m_fileBuffer;
     123              :     std::unique_ptr<muse::ZipReader> m_zip;
     124              :     f26dot6_t m_leading = -1;
     125              :     f26dot6_t m_ascent = -1;
     126              :     f26dot6_t m_descent = -1;
     127              :     f26dot6_t m_xHeight = -1;
     128              :     f26dot6_t m_capHeight = -1;
     129              :     f26dot6_t m_underlinePos = -1;
     130              :     f26dot6_t m_lineWidth = -1;
     131              : 
     132              :     Ligatures m_ligatures;
     133              :     Kernings m_kernings;
     134              : 
     135              :     mutable std::unordered_map<std::string, glyph_idx_t> m_nonUnicodeGlyphs;
     136              :     mutable std::unordered_map<char32_t, glyph_idx_t> m_unicodeGlyphs;
     137              :     mutable std::unordered_map<glyph_idx_t, GlyphData> m_cache;
     138              :     mutable AtlasTexture m_atlastexture;
     139              : };
     140              : }
        

Generated by: LCOV version 2.0-1