MCPcopy Create free account
hub / github.com/SFML/SFML / openFromFile

Method openFromFile

src/SFML/Graphics/Font.cpp:159–192  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

157
158////////////////////////////////////////////////////////////
159bool Font::openFromFile(const std::filesystem::path& filename)
160{
161 using namespace std::string_view_literals;
162
163 // Cleanup the previous resources
164 cleanup();
165
166 // Create the input stream and open the file
167#ifndef SFML_SYSTEM_ANDROID
168 const auto stream = std::make_shared<FileInputStream>();
169 const auto type = "file"sv;
170#else
171 const auto stream = std::make_shared<priv::ResourceStream>();
172 const auto type = "Android resource stream"sv;
173#endif
174
175 if (!stream->open(filename))
176 {
177 err() << "Failed to load font (failed to open file): " << std::strerror(errno) << '\n'
178 << formatDebugPathInfo(filename) << std::endl;
179 return false;
180 }
181
182 // Open the font, and if succesful save the stream to keep it alive
183 if (openFromStreamImpl(*stream, type))
184 {
185 m_stream = stream;
186 return true;
187 }
188
189 // If loading failed, print filename (after the error message already printed in openFromStreamImpl)
190 err() << formatDebugPathInfo(filename) << std::endl;
191 return false;
192}
193
194
195////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

cleanupFunction · 0.85
formatDebugPathInfoFunction · 0.85
openMethod · 0.45

Tested by

no test coverage detected