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 : #pragma once
23 :
24 : #include "global/types/bytearray.h"
25 : #include "types/fontstypes.h"
26 :
27 : namespace muse::draw {
28 : using f26dot6_t = long; // A signed 26.6 fixed-point type used for vectorial pixel coordinates.
29 :
30 216 : inline long to_f26d6(float v) { return static_cast<long>(v * 64); }
31 1889 : inline double from_f26d6(f26dot6_t v) { return static_cast<double>(v) / 64.0; }
32 :
33 : using FBBox = RectX<f26dot6_t>;
34 :
35 : struct ShapedGlyph {
36 : glyph_idx_t idx = 0;
37 : f26dot6_t x_advance = 0.;
38 : uint32_t cluster = 0;
39 : };
40 :
41 : class IFontFace
42 : {
43 : public:
44 :
45 220 : virtual ~IFontFace() = default;
46 :
47 : virtual bool load(const FaceKey& key, const FontData& fontData, bool isSymbolMode) = 0;
48 :
49 : virtual const FaceKey& key() const = 0;
50 : virtual bool isSymbolMode() const = 0;
51 :
52 : virtual f26dot6_t leading() const = 0;
53 : virtual f26dot6_t ascent() const = 0;
54 : virtual f26dot6_t descent() const = 0;
55 : virtual f26dot6_t xHeight() const = 0;
56 : virtual f26dot6_t capHeight() const = 0;
57 :
58 : virtual f26dot6_t underlinePos() const = 0;
59 : virtual f26dot6_t lineWidth() const = 0;
60 :
61 : virtual std::vector<ShapedGlyph> glyphs(const char32_t* text, int text_length) const = 0;
62 : virtual glyph_idx_t glyphIndex(char32_t ucs4) const = 0;
63 : virtual glyph_idx_t glyphIndex(const std::string& glyphName) const = 0;
64 : virtual char32_t findCharCode(glyph_idx_t idx) const = 0; // for tests
65 :
66 : virtual FBBox glyphBbox(glyph_idx_t idx) const = 0;
67 : virtual f26dot6_t glyphAdvance(glyph_idx_t idx) const = 0;
68 :
69 : virtual const GlyphImage& glyphImage(glyph_idx_t idx) const = 0;
70 : };
71 : }
|