MCPcopy Create free account
hub / github.com/beefytech/Beef / Load

Method Load

BeefySysLib/gfx/FTFont.cpp:132–211  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}*/
131
132bool FTFont::Load(const StringImpl& fileName, float pointSize)
133{
134 if (gFTLibrary == NULL)
135 FT_Init_FreeType(&gFTLibrary);
136
137 FTFontManager::Face* face = NULL;
138
139 String key = fileName;
140 void* memPtr = NULL;
141 int memLen = 0;
142 bool isMemory = ParseMemorySpan(fileName, memPtr, memLen, &key);
143
144 FTFontManager::Face** facePtr = NULL;
145 if (gFTFontManager.mFaces.TryAdd(key, NULL, &facePtr))
146 {
147 face = new FTFontManager::Face();
148 *facePtr = face;
149
150 face->mFileName = key;
151 FT_Face ftFace = NULL;
152
153 String useFileName = fileName;
154 int faceIdx = 0;
155 int atPos = (int)useFileName.IndexOf('@', 1);
156 if (atPos != -1)
157 {
158 faceIdx = atoi(useFileName.c_str() + atPos + 1);
159 useFileName.RemoveToEnd(atPos);
160 }
161
162 if (isMemory)
163 {
164 FT_New_Memory_Face(gFTLibrary, (FT_Byte*)memPtr, memLen, faceIdx, &ftFace);
165 }
166 else
167 {
168 FT_New_Face(gFTLibrary, useFileName.c_str(), faceIdx, &ftFace);
169 }
170
171 face->mFTFace = ftFace;
172 }
173 else
174 {
175 face = *facePtr;
176 }
177 if (face->mFTFace == NULL)
178 return false;
179
180 mFace = face;
181
182 FTFontManager::FaceSize** faceSizePtr = NULL;
183 if (face->mFaceSizes.TryAdd(pointSize, NULL, &faceSizePtr))
184 {
185 //OutputDebugStrF("Created face %s %f\n", fileName.c_str(), pointSize);
186
187 mFaceSize = new FTFontManager::FaceSize();
188 *faceSizePtr = mFaceSize;
189

Callers 1

BF_CALLTYPE FTFont_LoadFunction · 0.45

Calls 4

TryAddMethod · 0.45
IndexOfMethod · 0.45
c_strMethod · 0.45
RemoveToEndMethod · 0.45

Tested by

no test coverage detected