Subversion Repositories tpanel

Rev

Rev 462 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
446 andreas 1
/*
463 andreas 2
 * Copyright (C) 2020 to 2024 by Andreas Theofilu <andreas@theosys.at>
446 andreas 3
 *
4
 * This program is free software; you can redistribute it and/or modify
5
 * it under the terms of the GNU General Public License as published by
6
 * the Free Software Foundation; either version 3 of the License, or
7
 * (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software Foundation,
16
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
17
 */
18
 
19
#ifndef __TFONT_H__
20
#define __TFONT_H__
21
 
22
#include <string>
23
#include <map>
24
 
25
#include "tvalidatefile.h"
26
 
27
#include <include/core/SkTypeface.h>
28
#include <include/core/SkFontStyle.h>
29
 
30
typedef struct FONT_T
31
{
462 andreas 32
    int number{0};
446 andreas 33
    std::string file;
462 andreas 34
    int fileSize{0};
35
    int faceIndex{0};
446 andreas 36
    std::string name;
37
    std::string subfamilyName;
38
    std::string fullName;
462 andreas 39
    int size{0};
40
    int usageCount{0};
446 andreas 41
}FONT_T;
42
 
43
typedef enum FONT_STYLE
44
{
45
    FONT_NONE,
46
    FONT_NORMAL,
47
    FONT_ITALIC,
48
    FONT_BOLD,
49
    FONT_BOLD_ITALIC
50
}FONT_STYLE;
51
 
52
typedef enum FONT_TYPE
53
{
54
    FT_UNKNOWN,     // Unknown font type
55
    FT_NORMAL,      // Normal font with mostly letters
56
    FT_SYMBOL,      // Normal font with mostly symbols
57
    FT_SYM_MS       // Proprietary Microsoft symbol font
58
}FONT_TYPE;
59
 
60
class TFont : public TValidateFile
61
{
62
    public:
462 andreas 63
        TFont(const std::string& fname, bool tp=false);
446 andreas 64
        ~TFont();
65
 
66
        void initialize();
67
        bool systemFonts(bool setup=false);
68
        FONT_T getFont(int number);
69
        int getFontIDfromFile(const std::string& file);
70
        int getFontIDfromName(const std::string& name);
71
        FONT_STYLE getStyle(int number);
72
        FONT_STYLE getStyle(FONT_T& font);
73
        SkFontStyle getSkiaStyle(int number);
74
        sk_sp<SkTypeface> getTypeFace(int number);
462 andreas 75
        sk_sp<SkTypeface> getTypeFace(const std::string& ff);
76
        void setTP5(bool tp) { mIsTP5 = tp; }
446 andreas 77
 
78
        static std::vector<std::string> getFontPathList();
79
        static SkGlyphID *textToGlyphs(const std::string& str, sk_sp<SkTypeface>& typeFace, size_t *size);
80
        static FONT_TYPE isSymbol(sk_sp<SkTypeface>& typeFace);
81
        static size_t utf8ToUtf16(const std::string& str, uint16_t **uni, bool toSymbol = false);
82
        static double pixelToPoint(int dpi, int pixel);
83
 
84
    private:
85
        static void parseCmap(const unsigned char *cmaps);
86
        static uint16_t getGlyphIndex(SkUnichar);
87
        static void _freeCmap();
88
 
89
        std::map<int, FONT_T> mFonts;
462 andreas 90
        bool mIsTP5{false};
91
        std::string mFontFile;
446 andreas 92
};
93
 
94
#endif