feat: render interactive manuscript from Endor through generic graphics

This commit is contained in:
2026-11-12 10:52:28 +08:00
parent d29a1be329
commit 2715c1ce2c
71 changed files with 3000 additions and 78 deletions
+57
View File
@@ -474,6 +474,8 @@ pub struct MountGeometry {
pub width: f32,
pub height: f32,
pub interactive: bool,
#[serde(default)]
pub pointer_events: bool,
}
impl MountGeometry {
@@ -560,6 +562,19 @@ fn default_background() -> String {
#[serde(tag = "type", rename_all = "snake_case")]
/// 可校验、可序列化的逻辑绘制命令;转换到设备像素在 display_list 阶段完成。
pub enum RenderCommand {
#[serde(skip_deserializing)]
Image {
x: f32,
y: f32,
width: f32,
height: f32,
offset_x: f32,
offset_y: f32,
angle: f32,
opacity: f32,
tint: Option<Color>,
image: Arc<crate::render::image::Image>,
},
Scene3D {
x: f32,
y: f32,
@@ -603,6 +618,29 @@ impl RenderCommand {
/// 检查当前输入或发布值的不变量,调用方据校验结果决定是否继续。
pub(crate) fn validate(&self) -> Result<()> {
match self {
Self::Image {
x,
y,
width,
height,
offset_x,
offset_y,
angle,
opacity,
image,
..
} => {
validate_rect(*x, *y, *width, *height, 0.)?;
if ![offset_x, offset_y, angle, opacity]
.iter()
.all(|v| v.is_finite())
|| !(0. ..=1.).contains(opacity)
|| image.width == 0
|| image.height == 0
{
bail!("invalid image command");
}
}
Self::Scene3D {
x,
y,
@@ -676,6 +714,25 @@ impl RenderCommand {
/// 把一条已验证的发布命令变成原生绘制原语,缩放几何和文字样式。
fn to_draw_command(&self, scale: f32) -> Result<DrawCommand> {
Ok(match self {
Self::Image {
x,
y,
width,
height,
offset_x,
offset_y,
angle,
opacity,
tint,
image,
} => DrawCommand::Image {
image: image.clone(),
origin: Point::new(x * scale, y * scale),
rect: scaled_rect(*offset_x, *offset_y, *width, *height, scale),
angle: *angle,
opacity: *opacity,
tint: *tint,
},
Self::Scene3D {
x,
y,