diff --git a/linux/src/platform_linux.cpp b/linux/src/platform_linux.cpp index a6b95e2eae..a78e4db77e 100644 --- a/linux/src/platform_linux.cpp +++ b/linux/src/platform_linux.cpp @@ -94,26 +94,26 @@ std::string stringFromFile(const char* _path) { return out; } -unsigned char* bytesFromFile(const char* _path, size_t& _size) { +std::vector bytesFromFile(const char* _path) { + if (!_path || strlen(_path) == 0) { return {}; } std::ifstream resource(_path, std::ifstream::ate | std::ifstream::binary); if(!resource.is_open()) { - logMsg("Failed to read file at path: %s\n", _path); - _size = 0; - return nullptr; + LOG("Failed to read file at path: %s", _path); + return {}; } - _size = resource.tellg(); + std::vector data; + size_t size = resource.tellg(); + data.resize(size); resource.seekg(std::ifstream::beg); - char* cdata = (char*) malloc(sizeof(char) * (_size)); - - resource.read(cdata, _size); + resource.read(data.data(), size); resource.close(); - return reinterpret_cast(cdata); + return data; } std::vector systemFontFallbacksHandle() { @@ -130,8 +130,8 @@ std::vector systemFontFallbacksHandle() { // System fonts are not available on linux yet, we will possibly use FontConfig in the future, for // references see the tizen platform implementation of system fonts -unsigned char* systemFont(const std::string& _name, const std::string& _weight, const std::string& _face, size_t* _size) { - return nullptr; +std::vector systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) { + return {}; } bool startUrlRequest(const std::string& _url, UrlCallback _callback) { diff --git a/rpi/src/platform_rpi.cpp b/rpi/src/platform_rpi.cpp index ba25c61deb..93934628e0 100644 --- a/rpi/src/platform_rpi.cpp +++ b/rpi/src/platform_rpi.cpp @@ -82,26 +82,26 @@ std::string stringFromFile(const char* _path) { return out; } -unsigned char* bytesFromFile(const char* _path, size_t& _size) { +std::vector bytesFromFile(const char* _path) { + if (!_path || strlen(_path) == 0) { return {}; } std::ifstream resource(_path, std::ifstream::ate | std::ifstream::binary); if(!resource.is_open()) { - logMsg("Failed to read file at path: %s\n", _path); - _size = 0; - return nullptr; + LOG("failed to read file at path: %s", _path); + return {}; } - _size = resource.tellg(); + std::vector data; + size_t size = resource.tellg(); + data.resize(size); resource.seekg(std::ifstream::beg); - char* cdata = (char*) malloc(sizeof(char) * _size); - - resource.read(cdata, _size); + resource.read(data.data(), size); resource.close(); - return reinterpret_cast(cdata); + return data; } FontSourceHandle getFontHandle(const char* _path) { @@ -130,8 +130,8 @@ std::vector systemFontFallbacksHandle() { // System fonts are not available on Raspberry Pi yet, we will possibly use FontConfig in the future, // for references see the tizen platform implementation of system fonts -unsigned char* systemFont(const std::string& _name, const std::string& _weight, const std::string& _face, size_t* _size) { - return nullptr; +std::vector systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) { + return {}; } bool startUrlRequest(const std::string& _url, UrlCallback _callback) { diff --git a/tests/src/platform_mock.cpp b/tests/src/platform_mock.cpp index 09cae8cc7a..46657ee648 100644 --- a/tests/src/platform_mock.cpp +++ b/tests/src/platform_mock.cpp @@ -15,6 +15,8 @@ #define FONT_JA "fonts/DroidSansJapanese.ttf" #define FALLBACK "fonts/DroidSansFallback.ttf" +#include "log.h" + static bool s_isContinuousRendering = false; void logMsg(const char* fmt, ...) { @@ -56,31 +58,30 @@ std::string stringFromFile(const char* _path) { return out; } -unsigned char* bytesFromFile(const char* _path, size_t& _size) { +std::vector bytesFromFile(const char* _path) { + if (!_path || strlen(_path) == 0) { return {}; } std::ifstream resource(_path, std::ifstream::ate | std::ifstream::binary); if(!resource.is_open()) { - logMsg("Failed to read file at path: %s\n", _path); - _size = 0; - return nullptr; + LOG("Failed to read file at path: %s", _path); + return {}; } - _size = resource.tellg(); + std::vector data; + size_t size = resource.tellg(); + data.resize(size); resource.seekg(std::ifstream::beg); - char* cdata = (char*) malloc(sizeof(char) * _size); - - resource.read(cdata, _size); + resource.read(data.data(), size); resource.close(); - return reinterpret_cast(cdata); + return data; } - -unsigned char* systemFont(const std::string& _name, const std::string& _weight, const std::string& _face, size_t* _size) { - return nullptr; +std::vector systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) { + return {}; } std::vector systemFontFallbacksHandle() { diff --git a/tizen/src/platform_tizen.cpp b/tizen/src/platform_tizen.cpp index 83fffd071f..bb3adf7bd4 100644 --- a/tizen/src/platform_tizen.cpp +++ b/tizen/src/platform_tizen.cpp @@ -207,36 +207,34 @@ std::string fontPath(const std::string& _name, const std::string& _weight, return fontFile; } -unsigned char* systemFont(const std::string& _name, const std::string& _weight, const std::string& _face, size_t* _size) { +std::vector systemFont(const std::string& _name, const std::string& _weight, const std::string& _face, size_t* _size) { std::string path = fontPath(_name, _weight, _face); - if (path.empty()) { return nullptr; } + if (path.empty()) { return {}; } - return bytesFromFile(path.c_str(), *_size); + return bytesFromFile(path.c_str()); } -unsigned char* bytesFromFile(const char* _path, size_t& _size) { - - if (!_path || strlen(_path) == 0) { return nullptr; } +std::vector bytesFromFile(const char* _path) { + if (!_path || strlen(_path) == 0) { return {}; } std::ifstream resource(_path, std::ifstream::ate | std::ifstream::binary); if(!resource.is_open()) { - logMsg("Failed to read file at path: %s\n", _path); - _size = 0; - return nullptr; + LOG("Failed to read file at path: %s", _path); + return {}; } - _size = resource.tellg(); + std::vector data; + size_t size = resource.tellg(); + data.resize(size); resource.seekg(std::ifstream::beg); - char* cdata = (char*) malloc(sizeof(char) * (_size)); - - resource.read(cdata, _size); + resource.read(data.data(), size); resource.close(); - return reinterpret_cast(cdata); + return data; } std::string stringFromFile(const char* _path) {