定制 serafim/ffi-sdl-ttf 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

serafim/ffi-sdl-ttf

Composer 安装命令:

composer require serafim/ffi-sdl-ttf

包简介

SDL TTF FFI bindings for the PHP language

README 文档

README

PHP 8.1+ SDL_ttf Latest Stable Version Latest Unstable Version Total Downloads License MIT

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 serafim/ffi-sdl-ttf 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 251
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 2
  • 开发语言: C

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-04-11