Skylicht Engine
Loading...
Searching...
No Matches
CGlyphFreetype.h
1/*
2!@
3MIT License
4
5Copyright (c) 2019 Skylicht Technology CO., LTD
6
7Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files
8(the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify,
9merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
10subject to the following conditions:
11
12The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
15INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19
20This file is part of the "Skylicht Engine".
21https://github.com/skylicht-lab/skylicht-engine
22!#
23*/
24
25#pragma once
26
27#ifdef FT2_BUILD_LIBRARY
28#include <ft2build.h>
29#include FT_GLYPH_H
30#endif
31
32#include "Utils/CSingleton.h"
33#include "Graphics2D/Atlas/CAtlas.h"
34#include "Graphics2D/SpriteFrame/CSpriteAtlas.h"
35
36namespace Skylicht
37{
39 {
40 CAtlas* m_atlas;
41 float m_advance;
42 float m_uvX;
43 float m_uvY;
44 float m_uvW;
45 float m_uvH;
46 float m_offsetX;
47 float m_offsetY;
48 };
49
51 {
52#ifdef FT2_BUILD_LIBRARY
53 FT_Face m_face;
54 FT_Byte* m_data;
55#endif
56
57 std::map<u32, SGlyphEntity*> m_ge;
58
59#ifdef FT2_BUILD_LIBRARY
60 SFaceEntity(FT_Face face, FT_Byte* data) :
61 m_face(face),
62 m_data(data)
63 {
64 }
65
67 {
68 FT_Done_Face(m_face);
69
70 cleanGlyphEntity();
71 }
72#endif
73
74 void cleanGlyphEntity()
75 {
76 for (std::map<u32, SGlyphEntity*>::iterator it = m_ge.begin(), end = m_ge.end(); it != end; ++it)
77 delete it->second;
78 m_ge.clear();
79 }
80 };
81
82 class SKYLICHT_API CGlyphFreetype
83 {
84 public:
85 DECLARE_SINGLETON(CGlyphFreetype)
86
87 protected:
88
89#ifdef FT2_BUILD_LIBRARY
90 FT_Library m_lib;
91#endif
92 std::map<std::string, SFaceEntity*> m_faceEntity;
93
94 u32 m_width;
95 u32 m_height;
96
97 std::vector<CAtlas*> m_atlas;
98
99 public:
100 CGlyphFreetype();
101
102 virtual ~CGlyphFreetype();
103
104 bool initFont(const char* name, const char* path);
105
106 void clearAtlas();
107
108 static int sizePtToPx(float pt);
109
110 static float sizePxToPt(int px);
111
112 CAtlas* getCharImage(unsigned short code,
113 const char* name,
114 int fontSize,
115 float* advance,
116 float* uvX,
117 float* uvY,
118 float* uvW,
119 float* uvH,
120 float* offsetX, float* offsetY);
121
122 CAtlas* getCharImage(
123 CSpriteAtlas* external,
124 unsigned short code,
125 const char* name,
126 int fontSize,
127 float* advance,
128 float* uvX,
129 float* uvY,
130 float* uvW,
131 float* uvH,
132 float* offsetX, float* offsetY);
133
134 protected:
135 CAtlas* addEmptyAtlas(ECOLOR_FORMAT color, int w, int h);
136
137#ifdef FT2_BUILD_LIBRARY
138 int putGlyphToTexture(const FT_GlyphSlot& glyph, float* uvx, float* uvy, float* uvW, float* uvH);
139
140 CAtlas* putGlyphToTexture(CSpriteAtlas* external, const FT_GlyphSlot& glyph, float* uvx, float* uvy, float* uvW, float* uvH);
141#endif
142 };
143}
Definition CAtlas.h:30
The object class holds data on an image, including the locations of sprites and frames on it.
Definition CSpriteAtlas.h:41
#define DECLARE_SINGLETON(className)
Declare the standard singleton accessors for a class.
Definition CSingleton.h:36
Everything in the Skylicht Engine. You can start by looking at the topics.
Definition AudioDebugLog.h:29
Definition CGlyphFreetype.h:51
Definition CGlyphFreetype.h:39