mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-07 21:23:32 +00:00
example: load font from memory in Text.cpp
This commit is contained in:
parent
d8a720fb7e
commit
50d1d2fd36
1 changed files with 14 additions and 3 deletions
|
@ -21,6 +21,7 @@
|
|||
*/
|
||||
|
||||
#include "Common.h"
|
||||
#include <fstream>
|
||||
|
||||
/************************************************************************/
|
||||
/* Drawing Commands */
|
||||
|
@ -50,10 +51,20 @@ void tvgDrawCmds(tvg::Canvas* canvas)
|
|||
return;
|
||||
}
|
||||
|
||||
if (tvg::Text::load(EXAMPLE_DIR"/font/SentyCloud.ttf") != tvg::Result::Success) {
|
||||
cout << "TTF is not supported. Did you enable TTF Loader?" << endl;
|
||||
return;
|
||||
//Load from memory
|
||||
ifstream file(EXAMPLE_DIR"/font/SentyCloud.ttf", ios::binary);
|
||||
if (!file.is_open()) return;
|
||||
file.seekg(0, std::ios::end);
|
||||
auto size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
auto data = (char*)malloc(size);
|
||||
if (!data) return;
|
||||
file.read(data, size);
|
||||
file.close();
|
||||
if (tvg::Text::load("SentyCloud", data, size, "ttf", true) != tvg::Result::Success) {
|
||||
cout << "Error while loading TTF from memory. Did you enable TTF Loader?" << endl;
|
||||
}
|
||||
free(data);
|
||||
|
||||
auto text = tvg::Text::gen();
|
||||
text->font("Arial", 80);
|
||||
|
|
Loading…
Add table
Reference in a new issue