Documentation
¶
Overview ¶
Package webreader 包提供适合浏览器调用的 OFD 文档访问接口。
Index ¶
- type DocumentInfo
- 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) Info() (DocumentInfo, 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 RenderFormat
- type RenderOptions
- type SearchResult
- type TextRun
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DocumentInfo ¶ added in v0.1.1
type DocumentInfo struct {
DocID string
Title string
Author string
Subject string
Abstract string
CreationDate string
ModDate string
Creator string
Version string
}
DocumentInfo 描述 OFD 文档的元数据信息。
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 OpenOptions ¶
type OpenOptions struct {
// FallbackFonts 是文档未提供可用内嵌字体时使用的回退字体。
FallbackFonts []FontSource
// PageCacheCapacity 是页面缓存最多保留的页面数量,0 表示使用默认值。
PageCacheCapacity int
// PageCacheBytes 是页面缓存允许使用的估算最大字节数,0 表示使用默认值。
PageCacheBytes int64
}
OpenOptions 配置 OFD 打开行为。
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) Info ¶ added in v0.1.1
func (r *Reader) Info() (DocumentInfo, error)
Info 返回 OFD 文档的元数据信息。
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、JPG 或 SVG 数据。
func (*Reader) RenderPages ¶
func (r *Reader) RenderPages(indices []int, options RenderOptions) ([][]byte, error)
RenderPages 将多个页面按传入顺序渲染为 PNG、JPG 或 SVG 数据。 所有页面共享一次 Reader 锁和同一份文档状态;渲染本身仍按顺序执行。
type RenderFormat ¶ added in v0.1.1
type RenderFormat string
RenderFormat 是页面输出格式。
const ( // RenderPNG 输出 PNG 位图。为空时也使用该格式。 RenderPNG RenderFormat = "png" // RenderSVG 输出 SVG 矢量文档。 RenderSVG RenderFormat = "svg" // RenderJPG 输出 JPG 位图。JPG 不支持透明度,透明区域使用白色填充。 RenderJPG RenderFormat = "jpg" )
type RenderOptions ¶
type RenderOptions struct {
DPI float64
Background color.Color
Format RenderFormat
}
RenderOptions 控制页面输出。DPI 控制 PNG、JPG 和 PDF 中页面图像的分辨率; SVG 主要保留页面中的矢量内容,复杂渐变等仍可能包含栅格回退。
type SearchResult ¶
SearchResult 描述一个页面文字命中。