Changeset 662
- Timestamp:
- 05/14/11 06:14:33 (2 years ago)
- File:
-
- 1 edited
-
trunk/lib/font/rbf_font.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/lib/font/rbf_font.c
r627 r662 14 14 // Header as seperate structure so it can be directly loaded from the font file easily 15 15 // structure layout maps to file layout - do not change ! 16 struct font_hdr{17 int magic1, magic2; // header magic numbers to identify correct font file18 char name[RBF_MAX_NAME]; 19 int charSize; 20 int points; 21 int height; 22 int maxWidth; 23 int charFirst; 24 int charLast; 25 int _unknown4; 26 int _wmapAddr; 27 int _cmapAddr; 28 int descent; 29 int intline; 30 } ;31 32 structfont {33 structfont_hdr hdr;16 typedef struct { 17 int magic1, magic2; // header magic numbers to identify correct font file 18 char name[RBF_MAX_NAME]; // name of font (max 64 characters) 19 int charSize; // # of bytes used to store each character 20 int points; // font size in points 21 int height; // font height in pixels 22 int maxWidth; // width of widest character 23 int charFirst; // first character # 24 int charLast; // last character # 25 int _unknown4; // ? 26 int _wmapAddr; // offset in font file of wTable array 27 int _cmapAddr; // offset in font file of cTable array 28 int descent; // font descent (not used) 29 int intline; // interline spacing (not used) 30 } font_hdr; 31 32 typedef struct _font { 33 font_hdr hdr; 34 34 35 35 // calculated values (after font is loaded) 36 int charCount; 37 int width; 36 int charCount; // count of chars containing in font 37 int width; // font element width in pixels 38 38 39 39 // Width table 40 // List of character widths. Elements of list is width of char 40 41 char wTable[256]; 41 42 42 43 // Character data 44 // List of chars. Element of list is a bytecode string, contains pixels representation of char 43 45 char *cTable; 44 46 47 // Flag to indicate we are actually using the built in 8x16 font rather than a loaded font 48 int usingFont8x16; 49 45 50 // Current size of the cTable data 46 int usingFont8x16;47 51 int cTableSize; 48 struct font *uncached_font;// address of font in uncached memory (for passing to ufree & read)52 struct _font *uncached_font; // address of font in uncached memory (for passing to ufree & read) 49 53 char *uncached_cTable; // address of cTable in uncached memory (for passing to ufree & read) 50 } ;51 52 static structfont *rbf_symbol_font = 0, *rbf_font = 0;54 } font; 55 56 static font *rbf_symbol_font = 0, *rbf_font = 0; 53 57 static int rbf_codepage = FONT_CP_WIN; 54 58 55 59 //------------------------------------------------------------------- 56 60 57 structfont *new_font() {61 font *new_font() { 58 62 // allocate font from uncached memory 59 struct font *f = umalloc(sizeof(structfont));63 font *f = umalloc(sizeof(font)); 60 64 if (f) { 61 memset(f,0,sizeof( struct font));// wipe memory (use uncached address to avoid conflict with read & caching)62 f->uncached_font = f; // save uncached memory address65 memset(f,0,sizeof(font)); // wipe memory (use uncached address to avoid conflict with read & caching) 66 f->uncached_font = f; // save uncached memory address 63 67 // return address in cached memory for faster font rendering 64 return ( structfont*)((int)f & ~CAM_UNCACHED_BIT);68 return (font*)((int)f & ~CAM_UNCACHED_BIT); 65 69 } 66 70 … … 76 80 } 77 81 78 void alloc_cTable( structfont *f) {82 void alloc_cTable(font *f) { 79 83 80 84 // Calculate additional values for font … … 132 136 //------------------------------------------------------------------- 133 137 // Return address of 'character' data for specified font & char 134 char* rbf_font_char( structfont* f, int ch)138 char* rbf_font_char(font* f, int ch) 135 139 { 136 140 if (f && (ch >= f->hdr.charFirst) && (ch <= f->hdr.charLast)) … … 143 147 //------------------------------------------------------------------- 144 148 // Load from from file. If maxchar != 0 limit charLast (for symbols) 145 int rbf_font_load(char *file, struct font* f, int maxchar) { 146 /* 147 name - name of font (max 64 characters) 148 width - font element width in pixels 149 height - font element height in pixels 150 points - font size in points 151 charFirst - ASCII code of first char, presents in font 152 charCount - count of chars containing in font 153 cTable - List of chars. Element of list is a bytecode string, 154 contains pixels representation of char 155 wTable - List of character widths. Elements of list 156 is width of char 157 intline - Interline spasing 158 maxWidth - width of widhest char in pixels 159 descent - font descent 160 ''' 161 */ 162 163 int fd; 164 char buf[8]; 149 // Note: pass the uncached font address to this function 150 int rbf_font_load(char *file, font* f, int maxchar) 151 { 165 152 int i; 166 153 … … 172 159 173 160 // open file (can't use fopen here due to potential conflict FsIoNotify crash) 174 fd = open(file, O_RDONLY, 0777);175 if (fd >=0) {161 int fd = open(file, O_RDONLY, 0777); 162 if (fd >= 0) { 176 163 // read header 177 i = read(fd, &f-> uncached_font->hdr, sizeof(structfont_hdr));164 i = read(fd, &f->hdr, sizeof(font_hdr)); 178 165 179 166 // check size read is correct and magic numbers are valid 180 if ((i == sizeof( structfont_hdr)) && (f->hdr.magic1 == RBF_HDR_MAGIC1) && (f->hdr.magic2 == RBF_HDR_MAGIC2)) {167 if ((i == sizeof(font_hdr)) && (f->hdr.magic1 == RBF_HDR_MAGIC1) && (f->hdr.magic2 == RBF_HDR_MAGIC2)) { 181 168 182 169 if (maxchar != 0) { … … 188 175 // read width table (using uncached memory address) 189 176 lseek(fd, f->hdr._wmapAddr, SEEK_SET); 190 read(fd, &f-> uncached_font->wTable[f->hdr.charFirst], f->charCount);177 read(fd, &f->wTable[f->hdr.charFirst], f->charCount); 191 178 192 179 // read cTable data (using uncached memory address) … … 211 198 init_fonts(); 212 199 // Load font 213 return rbf_font_load(file, rbf_font , 0);200 return rbf_font_load(file, rbf_font->uncached_font, 0); 214 201 } 215 202 … … 220 207 init_fonts(); 221 208 // Load font 222 return rbf_font_load(file, rbf_symbol_font , maxSymbols+32);209 return rbf_font_load(file, rbf_symbol_font->uncached_font, maxSymbols+32); 223 210 } 224 211
Note: See TracChangeset
for help on using the changeset viewer.