FireBirdLib - Topfield TMS PVR TAP Programming Library
FMUC_LoadFontFile.c
Go to the documentation of this file.
1
#include <fcntl.h>
2
#include <unistd.h>
3
#include <string.h>
4
#include "
FBLib_FontManager.h
"
5
6
bool
FMUC_LoadFontFile
(
char
*FontFileName,
tFontDataUC
*FontData)
7
{
8
TRACEENTER
();
9
10
char
Hdr[5];
11
char
FileName[MAX_FILE_NAME_SIZE+1];
12
char
AbsFileName[512];
13
14
//Initialize the struct
15
if
(FontData) memset(FontData, 0,
sizeof
(
tFontDataUC
));
16
17
if
(!FontFileName || !FontFileName[0] || !FontData)
18
{
19
TRACEEXIT
();
20
return
FALSE;
21
}
22
23
ConvertPathType
(FontFileName, FileName,
PF_FileNameOnly
);
24
25
//Open the font file
26
strcpy(AbsFileName,
"/mnt/hd"
FONTSDIR
"/"
);
27
strcat(AbsFileName, FileName);
28
29
FontData->
FileHandle
= open(AbsFileName, O_RDONLY, 0600);
30
if
(FontData->
FileHandle
< 0)
31
{
32
char
s[120];
33
extern
char
__tap_program_name__[MAX_PROGRAM_NAME];
34
35
TAP_SPrint(s,
"failed to load %s"
, FileName);
36
LogEntryFBLibPrintf
(TRUE,
"FontManager UC: %s"
, s);
37
ShowMessageWin
(__tap_program_name__, s,
"Please install the font"
, 300);
38
39
TRACEEXIT
();
40
return
FALSE;
41
}
42
43
//Check the header
44
read(FontData->
FileHandle
, Hdr, 4);
45
Hdr[4] =
'\0'
;
46
if
(strcmp(Hdr,
"UFNT"
))
47
{
48
close(FontData->
FileHandle
);
49
FontData->
FileHandle
= 0;
50
LogEntryFBLibPrintf
(TRUE,
"FontManager UC: '%s' has invalid header"
, FileName);
51
52
TRACEEXIT
();
53
return
FALSE;
54
}
55
56
//Read the size of the FontDef table and allocate the necessary memory
57
read(FontData->
FileHandle
, &FontData->
FontDefEntries
,
sizeof
(dword));
58
FontData->
FontDef
=
FMUC_ReserveMemory
(
"FMUC_LoadFontFile FontDef"
, FontData->
FontDefEntries
*
sizeof
(
tFontDefUC
));
59
60
if
(FontData->
FontDef
== NULL)
61
{
62
close(FontData->
FileHandle
);
63
FontData->
FileHandle
= 0;
64
LogEntryFBLibPrintf
(TRUE,
"FontManager UC: failed to allocate %lu bytes for the FontDef table of '%s'"
, FontData->
FontDefEntries
*
sizeof
(
tFontDefUC
), FileName);
65
66
TRACEEXIT
();
67
return
FALSE;
68
}
69
70
//LogEntryFBLibPrintf(TRUE, "FontManager UC: %lu glyphs available in '%s'", FontData->FontDefEntries, FontFileName);
71
72
//Read the FontDef table
73
read(FontData->
FileHandle
, FontData->
FontDef
,
sizeof
(
tFontDefUC
) * FontData->
FontDefEntries
);
74
75
//Reserve memory for the font cache
76
FontData->
GlyphCacheEntries
= 0;
77
78
FontData->
GlyphCache
=
FMUC_ReserveMemory
(
"FMUC_LoadFontFile GlyphCache"
, FontData->
FontDefEntries
*
sizeof
(
tGlyphCacheUC
));
79
if
(FontData->
GlyphCache
== NULL)
80
{
81
LogEntryFBLibPrintf
(TRUE,
"FontManager UC: failed to allocate %lu bytes for the FontCache table of '%s'"
, FontData->
FontDefEntries
*
sizeof
(
tGlyphCacheUC
), FileName);
82
83
TRACEEXIT
();
84
return
FALSE;
85
}
86
87
TRACEEXIT
();
88
return
TRUE;
89
}
ConvertPathType
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
Definition:
ConvertPathType.c:4
FBLib_FontManager.h
FMUC_ReserveMemory
void * FMUC_ReserveMemory(char *Requester, dword size)
Definition:
FMUC_MemDebug.c:60
FMUC_LoadFontFile
bool FMUC_LoadFontFile(char *FontFileName, tFontDataUC *FontData)
Definition:
FMUC_LoadFontFile.c:6
LogEntryFBLibPrintf
void LogEntryFBLibPrintf(bool Console, char *format,...)
Definition:
LogEntryFBLibPrintf.c:13
ShowMessageWin
void ShowMessageWin(char *title, char *lpMessage1, char *lpMessage2, dword dwDelay)
Definition:
ShowMessageWin.c:3
TRACEEXIT
#define TRACEEXIT()
Definition:
libFireBird.h:1244
TRACEENTER
#define TRACEENTER()
Definition:
libFireBird.h:1243
PF_FileNameOnly
@ PF_FileNameOnly
Definition:
libFireBird.h:1922
FONTSDIR
#define FONTSDIR
Definition:
libFireBird.h:1809
tFontDataUC
Definition:
libFireBird.h:1849
tFontDataUC::GlyphCache
tGlyphCacheUC * GlyphCache
Definition:
libFireBird.h:1854
tFontDataUC::GlyphCacheEntries
dword GlyphCacheEntries
Definition:
libFireBird.h:1853
tFontDataUC::FileHandle
int FileHandle
Definition:
libFireBird.h:1850
tFontDataUC::FontDef
tFontDefUC * FontDef
Definition:
libFireBird.h:1852
tFontDataUC::FontDefEntries
dword FontDefEntries
Definition:
libFireBird.h:1851
tFontDefUC
Definition:
libFireBird.h:1833
tGlyphCacheUC
Definition:
libFireBird.h:1841
FontManager
FMUC_LoadFontFile.c
Generated on Fri Apr 29 2022 13:34:01 for FireBirdLib - Topfield TMS PVR TAP Programming Library by
1.9.3