float fontRenderClass::getLineHeight(const gFont& font) { if (!instance) return 0; ePtr<Font> fnt; getFont(fnt, font.family.c_str(), font.pointSize); if (!fnt) return 0; singleLock s(ftlock); FT_Face current_face; if ((FTC_Manager_LookupFace(cacheManager, fnt->scaler.face_id, ¤t_face) < 0) || (FTC_Manager_LookupSize(cacheManager, &fnt->scaler, &fnt->size) < 0)) { eDebug("FTC_Manager_Lookup_Size failed!"); return 0; } int height = current_face->size->metrics.height; if (!height) { /* some fonts don't have height filled in. Estimate it based on the bbox dimensions. */ /* Usually, 'height' is less than the complete boundingbox height, so we use only yMax, to avoid getting a much too large line spacing */ height = FT_MulFix(current_face->bbox.yMax, current_face->size->metrics.y_scale); } return (height>>6); }
static FT_Error ftc_scaler_lookup_size( FTC_Manager manager, FTC_Scaler scaler, FT_Size *asize ) { FT_Face face; FT_Size size = NULL; FT_Error error; error = FTC_Manager_LookupFace( manager, scaler->face_id, &face ); if ( error ) goto Exit; error = FT_New_Size( face, &size ); if ( error ) goto Exit; FT_Activate_Size( size ); if ( scaler->pixel ) error = FT_Set_Pixel_Sizes( face, scaler->width, scaler->height ); else error = FT_Set_Char_Size( face, scaler->width, scaler->height, scaler->x_res, scaler->y_res ); if ( error ) { FT_Done_Size( size ); size = NULL; } Exit: *asize = size; return error; }
ftc_basic_family_get_count( FTC_Family ftcfamily, FTC_Manager manager ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FT_Error error; FT_Face face; FT_UInt result = 0; error = FTC_Manager_LookupFace( manager, family->attrs.scaler.face_id, &face ); if ( error || !face ) return result; if ( (FT_ULong)face->num_glyphs > FT_UINT_MAX || 0 > face->num_glyphs ) { FT_TRACE1(( "ftc_basic_family_get_count: too large number of glyphs " )); FT_TRACE1(( "in this face, truncated\n", face->num_glyphs )); } if ( !error ) result = (FT_UInt)face->num_glyphs; return result; }
/* create new framebuffer face and cause it to be loaded to check its ok */ static fb_faceid_t * fb_new_face(const char *option, const char *resname, const char *fontname) { fb_faceid_t *newf; FT_Error error; FT_Face aface; char buf[PATH_MAX]; newf = calloc(1, sizeof(fb_faceid_t)); if (option != NULL) { newf->fontfile = strdup(option); } else { filepath_sfind(respaths, buf, fontname); newf->fontfile = strdup(buf); } error = FTC_Manager_LookupFace(ft_cmanager, (FTC_FaceID)newf, &aface); if (error) { LOG(("Could not find font face %s (code %d)\n", fontname, error)); free(newf); newf = NULL; } return newf; }
static void write_header( FT_Error error_code ) { FT_Face face; const char* basename; error = FTC_Manager_LookupFace( handle->cache_manager, handle->scaler.face_id, &face ); if ( error ) PanicZ( "can't access font file" ); if ( !status.header ) { basename = ft_basename( handle->current_font->filepathname ); switch ( error_code ) { case FT_Err_Ok: sprintf( status.header_buffer, "%.50s %.50s (file `%.100s')", face->family_name, face->style_name, basename ); break; case FT_Err_Invalid_Pixel_Size: sprintf( status.header_buffer, "Invalid pixel size (file `%.100s')", basename ); break; case FT_Err_Invalid_PPem: sprintf( status.header_buffer, "Invalid ppem value (file `%.100s')", basename ); break; default: sprintf( status.header_buffer, "File `%.100s': error 0x%04x", basename, (FT_UShort)error_code ); break; } status.header = status.header_buffer; } grWriteCellString( display->bitmap, 0, 0, status.header, display->fore_color ); sprintf( status.header_buffer, "at %g points, angle = %d", status.ptsize / 64.0, status.angle ); grWriteCellString( display->bitmap, 0, CELLSTRING_HEIGHT, status.header_buffer, display->fore_color ); grRefreshSurface( display->surface ); }
ftc_basic_family_get_count( FTC_Family ftcfamily, FTC_Manager manager ) { FTC_BasicFamily family = (FTC_BasicFamily)ftcfamily; FT_Error error; FT_Face face; FT_UInt result = 0; error = FTC_Manager_LookupFace( manager, family->attrs.scaler.face_id, &face ); if ( !error ) result = face->num_glyphs; return result; }
FT_Face _PGFT_GetFont(FreeTypeInstance *ft, PgFontObject *fontobj) { FT_Error error; FT_Face font; error = FTC_Manager_LookupFace(ft->cache_manager, (FTC_FaceID)(&fontobj->id), &font); if (error) { _PGFT_SetError(ft, "Failed to load font", error); return 0; } return font; }
FT_Face _PGFT_GetFace(FreeTypeInstance *ft, PgFaceObject *faceobj) { FT_Error error; FT_Face face; error = FTC_Manager_LookupFace(ft->cache_manager, (FTC_FaceID)(&faceobj->id), &face); if (error) { _PGFT_SetError(ft, "Failed to load face", error); return 0; } return face; }
std::vector<Handler<BitmapGlyph> > FreeType::lookupBitmap(Font& font, float size, std::vector<unsigned int> const& ucs4, float& ascent, float& descent, float& height) { Font::RawFaceSession rfs(font); FT_Face face = rfs.face(); FT_Face face__; FTC_ScalerRec scaler; { scaler.face_id = face; scaler.width = 0; scaler.height = FLOAT_TO_26_6( size ); scaler.pixel = 0; scaler.x_res=72; //XXX scaler.y_res=72; //XXX } FTC_Manager_LookupFace(this->cache_, face, &face__); { FT_Size size; FTC_Manager_LookupSize(this->cache_, &scaler, &size); ascent = FLOAT_FROM_26_6(size->metrics.ascender); descent = FLOAT_FROM_26_6(size->metrics.descender); height = FLOAT_FROM_26_6(size->metrics.height); } std::vector<Handler<BitmapGlyph> > ret; ret.reserve(ucs4.size()); for(unsigned int const& u : ucs4) { unsigned int const gindex = FTC_CMapCache_Lookup(this->cmap_, face, font.unicodeCharmapIndex(), u); FT_Glyph glyph; { FT_Glyph glyph_orig; FTC_ImageCache_LookupScaler(this->image_, &scaler, 0, gindex, &glyph_orig, nullptr); FT_Glyph_Copy(glyph_orig, &glyph); } if(glyph->format != FT_GLYPH_FORMAT_BITMAP ) { FT_Vector_ vec; vec.x = 0; vec.y = 0; FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, &vec, 1); } ret.push_back( Handler<BitmapGlyph>(new BitmapGlyph(reinterpret_cast<FT_BitmapGlyph>(glyph))) ); } return ret; }
FTC_Manager_Lookup_Face( FTC_Manager manager, FTC_FaceID face_id, FT_Face *aface ) { return FTC_Manager_LookupFace( manager, face_id, aface ); }
int main (int argc, char **argv) { int ix,tv,found=0, spr, resolution; int dloop=1, rcc=-1; char rstr[BUFSIZE]={0}, *rptr=NULL, *aptr=NULL; time_t tm1,tm2; #ifndef MARTII FILE *fh; #endif if(argc<2) { ShowUsage(); return 0; } //init framebuffer before 1st scale2res fb = open(FB_DEVICE, O_RDWR); #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE if (fb < 0) fb = open(FB_DEVICE_FALLBACK, O_RDWR); #endif if(fb == -1) { perror(__plugin__ " <open framebuffer device>"); exit(1); } if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { perror(__plugin__ " <FBIOGET_FSCREENINFO>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { perror(__plugin__ " <FBIOGET_VSCREENINFO>\n"); return -1; } #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) var_screeninfo.xres = DEFAULT_XRES; var_screeninfo.yres = DEFAULT_YRES; #endif if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { perror(__plugin__ " <mapping of Framebuffer>\n"); return -1; } dloop=0; for(tv=1; !dloop && tv<argc; tv++) { aptr=argv[tv]; if(!strcmp(aptr,"-v") || !strcmp(aptr,"--version")) { printf("%s Version %.2f\n", __plugin__, M_VERSION); return 0; } if((rptr=strchr(aptr,'='))!=NULL) { rptr++; if(strstr(aptr,"size=")!=NULL) { if(sscanf(rptr,"%d",&FSIZE_MED)!=1) { dloop=1; } } else { if(strstr(aptr,"title=")!=NULL) { size_t l = strlen(rptr); char *t = (char *)alloca(l * 4 + 1); memcpy(t, rptr, l + 1); TranslateString(t, l * 4); title = strdup(t); CatchTabs(title); if(strcmp(title,"none")==0) { header=0; } } else { if(strstr(aptr,"timeout=")!=NULL) { if(sscanf(rptr,"%d",&timeout)!=1) { dloop=1; } } else { if(strstr(aptr,"msg=")!=NULL) { dloop=Transform_Msg(rptr); if(timeout==0) { if((timeout=Read_Neutrino_Cfg("timing.epg"))<0) timeout=300; } type=1; } else { if(strstr(aptr,"popup=")!=NULL) { dloop=Transform_Msg(rptr); if(timeout==0) { if((timeout=Read_Neutrino_Cfg("timing.infobar"))<0) timeout=6; } type=2; } else { if(strstr(aptr,"refresh=")!=NULL) { if(sscanf(rptr,"%d",&refresh)!=1) { dloop=1; } } else { if(strstr(aptr,"select=")!=NULL) { dloop=GetSelection(rptr); } else { if(strstr(aptr,"default=")!=NULL) { if((sscanf(rptr,"%d",&selection)!=1) || selection<1) { dloop=1; } } else { if(strstr(aptr,"order=")!=NULL) { if(sscanf(rptr,"%d",&bpline)!=1) { dloop=1; } } else { if(strstr(aptr,"echo=")!=NULL) { if(sscanf(rptr,"%d",&echo)!=1) { dloop=1; } } else { if(strstr(aptr,"absolute=")!=NULL) { if(sscanf(rptr,"%d",&absolute)!=1) { dloop=1; } } else { if(strstr(aptr,"hide=")!=NULL) { if(sscanf(rptr,"%d",&mute)!=1) { dloop=1; } } else { if(strstr(aptr,"cyclic=")!=NULL) { if(sscanf(rptr,"%d",&cyclic)!=1) { dloop=1; } } else { if(strstr(aptr,"icon=")!=NULL) { icon=rptr; dloop=Transform_Icon(icon)==0; } else { dloop=2; } } } } } } } } } } } } } } } switch (dloop) { case 1: printf("%s <param error: %s>\n", __plugin__, aptr); return 0; break; case 2: printf("%s <unknown command: %s>\n\n", __plugin__, aptr); ShowUsage(); return 0; break; } } FSIZE_BIG=(float)FSIZE_MED*1.25; FSIZE_SMALL=(FSIZE_MED*4)/5; TABULATOR=2*FSIZE_MED; size=FSIZE_MED; /* if(!echo) { printf("\nMsgBox Version %.2f\n", M_VERSION); } */ if(!buttons) { butmsg[0]=strdup("OK"); buttons=1; } if(!absolute) { for(tv=0; tv<buttons; tv++) { rbutt[tv]=tv+1; } } if(selection) { for(tv=0; tv<buttons && !found; tv++) { if(rbutt[tv]==selection) { selection=tv+1; found=1; } } if(!found) { printf("%s <param error: default=%d>\n", __plugin__, selection); return 0; } } else { for(tv=0; tv<buttons && !selection; tv++) { if(strlen(butmsg[tv])) { selection=tv+1; } } } if(!icon) { icon=strdup("info"); } if(!title) { title=strdup("Information"); } if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL) { printf(NOMEM); return -1; } spr=Read_Neutrino_Cfg("screen_preset")+1; resolution=Read_Neutrino_Cfg("osd_resolution"); if (resolution == -1) sprintf(line_buffer,"screen_StartX_%s", spres[spr]); else sprintf(line_buffer,"screen_StartX_%s_%d", spres[spr], resolution); if((sx=Read_Neutrino_Cfg(line_buffer))<0) sx=scale2res(100); if (resolution == -1) sprintf(line_buffer,"screen_EndX_%s", spres[spr]); else sprintf(line_buffer,"screen_EndX_%s_%d", spres[spr], resolution); if((ex=Read_Neutrino_Cfg(line_buffer))<0) ex=scale2res(1180); if (resolution == -1) sprintf(line_buffer,"screen_StartY_%s", spres[spr]); else sprintf(line_buffer,"screen_StartY_%s_%d", spres[spr], resolution); if((sy=Read_Neutrino_Cfg(line_buffer))<0) sy=scale2res(100); if (resolution == -1) sprintf(line_buffer,"screen_EndY_%s", spres[spr]); else sprintf(line_buffer,"screen_EndY_%s_%d", spres[spr], resolution); if((ey=Read_Neutrino_Cfg(line_buffer))<0) ey=scale2res(620); for(ix=CMCST; ix<=CMH; ix++) { sprintf(rstr,"menu_%s_alpha",menucoltxt[ix]); if((tv=Read_Neutrino_Cfg(rstr))>=0) tr[ix]=255-(float)tv*2.55; sprintf(rstr,"menu_%s_blue",menucoltxt[ix]); if((tv=Read_Neutrino_Cfg(rstr))>=0) bl[ix]=(float)tv*2.55; sprintf(rstr,"menu_%s_green",menucoltxt[ix]); if((tv=Read_Neutrino_Cfg(rstr))>=0) gn[ix]=(float)tv*2.55; sprintf(rstr,"menu_%s_red",menucoltxt[ix]); if((tv=Read_Neutrino_Cfg(rstr))>=0) rd[ix]=(float)tv*2.55; } int cix=CMC; for(ix=COL_MENUCONTENT_PLUS_0; ix<=COL_MENUCONTENT_PLUS_3; ix++) { rd[ix]=rd[cix]+25; gn[ix]=gn[cix]+25; bl[ix]=bl[cix]+25; tr[ix]=tr[cix]; cix=ix; } sprintf(rstr,"infobar_alpha"); if((tv=Read_Neutrino_Cfg(rstr))>=0) tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55; sprintf(rstr,"infobar_blue"); if((tv=Read_Neutrino_Cfg(rstr))>=0) bl[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; sprintf(rstr,"infobar_green"); if((tv=Read_Neutrino_Cfg(rstr))>=0) gn[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; sprintf(rstr,"infobar_red"); if((tv=Read_Neutrino_Cfg(rstr))>=0) rd[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; for (ix = 0; ix <= COL_SHADOW_PLUS_0; ix++) bgra[ix] = (tr[ix] << 24) | (rd[ix] << 16) | (gn[ix] << 8) | bl[ix]; if(Read_Neutrino_Cfg("rounded_corners")>0) { radius = scale2res(11); radius_small = scale2res(5); } else radius = radius_small = 0; InitRC(); if((trstr=malloc(BUFSIZE))==NULL) { printf(NOMEM); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("%s <FT_Init_FreeType failed with Errorcode 0x%.2X>", __plugin__, error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("%s <FTC_Manager_New failed with Errorcode 0x%.2X>\n", __plugin__, error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("%s <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", __plugin__, error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } Read_Neutrino_Cfg("font_file="); if((error = FTC_Manager_LookupFace(manager, FONT, &face))) { if((error = FTC_Manager_LookupFace(manager, FONT2, &face))) { printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", __plugin__, 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_RENDER | FT_LOAD_FORCE_AUTOHINT; //init backbuffer #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE lbb = lfb + 1920 * 1080; fix_screeninfo.line_length = DEFAULT_XRES * sizeof(uint32_t); stride = DEFAULT_XRES; #else stride = fix_screeninfo.line_length/sizeof(uint32_t); if(stride == 7680 && var_screeninfo.xres == 1280) { var_screeninfo.yres = 1080; } if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { perror(__plugin__ " <allocating of Backbuffer>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } #endif if(!(obb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { perror(__plugin__ " <allocating of Backbuffer>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); free(lbb); munmap(lfb, fix_screeninfo.smem_len); return -1; } if(!(hbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { perror(__plugin__ " <allocating of Backbuffer>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); free(lbb); free(obb); munmap(lfb, fix_screeninfo.smem_len); return -1; } if(!(ibb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { perror(__plugin__ " <allocating of Backbuffer>\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, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } else { memset(ibb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } if(mute==2) { memcpy(hbb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } else { memset(hbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } if(refresh & 2) { memcpy(obb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } else { memset(obb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); } startx = sx; starty = sy; /* scale to resolution */ FSIZE_BIG = scale2res(FSIZE_BIG); FSIZE_MED = scale2res(FSIZE_MED); FSIZE_SMALL = scale2res(FSIZE_SMALL); TABULATOR = scale2res(TABULATOR); OFFSET_MED = scale2res(OFFSET_MED); OFFSET_SMALL = scale2res(OFFSET_SMALL); OFFSET_MIN = scale2res(OFFSET_MIN); size = scale2res(size); /* Set up signal handlers. */ signal(SIGINT, quit_signal); signal(SIGTERM, quit_signal); signal(SIGQUIT, quit_signal); signal(SIGSEGV, quit_signal); put_instance(instance=get_instance()+1); show_txt(0); time(&tm1); tm2=tm1; //main loop while((rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (rcc!=KEY_OK) && ((timeout==-1)||((tm2-tm1)<timeout))) { rcc=GetRCCode(1000); if(rcc!=-1) { time(&tm1); } else { if(cyclic) show_txt(0); #if 0 if(++cupd>100) { if(cyclic) { show_txt(0); cupd=0; } } usleep(10000L); #endif } if(mute && rcc==KEY_MUTE) { hide^=1; show_txt(0); #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE ClearRC(); #else while(GetRCCode(300)!=-1); if(hide) { if((fh=fopen(HDF_FILE,"w"))!=NULL) { fprintf(fh,"hidden"); fclose(fh); } } else { remove(HDF_FILE); } #endif } if((!hide) && (rcc!=KEY_EXIT) && (rcc!=KEY_HOME) && (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; default: flash^=1; break; } } time(&tm2); if(hide) { rcc=-1; } } if((type!=1) || (rcc!=KEY_OK)) { selection=0; } //cleanup #if HAVE_SPARK_HARDWARE || HAVE_DUCKBOX_HARDWARE memcpy(lbb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); blit(); #else memcpy(lfb, obb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); #endif munmap(lfb, fix_screeninfo.smem_len); close(fb); #if !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE) free(lbb); #endif put_instance(get_instance()-1); if(echo && selection>0) { printf("%s\n",butmsg[selection-1]); } for(tv=0; tv<buttons; tv++) { free(butmsg[tv]); } free(trstr); free(line_buffer); free(title); FTC_Manager_Done(manager); FT_Done_FreeType(library); free(obb); free(hbb); free(ibb); CloseRC(); remove("/tmp/msgbox.tmp"); if(selection) { return rbutt[selection-1]; } return 0; }
void vita2d_font_draw_text(vita2d_font *font, int x, int y, unsigned int color, unsigned int size, const char *text) { FTC_FaceID face_id = (FTC_FaceID)font; FT_Face face; FTC_Manager_LookupFace(font->ftcmanager, face_id, &face); FT_Int charmap_index; charmap_index = FT_Get_Charmap_Index(face->charmap); FT_Glyph glyph; FT_Bool use_kerning = FT_HAS_KERNING(face); FT_UInt glyph_index, previous = 0; int pen_x = x; int pen_y = y + size; FTC_ScalerRec scaler; scaler.face_id = face_id; scaler.width = size; scaler.height = size; scaler.pixel = 1; FT_ULong flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL; while (*text) { glyph_index = FTC_CMapCache_Lookup(font->cmapcache, (FTC_FaceID)font, charmap_index, *text); if (use_kerning && previous && glyph_index) { FT_Vector delta; FT_Get_Kerning(face, previous, glyph_index, FT_KERNING_DEFAULT, &delta); pen_x += delta.x >> 6; } if (!texture_atlas_exists(font->tex_atlas, glyph_index)) { FTC_ImageCache_LookupScaler(font->imagecache, &scaler, flags, glyph_index, &glyph, NULL); if (!atlas_add_glyph(font->tex_atlas, glyph_index, (FT_BitmapGlyph)glyph, size)) { continue; } } bp2d_rectangle rect; int bitmap_left, bitmap_top; int advance_x, advance_y; int glyph_size; texture_atlas_get(font->tex_atlas, glyph_index, &rect, &bitmap_left, &bitmap_top, &advance_x, &advance_y, &glyph_size); const float draw_scale = size/(float)glyph_size; vita2d_draw_texture_tint_part_scale(font->tex_atlas->tex, pen_x + bitmap_left * draw_scale, pen_y - bitmap_top * draw_scale, rect.x, rect.y, rect.w, rect.h, draw_scale, draw_scale, color); pen_x += (advance_x >> 16) * draw_scale; pen_y += (advance_y >> 16) * draw_scale; previous = glyph_index; text++; }
int main (int argc, char **argv) { int index=0,cindex=0,mainloop=1,dloop=1,tv, spr, resolution; char tstr[BUFSIZE]={0}, *rptr; PLISTENTRY pl; printf("%s Version %.2f\n", __plugin__, SH_VERSION); for(tv=1; tv<argc; tv++) { if(*argv[tv]=='/') { strcpy(CFG_FILE,argv[tv]); } } //init framebuffer before 1st scale2res fb = open(FB_DEVICE, O_RDWR); #ifdef MARTII if (fb < 0) fb = open(FB_DEVICE_FALLBACK, O_RDWR); #endif if(fb == -1) { perror(__plugin__ " <open framebuffer device>"); exit(1); } if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { perror(__plugin__ " <FBIOGET_FSCREENINFO>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { perror(__plugin__ " <FBIOGET_VSCREENINFO>\n"); return -1; } #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) var_screeninfo.xres = DEFAULT_XRES; var_screeninfo.yres = DEFAULT_YRES; #endif if(!(lfb = (uint32_t*)mmap(0, fix_screeninfo.smem_len, PROT_WRITE|PROT_READ, MAP_SHARED, fb, 0))) { perror(__plugin__ " <mapping of Framebuffer>\n"); return -1; } // read config ixw=scale2res(600), iyw=scale2res(680), xoffs=scale2res(13); if((line_buffer=calloc(BUFSIZE+1, sizeof(char)))==NULL) { printf(NOMEM); return -1; } if((trstr=calloc(BUFSIZE+1, sizeof(char)))==NULL) { printf(NOMEM); return -1; } spr=Read_Neutrino_Cfg("screen_preset")+1; resolution=Read_Neutrino_Cfg("osd_resolution"); if (resolution == -1) sprintf(trstr,"screen_StartX_%s", spres[spr]); else sprintf(trstr,"screen_StartX_%s_%d", spres[spr], resolution); if((sx=Read_Neutrino_Cfg(trstr))<0) sx=scale2res(100); if (resolution == -1) sprintf(trstr,"screen_EndX_%s", spres[spr]); else sprintf(trstr,"screen_EndX_%s_%d", spres[spr], resolution); if((ex=Read_Neutrino_Cfg(trstr))<0) ex=scale2res(1180); if (resolution == -1) sprintf(trstr,"screen_StartY_%s", spres[spr]); else sprintf(trstr,"screen_StartY_%s_%d", spres[spr], resolution); if((sy=Read_Neutrino_Cfg(trstr))<0) sy=scale2res(100); if (resolution == -1) sprintf(trstr,"screen_EndY_%s", spres[spr]); else sprintf(trstr,"screen_EndY_%s_%d", spres[spr], resolution); if((ey=Read_Neutrino_Cfg(trstr))<0) ey=scale2res(620); for(index=CMCST; index<=CMH; index++) { sprintf(trstr,"menu_%s_alpha",menucoltxt[index]); if((tv=Read_Neutrino_Cfg(trstr))>=0) tr[index]=255-(float)tv*2.55; sprintf(trstr,"menu_%s_blue",menucoltxt[index]); if((tv=Read_Neutrino_Cfg(trstr))>=0) bl[index]=(float)tv*2.55; sprintf(trstr,"menu_%s_green",menucoltxt[index]); if((tv=Read_Neutrino_Cfg(trstr))>=0) gn[index]=(float)tv*2.55; sprintf(trstr,"menu_%s_red",menucoltxt[index]); if((tv=Read_Neutrino_Cfg(trstr))>=0) rd[index]=(float)tv*2.55; } if(Read_Neutrino_Cfg("rounded_corners")>0) { radius = scale2res(11); radius_small = scale2res(5); } else radius = radius_small = 0; mtmo = Read_Neutrino_Cfg("timing.menu"); if (mtmo < 0) mtmo = 0; cindex=CMC; for(index=COL_MENUCONTENT_PLUS_0; index<=COL_MENUCONTENT_PLUS_3; index++) { rd[index]=rd[cindex]+25; gn[index]=gn[cindex]+25; bl[index]=bl[cindex]+25; tr[index]=tr[cindex]; cindex=index; } sprintf(trstr,"infobar_alpha"); if((tv=Read_Neutrino_Cfg(trstr))>=0) tr[COL_SHADOW_PLUS_0]=255-(float)tv*2.55; sprintf(trstr,"infobar_blue"); if((tv=Read_Neutrino_Cfg(trstr))>=0) bl[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; sprintf(trstr,"infobar_green"); if((tv=Read_Neutrino_Cfg(trstr))>=0) gn[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; sprintf(trstr,"infobar_red"); if((tv=Read_Neutrino_Cfg(trstr))>=0) rd[COL_SHADOW_PLUS_0]=(float)tv*2.55*0.4; for (index = 0; index <= COL_SHADOW_PLUS_0; index++) bgra[index] = (tr[index] << 24) | (rd[index] << 16) | (gn[index] << 8) | bl[index]; InitRC(); //InitVFD(); //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("%s <FT_Init_FreeType failed with Errorcode 0x%.2X>", __plugin__, error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("%s <FTC_Manager_New failed with Errorcode 0x%.2X>\n", __plugin__, error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("%s <FTC_SBitCache_New failed with Errorcode 0x%.2X>\n", __plugin__, error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } memset(&menu,0,sizeof(MENU)); if(Check_Config()) { printf("%s <Check_Config> Unable to read Config %s\n", __plugin__, CFG_FILE); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); Clear_List(&menu,-1); free(line_buffer); return -1; } if((error = FTC_Manager_LookupFace(manager, FONT, &face))) { printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X, trying default font>\n", __plugin__, error); if((error = FTC_Manager_LookupFace(manager, FONT2, &face))) { printf("%s <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", __plugin__, 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; printf("%s <FTC_Manager_LookupFace Font \"%s\" loaded>\n", __plugin__, desc.face_id); use_kerning = FT_HAS_KERNING(face); desc.flags = FT_LOAD_RENDER | FT_LOAD_FORCE_AUTOHINT; //init backbuffer #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) lbb = lfb + 1920 * 1080; fix_screeninfo.line_length = DEFAULT_XRES * sizeof(uint32_t); stride = DEFAULT_XRES; #else stride = fix_screeninfo.line_length/sizeof(uint32_t); if(stride == 7680 && var_screeninfo.xres == 1280) { var_screeninfo.yres = 1080; } if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)))) { printf("%s <allocating of Backbuffer failed>\n", __plugin__); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } #endif //lbb=lfb; #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0); blit(); #else memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); //blit(); #endif startx = sx; starty = sy; /* scale to resolution */ FSIZE_BIG = scale2res(FSIZE_BIG); FSIZE_MED = scale2res(FSIZE_MED); FSIZE_SMALL = scale2res(FSIZE_SMALL); TABULATOR = scale2res(TABULATOR); OFFSET_MED = scale2res(OFFSET_MED); OFFSET_SMALL = scale2res(OFFSET_SMALL); OFFSET_MIN = scale2res(OFFSET_MIN); /* Set up signal handlers. */ signal(SIGINT, quit_signal); signal(SIGTERM, quit_signal); signal(SIGQUIT, quit_signal); signal(SIGSEGV, quit_signal); index=0; if(vfd) { sprintf(tstr,"%s -c", VFD); system(tstr); } ShowInfo(&menu, 1); //main loop menu.act_entry=0; if(Get_Menu(1)) { printf("%s <unable to create menu>\n", __plugin__); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } cindex=0; put_instance(instance=get_instance()+1); while(mainloop) { cindex=Get_Selection(&menu); dloop=1; switch(cindex) { case -1: mainloop=0; break; case 0: mainloop=Menu_Up(&menu); break; case 1: pl=menu.list[menu.act_entry]; switch (pl->type) { case TYP_MENU: menu.act_header=pl->headerpos; menu.lastheaderentrys[menu.act_header]=menu.act_entry; menu.headerwait[menu.act_header]=pl->message!=NULL; if(menu.headerwait[menu.act_header]) { strcpy(tstr,pl->entry); if((rptr=strxchr(tstr,','))!=NULL) { *rptr=0; } ShowMessage(tstr, pl->message, 0); } Get_Menu(0); menu.act_entry=0; break; case TYP_EXECUTE: if((rptr=strxchr(pl->entry,','))!=NULL) { strcpy(tstr,pl->entry); rptr=strxchr(tstr,','); *rptr=0; rptr=strxchr(pl->entry,','); rptr++; if(pl->stay) { if(pl->stay==1) { if(pl->message) { if(strlen(pl->message)) { ShowMessage(tstr, pl->message, 0); } } else { ShowMessage(tstr, "Bitte warten", 0); } } else { #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0); blit(); #else memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); //blit(); #endif } if(*(rptr+strlen(rptr)-1)=='&') { *(rptr+strlen(rptr)-1)=0; } } else { if(*(rptr+strlen(rptr)-1)!='&') { sprintf(tstr,"%s &",rptr); rptr=tstr; } } CloseRC(); system(rptr); InitRC(); mainloop= pl->stay==1; if(pl->stay==1) { Get_Menu(1); } } break; } } } //cleanup Clear_List(&menu,-1); FTC_Manager_Done(manager); FT_Done_FreeType(library); #if 0 if(strlen(url)) { sprintf(line_buffer,"/sbin/rdate -s %s > /dev/null &",url); system(line_buffer); } #endif CloseRC(); //CloseVFD(); free(line_buffer); free(trstr); // clear Display #if defined(HAVE_SPARK_HARDWARE) || defined(HAVE_DUCKBOX_HARDWARE) FillRect(0, 0, DEFAULT_XRES, DEFAULT_YRES, 0); blit(); #else memset(lbb, TRANSP, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); memcpy(lfb, lbb, var_screeninfo.xres*var_screeninfo.yres*sizeof(uint32_t)); //blit(); #endif munmap(lfb, fix_screeninfo.smem_len); close(fb); #if !defined(MARTII) && !defined(HAVE_SPARK_HARDWARE) && !defined(HAVE_DUCKBOX_HARDWARE) free(lbb); #endif put_instance(get_instance()-1); return 0; }
FTC_CMapCache_Lookup( FTC_CMapCache cmap_cache, FTC_FaceID face_id, FT_Int cmap_index, FT_UInt32 char_code ) { FTC_Cache cache = FTC_CACHE( cmap_cache ); FTC_CMapQueryRec query; FTC_Node node; FT_Error error; FT_UInt gindex = 0; FT_Offset hash; FT_Int no_cmap_change = 0; if ( cmap_index < 0 ) { /* Treat a negative cmap index as a special value, meaning that you */ /* don't want to change the FT_Face's character map through this */ /* call. This can be useful if the face requester callback already */ /* sets the face's charmap to the appropriate value. */ no_cmap_change = 1; cmap_index = 0; } if ( !cache ) { FT_TRACE0(( "FTC_CMapCache_Lookup: bad arguments, returning 0\n" )); return 0; } query.face_id = face_id; query.cmap_index = (FT_UInt)cmap_index; query.char_code = char_code; hash = FTC_CMAP_HASH( face_id, (FT_UInt)cmap_index, char_code ); #if 1 FTC_CACHE_LOOKUP_CMP( cache, ftc_cmap_node_compare, hash, &query, node, error ); #else error = FTC_Cache_Lookup( cache, hash, &query, &node ); #endif if ( error ) goto Exit; FT_ASSERT( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first ) < FTC_CMAP_INDICES_MAX ); /* something rotten can happen with rogue clients */ if ( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first >= FTC_CMAP_INDICES_MAX ) ) return 0; /* XXX: should return appropriate error */ gindex = FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first]; if ( gindex == FTC_CMAP_UNKNOWN ) { FT_Face face; gindex = 0; error = FTC_Manager_LookupFace( cache->manager, FTC_CMAP_NODE( node )->face_id, &face ); if ( error ) goto Exit; if ( (FT_UInt)cmap_index < (FT_UInt)face->num_charmaps ) { FT_CharMap old, cmap = NULL; old = face->charmap; cmap = face->charmaps[cmap_index]; if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, cmap ); gindex = FT_Get_Char_Index( face, char_code ); if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, old ); } FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first] = (FT_UShort)gindex; } Exit: return gindex; }
FTC_CMapCache_Lookup( FTC_CMapCache cmap_cache, FTC_FaceID face_id, FT_Int cmap_index, FT_UInt32 char_code ) { FTC_Cache cache = FTC_CACHE( cmap_cache ); FTC_CMapQueryRec query; FTC_Node node; FT_Error error; FT_UInt gindex = 0; FT_PtrDist hash; FT_Int no_cmap_change = 0; if ( cmap_index < 0 ) { /* Treat a negative cmap index as a special value, meaning that you */ /* don't want to change the FT_Face's character map through this */ /* call. This can be useful if the face requester callback already */ /* sets the face's charmap to the appropriate value. */ no_cmap_change = 1; cmap_index = 0; } if ( !cache ) { FT_TRACE0(( "FTC_CMapCache_Lookup: bad arguments, returning 0\n" )); return 0; } #ifdef FT_CONFIG_OPTION_OLD_INTERNALS /* * If cmap_index is greater than the maximum number of cachable * charmaps, we assume the request is from a legacy rogue client * using old internal header. See include/config/ftoption.h. */ if ( cmap_index > FT_MAX_CHARMAP_CACHEABLE && !no_cmap_change ) { FTC_OldCMapDesc desc = (FTC_OldCMapDesc) face_id; char_code = (FT_UInt32)cmap_index; query.face_id = desc->face_id; switch ( desc->type ) { case FTC_OLD_CMAP_BY_INDEX: query.cmap_index = desc->u.index; query.char_code = (FT_UInt32)cmap_index; break; case FTC_OLD_CMAP_BY_ENCODING: { FT_Face face; error = FTC_Manager_LookupFace( cache->manager, desc->face_id, &face ); if ( error ) return 0; FT_Select_Charmap( face, desc->u.encoding ); return FT_Get_Char_Index( face, char_code ); } default: return 0; } } else #endif /* FT_CONFIG_OPTION_OLD_INTERNALS */ { query.face_id = face_id; query.cmap_index = (FT_UInt)cmap_index; query.char_code = char_code; } hash = FTC_CMAP_HASH( face_id, cmap_index, char_code ); #if 1 FTC_CACHE_LOOKUP_CMP( cache, ftc_cmap_node_compare, hash, &query, node, error ); #else error = FTC_Cache_Lookup( cache, hash, &query, &node ); #endif if ( error ) goto Exit; FT_ASSERT( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first ) < FTC_CMAP_INDICES_MAX ); /* something rotten can happen with rogue clients */ if ( (FT_UInt)( char_code - FTC_CMAP_NODE( node )->first >= FTC_CMAP_INDICES_MAX ) ) return 0; /* XXX: should return appropriate error */ gindex = FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first]; if ( gindex == FTC_CMAP_UNKNOWN ) { FT_Face face; gindex = 0; error = FTC_Manager_LookupFace( cache->manager, FTC_CMAP_NODE( node )->face_id, &face ); if ( error ) goto Exit; #ifdef FT_MAX_CHARMAP_CACHEABLE /* something rotten can happen with rogue clients */ if ( cmap_index > FT_MAX_CHARMAP_CACHEABLE ) return 0; /* XXX: should return appropriate error */ #endif if ( (FT_UInt)cmap_index < (FT_UInt)face->num_charmaps ) { FT_CharMap old, cmap = NULL; old = face->charmap; cmap = face->charmaps[cmap_index]; if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, cmap ); gindex = FT_Get_Char_Index( face, char_code ); if ( old != cmap && !no_cmap_change ) FT_Set_Charmap( face, old ); } FTC_CMAP_NODE( node )->indices[char_code - FTC_CMAP_NODE( node )->first] = (FT_UShort)gindex; } Exit: return gindex; }
int main (int argc, char **argv) { int tv,index,i,j,cmct=CMCT,cmc=CMC,trnspi=TRANSP,trnsp=0,found,loop=1,first=1,x0,x1,x2,x3,x4,x5,x6,x7; int xdir=1, ydir=1; double xstep=1, ystep=1; double csx, cex, csy, cey; time_t atim; struct tm *ltim; char *aptr,*rptr; char dstr[2]= {0,0}; printf("SSaver Version %s\n",CL_VERSION); ReadConf(); for(i=1; i<argc; i++) { aptr=argv[i]; if((rptr=strchr(aptr,'='))!=NULL) { rptr++; if(strstr(aptr,"DATE=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { sdat=j; } } if(strstr(aptr,"BIG=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { big=(j)?1:0; } } if(strstr(aptr,"SEC=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { secs=j; } } if(strstr(aptr,"SLOW=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { if(!j) { j=1; } slow=j; } } if(strstr(aptr,"FCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { fcol=j; } } if(strstr(aptr,"BCOL=")!=NULL) { if(sscanf(rptr,"%d",&j)==1) { bcol=j; } } } } if((sx=Read_Neutrino_Cfg("screen_StartX"))<0) sx=80; if((ex=Read_Neutrino_Cfg("screen_EndX"))<0) ex=620; if((sy=Read_Neutrino_Cfg("screen_StartY"))<0) sy=80; if((ey=Read_Neutrino_Cfg("screen_EndY"))<0) ey=505; if(!slow) { slow=1; } if(slow>10) { slow=10; } xpos=ex/2; ypos=ey/2; for(index=CMCST; index<=CMH; index++) { sprintf(tstr,"menu_%s_alpha",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) tr[index-1]=(tv<<8); sprintf(tstr,"menu_%s_blue",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) bl[index-1]=(tv+(tv<<8)); sprintf(tstr,"menu_%s_green",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) gn[index-1]=(tv+(tv<<8)); sprintf(tstr,"menu_%s_red",menucoltxt[index-1]); if((tv=Read_Neutrino_Cfg(tstr))>=0) rd[index-1]=(tv+(tv<<8)); } fb = open(FB_DEVICE, O_RDWR); if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { printf("Clock <FBIOGET_FSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { printf("Clock <FBIOGET_VSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGETCMAP, &colormap) == -1) { printf("Clock <FBIOGETCMAP failed>\n"); return -1; } if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { printf("Clock <mapping of Framebuffer failed>\n"); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("Clock <FT_Init_FreeType failed with Errorcode 0x%.2X>", error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("Clock <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("Clock <FTC_SBitCache_New failed with Errorcode 0x%.2X>\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))) { printf("Clock <FTC_Manager_LookupFace failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } use_kerning = FT_HAS_KERNING(face); desc.face_id = FONT; desc.flags = FT_LOAD_MONOCHROME; if(!(lbb = malloc(var_screeninfo.xres*var_screeninfo.yres))) { printf("Clock <allocating of Backbuffer failed>\n"); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } memset(lbb, 0, var_screeninfo.xres*var_screeninfo.yres); startx = sx; starty = sy; xstep/=(double)slow; ystep/=(double)slow; InitRC(); while(loop) { usleep(15000L); ioctl(fb, FBIOGETCMAP, &colormap); found=0; trnsp=0; for(i=colormap.start; i<colormap.len && found!=7; i++) { if(!colormap.red[i] && !colormap.green[i] && !colormap.blue[i] && !colormap.transp[i]) { cmc=i; found|=1; } if(colormap.red[i]>=0xF000 && colormap.green[i]>=0xF000 && colormap.blue[i]>=0xF000 && !colormap.transp[i]) { cmct=i; found|=2; } if(colormap.transp[i]>trnsp) { trnspi=i; trnsp=colormap.transp[i]; found|=4; } } if(first) { first=0; memset(lbb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres); memset(lfb, (bcol==0)?trnspi:((bcol==1)?cmc:cmct), var_screeninfo.xres*var_screeninfo.yres); } if(big) { x0=3; x1=14; x2=26; x3=BIG; x4=30; x5=60; } else { x0=7; x1=12; x2=18; x3=MED; x4=18; x5=40; } x6=0; x7=0; time(&atim); ltim=localtime(&atim); if(secs) { sprintf(tstr,"%02d:%02d:%02d",ltim->tm_hour,ltim->tm_min,ltim->tm_sec); } else { sprintf(tstr," %02d%c%02d",ltim->tm_hour,(ltim->tm_sec & 1)?':':' ',ltim->tm_min); if(!sdat) { x6=3; x7=36+4*big; } } xpos+=xstep*(double)xdir; ypos+=ystep*(double)ydir; csx=xpos+x7; csy=ypos; cex=xpos+x7+100+20*big; cey=ypos+x2+2*(1+big)+sdat*x4; if(csx<0 || (sx+cex)>=ex) { xdir*=-1; xpos+=xstep*(double)xdir; csx=xpos+x7; cex=xpos+x7+100+20*big; xstep=rand()&3; if(!xstep) { xstep=1; } xstep/=(double)slow; } if(csy<0 || (sy+cey)>=ey) { ydir*=-1; ypos+=ystep*(double)ydir; csy=ypos; cey=ypos+x2+2*(1+big)+sdat*x4; ystep=rand()&3; if(!ystep || (ystep==3 && ydir==1)) { ystep=1; } ystep/=(double)slow; } for(i=x6; i<strlen(tstr); i++) { *dstr=tstr[i]; RenderString(dstr, xpos-x0+(i*x1), ypos+x2, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc)); } if(sdat) { sprintf(tstr,"%02d.%02d.%02d",ltim->tm_mday,ltim->tm_mon+1,ltim->tm_year-100); for(i=0; i<strlen(tstr); i++) { *dstr=tstr[i]; RenderString(dstr, xpos-x0+(i*x1), ypos+x5-2-2*big, 30, CENTER, x3, (fcol==0)?trnspi:((fcol==2)?cmct:cmc)); } } for(i=0; i<=((sdat)?40:20)*(1+big); i++) { j=(starty+ypos+i)*var_screeninfo.xres+xpos+startx; if((j+100+20*big)<var_screeninfo.xres*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, 100+20*big); } } RenderBox(csx, csy, cex, cey, FILL, (bcol==0)?trnspi:((bcol==1)?cmc:cmct)); if(++loop>10) { if(RCKeyPressed()||ExistFile("/tmp/.ssaver_kill")) { loop=0; } } } cmct=0; cmc=0; for(i=colormap.start; i<colormap.len; i++) { if(colormap.transp[i]>cmct) { cmc=i; cmct=colormap.transp[i]; } } memset(lfb, cmc, var_screeninfo.xres*var_screeninfo.yres); FTC_Manager_Done(manager); FT_Done_FreeType(library); free(lbb); munmap(lfb, fix_screeninfo.smem_len); close(fb); CloseRC(); remove("/tmp/.ssaver_kill"); return 0; }
int main (int argc, char **argv) { int i,j,found=0,m,mask=1,kmode=1,pmode=0, lc=-1, changed=0, todo=1, help=1, help_changed=0, move=0; unsigned char actchan[20]=""/*,channel[128]=""*/; FILE *fh,*fh2; char *cpt1,*cpt2; gpixel mp, mc[MAX_MASK], tp; int tsx=430, tsy=120, tdy=24, tsz=28, txw=500, tcol=TURQUOISE; int xp[MAX_MASK][8],yp[MAX_MASK][8],xw[MAX_MASK][8],yw[MAX_MASK][8],valid[MAX_MASK],cmc[MAX_MASK],xxp,xxw,yyp,yyw,nmsk=0,amsk=0; double xs=1.0, ys=1.0; time_t t1,t2; for(j=0; j<MAX_MASK; j++) { valid[j]=0; cmc[j]=BLACK; make_color(BLACK, &mc[j]); for(i=0; i<8; i++) { xp[j][i]=(1280-40)/2; xw[j][i]=40; yp[j][i]=(720-20)/2; yw[j][i]=20; } } system("pzapit -var > /tmp/logomaskset.stat"); if((fh=fopen("/tmp/logomaskset.stat","r"))!=NULL) { if(fgets(tstr,500,fh)) { TrimString(tstr); if(strlen(tstr)) { if(sscanf(tstr+strlen(tstr)-1,"%d",&pmode)!=1) { pmode=0; } } } fclose(fh); } system("touch /tmp/.logomask_kill"); fb = open(FB_DEVICE, O_RDWR); if(ioctl(fb, FBIOGET_FSCREENINFO, &fix_screeninfo) == -1) { printf("logomask <FBIOGET_FSCREENINFO failed>\n"); return -1; } if(ioctl(fb, FBIOGET_VSCREENINFO, &var_screeninfo) == -1) { printf("logomask <FBIOGET_VSCREENINFO failed>\n"); return -1; } if(!(lfb = (unsigned char*)mmap(0, fix_screeninfo.smem_len, PROT_READ | PROT_WRITE, MAP_SHARED, fb, 0))) { printf("logomask <mapping of Framebuffer failed>\n"); return -1; } //init fontlibrary if((error = FT_Init_FreeType(&library))) { printf("logomask <FT_Init_FreeType failed with Errorcode 0x%.2X>", error); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_Manager_New(library, 1, 2, 0, &MyFaceRequester, NULL, &manager))) { printf("logomask <FTC_Manager_New failed with Errorcode 0x%.2X>\n", error); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } if((error = FTC_SBitCache_New(manager, &cache))) { printf("logomask <FTC_SBitCache_New failed with Errorcode 0x%.2X>\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))) { printf("logomask <FTC_Manager_Lookup_Face failed with Errorcode 0x%.2X>\n", error); FTC_Manager_Done(manager); FT_Done_FreeType(library); munmap(lfb, fix_screeninfo.smem_len); return -1; } use_kerning = FT_HAS_KERNING(face); desc.face_id = FONT; desc.flags = FT_LOAD_MONOCHROME; InitRC(); //init backbuffer if(!(lbb = malloc(fix_screeninfo.line_length*var_screeninfo.yres))) { printf("logomask <allocating of Backbuffer failed>\n"); munmap(lfb, fix_screeninfo.smem_len); return -1; } memset(lbb, 0, fix_screeninfo.line_length*var_screeninfo.yres); system("pzapit -gi > /tmp/logomask.chan"); if((fh=fopen("/tmp/logomask.chan","r"))!=NULL) { if(fgets(tstr, BUFSIZE, fh)) { TrimString(tstr); if((cpt1=strchr(tstr,' '))!=NULL) *cpt1=0; } fclose(fh); if(strlen(tstr)) { strcpy(actchan,tstr); } if((fh=fopen(CFG_FILE,"r"))!=NULL) { found=0; while(fgets(tstr, BUFSIZE, fh) && !found) { TrimString(tstr); if(strlen(tstr)) { if(strstr(tstr,actchan)!=NULL) { mask=1; nmsk=0; cpt2=strstr(tstr,",MC"); if((cpt1=strchr(tstr,','))!=NULL) { while(cpt1) { valid[nmsk]=0; if(cpt2 && sscanf(cpt2+1,"MC%8X",&mp.lpixel)==1) { cpt2=strchr(cpt2+1,','); } else { make_color(BLACK, &mp); } for(i=0; i<8 && cpt1; i++) { cpt1++; if(sscanf(cpt1,"%d,%d,%d,%d",&xxp,&xxw,&yyp,&yyw)==4) { xp[nmsk][i]=xxp; xw[nmsk][i]=xxw; yp[nmsk][i]=yyp; yw[nmsk][i]=yyw; mc[nmsk].lpixel=mp.lpixel; found=1; valid[nmsk]=1; } for(j=0; j<4 && cpt1; j++) { cpt1=strchr(cpt1+1,','); } } if(valid[nmsk]) { nmsk++; } } } } } } fclose(fh); } } if(!nmsk) { nmsk=1; valid[0]=1; } mask=nmsk; for(m=0; m<MAX_MASK; m++) { if(valid[m]) { xxp=xp[m][pmode]; xxw=xw[m][pmode]; yyp=yp[m][pmode]; yyw=yw[m][pmode]; tp.lpixel=mc[m].lpixel; RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &tp); if(m==amsk) RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, GRID, make_color(LBLUE,&tp)); for(i=0;i<=yyw;i++) { j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2); if((j+(xxw<<2))<fix_screeninfo.line_length*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, xxw<<2); } } } } time(&t1); while((rc!=KEY_EXIT) && (rc!=KEY_OK)) { rc=GetRCCode(); if((rc!=-1) && (rc!=KEY_EXIT) && (rc!=KEY_OK)) { time(&t1); move=0; xxp=xp[amsk][pmode]; xxw=xw[amsk][pmode]; yyp=yp[amsk][pmode]; yyw=yw[amsk][pmode]; lpix.lpixel=mc[amsk].lpixel; switch(rc) { case KEY_LEFT: if(lc==KEY_LEFT) { xs+=0.3; } else { xs=1.0; } if(kmode) { if(xxp>0) { changed=1; xxp-=xs; } } else { if(xxw>6) { changed=1; xxw-=xs; } } move=1; break; case KEY_RIGHT: if((xxp+xxw)<(fix_screeninfo.line_length-1)) { changed=1; if(lc==KEY_RIGHT) { xs+=0.3; } else { xs=1.0; } if(kmode) { xxp+=xs; } else { xxw+=xs; } } move=1; break; case KEY_UP: if(lc==KEY_UP) { ys+=0.2; } else { ys=1.0; } if(kmode) { if(yyp>0) { changed=1; yyp-=ys; } } else { if(yyw>6) { changed=1; yyw-=ys; } } move=1; break; case KEY_DOWN: if((yyp+yyw)<(var_screeninfo.yres-1)) { changed=1; if(lc==KEY_DOWN) { ys+=0.2; } else { ys=1.0; } if(kmode) { yyp+=ys; } else { yyw+=ys; } } move=1; break; case KEY_RED: changed=1; RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, make_color(TRANSP,&tp)); for(i=0;i<=yyw;i++) { j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2); if(((j+(xxw<<2)))<fix_screeninfo.line_length*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, xxw<<2); } } valid[amsk]=0; nmsk--; kmode=1; if(nmsk) { todo=2; amsk=-1; for(m=0; m<MAX_MASK && amsk<0; m++) { if(valid[m]) { amsk=m; xxp=xp[amsk][pmode]; xxw=xw[amsk][pmode]; yyp=yp[amsk][pmode]; yyw=yw[amsk][pmode]; lpix.lpixel=mc[amsk].lpixel; } } } else { todo=mask=0; } break; case KEY_GREEN: if(nmsk<MAX_MASK) { todo=2; changed=1; kmode=1; amsk=-1; for(m=0; amsk<0 && m<MAX_MASK; m++) { if(!valid[m]) { amsk=m; valid[amsk]=1; nmsk++; cmc[amsk]=BLACK; make_color(BLACK, &mc[amsk]); for(i=0; i<8; i++) { xp[amsk][i]=(1280-40)/2; xw[amsk][i]=40; yp[amsk][i]=(720-20)/2; yw[amsk][i]=20; } xxp=xp[amsk][pmode]; xxw=xw[amsk][pmode]; yyp=yp[amsk][pmode]; yyw=yw[amsk][pmode]; lpix.lpixel=mc[amsk].lpixel; } } } break; case KEY_PAGEUP: if(nmsk>1) { m=amsk+1; if(m>=MAX_MASK) { m=0; } while(!valid[m]) { if(++m>=MAX_MASK) { m=0; } } RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &lpix); amsk=m; xxp=xp[amsk][pmode]; xxw=xw[amsk][pmode]; yyp=yp[amsk][pmode]; yyw=yw[amsk][pmode]; lpix.lpixel=mc[amsk].lpixel; } break; case KEY_PAGEDOWN: if(nmsk>1) { m=amsk-1; if(m<0) { m=MAX_MASK-1; } while(!valid[m]) { if(--m<0) { m=MAX_MASK; } } RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, &lpix); amsk=m; xxp=xp[amsk][pmode]; xxw=xw[amsk][pmode]; yyp=yp[amsk][pmode]; yyw=yw[amsk][pmode]; lpix.lpixel=mc[amsk].lpixel; } break; case KEY_YELLOW: kmode=0; break; case KEY_BLUE: kmode=1; break; case KEY_1: if(nmsk) { if(mc[amsk].cpixel.rd < 0xF0) mc[amsk].cpixel.rd+=0x10; else mc[amsk].cpixel.rd=0xFF; changed=1; } break; case KEY_4: if(nmsk) { mc[amsk].cpixel.rd=0x80; changed=1; } break; case KEY_7: if(nmsk) { if(mc[amsk].cpixel.rd > 0x0F) mc[amsk].cpixel.rd-=0x10; else mc[amsk].cpixel.rd=0x00; changed=1; } break; case KEY_2: if(nmsk) { if(mc[amsk].cpixel.gn < 0xF0) mc[amsk].cpixel.gn+=0x10; else mc[amsk].cpixel.gn=0xFF; changed=1; } break; case KEY_5: if(nmsk) { mc[amsk].cpixel.gn=0x80; changed=1; } break; case KEY_8: if(nmsk) { if(mc[amsk].cpixel.gn > 0x0F) mc[amsk].cpixel.gn-=0x10; else mc[amsk].cpixel.gn=0x00; changed=1; } break; case KEY_3: if(nmsk) { if(mc[amsk].cpixel.bl < 0xF0) mc[amsk].cpixel.bl+=0x10; else mc[amsk].cpixel.bl=0xFF; changed=1; } break; case KEY_6: if(nmsk) { mc[amsk].cpixel.bl=0x80; changed=1; } break; case KEY_9: if(nmsk) { if(mc[amsk].cpixel.bl > 0x0F) mc[amsk].cpixel.bl-=0x10; else mc[amsk].cpixel.bl=0x00; changed=1; } break; case KEY_VOLUMEDOWN: if(nmsk) { if(mc[amsk].cpixel.tr < 0xF8) mc[amsk].cpixel.tr+=0x08; else mc[amsk].cpixel.tr=0xFF; changed=1; } break; case KEY_VOLUMEUP: if(nmsk) { if(mc[amsk].cpixel.tr > 0x08) mc[amsk].cpixel.tr-=0x08; else mc[amsk].cpixel.tr=0x00; changed=1; } break; case KEY_MUTE: if(nmsk) { if(++cmc[amsk]>LTURQUOISE) cmc[amsk]=BLACK; make_color(cmc[amsk], &mc[amsk]); changed=1; } break; case KEY_HELP: help_changed=1; break; } lc=rc; lpix.lpixel=mc[amsk].lpixel; if(mask || todo==2) { RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], FILL, make_color(TRANSP, &tp)); for(i=0;i<=yw[amsk][pmode];i++) { j=(yp[amsk][pmode]+i)*fix_screeninfo.line_length+(xp[amsk][pmode]<<2); if((j+(xw[amsk][pmode]<<2))<fix_screeninfo.line_length*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, (xw[amsk][pmode]+1)<<2); } } xp[amsk][pmode]=xxp; xw[amsk][pmode]=xxw; yp[amsk][pmode]=yyp; yw[amsk][pmode]=yyw; for(m=0; mask && m<MAX_MASK; m++) { if(valid[m]) { xxp=xp[m][pmode]; xxw=xw[m][pmode]; yyp=yp[m][pmode]; yyw=yw[m][pmode]; tp.lpixel=mc[m].lpixel; RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, FILL, ((m==amsk) && move)?make_color(TRANSP, &tp):&tp); if(m==amsk) RenderBox(xxp, yyp, xxp+xxw, yyp+yyw, GRID, make_color((kmode)?LBLUE:LYELLOW,&tp)); for(i=0;i<=yyw;i++) { j=(yyp+i)*fix_screeninfo.line_length+(xxp<<2); if((j+(xxw<<2))<fix_screeninfo.line_length*var_screeninfo.yres) { memcpy(lfb+j, lbb+j, (xxw+1)<<2); } } } } } } time(&t2); if((t2-t1)>1) { xs=1.0; ys=1.0; tsy=120; if(move) { RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], FILL, &mc[amsk]); RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW,&tp)); } move=0; if(help_changed) { help^=1; } if(help) { RenderBox(tsx,tsy,tsx+txw,tsy+21*tdy,FILL,make_color(TRANSP, &tp)); if(nmsk) RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW, &tp)); RenderString("Maskensteuerung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Blau : Umschalten auf Positionseinstellung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Gelb : Umschalten auf Größeneinstellung", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Grün : Maske hinzufügen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Rot : Maske löschen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("PgUp : nächste Maske auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("PgDn : vorherige Maske auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Maskenfarbe", tsx, tsy+=(2*tdy), txw, LEFT, tsz, tcol); RenderString("Mute : Maskenfarbe aus Vorgabe auswählen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("1,4,7 : Farbton Rot erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("2,5,8 : Farbton Grün erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("3,6,9 : Farbton Blau erhöhen, auf Mitte setzen, verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Vol + : Transparenz erhöhen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Vol - : Transparenz verringern", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Allgemein", tsx, tsy+=(2*tdy), txw, LEFT, tsz, tcol); RenderString("? : Hilfetext ein/ausschalten", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("Exit : Abbrechen", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); RenderString("OK : Speichern und Beenden", tsx, tsy+=tdy, txw, LEFT, tsz, tcol); } else { if(help_changed) { RenderBox(tsx, tsy, tsx+txw, tsy+21*tdy, FILL, make_color(TRANSP, &tp)); if(nmsk) RenderBox(xp[amsk][pmode], yp[amsk][pmode], xp[amsk][pmode]+xw[amsk][pmode], yp[amsk][pmode]+yw[amsk][pmode], GRID, make_color((kmode)?LBLUE:LYELLOW, &tp)); } } help_changed=0; memcpy(lfb, lbb, fix_screeninfo.line_length*var_screeninfo.yres); } } if(rc==KEY_EXIT) { changed=0; todo=0; } if(rc==KEY_OK && changed) { if((fh2=fopen("/tmp/logomask.conf","w"))!=NULL) { fh=fopen(CFG_FILE,"r"); while(fh && fgets(tstr, BUFSIZE, fh)) { TrimString(tstr); if(strlen(tstr)) { if(strstr(tstr,actchan)==NULL) { fprintf(fh2,"%s\n",tstr); } } } if(fh) { fclose(fh); } if(todo) { fprintf(fh2,"%s",actchan); for(j=0; j<MAX_MASK; j++) { if(valid[j]) { for(i=0; i<8; i++) { fprintf(fh2,",%d,%d,%d,%d",xp[j][i],xw[j][i],yp[j][i],yw[j][i]); } } } for(j=0; j<MAX_MASK; j++) { if(valid[j]) { fprintf(fh2,",MC%08X",mc[j].lpixel); } } fprintf(fh2,",\n"); } fclose(fh2); remove(CFG_FILE); system("mv /tmp/logomask.conf /var/tuxbox/config/logomask.conf"); } } free(lbb); munmap(lfb, fix_screeninfo.smem_len); close(fb); CloseRC(); remove("/tmp/.logomask_kill"); remove("/tmp/logomaskset.*"); system("logomask &"); return 0; }