Commit 8f407f8a authored by dscho's avatar dscho

extracted font routines from example

parent 48eb9b22
......@@ -23,11 +23,11 @@ OSX_LIBS = -framework ApplicationServices -framework Carbon
SOURCES=main.c rfbserver.c sraRegion.c auth.c sockets.c \
stats.c corre.c hextile.c rre.c translate.c cutpaste.c \
zlib.c tight.c httpd.c cursor.o \
zlib.c tight.c httpd.c cursor.c font.c \
d3des.c vncauth.c
OBJS=main.o rfbserver.o sraRegion.o auth.o sockets.o \
stats.o corre.o hextile.o rre.o translate.o cutpaste.o \
zlib.o tight.o httpd.o cursor.o \
zlib.o tight.o httpd.o cursor.o font.o \
d3des.o vncauth.o
all: example pnmshow storepasswd
......
......@@ -7,13 +7,16 @@ for($i=0;$i<256*5;$i++) {
$out="";
$counter=0;
$fontname="default";
$i=0;
$searchfor="";
$nullx="0x";
while(<>) {
if(/^ENCODING (.*)$/) {
if(/^FONT (.*)$/) {
$fontname=$1;
} elsif(/^ENCODING (.*)$/) {
$glyphindex=$1;
$searchfor="BBX";
} elsif(/^BBX (.*) (.*) (.*) (.*)$/) {
......@@ -36,9 +39,10 @@ while(<>) {
}
}
print "unsigned char bdffontdata[$counter]={\n" . $out;
print "};\nint bdffontmetadata[256*5]={\n";
print "unsigned char " . $fontname . "FontData[$counter]={\n" . $out;
print "};\nint " . $fontname . "FontMetaData[256*5]={\n";
for($i=0;$i<256*5;$i++) {
print $encodings[$i] . ",";
}
print "};\n";
print "};\nrfbFontData " . $fontname . "Font={" .
$fontname . "FontData, " . $fontname . "FontMetaData};\n";
......@@ -139,59 +139,6 @@ void doptr(int buttonMask,int x,int y,rfbClientPtr cl)
/* aux function to draw a character to x, y */
#include "radon.h"
int drawchar(unsigned char* buffer,int rowstride,int bpp,int x,int y,char c)
{
int i,j,k,width,height;
unsigned char d;
unsigned char* data=bdffontdata+bdffontmetadata[c*5];
width=bdffontmetadata[c*5+1];
height=bdffontmetadata[c*5+2];
x+=bdffontmetadata[c*5+3];
y+=bdffontmetadata[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++)
buffer[(y+j)*rowstride+(x+i)*bpp+k]=0xff;
}
d<<=1;
}
if((i&7)==0)
data++;
}
return(width);
}
void drawstring(unsigned char* buffer,int rowstride,int bpp,int x,int y,char* string)
{
while(*string) {
x+=drawchar(buffer,rowstride,bpp,x,y,*string);
string++;
}
}
int bdflength(char* string)
{
int i;
while(*string) {
i+=bdffontmetadata[*string*5+1];
string++;
}
return(i);
}
void bdfbbox(char c,int* x1,int* y1,int* x2,int* y2)
{
*x1+=bdffontmetadata[c*5+3];
*y1+=bdffontmetadata[c*5+4]-bdffontmetadata[c*5+2]+1;
*x2=*x1+bdffontmetadata[c*5+1];
*y2=*y1+bdffontmetadata[c*5+2];
}
/* Here the key events are handled */
......@@ -210,10 +157,8 @@ void dokey(Bool down,KeySym key,rfbClientPtr cl)
int x1=cd->oldx,y1=cd->oldy,x2,y2;
if(cl->screen->cursorIsDrawn)
rfbUndrawCursor(cl);
cd->oldx+=drawchar(cl->screen->frameBuffer,
cl->screen->paddedWidthInBytes,bpp,cd->oldx,cd->oldy,
key);
bdfbbox(key,&x1,&y1,&x2,&y2);
cd->oldx+=rfbDrawChar(cl->screen,&radonFont,cd->oldx,cd->oldy,key,0xffffff);
rfbFontBBox(&radonFont,key,&x1,&y1,&x2,&y2);
rfbMarkRectAsModified(cl->screen,x1,y1,x2-1,y2-1);
}
}
......@@ -299,7 +244,7 @@ int main(int argc,char** argv)
rfbScreen->httpDir = "./classes";
initBuffer(rfbScreen->frameBuffer);
drawstring(rfbScreen->frameBuffer,maxx*bpp,bpp,20,100,"Hello, World!");
rfbDrawString(rfbScreen,&radonFont,20,100,"Hello, World!",0xffffff);
/* This call creates a mask and then a cursor: */
/* rfbScreen->defaultCursor =
......
#include "rfb.h"
int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
int x,int y,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*bpp))&0xff);
}
d<<=1;
}
if((i&7)==0)
data++;
}
return(width);
}
void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,
int x,int y,char* string,CARD32 colour)
{
while(*string) {
x+=rfbDrawChar(rfbScreen,font,x,y,*string,colour);
string++;
}
}
int rfbWidth(rfbFontDataPtr font,char* string)
{
int i=0;
while(*string) {
i+=font->metaData[*string*5+1];
string++;
}
return(i);
}
void rfbFontBBox(rfbFontDataPtr font,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];
}
unsigned char bdffontdata[4560]={
unsigned char radonFontData[4560]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 32 */
0x00,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x10,0x00,0x10,0x00,0x00,0x00,0x00,0x00, /* 33 */
0x00,0x00,0x28,0x00,0x28,0x00,0x28,0x00,0x28,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 34 */
......@@ -190,5 +190,6 @@ unsigned char bdffontdata[4560]={
0x04,0x00,0x18,0x00,0x00,0x00,0x00,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x42,0x00,0x3a,0x00,0x02,0x00,0x3c,0x00, /* 253 */
0x00,0x00,0x80,0x00,0x80,0x00,0x9c,0x00,0xa2,0x00,0x82,0x00,0xa2,0x00,0x9c,0x00,0x80,0x00,0x80,0x00,0x00,0x00,0x00,0x00, /* 254 */
};
int bdffontmetadata[256*5]={
int radonFontMetaData[256*5]={
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,12,0,-2,24,8,12,0,-2,48,8,12,0,-2,72,8,12,0,-2,96,8,12,0,-2,120,8,12,0,-2,144,8,12,0,-2,168,8,12,0,-2,192,8,12,0,-2,216,8,12,0,-2,240,8,12,0,-2,264,8,12,0,-2,288,8,12,0,-2,312,8,12,0,-2,336,8,12,0,-2,360,8,12,0,-2,384,8,12,0,-2,408,8,12,0,-2,432,8,12,0,-2,456,8,12,0,-2,480,8,12,0,-2,504,8,12,0,-2,528,8,12,0,-2,552,8,12,0,-2,576,8,12,0,-2,600,8,12,0,-2,624,8,12,0,-2,648,8,12,0,-2,672,8,12,0,-2,696,8,12,0,-2,720,8,12,0,-2,744,8,12,0,-2,768,8,12,0,-2,792,8,12,0,-2,816,8,12,0,-2,840,8,12,0,-2,864,8,12,0,-2,888,8,12,0,-2,912,8,12,0,-2,936,8,12,0,-2,960,8,12,0,-2,984,8,12,0,-2,1008,8,12,0,-2,1032,8,12,0,-2,1056,8,12,0,-2,1080,8,12,0,-2,1104,8,12,0,-2,1128,8,12,0,-2,1152,8,12,0,-2,1176,8,12,0,-2,1200,8,12,0,-2,1224,8,12,0,-2,1248,8,12,0,-2,1272,8,12,0,-2,1296,8,12,0,-2,1320,8,12,0,-2,1344,8,12,0,-2,1368,8,12,0,-2,1392,8,12,0,-2,1416,8,12,0,-2,1440,8,12,0,-2,1464,8,12,0,-2,1488,8,12,0,-2,1512,8,12,0,-2,1536,8,12,0,-2,1560,8,12,0,-2,1584,8,12,0,-2,1608,8,12,0,-2,1632,8,12,0,-2,1656,8,12,0,-2,1680,8,12,0,-2,1704,8,12,0,-2,1728,8,12,0,-2,1752,8,12,0,-2,1776,8,12,0,-2,1800,8,12,0,-2,1824,8,12,0,-2,1848,8,12,0,-2,1872,8,12,0,-2,1896,8,12,0,-2,1920,8,12,0,-2,1944,8,12,0,-2,1968,8,12,0,-2,1992,8,12,0,-2,2016,8,12,0,-2,2040,8,12,0,-2,2064,8,12,0,-2,2088,8,12,0,-2,2112,8,12,0,-2,2136,8,12,0,-2,2160,8,12,0,-2,2184,8,12,0,-2,2208,8,12,0,-2,2232,8,12,0,-2,2256,8,12,0,-2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2280,8,12,0,-2,2304,8,12,0,-2,2328,8,12,0,-2,2352,8,12,0,-2,2376,8,12,0,-2,2400,8,12,0,-2,2424,8,12,0,-2,2448,8,12,0,-2,2472,8,12,0,-2,2496,8,12,0,-2,2520,8,12,0,-2,2544,8,12,0,-2,2568,8,12,0,-2,2592,8,12,0,-2,2616,8,12,0,-2,2640,8,12,0,-2,2664,8,12,0,-2,2688,8,12,0,-2,2712,8,12,0,-2,2736,8,12,0,-2,2760,8,12,0,-2,2784,8,12,0,-2,2808,8,12,0,-2,2832,8,12,0,-2,2856,8,12,0,-2,2880,8,12,0,-2,2904,8,12,0,-2,2928,8,12,0,-2,2952,8,12,0,-2,2976,8,12,0,-2,3000,8,12,0,-2,3024,8,12,0,-2,3048,8,12,0,-2,3072,8,12,0,-2,3096,8,12,0,-2,3120,8,12,0,-2,3144,8,12,0,-2,3168,8,12,0,-2,3192,8,12,0,-2,3216,8,12,0,-2,3240,8,12,0,-2,3264,8,12,0,-2,3288,8,12,0,-2,3312,8,12,0,-2,3336,8,12,0,-2,3360,8,12,0,-2,3384,8,12,0,-2,3408,8,12,0,-2,3432,8,12,0,-2,3456,8,12,0,-2,3480,8,12,0,-2,3504,8,12,0,-2,3528,8,12,0,-2,3552,8,12,0,-2,3576,8,12,0,-2,3600,8,12,0,-2,3624,8,12,0,-2,3648,8,12,0,-2,3672,8,12,0,-2,3696,8,12,0,-2,3720,8,12,0,-2,3744,8,12,0,-2,3768,8,12,0,-2,3792,8,12,0,-2,3816,8,12,0,-2,3840,8,12,0,-2,3864,8,12,0,-2,3888,8,12,0,-2,3912,8,12,0,-2,3936,8,12,0,-2,3960,8,12,0,-2,3984,8,12,0,-2,4008,8,12,0,-2,4032,8,12,0,-2,4056,8,12,0,-2,4080,8,12,0,-2,4104,8,12,0,-2,4128,8,12,0,-2,4152,8,12,0,-2,4176,8,12,0,-2,4200,8,12,0,-2,4224,8,12,0,-2,4248,8,12,0,-2,4272,8,12,0,-2,4296,8,12,0,-2,4320,8,12,0,-2,4344,8,12,0,-2,4368,8,12,0,-2,4392,8,12,0,-2,4416,8,12,0,-2,4440,8,12,0,-2,4464,8,12,0,-2,4488,8,12,0,-2,4512,8,12,0,-2,4536,8,12,0,-2,0,0,0,0,0,};
rfbFontData radonFont = { radonFontData, radonFontMetaData };
......@@ -679,9 +679,30 @@ extern void defaultPtrAddEvent(int buttonMask,int x,int y,rfbClientPtr cl);
extern void rfbResetStats(rfbClientPtr cl);
extern void rfbPrintStats(rfbClientPtr cl);
/* socket.c */
extern void rfbInitSockets(rfbScreenInfoPtr rfbScreen);
extern void rfbDisconnectUDPSock(rfbScreenInfoPtr cl);
/* font.c */
typedef struct rfbFontData {
char* data;
/*
metaData is a 256*5 array:
for each character
(offset,width,height,x,y)
*/
int* metaData;
} rfbFontData,* rfbFontDataPtr;
int rfbDrawChar(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,char c,CARD32 colour);
void rfbDrawString(rfbScreenInfoPtr rfbScreen,rfbFontDataPtr font,int x,int y,char* string,CARD32 colour);
int rfbWidth(rfbFontDataPtr font,char* string);
void rfbFontBBox(rfbFontDataPtr font,char c,int* x1,int* y1,int* x2,int* y2);
/* main.c */
void rfbMarkRectAsModified(rfbScreenInfoPtr rfbScreen,int x1,int y1,int x2,int y2);
void rfbMarkRegionAsModified(rfbScreenInfoPtr rfbScreen,sraRegionPtr modRegion);
void doNothingWithClient(rfbClientPtr cl);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment