render

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

render 包负责把标准化后的二维码请求转换成可缓存的位图、终端预览和导出 字节流。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequiredModules

func RequiredModules(content string, level core.Level) (int, error)

RequiredModules 返回指定内容和纠错等级在预览中的模块边长(包含 quiet zone)。 这个值可用于判断当前终端网格是否能完整显示并扫码。

Types

type Engine

type Engine struct {
	// contains filtered or unexported fields
}

Engine 根据标准化请求准备可复用的渲染产物,并缓存最近一次结果,供预览 和保存流程复用。

func NewEngine

func NewEngine() *Engine

NewEngine 返回一个带空单项缓存的渲染器。

func (*Engine) Prepare

func (e *Engine) Prepare(req core.NormalizedRequest) (*Prepared, error)

Prepare 只构建一次二维码位图,然后让所有输出模式都从同一份位图渲染。 外部库只负责生成矩阵,最终绘制保留在本包内,以避免预览和导出漂移。

type Prepared

type Prepared struct {
	// contains filtered or unexported fields
}

Prepared 表示 PNG、SVG、终端预览和文件导出共用的渲染结果,让应用只有 一套视觉真相来源。

func (*Prepared) PNG

func (p *Prepared) PNG() ([]byte, error)

PNG 把共享位图栅格化为指定尺寸的正方形图像。

func (*Prepared) Preview

func (p *Prepared) Preview() string

Preview 构建适合终端显示的块状预览,并缓存结果字符串,因为 TUI 可能反复 请求它。

func (*Prepared) PreviewFit

func (p *Prepared) PreviewFit(maxWidth, maxHeight int) string

PreviewFit 会按当前终端预览画布放大二维码矩阵;当画布不足时保持原始模块 分辨率,不做有损压缩,避免预览看起来完整但实际不可扫码。

func (*Prepared) PreviewModules

func (p *Prepared) PreviewModules() int

PreviewModules 返回包含 quiet zone 在内的预览模块边长,用于让上层判断 当前终端网格是否足够完整呈现二维码。

func (*Prepared) Raster

func (p *Prepared) Raster() image.Image

Raster 返回和最终导出一致的二维码栅格图像,供 PNG 导出与其他预览路径共用。

func (*Prepared) SVG

func (p *Prepared) SVG() ([]byte, error)

SVG 把共享位图渲染成清晰的矩形模块,确保矢量导出和 PNG 使用同一套几何 规则。

func (*Prepared) WriteToPath

func (p *Prepared) WriteToPath(path string) error

WriteToPath 会先写入临时文件,确保保存失败时不会留下半写入的图像文件。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL