From 8c3c2ab652d897acc7c8d630a1ed556731204b53 Mon Sep 17 00:00:00 2001 From: Hermet Park Date: Wed, 3 Jan 2024 11:23:47 +0900 Subject: [PATCH] ttf: fix the windows compilation errors. --- src/loaders/ttf/tvgTtfLoader.cpp | 27 +++++++++++++-------------- src/loaders/ttf/tvgTtfLoader.h | 2 +- src/loaders/ttf/tvgTtfReader.cpp | 25 +++++++++++++------------ 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/loaders/ttf/tvgTtfLoader.cpp b/src/loaders/ttf/tvgTtfLoader.cpp index 34dfea93..e86405b2 100644 --- a/src/loaders/ttf/tvgTtfLoader.cpp +++ b/src/loaders/ttf/tvgTtfLoader.cpp @@ -20,6 +20,9 @@ * SOFTWARE. */ + +#include "tvgTtfLoader.h" + #ifdef _WIN32 #include #else @@ -29,10 +32,6 @@ #include #endif -#include -#include "tvgTtfLoader.h" - - /************************************************************************/ /* Internal Class Implementation */ /************************************************************************/ @@ -43,7 +42,7 @@ static bool _map(TtfLoader* loader, const string& path) { auto& reader = loader->reader; - auto file = CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + auto file = CreateFileA(path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (file == INVALID_HANDLE_VALUE) return false; DWORD high; @@ -55,16 +54,16 @@ static bool _map(TtfLoader* loader, const string& path) reader.size = (uint32_t)((size_t)high << (8 * sizeof(DWORD)) | low); - loader.mapping = (uint8_t*)CreateFileMapping(file, NULL, PAGE_READONLY, high, low, NULL); + loader->mapping = (uint8_t*)CreateFileMapping(file, NULL, PAGE_READONLY, high, low, NULL); CloseHandle(file); - if (!mapping) return false; + if (!loader->mapping) return false; - font->data = (uint8_t*) MapViewOfFile(loader.mapping, FILE_MAP_READ, 0, 0, 0); - if (!font->data) { - CloseHandle(loader.mapping); - font->reader = NULL; + loader->reader.data = (uint8_t*) MapViewOfFile(loader->mapping, FILE_MAP_READ, 0, 0, 0); + if (!loader->reader.data) { + CloseHandle(loader->mapping); + loader->mapping = nullptr; return false; } return true; @@ -74,9 +73,9 @@ static void _unmap(TtfLoader* loader) { auto& reader = loader->reader; - if (reader->data) { - UnmapViewOfFile(reader->data); - reader->data = nullptr; + if (reader.data) { + UnmapViewOfFile(reader.data); + reader.data = nullptr; } if (loader->mapping) { CloseHandle(loader->mapping); diff --git a/src/loaders/ttf/tvgTtfLoader.h b/src/loaders/ttf/tvgTtfLoader.h index 31986c29..ce38e429 100644 --- a/src/loaders/ttf/tvgTtfLoader.h +++ b/src/loaders/ttf/tvgTtfLoader.h @@ -31,7 +31,7 @@ struct TtfLoader : public FontLoader { #if defined(_WIN32) - HANDLE mapping = nullptr; + void* mapping = nullptr; #endif TtfReader reader; char* text = nullptr; diff --git a/src/loaders/ttf/tvgTtfReader.cpp b/src/loaders/ttf/tvgTtfReader.cpp index def0e945..25237190 100644 --- a/src/loaders/ttf/tvgTtfReader.cpp +++ b/src/loaders/ttf/tvgTtfReader.cpp @@ -20,7 +20,14 @@ * SOFTWARE. */ -#include + +#ifdef _WIN32 + #include +#elif defined(__linux__) + #include +#else + #include +#endif #include "tvgMath.h" #include "tvgShape.h" @@ -57,12 +64,6 @@ static inline uint8_t _u8(uint8_t* data, uint32_t offset) } -static inline int8_t _i8(uint8_t* data, uint32_t offset) -{ - return (int8_t) _u8(data, offset); -} - - static int _cmpu32(const void *a, const void *b) { return memcmp(a, b, 4); @@ -242,7 +243,7 @@ bool TtfReader::points(uint32_t outline, uint8_t* flags, Point* pts, uint32_t pt return false; } auto value = (long) _u8(data, outline++); - auto bit = !!(flags[i] & X_CHANGE_IS_POSITIVE); + auto bit = (uint8_t)!!(flags[i] & X_CHANGE_IS_POSITIVE); accum -= (value ^ -bit) + bit; } else if (!(flags[i] & X_CHANGE_IS_ZERO)) { if (!validate(outline, 2)) return false; @@ -258,7 +259,7 @@ bool TtfReader::points(uint32_t outline, uint8_t* flags, Point* pts, uint32_t pt if (flags[i] & Y_CHANGE_IS_SMALL) { if (!validate(outline, 1)) return false; auto value = (long) _u8(data, outline++); - auto bit = !!(flags[i] & Y_CHANGE_IS_POSITIVE); + auto bit = (uint8_t)!!(flags[i] & Y_CHANGE_IS_POSITIVE); accum -= (value ^ -bit) + bit; } else if (!(flags[i] & Y_CHANGE_IS_ZERO)) { if (!validate(outline, 2)) return false; @@ -444,7 +445,7 @@ bool TtfReader::convert(Shape* shape, TtfGlyphMetrics& gmetrics, const Point& of if (!validate(outline, cntrsCnt * 2 + 2)) return false; auto ptsCnt = _u16(data, outline + (cntrsCnt - 1) * 2) + 1; - size_t endPts[cntrsCnt]; //the index of the contour points. + auto endPts = (size_t*)alloca(cntrsCnt * sizeof(size_t)); //the index of the contour points. for (uint32_t i = 0; i < cntrsCnt; ++i) { endPts[i] = (uint32_t) _u16(data, outline); @@ -452,10 +453,10 @@ bool TtfReader::convert(Shape* shape, TtfGlyphMetrics& gmetrics, const Point& of } outline += 2U + _u16(data, outline); - uint8_t flags[ptsCnt]; + auto flags = (uint8_t*)alloca(ptsCnt * sizeof(uint8_t)); if (!this->flags(&outline, flags, ptsCnt)) return false; - Point pts[ptsCnt]; + auto pts = (Point*)alloca(ptsCnt * sizeof(Point)); if (!this->points(outline, flags, pts, ptsCnt, offset + kerning)) return false; //generate tvg pathes.