FireBirdLib - Topfield TMS PVR TAP Programming Library
FM_LoadFontFile.c
Go to the documentation of this file.
1#include <stdlib.h>
2#include "FBLib_FontManager.h"
3
4bool FM_LoadFontFile(char *FontFileName, tFontData *FontData)
5{
7
8 TYPE_File *f;
9 dword GreyScaleSize;
10 dword i, j, k;
11 char TAPPath[FBLIB_DIR_SIZE], FileName[MAX_FILE_NAME_SIZE+1];
12
13 //Initialize the struct
14 if(FontData) memset(FontData, 0, sizeof(tFontData));
15
16 if(!FontFileName || !FontFileName[0] || !FontData)
17 {
18 TRACEEXIT();
19 return FALSE;
20 }
21
22 ConvertPathType(FontFileName, TAPPath, PF_TAPPathOnly);
23 ConvertPathType(FontFileName, FileName, PF_FileNameOnly);
24
26 if(*TAPPath) HDD_ChangeDir(TAPPath);
27 if(!TAP_Hdd_Exist(FileName))
28 {
29 char s[120];
30 extern char __tap_program_name__[MAX_PROGRAM_NAME];
31
32 TAP_SPrint(s, "failed to load %s", FileName);
33 LogEntryFBLibPrintf(TRUE, "FontManager: %s", s);
34 ShowMessageWin(__tap_program_name__, s, "Please install the font", 300);
35
37
38 TRACEEXIT();
39 return FALSE;
40 }
41
42 f = TAP_Hdd_Fopen(FileName);
43 if(f == NULL)
44 {
46
47 TRACEEXIT();
48 return FALSE;
49 }
50
51 TAP_Hdd_Fread(FontData->FontDef, sizeof(tFontDef), 191, f);
52
53 /* Check for normal or compressed bitmap font */
54 if(FontData->FontDef[0].BitmapIndex == 0)
55 {
56 /* Normal font file. Last font table entry defines total size */
57 GreyScaleSize = FontData->FontDef[190].Width * FontData->FontDef[190].Height + FontData->FontDef[190].BitmapIndex;
58 }
59 else
60 {
61
62 /* Compressed font file. The first index for a compressed bitmap font
63 * is set to the size of the bitmap so we can identify and read the
64 * bitmap array, even though that index is logically zero.
65 */
66 GreyScaleSize = FontData->FontDef[0].BitmapIndex;
67 }
68
69 FontData->pFontData = TAP_MemAlloc(GreyScaleSize);
70
71 i = 0;
72 j = GreyScaleSize;
73 do
74 {
75 k = j;
76 if(k > 32768) k = 32768;
77 TAP_Hdd_Fread(&FontData->pFontData[i], k, 1, f);
78 i += k;
79 j -= k;
80 }while(j > 0);
81
82 TAP_Hdd_Fclose(f);
83
85
86 TRACEEXIT();
87 return TRUE;
88}
void ConvertPathType(const char *Source, char *Dest, tPathFormat DestFormat)
bool FM_LoadFontFile(char *FontFileName, tFontData *FontData)
bool HDD_ChangeDir(const char *Dir)
Definition: HDD_ChangeDir.c:5
void LogEntryFBLibPrintf(bool Console, char *format,...)
void ShowMessageWin(char *title, char *lpMessage1, char *lpMessage2, dword dwDelay)
Definition: ShowMessageWin.c:3
bool HDD_TAP_PushDir(void)
#define FBLIB_DIR_SIZE
Definition: libFireBird.h:1871
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
bool HDD_TAP_PopDir(void)
Definition: HDD_TAP_PopDir.c:3
@ PF_TAPPathOnly
Definition: libFireBird.h:1923
@ PF_FileNameOnly
Definition: libFireBird.h:1922
tFontDef FontDef[191]
Definition: libFireBird.h:1821
byte * pFontData
Definition: libFireBird.h:1820
dword Width
Definition: libFireBird.h:1813
dword Height
Definition: libFireBird.h:1814
dword BitmapIndex
Definition: libFireBird.h:1815