예제 #1
0
char* getFontXLFDName(TTF_Font* font) {
    /* FOUNDRY - FAMILY_NAME - WEIGHT_NAME - SLANT - SETWIDTH_NAME - ADD_STYLE - PIXEL_SIZE -
       POINT_SIZE - RESOLUTION_X - RESOLUTION_Y - SPACING - AVERAGE_WIDTH - CHARSET_REGISTRY -
       CHARSET_ENCODING */
    int fontStyle = TTF_GetFontStyle(font);
    static char* emptyValue = "";
    char* foundry = emptyValue;
    char* familyName = TTF_FontFaceFamilyName(font);
    if (familyName == NULL) familyName = emptyValue;
    char* weightName = fontStyle & TTF_STYLE_BOLD ? "bold" : "medium";
    char slant = (char) (fontStyle & TTF_STYLE_ITALIC ? 'i' : 'r');
    char* setWidth = "normal";
    int pointSize = 0;
    char spacing = (char) (TTF_FontFaceIsFixedWidth(font) ? 'm' : 'p');
    short averageWidth = 0;
    char* charset = "iso10646"; // Unicode
    int charsetEncoding = 1;
    size_t nameLength = 14 + strlen(foundry) + strlen(familyName) + strlen(weightName)
                        + 1 + strlen(setWidth) + 1 + 6 + 1 + 1 + 1 + 5 + strlen(charset) + 1;
    
    char* name = malloc(sizeof(char) * nameLength);
    if (name != NULL) {
        // TODO: Should this not be "-%s-%s-%s-%c-%s--0-%d-0-0-%c-%hd-%s-%d"? Tk does not want the extra dash.
        snprintf(name, nameLength, "-%s-%s-%s-%c-%s-0-%d-0-0-%c-%hd-%s-%d",
                 foundry, familyName, weightName, slant, setWidth, pointSize,
                 spacing, averageWidth, charset, charsetEncoding);
    }
    LOG("Font name = '%s'\n", name);
    return name;
}
예제 #2
0
파일: font.c 프로젝트: GunioRobot/starruby
static VALUE
Font_name(VALUE self)
{
  const Font* font;
  Data_Get_Struct(self, Font, font);
  return rb_str_new2(TTF_FontFaceFamilyName(font->sdlFont));
}
예제 #3
0
static void font_folder_list(std::ofstream& fout, std::string path)
{
    DIR *dir;
    struct dirent *ent;
    if ((dir = opendir (path.c_str())) != NULL) {
        bool found = false;
        while (!found && (ent = readdir (dir)) != NULL) {
            if( 0 == strcmp( ent->d_name, "." ) ||
                0 == strcmp( ent->d_name, ".." ) ) {
                continue;
            }
            #if (defined _WIN32 || defined WINDOWS)
                std::string f = path + "\\" + ent->d_name;
            #else
                std::string f = path + "/" + ent->d_name;
            #endif

            struct stat stat_buffer;
            if( stat( f.c_str(), &stat_buffer ) == -1 ) {
                continue;
            }
            if( S_ISDIR(stat_buffer.st_mode) ) {
                font_folder_list( fout, f );
                continue;
            }
            TTF_Font* fnt = TTF_OpenFont(f.c_str(), 12);
            long nfaces = 0;
            if(fnt != NULL) {
                nfaces = TTF_FontFaces(fnt);
                TTF_CloseFont(fnt);
                fnt = NULL;
            }
            for(long i = 0; i < nfaces; i++) {
                fnt = TTF_OpenFontIndex(f.c_str(), 12, i);
                if(fnt != NULL) {
                    char *fami = TTF_FontFaceFamilyName(fnt);
                    char *style = TTF_FontFaceStyleName(fnt);
                    bool isbitmap = (0 == strcasecmp(".fon", f.substr(f.length() - 4).c_str()) );
                    if(fami != NULL && (!isbitmap || i == 0) ) {
                        fout << fami << std::endl;
                        fout << f << std::endl;
                        fout << i << std::endl;
                    }
                    if(fami != NULL && style != NULL && 0 != strcasecmp(style, "Regular")) {
                        if(!isbitmap) {
                            fout << fami << " " << style << std::endl;
                            fout << f << std::endl;
                            fout << i << std::endl;
                        }
                    }
                    TTF_CloseFont(fnt);
                    fnt = NULL;
                }
            }
        }
        closedir (dir);
    }

}
예제 #4
0
static mrb_value
mrb_sdl2_ttf_font_get_face_family_name(mrb_state *mrb, mrb_value self)
{
  char *r = TTF_FontFaceFamilyName(mrb_sdl2_font_get_ptr(mrb, self));
  if (r)
    return mrb_str_new_cstr(mrb, r);
  return mrb_nil_value();
}
예제 #5
0
		int LOBJECT_METHOD(getFontFamilyName, TTF_Font * font){
			char * name = TTF_FontFaceFamilyName(font);
			if (name){
				state.push_string(name);
			}else{
				state.push_literal("");
			}
			return 1;
		}
