mirror of
https://github.com/FreeRDP/FreeRDP.git
synced 2024-11-24 02:14:11 +08:00
[client,sdl] use TTF_OpenFontRW
In combination with SDL_RWFromConstMem the font can be embedded without using an intermediate file to load it from.
This commit is contained in:
parent
bc2caa8504
commit
b28521d2d9
@ -7,7 +7,5 @@ add_executable(
|
||||
add_library(font OBJECT
|
||||
opensans_variable_font.hpp
|
||||
opensans_variable_font.cpp
|
||||
font_writer.hpp
|
||||
font_writer.cpp
|
||||
)
|
||||
set_property(TARGET font PROPERTY POSITION_INDEPENDENT_CODE ON)
|
||||
|
@ -1,22 +0,0 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
|
||||
#include "font_writer.hpp"
|
||||
#include "opensans_variable_font.hpp"
|
||||
|
||||
std::string create_and_return_temorary_font()
|
||||
{
|
||||
static std::string name;
|
||||
|
||||
if (name.empty())
|
||||
{
|
||||
auto path = std::filesystem::temp_directory_path();
|
||||
path /= "font.ttf";
|
||||
|
||||
std::ofstream ofs(path, std::ios::binary);
|
||||
ofs.write(reinterpret_cast<const char*>(font_buffer.data()), font_buffer.size());
|
||||
|
||||
name = path.u8string();
|
||||
}
|
||||
return name;
|
||||
}
|
@ -1,5 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string create_and_return_temorary_font();
|
@ -27,7 +27,7 @@
|
||||
#include "sdl_widget.hpp"
|
||||
#include "../sdl_utils.hpp"
|
||||
|
||||
#include "font/font_writer.hpp"
|
||||
#include "font/opensans_variable_font.hpp"
|
||||
|
||||
#include <freerdp/log.h>
|
||||
|
||||
@ -43,8 +43,9 @@ SdlWidget::SdlWidget(SDL_Renderer* renderer, const SDL_Rect& rect, bool input)
|
||||
{
|
||||
assert(renderer);
|
||||
|
||||
auto font = create_and_return_temorary_font();
|
||||
_font = TTF_OpenFont(font.c_str(), 64);
|
||||
auto ops = SDL_RWFromConstMem(font_buffer.data(), static_cast<int>(font_buffer.size()));
|
||||
if (ops)
|
||||
_font = TTF_OpenFontRW(ops, 0, 64);
|
||||
}
|
||||
|
||||
SdlWidget::SdlWidget(SdlWidget&& other) noexcept
|
||||
|
Loading…
Reference in New Issue
Block a user