summaryrefslogtreecommitdiffstats
path: root/font.c
blob: 9356793a64efb4bc4726bfbec0e8025e50436fc5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include "rfb.h"

int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
		 int x,int y,unsigned char c,CARD32 colour)
{
  int i,j,k,width,height;
  unsigned char d;
  unsigned char* data=font->data+font->metaData[c*5];
  int rowstride=rfbScreen->paddedWidthInBytes;
  int bpp=rfbScreen->rfbServerFormat.bitsPerPixel/8;

  width=font->metaData[c*5+1];
  height=font->metaData[c*5+2];
  x+=font->metaData[c*5+3];
  y+=-font->metaData[c*5+4]-height+1;

  for(j=0;j<height;j++) {
    for(i=0;i<width;i++) {
      if((i&7)==0) {
	d=*data;
	data++;
      }
      if(d&0x80) {
	for(k=0;k<bpp;k++)
	  rfbScreen->frameBuffer[(y+j)*rowstride+(x+i)*bpp+k]=
	    ((colour>>(8*k))&0xff);
      }
      d<<=1;
    }
    if((i&7)==0)
      data++;
  }
  return(width);
}

void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
		   int x,int y,unsigned char* string,CARD32 colour)
{
  while(*string) {
    x+=rfbDrawChar(rfbScreen,font,x,y,*string,colour);
    string++;
  }
}

int rfbWidth(rfbFontDataPtr font,unsigned char* string)
{
  int i=0;
  while(*string) {
    i+=font->metaData[*string*5+1];
    string++;
  }
  return(i);
}

int rfbWidthOfChar(rfbFontDataPtr font,unsigned char c)
{
  return(font->metaData[c*5+1]+font->metaData[c*5+3]);
}

void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int* y2)
{
  *x1+=font->metaData[c*5+3];
  *y1+=-font->metaData[c*5+4]-font->metaData[c*5+2]+1;
  *x2=*x1+font->metaData[c*5+1];
  *y2=*y1+font->metaData[c*5+2];
}