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
6bool FMUC_LoadFontFile(char *FontFileName, tFontDataUC *FontData)
7{
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}
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
void * FMUC_ReserveMemory(char *Requester, dword size)
Definition: FMUC_MemDebug.c:60
bool FMUC_LoadFontFile(char *FontFileName, tFontDataUC *FontData)
void LogEntryFBLibPrintf(bool Console, char *format,...)
void ShowMessageWin(char *title, char *lpMessage1, char *lpMessage2, dword dwDelay)
Definition: ShowMessageWin.c:3
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
@ PF_FileNameOnly
Definition: libFireBird.h:1922
#define FONTSDIR
Definition: libFireBird.h:1809
tGlyphCacheUC * GlyphCache
Definition: libFireBird.h:1854
dword GlyphCacheEntries
Definition: libFireBird.h:1853
tFontDefUC * FontDef
Definition: libFireBird.h:1852
dword FontDefEntries
Definition: libFireBird.h:1851