Class EmbeddedFont
java.lang.Object
cloud.opencode.base.pdf.font.EmbeddedFont
- All Implemented Interfaces:
PdfFont
Embedded PDF Font - Custom font embedded in PDF
嵌入式 PDF 字体 - 嵌入 PDF 中的自定义字体
Supports TrueType (TTF) and OpenType (OTF) fonts.
支持 TrueType (TTF) 和 OpenType (OTF) 字体。
Features | 主要功能:
- Load fonts from file path or byte array - 从文件路径或字节数组加载字体
- Automatic font type detection - 自动字体类型检测
- Support for TTF, OTF, and TTC formats - 支持 TTF、OTF 和 TTC 格式
Usage Examples | 使用示例:
EmbeddedFont font = EmbeddedFont.fromFile("MyFont", Path.of("font.ttf"));
EmbeddedFont fromBytes = EmbeddedFont.fromBytes("Custom", data, FontType.TRUETYPE);
Security | 安全性:
- Thread-safe: Yes — immutable after construction - 线程安全: 是 — 构造后不可变
- Null-safe: Yes — name is validated as non-null - 空值安全: 是 — 名称已验证非空
- Defensive copies: Font byte arrays are cloned on input and output - 防御性拷贝: 字体字节数组在输入和输出时进行克隆
- Since:
- JDK 25, opencode-base-pdf V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic EmbeddedFontfromBytes(String name, byte[] data, EmbeddedFont.FontType type) Creates embedded font from byte array 从字节数组创建嵌入字体static EmbeddedFontCreates embedded font from file path 从文件路径创建嵌入字体byte[]Gets font data 获取字体数据Gets font file path 获取字体文件路径getName()Gets font name 获取字体名称Gets PDF font name (internal name) 获取 PDF 字体名称(内部名称)getType()Gets font type 获取字体类型booleanChecks if font is embedded 检查字体是否嵌入
-
Method Details
-
fromFile
Creates embedded font from file path 从文件路径创建嵌入字体- Parameters:
name- font name | 字体名称path- font file path | 字体文件路径- Returns:
- EmbeddedFont instance | EmbeddedFont 实例
-
fromBytes
Creates embedded font from byte array 从字节数组创建嵌入字体- Parameters:
name- font name | 字体名称data- font data | 字体数据type- font type | 字体类型- Returns:
- EmbeddedFont instance | EmbeddedFont 实例
-
getName
-
getPdfName
Description copied from interface:PdfFontGets PDF font name (internal name) 获取 PDF 字体名称(内部名称)- Specified by:
getPdfNamein interfacePdfFont- Returns:
- PDF internal name | PDF 内部名称
-
isEmbedded
public boolean isEmbedded()Description copied from interface:PdfFontChecks if font is embedded 检查字体是否嵌入- Specified by:
isEmbeddedin interfacePdfFont- Returns:
- true if embedded | 如果嵌入返回 true
-
getFontPath
Gets font file path 获取字体文件路径- Returns:
- font path, or null if created from bytes | 字体路径,如果从字节创建则返回 null
-
getFontData
public byte[] getFontData()Gets font data 获取字体数据- Returns:
- font data copy, or null if created from path | 字体数据副本,如果从路径创建则返回 null
-
getType
-