You are not logged in.

#1 2010-04-09 17:19:28

tiamattia
Member

A little help with a contribution

Hi, i'm mattia. (sorry for the bad english)

I noticed that in the latest revision has been added the support for TrueType fonts, so I've installed it.
I've also noticed that you can't print with TTF using multiple arguments.
So I changed the function; but I don't know if it's my fault or the modified code, but the applications I create with this function give black screen.

Here's the code:

Code:

//GRRLIB_ttf.c
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, unsigned int fontSize, char *text, ...) {
    char tmp[1024];
    va_list argp;
    va_start(argp, text);
    vsprintf(tmp, text, argp);
    va_end(argp);
    const char *string=tmp;
    if(myFont == NULL || string == NULL) {
        return 0;
    }
    unsigned int penX;
    size_t length = strlen(string) + 1;
    wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
    length = mbstowcs(utf32, string, length);
    utf32[length] = L'\0';

    penX = GRRLIB_WidthTTFW(myFont, utf32, fontSize);

    free(utf32);

    return penX;
}

Code:

//GRRLIB__lib.h
unsigned int GRRLIB_WidthTTF(GRRLIB_ttfFont *myFont, unsigned int, char *, ...);

Edit:
Sorry, i've forgot a part...

Code:

//GRRLIB_ttf.c
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, unsigned int fontSize, const u32 color, char *text, ...) {
    char tmp[1024];
    va_list argp;
    va_start(argp, text);
    vsprintf(tmp, text, argp);
    va_end(argp);
    const char *string=tmp;
    
    if(myFont == NULL || string == NULL)
        return;

    size_t length = strlen(string) + 1;
    wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
    if(utf32) {
        length = mbstowcs(utf32, string, length);
        if(length > 0) {
            utf32[length] = L'\0';
            GRRLIB_PrintfTTFW(x, y, myFont, utf32, fontSize, color);
        }
        free(utf32);
    }
}

Code:

//GRRLIB__lib.h
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, unsigned int fontSize, const u32 color, char *text, ...);

Bye, mattia

Last edited by tiamattia (2010-04-09 18:13:19)

Offline

 

#2 2010-04-09 18:42:15

Crayon
Bad Mother Fucker

Re: A little help with a contribution

This my contribution for GRRLIB smile

Code:

void GRRLIB_PrintfTTF2(int x, int y, GRRLIB_ttfFont *myFont, unsigned int fontSize, const u32 color, const char *string, ...) {
    if(myFont == NULL || string == NULL)
        return;

    char tmp[1024];
    va_list argp;
    va_start(argp, string);
    size_t length = vsprintf(tmp, string, argp) + 1;
    va_end(argp);

    wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
    if(utf32) {
        length = mbstowcs(utf32, tmp, length);
        if(length > 0) {
            utf32[length] = L'\0';
            GRRLIB_PrintfTTFW(x, y, myFont, utf32, fontSize, color);
        }
        free(utf32);
    }
}

Offline

 

#3 2010-04-09 20:03:52

tiamattia
Member

Re: A little help with a contribution

Thanks, wink

Offline

 

Board footer

Powered by FluxBB