1 /*
2 
3 Copyright (C) 2015-2018 Night Dive Studios, LLC.
4 Copyright (C) 2018-2020 Shockolate Project
5 
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15 
16 You should have received a copy of the GNU General Public License
17 along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 
19 */
20 /*
21  * $Source: n:/project/lib/src/2d/RCS/genchr.c $
22  * $Revision: 1.6 $
23  * $Author: lmfeeney $
24  * $Date: 1994/06/15 01:20:11 $
25  *
26  * Generic clipped character drawer.
27  *
28  * This file is part of the 2d library.
29  *
30  * $Log: genchr.c $
31  * Revision 1.6  1994/06/15  01:20:11  lmfeeney
32  * support extended ascii (c > 127) w\ uchars, don't change fn i\f
33  *
34  * Revision 1.5  1994/04/09  07:20:12  lmfeeney
35  * routine takes grs_font * as first arg, #define for compatibility in
36  * str.h
37  *
38  * Revision 1.4  1993/10/19  09:57:52  kaboom
39  * Replaced #include   new headers.
40  *
41  * Revision 1.3  1993/10/02  01:17:16  kaboom
42  * Changed include of clip.h to include of clpcon.h and/or clpfcn.h.
43  *
44  * Revision 1.2  1993/04/29  18:40:17  kaboom
45  * Changed include of gr.h to smaller more specific grxxx.h.
46  *
47  * Revision 1.1  1993/04/08  18:54:36  kaboom
48  * Initial revision
49  */
50 
51 #include "bitmap.h"
52 #include "clpcon.h"
53 #include "grdbm.h"
54 
55 /* draw a clipped character c from the specified font at (x,y). */
56 
gen_font_char(grs_font * f,char c,short x,short y)57 int gen_font_char(grs_font *f, char c, short x, short y) {
58     grs_bitmap bm;   /* character bitmap */
59     short *off_tab;  /* character offset table */
60     uchar *data_buf; /* pixel data buffer */
61     short offset;    /* current character offset */
62 
63     /* range check char, get font table pointers, offset. */
64     if ((uchar)c > f->max || (uchar)c < f->min)
65         return CLIP_ALL;
66     data_buf = (uchar *)f + f->buf;
67     off_tab = f->off_tab;
68     offset = off_tab[(uchar)c - f->min];
69     gr_init_bm(&bm, NULL, (f->id == 0xcccc) ? BMT_FLAT8 : BMT_MONO,
70         BMF_TRANS, off_tab[(uchar)c - f->min + 1] - offset, f->h);
71     bm.row = f->w;
72     /* draw the character with clipping. */
73     if (bm.type == BMT_MONO) {
74         bm.bits = data_buf + (offset >> 3);
75         bm.align = offset & 7;
76         return gr_mono_bitmap(&bm, x, y);
77     } else {
78         bm.bits = data_buf + offset;
79         return gr_flat8_bitmap(&bm, x, y);
80     }
81 }
82