Skip to content

Commit

Permalink
Update linux platforms with new interface
Browse files Browse the repository at this point in the history
  • Loading branch information
karimnaaji committed Jan 6, 2017
1 parent 576f44e commit acc2579
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 52 deletions.
22 changes: 11 additions & 11 deletions linux/src/platform_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,26 +94,26 @@ std::string stringFromFile(const char* _path) {
return out;
}

unsigned char* bytesFromFile(const char* _path, size_t& _size) {
std::vector<char> 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<char> 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<unsigned char *>(cdata);
return data;
}

std::vector<FontSourceHandle> systemFontFallbacksHandle() {
Expand All @@ -130,8 +130,8 @@ std::vector<FontSourceHandle> 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<char> systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) {
return {};
}

bool startUrlRequest(const std::string& _url, UrlCallback _callback) {
Expand Down
22 changes: 11 additions & 11 deletions rpi/src/platform_rpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,26 @@ std::string stringFromFile(const char* _path) {
return out;
}

unsigned char* bytesFromFile(const char* _path, size_t& _size) {
std::vector<char> 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<char> 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<unsigned char *>(cdata);
return data;
}

FontSourceHandle getFontHandle(const char* _path) {
Expand Down Expand Up @@ -130,8 +130,8 @@ std::vector<FontSourceHandle> 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<char> systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) {
return {};
}

bool startUrlRequest(const std::string& _url, UrlCallback _callback) {
Expand Down
25 changes: 13 additions & 12 deletions tests/src/platform_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) {
Expand Down Expand Up @@ -56,31 +58,30 @@ std::string stringFromFile(const char* _path) {
return out;
}

unsigned char* bytesFromFile(const char* _path, size_t& _size) {
std::vector<char> 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<char> 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<unsigned char *>(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<char> systemFont(const std::string& _name, const std::string& _weight, const std::string& _face) {
return {};
}

std::vector<FontSourceHandle> systemFontFallbacksHandle() {
Expand Down
6 changes: 2 additions & 4 deletions tests/unit/lineWrapTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,8 @@ std::shared_ptr<alfons::Font> font;
void initFont(std::string _font = TEST_FONT) {
font = fontManager.addFont("default", TEST_FONT_SIZE, alfons::InputSource(_font));

size_t dataSize = 0;
char* data = reinterpret_cast<char*>(bytesFromFile(_font.c_str(), dataSize));
auto face = fontManager.addFontFace(alfons::InputSource(data, dataSize), TEST_FONT_SIZE);
free(data);
auto data = bytesFromFile(_font.c_str());
auto face = fontManager.addFontFace(alfons::InputSource(data), TEST_FONT_SIZE);
font->addFace(face);
}

Expand Down
26 changes: 12 additions & 14 deletions tizen/src/platform_tizen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<char> 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<char> 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<char> 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<unsigned char *>(cdata);
return data;
}

std::string stringFromFile(const char* _path) {
Expand Down

0 comments on commit acc2579

Please sign in to comment.