mirror of
https://github.com/thorvg/thorvg.git
synced 2025-06-13 19:44:28 +00:00
ttf: fix the windows compilation errors.
This commit is contained in:
parent
15baf20363
commit
139a1c5e85
3 changed files with 27 additions and 27 deletions
|
@ -20,6 +20,9 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
#include "tvgTtfLoader.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
|
@ -29,10 +32,6 @@
|
|||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
#include <memory.h>
|
||||
#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);
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
struct TtfLoader : public FontLoader
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
HANDLE mapping = nullptr;
|
||||
void* mapping = nullptr;
|
||||
#endif
|
||||
TtfReader reader;
|
||||
char* text = nullptr;
|
||||
|
|
|
@ -20,7 +20,14 @@
|
|||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#include <malloc.h>
|
||||
#elif defined(__linux__)
|
||||
#include <alloca.h>
|
||||
#else
|
||||
#include <stdlib.h>
|
||||
#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.
|
||||
|
|
Loading…
Add table
Reference in a new issue