cleaner constructor interface.

This commit is contained in:
Christoph Oelckers 2024-01-08 21:54:50 +01:00
parent 10ce3abb77
commit a016bf1ef2
3 changed files with 4 additions and 4 deletions

View file

@ -47,7 +47,7 @@ class CanvasFont
public: public:
CanvasFont(const std::string& fontname, double height, std::vector<uint8_t>& _data) : fontname(fontname), height(height) CanvasFont(const std::string& fontname, double height, std::vector<uint8_t>& _data) : fontname(fontname), height(height)
{ {
ttf = std::make_unique<TrueTypeFont>(_data); ttf = std::make_unique<TrueTypeFont>(std::make_shared<TrueTypeFontFileData>(_data));
textmetrics = ttf->GetTextMetrics(height); textmetrics = ttf->GetTextMetrics(height);
} }

View file

@ -11,7 +11,7 @@
#include <fstream> #include <fstream>
#endif #endif
TrueTypeFont::TrueTypeFont(std::shared_ptr<TrueTypeFontFileData> initdata, int ttcFontIndex) : data(std::move(initdata)) TrueTypeFont::TrueTypeFont(std::shared_ptr<TrueTypeFontFileData>& initdata, int ttcFontIndex) : data(initdata)
{ {
if (data->size() > 0x7fffffff) if (data->size() > 0x7fffffff)
throw std::runtime_error("TTF file is larger than 2 gigabytes!"); throw std::runtime_error("TTF file is larger than 2 gigabytes!");

View file

@ -445,7 +445,7 @@ public:
class TrueTypeFontFileData class TrueTypeFontFileData
{ {
public: public:
TrueTypeFontFileData(std::vector<uint8_t> data) : dataVector(std::move(data)) TrueTypeFontFileData(std::vector<uint8_t>& data) : dataVector(std::move(data))
{ {
dataPtr = dataVector.data(); dataPtr = dataVector.data();
dataSize = dataVector.size(); dataSize = dataVector.size();
@ -491,7 +491,7 @@ private:
class TrueTypeFont class TrueTypeFont
{ {
public: public:
TrueTypeFont(std::shared_ptr<TrueTypeFontFileData> data, int ttcFontIndex = 0); TrueTypeFont(std::shared_ptr<TrueTypeFontFileData>& data, int ttcFontIndex = 0);
static std::vector<TTCFontName> GetFontNames(const std::shared_ptr<TrueTypeFontFileData>& data); static std::vector<TTCFontName> GetFontNames(const std::shared_ptr<TrueTypeFontFileData>& data);