承接 xenocrat/sfnt2woff 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

xenocrat/sfnt2woff

Composer 安装命令:

composer require xenocrat/sfnt2woff

包简介

A PHP class for converting OTF/TTF files to WOFF.

README 文档

README

sfnt2woff is a PHP class for converting OTF, TTF, TTC and OTC files to WOFF 1.0 and 2.0.

Requirements

  • PHP 8.0+
  • ZLIB extension for WOFF 1.0 export
  • Brotli extension for WOFF 2.0 export

Limitations

WOFF 2.0 export uses a null transformation: table data is not optimized.

Usage

Convert a font to WOFF 1.0:

$sfnt2woff = new \xenocrat\sfnt2woff();
$sfnt = file_get_contents("font.ttf");
$sfnt2woff->sfnt_import($sfnt);
$woff = $sfnt2woff->woff1_export();
file_put_contents("font.woff", $woff);

Convert a font to WOFF 2.0:

$sfnt2woff = new \xenocrat\sfnt2woff();
$sfnt = file_get_contents("font.ttf");
$sfnt2woff->sfnt_import($sfnt);
$woff = $sfnt2woff->woff2_export();
file_put_contents("font.woff2", $woff);

Methods

sfnt_import

Description

public sfnt2woff::sfnt_import(
    string $sfnt,
    bool $verify_checksums = true
): void

Imports SFNT data from a TTF or OTF font source.

Parameters

  • sfnt

    A complete TTF or OTF file as a string of data.

  • verify_checksums

    Whether or not to verify the table data checksums on import.

otfc_import

Description

public sfnt2woff::otfc_import(
    string $otfc,
    bool $verify_checksums = true
): void

Imports TTC or OTC data from a TrueType or OpenType font collection.

Parameters

  • otfc

    A complete TTC or OTC file as a string of data.

  • verify_checksums

    Whether or not to verify the table data checksums on import.

otfc_extract

Description

public sfnt2woff::otfc_extract(
    int $index
): void

Extracts SFNT data from a TrueType or OpenType font collection. After extraction, the data can be exported using woff1_export or woff2_export.

Parameters

  • index

    The zero-based index of the font in a collection imported using otfc_import. The total number of fonts in the collection is returned by get_otfc_info.

woff1_export

Description

public sfnt2woff::woff1_export(
    int $compression_level = -1
): string|false

Exports SFNT data in WOFF 1.0 format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 9 (maximum). Defaults to 6.

Return Values

Returns a complete WOFF 1.0 file as a string of data, or false if there is no data to export.

woff2_export

Description

public sfnt2woff::woff2_export(
    int $compression_level = -1
): string|false

Exports SFNT data in WOFF 2.0 format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 11 (maximum). Defaults to BROTLI_COMPRESS_LEVEL_DEFAULT.

Return Values

Returns a complete WOFF 2.0 file as a string of data, or false if there is no data to export.

woffc_export

Description

public sfnt2woff::woffc_export(
    int $compression_level = -1
): string|false

Exports TTC or OTC data in WOFF 2.0 font collection format.

Parameters

  • compression_level

    The compression level, from 0 (minimum) to 11 (maximum). Defaults to BROTLI_COMPRESS_LEVEL_DEFAULT.

Return Values

Returns a complete WOFF 2.0 collection file as a string of data, or false if there is no data to export.

set_woff_version

Description

public sfnt2woff::set_woff_version(
    int $major,
    int $major
): void

Set the major and minor version numbers for WOFF exports.

Parameters

  • major

    The major version, an integer in the range 0-65535.

  • minor

    The minor version, an integer in the range 0-65535.

get_woff_version

Description

public sfnt2woff::get_woff_version(
): array

Get the major and minor version numbers for WOFF exports.

Return Values

Returns an array of two integers representing the major and minor version numbers.

set_woff_meta

Description

public sfnt2woff::set_woff_meta(
    SimpleXMLElement $object
): void

Set the WOFF extended metadata block.

Parameters

  • object

    A SimpleXMLElement object representing the XML metadata.

get_woff_meta

Description

public sfnt2woff::get_woff_meta(
): object|false

Get the WOFF extended metadata block.

Return Values

Returns a SimpleXMLElement object representing the XML metadata, or false if no metadata block has been set.

set_woff_priv

Description

public sfnt2woff::set_woff_priv(
    string $data
): void

Set the WOFF private data block.

Parameters

  • data

    A string of data representing the private data block.

get_woff_priv

Description

public sfnt2woff::get_woff_priv(
): string|false

Get the WOFF private data block.

Return Values

Returns a string of data representing the private data block, or false if no private data block has been set.

get_sfnt_info

Description

public sfnt2woff::get_sfnt_info(
): array|false

Returns information about SFNT data imported using sfnt_import or otfc_extract.

Return Values

Returns an associative array, or false if no data has been imported.

get_otfc_info

Description

public sfnt2woff::get_otfc_info(
): array|false

Returns information about TTC or OTC data imported using otfc_import.

Return Values

Returns an associative array, or false if no data has been imported.

xenocrat/sfnt2woff 适用场景与选型建议

xenocrat/sfnt2woff 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.5k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2024 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「font」 「converter」 「otf」 「ttf」 「woff」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 xenocrat/sfnt2woff 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 xenocrat/sfnt2woff 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 18
  • 点击次数: 18
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 18
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2024-04-02