int load_font(char *fname, int size) { char *p; free_font(); font = TTF_OpenFont(fname, size); if (!font) { //Try to open the in memory font SDL_RWops *s; s = SDL_RWFromMem(dejavu_sans_ttf, dejavu_sans_ttf_len); font = TTF_OpenFontRW(s, 0, size); if (font) { __android_log_print(ANDROID_LOG_INFO, "BroovPlayer", "Open font from memory successful"); } else { __android_log_print(ANDROID_LOG_INFO, "BroovPlayer", "Open font from memory failed:%s", TTF_GetError()); return 3; } } /* print some metrics and attributes */ //printf("size : %d\n",size); //printf("TTF_FontHeight : %d\n",TTF_FontHeight(font)); //printf("TTF_FontAscent : %d\n",TTF_FontAscent(font)); //printf("TTF_FontDescent : %d\n",TTF_FontDescent(font)); //printf("TTF_FontLineSkip : %d\n",TTF_FontLineSkip(font)); //printf("TTF_FontFaceIsFixedWidth: %d\n",TTF_FontFaceIsFixedWidth(font)); /* cache new glyphs */ cache_glyphs(); return 0; }
//Basic Init, create the font, backbuffer, etc WINDOW *initscr(void) { lastchar=-1; inputdelay=-1; std::string typeface = ""; std::ifstream fin; int fontsize = 0; //actuall size fin.open("data/FONTDATA"); if (!fin.is_open()){ fontheight=16; fontwidth=8; } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; fin >> fontsize; if ((fontwidth <= 4) || (fontheight <=4)){ fontheight=16; fontwidth=8; } fin.close(); } halfwidth=fontwidth / 2; halfheight=fontheight / 2; WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth; WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight; if(!WinCreate()) {}// do something here //make fontdata compatible with wincurse if(!fexists(typeface.c_str())) typeface = "data/font/" + typeface + ".ttf"; //different default font with wincurse if(!fexists(typeface.c_str())) typeface = "data/font/fixedsys.ttf"; if(fontsize<=0) fontsize=fontheight-1; font = TTF_OpenFont(typeface.c_str(), fontsize); //if(!font) something went wrong TTF_SetFontStyle(font, TTF_STYLE_NORMAL); //TTF_SetFontOutline(font, 0); //TTF_SetFontKerning(font, 0); //TTF_SetFontHinting(font, TTF_HINTING_MONO); // glyph height hack by utunnels // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics // this causes baseline problems for certain fonts // I can only guess by check a certain tall character... cache_glyphs(); mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0); return mainwin; //create the 'stdscr' window and return its ref }
void load_font(char *fname, int size) { char *p; free_font(); font=TTF_OpenFont(fname, size); if(!font) { printf("TTF_OpenFont: %s\n", TTF_GetError()); exit(3); } /* print some metrics and attributes */ printf("size : %d\n",size); printf("TTF_FontHeight : %d\n",TTF_FontHeight(font)); printf("TTF_FontAscent : %d\n",TTF_FontAscent(font)); printf("TTF_FontDescent : %d\n",TTF_FontDescent(font)); printf("TTF_FontLineSkip : %d\n",TTF_FontLineSkip(font)); printf("TTF_FontFaceIsFixedWidth: %d\n",TTF_FontFaceIsFixedWidth(font)); { char *str=TTF_FontFaceFamilyName(font); if(!str) str="(null)"; printf("TTF_FontFaceFamilyName : \"%s\"\n",str); } { char *str=TTF_FontFaceStyleName(font); if(!str) str="(null)"; printf("TTF_FontFaceStyleName : \"%s\"\n",str); } if(TTF_GlyphIsProvided(font,'g')) { int minx, maxx, miny, maxy, advance; TTF_GlyphMetrics(font,'g', &minx, &maxx, &miny, &maxy, &advance); printf("TTF_GlyphMetrics('g'):\n\tminx=%d\n\tmaxx=%d\n\tminy=%d\n\tmaxy=%d\n\tadvance=%d\n", minx, maxx, miny, maxy, advance); } else printf("TTF_GlyphMetrics('g'): unavailable in font!\n"); /* set window title and icon name, using filename and stuff */ p=strrchr(fname,'/'); if(!p) p=strrchr(fname,'\\'); if(!p) p=strrchr(fname,':'); if(!p) p=fname; else p++; /* cache new glyphs */ cache_glyphs(); }
void cache_standard_glyphs(struct ft2_source *srcdata) { for (uint32_t i = 0; i < num_cache_slots; i++) { if (srcdata->cacheglyphs[i] != NULL) { bfree(srcdata->cacheglyphs[i]); srcdata->cacheglyphs[i] = NULL; } } srcdata->texbuf_x = 0; srcdata->texbuf_y = 0; cache_glyphs(srcdata, L"abcdefghijklmnopqrstuvwxyz" \ L"ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890" \ L"!@#$%^&*()-_=+,<.>/?\\|[]{}`~ \'\"\0"); }
static void ft2_video_tick(void *data, float seconds) { struct ft2_source *srcdata = data; if (srcdata == NULL) return; if (!srcdata->from_file || !srcdata->text_file) return; if (os_gettime_ns() - srcdata->last_checked >= 1000000000) { time_t t = get_modified_timestamp(srcdata->text_file); srcdata->last_checked = os_gettime_ns(); if (srcdata->m_timestamp != t) { if (srcdata->log_mode) read_from_end(srcdata, srcdata->text_file); else load_text_from_file(srcdata, srcdata->text_file); cache_glyphs(srcdata, srcdata->text); set_up_vertex_buffer(srcdata); } } UNUSED_PARAMETER(seconds); }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { lastchar=-1; inputdelay=-1; std::string typeface = ""; std::string blending = "solid"; std::ifstream fin; int faceIndex = 0; int fontsize = 0; //actuall size fin.open("data/FONTDATA"); if (!fin.is_open()){ fontheight=16; fontwidth=8; } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; fin >> fontsize; fin >> blending; if ((fontwidth <= 4) || (fontheight <= 4)) { fontheight=16; fontwidth=8; } fin.close(); } fontblending = (blending=="blended"); halfwidth=fontwidth / 2; halfheight=fontheight / 2; WindowWidth= (55 + (OPTIONS[OPT_VIEWPORT_X] * 2 + 1)) * fontwidth; WindowHeight= (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1) *fontheight; if(!WinCreate()) {}// do something here std::string sysfnt = find_system_font(typeface, faceIndex); if(sysfnt!="") typeface = sysfnt; //make fontdata compatible with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/" + typeface + ".ttf"; } //different default font with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/fixedsys.ttf"; } if(fontsize <= 0) fontsize = fontheight - 1; // STL_ttf handles bitmap fonts size incorrectly if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon")) faceIndex = test_face_size(typeface, fontsize, faceIndex); font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex); //if(!font) something went wrong TTF_SetFontStyle(font, TTF_STYLE_NORMAL); // glyph height hack by utunnels // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics // this causes baseline problems for certain fonts // I can only guess by check a certain tall character... cache_glyphs(); mainwin = newwin((OPTIONS[OPT_VIEWPORT_Y] * 2 + 1),(55 + (OPTIONS[OPT_VIEWPORT_Y] * 2 + 1)),0,0); return mainwin; //create the 'stdscr' window and return its ref }
static void ft2_source_update(void *data, obs_data_t settings) { struct ft2_source *srcdata = data; obs_data_t font_obj = obs_data_get_obj(settings, "font"); bool vbuf_needs_update = false; bool word_wrap = false; uint32_t color[2]; uint32_t custom_width = 0; const char *font_name = obs_data_get_string(font_obj, "face"); const char *font_style = obs_data_get_string(font_obj, "style"); uint16_t font_size = (uint16_t)obs_data_get_int(font_obj, "size"); uint32_t font_flags = (uint32_t)obs_data_get_int(font_obj, "flags"); if (!font_obj) return; srcdata->drop_shadow = obs_data_get_bool(settings, "drop_shadow"); srcdata->outline_text = obs_data_get_bool(settings, "outline"); word_wrap = obs_data_get_bool(settings, "word_wrap"); color[0] = (uint32_t)obs_data_get_int(settings, "color1"); color[1] = (uint32_t)obs_data_get_int(settings, "color2"); custom_width = (uint32_t)obs_data_get_int(settings, "custom_width"); if (custom_width >= 100) { if (custom_width != srcdata->custom_width) { srcdata->custom_width = custom_width; vbuf_needs_update = true; } } else { if (srcdata->custom_width >= 100) vbuf_needs_update = true; srcdata->custom_width = 0; } if (word_wrap != srcdata->word_wrap) { srcdata->word_wrap = word_wrap; vbuf_needs_update = true; } if (color[0] != srcdata->color[0] || color[1] != srcdata->color[1]) { srcdata->color[0] = color[0]; srcdata->color[1] = color[1]; vbuf_needs_update = true; } bool from_file = obs_data_get_bool(settings, "from_file"); bool chat_log_mode = obs_data_get_bool(settings, "log_mode"); srcdata->log_mode = chat_log_mode; if (ft2_lib == NULL) goto error; if (srcdata->draw_effect == NULL) { char *effect_file = NULL; char *error_string = NULL; effect_file = obs_module_file("text_default.effect"); if (effect_file) { obs_enter_graphics(); srcdata->draw_effect = gs_effect_create_from_file( effect_file, &error_string); obs_leave_graphics(); bfree(effect_file); if (error_string != NULL) bfree(error_string); } } if (srcdata->font_size != font_size || srcdata->from_file != from_file) vbuf_needs_update = true; srcdata->file_load_failed = false; srcdata->from_file = from_file; if (srcdata->font_name != NULL) { if (strcmp(font_name, srcdata->font_name) == 0 && strcmp(font_style, srcdata->font_style) == 0 && font_flags == srcdata->font_flags && font_size == srcdata->font_size) goto skip_font_load; bfree(srcdata->font_name); bfree(srcdata->font_style); srcdata->font_name = NULL; srcdata->font_style = NULL; srcdata->max_h = 0; } srcdata->font_name = bstrdup(font_name); srcdata->font_style = bstrdup(font_style); srcdata->font_size = font_size; srcdata->font_flags = font_flags; if (!init_font(srcdata) || srcdata->font_face == NULL) { blog(LOG_WARNING, "FT2-text: Failed to load font %s", srcdata->font_name); goto error; } else { FT_Set_Pixel_Sizes(srcdata->font_face, 0, srcdata->font_size); FT_Select_Charmap(srcdata->font_face, FT_ENCODING_UNICODE); } if (srcdata->texbuf != NULL) { bfree(srcdata->texbuf); srcdata->texbuf = NULL; } srcdata->texbuf = bzalloc(texbuf_w * texbuf_h * 4); if (srcdata->font_face) cache_standard_glyphs(srcdata); skip_font_load:; if (from_file) { const char *tmp = obs_data_get_string(settings, "text_file"); if (!tmp || !*tmp) { blog(LOG_WARNING, "FT2-text: Failed to open %s for reading", tmp); goto error; } if (srcdata->text_file != NULL && strcmp(srcdata->text_file, tmp) == 0 && !vbuf_needs_update) goto error; bfree(srcdata->text_file); srcdata->text_file = bstrdup(tmp); if (chat_log_mode) read_from_end(srcdata, tmp); else load_text_from_file(srcdata, tmp); srcdata->last_checked = os_gettime_ns(); } else { const char *tmp = obs_data_get_string(settings, "text"); if (!tmp || !*tmp) goto error; if (srcdata->text != NULL) { bfree(srcdata->text); srcdata->text = NULL; } os_utf8_to_wcs_ptr(tmp, strlen(tmp), &srcdata->text); } if (srcdata->font_face) { cache_glyphs(srcdata, srcdata->text); set_up_vertex_buffer(srcdata); } error: obs_data_release(font_obj); }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { lastchar = -1; inputdelay = -1; std::string typeface = "Terminus"; std::string blending = "solid"; std::ifstream fin; int faceIndex = 0; int fontsize = 0; //actuall size fin.open("data/FONTDATA"); if (!fin.is_open()){ fontwidth = 8; fontheight = 16; std::ofstream fout;//create data/FONDATA file fout.open("data/FONTDATA"); if(fout.is_open()) { fout << typeface << "\n"; fout << fontwidth << "\n"; fout << fontheight; fout.close(); } } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; fin >> fontsize; fin >> blending; if ((fontwidth <= 4) || (fontheight <= 4)) { fontheight = 16; fontwidth = 8; } fin.close(); } fontblending = (blending=="blended"); halfwidth=fontwidth / 2; halfheight=fontheight / 2; if(!InitSDL()) { DebugLog() << (std::string)"Failed to initialize SDL!\n"; } #ifdef SDLTILES DebugLog() << "Initializing SDL Tiles context\n"; tilecontext = new cata_tiles; tilecontext->init("gfx"); #endif // SDLTILES DebugLog() << (std::string)"Tiles initialized successfully.\n"; WindowWidth= OPTIONS["TERMINAL_X"]; if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH; WindowWidth *= fontwidth; WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight; if(!WinCreate()) { DebugLog() << (std::string)"Failed to create game window!\n"; return NULL; } #ifdef SDLTILES tilecontext->set_screen(screen); while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") || !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) { SDL_Surface *asciiload; typeface = "data/font/" + typeface; asciiload = IMG_Load(typeface.c_str()); if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) { SDL_FreeSurface(asciiload); break; } Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF); SDL_SetColorKey(asciiload,SDL_SRCCOLORKEY,key); ascii[0] = SDL_DisplayFormat(asciiload); SDL_FreeSurface(asciiload); for(int a = 1; a < 16; a++) { ascii[a]=SDL_ConvertSurface(ascii[0],ascii[0]->format,ascii[0]->flags); } init_colors(); for(int a = 0; a < 15; a++) { SDL_LockSurface(ascii[a]); int size = ascii[a]->h * ascii[a]->w; Uint32 *pixels = (Uint32 *)ascii[a]->pixels; Uint32 color = (windowsPalette[a].r << 16) | (windowsPalette[a].g << 8) | windowsPalette[a].b; for(int i=0;i<size;i++) { if(pixels[i] == 0xFFFFFF) pixels[i] = color; } SDL_UnlockSurface(ascii[a]); } if(fontwidth)tilewidth=ascii[0]->w/fontwidth; OutputChar = &OutputImageChar; mainwin = newwin(OPTIONS["TERMINAL_Y"], OPTIONS["TERMINAL_X"],0,0); return mainwin; } #endif // SDLTILES std::string sysfnt = find_system_font(typeface, faceIndex); if(sysfnt != "") typeface = sysfnt; //make fontdata compatible with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/" + typeface + ".ttf"; } //different default font with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/fixedsys.ttf"; } if(fontsize <= 0) fontsize = fontheight - 1; // SDL_ttf handles bitmap fonts size incorrectly if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon")) faceIndex = test_face_size(typeface, fontsize, faceIndex); font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex); //if(!font) something went wrong TTF_SetFontStyle(font, TTF_STYLE_NORMAL); // glyph height hack by utunnels // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics // this causes baseline problems for certain fonts // I can only guess by check a certain tall character... cache_glyphs(); init_colors(); OutputChar = &OutputFontChar; mainwin = newwin(OPTIONS["TERMINAL_Y"], OPTIONS["TERMINAL_X"],0,0); return mainwin; //create the 'stdscr' window and return its ref }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { lastchar = -1; inputdelay = -1; std::string typeface = "Terminus"; std::string blending = "solid"; std::ifstream fin; int faceIndex = 0; int fontsize = 0; //actuall size fin.open("data/FONTDATA"); if (!fin.is_open()){ fontwidth = 8; fontheight = 16; std::ofstream fout;//create data/FONDATA file fout.open("data/FONTDATA"); if(fout.is_open()) { fout << typeface << "\n"; fout << fontwidth << "\n"; fout << fontheight; fout.close(); } } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; fin >> fontsize; fin >> blending; if ((fontwidth <= 4) || (fontheight <= 4)) { fontheight = 16; fontwidth = 8; } fin.close(); } fontblending = (blending=="blended"); halfwidth=fontwidth / 2; halfheight=fontheight / 2; if(!InitSDL()) { DebugLog() << "Failed to initialize SDL: " << SDL_GetError() << "\n"; return NULL; } TERMINAL_WIDTH = OPTIONS["TERMINAL_X"]; TERMINAL_HEIGHT = OPTIONS["TERMINAL_Y"]; if(OPTIONS["FULLSCREEN"]) { // Fullscreen mode overrides terminal width/height SDL_DisplayMode display_mode; SDL_GetDesktopDisplayMode(0, &display_mode); TERMINAL_WIDTH = display_mode.w / fontwidth; TERMINAL_HEIGHT = display_mode.h / fontheight; WindowWidth = display_mode.w; WindowHeight = display_mode.h; } else { WindowWidth= OPTIONS["TERMINAL_X"]; if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH; WindowWidth *= fontwidth; WindowHeight = OPTIONS["TERMINAL_Y"] * fontheight; } if(!WinCreate()) { DebugLog() << "Failed to create game window: " << SDL_GetError() << "\n"; return NULL; } #ifdef SDLTILES DebugLog() << "Initializing SDL Tiles context\n"; tilecontext = new cata_tiles(renderer); try { tilecontext->init("gfx"); DebugLog() << "Tiles initialized successfully.\n"; } catch(std::string err) { // use_tiles is the cached value of the USE_TILES option. // most (all?) code refers to this to see if cata_tiles should be used. // Setting it to false disables this from getting used. use_tiles = false; } #endif // SDLTILES #ifdef SDLTILES while(!strcasecmp(typeface.substr(typeface.length()-4).c_str(),".bmp") || !strcasecmp(typeface.substr(typeface.length()-4).c_str(),".png")) { DebugLog() << "Loading bitmap font [" + typeface + "].\n" ; typeface = "data/font/" + typeface; SDL_Surface *asciiload = IMG_Load(typeface.c_str()); if(!asciiload || asciiload->w*asciiload->h < (fontwidth * fontheight * 256)) { DebugLog() << "Failed to load bitmap font: " << IMG_GetError() << "\n"; SDL_FreeSurface(asciiload); break; } Uint32 key = SDL_MapRGB(asciiload->format, 0xFF, 0, 0xFF); SDL_SetColorKey(asciiload,SDL_TRUE,key); SDL_Surface *ascii_surf[16]; ascii_surf[0] = SDL_ConvertSurface(asciiload,format,0); SDL_SetSurfaceRLE(ascii_surf[0], true); SDL_FreeSurface(asciiload); for(int a = 1; a < 16; ++a) { ascii_surf[a] = SDL_ConvertSurface(ascii_surf[0],format,0); SDL_SetSurfaceRLE(ascii_surf[a], true); } init_colors(); for(int a = 0; a < 15; ++a) { SDL_LockSurface(ascii_surf[a]); int size = ascii_surf[a]->h * ascii_surf[a]->w; Uint32 *pixels = (Uint32 *)ascii_surf[a]->pixels; Uint32 color = (windowsPalette[a].r << 16) | (windowsPalette[a].g << 8) | windowsPalette[a].b; for(int i=0;i<size;i++) { if(pixels[i] == 0xFFFFFF) pixels[i] = color; } SDL_UnlockSurface(ascii_surf[a]); } if(fontwidth) tilewidth = ascii_surf[0]->w / fontwidth; OutputChar = &OutputImageChar; //convert ascii_surf to SDL_Texture for(int a = 0; a < 16; ++a) { ascii[a] = SDL_CreateTextureFromSurface(renderer,ascii_surf[a]); SDL_FreeSurface(ascii_surf[a]); } mainwin = newwin(get_terminal_height(), get_terminal_width(),0,0); return mainwin; } #endif // SDLTILES std::string sysfnt = find_system_font(typeface, faceIndex); if(sysfnt != "") typeface = sysfnt; //make fontdata compatible with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/" + typeface + ".ttf"; } //different default font with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/fixedsys.ttf"; } DebugLog() << "Loading truetype font [" + typeface + "].\n" ; if(fontsize <= 0) fontsize = fontheight - 1; // SDL_ttf handles bitmap fonts size incorrectly if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon")) faceIndex = test_face_size(typeface, fontsize, faceIndex); font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex); if (font == NULL) { DebugLog() << "Failed to load truetype font: " << TTF_GetError() << "\n"; return NULL; } TTF_SetFontStyle(font, TTF_STYLE_NORMAL); // glyph height hack by utunnels // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics // this causes baseline problems for certain fonts // I can only guess by check a certain tall character... cache_glyphs(); init_colors(); OutputChar = &OutputFontChar; mainwin = newwin(get_terminal_height(), get_terminal_width(),0,0); return mainwin; //create the 'stdscr' window and return its ref }
//Basic Init, create the font, backbuffer, etc WINDOW *curses_init(void) { lastchar=-1; inputdelay=-1; std::string typeface = ""; std::string blending = "solid"; std::ifstream fin; int faceIndex = 0; int fontsize = 0; //actuall size fin.open("data/FONTDATA"); if (!fin.is_open()){ fontheight=16; fontwidth=8; } else { getline(fin, typeface); fin >> fontwidth; fin >> fontheight; fin >> fontsize; fin >> blending; if ((fontwidth <= 4) || (fontheight <= 4)) { fontheight=16; fontwidth=8; } fin.close(); } fontblending = (blending=="blended"); halfwidth=fontwidth / 2; halfheight=fontheight / 2; const int SidebarWidth = (OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55; WindowWidth= (SidebarWidth + (OPTIONS["VIEWPORT_X"] * 2 + 1)); if (WindowWidth < FULL_SCREEN_WIDTH) WindowWidth = FULL_SCREEN_WIDTH; WindowWidth *= fontwidth; WindowHeight= (OPTIONS["VIEWPORT_Y"] * 2 + 1) *fontheight; if(!WinCreate()) {}// do something here std::string sysfnt = find_system_font(typeface, faceIndex); if(sysfnt!="") typeface = sysfnt; //make fontdata compatible with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/" + typeface + ".ttf"; } //different default font with wincurse if(!fexists(typeface.c_str())) { faceIndex = 0; typeface = "data/font/fixedsys.ttf"; } if(fontsize <= 0) fontsize = fontheight - 1; // SDL_ttf handles bitmap fonts size incorrectly if(0 == strcasecmp(typeface.substr(typeface.length() - 4).c_str(), ".fon")) faceIndex = test_face_size(typeface, fontsize, faceIndex); font = TTF_OpenFontIndex(typeface.c_str(), fontsize, faceIndex); //if(!font) something went wrong TTF_SetFontStyle(font, TTF_STYLE_NORMAL); // glyph height hack by utunnels // SDL_ttf doesn't use FT_HAS_VERTICAL for function TTF_GlyphMetrics // this causes baseline problems for certain fonts // I can only guess by check a certain tall character... cache_glyphs(); #ifdef SDLTILES // Should NOT be doing this for every damned window I think... keeping too much in memory is wasteful of the tiles. // Most definitely should not be doing this multiple times... mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(((OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55) + (OPTIONS["VIEWPORT_X"] * 2 + 1)),0,0); DebugLog() << "Initializing SDL Tiles context\n"; IMG_Init(IMG_INIT_PNG); tilecontext = new cata_tiles; tilecontext->init(screen, "gfx"); #else mainwin = newwin((OPTIONS["VIEWPORT_Y"] * 2 + 1),(((OPTIONS["SIDEBAR_STYLE"] == "narrow") ? 45 : 55) + (OPTIONS["VIEWPORT_Y"] * 2 + 1)),0,0); #endif return mainwin; //create the 'stdscr' window and return its ref }
int your_test(int argc, char **argv) { int done=0; /* check args */ if(argc!=2) { fprintf(stderr,"%s file.ttf\n",argv[0]); return 1; } /* initialize the cache to NULL */ memset(text,0,sizeof(text)); /* start SDL video */ if(SDL_Init(SDL_INIT_VIDEO)==-1) { printf("SDL_Init: %s\n",SDL_GetError()); return 1; } atexit(SDL_Quit); /* remember to quit SDL */ /* open the screen */ if(!(screen=SDL_SetVideoMode(1200,1000,0,0))) { printf("SDL_SetVideoMode: %s\n",SDL_GetError()); return 1; } /* allow for key repeat (so the user can hold down a key...) */ SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); /* start SDL_ttf */ if(TTF_Init()==-1) { printf("TTF_Init: %s\n", TTF_GetError()); return 2; } atexit(TTF_Quit); /* remember to quit SDL_ttf */ atexit(free_font); /* remember to free any loaded font and glyph cache */ while(!done) { SDL_Event event; static int x=0, y=0, need_draw=1,last_size=0, last_start_glyph=-1; /* smartly load font and generate new glyph cache (font_size change) */ if(last_size!=font_size) { if(font_size<1) font_size=1; load_font(argv[1], font_size); need_draw=1; last_size=font_size; } /* smartly generate new glyph cache (page change) */ if(last_start_glyph!=start_glyph) { cache_glyphs(); need_draw=1; last_start_glyph=start_glyph; } /* smartly redraw as needed */ if(need_draw) { SDL_FillRect(screen,0,~0); draw_table(x,y); SDL_Flip(screen); need_draw=0; } /* wait for events and handle them */ /* this waits for one, then handles all that are queued before finishing */ if(SDL_WaitEvent(&event)) do { switch(event.type) { case SDL_QUIT: done=1; break; case SDL_KEYDOWN: switch(event.key.keysym.sym) { case '0': start_glyph=0; break; case SDLK_LEFT: start_glyph=(start_glyph+0x10000-0x80)&0xffff; break; case SDLK_RIGHT: start_glyph=(start_glyph+0x80)&0xffff; break; case SDLK_UP: font_size++; break; case SDLK_DOWN: font_size--; break; case 'n': style=TTF_STYLE_NORMAL; last_start_glyph=-1; break; case 'b': style^=TTF_STYLE_BOLD; last_start_glyph=-1; break; case 'i': style^=TTF_STYLE_ITALIC; last_start_glyph=-1; break; case 'u': style^=TTF_STYLE_UNDERLINE; last_start_glyph=-1; break; case 's': style^=TTF_STYLE_STRIKETHROUGH; last_start_glyph=-1; break; case 'k': kerning=!kerning; printf("kerning=%d\n",kerning); last_start_glyph=-1; break; case 'h': hinting=(hinting+1)%4; printf("hinting=%s\n", hinting==0?"Normal": hinting==1?"Light": hinting==2?"Mono": hinting==3?"None": "Unknonwn"); last_start_glyph=-1; break; case '=': ++outline; printf("outline=%d\n",outline); last_start_glyph=-1; break; case '-': if(outline>0) --outline; printf("outline=%d\n",outline); last_start_glyph=-1; break; case 'q': case SDLK_ESCAPE: done=1; break; default: break; } break; case SDL_MOUSEMOTION: if(event.motion.state) { x=event.motion.x; y=event.motion.y; need_draw=1; } break; case SDL_MOUSEBUTTONDOWN: x=event.button.x; y=event.button.y; need_draw=1; break; } } while(SDL_PollEvent(&event)); } /* main loop */ return 0; }