//Set the hinting of the value //param:fontIndex->The index of the font //param:hintingStyle->The style of hinting to apply //TTF_HINTING_NORMAL: Normal hinting //TTF_HINTING_LIGHT: Light hinting //TTF_HINTING_MONO: Monochromatic hinting //TTF_HINTING_NONE: No hinting void SpriteFont::SetFontHinting(int fontIndex, int hintingStyle) { //Try block to make sure index is valid try { //Get the font to modify TTF_Font* font = fontList.at(fontIndex); //Make sure its not null if(font) { //Get the current style int currentHint = TTF_GetFontHinting(font); //Save processing by not changing style if they are identical if(currentHint != hintingStyle) { //Otherwise, set the style TTF_SetFontHinting(font, hintingStyle); } } else { std::cout<<"SetFontHinting error: Provided index is NULL"<<std::endl; return; } } catch(std::out_of_range problem) { //display invalid index std::cout<<"SetFontOutline error: font index invalid"<<std::endl; return; } }
enumFontHintingType SDLFont::getHinting() { int hintingNum = TTF_GetFontHinting(this->fontContext); switch(hintingNum) { case TTF_HINTING_NONE: return enumFontHintingType::NONE; case TTF_HINTING_MONO: return enumFontHintingType::MONO; case TTF_HINTING_LIGHT: return enumFontHintingType::LIGHT; case TTF_HINTING_NORMAL: default: return enumFontHintingType::NORMAL; } }
void cache_glyphs() { SDL_Color fg={0,0,0,255}; #if RENDER_MODE==1 SDL_Color bg={255,255,255,255}; #endif if (!font) return; if (style!=TTF_GetFontStyle(font)) TTF_SetFontStyle(font,style); if (kerning != !!TTF_GetFontKerning(font)) TTF_SetFontKerning(font,kerning); if (hinting != TTF_GetFontHinting(font)) TTF_SetFontHinting(font,hinting); if (outline != TTF_GetFontOutline(font)) TTF_SetFontOutline(font,outline); }
void cache_glyphs() { int i; char title[800]; SDL_Color fg={0,0,0,255}; #if RENDER_MODE==1 SDL_Color bg={255,255,255,255}; #endif free_glyphs(); if(!font) return; if(style!=TTF_GetFontStyle(font)) TTF_SetFontStyle(font,style); if(kerning != !!TTF_GetFontKerning(font)) TTF_SetFontKerning(font,kerning); if(hinting != TTF_GetFontHinting(font)) TTF_SetFontHinting(font,hinting); if(outline != TTF_GetFontOutline(font)) TTF_SetFontOutline(font,outline); for(i=0; i<128; i++) { /* cache rendered surface */ #if RENDER_MODE==0 text[i]=TTF_RenderGlyph_Solid(font,i+start_glyph,fg); #elif RENDER_MODE==1 text[i]=TTF_RenderGlyph_Shaded(font,i+start_glyph,fg,bg); #elif RENDER_MODE==2 text[i]=TTF_RenderGlyph_Blended(font,i+start_glyph,fg); #endif if(!text[i]) { printf("TTF_RenderGlyph_Shaded: %s\n", TTF_GetError()); exit(4); } /* cache metrics */ TTF_GlyphMetrics(font, i+start_glyph, &gm[i].minx, &gm[i].maxx, &gm[i].miny, &gm[i].maxy, &gm[i].advance); } sprintf(title,"%s-%s:%d+0x%04x",TTF_FontFaceFamilyName(font), TTF_FontFaceStyleName(font),font_size,start_glyph); SDL_WM_SetCaption(title,"latin1"); }
// Load TTF font from file. INT32 I_TTFLoadFont(const char *file, UINT32 ptsize) { TTF_Font *tmpfont = NULL; float fontsize; // If a font is currently loaded, unload it. if (currentfont) { TTF_CloseFont(currentfont); } // Scale the specified font point size for the current resolution. fontsize = (ptsize * 0.005f) * (res.width - res.height); tmpfont = TTF_OpenFont(file, fontsize); if (!tmpfont) return FONTHANDLE; // set pointer for current font currentfont = tmpfont; // set current font point size currentfontpoint = ptsize; // get font properties, and set them currentfontstyle = TTF_GetFontStyle(currentfont); TTF_SetFontStyle(currentfont, currentfontstyle); // these functions only exist in SDL_ttf 2.0.10 onwards #if SDL_TTF_VERSION_ATLEAST(2,0,10) currentfontkerning = TTF_GetFontKerning(currentfont); TTF_SetFontKerning(currentfont, currentfontkerning); currentfonthinting = TTF_GetFontHinting(currentfont); TTF_SetFontHinting(currentfont, currentfonthinting); currentfontoutline = TTF_GetFontOutline(currentfont); TTF_SetFontOutline(currentfont, currentfontoutline); #endif return 0; }
int LOBJECT_METHOD(getFontHinting, TTF_Font * font){ int result = TTF_GetFontHinting(font); state.push_integer(result); return 1; }
static mrb_value mrb_sdl2_ttf_font_get_hinting(mrb_state *mrb, mrb_value self) { return mrb_fixnum_value(TTF_GetFontHinting(mrb_sdl2_font_get_ptr(mrb, self))); }