source: abuse/tags/pd/macabuse/imlib/fonts.c @ 604

Last change on this file since 604 was 49, checked in by Sam Hocevar, 15 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.6 KB
RevLine 
[49]1#include "fonts.hpp"
2#include <ctype.h>
3
4texture_font::texture_font(image *letters, image *font_pattern)
5{ fntpat=font_pattern;
6  let=letters;
7  tl=(let->width()+1)/32;
8  th=(let->height()+1)/8;
9}
10
11void texture_font::put_char(image *screen,  int x, int y, char ch)
12{ if (fntpat)
13    fntpat->put_part_masked(screen,let, x,y,
14       ((int)ch%32)*tl,((int)ch/32)*th,0,0,tl-1,th-1);
15  else let->put_part(screen,x,y,((int)ch%32)*tl,((int)ch/32)*th,
16     ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1);
17}
18
19void texture_font::put_string(image *screen, int x, int y, char *st)
20{ while (*st)
21  { put_char(screen,x,y,*st);
22    st++;
23    x+=tl;
24  }
25}
26
27
28void JCFont::put_string(image *screen, int x, int y, char *st, int color)
29{ while (*st)
30  { put_char(screen,x,y,*st,color);
31    st++;
32    x+=tl;
33  }
34}
35
36
37void JCFont::put_char(image *screen,  int x, int y, char ch, int color)
38{
39  if (let[(unsigned char)ch])
40  {
41    if (color>=0)
42      let[(unsigned char)ch]->put_color(screen,x,y,color);
43    else let[(unsigned char)ch]->put_image(screen,x,y);
44  }
45}
46
47JCFont::JCFont(image *letters)
48{
49  tl=(letters->width()+1)/32;
50  th=(letters->height()+1)/8;   
51
52  image tmp(tl,th);
53 
54  int ch;
55 
56  for (ch=0;ch<256;ch++)
57  {   
58    if (ch>' ' && ch<'~')
59    {
60      tmp.clear();   
61      letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
62          ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1); 
63      let[ch]=new trans_image(&tmp,"JCfont");
64    } else let[ch]=0;
65  }
66}
67
68JCFont::~JCFont()
69{
70  int ch;
71  for (ch=0;ch<256;ch++) 
72    if (let[(unsigned char)ch])
73      delete let[(unsigned char)ch]; 
74}
75
Note: See TracBrowser for help on using the repository browser.