Class EmbeddedFont

java.lang.Object
cloud.opencode.base.pdf.font.EmbeddedFont
All Implemented Interfaces:
PdfFont

public final class EmbeddedFont extends Object implements 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:
  • Method Details

    • fromFile

      public static EmbeddedFont fromFile(String name, Path path)
      Creates embedded font from file path 从文件路径创建嵌入字体
      Parameters:
      name - font name | 字体名称
      path - font file path | 字体文件路径
      Returns:
      EmbeddedFont instance | EmbeddedFont 实例
    • fromBytes

      public static EmbeddedFont fromBytes(String name, byte[] data, EmbeddedFont.FontType type)
      Creates embedded font from byte array 从字节数组创建嵌入字体
      Parameters:
      name - font name | 字体名称
      data - font data | 字体数据
      type - font type | 字体类型
      Returns:
      EmbeddedFont instance | EmbeddedFont 实例
    • getName

      public String getName()
      Description copied from interface: PdfFont
      Gets font name 获取字体名称
      Specified by:
      getName in interface PdfFont
      Returns:
      font name | 字体名称
    • getPdfName

      public String getPdfName()
      Description copied from interface: PdfFont
      Gets PDF font name (internal name) 获取 PDF 字体名称(内部名称)
      Specified by:
      getPdfName in interface PdfFont
      Returns:
      PDF internal name | PDF 内部名称
    • isEmbedded

      public boolean isEmbedded()
      Description copied from interface: PdfFont
      Checks if font is embedded 检查字体是否嵌入
      Specified by:
      isEmbedded in interface PdfFont
      Returns:
      true if embedded | 如果嵌入返回 true
    • getFontPath

      public Path 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

      public EmbeddedFont.FontType getType()
      Gets font type 获取字体类型
      Returns:
      font type | 字体类型