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
4tGlyphCacheUC *FMUC_GetGlyphData(tFontDataUC *FontData, const byte *UTF8Character, byte *BytesPerChar)
5{
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}
void * FMUC_ReserveMemory(char *Requester, dword size)
Definition: FMUC_MemDebug.c:60
tGlyphCacheUC * FMUC_GetGlyphData(tFontDataUC *FontData, const byte *UTF8Character, byte *BytesPerChar)
void LogEntryFBLibPrintf(bool Console, char *format,...)
#define SEEK_SET
Definition: libFireBird.h:1875
#define TRACEEXIT()
Definition: libFireBird.h:1244
#define TRACEENTER()
Definition: libFireBird.h:1243
dword UTF8ToUTF32(const byte *UTF8Character, byte *BytesPerChar)
Definition: UTF8ToUTF32.c:3
tGlyphCacheUC * GlyphCache
Definition: libFireBird.h:1854
dword GlyphCacheEntries
Definition: libFireBird.h:1853
tFontDefUC * FontDef
Definition: libFireBird.h:1852
dword FontDefEntries
Definition: libFireBird.h:1851
dword FileOffset
Definition: libFireBird.h:1835
dword Unicode
Definition: libFireBird.h:1834
byte * GlyphData
Definition: libFireBird.h:1843