Skip to content

Commit

Permalink
Added TTF_SizeUTF8
Browse files Browse the repository at this point in the history
  • Loading branch information
cgrabenstein committed Oct 4, 2023
1 parent 961d73b commit 36b566f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
22 changes: 22 additions & 0 deletions sdl_ttf.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,28 @@ PHP_FUNCTION(TTF_RenderText_Shaded)
sdl_surface_to_zval(surface, return_value);
}

PHP_FUNCTION(TTF_SizeUTF8)
{
char *text;
size_t text_len;
zval *z_font, *z_width=NULL, *z_height=NULL;

if( zend_parse_parameters(ZEND_NUM_ARGS(), "zsz/z/", &z_font, &text, &text_len, &z_width, &z_height) == FAILURE ) {
return;
}

TTF_Font *font;
font = php_ttf_font_from_zval_p(z_font);
int w, h;

TTF_SizeUTF8(font, text, &w, &h);

zval_dtor(z_width);
ZVAL_LONG(z_width, w);
zval_dtor(z_height);
ZVAL_LONG(z_height, h);
}

/* {{{ PHP_RINIT_FUNCTION */
PHP_RINIT_FUNCTION(sdl_ttf)
{
Expand Down
4 changes: 3 additions & 1 deletion sdl_ttf.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ function TTF_Quit(): void {}
function TTF_OpenFont(string $name, int $size): TTF_Font {}
function TTF_CloseFont(TTF_Font $font): int {}

function TTF_RenderText_Solid(TTF_Font $font, string $text, SDL_Color $color): SDL_Surface {}
function TTF_RenderText_Solid(TTF_Font $font, string $text, SDL_Color $color): ?SDL_Surface {}
function TTF_RenderText_Blended(TTF_Font $font, string $text, SDL_Color $color): SDL_Surface {}
function TTF_RenderText_Shaded(TTF_Font $font, string $text, SDL_Color $color, SDL_Color $backgroundColor): SDL_Surface {}

function TTF_SizeUTF8(TTF_Font $font, string $text, int &$width, int &$height): void {};
19 changes: 16 additions & 3 deletions sdl_ttf_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: a227cb9e9a1c09d4ad3d395fa603dd775fb0820a */
* Stub hash: b93fa1c8268fe12987909aaef79131d04f2a7e97 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_TTF_Init, 0, 0, IS_LONG, 0)
ZEND_END_ARG_INFO()
Expand All @@ -18,13 +18,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_TTF_CloseFont, 0, 1, IS_LONG, 0)
ZEND_ARG_OBJ_INFO(0, font, TTF_Font, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_RenderText_Solid, 0, 3, SDL_Surface, 0)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_RenderText_Solid, 0, 3, SDL_Surface, 1)
ZEND_ARG_OBJ_INFO(0, font, TTF_Font, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, color, SDL_Color, 0)
ZEND_END_ARG_INFO()

#define arginfo_TTF_RenderText_Blended arginfo_TTF_RenderText_Solid
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_RenderText_Blended, 0, 3, SDL_Surface, 0)
ZEND_ARG_OBJ_INFO(0, font, TTF_Font, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_ARG_OBJ_INFO(0, color, SDL_Color, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_RenderText_Shaded, 0, 4, SDL_Surface, 0)
ZEND_ARG_OBJ_INFO(0, font, TTF_Font, 0)
Expand All @@ -33,6 +37,13 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_RenderText_Shaded, 0, 4, SDL_
ZEND_ARG_OBJ_INFO(0, backgroundColor, SDL_Color, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_TTF_SizeUTF8, 0, 4, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, font, TTF_Font, 0)
ZEND_ARG_TYPE_INFO(0, text, IS_STRING, 0)
ZEND_ARG_INFO(1, w)
ZEND_ARG_INFO(1, h)
ZEND_END_ARG_INFO()


ZEND_FUNCTION(TTF_Init);
ZEND_FUNCTION(TTF_WasInit);
Expand All @@ -42,6 +53,7 @@ ZEND_FUNCTION(TTF_CloseFont);
ZEND_FUNCTION(TTF_RenderText_Solid);
ZEND_FUNCTION(TTF_RenderText_Blended);
ZEND_FUNCTION(TTF_RenderText_Shaded);
ZEND_FUNCTION(TTF_SizeUTF8);


static const zend_function_entry ext_functions[] = {
Expand All @@ -53,6 +65,7 @@ static const zend_function_entry ext_functions[] = {
ZEND_FE(TTF_RenderText_Solid, arginfo_TTF_RenderText_Solid)
ZEND_FE(TTF_RenderText_Blended, arginfo_TTF_RenderText_Blended)
ZEND_FE(TTF_RenderText_Shaded, arginfo_TTF_RenderText_Shaded)
ZEND_FE(TTF_SizeUTF8, arginfo_TTF_SizeUTF8)
ZEND_FE_END
};

Expand Down

0 comments on commit 36b566f

Please sign in to comment.