OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [drivers/] [genfont.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 1999, 2000 Greg Haerr <greg@censoft.com>
3
 *
4
 * Screen Driver Utilities
5
 *
6
 * Microwindows Proportional Font Routines (proportional font format)
7
 *
8
 * This file contains the generalized low-level font/text
9
 * drawing routines.  Both fixed and proportional fonts are
10
 * supported, with fixed pitch structure allowing much smaller
11
 * font files.
12
 */
13
#include <stdio.h>
14
#include "device.h"
15
#include "genfont.h"
16
 
17
/* Make compiler happy */
18
#if HAVE_KSC5601_SUPPORT
19
extern unsigned short convert_ksc_to_johab( unsigned char CH, unsigned char CL);
20
extern int      get_han_image(int mc, char *retmap );
21
#endif
22
 
23
/* compiled in fonts*/
24
extern MWCFONT font_rom8x16, font_rom8x8;
25
extern MWCFONT font_winFreeSansSerif11x13;
26
extern MWCFONT font_winFreeSystem14x16;
27
extern MWCFONT font_winSystem14x16;
28
extern MWCFONT font_winMSSansSerif11x13;
29
extern MWCFONT font_winTerminal8x12;
30
extern MWCFONT font_helvB10, font_helvB12, font_helvR10;
31
extern MWCFONT font_X5x7, font_X6x13;
32
 
33
/* handling routines for MWCOREFONT*/
34
static MWFONTPROCS fontprocs = {
35
        MWTF_ASCII,             /* routines expect ascii*/
36
        gen_getfontinfo,
37
        gen_gettextsize,
38
        gen_gettextbits,
39
        gen_unloadfont,
40
        corefont_drawtext,
41
        NULL,                   /* setfontsize*/
42
        NULL,                   /* setfontrotation*/
43
        NULL,                   /* setfontattr*/
44
};
45
 
46
/* first font is default font if no match*/
47
MWCOREFONT gen_fonts[NUMBER_FONTS] = {
48
#if HAVEMSFONTS
49
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR, &font_winSystem14x16},
50
        {&fontprocs, 0, 0, 0, MWFONT_GUI_VAR, &font_winMSSansSerif11x13},
51
        {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, &font_winTerminal8x12},
52
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13}
53
#else
54
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_VAR, &font_winFreeSystem14x16},
55
        {&fontprocs, 0, 0, 0, MWFONT_GUI_VAR, &font_winFreeSansSerif11x13},
56
        {&fontprocs, 0, 0, 0, MWFONT_OEM_FIXED, &font_rom8x16},
57
        {&fontprocs, 0, 0, 0, MWFONT_SYSTEM_FIXED, &font_X6x13}
58
#endif
59
};
60
 
61
/*
62
 * Generalized low level get font info routine.  This
63
 * routine works with fixed and proportional fonts.
64
 */
65
MWBOOL
66
gen_getfontinfo(PMWFONT pfont, PMWFONTINFO pfontinfo)
67
{
68
        PMWCFONT        pf = ((PMWCOREFONT)pfont)->cfont;
69
        int             i;
70
 
71
        pfontinfo->maxwidth = pf->maxwidth;
72
        pfontinfo->height = pf->height;
73
        pfontinfo->baseline = pf->ascent;
74
        pfontinfo->firstchar = pf->firstchar;
75
        pfontinfo->lastchar = pf->firstchar + pf->size - 1;
76
        pfontinfo->fixed = pf->width == NULL? TRUE: FALSE;
77
        for(i=0; i<256; ++i) {
78
                if(pf->width == NULL)
79
                        pfontinfo->widths[i] = pf->maxwidth;
80
                else {
81
                        if(i<pf->firstchar || i >= pf->firstchar+pf->size)
82
                                pfontinfo->widths[i] = 0;
83
                        else pfontinfo->widths[i] = pf->width[i-pf->firstchar];
84
                }
85
        }
86
        return TRUE;
87
}
88
 
89
/*
90
 * Generalized low level routine to calc bounding box for text output.
91
 * Handles both fixed and proportional fonts.  Passed ascii string.
92
 */
