source: abuse/tags/pd/imlib/fonts.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 12 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.4 KB
Line 
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[ch])
40  {
41    if (color>=0)
42      let[ch]->put_color(screen,x,y,color);
43    else let[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    tmp.clear();   
59    letters->put_part(&tmp,0,0,((int)ch%32)*tl,((int)ch/32)*th,
60                      ((int)ch%32)*tl+tl-1,((int)ch/32)*th+th-1,1); 
61    let[ch]=new trans_image(&tmp,"JCfont");
62  }
63}
64
65JCFont::~JCFont()
66{
67  int ch;
68  for (ch=0;ch<256;ch++) 
69    delete let[ch]; 
70}
71
Note: See TracBrowser for help on using the repository browser.