Changeset 1186


Ignore:
Timestamp:
05/14/11 06:07:33 (2 years ago)
Author:
reyalp
Message:

possible workaround for rbf font bug http://chdk.setepontos.com/index.php?topic=6365 - from philmoz in http://chdk.setepontos.com/index.php?topic=650.msg66601#msg66601

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/font/rbf_font.c

    r1142 r1186  
    1414// Header as seperate structure so it can be directly loaded from the font file easily 
    1515// structure layout maps to file layout - do not change ! 
    16 struct font_hdr { 
    17     int magic1, magic2;        // header magic numbers to identify correct font file 
    18     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 struct font { 
    33     struct font_hdr hdr; 
     16typedef 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 
     32typedef struct _font { 
     33    font_hdr hdr; 
    3434 
    3535    // 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 
    3838 
    3939    // Width table 
     40    // List of character widths. Elements of list is width of char  
    4041    char wTable[256]; 
    4142 
    4243    // Character data 
     44    // List of chars. Element of list is a bytecode string, contains pixels representation of char 
    4345    char *cTable; 
    4446 
     47    // Flag to indicate we are actually using the built in 8x16 font rather than a loaded font 
     48    int usingFont8x16; 
     49 
    4550    // Current size of the cTable data 
    46     int usingFont8x16; 
    4751    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) 
    4953    char *uncached_cTable;            // address of cTable in uncached memory (for passing to ufree & read) 
    50 }; 
    51  
    52 static struct font *rbf_symbol_font = 0, *rbf_font = 0; 
     54} font; 
     55 
     56static font *rbf_symbol_font = 0, *rbf_font = 0; 
    5357static int rbf_codepage = FONT_CP_WIN;  
    5458 
    5559//------------------------------------------------------------------- 
    5660 
    57 struct font *new_font() { 
     61font *new_font() { 
    5862    // allocate font from uncached memory 
    59     struct font *f = umalloc(sizeof(struct font)); 
     63    font *f = umalloc(sizeof(font)); 
    6064    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 address 
     65        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 
    6367        // return address in cached memory for faster font rendering 
    64         return (struct font*)((int)f & ~CAM_UNCACHED_BIT); 
     68        return (font*)((int)f & ~CAM_UNCACHED_BIT); 
    6569    } 
    6670 
     
    7680} 
    7781 
    78 void alloc_cTable(struct font *f) { 
     82void alloc_cTable(font *f) { 
    7983 
    8084    // Calculate additional values for font 
     
    132136//------------------------------------------------------------------- 
    133137// Return address of 'character' data for specified font & char 
    134 char* rbf_font_char(struct font* f, int ch) 
     138char* rbf_font_char(font* f, int ch) 
    135139{ 
    136140    if (f && (ch >= f->hdr.charFirst) && (ch <= f->hdr.charLast)) 
     
    143147//------------------------------------------------------------------- 
    144148// 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 
     150int rbf_font_load(char *file, font* f, int maxchar) 
     151{ 
    165152    int i; 
    166153 
     
    172159 
    173160    // 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) { 
    176163        // read header 
    177         i = read(fd, &f->uncached_font->hdr, sizeof(struct font_hdr)); 
     164        i = read(fd, &f->hdr, sizeof(font_hdr)); 
    178165 
    179166        // check size read is correct and magic numbers are valid 
    180         if ((i == sizeof(struct font_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)) { 
    181168 
    182169            if (maxchar != 0) { 
     
    188175            // read width table (using uncached memory address) 
    189176            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); 
    191178 
    192179            // read cTable data (using uncached memory address) 
     
    211198    init_fonts(); 
    212199    // Load font 
    213     return rbf_font_load(file, rbf_font, 0); 
     200    return rbf_font_load(file, rbf_font->uncached_font, 0); 
    214201} 
    215202 
     
    220207    init_fonts(); 
    221208    // 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); 
    223210} 
    224211 
Note: See TracChangeset for help on using the changeset viewer.