FireBirdLib - Topfield TMS PVR TAP Programming Library
FMUC_GetGlyphData.c
Go to the documentation of this file.
1
#include <unistd.h>
2
#include "
FBLib_FontManager.h
"
3
4
tGlyphCacheUC
*
FMUC_GetGlyphData
(
tFontDataUC
*FontData,
const
byte
*UTF8Character,
byte
*BytesPerChar)
5
{
6
TRACEENTER
();
7
8
int
i;
9
dword UTF32;
10
tGlyphCacheUC
*GC;
11
12
if
(!FontData || (FontData->
FileHandle
<= 0) || !UTF8Character || !*UTF8Character)
13
{
14
if
(BytesPerChar) *BytesPerChar = 1;
15
16
TRACEEXIT
();
17
return
NULL;
18
}
19
20
//Code Points 0x00-0x1f and 0x80-0x9f do not contain glyphs
21
if
((*UTF8Character <= 0x1f) || ((*UTF8Character >= 0x80) && (*UTF8Character <= 0x9f)))
22
{
23
if
(BytesPerChar) *BytesPerChar = 1;
24
25
TRACEEXIT
();
26
return
NULL;
27
}
28
29
UTF32 =
UTF8ToUTF32
(UTF8Character, BytesPerChar);
30
31
//Check if the character is already in the cache
32
GC = &FontData->
GlyphCache
[0];
33
for
(i = 0; i < (int)FontData->
GlyphCacheEntries
; i++)
34
{
35
if
(GC->
Unicode
== UTF32)
36
{
37
TRACEEXIT
();
38
return
GC;
39
}
40
GC++;
41
}
42
43
//Locate it in the file
44
for
(i = 0; i < (int)FontData->
FontDefEntries
; i++)
45
if
(FontData->
FontDef
[i].
Unicode
== UTF32)
46
{
47
//Create a cache entry for that glyph and return a pointer to it
48
tFontDefUC
*FontDef = &FontData->
FontDef
[i];
49
tGlyphCacheUC
*GlyphCache = &FontData->
GlyphCache
[FontData->
GlyphCacheEntries
];
50
51
GlyphCache->
Unicode
= FontDef->
Unicode
;
52
GlyphCache->
Width
= FontDef->
Width
;
53
GlyphCache->
Height
= FontDef->
Height
;
54
55
GlyphCache->
GlyphData
=
FMUC_ReserveMemory
(
"FMUC_GetGlyphData GlyphData"
, FontDef->
Width
* FontDef->
Height
);
56
if
(GlyphCache->
GlyphData
== NULL)
57
{
58
LogEntryFBLibPrintf
(TRUE,
"FontManager UC: failed to reserve %d bytes for a glyph"
, FontDef->
Width
* FontDef->
Height
);
59
60
TRACEEXIT
();
61
return
NULL;
62
}
63
64
lseek(FontData->
FileHandle
, FontDef->
FileOffset
,
SEEK_SET
);
65
read(FontData->
FileHandle
, GlyphCache->
GlyphData
, FontDef->
Width
* FontDef->
Height
);
66
67
FontData->
GlyphCacheEntries
++;
68
69
TRACEEXIT
();
70
return
GlyphCache;
71
}
72
73
//LogEntryFBLibPrintf(TRUE, "Glyph %x not found", UTF32);
74
75
TRACEEXIT
();
76
return
NULL;
77
}
FBLib_FontManager.h
FMUC_ReserveMemory
void * FMUC_ReserveMemory(char *Requester, dword size)
Definition:
FMUC_MemDebug.c:60
FMUC_GetGlyphData
tGlyphCacheUC * FMUC_GetGlyphData(tFontDataUC *FontData, const byte *UTF8Character, byte *BytesPerChar)
Definition:
FMUC_GetGlyphData.c:4
LogEntryFBLibPrintf
void LogEntryFBLibPrintf(bool Console, char *format,...)
Definition:
LogEntryFBLibPrintf.c:13
SEEK_SET
#define SEEK_SET
Definition:
libFireBird.h:1875
TRACEEXIT
#define TRACEEXIT()
Definition:
libFireBird.h:1244
TRACEENTER
#define TRACEENTER()
Definition:
libFireBird.h:1243
UTF8ToUTF32
dword UTF8ToUTF32(const byte *UTF8Character, byte *BytesPerChar)
Definition:
UTF8ToUTF32.c:3
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
tFontDefUC::FileOffset
dword FileOffset
Definition:
libFireBird.h:1835
tFontDefUC::Unicode
dword Unicode
Definition:
libFireBird.h:1834
tFontDefUC::Height
word Height
Definition:
libFireBird.h:1837
tFontDefUC::Width
word Width
Definition:
libFireBird.h:1836
tGlyphCacheUC
Definition:
libFireBird.h:1841
tGlyphCacheUC::Height
word Height
Definition:
libFireBird.h:1845
tGlyphCacheUC::GlyphData
byte * GlyphData
Definition:
libFireBird.h:1843
tGlyphCacheUC::Unicode
dword Unicode
Definition:
libFireBird.h:1842
tGlyphCacheUC::Width
word Width
Definition:
libFireBird.h:1844
FontManager
FMUC_GetGlyphData.c
Generated on Fri Apr 29 2022 13:34:01 for FireBirdLib - Topfield TMS PVR TAP Programming Library by
1.9.3