93
void
94
gen_gettextsize(PMWFONT pfont, const void *text, int cc,
95
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
96
{
97
        PMWCFONT                pf = ((PMWCOREFONT)pfont)->cfont;
98
        const unsigned char *   str = text;
99
        unsigned int            c;
100
        int                     width;
101
 
102
        if(pf->width == NULL)
103
                width = cc * pf->maxwidth;
104
        else {
105
                width = 0;
106
                while(--cc >= 0) {
107
                        c = *str++;
108
#if HAVE_BIG5_SUPPORT
109
                        /* chinese big5 decoding*/
110
                        if (c >= 0xA1 && c <= 0xF9 && cc >= 1 &&
111
                                ((*str >= 0x40 && *str <= 0x7E) ||
112
                                (*str >= 0xA1 && *str <= 0xFE)) ) {
113
                                        --cc;
114
                                        ++str;
115
                                        width += 12;    /* FIXME*/
116
                        } else
117
#endif
118
#if HAVE_GB2312_SUPPORT
119
                        /* chinese gb2312 decoding*/
120
                        if (c >= 0xA1 && c < 0xF8 && cc >= 1 &&
121
                                *str >= 0xA1 && *str < 0xFF) {
122
                                        --cc;
123
                                        ++str;
124
                                        width += 12;    /* FIXME*/
125
                        } else
126
#endif
127
#if HAVE_KSC5601_SUPPORT
128
                        /* Korean KSC5601 decoding */
129
                        if (c >= 0xA1 && c <= 0xFE && cc >= 1 &&
130
                                (*str >= 0xA1 && *str <= 0xFE)) {
131
                                        --cc;
132
                                        ++str;
133
                                        width += 16;    /* FIXME*/
134
                        } else
135
#endif
136
 
137
                            if(c >= pf->firstchar && c < pf->firstchar+pf->size)
138
                                width += pf->width[c - pf->firstchar];
139
                }
140
        }
141
        *pwidth = width;
142
        *pheight = pf->height;
143
        *pbase = pf->ascent;
144
}
145
 
146
/*
147
 * Generalized low level routine to get the bitmap associated
148
 * with a character.  Handles fixed and proportional fonts.
149
 */
150
void
151
gen_gettextbits(PMWFONT pfont, int ch, MWIMAGEBITS *retmap,
152
        MWCOORD *pwidth, MWCOORD *pheight, MWCOORD *pbase)
153
{
154
        PMWCFONT        pf = ((PMWCOREFONT)pfont)->cfont;
155
        int             n, count, width;
156
        MWIMAGEBITS *   bits;
157
 
158
#if HAVE_BIG5_SUPPORT
159
        /* decode chinese big5*/
160
        int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF;
161
        if (CH >= 0xA1 && CH <= 0xF9 && ((CL >= 0x40 && CL <= 0x7E) || (CL >= 0xA1 && CL <= 0xFE)) )
162
        {
163
            int Pos;    /* != ((CH - 0xA1) * 94 + (CL - 0xA1)) * 18; */
164
 
165
            int i;
166
            extern unsigned char JMT_BIG5_12X12_FONT_BITMAP[];
167
 
168
            int seq;
169
            {
170
                seq=0;
171
                /* ladd=loby-(if(loby<127)?64:98) */
172
                CL/*c2*/-=(CL/*c2*/<127?64:98);
173
 
174
                /* hadd=(hiby-164)*157 */
175
                if (CH/*c1*/>=0xa4)     /* standard font */
176
                {
177
                        seq=(((CH/*c1*/-164)*157)+CL/*c2*/);
178
                        if (seq>=5809) seq-=408;
179
                }
180
 
181
                /* hadd=(hiby-161)*157 */
182
                if (CH/*c1*/<=0xa3)     /* special font */
183
                        seq=(((CH/*c1*/-161)*157)+CL/*c2*/)+13094;
184
            }
185
            Pos=seq*18;
186
 
187
            *pwidth = width = 12;
188
            *pheight = 12;
189
            *pbase = 0;
190
 
191
            for (i = 0; i < 6; i++) {
192
                unsigned char *DstBitmap  = ((unsigned char *)retmap) + i * 4;
193
                unsigned char *FontBitmap = JMT_BIG5_12X12_FONT_BITMAP +
194
                        Pos + i * 3;
195
                DstBitmap[0] = FontBitmap[1];
196
                DstBitmap[1] = FontBitmap[0];
197
                DstBitmap[2] = FontBitmap[1] << 4;
198
                DstBitmap[3] = FontBitmap[2];
199
            }
200
            return;
201
        }
202
#endif /* HAVE_BIG5_SUPPORT*/
203
 
204
#if HAVE_GB2312_SUPPORT
205
        /* decode chinese gb2312*/
206
        int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF;
207
        if (CH >= 0xA1 && CH < 0xF8 && CL >= 0xA1 && CL < 0xFF) {
208
            int Pos = ((CH - 0xA1) * 94 + (CL - 0xA1)) * 18;
209
            int i;
210
            extern unsigned char GUO_GB2312_12X12_FONT_BITMAP[];
211
 
212
            *pwidth = width = 12;
213
            *pheight = 12;
214
            *pbase = 0;
215
 
216
            for (i = 0; i < 6; i++) {
217
                unsigned char *DstBitmap  = ((unsigned char *)retmap) + i * 4;
218
                unsigned char *FontBitmap = GUO_GB2312_12X12_FONT_BITMAP +
219
                        Pos + i * 3;
220
                DstBitmap[0] = FontBitmap[1];
221
                DstBitmap[1] = FontBitmap[0];
222
                DstBitmap[2] = FontBitmap[1] << 4;
223
                DstBitmap[3] = FontBitmap[2];
224
            }
225
            return;
226
        }
227
#endif /* HAVE_GB2312_SUPPORT*/
228
 
229
#if HAVE_KSC5601_SUPPORT
230
        int CH = ((unsigned int)ch) >> 8, CL = ((unsigned int)ch) & 0xFF;
231
        int     mc;
232
 
233
        if ( CH>= 0xA1 &&  CH<= 0xFE && (CL >= 0xA1 && CL <= 0xFE))
234
        {
235
                mc = convert_ksc_to_johab( CH, CL);
236
                if ( mc )
237
                        get_han_image(mc, retmap );
238
 
239
                /* Fix me */
240
                *pwidth = width = 16;
241
                *pheight = 16;
242
                *pbase = 0;
243
                return;
244
        }
245
#endif
246
 
247
        /* if char not in font, map to first character by default*/
248
        if(ch < pf->firstchar || ch >= pf->firstchar+pf->size)
249
                ch = pf->firstchar;
250
 
251
        ch -= pf->firstchar;
252
 
253
        /* get font bitmap depending on fixed pitch or not*/
254
        bits = pf->bits + (pf->offset? pf->offset[ch]: (pf->height * ch));
255
        width = pf->width ? pf->width[ch] : pf->maxwidth;
256
        count = MWIMAGE_WORDS(width) * pf->height;
257
        for(n=0; n<count; ++n)
258
                *retmap++ = *bits++;
259
 
260
        /* return width depending on fixed pitch or not*/
261
        *pwidth = width;
262
        *pheight = pf->height;
263
        *pbase = pf->ascent;
264
}
265
 
266
void
267
gen_unloadfont(PMWFONT pfont)
268
{
269
        /* builtins can't be unloaded*/
270
}
271
 
272
#if NOTUSED
273
/*
274
 * Generalized low level text draw routine, called only
275
 * if no clipping is required
276
 */
277
void
278
gen_drawtext(PMWFONT pfont,PSD psd,MWCOORD x,MWCOORD y,const void *text,
279
        int n,MWPIXELVAL fg)
280
{
281
        PMWCFONT                pf = ((PMWCOREFONT)pfont)->cfont;
282
        const unsigned char *   str = text;
283
        MWCOORD                 width;          /* width of character */
284
        MWCOORD                 height;         /* height of character */
285
        IMAGEBITS   bitmap[MAX_CHAR_HEIGHT*MAX_CHAR_WIDTH/MWIMAGE_BITSPERIMAGE];
286
 
287
        /* x, y is bottom left corner*/
288
        y -= pf->height - 1;
289
        while (n-- > 0) {
290
                pfont->GetTextBits(pfont, *s++, bitmap, &width, &height);
291
                gen_drawbitmap(psd, x, y, width, height, bitmap, fg);
292
                x += width;
293
        }
294
}
295
 
296
/*
297
 * Generalized low level bitmap output routine, called
298
 * only if no clipping is required.  Only the set bits
299
 * in the bitmap are drawn, in the foreground color.
300
 */
301
void
302
gen_drawbitmap(PSD psd,MWCOORD x, MWCOORD y, MWCOORD width, MWCOORD height,
303
        MWIMAGEBITS *table, PIXELVAL fgcolor)
304
{
305
  MWCOORD minx;
306
  MWCOORD maxx;
307
  MWIMAGEBITS bitvalue; /* bitmap word value */
308
  int bitcount;                 /* number of bits left in bitmap word */
309
 
310
  minx = x;
311
  maxx = x + width - 1;
312
  bitcount = 0;
313
  while (height > 0) {
314
        if (bitcount <= 0) {
315
                bitcount = MWIMAGE_BITSPERIMAGE;
316
                bitvalue = *table++;
317
        }
318
        if (MWIMAGE_TESTBIT(bitvalue))
319
                psd->DrawPixel(psd, x, y, fgcolor);
320
        bitvalue = MWIMAGE_SHIFTBIT(bitvalue);
321
        --bitcount;
322
        if (x++ == maxx) {
323
                x = minx;
324
                ++y;
325
                --height;
326
                bitcount = 0;
327
        }
328
  }
329
}
330
#endif /* NOTUSED*/

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.