예제 #6
0
std::string BEE::Font::get_fontname() {
	std::string fontname = "";
	char* familyname = TTF_FontFaceFamilyName(font);
	char* stylename = TTF_FontFaceStyleName(font);
	fontname += familyname;
	fontname += " ";
	fontname += stylename;
	return fontname;
}
예제 #7
0
파일: SDLFont.cpp 프로젝트: benzap/Kampf
stringType SDLFont::getFamilyName() {
    char* fontFamily = TTF_FontFaceFamilyName(this->fontContext);
    if (fontFamily != NULL) {
	stringType fontFamilyString = stringType(fontFamily);
	return fontFamilyString;
    }
    else {
	return "None";
    }
}
예제 #8
0
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();
}
예제 #9
0
JNIEXPORT jstring JNICALL Java_sdljava_x_swig_SWIG_1SDLTTFJNI_TTF_1FontFaceFamilyName(JNIEnv *jenv, jclass jcls, jlong jarg1) {
    jstring jresult = 0 ;
    TTF_Font *arg1 = (TTF_Font *) 0 ;
    char *result;
    
    (void)jenv;
    (void)jcls;
    arg1 = *(TTF_Font **)&jarg1; 
    result = (char *)TTF_FontFaceFamilyName(arg1);
    
    {
        if(result) jresult = (*jenv)->NewStringUTF(jenv, result); 
    }
    return jresult;
}
예제 #10
0
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");
}
예제 #11
0
KFontProperties::KFontProperties(const TTF_Font *_Font, const KFile *file, int ptSize) :
fontPath(file->getAbsolutePath().c_str()),
familyName(TTF_FontFaceFamilyName(_Font)),
styleName(TTF_FontFaceStyleName(_Font)),
ttf_Style(TTF_GetFontStyle(_Font)),
height(TTF_FontHeight(_Font)),
ascent(TTF_FontAscent(_Font)),
descent(TTF_FontDescent(_Font)),
lineSkip(TTF_FontLineSkip(_Font)),
faces(TTF_FontFaces(_Font)),
monospace(TTF_FontFaceIsFixedWidth(_Font)),
firstGlyph(getFirstGlyph(_Font)),
lastGlyph(getLastGlyph(_Font)),
totalGlyphs(getTotalGlyphs(_Font)),
glyphRanges(getRanges(_Font)),
pointSize(ptSize) {

}
예제 #12
0
void SharedFontState::initFontSetCB(SDL_RWops &ops,
                                    const std::string &filename)
{
	TTF_Font *font = TTF_OpenFontRW(&ops, 0, 0);

	if (!font)
		return;

	std::string family = TTF_FontFaceFamilyName(font);
	std::string style = TTF_FontFaceStyleName(font);

	TTF_CloseFont(font);

	FontSet &set = p->sets[family];

	if (style == "Regular")
		set.regular = filename;
	else
		set.other = filename;
}