summaryrefslogtreecommitdiffstats
path: root/font.c
diff options
context:
space:
mode:
authordscho <dscho>2001-10-13 15:14:27 +0000
committerdscho <dscho>2001-10-13 15:14:27 +0000
commit9f07e222f828b7b2bf2775b9dc8cd18b22a829c1 (patch)
tree96d8ade36b70799217d3cfd9fb89193c2c1be7a0 /font.c
parentac263ce9aa1561847427b71298861594d8623e61 (diff)
downloadlibvncserver-9f07e222f828b7b2bf2775b9dc8cd18b22a829c1.zip
libvncserver-9f07e222f828b7b2bf2775b9dc8cd18b22a829c1.tar.gz
rfbSelectBox, consoleFonts, too many changes
Diffstat (limited to 'font.c')
-rw-r--r--font.c140
1 files changed, 129 insertions, 11 deletions
diff --git a/font.c b/font.c
index 9356793..53055b4 100644
--- a/font.c
+++ b/font.c
@@ -1,13 +1,17 @@
#include "rfb.h"
int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
- int x,int y,unsigned char c,CARD32 colour)
+ int x,int y,unsigned char c,Pixel col)
{
- int i,j,k,width,height;
+ int i,j,width,height;
unsigned char d;
unsigned char* data=font->data+font->metaData[c*5];
int rowstride=rfbScreen->paddedWidthInBytes;
int bpp=rfbScreen->rfbServerFormat.bitsPerPixel/8;
+ char *colour=(char*)&col;
+
+ if(!rfbEndianTest)
+ colour += 4-bpp;
width=font->metaData[c*5+1];
height=font->metaData[c*5+2];
@@ -20,21 +24,17 @@ int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
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);
- }
+ if(d&0x80)
+ memcpy(rfbScreen->frameBuffer+(y+j)*rowstride+(x+i)*bpp,colour,bpp);
d<<=1;
}
- if((i&7)==0)
- data++;
+ if((i&7)!=0) data++;
}
return(width);
}
void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
- int x,int y,unsigned char* string,CARD32 colour)
+ int x,int y,const unsigned char* string,Pixel colour)
{
while(*string) {
x+=rfbDrawChar(rfbScreen,font,x,y,*string,colour);
@@ -42,7 +42,73 @@ void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
}
}
-int rfbWidth(rfbFontDataPtr font,unsigned char* string)
+/* TODO: these two functions need to be more efficient */
+int rfbDrawCharWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
+ int x,int y,unsigned char c,
+ int x1,int y1,int x2,int y2,
+ Pixel col,Pixel bcol)
+{
+ int i,j,width,height;
+ unsigned char d;
+ unsigned char* data=font->data+font->metaData[c*5];
+ int rowstride=rfbScreen->paddedWidthInBytes;
+ int bpp=rfbScreen->rfbServerFormat.bitsPerPixel/8,extra_bytes=0;
+ char* colour=(char*)&col;
+ char* bcolour=(char*)&bcol;
+
+ if(!rfbEndianTest) {
+ colour+=4-bpp;
+ bcolour+=4-bpp;
+ }
+
+ 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;
+
+ /* after clipping, x2 will be count of bytes between rows,
+ * x1 start of i, y1 start of j, width and height will be adjusted. */
+ if(y1>y) { y1-=y; d+=(width+7)/8; height-=y1; y+=y1; } else y1=0;
+ if(x1>x) { x1-=x; d+=x1; width-=x1; x+=x1; extra_bytes+=x1/8; } else x1=0;
+ if(y2<y+height) height-=y+height-y2;
+ if(x2<x+width) { extra_bytes+=(x1+width)/8-(x+width-x2+7)/8; width-=x+width-x2; }
+
+ for(j=y1;j<height;j++) {
+ for(i=x1;i<width;i++) {
+ if((i&7)==0) {
+ d=*data;
+ data++;
+ }
+ /* if(x+i>=x1 && x+i<x2 && y+j>=y1 && y+j<y2) */ {
+ if(d&0x80) {
+ memcpy(rfbScreen->frameBuffer+(y+j)*rowstride+(x+i)*bpp,
+ colour,bpp);
+ } else if(bcol!=col) {
+ memcpy(rfbScreen->frameBuffer+(y+j)*rowstride+(x+i)*bpp,
+ bcolour,bpp);
+ }
+ }
+ d<<=1;
+ }
+ //if((i&7)==0) data++;
+ data += extra_bytes;
+ }
+ return(width);
+}
+
+void rfbDrawStringWithClip(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
+ int x,int y,const unsigned char* string,
+ int x1,int y1,int x2,int y2,
+ Pixel colour,Pixel backColour)
+{
+ while(*string) {
+ x+=rfbDrawCharWithClip(rfbScreen,font,x,y,*string,x1,y1,x2,y2,
+ colour,backColour);
+ string++;
+ }
+}
+
+int rfbWidthOfString(rfbFontDataPtr font,const unsigned char* string)
{
int i=0;
while(*string) {
@@ -65,3 +131,55 @@ void rfbFontBBox(rfbFontDataPtr font,unsigned char c,int* x1,int* y1,int* x2,int
*y2=*y1+font->metaData[c*5+2];
}
+void rfbWholeFontBBox(rfbFontDataPtr font,
+ int *x1, int *y1, int *x2, int *y2)
+{
+ int i;
+ int* m=font->metaData;
+
+ (*x1)=(*y1)=INT_MAX; (*x2)=(*y2)=-INT_MAX+1;
+ for(i=0;i<256;i++) {
+ if(m[i*5+1]-m[i*5+3]>(*x2))
+ (*x2)=m[i*5+1]-m[i*5+3];
+ if(-m[i*5+2]+m[i*5+4]<(*y1))
+ (*y1)=-m[i*5+2]+m[i*5+4];
+ if(m[i*5+3]<(*x1))
+ (*x1)=m[i*5+3];
+ if(-m[i*5+4]>(*y2))
+ (*y2)=-m[i*5+4];
+ }
+}
+
+rfbFontDataPtr rfbLoadConsoleFont(char *filename)
+{
+ FILE *f=fopen(filename,"rb");
+ rfbFontDataPtr p;
+ int i;
+
+ if(!f) return(0);
+
+ p=(rfbFontDataPtr)malloc(sizeof(rfbFontData));
+ p->data=(char*)malloc(4096);
+ if(1!=fread(p->data,4096,1,f)) {
+ free(p->data);
+ free(p);
+ return(0);
+ }
+ fclose(f);
+ p->metaData=(int*)malloc(256*5*sizeof(int));
+ for(i=0;i<256;i++) {
+ p->metaData[i*5+0]=i*16; /* offset */
+ p->metaData[i*5+1]=8; /* width */
+ p->metaData[i*5+2]=16; /* height */
+ p->metaData[i*5+3]=0; /* xhot */
+ p->metaData[i*5+4]=0; /* yhot */
+ }
+ return(p);
+}
+
+void rfbFreeFont(rfbFontDataPtr f)
+{
+ free(f->data);
+ free(f->metaData);
+ free(f);
+}
OpenPOWER on IntegriCloud