From 5842e4cdb2c7bed9e7dfccd27e95773b23652378 Mon Sep 17 00:00:00 2001 From: svenhoefer Date: Tue, 14 Aug 2012 22:13:58 +0200 Subject: [PATCH 1/1] * initial commit --- gfx.c | 97 ++++++ gfx.h | 7 + io.c | 77 +++++ io.h | 11 + msgbox.c | 956 +++++++++++++++++++++++++++++++++++++++++++++++++++++ msgbox.h | 136 ++++++++ msgbox.txt | 8 + text.c | 272 +++++++++++++++ text.h | 12 + txtform.c | 108 ++++++ txtform.h | 7 + 11 files changed, 1691 insertions(+) create mode 100644 gfx.c create mode 100644 gfx.h create mode 100644 io.c create mode 100644 io.h create mode 100644 msgbox.c create mode 100644 msgbox.h create mode 100644 msgbox.txt create mode 100644 text.c create mode 100644 text.h create mode 100644 txtform.c create mode 100644 txtform.h diff --git a/gfx.c b/gfx.c new file mode 100644 index 0000000..e1fae21 --- /dev/null +++ b/gfx.c @@ -0,0 +1,97 @@ +#include "msgbox.h" + +void RenderBox(int sx, int sy, int ex, int ey, int rad, int col) +{ + int F,R=rad,ssx=startx+sx,ssy=starty+sy,dxx=ex-sx,dyy=ey-sy,rx,ry,wx,wy,count; + + unsigned char *pos=(lbb+(ssx<<2)+fix_screeninfo.line_length*ssy); + unsigned char *pos0, *pos1, *pos2, *pos3, *i; + unsigned char pix[4]={bl[col],gn[col],rd[col],tr[col]}; + + if (dxx<0) + { + printf("[shellexec] RenderBox called with dx < 0 (%d)\n", dxx); + dxx=0; + } + + if(R) + { + if(--dyy<=0) + { + dyy=1; + } + + if(R==1 || R>(dxx/2) || R>(dyy/2)) + { + R=dxx/10; + F=dyy/10; + if(R>F) + { + if(R>(dyy/3)) + { + R=dyy/3; + } + } + else + { + R=F; + if(R>(dxx/3)) + { + R=dxx/3; + } + } + } + ssx=0; + ssy=R; + F=1-R; + + rx=R-ssx; + ry=R-ssy; + + pos0=pos+((dyy-ry)*fix_screeninfo.line_length); + pos1=pos+(ry*fix_screeninfo.line_length); + pos2=pos+(rx*fix_screeninfo.line_length); + pos3=pos+((dyy-rx)*fix_screeninfo.line_length); + while (ssx <= ssy) + { + rx=R-ssx; + ry=R-ssy; + wx=rx<<1; + wy=ry<<1; + + for(i=pos0+(rx<<2); i +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "io.h" + +#define RC_DEVICE "/dev/input/nevis_ir" + +extern int instance; +struct input_event ev; +static unsigned short rccode=-1; +static int rc; + +int InitRC(void) +{ + rc = open(RC_DEVICE, O_RDONLY); + if(rc == -1) + { + perror("msgbox "); + exit(1); + } + fcntl(rc, F_SETFL, O_NONBLOCK | O_SYNC); + while(RCKeyPressed()); + return 1; +} + +int CloseRC(void) +{ + while(RCKeyPressed()); + close(rc); + return 1; +} + +int RCKeyPressed(void) +{ + if(read(rc, &ev, sizeof(ev)) == sizeof(ev)) + { + if(ev.value) + { + rccode=ev.code; + return 1; + } + } + rccode = -1; + return 0; +} + + +int GetRCCode(void) +{ + int rv; + + if(!RCKeyPressed() || (get_instance()>instance)) + { + return -1; + } + rv=rccode; + while(RCKeyPressed()); + + return rv; +} + + diff --git a/io.h b/io.h new file mode 100644 index 0000000..d7914d4 --- /dev/null +++ b/io.h @@ -0,0 +1,11 @@ +#ifndef __IO_H__ + +#define __IO_H__ + +#define RC_DEVICE "/dev/input/nevis_ir" + +int InitRC(void); +int CloseRC(void); +int RCKeyPressed(void); + +#endif diff --git a/msgbox.c b/msgbox.c new file mode 100644 index 0000000..a9370e7 --- /dev/null +++ b/msgbox.c @@ -0,0 +1,956 @@ +#include +#include +#include +#include +#include "msgbox.h" +#include "text.h" +#include "io.h" +#include "gfx.h" +#include "txtform.h" + +#define M_VERSION 1.11 + +#define NCF_FILE "/var/tuxbox/config/neutrino.conf" +#define HDF_FILE "/tmp/.msgbox_hidden" + +//#define FONT "/usr/share/fonts/md_khmurabi_10.ttf" +#define FONT2 "/share/fonts/pakenham.ttf" +// if font is not in usual place, we look here: +#define FONT "/share/fonts/neutrino.ttf" + +// CMCST, CMCS, CMCT, CMC, CMCIT, CMCI, CMHT, CMH +// WHITE, BLUE0, TRANSP, CMS, ORANGE, GREEN, YELLOW, RED + +unsigned char bl[] = {0x00, 0x00, 0xFF, 0x80, 0xFF, 0x80, 0x00, 0x80, + 0xFF, 0xFF, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00}; +unsigned char gn[] = {0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xC0, 0x00, + 0xFF, 0x80, 0x00, 0x80, 0xC0, 0xFF, 0xFF, 0x00}; +unsigned char rd[] = {0x00, 0x00, 0xFF, 0x00, 0xFF, 0x00, 0xFF, 0x00, + 0xFF, 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF}; +unsigned char tr[] = {0xFF, 0xFF, 0xFF, 0xA0, 0xFF, 0xA0, 0xFF, 0xFF, + 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; + +void TrimString(char *strg); + +// Color table stuff +static char menucoltxt[][25]={"Content_Selected_Text","Content_Selected","Content_Text","Content","Content_inactive_Text","Content_inactive","Head_Text","Head"}; +char *line_buffer=NULL, *title=NULL; +int size=24, type=0, timeout=0, refresh=3, flash=0, selection=0, tbuttons=0, buttons=0, bpline=3, echo=0, absolute=0, mute=1, header=1, cyclic=1; +char *butmsg[16]; +int rbutt[16],hide=0,radius=10; + +// Misc +char NOMEM[]="msgbox \n"; +char TMP_FILE[64]="/tmp/msgbox.tmp"; +unsigned char *lfb = 0, *lbb = 0, *obb = 0, *hbb = 0, *ibb = 0; +unsigned char nstr[BUFSIZE]=""; +unsigned char *trstr; +unsigned rc,sc[8]={'a','o','u','A','O','U','z','d'}, tc[8]={0xE4,0xF6,0xFC,0xC4,0xD6,0xDC,0xDF,0xB0}; +char INST_FILE[]="/tmp/rc.locked"; +int instance=0; + +int get_instance(void) +{ +FILE *fh; +int rval=0; + + if((fh=fopen(INST_FILE,"r"))!=NULL) + { + rval=fgetc(fh); + fclose(fh); + } + return rval; +} + +void put_instance(int pval) +{ +FILE *fh; + + if(pval) + { + if((fh=fopen(INST_FILE,"w"))!=NULL) + { + fputc(pval,fh); + fclose(fh); + } + } + else + { + remove(INST_FILE); + } +} + +static void quit_signal(int sig) +{ + put_instance(get_instance()-1); + printf("msgbox Version %.2f killed\n",M_VERSION); + exit(1); +} + +int Read_Neutrino_Cfg(char *entry) +{ +FILE *nfh; +char tstr [512], *cfptr=NULL; +int rv=-1; + + if((nfh=fopen(NCF_FILE,"r"))!=NULL) + { + tstr[0]=0; + + while((!feof(nfh)) && ((strstr(tstr,entry)==NULL) || ((cfptr=strchr(tstr,'='))==NULL))) + { + fgets(tstr,500,nfh); + } + if(!feof(nfh) && cfptr) + { + ++cfptr; + if(sscanf(cfptr,"%d",&rv)!=1) + { + if(strstr(cfptr,"true")!=NULL) + { + rv=1; + } + else + { + if(strstr(cfptr,"false")!=NULL) + { + rv=0; + } + else + { + rv=-1; + } + } + } +// printf("%s\n%s=%s -> %d\n",tstr,entry,cfptr,rv); + } + fclose(nfh); + } + return rv; +} + +void TrimString(char *strg) +{ +char *pt1=strg, *pt2=strg; + + while(*pt2 && *pt2<=' ') + { + ++pt2; + } + if(pt1 != pt2) + { + do + { + *pt1=*pt2; + ++pt1; + ++pt2; + } + while(*pt2); + *pt1=0; + } + while(strlen(strg) && strg[strlen(strg)-1]<=' ') + { + strg[strlen(strg)-1]=0; + } +} + +int GetSelection(char *sptr) +{ +int rv=0,btn=0,run=1; +char *pt1=strdup(sptr),*pt2,*pt3; + + pt2=pt1; + while(*pt2 && run && btnbpline)?bpline:buttons,blines=1+((btns-1)/lbtns); + + if(hide) + { + memcpy(lfb, hbb, fix_screeninfo.line_length*var_screeninfo.yres); + return 0; + } + yo=40+((header)?FSIZE_MED*5/4:0); + if(!buttonly) + { + memcpy(lbb, ibb, fix_screeninfo.line_length*var_screeninfo.yres); + } + if((tfh=fopen(TMP_FILE,"r"))!=NULL) + { + fclose(tfh); + if(!buttonly) + { + if(type!=1) + { + btns=0; + myo=0; + } + + pxw=GetStringLen(sx,title,FSIZE_BIG)+10; + if(type==1) + { + myo=blines*(butty+buttdy); + for(i=0; ibuttx) + { + buttx=itmp; + } + } + } + buttsize=buttx; + + if(fh_txt_getsize(TMP_FILE, &x1, &y1, size, &cut)) + { + printf("msgbox \n"); + return -1; + } + x1+=10; + + dy=size; + if(pxw((ex-sx)-2*buttdx)) + { + pxw=ex-sx-2*buttdx; + } + psx=((ex-sx)/2-pxw/2); + pyw=y1*dy/*-myo*/; + if(pyw>((ey-sy)-yo-myo)) + { + pyw=((ey-sy)-yo-myo); + } + psy=((ey-sy)/2-(pyw+myo-yo)/2); + if(btns) + { + buttxstart=psx+pxw/2-(((double)lbtns*(double)buttsize+(((lbtns>2)&&(lbtns&1))?((double)buttdx):0.0))/2.0); + buttystart=psy+y1*dy; + } + } + + while(run) + { + //frame layout + if(action) + { + if(!buttonly) + { + RenderBox(psx-20, psy-yo, psx+pxw+20, psy+pyw+myo, radius, CMH); + RenderBox(psx-20+2, psy-yo+2, psx+pxw+20-2, psy+pyw+myo-2, radius, CMC); + if(header) + { + RenderBox(psx-20, psy-yo+2-FSIZE_BIG/2, psx+pxw+20, psy-yo+FSIZE_BIG*3/4, radius, CMH); + RenderString(title, psx, psy-yo+FSIZE_BIG/2, pxw, CENTER, FSIZE_BIG, CMHT); + } + } + if(buttonly || !(rv=fh_txt_load(TMP_FILE, psx, pxw, psy, dy, size, line, &cut))) + { + if(type==1) + { + for(i=0; i\n",aptr); + return 0; + break; + + case 2: + printf("msgbox \n\n",aptr); + ShowUsage(); + return 0; + break; + } + } + + FSIZE_BIG=(FSIZE_MED*5)/4; + FSIZE_SMALL=(FSIZE_MED*4)/5; + TABULATOR=2*FSIZE_MED; + size=FSIZE_MED; + + if(!echo) + { + printf("\nmsgbox Message-Box Version %.2f\n",M_VERSION); + } + if(!buttons) + { + butmsg[0]=strdup("OK"); + buttons=1; + } + if(!absolute) + { + for(tv=0; tv\n",selection); + return 0; + } + } + else + { + for(tv=0; tv=0) + tr[index]=255-(float)tv*2.55; + + sprintf(rstr,"menu_%s_blue",menucoltxt[index]); + if((tv=Read_Neutrino_Cfg(rstr))>=0) + bl[index]=(float)tv*2.55; + + sprintf(rstr,"menu_%s_green",menucoltxt[index]); + if((tv=Read_Neutrino_Cfg(rstr))>=0) + gn[index]=(float)tv*2.55; + + sprintf(rstr,"menu_%s_red",menucoltxt[index]); + if((tv=Read_Neutrino_Cfg(rstr))>=0) + rd[index]=(float)tv*2.55; + } + + if(Read_Neutrino_Cfg("rounded_corners")>0) + radius=10; + else + radius=0; + + fb = open(FB_DEVICE, O_RDWR); + if(fb == -1) + { + perror("msgbox "); + exit(1); + } + + InitRC(); + + if((trstr=malloc(BUFSIZE))==NULL) + { + printf(NOMEM); + return -1; + } + + //init framebuffer + + if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) + { + perror("msgbox \n"); + return -1; + } + if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) + { + perror("msgbox \n"); + return -1; + } + if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) + { + perror("msgbox \n"); + return -1; + } + + //init fontlibrary + + if((error = FT_Init_FreeType(&library))) + { + printf("msgbox ", error); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) + { + printf("msgbox \n", error); + FT_Done_FreeType(library); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if((error = FTC_SBitCache_New(manager, &cache))) + { + printf("msgbox \n", error); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if((error = FTC_Manager_LookupFace(manager, FONT, &face))) + { + if((error = FTC_Manager_LookupFace(manager, FONT2, &face))) + { + printf("msgbox \n", error); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + munmap(lfb, fix_screeninfo.smem_len); + return 2; + } + else + desc.face_id = FONT2; + } + else + desc.face_id = FONT; + + use_kerning = FT_HAS_KERNING(face); + + desc.flags = FT_LOAD_MONOCHROME; + + //init backbuffer + + if(!(lbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) + { + perror("msgbox \n"); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if(!(obb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) + { + perror("msgbox \n"); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + free(lbb); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if(!(hbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) + { + perror("msgbox \n"); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + free(lbb); + free(obb); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if(!(ibb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) + { + perror("msgbox \n"); + FTC_Manager_Done(manager); + FT_Done_FreeType(library); + free(lbb); + free(obb); + free(hbb); + munmap(lfb, fix_screeninfo.smem_len); + return -1; + } + + if(refresh & 1) + { + memcpy(ibb, lfb, fix_screeninfo.line_length*var_screeninfo.yres); + } + else + { + memset(ibb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres); + } + if(mute==2) + { + memcpy(hbb, lfb, fix_screeninfo.line_length*var_screeninfo.yres); + } + else + { + memset(hbb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres); + } + if(refresh & 2) + { + memcpy(obb, lfb, fix_screeninfo.line_length*var_screeninfo.yres); + } + else + { + memset(obb, TRANSP, fix_screeninfo.line_length*var_screeninfo.yres); + } + + startx = sx; + starty = sy; + + + /* Set up signal handlers. */ + signal(SIGINT, quit_signal); + signal(SIGTERM, quit_signal); + signal(SIGQUIT, quit_signal); + + put_instance(instance=get_instance()+1); + + show_txt(0); + + time(&tm1); + tm2=tm1; + + //main loop + while((rcc!=KEY_EXIT) && (rcc!=KEY_OK) && ((timeout==-1)||((tm2-tm1)100) + { + if(cyclic) + { + show_txt(0); + cupd=0; + } + } + usleep(10000L); + } + if(mute && rcc==KEY_MUTE) + { + hide^=1; + show_txt(0); + usleep(500000L); + while(GetRCCode()!=-1); + if(hide) + { + if((fh=fopen(HDF_FILE,"w"))!=NULL) + { + fprintf(fh,"hidden"); + fclose(fh); + } + } + else + { + remove(HDF_FILE); + } + } + if((!hide) && (rcc!=KEY_EXIT) && (rcc!=KEY_OK)) + { + switch(rcc) + { + case KEY_LEFT: + if(!hide && (--selection<1)) + { + selection=buttons; + } + show_txt(1); + break; + + case KEY_RIGHT: + if(!hide && (++selection>buttons)) + { + selection=1; + } + show_txt(1); + break; + + case KEY_UP: + if(!hide && ((selection-=bpline)<1)) + { + selection=1; + } + show_txt(1); + break; + + case KEY_DOWN: + if(!hide && ((selection+=bpline)>buttons)) + { + selection=buttons; + } + show_txt(1); + break; + } + } + time(&tm2); + if(hide) + { + rcc=-1; + } + } + if((type!=1) || (rcc!=KEY_OK)) + { + selection=0; + } + + + //cleanup + + memcpy(lfb, obb, fix_screeninfo.line_length*var_screeninfo.yres); + munmap(lfb, fix_screeninfo.smem_len); + close(fb); + free(lbb); + + put_instance(get_instance()-1); + + if(echo && selection>0) + { + printf("%s\n",butmsg[selection-1]); + } + + for(tv=0; tv +#include +#include +#include +#include +#include +#include +#include +#if HAVE_DVB_API_VERSION == 3 +#include +#endif +#include +#include +#include +#include + +#include +#include FT_FREETYPE_H +#include FT_CACHE_H +#include FT_CACHE_SMALL_BITMAPS_H + +#define MAX_BUTTONS 16 +#define BUFSIZE 4095 + +extern unsigned char FONT[64]; + +enum {LEFT, CENTER, RIGHT}; + +FT_Error error; +FT_Library library; +FTC_Manager manager; +FTC_SBitCache cache; +FTC_SBit sbit; +#if FREETYPE_MAJOR == 2 && FREETYPE_MINOR == 0 +FTC_Image_Desc desc; +#else +FTC_ImageTypeRec desc; +#endif +FT_Face face; +FT_UInt prev_glyphindex; +FT_Bool use_kerning; + +// rc codes + +#undef KEY_EPG +#undef KEY_SAT +#undef KEY_STOP +#undef KEY_PLAY + +#define KEY_1 2 +#define KEY_2 3 +#define KEY_3 4 +#define KEY_4 5 +#define KEY_5 6 +#define KEY_6 7 +#define KEY_7 8 +#define KEY_8 9 +#define KEY_9 10 +#define KEY_BACKSPACE 14 +#define KEY_UP 103 +#define KEY_LEFT 105 +#define KEY_RIGHT 106 +#define KEY_DOWN 108 +#define KEY_MUTE 113 +#define KEY_VOLUMEDOWN 114 +#define KEY_VOLUMEUP 115 +#define KEY_POWER 116 +#define KEY_HELP 138 +#define KEY_HOME 102 +#define KEY_EXIT 174 +#define KEY_SETUP 141 +#define KEY_PAGEUP 104 +#define KEY_PAGEDOWN 109 +#define KEY_OK 0x160 +#define KEY_RED 0x18e +#define KEY_GREEN 0x18f +#define KEY_YELLOW 0x190 +#define KEY_BLUE 0x191 + +#define KEY_TVR 0x179 +#define KEY_TTX 0x184 +#define KEY_COOL 0x1A1 +#define KEY_FAV 0x16C +#define KEY_EPG 0x16D +#define KEY_VF 0x175 + +#define KEY_SAT 0x17D +#define KEY_SKIPP 0x197 +#define KEY_SKIPM 0x19C +#define KEY_TS 0x167 +#define KEY_AUDIO 0x188 +#define KEY_REW 0x0A8 +#define KEY_FWD 0x09F +#define KEY_HOLD 0x077 +#define KEY_REC 0x0A7 +#define KEY_STOP 0x080 +#define KEY_PLAY 0x0CF + +//devs + +int fb; + +//framebuffer stuff + +enum {FILL, GRID}; + +enum {CMCST, CMCS, CMCT, CMC, CMCIT, CMCI, CMHT, CMH, WHITE, BLUE1, GTRANSP, CMS, ORANGE, GREEN, YELLOW, RED}; +#define TRANSP 0 + +extern int FSIZE_BIG; +extern int FSIZE_MED; +extern int FSIZE_SMALL; +extern int TABULATOR; + +extern unsigned char *lfb, *lbb, *obb, *hbb; + +struct fb_fix_screeninfo fix_screeninfo; +struct fb_var_screeninfo var_screeninfo; +extern unsigned char rd[],gn[],bl[],tr[]; + +int startx, starty, sx, ex, sy, ey, debounce, rblock; +extern unsigned sc[8], tc[8]; +extern char *butmsg[MAX_BUTTONS]; +extern int buttons,selection; +extern int instance; +int get_instance(void); +void put_instance(int pval); + +#define FB_DEVICE "/dev/fb/0" + +#endif + diff --git a/msgbox.txt b/msgbox.txt new file mode 100644 index 0000000..deb13ed --- /dev/null +++ b/msgbox.txt @@ -0,0 +1,8 @@ +~cBeispiel f~ur Formatierungs-M~oglichkeiten der Message-Box +~s +Text ist in Standard, ~Rrot~S, ~Ggr~un~S, ~Bblau~S und ~Ygelb ~Sm~oglich +~cZeilen k~onnen zentriert, +~roder auf Rechtsanschlag formatiert werden + +Tabulatoren:~tTab1~tTab2~tTab3~tTab4~tTab5~tTab6 +~t~tTab1~t~tTab3~t~tTab5 \ No newline at end of file diff --git a/text.c b/text.c new file mode 100644 index 0000000..fb90e07 --- /dev/null +++ b/text.c @@ -0,0 +1,272 @@ +#include "text.h" +#include "gfx.h" +#include "io.h" + +int FSIZE_BIG=28; +int FSIZE_MED=24; +int FSIZE_SMALL=20; +int TABULATOR=72; + +/****************************************************************************** + * MyFaceRequester + ******************************************************************************/ + +FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface) +{ + FT_Error result; + + result = FT_New_Face(library, face_id, 0, aface); + + if(result) printf("msgbox \n", (char*)face_id); + + return result; +} + +/****************************************************************************** + * RenderChar + ******************************************************************************/ + +int RenderChar(FT_ULong currentchar, int sx, int sy, int ex, int color) +{ +// unsigned char pix[4]={oldcmap.red[col],oldcmap.green[col],oldcmap.blue[col],oldcmap.transp[col]}; +// unsigned char pix[4]={0x80,0x80,0x80,0x80}; + unsigned char pix[4]={bl[color],gn[color],rd[color],tr[color]}; + int row, pitch, bit, x = 0, y = 0; + FT_UInt glyphindex; + FT_Vector kerning; + FT_Error error; + + currentchar=currentchar & 0xFF; + + //load char + + if(!(glyphindex = FT_Get_Char_Index(face, (int)currentchar))) + { +// printf("msgbox \n", (int)currentchar, error); + return 0; + } + +// no kerning used +/* + if(use_kerning) + { + FT_Get_Kerning(face, prev_glyphindex, glyphindex, ft_kerning_default, &kerning); + + prev_glyphindex = glyphindex; + kerning.x >>= 6; + } + else +*/ + kerning.x = 0; + + //render char + + if(color != -1) /* don't render char, return charwidth only */ + { + if(sx + sbit->xadvance >= ex) return -1; /* limit to maxwidth */ + + for(row = 0; row < sbit->height; row++) + { + for(pitch = 0; pitch < sbit->pitch; pitch++) + { + for(bit = 7; bit >= 0; bit--) + { + if(pitch*8 + 7-bit >= sbit->width) break; /* render needed bits only */ + + if((sbit->buffer[row * sbit->pitch + pitch]) & 1<left + kerning.x + x)*4 + fix_screeninfo.line_length*(starty + sy - sbit->top + y),pix,4); + + x++; + } + } + + x = 0; + y++; + } + + } + + //return charwidth + + return sbit->xadvance + kerning.x; +} + +/****************************************************************************** + * GetStringLen + ******************************************************************************/ + +int GetStringLen(int sx, unsigned char *string, int size) +{ +int i, found; +int stringlen = 0; + + //reset kerning + + prev_glyphindex = 0; + + //calc len + + if(size) + { + desc.width = desc.height = size; + } + + while(*string != '\0') + { + if(*string != '~') + { + stringlen += RenderChar(*string, -1, -1, -1, -1); + } + else + { + string++; + if(*string=='t') + { + stringlen=desc.width+TABULATOR*((int)(stringlen/TABULATOR)+1); + } + else + { + if(*string=='T') + { + if(sscanf(string+1,"%4d",&i)==1) + { + string+=4; + stringlen=i-sx; + } + } + else + { + found=0; + for(i=0; i maxwidth */ + sx += charwidth; + } + else + { + switch(*rptr) + { + case 'R': varcolor=RED; break; + case 'G': varcolor=GREEN; break; + case 'Y': varcolor=YELLOW; break; + case 'B': varcolor=BLUE1; break; + case 'S': varcolor=color; break; + case 't': + sx=TABULATOR*((int)(sx/TABULATOR)+1); + break; + case 'T': + if(sscanf(rptr+1,"%4d",&i)==1) + { + rptr+=4; + sx=i; + } + break; + } + } + } + else + { + if((charwidth = RenderChar(*rptr, sx, sy, ex, varcolor)) == -1) return sx; /* string > maxwidth */ + sx += charwidth; + } + rptr++; + } + return stringlen; +} + diff --git a/text.h b/text.h new file mode 100644 index 0000000..a28cac1 --- /dev/null +++ b/text.h @@ -0,0 +1,12 @@ +#ifndef __TEXT_H__ + +#define __TEXT_H__ + +#include "msgbox.h" + +FT_Error MyFaceRequester(FTC_FaceID face_id, FT_Library library, FT_Pointer request_data, FT_Face *aface); +int RenderString(char *string, int sx, int sy, int maxwidth, int layout, int size, int color); +int GetStringLen(int sx, unsigned char *string, int size); +void CatchTabs(char *text); + +#endif diff --git a/txtform.c b/txtform.c new file mode 100644 index 0000000..4933d27 --- /dev/null +++ b/txtform.c @@ -0,0 +1,108 @@ +//#include "config.h" +#include +#include +#include +#include +#include "text.h" +#include "gfx.h" +#include "msgbox.h" + +#define FH_ERROR_OK 0 +#define FH_ERROR_FILE 1 /* read/access error */ +#define FH_ERROR_FORMAT 2 /* file format error */ +#define FH_ERROR_MALLOC 3 /* error during malloc */ + +int fh_txt_trans(const char *name, int xs, int xw, int ys, int dy, int size, int line, int *cut, int *x, int *y, int plot) +{ +char tstr[BUFSIZE],rstr[BUFSIZE],*tptr; +int loop=1, j, first, slen, cnt=0; +FILE *fh; +int just, color=CMCT; + + if(!(fh=fopen(name,"rb"))) return(FH_ERROR_FILE); + + first=(line==0); + *x=0; + *y=0; + while((loop>0) && (fgets(tstr, sizeof(tstr), fh))) + { + j=0; + just=LEFT; + color=CMCT; + + tptr=tstr+strlen(tstr); + while((tptr>=tstr) && (*tptr<=32)) + { + *tptr=0; + --tptr; + } + tptr=tstr; + while(*tptr) + { + rstr[j++]=*tptr; + cnt++; + + if(*tptr == '~') + { + switch (*(tptr+1)) + { + case 'l': just=LEFT; break; + case 'r': just=RIGHT; break; + case 'c': just=CENTER; break; + case 's': + RenderBox(xs, ys-size/3+1, xs+xw, ys-size/3+2, FILL, CMS); + RenderBox(xs, ys-size/3, xs+xw, ys-size/3+1, FILL, CMCIT); + break; + } + } + tptr++; + } + if((loop>0) && (ys<(ey-dy))) + { + rstr[j]=0; + if(plot) + { + if(loop>=line) + { + RenderString(rstr, xs, ys, xw, just, size, color); + if(strlen(rstr)) + { + first=0; + } + ys+=dy; + } + } + else + { + if(strlen(rstr)) + { + slen=GetStringLen(xs, rstr, size); + if(slen>*x) + { + *x=slen; + } + } + *y=*y+1; + } + } + } + if(plot) + { + *cut=(ys>=(ey-dy)); + } + fclose(fh); + return(FH_ERROR_OK); +} + +int fh_txt_load(const char *name, int sx, int wx, int sy, int dy, int size, int line, int *cut) +{ +int dummy; + + return fh_txt_trans(name, sx, wx, sy, dy, size, line, cut, &dummy, &dummy, 1); +} + + +int fh_txt_getsize(const char *name, int *x, int *y, int size, int *cut) +{ + return fh_txt_trans(name, 0, 0, 0, 0, size, 0, cut, x, y, 0); +} diff --git a/txtform.h b/txtform.h new file mode 100644 index 0000000..ff7d7f8 --- /dev/null +++ b/txtform.h @@ -0,0 +1,7 @@ +#ifndef __TXTFORM_H__ +#define __TXTFORM_H__ + +int fh_txt_load(const char *name, int sx, int wx, int sy, int dy, int size, int line, int *cut); +int fh_txt_getsize(const char *filename, int *x, int *y, int size, int *cut); + +#endif -- 2.39.5