选项与资源¶
这些类型把渲染、动画、HTML 解析、字体和图片输入组织在一起。
通用的校验约定:
- 设置
RenderOptions.lang时,它必须是合法的 BCP-47 语言标签。 - 设置
FontResource.weight时,它必须是 1 到 1000 的有限数。 FontResource.unicode_range的每一项都是满足0 <= start <= end <= 0x10FFFF的(start, end)闭区间。AnimationEncodeOptions.quality接受 0 到 100,webp_speed接受 0 到 6。
违反这些数值或语言标签约定时抛出 ValueError。
takumi_py.options.RenderOptions
dataclass
¶
Reusable render settings shared by raster, SVG, and measurement APIs.
Explicit keyword arguments on a render method override matching fields.
Attributes:
| Name | Type | Description |
|---|---|---|
width |
int | None
|
Viewport width in CSS pixels, or |
height |
int | None
|
Viewport height in CSS pixels, or |
format |
ImageOutputFormat
|
Static output format. |
quality |
int | None
|
Lossy encoder quality from 0 through 100 where supported. |
lossless |
bool | None
|
Whether to use lossless WebP encoding. |
font_size |
float
|
Root font size in CSS pixels. |
device_pixel_ratio |
float
|
Scale factor for raster output and layout. |
draw_debug_border |
bool
|
Draw Takumi's layout debug borders. |
time_ms |
int
|
Animation sampling time in milliseconds. |
dithering |
DitheringAlgorithm
|
Color-dithering algorithm for supported formats. |
images |
Sequence[ImageResourceInput] | None
|
Per-render image resources addressable by their |
keyframes |
KeyframesInput | None
|
Structured animation rules appended to the stylesheets. |
font_families |
Sequence[str] | None
|
Preferred fallback font-family order. |
lang |
str | None
|
BCP-47 language tag used for text shaping and font selection. |
__init__ ¶
__init__(
width: int | None = 1200,
height: int | None = 630,
format: ImageOutputFormat = "png",
quality: int | None = None,
lossless: bool | None = None,
font_size: float = 16.0,
device_pixel_ratio: float = 1.0,
draw_debug_border: bool = False,
time_ms: int = 0,
dithering: DitheringAlgorithm = "none",
images: Sequence[ImageResourceInput] | None = None,
keyframes: KeyframesInput | None = None,
font_families: Sequence[str] | None = None,
lang: str | None = None,
) -> None
takumi_py.options.AnimationEncodeOptions
dataclass
¶
Reusable encoder settings for animated output.
Explicit keyword arguments on render_animation or encode_frames
override matching fields.
Attributes:
| Name | Type | Description |
|---|---|---|
format |
AnimationOutputFormat
|
Animation container format. |
quality |
int | None
|
Lossy encoder quality from 0 through 100 where supported. |
lossless |
bool | None
|
Whether to use lossless WebP encoding. |
loop_count |
int | None
|
Number of animation repetitions, or |
webp_blend |
bool
|
Blend each WebP frame with the previous canvas. |
webp_dispose |
bool
|
Dispose each WebP frame before drawing the next one. |
webp_speed |
int | None
|
WebP encoder speed/effort setting from 0 through 6. |
__init__ ¶
__init__(
format: AnimationOutputFormat = "webp",
quality: int | None = None,
lossless: bool | None = None,
loop_count: int | None = None,
webp_blend: bool = True,
webp_dispose: bool = False,
webp_speed: int | None = None,
) -> None
takumi_py.options.HtmlOptions
dataclass
¶
Inputs that control how the Rust HTML parser builds a node tree.
Attributes:
| Name | Type | Description |
|---|---|---|
presets |
HtmlStylePresets
|
Default element styles to apply. |
tailwind_property |
str | None
|
HTML attribute that contains Tailwind classes.
|
max_depth |
int | None
|
Maximum element nesting depth, or |
__init__ ¶
__init__(
presets: HtmlStylePresets = "chromium",
tailwind_property: str | None = None,
max_depth: int | None = None,
) -> None
takumi_py.options.ImageResource
dataclass
¶
Image bytes addressable by an image node's src.
Attributes:
| Name | Type | Description |
|---|---|---|
src |
str
|
Identifier matched against the image node's |
data |
bytes
|
Encoded image bytes, such as PNG, JPEG, WebP, or SVG data. |
cache |
ImageCacheMode
|
Whether the renderer may retain the decoded image in its renderer-local resource cache. |
takumi_py.options.FontResource
dataclass
¶
Font bytes plus the @font-face descriptors used to register them.
Register each subset of a family under the same name with the
unicode_range its @font-face declares; a subset only serves the
codepoints in its ranges.
Attributes:
| Name | Type | Description |
|---|---|---|
data |
bytes
|
TrueType, OpenType, WOFF, or WOFF2 font bytes. |
name |
str | None
|
Family name to register the font under. Defaults to the name stored in the font file. |
weight |
float | None
|
Weight override from 1 through 1000. |
style |
str | None
|
CSS |
subset_of |
str | None
|
Deprecated. Takumi now treats it as the family name and it
takes precedence over |
generic_family |
GenericFontFamily | None
|
CSS generic family keyword this font resolves. |
unicode_range |
Sequence[UnicodeRange] | None
|
Inclusive |
unicode_range
class-attribute
instance-attribute
¶
__init__ ¶
__init__(
data: bytes,
name: str | None = None,
weight: float | None = None,
style: str | None = None,
subset_of: str | None = None,
generic_family: GenericFontFamily | None = None,
unicode_range: Sequence[UnicodeRange] | None = None,
) -> None
结构化关键帧¶
可以把结构化关键帧传给渲染方法,或存入 RenderOptions.keyframes。映射形式使用动画名称
作为键。
takumi_py.options.Keyframe ¶
Bases: TypedDict
One structured keyframe and the declarations it applies.
Attributes:
| Name | Type | Description |
|---|---|---|
offsets |
Sequence[float]
|
Normalized timeline positions from 0 through 1. |
declarations |
StyleInput
|
CSS declarations applied at those positions. |