00001
00002
00003
00004
00005 #include "common.h"
00006 #include "memgfx.h"
00007 #include "gemfont.h"
00008
00009 static char const rcsid[] = "$Id: gemfont.c,v 1.9 2006/06/20 18:17:38 hiram Exp $";
00010
00011 typedef union
00012 {
00013 int theInt;
00014 char bytes[2];
00015 } myInt;
00016
00017 void gfText(struct memGfx *screen, struct font_hdr *f, char *text,
00018 int x, int y, Color color, TextBlit tblit, Color bcolor)
00019 {
00020 UBYTE *s = (UBYTE*)text;
00021 UBYTE *ss;
00022 int c, lo, hi;
00023 int sx, imageWid;
00024 WORD *off, wd, ht;
00025 UBYTE *data;
00026 myInt *OWtab, *iPtr;
00027 int missChar;
00028 int font_type;
00029 int extraWidth = f->lft_ofst + f->rgt_ofst;
00030
00031 x += f->xOff;
00032 y += f->yOff;
00033 x += f->lft_ofst;
00034 lo = f->ADE_lo;
00035 hi = f->ADE_hi;
00036 off = f->ch_ofst;
00037 wd = f->frm_wdt;
00038 ht = f->frm_hgt,
00039 data = f->fnt_dta;
00040 OWtab= (myInt *)(f->hz_ofst);
00041 font_type = f->id;
00042
00043 while ((c = *s++)!=0)
00044 {
00045
00046 if (c > hi)
00047 {
00048 c = ' ';
00049 }
00050 c -= lo;
00051 if (c < 0)
00052 {
00053 c = ' ' - lo;
00054 }
00055
00056
00057 if (font_type == MPROP && (*(OWtab+c)).theInt == -1)
00058 {
00059 c=hi-lo;
00060 missChar=1;
00061 sx = off[c+1];
00062 imageWid= f->frm_wdt*8 - sx;
00063 }
00064 else
00065 {
00066 missChar=0;
00067 sx = off[c];
00068 imageWid = off[c+1]-sx;
00069 }
00070 (*tblit)(imageWid, ht, sx, 0, data, wd, screen, x, y, color, bcolor);
00071 switch (font_type)
00072 {
00073 case STPROP:
00074 x += imageWid + extraWidth;
00075 break;
00076 case MFIXED:
00077 x += f->wchr_wdt + extraWidth;
00078 break;
00079 case MPROP:
00080 iPtr=OWtab+c;
00081 if (!missChar)
00082
00083 {
00084 x += (int)((*iPtr).bytes[1]);
00085 ss=s;
00086 if ((c=*(ss++)) != 0)
00087
00088 {
00089 c-= lo;
00090 iPtr=OWtab+c;
00091
00092
00093 if ((*iPtr).theInt!=-1)
00094 x += (int)((*iPtr).bytes[0])+ f->rgt_ofst;
00095 }
00096 }
00097 else
00098 x+=imageWid + extraWidth;
00099 break;
00100 }
00101 }
00102 }
00103
00104 static int fchar_width(struct font_hdr *f,unsigned char *s)
00105
00106 {
00107 int c;
00108 signed char *offsets;
00109 int width;
00110 int t;
00111
00112 c = *s++;
00113 if (c > f->ADE_hi)
00114 c = ' ';
00115 c -= f->ADE_lo;
00116 if (c < 0)
00117 {
00118 c = ' ' - f->ADE_lo;
00119 }
00120 switch (f->id)
00121 {
00122 case MFIXED:
00123 return(f->wchr_wdt + f->lft_ofst + f->rgt_ofst);
00124 case STPROP:
00125 return(f->ch_ofst[c+1] - f->ch_ofst[c] + f->lft_ofst + f->rgt_ofst);
00126 case MPROP:
00127 offsets = f->hz_ofst+c*2;
00128 if (offsets[0] == -1 && offsets[1] == -1)
00129 {
00130 t = f->ADE_hi - f->ADE_lo;
00131 return( f->frm_wdt*8 - f->ch_ofst[t+1]);
00132 }
00133 else
00134 {
00135 width = offsets[1];
00136 if ((c = *s++) != 0)
00137 {
00138 c -= f->ADE_lo;
00139 offsets = f->hz_ofst+c*2;
00140 width += offsets[0] + f->rgt_ofst;
00141 }
00142 return(width);
00143 }
00144 default:
00145 internalErr();
00146 return 0;
00147 }
00148 }
00149
00150 long fnstring_width(struct font_hdr *f, unsigned char *s, int n)
00151 {
00152 long acc = 0;
00153
00154 while (--n >= 0)
00155 {
00156 acc += fchar_width(f, s);
00157 s++;
00158 }
00159 return(acc);
00160 }
00161
00162 #if 0
00163 static long fstring_width(struct font_hdr *f, unsigned char *s)
00164 {
00165 return(fnstring_width(f, s, strlen((char *)s)));
00166 }
00167 #endif
00168
00169
00170 int fwidest_char(struct font_hdr *f)
00171 {
00172 unsigned char buf[2];
00173 int i;
00174 int c;
00175 int widest = 1;
00176 int w;
00177
00178 c = f->ADE_lo;
00179 i = f->ADE_hi - c;
00180 buf[1] = 0;
00181 while (--i >= 0)
00182 {
00183 buf[0] = c++;
00184 w = fchar_width(f, buf);
00185 if (w > widest)
00186 widest = w;
00187 }
00188 return(widest);
00189 }
00190
00191 int font_cel_height(struct font_hdr *f)
00192 {
00193 int dy;
00194
00195 dy = f->frm_hgt;
00196 return(dy);
00197 }
00198