SDL
view release on metacpan or search on metacpan
src/TTF/TTF.xs view on Meta::CPAN
#include "ppport.h"
#include <SDL.h>
#ifdef HAVE_SDL_TTF
#include <SDL_ttf.h>
#ifndef SDL_TTF_MAJOR_VERSION
#define SDL_TTF_MAJOR_VERSION 0
#endif
#ifndef SDL_TTF_MINOR_VERSION
#define SDL_TTF_MINOR_VERSION 0
#endif
#ifndef SDL_TTF_PATCHLEVEL
#define SDL_TTF_PATCHLEVEL 0
#endif
#define SDL_TTF_VERSION(X) \
{ \
(X)->major = SDL_TTF_MAJOR_VERSION; \
(X)->minor = SDL_TTF_MINOR_VERSION; \
(X)->patch = SDL_TTF_PATCHLEVEL; \
}
static Uint16 *UTF8_to_UNICODE(Uint16 *unicode, const char *utf8, int len)
{
int i, j;
Uint16 ch;
for ( i=0, j=0; i < len; ++i, ++j ) {
ch = ((const unsigned char *)utf8)[i];
if ( ch >= 0xF0 ) {
ch = (Uint16)(utf8[i]&0x07) << 18;
ch |= (Uint16)(utf8[++i]&0x3F) << 12;
ch |= (Uint16)(utf8[++i]&0x3F) << 6;
ch |= (Uint16)(utf8[++i]&0x3F);
} else
if ( ch >= 0xE0 ) {
ch = (Uint16)(utf8[i]&0x0F) << 12;
ch |= (Uint16)(utf8[++i]&0x3F) << 6;
ch |= (Uint16)(utf8[++i]&0x3F);
} else
if ( ch >= 0xC0 ) {
ch = (Uint16)(utf8[i]&0x1F) << 6;
ch |= (Uint16)(utf8[++i]&0x3F);
}
unicode[j] = ch;
}
unicode[j] = 0;
return unicode;
}
static Uint16 *utf16_to_UNICODE(SV *sv)
{
STRLEN len;
char *text = SvPV(sv, len);
len /= 2; /* 1-Byte chars to 2-Byte Uint16 */
Uint16 *unicode = safemalloc((len + 2) * sizeof(Uint16)); /* length = BOM + characters + NULL */
int i;
/* UTF-16 Big Endian with BOM */
if((Uint8)text[0] == 0xFE && (Uint8)text[1] == 0xFF)
{
for( i = 0; i < len; i++ )
{
unicode[i] = ((Uint8)text[i * 2] << 8) | (Uint8)text[i * 2 + 1];
}
unicode[i] = 0;
}
else
/* UTF-16 Little Endian with BOM */
if((Uint8)text[0] == 0xFF && (Uint8)text[1] == 0xFE)
{
for( i = 0; i < len; i++ )
{
unicode[i] = ((Uint8)text[i * 2 + 1] << 8) | (Uint8)text[i * 2];
}
unicode[i] = 0;
}
else /* everything without BOM is treated as UTF-16 Big Endian */
{
unicode[0] = 0xFEFF; /* we have to pass it as UTF-16 Big Endian */
for( i = 0; i <= len; i++ )
{
unicode[i + 1] = (text[i * 2] << 8) | text[i * 2 + 1];
}
unicode[i] = 0;
}
return unicode;
}
#endif
MODULE = SDL::TTF PACKAGE = SDL::TTF PREFIX = ttf_
#ifdef HAVE_SDL_TTF
const SDL_version *
ttf_linked_version()
PREINIT:
char* CLASS = "SDL::Version";
SDL_version *version;
CODE:
version = (SDL_version *) safemalloc ( sizeof(SDL_version) );
SDL_version* version_dont_free = (SDL_version *)TTF_Linked_Version();
version->major = version_dont_free->major;
version->minor = version_dont_free->minor;
version->patch = version_dont_free->patch;
RETVAL = version;
OUTPUT:
RETVAL
const SDL_version *
ttf_compile_time_version()
PREINIT:
char* CLASS = "SDL::Version";
CODE:
SDL_version *compile_time_version = safemalloc(sizeof(SDL_version));
SDL_TTF_VERSION(compile_time_version);
RETVAL = compile_time_version;
OUTPUT:
RETVAL
void
ttf_byte_swapped_unicode(swapped)
int swapped
CODE:
TTF_ByteSwappedUNICODE(swapped);
int
ttf_init()
CODE:
RETVAL = TTF_Init();
OUTPUT:
RETVAL
TTF_Font *
ttf_open_font(file, ptsize)
( run in 0.741 second using v1.01-cache-2.11-cpan-5b529ec07f3 )