|
|
|
@ -1,19 +1,19 @@ |
|
|
|
|
/***************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* ftsystem.c */ |
|
|
|
|
/* */ |
|
|
|
|
/* Unix-specific FreeType low-level system interface (body). */ |
|
|
|
|
/* */ |
|
|
|
|
/* Copyright (C) 1996-2020 by */ |
|
|
|
|
/* David Turner, Robert Wilhelm, and Werner Lemberg. */ |
|
|
|
|
/* */ |
|
|
|
|
/* This file is part of the FreeType project, and may only be used, */ |
|
|
|
|
/* modified, and distributed under the terms of the FreeType project */ |
|
|
|
|
/* license, LICENSE.TXT. By continuing to use, modify, or distribute */ |
|
|
|
|
/* this file you indicate that you have read the license and */ |
|
|
|
|
/* understand and accept it fully. */ |
|
|
|
|
/* */ |
|
|
|
|
/***************************************************************************/ |
|
|
|
|
/****************************************************************************
|
|
|
|
|
* |
|
|
|
|
* ftsystem.c |
|
|
|
|
* |
|
|
|
|
* Windows-specific FreeType low-level system interface (body). |
|
|
|
|
* |
|
|
|
|
* Copyright (C) 2021 by |
|
|
|
|
* David Turner, Robert Wilhelm, and Werner Lemberg. |
|
|
|
|
* |
|
|
|
|
* This file is part of the FreeType project, and may only be used, |
|
|
|
|
* modified, and distributed under the terms of the FreeType project |
|
|
|
|
* license, LICENSE.TXT. By continuing to use, modify, or distribute |
|
|
|
|
* this file you indicate that you have read the license and |
|
|
|
|
* understand and accept it fully. |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <ft2build.h> |
|
|
|
@ -31,29 +31,40 @@ |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* MEMORY MANAGEMENT INTERFACE */ |
|
|
|
|
/* */ |
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* <Function> */ |
|
|
|
|
/* ft_alloc */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Description> */ |
|
|
|
|
/* The memory allocation function. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Input> */ |
|
|
|
|
/* memory :: A pointer to the memory object. */ |
|
|
|
|
/* */ |
|
|
|
|
/* size :: The requested size in bytes. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Return> */ |
|
|
|
|
/* The address of newly allocated block. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* MEMORY MANAGEMENT INTERFACE |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* It is not necessary to do any error checking for the |
|
|
|
|
* allocation-related functions. This will be done by the higher level |
|
|
|
|
* routines like ft_mem_alloc() or ft_mem_realloc(). |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* @Function: |
|
|
|
|
* ft_alloc |
|
|
|
|
* |
|
|
|
|
* @Description: |
|
|
|
|
* The memory allocation function. |
|
|
|
|
* |
|
|
|
|
* @Input: |
|
|
|
|
* memory :: |
|
|
|
|
* A pointer to the memory object. |
|
|
|
|
* |
|
|
|
|
* size :: |
|
|
|
|
* The requested size in bytes. |
|
|
|
|
* |
|
|
|
|
* @Return: |
|
|
|
|
* The address of newly allocated block. |
|
|
|
|
*/ |
|
|
|
|
FT_CALLBACK_DEF( void* ) |
|
|
|
|
ft_alloc( FT_Memory memory, |
|
|
|
|
long size ) |
|
|
|
@ -64,26 +75,30 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* <Function> */ |
|
|
|
|
/* ft_realloc */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Description> */ |
|
|
|
|
/* The memory reallocation function. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Input> */ |
|
|
|
|
/* memory :: A pointer to the memory object. */ |
|
|
|
|
/* */ |
|
|
|
|
/* cur_size :: The current size of the allocated memory block. */ |
|
|
|
|
/* */ |
|
|
|
|
/* new_size :: The newly requested size in bytes. */ |
|
|
|
|
/* */ |
|
|
|
|
/* block :: The current address of the block in memory. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Return> */ |
|
|
|
|
/* The address of the reallocated memory block. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* @Function: |
|
|
|
|
* ft_realloc |
|
|
|
|
* |
|
|
|
|
* @Description: |
|
|
|
|
* The memory reallocation function. |
|
|
|
|
* |
|
|
|
|
* @Input: |
|
|
|
|
* memory :: |
|
|
|
|
* A pointer to the memory object. |
|
|
|
|
* |
|
|
|
|
* cur_size :: |
|
|
|
|
* The current size of the allocated memory block. |
|
|
|
|
* |
|
|
|
|
* new_size :: |
|
|
|
|
* The newly requested size in bytes. |
|
|
|
|
* |
|
|
|
|
* block :: |
|
|
|
|
* The current address of the block in memory. |
|
|
|
|
* |
|
|
|
|
* @Return: |
|
|
|
|
* The address of the reallocated memory block. |
|
|
|
|
*/ |
|
|
|
|
FT_CALLBACK_DEF( void* ) |
|
|
|
|
ft_realloc( FT_Memory memory, |
|
|
|
|
long cur_size, |
|
|
|
@ -97,19 +112,21 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* <Function> */ |
|
|
|
|
/* ft_free */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Description> */ |
|
|
|
|
/* The memory release function. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Input> */ |
|
|
|
|
/* memory :: A pointer to the memory object. */ |
|
|
|
|
/* */ |
|
|
|
|
/* block :: The address of block in memory to be freed. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* @Function: |
|
|
|
|
* ft_free |
|
|
|
|
* |
|
|
|
|
* @Description: |
|
|
|
|
* The memory release function. |
|
|
|
|
* |
|
|
|
|
* @Input: |
|
|
|
|
* memory :: |
|
|
|
|
* A pointer to the memory object. |
|
|
|
|
* |
|
|
|
|
* block :: |
|
|
|
|
* The address of block in memory to be freed. |
|
|
|
|
*/ |
|
|
|
|
FT_CALLBACK_DEF( void ) |
|
|
|
|
ft_free( FT_Memory memory, |
|
|
|
|
void* block ) |
|
|
|
@ -120,19 +137,19 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* RESOURCE MANAGEMENT INTERFACE */ |
|
|
|
|
/* */ |
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* RESOURCE MANAGEMENT INTERFACE |
|
|
|
|
* |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* The macro FT_COMPONENT is used in trace mode. It is an implicit */ |
|
|
|
|
/* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */ |
|
|
|
|
/* messages during execution. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* The macro FT_COMPONENT is used in trace mode. It is an implicit |
|
|
|
|
* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log |
|
|
|
|
* messages during execution. |
|
|
|
|
*/ |
|
|
|
|
#undef FT_COMPONENT |
|
|
|
|
#define FT_COMPONENT io |
|
|
|
|
|
|
|
|
@ -141,17 +158,17 @@ |
|
|
|
|
#define STREAM_FILE( stream ) ( (FILE*)stream->descriptor.pointer ) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* <Function> */ |
|
|
|
|
/* ft_close_stream_by_munmap */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Description> */ |
|
|
|
|
/* The function to close a stream which is opened by mmap. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Input> */ |
|
|
|
|
/* stream :: A pointer to the stream object. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* @Function: |
|
|
|
|
* ft_close_stream_by_munmap |
|
|
|
|
* |
|
|
|
|
* @Description: |
|
|
|
|
* The function to close a stream which is opened by mmap. |
|
|
|
|
* |
|
|
|
|
* @Input: |
|
|
|
|
* stream :: A pointer to the stream object. |
|
|
|
|
*/ |
|
|
|
|
FT_CALLBACK_DEF( void ) |
|
|
|
|
ft_close_stream_by_munmap( FT_Stream stream ) |
|
|
|
|
{ |
|
|
|
@ -163,17 +180,17 @@ |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
/* */ |
|
|
|
|
/* <Function> */ |
|
|
|
|
/* ft_close_stream_by_free */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Description> */ |
|
|
|
|
/* The function to close a stream which is created by ft_alloc. */ |
|
|
|
|
/* */ |
|
|
|
|
/* <Input> */ |
|
|
|
|
/* stream :: A pointer to the stream object. */ |
|
|
|
|
/* */ |
|
|
|
|
/**************************************************************************
|
|
|
|
|
* |
|
|
|
|
* @Function: |
|
|
|
|
* ft_close_stream_by_free |
|
|
|
|
* |
|
|
|
|
* @Description: |
|
|
|
|
* The function to close a stream which is created by ft_alloc. |
|
|
|
|
* |
|
|
|
|
* @Input: |
|
|
|
|
* stream :: A pointer to the stream object. |
|
|
|
|
*/ |
|
|
|
|
FT_CALLBACK_DEF( void ) |
|
|
|
|
ft_close_stream_by_free( FT_Stream stream ) |
|
|
|
|
{ |
|
|
|
@ -191,9 +208,10 @@ |
|
|
|
|
FT_Stream_Open( FT_Stream stream, |
|
|
|
|
const char* filepathname ) |
|
|
|
|
{ |
|
|
|
|
HANDLE file; |
|
|
|
|
HANDLE fm; |
|
|
|
|
LARGE_INTEGER size; |
|
|
|
|
HANDLE file; |
|
|
|
|
HANDLE fm; |
|
|
|
|
LARGE_INTEGER size; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( !stream ) |
|
|
|
|
return FT_THROW( Invalid_Stream_Handle ); |
|
|
|
@ -201,14 +219,14 @@ |
|
|
|
|
/* open the file */ |
|
|
|
|
file = CreateFileA( filepathname, GENERIC_READ, FILE_SHARE_READ, NULL, |
|
|
|
|
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0 ); |
|
|
|
|
if (file == INVALID_HANDLE_VALUE) |
|
|
|
|
if ( file == INVALID_HANDLE_VALUE ) |
|
|
|
|
{ |
|
|
|
|
FT_ERROR(( "FT_Stream_Open:" )); |
|
|
|
|
FT_ERROR(( " could not open `%s'\n", filepathname )); |
|
|
|
|
return FT_THROW( Cannot_Open_Resource ); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if ( GetFileSizeEx(file, &size) == FALSE ) |
|
|
|
|
if ( GetFileSizeEx( file, &size ) == FALSE ) |
|
|
|
|
{ |
|
|
|
|
FT_ERROR(( "FT_Stream_Open:" )); |
|
|
|
|
FT_ERROR(( " could not retrieve size of file `%s'\n", filepathname )); |
|
|
|
@ -229,8 +247,8 @@ |
|
|
|
|
goto Fail_Open; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
fm = CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, NULL); |
|
|
|
|
if (fm == NULL) |
|
|
|
|
fm = CreateFileMapping( file, NULL, PAGE_READONLY, 0, 0, NULL ); |
|
|
|
|
if ( fm == NULL ) |
|
|
|
|
{ |
|
|
|
|
FT_ERROR(( "FT_Stream_Open: can not map file\n" )); |
|
|
|
|
goto Fail_Open; |
|
|
|
@ -241,14 +259,17 @@ |
|
|
|
|
/* a size greater than LONG_MAX */ |
|
|
|
|
stream->size = size.LowPart; |
|
|
|
|
stream->pos = 0; |
|
|
|
|
stream->base = (unsigned char *)MapViewOfFile(fm, FILE_MAP_READ, 0, 0, 0); |
|
|
|
|
stream->base = (unsigned char *) |
|
|
|
|
MapViewOfFile( fm, FILE_MAP_READ, 0, 0, 0 ); |
|
|
|
|
|
|
|
|
|
CloseHandle( fm ); |
|
|
|
|
|
|
|
|
|
CloseHandle(fm); |
|
|
|
|
if ( stream->base != NULL ) |
|
|
|
|
stream->close = ft_close_stream_by_munmap; |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
DWORD total_read_count; |
|
|
|
|
DWORD total_read_count; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FT_ERROR(( "FT_Stream_Open:" )); |
|
|
|
|
FT_ERROR(( " could not `mmap' file `%s'\n", filepathname )); |
|
|
|
@ -265,7 +286,8 @@ |
|
|
|
|
total_read_count = 0; |
|
|
|
|
do |
|
|
|
|
{ |
|
|
|
|
DWORD read_count; |
|
|
|
|
DWORD read_count; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ( ReadFile( file, |
|
|
|
|
stream->base + total_read_count, |
|
|
|
|