certflow.config.print_config module

打印配置 - 一次加载,全链路透传

同时提供打印配置的模块级 helper(原 services/cert_print_config.py, 已于重构 §2.3 迁入本 canonical 模块):加载、缓存、热重载与字段定义读取。

certflow.config.print_config.load_print_config()[源代码]

从 config.yaml → print 加载打印配置(canonical 唯一信源,带缓存)

返回类型:

dict[str, Any]

certflow.config.print_config.reload_print_config()[源代码]

热重载打印配置:清除 YAML 缓存 + 打印配置缓存

返回类型:

None

certflow.config.print_config.get_paper()[源代码]

纸张尺寸 (mm)

返回类型:

dict[str, Any]

certflow.config.print_config.get_layout()[源代码]

打印坐标

返回类型:

dict[str, Any]

certflow.config.print_config.get_font()[源代码]

打印字体

返回类型:

dict[str, Any]

certflow.config.print_config.get_print_fields()[源代码]

打印字段定义

返回类型:

list[dict[str, Any]]

certflow.config.print_config.fields_to_tuples()[源代码]

转为 (label, key, offset) 元组列表

返回类型:

list[tuple[str, str, int]]

certflow.config.print_config.get_empty_markers()[源代码]

从 config.yaml → print_log_empty_markers 加载空值默认标记

返回类型:

dict[str, Any]

class certflow.config.print_config.PaperConfig(width_mm=60, height_mm=100)[源代码]

基类:object

纸张尺寸配置(数据类)

定义打印纸张的宽高,单位为毫米(mm).

参数:
width_mm

纸张宽度,单位毫米,默认为 60。

Type:

float

height_mm

纸张高度,单位毫米,默认为 100。

Type:

float

width_mm: float = 60
height_mm: float = 100
class certflow.config.print_config.LayoutConfig(x_offset_mm=14, y_offset_mm=0, start_y_mm=22, line_spacing_mm=6.5, font_size=9, font_name='SimSun', font_weight=400)[源代码]

基类:object

打印布局配置(数据类)

定义打印内容的坐标、偏移、行间距与字体等布局参数.

参数:
x_offset_mm

打印机物理 X 偏移修正,单位毫米,默认为 14。

Type:

float

y_offset_mm

打印机物理 Y 偏移修正,单位毫米,默认为 0。

Type:

float

start_y_mm

起始 Y 坐标,单位毫米,默认为 22。

Type:

float

line_spacing_mm

行间距,单位毫米,默认为 6.5。

Type:

float

font_size

字体大小(磅),默认为 9。

Type:

int

font_name

字体名称,默认为 "SimSun"。

Type:

str

font_weight

字体粗细,默认为 400。

Type:

int

x_offset_mm: float = 14
y_offset_mm: float = 0
start_y_mm: float = 22
line_spacing_mm: float = 6.5
font_size: int = 9
font_name: str = 'SimSun'
font_weight: int = 400
class certflow.config.print_config.FieldDef(key, label, x_mm=0, y_mm=0, width_mm=0, height_mm=0, font_size=9, align='left', bold=False)[源代码]

基类:object

打印字段定义(数据类)

描述单个打印字段的键名、标签与在模板中的坐标和样式.

参数:
key

字段键名,用于程序内引用。

Type:

str

label

字段显示标签(中文)。

Type:

str

x_mm

字段 X 坐标,单位毫米,默认为 0。

Type:

float

y_mm

字段 Y 坐标,单位毫米,默认为 0。

Type:

float

width_mm

字段宽度,单位毫米,默认为 0。

Type:

float

height_mm

字段高度,单位毫米,默认为 0。

Type:

float

font_size

字体大小(磅),默认为 9。

Type:

int

align

对齐方式,默认为 "left"。

Type:

str

bold

是否加粗,默认为 False。

Type:

bool

key: str
label: str
x_mm: float = 0
y_mm: float = 0
width_mm: float = 0
height_mm: float = 0
font_size: int = 9
align: str = 'left'
bold: bool = False
class certflow.config.print_config.TemplateConfig(name, key, variant='', background='', page_width_mm=60, page_height_mm=100, fields=<factory>)[源代码]

基类:object

打印模板配置(数据类)

聚合单个打印模板的名称、页面尺寸与字段列表.

参数:
name

模板显示名称。

Type:

str

key

模板键名,用于从配置中检索。

Type:

str

variant

模板变体标识,默认为空字符串。

Type:

str

background

背景图片路径,默认为空字符串。

Type:

str

page_width_mm

页面宽度,单位毫米,默认为 60。

Type:

float

page_height_mm

页面高度,单位毫米,默认为 100。

Type:

float

fields

模板字段列表,默认为空列表。

Type:

list[certflow.config.print_config.FieldDef]

name: str
key: str
variant: str = ''
background: str = ''
page_width_mm: float = 60
page_height_mm: float = 100
fields: list[FieldDef]
get_field(key)[源代码]

按字段键名查找模板字段

参数:

key (str) -- 字段键名。

返回:

匹配到的字段定义;未找到时返回 None。

返回类型:

FieldDef | None

class certflow.config.print_config.RuntimePrintConfig(engine='escp', printer_name='', copies=1, paper=<factory>, layout=<factory>, template=None)[源代码]

基类:object

打印聚合配置 - 包含一次打印所需的全部参数

注意:与 certflow.config.models.PrintConfig``(pydantic 引擎配置模型)同名, 此处运行时聚合类已重命名为 ``RuntimePrintConfig 以消除歧义(见 §8/§16.3)。

参数:
engine: Literal['escp', 'gdi'] = 'escp'
printer_name: str = ''
copies: int = 1
paper: PaperConfig
layout: LayoutConfig
template: TemplateConfig | None = None
classmethod from_template(template_key='full_chinese_1', printer_name='', copies=1)[源代码]

从模板键名加载完整打印配置

参数:
  • template_key (str) -- 模板键名 (full_chinese_1, bilingual_1, russian...)

  • printer_name (str) -- 打印机名称,为空则用默认

  • copies (int) -- 打印份数

返回:

RuntimePrintConfig 实例,包含一次打印所需的全部参数

返回类型:

RuntimePrintConfig