LCOV - code coverage report
Current view: top level - core/font - SPFontFace.h (source / functions) Hit Total Coverage
Test: coverage.info Lines: 14 15 93.3 %
Date: 2024-05-12 00:16:13 Functions: 16 17 94.1 %

          Line data    Source code
       1             : /**
       2             :  Copyright (c) 2023-2024 Stappler LLC <admin@stappler.dev>
       3             : 
       4             :  Permission is hereby granted, free of charge, to any person obtaining a copy
       5             :  of this software and associated documentation files (the "Software"), to deal
       6             :  in the Software without restriction, including without limitation the rights
       7             :  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
       8             :  copies of the Software, and to permit persons to whom the Software is
       9             :  furnished to do so, subject to the following conditions:
      10             : 
      11             :  The above copyright notice and this permission notice shall be included in
      12             :  all copies or substantial portions of the Software.
      13             : 
      14             :  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
      15             :  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      16             :  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
      17             :  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      18             :  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
      19             :  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
      20             :  THE SOFTWARE.
      21             :  **/
      22             : 
      23             : #ifndef CORE_FONT_XLFONTFACE_H_
      24             : #define CORE_FONT_XLFONTFACE_H_
      25             : 
      26             : #include "SPFontTextLayout.h"
      27             : #include "SPRef.h"
      28             : #include <shared_mutex>
      29             : 
      30             : typedef struct FT_LibraryRec_ * FT_Library;
      31             : typedef struct FT_FaceRec_ * FT_Face;
      32             : 
      33             : namespace STAPPLER_VERSIONIZED stappler::font {
      34             : 
      35             : class FontLibrary;
      36             : 
      37             : class FontFaceData : public RefBase<memory::StandartInterface>, public InterfaceObject<memory::StandartInterface> {
      38             : public:
      39         400 :         virtual ~FontFaceData() { }
      40             : 
      41             :         bool init(StringView, BytesView, bool);
      42             :         bool init(StringView, Bytes &&);
      43             :         bool init(StringView, Function<Bytes()> &&);
      44             : 
      45             :         FontLayoutParameters acquireDefaultParams(FT_Face);
      46             : 
      47             :         void inspectVariableFont(FontLayoutParameters params, FT_Library lib, FT_Face);
      48             : 
      49        2445 :         StringView getName() const { return _name; }
      50             :         BytesView getView() const;
      51             : 
      52        6716 :         const FontVariations &getVariations() const { return _variations; }
      53             : 
      54             :         FontSpecializationVector getSpecialization(const FontSpecializationVector &) const;
      55             : 
      56             : protected:
      57             :         bool _persistent = false;
      58             :         String _name;
      59             :         BytesView _view;
      60             :         Bytes _data;
      61             :         FontVariations _variations;
      62             :         FontLayoutParameters _params;
      63             : };
      64             : 
      65             : class FontFaceObject : public RefBase<memory::StandartInterface>, public InterfaceObject<memory::StandartInterface> {
      66             : public:
      67             :         virtual ~FontFaceObject();
      68             : 
      69             :         bool init(StringView, const Rc<FontFaceData> &, FT_Library, FT_Face, const FontSpecializationVector &, uint16_t);
      70             : 
      71        6716 :         StringView getName() const { return _name; }
      72     1841550 :         uint16_t getId() const { return _id; }
      73        6437 :         FT_Face getFace() const { return _face; }
      74        8942 :         const Rc<FontFaceData> &getData() const { return _data; }
      75        4471 :         const FontSpecializationVector &getSpec() const { return _spec; }
      76             : 
      77             :         bool acquireTexture(char32_t, const Callback<void(const CharTexture &)> &);
      78             :         bool acquireTextureUnsafe(char32_t, const Callback<void(const CharTexture &)> &);
      79             : 
      80             :         // returns true if updated
      81             :         bool addChars(const Vector<char32_t> &chars, bool expand, Vector<char32_t> *failed);
      82             :         bool addCharGroup(CharGroupId, Interface::VectorType<char32_t> *failed);
      83             : 
      84             :         bool addRequiredChar(char32_t);
      85             : 
      86             :         Interface::VectorType<char32_t> getRequiredChars() const;
      87             : 
      88             :         CharShape getChar(char16_t c) const;
      89             :         int16_t getKerningAmount(char16_t first, char16_t second) const;
      90             : 
      91        1374 :         Metrics getMetrics() const { return _metrics; }
      92             : 
      93             : protected:
      94             :         bool addChar(char16_t, bool &updated);
      95             : 
      96             :         Interface::StringType _name;
      97             :         Rc<FontFaceData> _data;
      98             :         uint16_t _id = 0;
      99             :         FT_Face _face = nullptr;
     100             :         FontSpecializationVector _spec;
     101             :         Metrics _metrics;
     102             :         Interface::VectorType<char32_t> _required;
     103             :         FontCharStorage<CharShape> _chars;
     104             :         mem_std::HashMap<uint32_t, int16_t> _kerning;
     105             :         mem_std::Mutex _faceMutex;
     106             :         mutable std::shared_mutex _charsMutex;
     107             :         mutable mem_std::Mutex _requiredMutex;
     108             : };
     109             : 
     110             : class FontFaceSet : public RefBase<memory::StandartInterface>, public InterfaceObject<memory::StandartInterface> {
     111             : public:
     112             :         static String constructName(StringView, const FontSpecializationVector &);
     113             : 
     114        1340 :         virtual ~FontFaceSet() { }
     115         670 :         FontFaceSet() { }
     116             : 
     117             :         bool init(String &&, StringView family, FontSpecializationVector &&, Rc<FontFaceData> &&data, FontLibrary *);
     118             :         bool init(String &&, StringView family, FontSpecializationVector &&, Vector<Rc<FontFaceData>> &&data, FontLibrary *);
     119             : 
     120             :         void touch(uint64_t clock, bool persistent);
     121             : 
     122             :         uint64_t getAccessTime() const { return _accessTime; }
     123       16112 :         bool isPersistent() const { return _persistent; }
     124             : 
     125         670 :         StringView getName() const { return _name; }
     126             :         StringView getFamily() const { return _family; }
     127             : 
     128           0 :         const FontSpecializationVector &getSpec() const { return _spec; }
     129             : 
     130             :         size_t getFaceCount() const;
     131             : 
     132             :         Rc<FontFaceData> getSource(size_t) const;
     133             :         FontLibrary *getLibrary() const { return _library; }
     134             : 
     135             :         bool addString(const CharVector &);
     136             :         bool addString(const CharVector &, Vector<char32_t> &failed);
     137             : 
     138             :         uint16_t getFontHeight() const;
     139             :         int16_t getKerningAmount(char16_t first, char16_t second, uint16_t face) const;
     140             :         Metrics getMetrics() const;
     141             :         CharShape getChar(char16_t, uint16_t &face) const;
     142             : 
     143         563 :         size_t getTexturesCount() const { return _texturesCount; }
     144             : 
     145             :         bool addTextureChars(SpanView<CharLayoutData>) const;
     146             : 
     147             :         const Vector<Rc<FontFaceObject>> &getFaces() const;
     148             : 
     149             : protected:
     150             :         std::atomic<uint64_t> _accessTime;
     151             :         std::atomic<bool> _persistent = false;
     152             : 
     153             :         String _name;
     154             :         String _family;
     155             :         Metrics _metrics;
     156             :         FontSpecializationVector _spec;
     157             :         Vector<Rc<FontFaceData>> _sources;
     158             :         Vector<Rc<FontFaceObject>> _faces;
     159             :         FontLibrary *_library = nullptr;
     160             : 
     161             :         mutable size_t _texturesCount = 0;
     162             :         mutable std::shared_mutex _mutex;
     163             : };
     164             : 
     165             : }
     166             : 
     167             : #endif /* CORE_FONT_XLFONTFACE_H_ */

Generated by: LCOV version 1.14