Documentation
¶
Overview ¶
Package webreader 包提供适合浏览器调用的 OFD 文档访问接口。
Index ¶
- type FontResource
- type FontSource
- type Glyph
- type OpenOptions
- type PageInfo
- type Reader
- func (r *Reader) AddFallbackFont(source FontSource) error
- func (r *Reader) Close() error
- func (r *Reader) Fonts() ([]FontResource, error)
- func (r *Reader) Page(index int) (PageInfo, error)
- func (r *Reader) PageCount() int
- func (r *Reader) Pages() ([]PageInfo, error)
- func (r *Reader) RenderPDF(indices []int, options RenderOptions) (outputBytes []byte, err error)
- func (r *Reader) RenderPage(index int, options RenderOptions) ([]byte, error)
- func (r *Reader) RenderPages(indices []int, options RenderOptions) ([][]byte, error)
- func (r *Reader) Search(query string) ([]SearchResult, error)
- func (r *Reader) Text(index int) ([]TextRun, error)
- type Rect
- type RenderOptions
- type SearchResult
- type TextRun
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FontResource ¶
type FontResource struct {
ID uint64
Family string
Name string
Bold bool
Italic bool
Format string
Data []byte
}
FontResource 描述文档中可注入浏览器的嵌入字体。 Data 为空表示该字体只声明了名称,没有嵌入字体文件。
type FontSource ¶
FontSource 是由调用方提供给 WASM 渲染器的字体文件。 浏览器无法读取本机系统字体文件,因此无内嵌字体时应传入可访问的 TTF/OTF Web Font 数据,例如 Google Fonts 的 Noto Sans SC。
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader 是一个已打开的 OFD 文档。 Reader 负责持有文档资源,使用完毕后必须调用 Close。
func OpenWithOptions ¶
func OpenWithOptions(data []byte, options OpenOptions) (*Reader, error)
OpenWithOptions 从内存中的 OFD 数据创建浏览器文档引擎,并注册外部回退字体。
func (*Reader) AddFallbackFont ¶
func (r *Reader) AddFallbackFont(source FontSource) error
AddFallbackFont 为没有内嵌 FontFile 的文档字体添加外部字体。 文字和搜索快照会失效,因为它们的字形度量可能使用了不同的回退字体。
func (*Reader) Fonts ¶
func (r *Reader) Fonts() ([]FontResource, error)
Fonts 返回文档中声明的字体资源。只有包含 FontFile 的字体会带有 Data, 调用方可以将这些数据交给浏览器 FontFace 构造器进行注入。
func (*Reader) RenderPDF ¶
func (r *Reader) RenderPDF(indices []int, options RenderOptions) (outputBytes []byte, err error)
RenderPDF 将多个页面按传入顺序栅格化后写入一个 PDF 文档。
func (*Reader) RenderPage ¶
func (r *Reader) RenderPage(index int, options RenderOptions) ([]byte, error)
RenderPage 将指定页面渲染为 PNG 数据。
func (*Reader) RenderPages ¶
func (r *Reader) RenderPages(indices []int, options RenderOptions) ([][]byte, error)
RenderPages 将多个页面按传入顺序渲染为 PNG 数据。 所有页面共享一次 Reader 锁和同一份文档状态;渲染本身仍按顺序执行。
type RenderOptions ¶
RenderOptions 控制页面输出。DPI 控制 PNG 和 PDF 中页面图像的分辨率。
type SearchResult ¶
SearchResult 描述一个页面文字命中。