1 /*
2 * Abuse - dark 2D side-scrolling platform game
3 * Copyright (c) 1995 Crack dot Com
4 * Copyright (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
5 *
6 * This software was released into the Public Domain. As with most public
7 * domain software, no warranty is made or implied by Crack dot Com, by
8 * Jonathan Clark, or by Sam Hocevar.
9 */
10
11 #if defined HAVE_CONFIG_H
12 # include "config.h"
13 #endif
14
15 #include <ctype.h>
16
17 #include "common.h"
18
19 #include "fonts.h"
20
texture_font(image * letters,image * font_pattern)21 texture_font::texture_font(image *letters, image *font_pattern)
22 { fntpat=font_pattern;
23 let=letters;
24 tl=(let->Size().x+1)/32;
25 th=(let->Size().y+1)/8;
26 }
27
put_char(image * screen,int x,int y,char ch)28 void texture_font::put_char(image *screen, int x, int y, char ch)
29 { if (fntpat)
30 fntpat->put_part_masked(screen,let, x,y,
31 ((int)ch%32)*tl,((int)ch/32)*th,0,0,tl-1,th-1);
32 else let->put_part(screen,x,y,((int)ch%32)*tl,((int)ch/32)*th,
33 ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
34 }
35
put_string(image * screen,int x,int y,char const * st)36 void texture_font::put_string(image *screen, int x, int y, char const *st)
37 { while (*st)
38 { put_char(screen,x,y,*st);
39 st++;
40 x+=tl;
41 }
42 }
43
44
put_string(image * screen,int x,int y,char const * st,int color)45 void JCFont::put_string(image *screen, int x, int y, char const *st, int color)
46 { while (*st)
47 { put_char(screen,x,y,*st,color);
48 st++;
49 x+=tl;
50 }
51 }
52
53
put_char(image * screen,int x,int y,char ch,int color)54 void JCFont::put_char(image *screen, int x, int y, char ch, int color)
55 {
56 if (let[(int)ch])
57 {
58 if (color>=0)
59 let[(int)ch]->PutColor(screen,vec2i(x,y),color);
60 else let[(int)ch]->PutImage(screen,vec2i(x,y));
61 }
62 }
63
JCFont(image * letters)64 JCFont::JCFont(image *letters)
65 {
66 tl=(letters->Size().x+1)/32;
67 th=(letters->Size().y+1)/8;
68
69 image tmp(vec2i(tl,th));
70
71 int ch;
72
73 for (ch=0; ch<256; ch++)
74 {
75 tmp.clear();
76 letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
77 ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
78 let[ch]=new TransImage(&tmp,"JCfont");
79 }
80 }
81
~JCFont()82 JCFont::~JCFont()
83 {
84 int ch;
85 for (ch=0; ch<256; ch++)
86 delete let[ch];
87 }
88
89