ttf: fix the windows compilation errors.

This commit is contained in:
Hermet Park 2024-01-03 11:23:47 +09:00
parent cfb9ea8a43
commit 8c3c2ab652
3 changed files with 27 additions and 27 deletions

View file

@ -20,6 +20,9 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include "tvgTtfLoader.h"
#ifdef _WIN32 #ifdef _WIN32
#include <windows.h> #include <windows.h>
#else #else
@ -29,10 +32,6 @@
#include <sys/stat.h> #include <sys/stat.h>
#endif #endif
#include <memory.h>
#include "tvgTtfLoader.h"
/************************************************************************/ /************************************************************************/
/* Internal Class Implementation */ /* Internal Class Implementation */
/************************************************************************/ /************************************************************************/
@ -43,7 +42,7 @@ static bool _map(TtfLoader* loader, const string& path)
{ {
auto& reader = loader->reader; 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; if (file == INVALID_HANDLE_VALUE) return false;
DWORD high; 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); 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); CloseHandle(file);
if (!mapping) return false; if (!loader->mapping) return false;
font->data = (uint8_t*) MapViewOfFile(loader.mapping, FILE_MAP_READ, 0, 0, 0); loader->reader.data = (uint8_t*) MapViewOfFile(loader->mapping, FILE_MAP_READ, 0, 0, 0);
if (!font->data) { if (!loader->reader.data) {
CloseHandle(loader.mapping); CloseHandle(loader->mapping);
font->reader = NULL; loader->mapping = nullptr;
return false; return false;
} }
return true; return true;
@ -74,9 +73,9 @@ static void _unmap(TtfLoader* loader)
{ {
auto& reader = loader->reader; auto& reader = loader->reader;
if (reader->data) { if (reader.data) {
UnmapViewOfFile(reader->data); UnmapViewOfFile(reader.data);
reader->data = nullptr; reader.data = nullptr;
} }
if (loader->mapping) { if (loader->mapping) {
CloseHandle(loader->mapping); CloseHandle(loader->mapping);

View file

@ -31,7 +31,7 @@
struct TtfLoader : public FontLoader struct TtfLoader : public FontLoader
{ {
#if defined(_WIN32) #if defined(_WIN32)
HANDLE mapping = nullptr; void* mapping = nullptr;
#endif #endif
TtfReader reader; TtfReader reader;
char* text = nullptr; char* text = nullptr;

View file

@ -20,7 +20,14 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <memory.h>
#ifdef _WIN32
#include <malloc.h>
#elif defined(__linux__)
#include <alloca.h>
#else
#include <stdlib.h>
#endif
#include "tvgMath.h" #include "tvgMath.h"
#include "tvgShape.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) static int _cmpu32(const void *a, const void *b)
{ {
return memcmp(a, b, 4); 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; return false;
} }
auto value = (long) _u8(data, outline++); 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; accum -= (value ^ -bit) + bit;
} else if (!(flags[i] & X_CHANGE_IS_ZERO)) { } else if (!(flags[i] & X_CHANGE_IS_ZERO)) {
if (!validate(outline, 2)) return false; 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 (flags[i] & Y_CHANGE_IS_SMALL) {
if (!validate(outline, 1)) return false; if (!validate(outline, 1)) return false;
auto value = (long) _u8(data, outline++); 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; accum -= (value ^ -bit) + bit;
} else if (!(flags[i] & Y_CHANGE_IS_ZERO)) { } else if (!(flags[i] & Y_CHANGE_IS_ZERO)) {
if (!validate(outline, 2)) return false; 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; if (!validate(outline, cntrsCnt * 2 + 2)) return false;
auto ptsCnt = _u16(data, outline + (cntrsCnt - 1) * 2) + 1; 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) { for (uint32_t i = 0; i < cntrsCnt; ++i) {
endPts[i] = (uint32_t) _u16(data, outline); 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); 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; 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; if (!this->points(outline, flags, pts, ptsCnt, offset + kerning)) return false;
//generate tvg pathes. //generate tvg pathes.