serafim/ffi-sdl-ttf
Composer 安装命令:
composer require serafim/ffi-sdl-ttf
包简介
SDL TTF FFI bindings for the PHP language
README 文档
README
A SDL_ttf extension FFI bindings for the PHP language compatible with SDL FFI bindings for the PHP language.
Requirements
- PHP ^8.1
- ext-ffi
- Windows, Linux, BSD or MacOS
- Android, iOS or something else are not supported yet
- SDL and SDL TTF >= 2.0
Installation
Library is available as composer repository and can be installed using the following command in a root of your project.
$ composer require serafim/ffi-sdl-ttf
Additional dependencies:
- Debian-based Linux:
sudo apt install libsdl2-ttf-2.0-0 -y - MacOS:
brew install sdl2_ttf - Window: Can be downloaded from here
Documentation
The library API completely supports and repeats the analogue in the C language.
Initialization
In the case that you need a specific SDL instance, it should be passed explicitly:
$sdl = new Serafim\SDL\SDL(version: '2.28.3'); $ttf = new Serafim\SDL\TTF\TTF(sdl: $sdl); // If no argument is passed, the latest initialized // version will be used. $ttf = new Serafim\SDL\TTF\TTF(sdl: null);
! It is recommended to always specify the SDL dependency explicitly.
To specify a library pathname explicitly, you can add the library argument to
the Serafim\SDL\TTF\TTF constructor.
By default, the library will try to resolve the binary's pathname automatically.
// Load library from pathname (it may be relative or part of system-dependent path) $ttf = new Serafim\SDL\TTF\TTF(library: __DIR__ . '/path/to/library.so'); // Try to automatically resolve library's pathname $ttf = new Serafim\SDL\TTF\TTF(library: null);
You can also specify the library version explicitly. Depending on this version, the corresponding functions of the SDL Image will be available.
By default, the library will try to resolve SDL Image version automatically.
// Use v2.0.14 from string $ttf = new Serafim\SDL\TTF\TTF(version: '2.0.14'); // Use v2.20.2 from predefined versions constant $ttf = new Serafim\SDL\TTF\TTF(version: \Serafim\SDL\TTF\Version::V2_20_2); // Use latest supported version $ttf = new Serafim\SDL\TTF\TTF(version: \Serafim\SDL\TTF\Version::LATEST);
To speed up the header compiler, you can use any PSR-16 compatible cache driver.
$ttf = new Serafim\SDL\TTF\TTF(cache: new Psr16Cache(...));
In addition, you can control other preprocessor directives explicitly:
$pre = new \FFI\Preprocessor\Preprocessor(); $pre->define('true', 'false'); // happy debugging! $ttf = new Serafim\SDL\TTF\TTF(pre: $pre);
Example
use Serafim\SDL\SDL; use Serafim\SDL\TTF\TTF; $sdl = new SDL(); $ttf = new TTF(sdl: $sdl); $sdl->SDL_Init(SDL::SDL_INIT_EVERYTHING); $ttf->TTF_Init(); $font = $ttf->TTF_OpenFont(__DIR__ . '/path/to/font.ttf', 42); echo 'Hinting: ' . $ttf->TTF_GetFontHinting($font) . "\n"; echo 'Kerning: ' . $ttf->TTF_GetFontKerning($font) . "\n"; echo 'Style: ' . match($ttf->TTF_GetFontStyle($font)) { TTF::TTF_STYLE_NORMAL => 'normal', TTF::TTF_STYLE_BOLD => 'bold', TTF::TTF_STYLE_ITALIC => 'italic', TTF::TTF_STYLE_UNDERLINE => 'underline', TTF::TTF_STYLE_STRIKETHROUGH => 'strikethrough', } . "\n"; $color = $sdl->new('SDL_Color'); $color->r = 120; $color->g = 100; $color->b = 80; $surface = $ttf->TTF_RenderText_Solid($font, 'Hello World!', $color); $ttf->TTF_Quit(); $sdl->SDL_Quit();
serafim/ffi-sdl-ttf 适用场景与选型建议
serafim/ffi-sdl-ttf 是一款 基于 C 开发的 Composer 扩展包,目前已累计 251 次下载、GitHub Stars 达 2, 最近一次更新时间为 2020 年 04 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「graphics」 「library」 「font」 「bindings」 「ttf」 「sdl」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 serafim/ffi-sdl-ttf 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 serafim/ffi-sdl-ttf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 serafim/ffi-sdl-ttf 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
FontAwesome5 for Magento2
PHP SVG font parser
SDL FFI bindings for the PHP language
An asset bundle for Font Awesome icons with Bootstrap 4.
Inbox pattern process implementation for your Laravel Applications
Image processing for PHP 5.3
统计信息
- 总下载量: 251
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2020-04-11